UNPKG

274 kBJavaScriptView Raw
1import MagicString from 'magic-string';
2import * as acorn from 'acorn';
3
4var xhtml = {
5 quot: '\u0022',
6 amp: '&',
7 apos: '\u0027',
8 lt: '<',
9 gt: '>',
10 nbsp: '\u00A0',
11 iexcl: '\u00A1',
12 cent: '\u00A2',
13 pound: '\u00A3',
14 curren: '\u00A4',
15 yen: '\u00A5',
16 brvbar: '\u00A6',
17 sect: '\u00A7',
18 uml: '\u00A8',
19 copy: '\u00A9',
20 ordf: '\u00AA',
21 laquo: '\u00AB',
22 not: '\u00AC',
23 shy: '\u00AD',
24 reg: '\u00AE',
25 macr: '\u00AF',
26 deg: '\u00B0',
27 plusmn: '\u00B1',
28 sup2: '\u00B2',
29 sup3: '\u00B3',
30 acute: '\u00B4',
31 micro: '\u00B5',
32 para: '\u00B6',
33 middot: '\u00B7',
34 cedil: '\u00B8',
35 sup1: '\u00B9',
36 ordm: '\u00BA',
37 raquo: '\u00BB',
38 frac14: '\u00BC',
39 frac12: '\u00BD',
40 frac34: '\u00BE',
41 iquest: '\u00BF',
42 Agrave: '\u00C0',
43 Aacute: '\u00C1',
44 Acirc: '\u00C2',
45 Atilde: '\u00C3',
46 Auml: '\u00C4',
47 Aring: '\u00C5',
48 AElig: '\u00C6',
49 Ccedil: '\u00C7',
50 Egrave: '\u00C8',
51 Eacute: '\u00C9',
52 Ecirc: '\u00CA',
53 Euml: '\u00CB',
54 Igrave: '\u00CC',
55 Iacute: '\u00CD',
56 Icirc: '\u00CE',
57 Iuml: '\u00CF',
58 ETH: '\u00D0',
59 Ntilde: '\u00D1',
60 Ograve: '\u00D2',
61 Oacute: '\u00D3',
62 Ocirc: '\u00D4',
63 Otilde: '\u00D5',
64 Ouml: '\u00D6',
65 times: '\u00D7',
66 Oslash: '\u00D8',
67 Ugrave: '\u00D9',
68 Uacute: '\u00DA',
69 Ucirc: '\u00DB',
70 Uuml: '\u00DC',
71 Yacute: '\u00DD',
72 THORN: '\u00DE',
73 szlig: '\u00DF',
74 agrave: '\u00E0',
75 aacute: '\u00E1',
76 acirc: '\u00E2',
77 atilde: '\u00E3',
78 auml: '\u00E4',
79 aring: '\u00E5',
80 aelig: '\u00E6',
81 ccedil: '\u00E7',
82 egrave: '\u00E8',
83 eacute: '\u00E9',
84 ecirc: '\u00EA',
85 euml: '\u00EB',
86 igrave: '\u00EC',
87 iacute: '\u00ED',
88 icirc: '\u00EE',
89 iuml: '\u00EF',
90 eth: '\u00F0',
91 ntilde: '\u00F1',
92 ograve: '\u00F2',
93 oacute: '\u00F3',
94 ocirc: '\u00F4',
95 otilde: '\u00F5',
96 ouml: '\u00F6',
97 divide: '\u00F7',
98 oslash: '\u00F8',
99 ugrave: '\u00F9',
100 uacute: '\u00FA',
101 ucirc: '\u00FB',
102 uuml: '\u00FC',
103 yacute: '\u00FD',
104 thorn: '\u00FE',
105 yuml: '\u00FF',
106 OElig: '\u0152',
107 oelig: '\u0153',
108 Scaron: '\u0160',
109 scaron: '\u0161',
110 Yuml: '\u0178',
111 fnof: '\u0192',
112 circ: '\u02C6',
113 tilde: '\u02DC',
114 Alpha: '\u0391',
115 Beta: '\u0392',
116 Gamma: '\u0393',
117 Delta: '\u0394',
118 Epsilon: '\u0395',
119 Zeta: '\u0396',
120 Eta: '\u0397',
121 Theta: '\u0398',
122 Iota: '\u0399',
123 Kappa: '\u039A',
124 Lambda: '\u039B',
125 Mu: '\u039C',
126 Nu: '\u039D',
127 Xi: '\u039E',
128 Omicron: '\u039F',
129 Pi: '\u03A0',
130 Rho: '\u03A1',
131 Sigma: '\u03A3',
132 Tau: '\u03A4',
133 Upsilon: '\u03A5',
134 Phi: '\u03A6',
135 Chi: '\u03A7',
136 Psi: '\u03A8',
137 Omega: '\u03A9',
138 alpha: '\u03B1',
139 beta: '\u03B2',
140 gamma: '\u03B3',
141 delta: '\u03B4',
142 epsilon: '\u03B5',
143 zeta: '\u03B6',
144 eta: '\u03B7',
145 theta: '\u03B8',
146 iota: '\u03B9',
147 kappa: '\u03BA',
148 lambda: '\u03BB',
149 mu: '\u03BC',
150 nu: '\u03BD',
151 xi: '\u03BE',
152 omicron: '\u03BF',
153 pi: '\u03C0',
154 rho: '\u03C1',
155 sigmaf: '\u03C2',
156 sigma: '\u03C3',
157 tau: '\u03C4',
158 upsilon: '\u03C5',
159 phi: '\u03C6',
160 chi: '\u03C7',
161 psi: '\u03C8',
162 omega: '\u03C9',
163 thetasym: '\u03D1',
164 upsih: '\u03D2',
165 piv: '\u03D6',
166 ensp: '\u2002',
167 emsp: '\u2003',
168 thinsp: '\u2009',
169 zwnj: '\u200C',
170 zwj: '\u200D',
171 lrm: '\u200E',
172 rlm: '\u200F',
173 ndash: '\u2013',
174 mdash: '\u2014',
175 lsquo: '\u2018',
176 rsquo: '\u2019',
177 sbquo: '\u201A',
178 ldquo: '\u201C',
179 rdquo: '\u201D',
180 bdquo: '\u201E',
181 dagger: '\u2020',
182 Dagger: '\u2021',
183 bull: '\u2022',
184 hellip: '\u2026',
185 permil: '\u2030',
186 prime: '\u2032',
187 Prime: '\u2033',
188 lsaquo: '\u2039',
189 rsaquo: '\u203A',
190 oline: '\u203E',
191 frasl: '\u2044',
192 euro: '\u20AC',
193 image: '\u2111',
194 weierp: '\u2118',
195 real: '\u211C',
196 trade: '\u2122',
197 alefsym: '\u2135',
198 larr: '\u2190',
199 uarr: '\u2191',
200 rarr: '\u2192',
201 darr: '\u2193',
202 harr: '\u2194',
203 crarr: '\u21B5',
204 lArr: '\u21D0',
205 uArr: '\u21D1',
206 rArr: '\u21D2',
207 dArr: '\u21D3',
208 hArr: '\u21D4',
209 forall: '\u2200',
210 part: '\u2202',
211 exist: '\u2203',
212 empty: '\u2205',
213 nabla: '\u2207',
214 isin: '\u2208',
215 notin: '\u2209',
216 ni: '\u220B',
217 prod: '\u220F',
218 sum: '\u2211',
219 minus: '\u2212',
220 lowast: '\u2217',
221 radic: '\u221A',
222 prop: '\u221D',
223 infin: '\u221E',
224 ang: '\u2220',
225 and: '\u2227',
226 or: '\u2228',
227 cap: '\u2229',
228 cup: '\u222A',
229 'int': '\u222B',
230 there4: '\u2234',
231 sim: '\u223C',
232 cong: '\u2245',
233 asymp: '\u2248',
234 ne: '\u2260',
235 equiv: '\u2261',
236 le: '\u2264',
237 ge: '\u2265',
238 sub: '\u2282',
239 sup: '\u2283',
240 nsub: '\u2284',
241 sube: '\u2286',
242 supe: '\u2287',
243 oplus: '\u2295',
244 otimes: '\u2297',
245 perp: '\u22A5',
246 sdot: '\u22C5',
247 lceil: '\u2308',
248 rceil: '\u2309',
249 lfloor: '\u230A',
250 rfloor: '\u230B',
251 lang: '\u2329',
252 rang: '\u232A',
253 loz: '\u25CA',
254 spades: '\u2660',
255 clubs: '\u2663',
256 hearts: '\u2665',
257 diams: '\u2666'
258};
259
260var hexNumber = /^[\da-fA-F]+$/;
261var decimalNumber = /^\d+$/;
262
263var inject = function(acorn$$1) {
264 var tt = acorn$$1.tokTypes;
265 var tc = acorn$$1.tokContexts;
266
267 tc.j_oTag = new acorn$$1.TokContext('<tag', false);
268 tc.j_cTag = new acorn$$1.TokContext('</tag', false);
269 tc.j_expr = new acorn$$1.TokContext('<tag>...</tag>', true, true);
270
271 tt.jsxName = new acorn$$1.TokenType('jsxName');
272 tt.jsxText = new acorn$$1.TokenType('jsxText', {beforeExpr: true});
273 tt.jsxTagStart = new acorn$$1.TokenType('jsxTagStart');
274 tt.jsxTagEnd = new acorn$$1.TokenType('jsxTagEnd');
275
276 tt.jsxTagStart.updateContext = function() {
277 this.context.push(tc.j_expr); // treat as beginning of JSX expression
278 this.context.push(tc.j_oTag); // start opening tag context
279 this.exprAllowed = false;
280 };
281 tt.jsxTagEnd.updateContext = function(prevType) {
282 var out = this.context.pop();
283 if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) {
284 this.context.pop();
285 this.exprAllowed = this.curContext() === tc.j_expr;
286 } else {
287 this.exprAllowed = true;
288 }
289 };
290
291 var pp = acorn$$1.Parser.prototype;
292
293 // Reads inline JSX contents token.
294
295 pp.jsx_readToken = function() {
296 var out = '', chunkStart = this.pos;
297 for (;;) {
298 if (this.pos >= this.input.length)
299 this.raise(this.start, 'Unterminated JSX contents');
300 var ch = this.input.charCodeAt(this.pos);
301
302 switch (ch) {
303 case 60: // '<'
304 case 123: // '{'
305 if (this.pos === this.start) {
306 if (ch === 60 && this.exprAllowed) {
307 ++this.pos;
308 return this.finishToken(tt.jsxTagStart);
309 }
310 return this.getTokenFromCode(ch);
311 }
312 out += this.input.slice(chunkStart, this.pos);
313 return this.finishToken(tt.jsxText, out);
314
315 case 38: // '&'
316 out += this.input.slice(chunkStart, this.pos);
317 out += this.jsx_readEntity();
318 chunkStart = this.pos;
319 break;
320
321 default:
322 if (acorn$$1.isNewLine(ch)) {
323 out += this.input.slice(chunkStart, this.pos);
324 out += this.jsx_readNewLine(true);
325 chunkStart = this.pos;
326 } else {
327 ++this.pos;
328 }
329 }
330 }
331 };
332
333 pp.jsx_readNewLine = function(normalizeCRLF) {
334 var ch = this.input.charCodeAt(this.pos);
335 var out;
336 ++this.pos;
337 if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
338 ++this.pos;
339 out = normalizeCRLF ? '\n' : '\r\n';
340 } else {
341 out = String.fromCharCode(ch);
342 }
343 if (this.options.locations) {
344 ++this.curLine;
345 this.lineStart = this.pos;
346 }
347
348 return out;
349 };
350
351 pp.jsx_readString = function(quote) {
352 var out = '', chunkStart = ++this.pos;
353 for (;;) {
354 if (this.pos >= this.input.length)
355 this.raise(this.start, 'Unterminated string constant');
356 var ch = this.input.charCodeAt(this.pos);
357 if (ch === quote) break;
358 if (ch === 38) { // '&'
359 out += this.input.slice(chunkStart, this.pos);
360 out += this.jsx_readEntity();
361 chunkStart = this.pos;
362 } else if (acorn$$1.isNewLine(ch)) {
363 out += this.input.slice(chunkStart, this.pos);
364 out += this.jsx_readNewLine(false);
365 chunkStart = this.pos;
366 } else {
367 ++this.pos;
368 }
369 }
370 out += this.input.slice(chunkStart, this.pos++);
371 return this.finishToken(tt.string, out);
372 };
373
374 pp.jsx_readEntity = function() {
375 var str = '', count = 0, entity;
376 var ch = this.input[this.pos];
377 if (ch !== '&')
378 this.raise(this.pos, 'Entity must start with an ampersand');
379 var startPos = ++this.pos;
380 while (this.pos < this.input.length && count++ < 10) {
381 ch = this.input[this.pos++];
382 if (ch === ';') {
383 if (str[0] === '#') {
384 if (str[1] === 'x') {
385 str = str.substr(2);
386 if (hexNumber.test(str))
387 entity = String.fromCharCode(parseInt(str, 16));
388 } else {
389 str = str.substr(1);
390 if (decimalNumber.test(str))
391 entity = String.fromCharCode(parseInt(str, 10));
392 }
393 } else {
394 entity = xhtml[str];
395 }
396 break;
397 }
398 str += ch;
399 }
400 if (!entity) {
401 this.pos = startPos;
402 return '&';
403 }
404 return entity;
405 };
406
407
408 // Read a JSX identifier (valid tag or attribute name).
409 //
410 // Optimized version since JSX identifiers can't contain
411 // escape characters and so can be read as single slice.
412 // Also assumes that first character was already checked
413 // by isIdentifierStart in readToken.
414
415 pp.jsx_readWord = function() {
416 var ch, start = this.pos;
417 do {
418 ch = this.input.charCodeAt(++this.pos);
419 } while (acorn$$1.isIdentifierChar(ch) || ch === 45); // '-'
420 return this.finishToken(tt.jsxName, this.input.slice(start, this.pos));
421 };
422
423 // Transforms JSX element name to string.
424
425 function getQualifiedJSXName(object) {
426 if (!object)
427 return object;
428
429 if (object.type === 'JSXIdentifier')
430 return object.name;
431
432 if (object.type === 'JSXNamespacedName')
433 return object.namespace.name + ':' + object.name.name;
434
435 if (object.type === 'JSXMemberExpression')
436 return getQualifiedJSXName(object.object) + '.' +
437 getQualifiedJSXName(object.property);
438 }
439
440 // Parse next token as JSX identifier
441
442 pp.jsx_parseIdentifier = function() {
443 var node = this.startNode();
444 if (this.type === tt.jsxName)
445 node.name = this.value;
446 else if (this.type.keyword)
447 node.name = this.type.keyword;
448 else
449 this.unexpected();
450 this.next();
451 return this.finishNode(node, 'JSXIdentifier');
452 };
453
454 // Parse namespaced identifier.
455
456 pp.jsx_parseNamespacedName = function() {
457 var startPos = this.start, startLoc = this.startLoc;
458 var name = this.jsx_parseIdentifier();
459 if (!this.options.plugins.jsx.allowNamespaces || !this.eat(tt.colon)) return name;
460 var node = this.startNodeAt(startPos, startLoc);
461 node.namespace = name;
462 node.name = this.jsx_parseIdentifier();
463 return this.finishNode(node, 'JSXNamespacedName');
464 };
465
466 // Parses element name in any form - namespaced, member
467 // or single identifier.
468
469 pp.jsx_parseElementName = function() {
470 if (this.type === tt.jsxTagEnd)
471 return '';
472 var startPos = this.start, startLoc = this.startLoc;
473 var node = this.jsx_parseNamespacedName();
474 if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !this.options.plugins.jsx.allowNamespacedObjects) {
475 this.unexpected();
476 }
477 while (this.eat(tt.dot)) {
478 var newNode = this.startNodeAt(startPos, startLoc);
479 newNode.object = node;
480 newNode.property = this.jsx_parseIdentifier();
481 node = this.finishNode(newNode, 'JSXMemberExpression');
482 }
483 return node;
484 };
485
486 // Parses any type of JSX attribute value.
487
488 pp.jsx_parseAttributeValue = function() {
489 switch (this.type) {
490 case tt.braceL:
491 var node = this.jsx_parseExpressionContainer();
492 if (node.expression.type === 'JSXEmptyExpression')
493 this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression');
494 return node;
495
496 case tt.jsxTagStart:
497 case tt.string:
498 return this.parseExprAtom();
499
500 default:
501 this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
502 }
503 };
504
505 // JSXEmptyExpression is unique type since it doesn't actually parse anything,
506 // and so it should start at the end of last read token (left brace) and finish
507 // at the beginning of the next one (right brace).
508
509 pp.jsx_parseEmptyExpression = function() {
510 var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
511 return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
512 };
513
514 // Parses JSX expression enclosed into curly brackets.
515
516
517 pp.jsx_parseExpressionContainer = function() {
518 var node = this.startNode();
519 this.next();
520 node.expression = this.type === tt.braceR
521 ? this.jsx_parseEmptyExpression()
522 : this.parseExpression();
523 this.expect(tt.braceR);
524 return this.finishNode(node, 'JSXExpressionContainer');
525 };
526
527 // Parses following JSX attribute name-value pair.
528
529 pp.jsx_parseAttribute = function() {
530 var node = this.startNode();
531 if (this.eat(tt.braceL)) {
532 this.expect(tt.ellipsis);
533 node.argument = this.parseMaybeAssign();
534 this.expect(tt.braceR);
535 return this.finishNode(node, 'JSXSpreadAttribute');
536 }
537 node.name = this.jsx_parseNamespacedName();
538 node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
539 return this.finishNode(node, 'JSXAttribute');
540 };
541
542 // Parses JSX opening tag starting after '<'.
543
544 pp.jsx_parseOpeningElementAt = function(startPos, startLoc) {
545 var node = this.startNodeAt(startPos, startLoc);
546 node.attributes = [];
547 var nodeName = this.jsx_parseElementName();
548 if (nodeName) node.name = nodeName;
549 while (this.type !== tt.slash && this.type !== tt.jsxTagEnd)
550 node.attributes.push(this.jsx_parseAttribute());
551 node.selfClosing = this.eat(tt.slash);
552 this.expect(tt.jsxTagEnd);
553 return this.finishNode(node, nodeName ? 'JSXOpeningElement' : 'JSXOpeningFragment');
554 };
555
556 // Parses JSX closing tag starting after '</'.
557
558 pp.jsx_parseClosingElementAt = function(startPos, startLoc) {
559 var node = this.startNodeAt(startPos, startLoc);
560 var nodeName = this.jsx_parseElementName();
561 if (nodeName) node.name = nodeName;
562 this.expect(tt.jsxTagEnd);
563 return this.finishNode(node, nodeName ? 'JSXClosingElement' : 'JSXClosingFragment');
564 };
565
566 // Parses entire JSX element, including it's opening tag
567 // (starting after '<'), attributes, contents and closing tag.
568
569 pp.jsx_parseElementAt = function(startPos, startLoc) {
570 var node = this.startNodeAt(startPos, startLoc);
571 var children = [];
572 var openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
573 var closingElement = null;
574
575 if (!openingElement.selfClosing) {
576 contents: for (;;) {
577 switch (this.type) {
578 case tt.jsxTagStart:
579 startPos = this.start; startLoc = this.startLoc;
580 this.next();
581 if (this.eat(tt.slash)) {
582 closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
583 break contents;
584 }
585 children.push(this.jsx_parseElementAt(startPos, startLoc));
586 break;
587
588 case tt.jsxText:
589 children.push(this.parseExprAtom());
590 break;
591
592 case tt.braceL:
593 children.push(this.jsx_parseExpressionContainer());
594 break;
595
596 default:
597 this.unexpected();
598 }
599 }
600 if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
601 this.raise(
602 closingElement.start,
603 'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
604 }
605 }
606
607 node.openingElement = openingElement;
608 node.closingElement = closingElement;
609 node.children = children;
610 if (this.type === tt.relational && this.value === "<") {
611 this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
612 }
613 return this.finishNode(node, openingElement.name ? 'JSXElement' : 'JSXFragment');
614 };
615
616 // Parse JSX text
617
618 pp.jsx_parseText = function(value) {
619 var node = this.parseLiteral(value);
620 node.type = "JSXText";
621
622 return node;
623 };
624
625 // Parses entire JSX element from current position.
626
627 pp.jsx_parseElement = function() {
628 var startPos = this.start, startLoc = this.startLoc;
629 this.next();
630 return this.jsx_parseElementAt(startPos, startLoc);
631 };
632
633 acorn$$1.plugins.jsx = function(instance, opts) {
634 if (!opts) {
635 return;
636 }
637
638 if (typeof opts !== 'object') {
639 opts = {};
640 }
641
642 instance.options.plugins.jsx = {
643 allowNamespaces: opts.allowNamespaces !== false,
644 allowNamespacedObjects: !!opts.allowNamespacedObjects
645 };
646
647 instance.extend('parseExprAtom', function(inner) {
648 return function(refShortHandDefaultPos) {
649 if (this.type === tt.jsxText)
650 return this.jsx_parseText(this.value);
651 else if (this.type === tt.jsxTagStart)
652 return this.jsx_parseElement();
653 else
654 return inner.call(this, refShortHandDefaultPos);
655 };
656 });
657
658 instance.extend('readToken', function(inner) {
659 return function(code) {
660 var context = this.curContext();
661
662 if (context === tc.j_expr) return this.jsx_readToken();
663
664 if (context === tc.j_oTag || context === tc.j_cTag) {
665 if (acorn$$1.isIdentifierStart(code)) return this.jsx_readWord();
666
667 if (code == 62) {
668 ++this.pos;
669 return this.finishToken(tt.jsxTagEnd);
670 }
671
672 if ((code === 34 || code === 39) && context == tc.j_oTag)
673 return this.jsx_readString(code);
674 }
675
676 if (code === 60 && this.exprAllowed && this.input.charCodeAt(this.pos + 1) !== 33) {
677 ++this.pos;
678 return this.finishToken(tt.jsxTagStart);
679 }
680 return inner.call(this, code);
681 };
682 });
683
684 instance.extend('updateContext', function(inner) {
685 return function(prevType) {
686 if (this.type == tt.braceL) {
687 var curContext = this.curContext();
688 if (curContext == tc.j_oTag) this.context.push(tc.b_expr);
689 else if (curContext == tc.j_expr) this.context.push(tc.b_tmpl);
690 else inner.call(this, prevType);
691 this.exprAllowed = true;
692 } else if (this.type === tt.slash && prevType === tt.jsxTagStart) {
693 this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
694 this.context.push(tc.j_cTag); // reconsider as closing tag context
695 this.exprAllowed = false;
696 } else {
697 return inner.call(this, prevType);
698 }
699 };
700 });
701 };
702
703 return acorn$$1;
704};
705
706var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
707
708function commonjsRequire () {
709 throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
710}
711
712function unwrapExports (x) {
713 return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
714}
715
716function createCommonjsModule(fn, module) {
717 return module = { exports: {} }, fn(module, module.exports), module.exports;
718}
719
720var inject$1 = createCommonjsModule(function (module, exports) {
721Object.defineProperty(exports, "__esModule", {
722 value: true
723});
724exports['default'] = injectDynamicImport;
725/* eslint-disable no-underscore-dangle */
726
727var DynamicImportKey = exports.DynamicImportKey = 'Import';
728
729function injectDynamicImport(acorn$$1) {
730 var tt = acorn$$1.tokTypes;
731
732 // NOTE: This allows `yield import()` to parse correctly.
733 tt._import.startsExpr = true;
734
735 function parseDynamicImport() {
736 var node = this.startNode();
737 this.next();
738 if (this.type !== tt.parenL) {
739 this.unexpected();
740 }
741 return this.finishNode(node, DynamicImportKey);
742 }
743
744 function peekNext() {
745 return this.input[this.pos];
746 }
747
748 // eslint-disable-next-line no-param-reassign
749 acorn$$1.plugins.dynamicImport = function () {
750 function dynamicImportPlugin(instance) {
751 instance.extend('parseStatement', function (nextMethod) {
752 return function () {
753 function parseStatement() {
754 var node = this.startNode();
755 if (this.type === tt._import) {
756 var nextToken = peekNext.call(this);
757 if (nextToken === tt.parenL.label) {
758 var expr = this.parseExpression();
759 return this.parseExpressionStatement(node, expr);
760 }
761 }
762
763 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
764 args[_key] = arguments[_key];
765 }
766
767 return nextMethod.apply(this, args);
768 }
769
770 return parseStatement;
771 }();
772 });
773
774 instance.extend('parseExprAtom', function (nextMethod) {
775 return function () {
776 function parseExprAtom(refDestructuringErrors) {
777 if (this.type === tt._import) {
778 return parseDynamicImport.call(this);
779 }
780 return nextMethod.call(this, refDestructuringErrors);
781 }
782
783 return parseExprAtom;
784 }();
785 });
786 }
787
788 return dynamicImportPlugin;
789 }();
790
791 return acorn$$1;
792}
793});
794
795var acornDynamicImport = unwrapExports(inject$1);
796var inject_1 = inject$1.DynamicImportKey;
797
798// used for debugging, without the noise created by
799// circular references
800function toJSON(node) {
801 var obj = {};
802
803 Object.keys(node).forEach(function (key) {
804 if (
805 key === 'parent' ||
806 key === 'program' ||
807 key === 'keys' ||
808 key === '__wrapped'
809 )
810 { return; }
811
812 if (Array.isArray(node[key])) {
813 obj[key] = node[key].map(toJSON);
814 } else if (node[key] && node[key].toJSON) {
815 obj[key] = node[key].toJSON();
816 } else {
817 obj[key] = node[key];
818 }
819 });
820
821 return obj;
822}
823
824var Node = function Node () {};
825
826Node.prototype.ancestor = function ancestor (level) {
827 var node = this;
828 while (level--) {
829 node = node.parent;
830 if (!node) { return null; }
831 }
832
833 return node;
834};
835
836Node.prototype.contains = function contains (node) {
837 var this$1 = this;
838
839 while (node) {
840 if (node === this$1) { return true; }
841 node = node.parent;
842 }
843
844 return false;
845};
846
847Node.prototype.findLexicalBoundary = function findLexicalBoundary () {
848 return this.parent.findLexicalBoundary();
849};
850
851Node.prototype.findNearest = function findNearest (type) {
852 if (typeof type === 'string') { type = new RegExp(("^" + type + "$")); }
853 if (type.test(this.type)) { return this; }
854 return this.parent.findNearest(type);
855};
856
857Node.prototype.unparenthesizedParent = function unparenthesizedParent () {
858 var node = this.parent;
859 while (node && node.type === 'ParenthesizedExpression') {
860 node = node.parent;
861 }
862 return node;
863};
864
865Node.prototype.unparenthesize = function unparenthesize () {
866 var node = this;
867 while (node.type === 'ParenthesizedExpression') {
868 node = node.expression;
869 }
870 return node;
871};
872
873Node.prototype.findScope = function findScope (functionScope) {
874 return this.parent.findScope(functionScope);
875};
876
877Node.prototype.getIndentation = function getIndentation () {
878 return this.parent.getIndentation();
879};
880
881Node.prototype.initialise = function initialise (transforms) {
882 var this$1 = this;
883
884 for (var i = 0, list = this$1.keys; i < list.length; i += 1) {
885 var key = list[i];
886
887 var value = this$1[key];
888
889 if (Array.isArray(value)) {
890 value.forEach(function (node) { return node && node.initialise(transforms); });
891 } else if (value && typeof value === 'object') {
892 value.initialise(transforms);
893 }
894 }
895};
896
897Node.prototype.toJSON = function toJSON$1 () {
898 return toJSON(this);
899};
900
901Node.prototype.toString = function toString () {
902 return this.program.magicString.original.slice(this.start, this.end);
903};
904
905Node.prototype.transpile = function transpile (code, transforms) {
906 var this$1 = this;
907
908 for (var i = 0, list = this$1.keys; i < list.length; i += 1) {
909 var key = list[i];
910
911 var value = this$1[key];
912
913 if (Array.isArray(value)) {
914 value.forEach(function (node) { return node && node.transpile(code, transforms); });
915 } else if (value && typeof value === 'object') {
916 value.transpile(code, transforms);
917 }
918 }
919};
920
921function extractNames(node) {
922 var names = [];
923 extractors[node.type](names, node);
924 return names;
925}
926
927var extractors = {
928 Identifier: function Identifier(names, node) {
929 names.push(node);
930 },
931
932 ObjectPattern: function ObjectPattern(names, node) {
933 for (var i = 0, list = node.properties; i < list.length; i += 1) {
934 var prop = list[i];
935
936 extractors[prop.type](names, prop);
937 }
938 },
939
940 Property: function Property(names, node) {
941 extractors[node.value.type](names, node.value);
942 },
943
944 ArrayPattern: function ArrayPattern(names, node) {
945 for (var i = 0, list = node.elements; i < list.length; i += 1) {
946 var element = list[i];
947
948 if (element) { extractors[element.type](names, element); }
949 }
950 },
951
952 RestElement: function RestElement(names, node) {
953 extractors[node.argument.type](names, node.argument);
954 },
955
956 AssignmentPattern: function AssignmentPattern(names, node) {
957 extractors[node.left.type](names, node.left);
958 }
959};
960
961var reserved = Object.create(null);
962'do if in for let new try var case else enum eval null this true void with await break catch class const false super throw while yield delete export import public return static switch typeof default extends finally package private continue debugger function arguments interface protected implements instanceof'
963 .split(' ')
964 .forEach(function (word) { return (reserved[word] = true); });
965
966function Scope(options) {
967 options = options || {};
968
969 this.parent = options.parent;
970 this.isBlockScope = !!options.block;
971 this.createDeclarationCallback = options.declare;
972
973 var scope = this;
974 while (scope.isBlockScope) { scope = scope.parent; }
975 this.functionScope = scope;
976
977 this.identifiers = [];
978 this.declarations = Object.create(null);
979 this.references = Object.create(null);
980 this.blockScopedDeclarations = this.isBlockScope ? null : Object.create(null);
981 this.aliases = Object.create(null);
982}
983
984Scope.prototype = {
985 addDeclaration: function addDeclaration(node, kind) {
986 var this$1 = this;
987
988 for (var i = 0, list = extractNames(node); i < list.length; i += 1) {
989 var identifier = list[i];
990
991 var name = identifier.name;
992
993 var declaration = { name: name, node: identifier, kind: kind, instances: [] };
994 this$1.declarations[name] = declaration;
995
996 if (this$1.isBlockScope) {
997 if (!this$1.functionScope.blockScopedDeclarations[name])
998 { this$1.functionScope.blockScopedDeclarations[name] = []; }
999 this$1.functionScope.blockScopedDeclarations[name].push(declaration);
1000 }
1001 }
1002 },
1003
1004 addReference: function addReference(identifier) {
1005 if (this.consolidated) {
1006 this.consolidateReference(identifier);
1007 } else {
1008 this.identifiers.push(identifier);
1009 }
1010 },
1011
1012 consolidate: function consolidate() {
1013 var this$1 = this;
1014
1015 for (var i = 0; i < this.identifiers.length; i += 1) {
1016 // we might push to the array during consolidation, so don't cache length
1017 var identifier = this$1.identifiers[i];
1018 this$1.consolidateReference(identifier);
1019 }
1020
1021 this.consolidated = true; // TODO understand why this is necessary... seems bad
1022 },
1023
1024 consolidateReference: function consolidateReference(identifier) {
1025 var declaration = this.declarations[identifier.name];
1026 if (declaration) {
1027 declaration.instances.push(identifier);
1028 } else {
1029 this.references[identifier.name] = true;
1030 if (this.parent) { this.parent.addReference(identifier); }
1031 }
1032 },
1033
1034 contains: function contains(name) {
1035 return (
1036 this.declarations[name] ||
1037 (this.parent ? this.parent.contains(name) : false)
1038 );
1039 },
1040
1041 createIdentifier: function createIdentifier(base) {
1042 if (typeof base === 'number') { base = base.toString(); }
1043
1044 base = base
1045 .replace(/\s/g, '')
1046 .replace(/\[([^\]]+)\]/g, '_$1')
1047 .replace(/[^a-zA-Z0-9_$]/g, '_')
1048 .replace(/_{2,}/, '_');
1049
1050 var name = base;
1051 var counter = 1;
1052
1053 while (
1054 this.declarations[name] ||
1055 this.references[name] ||
1056 this.aliases[name] ||
1057 name in reserved
1058 ) {
1059 name = base + "$" + (counter++);
1060 }
1061
1062 this.aliases[name] = true;
1063 return name;
1064 },
1065
1066 createDeclaration: function createDeclaration(base) {
1067 var id = this.createIdentifier(base);
1068 this.createDeclarationCallback(id);
1069 return id;
1070 },
1071
1072 findDeclaration: function findDeclaration(name) {
1073 return (
1074 this.declarations[name] ||
1075 (this.parent && this.parent.findDeclaration(name))
1076 );
1077 },
1078
1079 // Sometimes, block scope declarations change name during transpilation
1080 resolveName: function resolveName(name) {
1081 var declaration = this.findDeclaration(name);
1082 return declaration ? declaration.name : name;
1083 }
1084};
1085
1086function locate(source, index) {
1087 var lines = source.split('\n');
1088 var len = lines.length;
1089
1090 var lineStart = 0;
1091 var i;
1092
1093 for (i = 0; i < len; i += 1) {
1094 var line = lines[i];
1095 var lineEnd = lineStart + line.length + 1; // +1 for newline
1096
1097 if (lineEnd > index) {
1098 return { line: i + 1, column: index - lineStart, char: i };
1099 }
1100
1101 lineStart = lineEnd;
1102 }
1103
1104 throw new Error('Could not determine location of character');
1105}
1106
1107function pad(num, len) {
1108 var result = String(num);
1109 return result + repeat(' ', len - result.length);
1110}
1111
1112function repeat(str, times) {
1113 var result = '';
1114 while (times--) { result += str; }
1115 return result;
1116}
1117
1118function getSnippet(source, loc, length) {
1119 if ( length === void 0 ) length = 1;
1120
1121 var first = Math.max(loc.line - 5, 0);
1122 var last = loc.line;
1123
1124 var numDigits = String(last).length;
1125
1126 var lines = source.split('\n').slice(first, last);
1127
1128 var lastLine = lines[lines.length - 1];
1129 var offset = lastLine.slice(0, loc.column).replace(/\t/g, ' ').length;
1130
1131 var snippet = lines
1132 .map(function (line, i) { return ((pad(i + first + 1, numDigits)) + " : " + (line.replace(/\t/g, ' '))); })
1133 .join('\n');
1134
1135 snippet += '\n' + repeat(' ', numDigits + 3 + offset) + repeat('^', length);
1136
1137 return snippet;
1138}
1139
1140var CompileError = (function (Error) {
1141 function CompileError(message, node) {
1142 Error.call(this, message);
1143
1144 this.name = 'CompileError';
1145 if (!node) {
1146 return;
1147 }
1148
1149 var source = node.program.magicString.original;
1150 var loc = locate(source, node.start);
1151
1152 this.message = message + " (" + (loc.line) + ":" + (loc.column) + ")";
1153
1154 this.stack = new Error().stack.replace(
1155 new RegExp((".+new " + (this.name) + ".+\\n"), 'm'),
1156 ''
1157 );
1158
1159 this.loc = loc;
1160 this.snippet = getSnippet(source, loc, node.end - node.start);
1161 }
1162
1163 if ( Error ) CompileError.__proto__ = Error;
1164 CompileError.prototype = Object.create( Error && Error.prototype );
1165 CompileError.prototype.constructor = CompileError;
1166
1167 CompileError.prototype.toString = function toString () {
1168 return ((this.name) + ": " + (this.message) + "\n" + (this.snippet));
1169 };
1170
1171 return CompileError;
1172}(Error));
1173
1174function findIndex(array, fn) {
1175 for (var i = 0; i < array.length; i += 1) {
1176 if (fn(array[i], i)) { return i; }
1177 }
1178
1179 return -1;
1180}
1181
1182var handlers = {
1183 Identifier: destructureIdentifier,
1184 AssignmentPattern: destructureAssignmentPattern,
1185 ArrayPattern: destructureArrayPattern,
1186 ObjectPattern: destructureObjectPattern
1187};
1188
1189function destructure(
1190 code,
1191 createIdentifier,
1192 resolveName,
1193 node,
1194 ref,
1195 inline,
1196 statementGenerators
1197) {
1198 handlers[node.type](code, createIdentifier, resolveName, node, ref, inline, statementGenerators);
1199}
1200
1201function destructureIdentifier(
1202 code,
1203 createIdentifier,
1204 resolveName,
1205 node,
1206 ref,
1207 inline,
1208 statementGenerators
1209) {
1210 statementGenerators.push(function (start, prefix, suffix) {
1211 code.overwrite(node.start, node.end, (inline ? prefix : (prefix + "var ")) + resolveName(node) + " = " + ref + suffix);
1212 code.move(node.start, node.end, start);
1213 });
1214}
1215
1216function destructureMemberExpression(
1217 code,
1218 createIdentifier,
1219 resolveName,
1220 node,
1221 ref,
1222 inline,
1223 statementGenerators
1224) {
1225 statementGenerators.push(function (start, prefix, suffix) {
1226 code.prependRight(node.start, inline ? prefix : (prefix + "var "));
1227 code.appendLeft(node.end, (" = " + ref + suffix));
1228 code.move(node.start, node.end, start);
1229 });
1230}
1231
1232function destructureAssignmentPattern(
1233 code,
1234 createIdentifier,
1235 resolveName,
1236 node,
1237 ref,
1238 inline,
1239 statementGenerators
1240) {
1241 var isIdentifier = node.left.type === 'Identifier';
1242 var name = isIdentifier ? node.left.name : ref;
1243
1244 if (!inline) {
1245 statementGenerators.push(function (start, prefix, suffix) {
1246 code.prependRight(
1247 node.left.end,
1248 (prefix + "if ( " + name + " === void 0 ) " + name)
1249 );
1250 code.move(node.left.end, node.right.end, start);
1251 code.appendLeft(node.right.end, suffix);
1252 });
1253 }
1254
1255 if (!isIdentifier) {
1256 destructure(code, createIdentifier, resolveName, node.left, ref, inline, statementGenerators);
1257 }
1258}
1259
1260function destructureArrayPattern(
1261 code,
1262 createIdentifier,
1263 resolveName,
1264 node,
1265 ref,
1266 inline,
1267 statementGenerators
1268) {
1269 var c = node.start;
1270
1271 node.elements.forEach(function (element, i) {
1272 if (!element) { return; }
1273
1274 if (element.type === 'RestElement') {
1275 handleProperty(
1276 code,
1277 createIdentifier,
1278 resolveName,
1279 c,
1280 element.argument,
1281 (ref + ".slice(" + i + ")"),
1282 inline,
1283 statementGenerators
1284 );
1285 } else {
1286 handleProperty(
1287 code,
1288 createIdentifier,
1289 resolveName,
1290 c,
1291 element,
1292 (ref + "[" + i + "]"),
1293 inline,
1294 statementGenerators
1295 );
1296 }
1297 c = element.end;
1298 });
1299
1300 code.remove(c, node.end);
1301}
1302
1303function destructureObjectPattern(
1304 code,
1305 createIdentifier,
1306 resolveName,
1307 node,
1308 ref,
1309 inline,
1310 statementGenerators
1311) {
1312 var this$1 = this;
1313
1314 var c = node.start;
1315
1316 var nonRestKeys = [];
1317 node.properties.forEach(function (prop) {
1318 var value;
1319 var content;
1320 if (prop.type === 'Property') {
1321 var isComputedKey = prop.computed || prop.key.type !== 'Identifier';
1322 var key = isComputedKey
1323 ? code.slice(prop.key.start, prop.key.end)
1324 : prop.key.name;
1325 value = isComputedKey ? (ref + "[" + key + "]") : (ref + "." + key);
1326 content = prop.value;
1327 nonRestKeys.push(isComputedKey ? key : '"' + key + '"');
1328 } else if (prop.type === 'RestElement') {
1329 content = prop.argument;
1330 value = createIdentifier('rest');
1331 statementGenerators.push(function (start, prefix, suffix) {
1332 var helper = prop.program.getObjectWithoutPropertiesHelper(code);
1333 code.overwrite(
1334 prop.start,
1335 (c = prop.argument.start),
1336 (inline ? prefix : (prefix + "var ")) + value + " = " + helper + "( " + ref + ", [" + (nonRestKeys.join(', ')) + "] )" + suffix
1337 );
1338 code.move(prop.start, c, start);
1339 });
1340 } else {
1341 throw new CompileError(
1342 this$1,
1343 ("Unexpected node of type " + (prop.type) + " in object pattern")
1344 );
1345 }
1346 handleProperty(code, createIdentifier, resolveName, c, content, value, inline, statementGenerators);
1347 c = prop.end;
1348 });
1349
1350 code.remove(c, node.end);
1351}
1352
1353function handleProperty(
1354 code,
1355 createIdentifier,
1356 resolveName,
1357 c,
1358 node,
1359 value,
1360 inline,
1361 statementGenerators
1362) {
1363 switch (node.type) {
1364 case 'Identifier': {
1365 code.remove(c, node.start);
1366 destructureIdentifier(
1367 code,
1368 createIdentifier,
1369 resolveName,
1370 node,
1371 value,
1372 inline,
1373 statementGenerators
1374 );
1375 break;
1376 }
1377
1378 case 'MemberExpression':
1379 code.remove(c, node.start);
1380 destructureMemberExpression(
1381 code,
1382 createIdentifier,
1383 resolveName,
1384 node,
1385 value,
1386 true,
1387 statementGenerators
1388 );
1389 break;
1390
1391 case 'AssignmentPattern': {
1392 var name;
1393
1394 var isIdentifier = node.left.type === 'Identifier';
1395
1396 if (isIdentifier) {
1397 name = resolveName(node.left);
1398 } else {
1399 name = createIdentifier(value);
1400 }
1401
1402 statementGenerators.push(function (start, prefix, suffix) {
1403 if (inline) {
1404 code.prependRight(
1405 node.right.start,
1406 (name + " = " + value + ", " + name + " = " + name + " === void 0 ? ")
1407 );
1408 code.appendLeft(node.right.end, (" : " + name + suffix));
1409 } else {
1410 code.prependRight(
1411 node.right.start,
1412 (prefix + "var " + name + " = " + value + "; if ( " + name + " === void 0 ) " + name + " = ")
1413 );
1414 code.appendLeft(node.right.end, suffix);
1415 }
1416
1417 code.move(node.right.start, node.right.end, start);
1418 });
1419
1420 if (isIdentifier) {
1421 code.remove(c, node.right.start);
1422 } else {
1423 code.remove(c, node.left.start);
1424 code.remove(node.left.end, node.right.start);
1425 handleProperty(
1426 code,
1427 createIdentifier,
1428 resolveName,
1429 c,
1430 node.left,
1431 name,
1432 inline,
1433 statementGenerators
1434 );
1435 }
1436
1437 break;
1438 }
1439
1440 case 'ObjectPattern': {
1441 code.remove(c, (c = node.start));
1442
1443 var ref = value;
1444 if (node.properties.length > 1) {
1445 ref = createIdentifier(value);
1446
1447 statementGenerators.push(function (start, prefix, suffix) {
1448 // this feels a tiny bit hacky, but we can't do a
1449 // straightforward appendLeft and keep correct order...
1450 code.prependRight(node.start, (inline ? '' : (prefix + "var ")) + ref + " = ");
1451 code.overwrite(node.start, (c = node.start + 1), value);
1452 code.appendLeft(c, suffix);
1453
1454 code.overwrite(
1455 node.start,
1456 (c = node.start + 1),
1457 (inline ? '' : (prefix + "var ")) + ref + " = " + value + suffix
1458 );
1459 code.move(node.start, c, start);
1460 });
1461 }
1462
1463 destructureObjectPattern(
1464 code,
1465 createIdentifier,
1466 resolveName,
1467 node,
1468 ref,
1469 inline,
1470 statementGenerators
1471 );
1472
1473 break;
1474 }
1475
1476 case 'ArrayPattern': {
1477 code.remove(c, (c = node.start));
1478
1479 if (node.elements.filter(Boolean).length > 1) {
1480 var ref$1 = createIdentifier(value);
1481
1482 statementGenerators.push(function (start, prefix, suffix) {
1483 code.prependRight(node.start, (inline ? '' : (prefix + "var ")) + ref$1 + " = ");
1484 code.overwrite(node.start, (c = node.start + 1), value, {
1485 contentOnly: true
1486 });
1487 code.appendLeft(c, suffix);
1488
1489 code.move(node.start, c, start);
1490 });
1491
1492 node.elements.forEach(function (element, i) {
1493 if (!element) { return; }
1494
1495 if (element.type === 'RestElement') {
1496 handleProperty(
1497 code,
1498 createIdentifier,
1499 resolveName,
1500 c,
1501 element.argument,
1502 (ref$1 + ".slice(" + i + ")"),
1503 inline,
1504 statementGenerators
1505 );
1506 } else {
1507 handleProperty(
1508 code,
1509 createIdentifier,
1510 resolveName,
1511 c,
1512 element,
1513 (ref$1 + "[" + i + "]"),
1514 inline,
1515 statementGenerators
1516 );
1517 }
1518 c = element.end;
1519 });
1520 } else {
1521 var index = findIndex(node.elements, Boolean);
1522 var element = node.elements[index];
1523 if (element.type === 'RestElement') {
1524 handleProperty(
1525 code,
1526 createIdentifier,
1527 resolveName,
1528 c,
1529 element.argument,
1530 (value + ".slice(" + index + ")"),
1531 inline,
1532 statementGenerators
1533 );
1534 } else {
1535 handleProperty(
1536 code,
1537 createIdentifier,
1538 resolveName,
1539 c,
1540 element,
1541 (value + "[" + index + "]"),
1542 inline,
1543 statementGenerators
1544 );
1545 }
1546 c = element.end;
1547 }
1548
1549 code.remove(c, node.end);
1550 break;
1551 }
1552
1553 default: {
1554 throw new Error(("Unexpected node type in destructuring (" + (node.type) + ")"));
1555 }
1556 }
1557}
1558
1559function isUseStrict(node) {
1560 if (!node) { return false; }
1561 if (node.type !== 'ExpressionStatement') { return false; }
1562 if (node.expression.type !== 'Literal') { return false; }
1563 return node.expression.value === 'use strict';
1564}
1565
1566var BlockStatement = (function (Node$$1) {
1567 function BlockStatement () {
1568 Node$$1.apply(this, arguments);
1569 }
1570
1571 if ( Node$$1 ) BlockStatement.__proto__ = Node$$1;
1572 BlockStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
1573 BlockStatement.prototype.constructor = BlockStatement;
1574
1575 BlockStatement.prototype.createScope = function createScope () {
1576 var this$1 = this;
1577
1578 this.parentIsFunction = /Function/.test(this.parent.type);
1579 this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root';
1580 this.scope = new Scope({
1581 block: !this.isFunctionBlock,
1582 parent: this.parent.findScope(false),
1583 declare: function (id) { return this$1.createdDeclarations.push(id); }
1584 });
1585
1586 if (this.parentIsFunction) {
1587 this.parent.params.forEach(function (node) {
1588 this$1.scope.addDeclaration(node, 'param');
1589 });
1590 }
1591 };
1592
1593 BlockStatement.prototype.initialise = function initialise (transforms) {
1594 this.thisAlias = null;
1595 this.argumentsAlias = null;
1596 this.defaultParameters = [];
1597 this.createdDeclarations = [];
1598
1599 // normally the scope gets created here, during initialisation,
1600 // but in some cases (e.g. `for` statements), we need to create
1601 // the scope early, as it pertains to both the init block and
1602 // the body of the statement
1603 if (!this.scope) { this.createScope(); }
1604
1605 this.body.forEach(function (node) { return node.initialise(transforms); });
1606
1607 this.scope.consolidate();
1608 };
1609
1610 BlockStatement.prototype.findLexicalBoundary = function findLexicalBoundary () {
1611 if (this.type === 'Program') { return this; }
1612 if (/^Function/.test(this.parent.type)) { return this; }
1613
1614 return this.parent.findLexicalBoundary();
1615 };
1616
1617 BlockStatement.prototype.findScope = function findScope (functionScope) {
1618 if (functionScope && !this.isFunctionBlock)
1619 { return this.parent.findScope(functionScope); }
1620 return this.scope;
1621 };
1622
1623 BlockStatement.prototype.getArgumentsAlias = function getArgumentsAlias () {
1624 if (!this.argumentsAlias) {
1625 this.argumentsAlias = this.scope.createIdentifier('arguments');
1626 }
1627
1628 return this.argumentsAlias;
1629 };
1630
1631 BlockStatement.prototype.getArgumentsArrayAlias = function getArgumentsArrayAlias () {
1632 if (!this.argumentsArrayAlias) {
1633 this.argumentsArrayAlias = this.scope.createIdentifier('argsArray');
1634 }
1635
1636 return this.argumentsArrayAlias;
1637 };
1638
1639 BlockStatement.prototype.getThisAlias = function getThisAlias () {
1640 if (!this.thisAlias) {
1641 this.thisAlias = this.scope.createIdentifier('this');
1642 }
1643
1644 return this.thisAlias;
1645 };
1646
1647 BlockStatement.prototype.getIndentation = function getIndentation () {
1648 var this$1 = this;
1649
1650 if (this.indentation === undefined) {
1651 var source = this.program.magicString.original;
1652
1653 var useOuter = this.synthetic || !this.body.length;
1654 var c = useOuter ? this.start : this.body[0].start;
1655
1656 while (c && source[c] !== '\n') { c -= 1; }
1657
1658 this.indentation = '';
1659
1660 // eslint-disable-next-line no-constant-condition
1661 while (true) {
1662 c += 1;
1663 var char = source[c];
1664
1665 if (char !== ' ' && char !== '\t') { break; }
1666
1667 this$1.indentation += char;
1668 }
1669
1670 var indentString = this.program.magicString.getIndentString();
1671
1672 // account for dedented class constructors
1673 var parent = this.parent;
1674 while (parent) {
1675 if (parent.kind === 'constructor' && !parent.parent.parent.superClass) {
1676 this$1.indentation = this$1.indentation.replace(indentString, '');
1677 }
1678
1679 parent = parent.parent;
1680 }
1681
1682 if (useOuter) { this.indentation += indentString; }
1683 }
1684
1685 return this.indentation;
1686 };
1687
1688 BlockStatement.prototype.transpile = function transpile (code, transforms) {
1689 var this$1 = this;
1690
1691 var indentation = this.getIndentation();
1692
1693 var introStatementGenerators = [];
1694
1695 if (this.argumentsAlias) {
1696 introStatementGenerators.push(function (start, prefix, suffix) {
1697 var assignment = prefix + "var " + (this$1.argumentsAlias) + " = arguments" + suffix;
1698 code.appendLeft(start, assignment);
1699 });
1700 }
1701
1702 if (this.thisAlias) {
1703 introStatementGenerators.push(function (start, prefix, suffix) {
1704 var assignment = prefix + "var " + (this$1.thisAlias) + " = this" + suffix;
1705 code.appendLeft(start, assignment);
1706 });
1707 }
1708
1709 if (this.argumentsArrayAlias) {
1710 introStatementGenerators.push(function (start, prefix, suffix) {
1711 var i = this$1.scope.createIdentifier('i');
1712 var assignment = prefix + "var " + i + " = arguments.length, " + (this$1.argumentsArrayAlias) + " = Array(" + i + ");\n" + indentation + "while ( " + i + "-- ) " + (this$1.argumentsArrayAlias) + "[" + i + "] = arguments[" + i + "]" + suffix;
1713 code.appendLeft(start, assignment);
1714 });
1715 }
1716
1717 if (/Function/.test(this.parent.type)) {
1718 this.transpileParameters(
1719 this.parent.params,
1720 code,
1721 transforms,
1722 indentation,
1723 introStatementGenerators
1724 );
1725 } else if ('CatchClause' === this.parent.type) {
1726 this.transpileParameters(
1727 [this.parent.param],
1728 code,
1729 transforms,
1730 indentation,
1731 introStatementGenerators
1732 );
1733 }
1734
1735 if (transforms.letConst && this.isFunctionBlock) {
1736 this.transpileBlockScopedIdentifiers(code);
1737 }
1738
1739 Node$$1.prototype.transpile.call(this, code, transforms);
1740
1741 if (this.createdDeclarations.length) {
1742 introStatementGenerators.push(function (start, prefix, suffix) {
1743 var assignment = prefix + "var " + (this$1.createdDeclarations.join(', ')) + suffix;
1744 code.appendLeft(start, assignment);
1745 });
1746 }
1747
1748 if (this.synthetic) {
1749 if (this.parent.type === 'ArrowFunctionExpression') {
1750 var expr = this.body[0];
1751
1752 if (introStatementGenerators.length) {
1753 code
1754 .appendLeft(this.start, "{")
1755 .prependRight(this.end, ((this.parent.getIndentation()) + "}"));
1756
1757 code.prependRight(expr.start, ("\n" + indentation + "return "));
1758 code.appendLeft(expr.end, ";\n");
1759 } else if (transforms.arrow) {
1760 code.prependRight(expr.start, "{ return ");
1761 code.appendLeft(expr.end, "; }");
1762 }
1763 } else if (introStatementGenerators.length) {
1764 code.prependRight(this.start, "{").appendLeft(this.end, "}");
1765 }
1766 }
1767
1768 var start;
1769 if (isUseStrict(this.body[0])) {
1770 start = this.body[0].end;
1771 } else if (this.synthetic || this.parent.type === 'Root') {
1772 start = this.start;
1773 } else {
1774 start = this.start + 1;
1775 }
1776
1777 var prefix = "\n" + indentation;
1778 var suffix = ';';
1779 introStatementGenerators.forEach(function (fn, i) {
1780 if (i === introStatementGenerators.length - 1) { suffix = ";\n"; }
1781 fn(start, prefix, suffix);
1782 });
1783 };
1784
1785 BlockStatement.prototype.transpileParameters = function transpileParameters (params, code, transforms, indentation, introStatementGenerators) {
1786 var this$1 = this;
1787
1788 params.forEach(function (param) {
1789 if (
1790 param.type === 'AssignmentPattern' &&
1791 param.left.type === 'Identifier'
1792 ) {
1793 if (transforms.defaultParameter) {
1794 introStatementGenerators.push(function (start, prefix, suffix) {
1795 var lhs = prefix + "if ( " + (param.left.name) + " === void 0 ) " + (param.left.name);
1796
1797 code
1798 .prependRight(param.left.end, lhs)
1799 .move(param.left.end, param.right.end, start)
1800 .appendLeft(param.right.end, suffix);
1801 });
1802 }
1803 } else if (param.type === 'RestElement') {
1804 if (transforms.spreadRest) {
1805 introStatementGenerators.push(function (start, prefix, suffix) {
1806 var penultimateParam = params[params.length - 2];
1807
1808 if (penultimateParam) {
1809 code.remove(
1810 penultimateParam ? penultimateParam.end : param.start,
1811 param.end
1812 );
1813 } else {
1814 var start$1 = param.start,
1815 end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8
1816
1817 while (/\s/.test(code.original[start$1 - 1])) { start$1 -= 1; }
1818 while (/\s/.test(code.original[end])) { end += 1; }
1819
1820 code.remove(start$1, end);
1821 }
1822
1823 var name = param.argument.name;
1824 var len = this$1.scope.createIdentifier('len');
1825 var count = params.length - 1;
1826
1827 if (count) {
1828 code.prependRight(
1829 start,
1830 (prefix + "var " + name + " = [], " + len + " = arguments.length - " + count + ";\n" + indentation + "while ( " + len + "-- > 0 ) " + name + "[ " + len + " ] = arguments[ " + len + " + " + count + " ]" + suffix)
1831 );
1832 } else {
1833 code.prependRight(
1834 start,
1835 (prefix + "var " + name + " = [], " + len + " = arguments.length;\n" + indentation + "while ( " + len + "-- ) " + name + "[ " + len + " ] = arguments[ " + len + " ]" + suffix)
1836 );
1837 }
1838 });
1839 }
1840 } else if (param.type !== 'Identifier') {
1841 if (transforms.parameterDestructuring) {
1842 var ref = this$1.scope.createIdentifier('ref');
1843 destructure(
1844 code,
1845 function (id) { return this$1.scope.createIdentifier(id); },
1846 function (ref) {
1847 var name = ref.name;
1848
1849 return this$1.scope.resolveName(name);
1850 },
1851 param,
1852 ref,
1853 false,
1854 introStatementGenerators
1855 );
1856 code.prependRight(param.start, ref);
1857 }
1858 }
1859 });
1860 };
1861
1862 BlockStatement.prototype.transpileBlockScopedIdentifiers = function transpileBlockScopedIdentifiers (code) {
1863 var this$1 = this;
1864
1865 Object.keys(this.scope.blockScopedDeclarations).forEach(function (name) {
1866 var declarations = this$1.scope.blockScopedDeclarations[name];
1867
1868 for (var i$2 = 0, list$2 = declarations; i$2 < list$2.length; i$2 += 1) {
1869 var declaration = list$2[i$2];
1870
1871 var cont = false; // TODO implement proper continue...
1872
1873 if (declaration.kind === 'for.let') {
1874 // special case
1875 var forStatement = declaration.node.findNearest('ForStatement');
1876
1877 if (forStatement.shouldRewriteAsFunction) {
1878 var outerAlias = this$1.scope.createIdentifier(name);
1879 var innerAlias = forStatement.reassigned[name]
1880 ? this$1.scope.createIdentifier(name)
1881 : name;
1882
1883 declaration.name = outerAlias;
1884 code.overwrite(
1885 declaration.node.start,
1886 declaration.node.end,
1887 outerAlias,
1888 { storeName: true }
1889 );
1890
1891 forStatement.aliases[name] = {
1892 outer: outerAlias,
1893 inner: innerAlias
1894 };
1895
1896 for (var i = 0, list = declaration.instances; i < list.length; i += 1) {
1897 var identifier = list[i];
1898
1899 var alias = forStatement.body.contains(identifier)
1900 ? innerAlias
1901 : outerAlias;
1902
1903 if (name !== alias) {
1904 code.overwrite(identifier.start, identifier.end, alias, {
1905 storeName: true
1906 });
1907 }
1908 }
1909
1910 cont = true;
1911 }
1912 }
1913
1914 if (!cont) {
1915 var alias$1 = this$1.scope.createIdentifier(name);
1916
1917 if (name !== alias$1) {
1918 declaration.name = alias$1;
1919 code.overwrite(
1920 declaration.node.start,
1921 declaration.node.end,
1922 alias$1,
1923 { storeName: true }
1924 );
1925
1926 for (var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1) {
1927 var identifier$1 = list$1[i$1];
1928
1929 identifier$1.rewritten = true;
1930 code.overwrite(identifier$1.start, identifier$1.end, alias$1, {
1931 storeName: true
1932 });
1933 }
1934 }
1935 }
1936 }
1937 });
1938 };
1939
1940 return BlockStatement;
1941}(Node));
1942
1943function isArguments(node) {
1944 return node.type === 'Identifier' && node.name === 'arguments';
1945}
1946
1947function spread(
1948 code,
1949 elements,
1950 start,
1951 argumentsArrayAlias,
1952 isNew
1953) {
1954 var i = elements.length;
1955 var firstSpreadIndex = -1;
1956
1957 while (i--) {
1958 var element$1 = elements[i];
1959 if (element$1 && element$1.type === 'SpreadElement') {
1960 if (isArguments(element$1.argument)) {
1961 code.overwrite(
1962 element$1.argument.start,
1963 element$1.argument.end,
1964 argumentsArrayAlias
1965 );
1966 }
1967
1968 firstSpreadIndex = i;
1969 }
1970 }
1971
1972 if (firstSpreadIndex === -1) { return false; } // false indicates no spread elements
1973
1974 if (isNew) {
1975 for (i = 0; i < elements.length; i += 1) {
1976 var element$2 = elements[i];
1977 if (element$2.type === 'SpreadElement') {
1978 code.remove(element$2.start, element$2.argument.start);
1979 } else {
1980 code.prependRight(element$2.start, '[');
1981 code.prependRight(element$2.end, ']');
1982 }
1983 }
1984
1985 return true; // true indicates some spread elements
1986 }
1987
1988 var element = elements[firstSpreadIndex];
1989 var previousElement = elements[firstSpreadIndex - 1];
1990
1991 if (!previousElement) {
1992 code.remove(start, element.start);
1993 code.overwrite(element.end, elements[1].start, '.concat( ');
1994 } else {
1995 code.overwrite(previousElement.end, element.start, ' ].concat( ');
1996 }
1997
1998 for (i = firstSpreadIndex; i < elements.length; i += 1) {
1999 element = elements[i];
2000
2001 if (element) {
2002 if (element.type === 'SpreadElement') {
2003 code.remove(element.start, element.argument.start);
2004 } else {
2005 code.appendLeft(element.start, '[');
2006 code.appendLeft(element.end, ']');
2007 }
2008 }
2009 }
2010
2011 return true; // true indicates some spread elements
2012}
2013
2014var ArrayExpression = (function (Node$$1) {
2015 function ArrayExpression () {
2016 Node$$1.apply(this, arguments);
2017 }
2018
2019 if ( Node$$1 ) ArrayExpression.__proto__ = Node$$1;
2020 ArrayExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
2021 ArrayExpression.prototype.constructor = ArrayExpression;
2022
2023 ArrayExpression.prototype.initialise = function initialise (transforms) {
2024 var this$1 = this;
2025
2026 if (transforms.spreadRest && this.elements.length) {
2027 var lexicalBoundary = this.findLexicalBoundary();
2028
2029 var i = this.elements.length;
2030 while (i--) {
2031 var element = this$1.elements[i];
2032 if (
2033 element &&
2034 element.type === 'SpreadElement' &&
2035 isArguments(element.argument)
2036 ) {
2037 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
2038 }
2039 }
2040 }
2041
2042 Node$$1.prototype.initialise.call(this, transforms);
2043 };
2044
2045 ArrayExpression.prototype.transpile = function transpile (code, transforms) {
2046 Node$$1.prototype.transpile.call(this, code, transforms);
2047
2048 if (transforms.spreadRest) {
2049 // erase trailing comma after last array element if not an array hole
2050 if (this.elements.length) {
2051 var lastElement = this.elements[this.elements.length - 1];
2052 if (
2053 lastElement &&
2054 /\s*,/.test(code.original.slice(lastElement.end, this.end))
2055 ) {
2056 code.overwrite(lastElement.end, this.end - 1, ' ');
2057 }
2058 }
2059
2060 if (this.elements.length === 1) {
2061 var element = this.elements[0];
2062
2063 if (element && element.type === 'SpreadElement') {
2064 // special case – [ ...arguments ]
2065 if (isArguments(element.argument)) {
2066 code.overwrite(
2067 this.start,
2068 this.end,
2069 ("[].concat( " + (this.argumentsArrayAlias) + " )")
2070 ); // TODO if this is the only use of argsArray, don't bother concating
2071 } else {
2072 code.overwrite(this.start, element.argument.start, '[].concat( ');
2073 code.overwrite(element.end, this.end, ' )');
2074 }
2075 }
2076 } else {
2077 var hasSpreadElements = spread(
2078 code,
2079 this.elements,
2080 this.start,
2081 this.argumentsArrayAlias
2082 );
2083
2084 if (hasSpreadElements) {
2085 code.overwrite(this.end - 1, this.end, ')');
2086 }
2087 }
2088 }
2089 };
2090
2091 return ArrayExpression;
2092}(Node));
2093
2094function removeTrailingComma(code, c) {
2095 while (code.original[c] !== ')') {
2096 if (code.original[c] === ',') {
2097 code.remove(c, c + 1);
2098 return;
2099 }
2100
2101 if (code.original[c] === '/') {
2102 c = code.original.indexOf(code.original[c + 1] === '/' ? '\n' : '*/', c) + 1;
2103 }
2104 c += 1;
2105 }
2106}
2107
2108var ArrowFunctionExpression = (function (Node$$1) {
2109 function ArrowFunctionExpression () {
2110 Node$$1.apply(this, arguments);
2111 }
2112
2113 if ( Node$$1 ) ArrowFunctionExpression.__proto__ = Node$$1;
2114 ArrowFunctionExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
2115 ArrowFunctionExpression.prototype.constructor = ArrowFunctionExpression;
2116
2117 ArrowFunctionExpression.prototype.initialise = function initialise (transforms) {
2118 this.body.createScope();
2119 Node$$1.prototype.initialise.call(this, transforms);
2120 };
2121
2122 ArrowFunctionExpression.prototype.transpile = function transpile (code, transforms) {
2123 var naked = this.params.length === 1 && this.start === this.params[0].start;
2124
2125 if (transforms.arrow || this.needsArguments(transforms)) {
2126 // remove arrow
2127 var charIndex = this.body.start;
2128 while (code.original[charIndex] !== '=') {
2129 charIndex -= 1;
2130 }
2131 code.remove(charIndex, this.body.start);
2132
2133 Node$$1.prototype.transpile.call(this, code, transforms);
2134
2135 // wrap naked parameter
2136 if (naked) {
2137 code.prependRight(this.params[0].start, '(');
2138 code.appendLeft(this.params[0].end, ')');
2139 }
2140
2141 // add function
2142 if (this.parent && this.parent.type === 'ExpressionStatement') {
2143 // standalone expression statement
2144 code.prependRight(this.start, '!function');
2145 } else {
2146 code.prependRight(this.start, 'function ');
2147 }
2148 } else {
2149 Node$$1.prototype.transpile.call(this, code, transforms);
2150 }
2151
2152 if (transforms.trailingFunctionCommas && this.params.length && !naked) {
2153 removeTrailingComma(code, this.params[this.params.length - 1].end);
2154 }
2155 };
2156
2157 // Returns whether any transforms that will happen use `arguments`
2158 ArrowFunctionExpression.prototype.needsArguments = function needsArguments (transforms) {
2159 return (
2160 transforms.spreadRest &&
2161 this.params.filter(function (param) { return param.type === 'RestElement'; }).length > 0
2162 );
2163 };
2164
2165 return ArrowFunctionExpression;
2166}(Node));
2167
2168function checkConst(identifier, scope) {
2169 var declaration = scope.findDeclaration(identifier.name);
2170 if (declaration && declaration.kind === 'const') {
2171 throw new CompileError(((identifier.name) + " is read-only"), identifier);
2172 }
2173}
2174
2175var AssignmentExpression = (function (Node$$1) {
2176 function AssignmentExpression () {
2177 Node$$1.apply(this, arguments);
2178 }
2179
2180 if ( Node$$1 ) AssignmentExpression.__proto__ = Node$$1;
2181 AssignmentExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
2182 AssignmentExpression.prototype.constructor = AssignmentExpression;
2183
2184 AssignmentExpression.prototype.initialise = function initialise (transforms) {
2185 if (this.left.type === 'Identifier') {
2186 var declaration = this.findScope(false).findDeclaration(this.left.name);
2187 // special case – https://gitlab.com/Rich-Harris/buble/issues/11
2188 var statement = declaration && declaration.node.ancestor(3);
2189 if (
2190 statement &&
2191 statement.type === 'ForStatement' &&
2192 statement.body.contains(this)
2193 ) {
2194 statement.reassigned[this.left.name] = true;
2195 }
2196 }
2197
2198 Node$$1.prototype.initialise.call(this, transforms);
2199 };
2200
2201 AssignmentExpression.prototype.transpile = function transpile (code, transforms) {
2202 if (this.left.type === 'Identifier') {
2203 // Do this check after everything has been initialized to find
2204 // shadowing declarations after this expression
2205 checkConst(this.left, this.findScope(false));
2206 }
2207
2208 if (this.operator === '**=' && transforms.exponentiation) {
2209 this.transpileExponentiation(code, transforms);
2210 } else if (/Pattern/.test(this.left.type) && transforms.destructuring) {
2211 this.transpileDestructuring(code, transforms);
2212 }
2213
2214 Node$$1.prototype.transpile.call(this, code, transforms);
2215 };
2216
2217 AssignmentExpression.prototype.transpileDestructuring = function transpileDestructuring (code) {
2218 var this$1 = this;
2219
2220 var writeScope = this.findScope(true);
2221 var lookupScope = this.findScope(false);
2222 var assign = writeScope.createDeclaration('assign');
2223 code.appendRight(this.left.end, ("(" + assign));
2224
2225 code.appendLeft(this.right.end, ', ');
2226 var statementGenerators = [];
2227 destructure(
2228 code,
2229 function (id) { return writeScope.createDeclaration(id); },
2230 function (node) {
2231 var name = lookupScope.resolveName(node.name);
2232 checkConst(node, lookupScope);
2233 return name;
2234 },
2235 this.left,
2236 assign,
2237 true,
2238 statementGenerators
2239 );
2240
2241 var suffix = ', ';
2242 statementGenerators.forEach(function (fn, j) {
2243 if (j === statementGenerators.length - 1) {
2244 suffix = '';
2245 }
2246
2247 fn(this$1.end, '', suffix);
2248 });
2249
2250 if (this.unparenthesizedParent().type === 'ExpressionStatement') {
2251 // no rvalue needed for expression statement
2252 code.appendRight(this.end, ")");
2253 } else {
2254 // destructuring is part of an expression - need an rvalue
2255 code.appendRight(this.end, (", " + assign + ")"));
2256 }
2257 };
2258
2259 AssignmentExpression.prototype.transpileExponentiation = function transpileExponentiation (code) {
2260 var scope = this.findScope(false);
2261
2262 // first, the easy part – `**=` -> `=`
2263 var charIndex = this.left.end;
2264 while (code.original[charIndex] !== '*') { charIndex += 1; }
2265 code.remove(charIndex, charIndex + 2);
2266
2267 // how we do the next part depends on a number of factors – whether
2268 // this is a top-level statement, and whether we're updating a
2269 // simple or complex reference
2270 var base;
2271
2272 var left = this.left.unparenthesize();
2273
2274 if (left.type === 'Identifier') {
2275 base = scope.resolveName(left.name);
2276 } else if (left.type === 'MemberExpression') {
2277 var object;
2278 var needsObjectVar = false;
2279 var property;
2280 var needsPropertyVar = false;
2281
2282 var statement = this.findNearest(/(?:Statement|Declaration)$/);
2283 var i0 = statement.getIndentation();
2284
2285 if (left.property.type === 'Identifier') {
2286 property = left.computed
2287 ? scope.resolveName(left.property.name)
2288 : left.property.name;
2289 } else {
2290 property = scope.createDeclaration('property');
2291 needsPropertyVar = true;
2292 }
2293
2294 if (left.object.type === 'Identifier') {
2295 object = scope.resolveName(left.object.name);
2296 } else {
2297 object = scope.createDeclaration('object');
2298 needsObjectVar = true;
2299 }
2300
2301 if (left.start === statement.start) {
2302 if (needsObjectVar && needsPropertyVar) {
2303 code.prependRight(statement.start, (object + " = "));
2304 code.overwrite(
2305 left.object.end,
2306 left.property.start,
2307 (";\n" + i0 + property + " = ")
2308 );
2309 code.overwrite(
2310 left.property.end,
2311 left.end,
2312 (";\n" + i0 + object + "[" + property + "]")
2313 );
2314 } else if (needsObjectVar) {
2315 code.prependRight(statement.start, (object + " = "));
2316 code.appendLeft(left.object.end, (";\n" + i0));
2317 code.appendLeft(left.object.end, object);
2318 } else if (needsPropertyVar) {
2319 code.prependRight(left.property.start, (property + " = "));
2320 code.appendLeft(left.property.end, (";\n" + i0));
2321 code.move(left.property.start, left.property.end, this.start);
2322
2323 code.appendLeft(left.object.end, ("[" + property + "]"));
2324 code.remove(left.object.end, left.property.start);
2325 code.remove(left.property.end, left.end);
2326 }
2327 } else {
2328 if (needsObjectVar && needsPropertyVar) {
2329 code.prependRight(left.start, ("( " + object + " = "));
2330 code.overwrite(
2331 left.object.end,
2332 left.property.start,
2333 (", " + property + " = ")
2334 );
2335 code.overwrite(
2336 left.property.end,
2337 left.end,
2338 (", " + object + "[" + property + "]")
2339 );
2340 } else if (needsObjectVar) {
2341 code.prependRight(left.start, ("( " + object + " = "));
2342 code.appendLeft(left.object.end, (", " + object));
2343 } else if (needsPropertyVar) {
2344 code.prependRight(left.property.start, ("( " + property + " = "));
2345 code.appendLeft(left.property.end, ", ");
2346 code.move(left.property.start, left.property.end, left.start);
2347
2348 code.overwrite(left.object.end, left.property.start, ("[" + property + "]"));
2349 code.remove(left.property.end, left.end);
2350 }
2351
2352 if (needsPropertyVar) {
2353 code.appendLeft(this.end, " )");
2354 }
2355 }
2356
2357 base =
2358 object +
2359 (left.computed || needsPropertyVar ? ("[" + property + "]") : ("." + property));
2360 }
2361
2362 code.prependRight(this.right.start, ("Math.pow( " + base + ", "));
2363 code.appendLeft(this.right.end, " )");
2364 };
2365
2366 return AssignmentExpression;
2367}(Node));
2368
2369var BinaryExpression = (function (Node$$1) {
2370 function BinaryExpression () {
2371 Node$$1.apply(this, arguments);
2372 }
2373
2374 if ( Node$$1 ) BinaryExpression.__proto__ = Node$$1;
2375 BinaryExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
2376 BinaryExpression.prototype.constructor = BinaryExpression;
2377
2378 BinaryExpression.prototype.transpile = function transpile (code, transforms) {
2379 if (this.operator === '**' && transforms.exponentiation) {
2380 code.prependRight(this.start, "Math.pow( ");
2381 code.overwrite(this.left.end, this.right.start, ", ");
2382 code.appendLeft(this.end, " )");
2383 }
2384 Node$$1.prototype.transpile.call(this, code, transforms);
2385 };
2386
2387 return BinaryExpression;
2388}(Node));
2389
2390var loopStatement = /(?:For(?:In|Of)?|While)Statement/;
2391
2392var BreakStatement = (function (Node$$1) {
2393 function BreakStatement () {
2394 Node$$1.apply(this, arguments);
2395 }
2396
2397 if ( Node$$1 ) BreakStatement.__proto__ = Node$$1;
2398 BreakStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
2399 BreakStatement.prototype.constructor = BreakStatement;
2400
2401 BreakStatement.prototype.initialise = function initialise () {
2402 var loop = this.findNearest(loopStatement);
2403 var switchCase = this.findNearest('SwitchCase');
2404
2405 if (loop && (!switchCase || loop.depth > switchCase.depth)) {
2406 loop.canBreak = true;
2407 this.loop = loop;
2408 }
2409 };
2410
2411 BreakStatement.prototype.transpile = function transpile (code) {
2412 if (this.loop && this.loop.shouldRewriteAsFunction) {
2413 if (this.label)
2414 { throw new CompileError(
2415 'Labels are not currently supported in a loop with locally-scoped variables',
2416 this
2417 ); }
2418 code.overwrite(this.start, this.start + 5, "return 'break'");
2419 }
2420 };
2421
2422 return BreakStatement;
2423}(Node));
2424
2425var CallExpression = (function (Node$$1) {
2426 function CallExpression () {
2427 Node$$1.apply(this, arguments);
2428 }
2429
2430 if ( Node$$1 ) CallExpression.__proto__ = Node$$1;
2431 CallExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
2432 CallExpression.prototype.constructor = CallExpression;
2433
2434 CallExpression.prototype.initialise = function initialise (transforms) {
2435 var this$1 = this;
2436
2437 if (transforms.spreadRest && this.arguments.length > 1) {
2438 var lexicalBoundary = this.findLexicalBoundary();
2439
2440 var i = this.arguments.length;
2441 while (i--) {
2442 var arg = this$1.arguments[i];
2443 if (arg.type === 'SpreadElement' && isArguments(arg.argument)) {
2444 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
2445 }
2446 }
2447 }
2448
2449 Node$$1.prototype.initialise.call(this, transforms);
2450 };
2451
2452 CallExpression.prototype.transpile = function transpile (code, transforms) {
2453 if (transforms.spreadRest && this.arguments.length) {
2454 var hasSpreadElements = false;
2455 var context;
2456
2457 var firstArgument = this.arguments[0];
2458
2459 if (this.arguments.length === 1) {
2460 if (firstArgument.type === 'SpreadElement') {
2461 code.remove(firstArgument.start, firstArgument.argument.start);
2462 hasSpreadElements = true;
2463 }
2464 } else {
2465 hasSpreadElements = spread(
2466 code,
2467 this.arguments,
2468 firstArgument.start,
2469 this.argumentsArrayAlias
2470 );
2471 }
2472
2473 if (hasSpreadElements) {
2474 // we need to handle super() and super.method() differently
2475 // due to its instance
2476 var _super = null;
2477 if (this.callee.type === 'Super') {
2478 _super = this.callee;
2479 } else if (
2480 this.callee.type === 'MemberExpression' &&
2481 this.callee.object.type === 'Super'
2482 ) {
2483 _super = this.callee.object;
2484 }
2485
2486 if (!_super && this.callee.type === 'MemberExpression') {
2487 if (this.callee.object.type === 'Identifier') {
2488 context = this.callee.object.name;
2489 } else {
2490 context = this.findScope(true).createDeclaration('ref');
2491 var callExpression = this.callee.object;
2492 code.prependRight(callExpression.start, ("(" + context + " = "));
2493 code.appendLeft(callExpression.end, ")");
2494 }
2495 } else {
2496 context = 'void 0';
2497 }
2498
2499 code.appendLeft(this.callee.end, '.apply');
2500
2501 if (_super) {
2502 _super.noCall = true; // bit hacky...
2503
2504 if (this.arguments.length > 1) {
2505 if (firstArgument.type !== 'SpreadElement') {
2506 code.prependRight(firstArgument.start, "[ ");
2507 }
2508
2509 code.appendLeft(
2510 this.arguments[this.arguments.length - 1].end,
2511 ' )'
2512 );
2513 }
2514 } else if (this.arguments.length === 1) {
2515 code.prependRight(firstArgument.start, (context + ", "));
2516 } else {
2517 if (firstArgument.type === 'SpreadElement') {
2518 code.appendLeft(firstArgument.start, (context + ", "));
2519 } else {
2520 code.appendLeft(firstArgument.start, (context + ", [ "));
2521 }
2522
2523 code.appendLeft(this.arguments[this.arguments.length - 1].end, ' )');
2524 }
2525 }
2526 }
2527
2528 if (transforms.trailingFunctionCommas && this.arguments.length) {
2529 removeTrailingComma(code, this.arguments[this.arguments.length - 1].end);
2530 }
2531
2532 Node$$1.prototype.transpile.call(this, code, transforms);
2533 };
2534
2535 return CallExpression;
2536}(Node));
2537
2538// TODO this code is pretty wild, tidy it up
2539var ClassBody = (function (Node$$1) {
2540 function ClassBody () {
2541 Node$$1.apply(this, arguments);
2542 }
2543
2544 if ( Node$$1 ) ClassBody.__proto__ = Node$$1;
2545 ClassBody.prototype = Object.create( Node$$1 && Node$$1.prototype );
2546 ClassBody.prototype.constructor = ClassBody;
2547
2548 ClassBody.prototype.transpile = function transpile (code, transforms, inFunctionExpression, superName) {
2549 var this$1 = this;
2550
2551 if (transforms.classes) {
2552 var name = this.parent.name;
2553
2554 var indentStr = code.getIndentString();
2555 var i0 =
2556 this.getIndentation() + (inFunctionExpression ? indentStr : '');
2557 var i1 = i0 + indentStr;
2558
2559 var constructorIndex = findIndex(
2560 this.body,
2561 function (node) { return node.kind === 'constructor'; }
2562 );
2563 var constructor = this.body[constructorIndex];
2564
2565 var introBlock = '';
2566 var outroBlock = '';
2567
2568 if (this.body.length) {
2569 code.remove(this.start, this.body[0].start);
2570 code.remove(this.body[this.body.length - 1].end, this.end);
2571 } else {
2572 code.remove(this.start, this.end);
2573 }
2574
2575 if (constructor) {
2576 constructor.value.body.isConstructorBody = true;
2577
2578 var previousMethod = this.body[constructorIndex - 1];
2579 var nextMethod = this.body[constructorIndex + 1];
2580
2581 // ensure constructor is first
2582 if (constructorIndex > 0) {
2583 code.remove(previousMethod.end, constructor.start);
2584 code.move(
2585 constructor.start,
2586 nextMethod ? nextMethod.start : this.end - 1,
2587 this.body[0].start
2588 );
2589 }
2590
2591 if (!inFunctionExpression) { code.appendLeft(constructor.end, ';'); }
2592 }
2593
2594 var namedFunctions =
2595 this.program.options.namedFunctionExpressions !== false;
2596 var namedConstructor =
2597 namedFunctions ||
2598 this.parent.superClass ||
2599 this.parent.type !== 'ClassDeclaration';
2600 if (this.parent.superClass) {
2601 var inheritanceBlock = "if ( " + superName + " ) " + name + ".__proto__ = " + superName + ";\n" + i0 + name + ".prototype = Object.create( " + superName + " && " + superName + ".prototype );\n" + i0 + name + ".prototype.constructor = " + name + ";";
2602
2603 if (constructor) {
2604 introBlock += "\n\n" + i0 + inheritanceBlock;
2605 } else {
2606 var fn =
2607 "function " + name + " () {" +
2608 (superName
2609 ? ("\n" + i1 + superName + ".apply(this, arguments);\n" + i0 + "}")
2610 : "}") +
2611 (inFunctionExpression ? '' : ';') +
2612 (this.body.length ? ("\n\n" + i0) : '');
2613
2614 inheritanceBlock = fn + inheritanceBlock;
2615 introBlock += inheritanceBlock + "\n\n" + i0;
2616 }
2617 } else if (!constructor) {
2618 var fn$1 = 'function ' + (namedConstructor ? name + ' ' : '') + '() {}';
2619 if (this.parent.type === 'ClassDeclaration') { fn$1 += ';'; }
2620 if (this.body.length) { fn$1 += "\n\n" + i0; }
2621
2622 introBlock += fn$1;
2623 }
2624
2625 var scope = this.findScope(false);
2626
2627 var prototypeGettersAndSetters = [];
2628 var staticGettersAndSetters = [];
2629 var prototypeAccessors;
2630 var staticAccessors;
2631
2632 this.body.forEach(function (method, i) {
2633 if (method.kind === 'constructor') {
2634 var constructorName = namedConstructor ? ' ' + name : '';
2635 code.overwrite(
2636 method.key.start,
2637 method.key.end,
2638 ("function" + constructorName)
2639 );
2640 return;
2641 }
2642
2643 if (method.static) {
2644 var len = code.original[method.start + 6] == ' ' ? 7 : 6;
2645 code.remove(method.start, method.start + len);
2646 }
2647
2648 var isAccessor = method.kind !== 'method';
2649 var lhs;
2650
2651 var methodName = method.key.name;
2652 if (
2653 reserved[methodName] ||
2654 method.value.body.scope.references[methodName]
2655 ) {
2656 methodName = scope.createIdentifier(methodName);
2657 }
2658
2659 // when method name is a string or a number let's pretend it's a computed method
2660
2661 var fake_computed = false;
2662 if (!method.computed && method.key.type === 'Literal') {
2663 fake_computed = true;
2664 method.computed = true;
2665 }
2666
2667 if (isAccessor) {
2668 if (method.computed) {
2669 throw new Error(
2670 'Computed accessor properties are not currently supported'
2671 );
2672 }
2673
2674 code.remove(method.start, method.key.start);
2675
2676 if (method.static) {
2677 if (!~staticGettersAndSetters.indexOf(method.key.name))
2678 { staticGettersAndSetters.push(method.key.name); }
2679 if (!staticAccessors)
2680 { staticAccessors = scope.createIdentifier('staticAccessors'); }
2681
2682 lhs = "" + staticAccessors;
2683 } else {
2684 if (!~prototypeGettersAndSetters.indexOf(method.key.name))
2685 { prototypeGettersAndSetters.push(method.key.name); }
2686 if (!prototypeAccessors)
2687 { prototypeAccessors = scope.createIdentifier('prototypeAccessors'); }
2688
2689 lhs = "" + prototypeAccessors;
2690 }
2691 } else {
2692 lhs = method.static ? ("" + name) : (name + ".prototype");
2693 }
2694
2695 if (!method.computed) { lhs += '.'; }
2696
2697 var insertNewlines =
2698 (constructorIndex > 0 && i === constructorIndex + 1) ||
2699 (i === 0 && constructorIndex === this$1.body.length - 1);
2700
2701 if (insertNewlines) { lhs = "\n\n" + i0 + lhs; }
2702
2703 var c = method.key.end;
2704 if (method.computed) {
2705 if (fake_computed) {
2706 code.prependRight(method.key.start, '[');
2707 code.appendLeft(method.key.end, ']');
2708 } else {
2709 while (code.original[c] !== ']') { c += 1; }
2710 c += 1;
2711 }
2712 }
2713
2714 var funcName =
2715 method.computed || isAccessor || !namedFunctions
2716 ? ''
2717 : (methodName + " ");
2718 var rhs =
2719 (isAccessor ? ("." + (method.kind)) : '') +
2720 " = function" +
2721 (method.value.generator ? '* ' : ' ') +
2722 funcName;
2723 code.remove(c, method.value.start);
2724 code.prependRight(method.value.start, rhs);
2725 code.appendLeft(method.end, ';');
2726
2727 if (method.value.generator) { code.remove(method.start, method.key.start); }
2728
2729 code.prependRight(method.start, lhs);
2730 });
2731
2732 if (prototypeGettersAndSetters.length || staticGettersAndSetters.length) {
2733 var intro = [];
2734 var outro = [];
2735
2736 if (prototypeGettersAndSetters.length) {
2737 intro.push(
2738 ("var " + prototypeAccessors + " = { " + (prototypeGettersAndSetters
2739 .map(function (name) { return (name + ": { configurable: true }"); })
2740 .join(',')) + " };")
2741 );
2742 outro.push(
2743 ("Object.defineProperties( " + name + ".prototype, " + prototypeAccessors + " );")
2744 );
2745 }
2746
2747 if (staticGettersAndSetters.length) {
2748 intro.push(
2749 ("var " + staticAccessors + " = { " + (staticGettersAndSetters
2750 .map(function (name) { return (name + ": { configurable: true }"); })
2751 .join(',')) + " };")
2752 );
2753 outro.push(("Object.defineProperties( " + name + ", " + staticAccessors + " );"));
2754 }
2755
2756 if (constructor) { introBlock += "\n\n" + i0; }
2757 introBlock += intro.join(("\n" + i0));
2758 if (!constructor) { introBlock += "\n\n" + i0; }
2759
2760 outroBlock += "\n\n" + i0 + outro.join(("\n" + i0));
2761 }
2762
2763 if (constructor) {
2764 code.appendLeft(constructor.end, introBlock);
2765 } else {
2766 code.prependRight(this.start, introBlock);
2767 }
2768
2769 code.appendLeft(this.end, outroBlock);
2770 }
2771
2772 Node$$1.prototype.transpile.call(this, code, transforms);
2773 };
2774
2775 return ClassBody;
2776}(Node));
2777
2778// TODO this function is slightly flawed – it works on the original string,
2779// not its current edited state.
2780// That's not a problem for the way that it's currently used, but it could
2781// be in future...
2782function deindent(node, code) {
2783 var start = node.start;
2784 var end = node.end;
2785
2786 var indentStr = code.getIndentString();
2787 var indentStrLen = indentStr.length;
2788 var indentStart = start - indentStrLen;
2789
2790 if (
2791 !node.program.indentExclusions[indentStart] &&
2792 code.original.slice(indentStart, start) === indentStr
2793 ) {
2794 code.remove(indentStart, start);
2795 }
2796
2797 var pattern = new RegExp(indentStr + '\\S', 'g');
2798 var slice = code.original.slice(start, end);
2799 var match;
2800
2801 while ((match = pattern.exec(slice))) {
2802 var removeStart = start + match.index;
2803 if (!node.program.indentExclusions[removeStart]) {
2804 code.remove(removeStart, removeStart + indentStrLen);
2805 }
2806 }
2807}
2808
2809var ClassDeclaration = (function (Node$$1) {
2810 function ClassDeclaration () {
2811 Node$$1.apply(this, arguments);
2812 }
2813
2814 if ( Node$$1 ) ClassDeclaration.__proto__ = Node$$1;
2815 ClassDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
2816 ClassDeclaration.prototype.constructor = ClassDeclaration;
2817
2818 ClassDeclaration.prototype.initialise = function initialise (transforms) {
2819 if (this.id) {
2820 this.name = this.id.name;
2821 this.findScope(true).addDeclaration(this.id, 'class');
2822 } else {
2823 this.name = this.findScope(true).createIdentifier("defaultExport");
2824 }
2825
2826 Node$$1.prototype.initialise.call(this, transforms);
2827 };
2828
2829 ClassDeclaration.prototype.transpile = function transpile (code, transforms) {
2830 if (transforms.classes) {
2831 if (!this.superClass) { deindent(this.body, code); }
2832
2833 var superName =
2834 this.superClass && (this.superClass.name || 'superclass');
2835
2836 var i0 = this.getIndentation();
2837 var i1 = i0 + code.getIndentString();
2838
2839 // if this is an export default statement, we have to move the export to
2840 // after the declaration, because `export default var Foo = ...` is illegal
2841 var isExportDefaultDeclaration = this.parent.type === 'ExportDefaultDeclaration';
2842
2843 if (isExportDefaultDeclaration) {
2844 code.remove(this.parent.start, this.start);
2845 }
2846
2847 var c = this.start;
2848 if (this.id) {
2849 code.overwrite(c, this.id.start, 'var ');
2850 c = this.id.end;
2851 } else {
2852 code.prependLeft(c, ("var " + (this.name)));
2853 }
2854
2855 if (this.superClass) {
2856 if (this.superClass.end === this.body.start) {
2857 code.remove(c, this.superClass.start);
2858 code.appendLeft(c, (" = (function (" + superName + ") {\n" + i1));
2859 } else {
2860 code.overwrite(c, this.superClass.start, ' = ');
2861 code.overwrite(
2862 this.superClass.end,
2863 this.body.start,
2864 ("(function (" + superName + ") {\n" + i1)
2865 );
2866 }
2867 } else {
2868 if (c === this.body.start) {
2869 code.appendLeft(c, ' = ');
2870 } else {
2871 code.overwrite(c, this.body.start, ' = ');
2872 }
2873 }
2874
2875 this.body.transpile(code, transforms, !!this.superClass, superName);
2876
2877 var syntheticDefaultExport =
2878 isExportDefaultDeclaration
2879 ? ("\n\n" + i0 + "export default " + (this.name) + ";")
2880 : '';
2881 if (this.superClass) {
2882 code.appendLeft(this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}("));
2883 code.move(this.superClass.start, this.superClass.end, this.end);
2884 code.prependRight(this.end, ("));" + syntheticDefaultExport));
2885 } else if (syntheticDefaultExport) {
2886 code.prependRight(this.end, syntheticDefaultExport);
2887 }
2888 } else {
2889 this.body.transpile(code, transforms, false, null);
2890 }
2891 };
2892
2893 return ClassDeclaration;
2894}(Node));
2895
2896var ClassExpression = (function (Node$$1) {
2897 function ClassExpression () {
2898 Node$$1.apply(this, arguments);
2899 }
2900
2901 if ( Node$$1 ) ClassExpression.__proto__ = Node$$1;
2902 ClassExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
2903 ClassExpression.prototype.constructor = ClassExpression;
2904
2905 ClassExpression.prototype.initialise = function initialise (transforms) {
2906 this.name = ( this.id
2907 ? this.id.name
2908 : this.parent.type === 'VariableDeclarator'
2909 ? this.parent.id.name
2910 : this.parent.type !== 'AssignmentExpression'
2911 ? null
2912 : this.parent.left.type === 'Identifier'
2913 ? this.parent.left.name
2914 : this.parent.left.type === 'MemberExpression'
2915 ? this.parent.left.property.name
2916 : null ) || this.findScope(true).createIdentifier('anonymous');
2917
2918 Node$$1.prototype.initialise.call(this, transforms);
2919 };
2920
2921 ClassExpression.prototype.transpile = function transpile (code, transforms) {
2922 if (transforms.classes) {
2923 var superName =
2924 this.superClass && (this.superClass.name || 'superclass');
2925
2926 var i0 = this.getIndentation();
2927 var i1 = i0 + code.getIndentString();
2928
2929 if (this.superClass) {
2930 code.remove(this.start, this.superClass.start);
2931 code.remove(this.superClass.end, this.body.start);
2932 code.appendLeft(this.start, ("(function (" + superName + ") {\n" + i1));
2933 } else {
2934 code.overwrite(this.start, this.body.start, ("(function () {\n" + i1));
2935 }
2936
2937 this.body.transpile(code, transforms, true, superName);
2938
2939 var outro = "\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(";
2940
2941 if (this.superClass) {
2942 code.appendLeft(this.end, outro);
2943 code.move(this.superClass.start, this.superClass.end, this.end);
2944 code.prependRight(this.end, '))');
2945 } else {
2946 code.appendLeft(this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}())"));
2947 }
2948 } else {
2949 this.body.transpile(code, transforms, false);
2950 }
2951 };
2952
2953 return ClassExpression;
2954}(Node));
2955
2956var ContinueStatement = (function (Node$$1) {
2957 function ContinueStatement () {
2958 Node$$1.apply(this, arguments);
2959 }
2960
2961 if ( Node$$1 ) ContinueStatement.__proto__ = Node$$1;
2962 ContinueStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
2963 ContinueStatement.prototype.constructor = ContinueStatement;
2964
2965 ContinueStatement.prototype.transpile = function transpile (code) {
2966 var loop = this.findNearest(loopStatement);
2967 if (loop.shouldRewriteAsFunction) {
2968 if (this.label)
2969 { throw new CompileError(
2970 'Labels are not currently supported in a loop with locally-scoped variables',
2971 this
2972 ); }
2973 code.overwrite(this.start, this.start + 8, 'return');
2974 }
2975 };
2976
2977 return ContinueStatement;
2978}(Node));
2979
2980var ExportDefaultDeclaration = (function (Node$$1) {
2981 function ExportDefaultDeclaration () {
2982 Node$$1.apply(this, arguments);
2983 }
2984
2985 if ( Node$$1 ) ExportDefaultDeclaration.__proto__ = Node$$1;
2986 ExportDefaultDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
2987 ExportDefaultDeclaration.prototype.constructor = ExportDefaultDeclaration;
2988
2989 ExportDefaultDeclaration.prototype.initialise = function initialise (transforms) {
2990 if (transforms.moduleExport)
2991 { throw new CompileError('export is not supported', this); }
2992 Node$$1.prototype.initialise.call(this, transforms);
2993 };
2994
2995 return ExportDefaultDeclaration;
2996}(Node));
2997
2998var ExportNamedDeclaration = (function (Node$$1) {
2999 function ExportNamedDeclaration () {
3000 Node$$1.apply(this, arguments);
3001 }
3002
3003 if ( Node$$1 ) ExportNamedDeclaration.__proto__ = Node$$1;
3004 ExportNamedDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
3005 ExportNamedDeclaration.prototype.constructor = ExportNamedDeclaration;
3006
3007 ExportNamedDeclaration.prototype.initialise = function initialise (transforms) {
3008 if (transforms.moduleExport)
3009 { throw new CompileError('export is not supported', this); }
3010 Node$$1.prototype.initialise.call(this, transforms);
3011 };
3012
3013 return ExportNamedDeclaration;
3014}(Node));
3015
3016var LoopStatement = (function (Node$$1) {
3017 function LoopStatement () {
3018 Node$$1.apply(this, arguments);
3019 }
3020
3021 if ( Node$$1 ) LoopStatement.__proto__ = Node$$1;
3022 LoopStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
3023 LoopStatement.prototype.constructor = LoopStatement;
3024
3025 LoopStatement.prototype.findScope = function findScope (functionScope) {
3026 return functionScope || !this.createdScope
3027 ? this.parent.findScope(functionScope)
3028 : this.body.scope;
3029 };
3030
3031 LoopStatement.prototype.initialise = function initialise (transforms) {
3032 var this$1 = this;
3033
3034 this.body.createScope();
3035 this.createdScope = true;
3036
3037 // this is populated as and when reassignments occur
3038 this.reassigned = Object.create(null);
3039 this.aliases = Object.create(null);
3040
3041 Node$$1.prototype.initialise.call(this, transforms);
3042
3043 if (transforms.letConst) {
3044 // see if any block-scoped declarations are referenced
3045 // inside function expressions
3046 var names = Object.keys(this.body.scope.declarations);
3047
3048 var i = names.length;
3049 while (i--) {
3050 var name = names[i];
3051 var declaration = this$1.body.scope.declarations[name];
3052
3053 var j = declaration.instances.length;
3054 while (j--) {
3055 var instance = declaration.instances[j];
3056 var nearestFunctionExpression = instance.findNearest(/Function/);
3057
3058 if (
3059 nearestFunctionExpression &&
3060 nearestFunctionExpression.depth > this$1.depth
3061 ) {
3062 this$1.shouldRewriteAsFunction = true;
3063 break;
3064 }
3065 }
3066
3067 if (this$1.shouldRewriteAsFunction) { break; }
3068 }
3069 }
3070 };
3071
3072 LoopStatement.prototype.transpile = function transpile (code, transforms) {
3073 var needsBlock =
3074 this.type != 'ForOfStatement' &&
3075 (this.body.type !== 'BlockStatement' ||
3076 (this.body.type === 'BlockStatement' && this.body.synthetic));
3077
3078 if (this.shouldRewriteAsFunction) {
3079 var i0 = this.getIndentation();
3080 var i1 = i0 + code.getIndentString();
3081
3082 var argString = this.args ? (" " + (this.args.join(', ')) + " ") : '';
3083 var paramString = this.params ? (" " + (this.params.join(', ')) + " ") : '';
3084
3085 var functionScope = this.findScope(true);
3086 var loop = functionScope.createIdentifier('loop');
3087
3088 var before =
3089 "var " + loop + " = function (" + paramString + ") " +
3090 (this.body.synthetic ? ("{\n" + i0 + (code.getIndentString())) : '');
3091 var after = (this.body.synthetic ? ("\n" + i0 + "}") : '') + ";\n\n" + i0;
3092
3093 code.prependRight(this.body.start, before);
3094 code.appendLeft(this.body.end, after);
3095 code.move(this.start, this.body.start, this.body.end);
3096
3097 if (this.canBreak || this.canReturn) {
3098 var returned = functionScope.createIdentifier('returned');
3099
3100 var insert = "{\n" + i1 + "var " + returned + " = " + loop + "(" + argString + ");\n";
3101 if (this.canBreak)
3102 { insert += "\n" + i1 + "if ( " + returned + " === 'break' ) break;"; }
3103 if (this.canReturn)
3104 { insert += "\n" + i1 + "if ( " + returned + " ) return " + returned + ".v;"; }
3105 insert += "\n" + i0 + "}";
3106
3107 code.prependRight(this.body.end, insert);
3108 } else {
3109 var callExpression = loop + "(" + argString + ");";
3110
3111 if (this.type === 'DoWhileStatement') {
3112 code.overwrite(
3113 this.start,
3114 this.body.start,
3115 ("do {\n" + i1 + callExpression + "\n" + i0 + "}")
3116 );
3117 } else {
3118 code.prependRight(this.body.end, callExpression);
3119 }
3120 }
3121 } else if (needsBlock) {
3122 code.appendLeft(this.body.start, '{ ');
3123 code.prependRight(this.body.end, ' }');
3124 }
3125
3126 Node$$1.prototype.transpile.call(this, code, transforms);
3127 };
3128
3129 return LoopStatement;
3130}(Node));
3131
3132var ForStatement = (function (LoopStatement$$1) {
3133 function ForStatement () {
3134 LoopStatement$$1.apply(this, arguments);
3135 }
3136
3137 if ( LoopStatement$$1 ) ForStatement.__proto__ = LoopStatement$$1;
3138 ForStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
3139 ForStatement.prototype.constructor = ForStatement;
3140
3141 ForStatement.prototype.findScope = function findScope (functionScope) {
3142 return functionScope || !this.createdScope
3143 ? this.parent.findScope(functionScope)
3144 : this.body.scope;
3145 };
3146
3147 ForStatement.prototype.transpile = function transpile (code, transforms) {
3148 var this$1 = this;
3149
3150 var i1 = this.getIndentation() + code.getIndentString();
3151
3152 if (this.shouldRewriteAsFunction) {
3153 // which variables are declared in the init statement?
3154 var names =
3155 this.init.type === 'VariableDeclaration'
3156 ? [].concat.apply(
3157 [],
3158 this.init.declarations.map(function (declarator) { return extractNames(declarator.id); }
3159 )
3160 )
3161 : [];
3162
3163 var aliases = this.aliases;
3164
3165 this.args = names.map(
3166 function (name) { return (name in this$1.aliases ? this$1.aliases[name].outer : name); }
3167 );
3168 this.params = names.map(
3169 function (name) { return (name in this$1.aliases ? this$1.aliases[name].inner : name); }
3170 );
3171
3172 var updates = Object.keys(this.reassigned).map(
3173 function (name) { return ((aliases[name].outer) + " = " + (aliases[name].inner) + ";"); }
3174 );
3175
3176 if (updates.length) {
3177 if (this.body.synthetic) {
3178 code.appendLeft(this.body.body[0].end, ("; " + (updates.join(" "))));
3179 } else {
3180 var lastStatement = this.body.body[this.body.body.length - 1];
3181 code.appendLeft(
3182 lastStatement.end,
3183 ("\n\n" + i1 + (updates.join(("\n" + i1))))
3184 );
3185 }
3186 }
3187 }
3188
3189 LoopStatement$$1.prototype.transpile.call(this, code, transforms);
3190 };
3191
3192 return ForStatement;
3193}(LoopStatement));
3194
3195var ForInStatement = (function (LoopStatement$$1) {
3196 function ForInStatement () {
3197 LoopStatement$$1.apply(this, arguments);
3198 }
3199
3200 if ( LoopStatement$$1 ) ForInStatement.__proto__ = LoopStatement$$1;
3201 ForInStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
3202 ForInStatement.prototype.constructor = ForInStatement;
3203
3204 ForInStatement.prototype.findScope = function findScope (functionScope) {
3205 return functionScope || !this.createdScope
3206 ? this.parent.findScope(functionScope)
3207 : this.body.scope;
3208 };
3209
3210 ForInStatement.prototype.transpile = function transpile (code, transforms) {
3211 var this$1 = this;
3212
3213 var hasDeclaration = this.left.type === 'VariableDeclaration';
3214
3215 if (this.shouldRewriteAsFunction) {
3216 // which variables are declared in the init statement?
3217 var names =
3218 hasDeclaration
3219 ? [].concat.apply(
3220 [],
3221 this.left.declarations.map(function (declarator) { return extractNames(declarator.id); }
3222 )
3223 )
3224 : [];
3225
3226 this.args = names.map(
3227 function (name) { return (name in this$1.aliases ? this$1.aliases[name].outer : name); }
3228 );
3229 this.params = names.map(
3230 function (name) { return (name in this$1.aliases ? this$1.aliases[name].inner : name); }
3231 );
3232 }
3233
3234 LoopStatement$$1.prototype.transpile.call(this, code, transforms);
3235
3236 var maybePattern = hasDeclaration ? this.left.declarations[0].id : this.left;
3237 if (maybePattern.type !== 'Identifier') {
3238 this.destructurePattern(code, maybePattern, hasDeclaration);
3239 }
3240 };
3241
3242 ForInStatement.prototype.destructurePattern = function destructurePattern (code, pattern, isDeclaration) {
3243 var scope = this.findScope(true);
3244 var i0 = this.getIndentation();
3245 var i1 = i0 + code.getIndentString();
3246
3247 var ref = scope.createIdentifier('ref');
3248
3249 var bodyStart = this.body.body.length ? this.body.body[0].start : this.body.start + 1;
3250
3251 code.move(pattern.start, pattern.end, bodyStart);
3252
3253 code.prependRight(pattern.end, isDeclaration ? ref : ("var " + ref));
3254
3255 var statementGenerators = [];
3256 destructure(
3257 code,
3258 function (id) { return scope.createIdentifier(id); },
3259 function (ref) {
3260 var name = ref.name;
3261
3262 return scope.resolveName(name);
3263 },
3264 pattern,
3265 ref,
3266 false,
3267 statementGenerators
3268 );
3269
3270 var suffix = ";\n" + i1;
3271 statementGenerators.forEach(function (fn, i) {
3272 if (i === statementGenerators.length - 1) {
3273 suffix = ";\n\n" + i1;
3274 }
3275
3276 fn(bodyStart, '', suffix);
3277 });
3278 };
3279
3280 return ForInStatement;
3281}(LoopStatement));
3282
3283var ForOfStatement = (function (LoopStatement$$1) {
3284 function ForOfStatement () {
3285 LoopStatement$$1.apply(this, arguments);
3286 }
3287
3288 if ( LoopStatement$$1 ) ForOfStatement.__proto__ = LoopStatement$$1;
3289 ForOfStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
3290 ForOfStatement.prototype.constructor = ForOfStatement;
3291
3292 ForOfStatement.prototype.initialise = function initialise (transforms) {
3293 if (transforms.forOf && !transforms.dangerousForOf)
3294 { throw new CompileError(
3295 "for...of statements are not supported. Use `transforms: { forOf: false }` to skip transformation and disable this error, or `transforms: { dangerousForOf: true }` if you know what you're doing",
3296 this
3297 ); }
3298 LoopStatement$$1.prototype.initialise.call(this, transforms);
3299 };
3300
3301 ForOfStatement.prototype.transpile = function transpile (code, transforms) {
3302 LoopStatement$$1.prototype.transpile.call(this, code, transforms);
3303 if (!transforms.dangerousForOf) { return; }
3304
3305 // edge case (#80)
3306 if (!this.body.body[0]) {
3307 if (
3308 this.left.type === 'VariableDeclaration' &&
3309 this.left.kind === 'var'
3310 ) {
3311 code.remove(this.start, this.left.start);
3312 code.appendLeft(this.left.end, ';');
3313 code.remove(this.left.end, this.end);
3314 } else {
3315 code.remove(this.start, this.end);
3316 }
3317
3318 return;
3319 }
3320
3321 var scope = this.findScope(true);
3322 var i0 = this.getIndentation();
3323 var i1 = i0 + code.getIndentString();
3324
3325 var key = scope.createIdentifier('i');
3326 var list = scope.createIdentifier('list');
3327
3328 if (this.body.synthetic) {
3329 code.prependRight(this.left.start, ("{\n" + i1));
3330 code.appendLeft(this.body.body[0].end, ("\n" + i0 + "}"));
3331 }
3332
3333 var bodyStart = this.body.body[0].start;
3334
3335 code.remove(this.left.end, this.right.start);
3336 code.move(this.left.start, this.left.end, bodyStart);
3337
3338 code.prependRight(this.right.start, ("var " + key + " = 0, " + list + " = "));
3339 code.appendLeft(this.right.end, ("; " + key + " < " + list + ".length; " + key + " += 1"));
3340
3341 var isDeclaration = this.left.type === 'VariableDeclaration';
3342 var maybeDestructuring = isDeclaration ? this.left.declarations[0].id : this.left;
3343 if (maybeDestructuring.type !== 'Identifier') {
3344 var statementGenerators = [];
3345 var ref = scope.createIdentifier('ref');
3346 destructure(
3347 code,
3348 function (id) { return scope.createIdentifier(id); },
3349 function (ref) {
3350 var name = ref.name;
3351
3352 return scope.resolveName(name);
3353 },
3354 maybeDestructuring,
3355 ref,
3356 !isDeclaration,
3357 statementGenerators
3358 );
3359
3360 var suffix = ";\n" + i1;
3361 statementGenerators.forEach(function (fn, i) {
3362 if (i === statementGenerators.length - 1) {
3363 suffix = ";\n\n" + i1;
3364 }
3365
3366 fn(bodyStart, '', suffix);
3367 });
3368
3369 if (isDeclaration) {
3370 code.appendLeft(this.left.start + this.left.kind.length + 1, ref);
3371 code.appendLeft(this.left.end, (" = " + list + "[" + key + "];\n" + i1));
3372 } else {
3373 code.appendLeft(this.left.end, ("var " + ref + " = " + list + "[" + key + "];\n" + i1));
3374 }
3375 } else {
3376 code.appendLeft(this.left.end, (" = " + list + "[" + key + "];\n\n" + i1));
3377 }
3378 };
3379
3380 return ForOfStatement;
3381}(LoopStatement));
3382
3383var FunctionDeclaration = (function (Node$$1) {
3384 function FunctionDeclaration () {
3385 Node$$1.apply(this, arguments);
3386 }
3387
3388 if ( Node$$1 ) FunctionDeclaration.__proto__ = Node$$1;
3389 FunctionDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
3390 FunctionDeclaration.prototype.constructor = FunctionDeclaration;
3391
3392 FunctionDeclaration.prototype.initialise = function initialise (transforms) {
3393 if (this.generator && transforms.generator) {
3394 throw new CompileError('Generators are not supported', this);
3395 }
3396
3397 this.body.createScope();
3398
3399 if (this.id) {
3400 this.findScope(true).addDeclaration(this.id, 'function');
3401 }
3402 Node$$1.prototype.initialise.call(this, transforms);
3403 };
3404
3405 FunctionDeclaration.prototype.transpile = function transpile (code, transforms) {
3406 Node$$1.prototype.transpile.call(this, code, transforms);
3407 if (transforms.trailingFunctionCommas && this.params.length) {
3408 removeTrailingComma(code, this.params[this.params.length - 1].end);
3409 }
3410 };
3411
3412 return FunctionDeclaration;
3413}(Node));
3414
3415var FunctionExpression = (function (Node$$1) {
3416 function FunctionExpression () {
3417 Node$$1.apply(this, arguments);
3418 }
3419
3420 if ( Node$$1 ) FunctionExpression.__proto__ = Node$$1;
3421 FunctionExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
3422 FunctionExpression.prototype.constructor = FunctionExpression;
3423
3424 FunctionExpression.prototype.initialise = function initialise (transforms) {
3425 var this$1 = this;
3426
3427 if (this.generator && transforms.generator) {
3428 throw new CompileError('Generators are not supported', this);
3429 }
3430
3431 this.body.createScope();
3432
3433 if (this.id) {
3434 // function expression IDs belong to the child scope...
3435 this.body.scope.addDeclaration(this.id, 'function');
3436 }
3437
3438 Node$$1.prototype.initialise.call(this, transforms);
3439
3440 var parent = this.parent;
3441 var methodName;
3442
3443 if (
3444 transforms.conciseMethodProperty &&
3445 parent.type === 'Property' &&
3446 parent.kind === 'init' &&
3447 parent.method &&
3448 parent.key.type === 'Identifier'
3449 ) {
3450 // object literal concise method
3451 methodName = parent.key.name;
3452 } else if (
3453 transforms.classes &&
3454 parent.type === 'MethodDefinition' &&
3455 parent.kind === 'method' &&
3456 parent.key.type === 'Identifier'
3457 ) {
3458 // method definition in a class
3459 methodName = parent.key.name;
3460 } else if (this.id && this.id.type === 'Identifier') {
3461 // naked function expression
3462 methodName = this.id.alias || this.id.name;
3463 }
3464
3465 if (methodName) {
3466 for (var i$1 = 0, list$1 = this$1.params; i$1 < list$1.length; i$1 += 1) {
3467 var param = list$1[i$1];
3468
3469 if (param.type === 'Identifier' && methodName === param.name) {
3470 // workaround for Safari 9/WebKit bug:
3471 // https://gitlab.com/Rich-Harris/buble/issues/154
3472 // change parameter name when same as method name
3473
3474 var scope = this$1.body.scope;
3475 var declaration = scope.declarations[methodName];
3476
3477 var alias = scope.createIdentifier(methodName);
3478 param.alias = alias;
3479
3480 for (var i = 0, list = declaration.instances; i < list.length; i += 1) {
3481 var identifier = list[i];
3482
3483 identifier.alias = alias;
3484 }
3485
3486 break;
3487 }
3488 }
3489 }
3490 };
3491
3492 FunctionExpression.prototype.transpile = function transpile (code, transforms) {
3493 Node$$1.prototype.transpile.call(this, code, transforms);
3494 if (transforms.trailingFunctionCommas && this.params.length) {
3495 removeTrailingComma(code, this.params[this.params.length - 1].end);
3496 }
3497 };
3498
3499 return FunctionExpression;
3500}(Node));
3501
3502function isReference(node, parent) {
3503 if (node.type === 'MemberExpression') {
3504 return !node.computed && isReference(node.object, node);
3505 }
3506
3507 if (node.type === 'Identifier') {
3508 // the only time we could have an identifier node without a parent is
3509 // if it's the entire body of a function without a block statement –
3510 // i.e. an arrow function expression like `a => a`
3511 if (!parent) { return true; }
3512
3513 if (/(Function|Class)Expression/.test(parent.type)) { return false; }
3514
3515 if (parent.type === 'VariableDeclarator') { return node === parent.init; }
3516
3517 // TODO is this right?
3518 if (
3519 parent.type === 'MemberExpression' ||
3520 parent.type === 'MethodDefinition'
3521 ) {
3522 return parent.computed || node === parent.object;
3523 }
3524
3525 if (parent.type === 'ArrayPattern') { return false; }
3526
3527 // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
3528 if (parent.type === 'Property') {
3529 if (parent.parent.type === 'ObjectPattern') { return false; }
3530 return parent.computed || node === parent.value;
3531 }
3532
3533 // disregard the `bar` in `class Foo { bar () {...} }`
3534 if (parent.type === 'MethodDefinition') { return false; }
3535
3536 // disregard the `bar` in `export { foo as bar }`
3537 if (parent.type === 'ExportSpecifier' && node !== parent.local)
3538 { return false; }
3539
3540 return true;
3541 }
3542}
3543
3544var Identifier = (function (Node$$1) {
3545 function Identifier () {
3546 Node$$1.apply(this, arguments);
3547 }
3548
3549 if ( Node$$1 ) Identifier.__proto__ = Node$$1;
3550 Identifier.prototype = Object.create( Node$$1 && Node$$1.prototype );
3551 Identifier.prototype.constructor = Identifier;
3552
3553 Identifier.prototype.findScope = function findScope (functionScope) {
3554 if (this.parent.params && ~this.parent.params.indexOf(this)) {
3555 return this.parent.body.scope;
3556 }
3557
3558 if (this.parent.type === 'FunctionExpression' && this === this.parent.id) {
3559 return this.parent.body.scope;
3560 }
3561
3562 return this.parent.findScope(functionScope);
3563 };
3564
3565 Identifier.prototype.initialise = function initialise (transforms) {
3566 if (isReference(this, this.parent)) {
3567 if (
3568 transforms.arrow &&
3569 this.name === 'arguments' &&
3570 !this.findScope(false).contains(this.name)
3571 ) {
3572 var lexicalBoundary = this.findLexicalBoundary();
3573 var arrowFunction = this.findNearest('ArrowFunctionExpression');
3574 var loop = this.findNearest(loopStatement);
3575
3576 if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) {
3577 this.alias = lexicalBoundary.getArgumentsAlias();
3578 }
3579
3580 if (
3581 loop &&
3582 loop.body.contains(this) &&
3583 loop.depth > lexicalBoundary.depth
3584 ) {
3585 this.alias = lexicalBoundary.getArgumentsAlias();
3586 }
3587 }
3588
3589 this.findScope(false).addReference(this);
3590 }
3591 };
3592
3593 Identifier.prototype.transpile = function transpile (code) {
3594 if (this.alias) {
3595 code.overwrite(this.start, this.end, this.alias, {
3596 storeName: true,
3597 contentOnly: true
3598 });
3599 }
3600 };
3601
3602 return Identifier;
3603}(Node));
3604
3605var IfStatement = (function (Node$$1) {
3606 function IfStatement () {
3607 Node$$1.apply(this, arguments);
3608 }
3609
3610 if ( Node$$1 ) IfStatement.__proto__ = Node$$1;
3611 IfStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
3612 IfStatement.prototype.constructor = IfStatement;
3613
3614 IfStatement.prototype.initialise = function initialise (transforms) {
3615 Node$$1.prototype.initialise.call(this, transforms);
3616 };
3617
3618 IfStatement.prototype.transpile = function transpile (code, transforms) {
3619 if (
3620 this.consequent.type !== 'BlockStatement' ||
3621 (this.consequent.type === 'BlockStatement' && this.consequent.synthetic)
3622 ) {
3623 code.appendLeft(this.consequent.start, '{ ');
3624 code.prependRight(this.consequent.end, ' }');
3625 }
3626
3627 if (
3628 this.alternate &&
3629 this.alternate.type !== 'IfStatement' &&
3630 (this.alternate.type !== 'BlockStatement' ||
3631 (this.alternate.type === 'BlockStatement' && this.alternate.synthetic))
3632 ) {
3633 code.appendLeft(this.alternate.start, '{ ');
3634 code.prependRight(this.alternate.end, ' }');
3635 }
3636
3637 Node$$1.prototype.transpile.call(this, code, transforms);
3638 };
3639
3640 return IfStatement;
3641}(Node));
3642
3643var ImportDeclaration = (function (Node$$1) {
3644 function ImportDeclaration () {
3645 Node$$1.apply(this, arguments);
3646 }
3647
3648 if ( Node$$1 ) ImportDeclaration.__proto__ = Node$$1;
3649 ImportDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
3650 ImportDeclaration.prototype.constructor = ImportDeclaration;
3651
3652 ImportDeclaration.prototype.initialise = function initialise (transforms) {
3653 if (transforms.moduleImport)
3654 { throw new CompileError('import is not supported', this); }
3655 Node$$1.prototype.initialise.call(this, transforms);
3656 };
3657
3658 return ImportDeclaration;
3659}(Node));
3660
3661var ImportDefaultSpecifier = (function (Node$$1) {
3662 function ImportDefaultSpecifier () {
3663 Node$$1.apply(this, arguments);
3664 }
3665
3666 if ( Node$$1 ) ImportDefaultSpecifier.__proto__ = Node$$1;
3667 ImportDefaultSpecifier.prototype = Object.create( Node$$1 && Node$$1.prototype );
3668 ImportDefaultSpecifier.prototype.constructor = ImportDefaultSpecifier;
3669
3670 ImportDefaultSpecifier.prototype.initialise = function initialise (transforms) {
3671 this.findScope(true).addDeclaration(this.local, 'import');
3672 Node$$1.prototype.initialise.call(this, transforms);
3673 };
3674
3675 return ImportDefaultSpecifier;
3676}(Node));
3677
3678var ImportSpecifier = (function (Node$$1) {
3679 function ImportSpecifier () {
3680 Node$$1.apply(this, arguments);
3681 }
3682
3683 if ( Node$$1 ) ImportSpecifier.__proto__ = Node$$1;
3684 ImportSpecifier.prototype = Object.create( Node$$1 && Node$$1.prototype );
3685 ImportSpecifier.prototype.constructor = ImportSpecifier;
3686
3687 ImportSpecifier.prototype.initialise = function initialise (transforms) {
3688 this.findScope(true).addDeclaration(this.local, 'import');
3689 Node$$1.prototype.initialise.call(this, transforms);
3690 };
3691
3692 return ImportSpecifier;
3693}(Node));
3694
3695var hasDashes = function (val) { return /-/.test(val); };
3696
3697var formatKey = function (key) { return (hasDashes(key) ? ("'" + key + "'") : key); };
3698
3699var formatVal = function (val) { return (val ? '' : 'true'); };
3700
3701var JSXAttribute = (function (Node$$1) {
3702 function JSXAttribute () {
3703 Node$$1.apply(this, arguments);
3704 }
3705
3706 if ( Node$$1 ) JSXAttribute.__proto__ = Node$$1;
3707 JSXAttribute.prototype = Object.create( Node$$1 && Node$$1.prototype );
3708 JSXAttribute.prototype.constructor = JSXAttribute;
3709
3710 JSXAttribute.prototype.transpile = function transpile (code, transforms) {
3711 var ref = this.name;
3712 var start = ref.start;
3713 var name = ref.name;
3714
3715 // Overwrite equals sign if value is present.
3716 var end = this.value ? this.value.start : this.name.end;
3717
3718 code.overwrite(start, end, ((formatKey(name)) + ": " + (formatVal(this.value))));
3719
3720 Node$$1.prototype.transpile.call(this, code, transforms);
3721 };
3722
3723 return JSXAttribute;
3724}(Node));
3725
3726function containsNewLine(node) {
3727 return (
3728 node.type === 'JSXText' && !/\S/.test(node.value) && /\n/.test(node.value)
3729 );
3730}
3731
3732var JSXClosingElement = (function (Node$$1) {
3733 function JSXClosingElement () {
3734 Node$$1.apply(this, arguments);
3735 }
3736
3737 if ( Node$$1 ) JSXClosingElement.__proto__ = Node$$1;
3738 JSXClosingElement.prototype = Object.create( Node$$1 && Node$$1.prototype );
3739 JSXClosingElement.prototype.constructor = JSXClosingElement;
3740
3741 JSXClosingElement.prototype.transpile = function transpile (code) {
3742 var spaceBeforeParen = true;
3743
3744 var lastChild = this.parent.children[this.parent.children.length - 1];
3745
3746 // omit space before closing paren if
3747 // a) this is on a separate line, or
3748 // b) there are no children but there are attributes
3749 if (
3750 (lastChild && containsNewLine(lastChild)) ||
3751 this.parent.openingElement.attributes.length
3752 ) {
3753 spaceBeforeParen = false;
3754 }
3755
3756 code.overwrite(this.start, this.end, spaceBeforeParen ? ' )' : ')');
3757 };
3758
3759 return JSXClosingElement;
3760}(Node));
3761
3762function containsNewLine$1(node) {
3763 return (
3764 node.type === 'JSXText' && !/\S/.test(node.value) && /\n/.test(node.value)
3765 );
3766}
3767
3768var JSXClosingFragment = (function (Node$$1) {
3769 function JSXClosingFragment () {
3770 Node$$1.apply(this, arguments);
3771 }
3772
3773 if ( Node$$1 ) JSXClosingFragment.__proto__ = Node$$1;
3774 JSXClosingFragment.prototype = Object.create( Node$$1 && Node$$1.prototype );
3775 JSXClosingFragment.prototype.constructor = JSXClosingFragment;
3776
3777 JSXClosingFragment.prototype.transpile = function transpile (code) {
3778 var spaceBeforeParen = true;
3779
3780 var lastChild = this.parent.children[this.parent.children.length - 1];
3781
3782 // omit space before closing paren if this is on a separate line
3783 if (lastChild && containsNewLine$1(lastChild)) {
3784 spaceBeforeParen = false;
3785 }
3786
3787 code.overwrite(this.start, this.end, spaceBeforeParen ? ' )' : ')');
3788 };
3789
3790 return JSXClosingFragment;
3791}(Node));
3792
3793function normalise(str, removeTrailingWhitespace) {
3794
3795 str = str.replace(/\u00a0/g, '&nbsp;');
3796
3797 if (removeTrailingWhitespace && /\n/.test(str)) {
3798 str = str.replace(/\s+$/, '');
3799 }
3800
3801 str = str
3802 .replace(/^\n\r?\s+/, '') // remove leading newline + space
3803 .replace(/\s*\n\r?\s*/gm, ' '); // replace newlines with spaces
3804
3805 // TODO prefer single quotes?
3806 return JSON.stringify(str);
3807}
3808
3809var JSXElement = (function (Node$$1) {
3810 function JSXElement () {
3811 Node$$1.apply(this, arguments);
3812 }
3813
3814 if ( Node$$1 ) JSXElement.__proto__ = Node$$1;
3815 JSXElement.prototype = Object.create( Node$$1 && Node$$1.prototype );
3816 JSXElement.prototype.constructor = JSXElement;
3817
3818 JSXElement.prototype.transpile = function transpile (code, transforms) {
3819 Node$$1.prototype.transpile.call(this, code, transforms);
3820
3821 var children = this.children.filter(function (child) {
3822 if (child.type !== 'JSXText') { return true; }
3823
3824 // remove whitespace-only literals, unless on a single line
3825 return /\S/.test(child.raw) || !/\n/.test(child.raw);
3826 });
3827
3828 if (children.length) {
3829 var c = this.openingElement.end;
3830
3831 var i;
3832 for (i = 0; i < children.length; i += 1) {
3833 var child = children[i];
3834
3835 if (
3836 child.type === 'JSXExpressionContainer' &&
3837 child.expression.type === 'JSXEmptyExpression'
3838 ) {
3839 // empty block is a no op
3840 } else {
3841 var tail =
3842 code.original[c] === '\n' && child.type !== 'JSXText' ? '' : ' ';
3843 code.appendLeft(c, ("," + tail));
3844 }
3845
3846 if (child.type === 'JSXText') {
3847 var str = normalise(child.value, i === children.length - 1);
3848 code.overwrite(child.start, child.end, str);
3849 }
3850
3851 c = child.end;
3852 }
3853 }
3854 };
3855
3856 return JSXElement;
3857}(Node));
3858
3859var JSXExpressionContainer = (function (Node$$1) {
3860 function JSXExpressionContainer () {
3861 Node$$1.apply(this, arguments);
3862 }
3863
3864 if ( Node$$1 ) JSXExpressionContainer.__proto__ = Node$$1;
3865 JSXExpressionContainer.prototype = Object.create( Node$$1 && Node$$1.prototype );
3866 JSXExpressionContainer.prototype.constructor = JSXExpressionContainer;
3867
3868 JSXExpressionContainer.prototype.transpile = function transpile (code, transforms) {
3869 code.remove(this.start, this.expression.start);
3870 code.remove(this.expression.end, this.end);
3871
3872 Node$$1.prototype.transpile.call(this, code, transforms);
3873 };
3874
3875 return JSXExpressionContainer;
3876}(Node));
3877
3878var JSXFragment = (function (JSXElement$$1) {
3879 function JSXFragment () {
3880 JSXElement$$1.apply(this, arguments);
3881 }if ( JSXElement$$1 ) JSXFragment.__proto__ = JSXElement$$1;
3882 JSXFragment.prototype = Object.create( JSXElement$$1 && JSXElement$$1.prototype );
3883 JSXFragment.prototype.constructor = JSXFragment;
3884
3885
3886
3887 return JSXFragment;
3888}(JSXElement));
3889
3890var JSXOpeningElement = (function (Node$$1) {
3891 function JSXOpeningElement () {
3892 Node$$1.apply(this, arguments);
3893 }
3894
3895 if ( Node$$1 ) JSXOpeningElement.__proto__ = Node$$1;
3896 JSXOpeningElement.prototype = Object.create( Node$$1 && Node$$1.prototype );
3897 JSXOpeningElement.prototype.constructor = JSXOpeningElement;
3898
3899 JSXOpeningElement.prototype.transpile = function transpile (code, transforms) {
3900 var this$1 = this;
3901
3902 Node$$1.prototype.transpile.call(this, code, transforms);
3903
3904 code.overwrite(this.start, this.name.start, ((this.program.jsx) + "( "));
3905
3906 var html =
3907 this.name.type === 'JSXIdentifier' &&
3908 this.name.name[0] === this.name.name[0].toLowerCase();
3909 if (html) { code.prependRight(this.name.start, "'"); }
3910
3911 var len = this.attributes.length;
3912 var c = this.name.end;
3913
3914 if (len) {
3915 var i;
3916
3917 var hasSpread = false;
3918 for (i = 0; i < len; i += 1) {
3919 if (this$1.attributes[i].type === 'JSXSpreadAttribute') {
3920 hasSpread = true;
3921 break;
3922 }
3923 }
3924
3925 c = this.attributes[0].end;
3926
3927 for (i = 0; i < len; i += 1) {
3928 var attr = this$1.attributes[i];
3929
3930 if (i > 0) {
3931 if (attr.start === c) { code.prependRight(c, ', '); }
3932 else { code.overwrite(c, attr.start, ', '); }
3933 }
3934
3935 if (hasSpread && attr.type !== 'JSXSpreadAttribute') {
3936 var lastAttr = this$1.attributes[i - 1];
3937 var nextAttr = this$1.attributes[i + 1];
3938
3939 if (!lastAttr || lastAttr.type === 'JSXSpreadAttribute') {
3940 code.prependRight(attr.start, '{ ');
3941 }
3942
3943 if (!nextAttr || nextAttr.type === 'JSXSpreadAttribute') {
3944 code.appendLeft(attr.end, ' }');
3945 }
3946 }
3947
3948 c = attr.end;
3949 }
3950
3951 var after;
3952 var before;
3953 if (hasSpread) {
3954 if (len === 1) {
3955 before = html ? "'," : ',';
3956 } else {
3957 if (!this.program.options.objectAssign) {
3958 throw new CompileError(
3959 "Mixed JSX attributes ending in spread requires specified objectAssign option with 'Object.assign' or polyfill helper.",
3960 this
3961 );
3962 }
3963 before = html
3964 ? ("', " + (this.program.options.objectAssign) + "({},")
3965 : (", " + (this.program.options.objectAssign) + "({},");
3966 after = ')';
3967 }
3968 } else {
3969 before = html ? "', {" : ', {';
3970 after = ' }';
3971 }
3972
3973 code.prependRight(this.name.end, before);
3974
3975 if (after) {
3976 code.appendLeft(this.attributes[len - 1].end, after);
3977 }
3978 } else {
3979 code.appendLeft(this.name.end, html ? "', null" : ", null");
3980 c = this.name.end;
3981 }
3982
3983 if (this.selfClosing) {
3984 code.overwrite(c, this.end, this.attributes.length ? ")" : " )");
3985 } else {
3986 code.remove(c, this.end);
3987 }
3988 };
3989
3990 return JSXOpeningElement;
3991}(Node));
3992
3993var JSXOpeningFragment = (function (Node$$1) {
3994 function JSXOpeningFragment () {
3995 Node$$1.apply(this, arguments);
3996 }
3997
3998 if ( Node$$1 ) JSXOpeningFragment.__proto__ = Node$$1;
3999 JSXOpeningFragment.prototype = Object.create( Node$$1 && Node$$1.prototype );
4000 JSXOpeningFragment.prototype.constructor = JSXOpeningFragment;
4001
4002 JSXOpeningFragment.prototype.transpile = function transpile (code, transforms) {
4003 code.overwrite(this.start, this.end, ((this.program.jsx) + "( React.Fragment, null"));
4004 };
4005
4006 return JSXOpeningFragment;
4007}(Node));
4008
4009var JSXSpreadAttribute = (function (Node$$1) {
4010 function JSXSpreadAttribute () {
4011 Node$$1.apply(this, arguments);
4012 }
4013
4014 if ( Node$$1 ) JSXSpreadAttribute.__proto__ = Node$$1;
4015 JSXSpreadAttribute.prototype = Object.create( Node$$1 && Node$$1.prototype );
4016 JSXSpreadAttribute.prototype.constructor = JSXSpreadAttribute;
4017
4018 JSXSpreadAttribute.prototype.transpile = function transpile (code, transforms) {
4019 code.remove(this.start, this.argument.start);
4020 code.remove(this.argument.end, this.end);
4021
4022 Node$$1.prototype.transpile.call(this, code, transforms);
4023 };
4024
4025 return JSXSpreadAttribute;
4026}(Node));
4027
4028var regjsgen = createCommonjsModule(function (module, exports) {
4029/*!
4030 * regjsgen 0.3.0
4031 * Copyright 2014-2016 Benjamin Tan <https://demoneaux.github.io/>
4032 * Available under MIT license <https://github.com/demoneaux/regjsgen/blob/master/LICENSE>
4033 */
4034(function() {
4035 var objectTypes = {
4036 'function': true,
4037 'object': true
4038 };
4039
4040 // Used as a reference to the global object.
4041 var root = (objectTypes[typeof window] && window) || this;
4042
4043 // Detect free variable `exports`.
4044 var freeExports = objectTypes['object'] && exports;
4045
4046 // Detect free variable `module`.
4047 var freeModule = objectTypes['object'] && module && !module.nodeType && module;
4048
4049 // Detect free variable `global` from Node.js or Browserified code and use it as `root`.
4050 var freeGlobal = freeExports && freeModule && typeof commonjsGlobal == 'object' && commonjsGlobal;
4051 if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
4052 root = freeGlobal;
4053 }
4054
4055 // Used to check objects for own properties.
4056 var hasOwnProperty = Object.prototype.hasOwnProperty;
4057
4058 /*--------------------------------------------------------------------------*/
4059
4060 // Generates strings based on the given code points.
4061 // Based on https://mths.be/fromcodepoint v0.2.0 by @mathias.
4062 var stringFromCharCode = String.fromCharCode;
4063 var floor = Math.floor;
4064 function fromCodePoint() {
4065 var MAX_SIZE = 0x4000;
4066 var codeUnits = [];
4067 var highSurrogate;
4068 var lowSurrogate;
4069 var index = -1;
4070 var length = arguments.length;
4071 if (!length) {
4072 return '';
4073 }
4074 var result = '';
4075 while (++index < length) {
4076 var codePoint = Number(arguments[index]);
4077 if (
4078 !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
4079 codePoint < 0 || // not a valid Unicode code point
4080 codePoint > 0x10FFFF || // not a valid Unicode code point
4081 floor(codePoint) != codePoint // not an integer
4082 ) {
4083 throw RangeError('Invalid code point: ' + codePoint);
4084 }
4085 if (codePoint <= 0xFFFF) {
4086 // BMP code point
4087 codeUnits.push(codePoint);
4088 } else {
4089 // Astral code point; split in surrogate halves
4090 // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
4091 codePoint -= 0x10000;
4092 highSurrogate = (codePoint >> 10) + 0xD800;
4093 lowSurrogate = (codePoint % 0x400) + 0xDC00;
4094 codeUnits.push(highSurrogate, lowSurrogate);
4095 }
4096 if (index + 1 == length || codeUnits.length > MAX_SIZE) {
4097 result += stringFromCharCode.apply(null, codeUnits);
4098 codeUnits.length = 0;
4099 }
4100 }
4101 return result;
4102 }
4103
4104 /*--------------------------------------------------------------------------*/
4105
4106 // Ensures that nodes have the correct types.
4107 var assertTypeRegexMap = {};
4108 function assertType(type, expected) {
4109 if (expected.indexOf('|') == -1) {
4110 if (type == expected) {
4111 return;
4112 }
4113
4114 throw Error('Invalid node type: ' + type + '; expected type: ' + expected);
4115 }
4116
4117 expected = hasOwnProperty.call(assertTypeRegexMap, expected)
4118 ? assertTypeRegexMap[expected]
4119 : (assertTypeRegexMap[expected] = RegExp('^(?:' + expected + ')$'));
4120
4121 if (expected.test(type)) {
4122 return;
4123 }
4124
4125 throw Error('Invalid node type: ' + type + '; expected types: ' + expected);
4126 }
4127
4128 /*--------------------------------------------------------------------------*/
4129
4130 // Generates a regular expression string based on an AST.
4131 function generate(node) {
4132 var type = node.type;
4133
4134 if (hasOwnProperty.call(generators, type)) {
4135 return generators[type](node);
4136 }
4137
4138 throw Error('Invalid node type: ' + type);
4139 }
4140
4141 /*--------------------------------------------------------------------------*/
4142
4143 function generateAlternative(node) {
4144 assertType(node.type, 'alternative');
4145
4146 var terms = node.body,
4147 i = -1,
4148 length = terms.length,
4149 result = '';
4150
4151 while (++i < length) {
4152 result += generateTerm(terms[i]);
4153 }
4154
4155 return result;
4156 }
4157
4158 function generateAnchor(node) {
4159 assertType(node.type, 'anchor');
4160
4161 switch (node.kind) {
4162 case 'start':
4163 return '^';
4164 case 'end':
4165 return '$';
4166 case 'boundary':
4167 return '\\b';
4168 case 'not-boundary':
4169 return '\\B';
4170 default:
4171 throw Error('Invalid assertion');
4172 }
4173 }
4174
4175 function generateAtom(node) {
4176 assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
4177
4178 return generate(node);
4179 }
4180
4181 function generateCharacterClass(node) {
4182 assertType(node.type, 'characterClass');
4183
4184 var classRanges = node.body,
4185 i = -1,
4186 length = classRanges.length,
4187 result = '';
4188
4189 if (node.negative) {
4190 result += '^';
4191 }
4192
4193 while (++i < length) {
4194 result += generateClassAtom(classRanges[i]);
4195 }
4196
4197 return '[' + result + ']';
4198 }
4199
4200 function generateCharacterClassEscape(node) {
4201 assertType(node.type, 'characterClassEscape');
4202
4203 return '\\' + node.value;
4204 }
4205
4206 function generateUnicodePropertyEscape(node) {
4207 assertType(node.type, 'unicodePropertyEscape');
4208
4209 return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
4210 }
4211
4212 function generateCharacterClassRange(node) {
4213 assertType(node.type, 'characterClassRange');
4214
4215 var min = node.min,
4216 max = node.max;
4217
4218 if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
4219 throw Error('Invalid character class range');
4220 }
4221
4222 return generateClassAtom(min) + '-' + generateClassAtom(max);
4223 }
4224
4225 function generateClassAtom(node) {
4226 assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value');
4227
4228 return generate(node);
4229 }
4230
4231 function generateDisjunction(node) {
4232 assertType(node.type, 'disjunction');
4233
4234 var body = node.body,
4235 i = -1,
4236 length = body.length,
4237 result = '';
4238
4239 while (++i < length) {
4240 if (i != 0) {
4241 result += '|';
4242 }
4243 result += generate(body[i]);
4244 }
4245
4246 return result;
4247 }
4248
4249 function generateDot(node) {
4250 assertType(node.type, 'dot');
4251
4252 return '.';
4253 }
4254
4255 function generateGroup(node) {
4256 assertType(node.type, 'group');
4257
4258 var result = '';
4259
4260 switch (node.behavior) {
4261 case 'normal':
4262 break;
4263 case 'ignore':
4264 result += '?:';
4265 break;
4266 case 'lookahead':
4267 result += '?=';
4268 break;
4269 case 'negativeLookahead':
4270 result += '?!';
4271 break;
4272 default:
4273 throw Error('Invalid behaviour: ' + node.behaviour);
4274 }
4275
4276 var body = node.body,
4277 i = -1,
4278 length = body.length;
4279
4280 while (++i < length) {
4281 result += generate(body[i]);
4282 }
4283
4284 return '(' + result + ')';
4285 }
4286
4287 function generateQuantifier(node) {
4288 assertType(node.type, 'quantifier');
4289
4290 var quantifier = '',
4291 min = node.min,
4292 max = node.max;
4293
4294 if (max == null) {
4295 if (min == 0) {
4296 quantifier = '*';
4297 } else if (min == 1) {
4298 quantifier = '+';
4299 } else {
4300 quantifier = '{' + min + ',}';
4301 }
4302 } else if (min == max) {
4303 quantifier = '{' + min + '}';
4304 } else if (min == 0 && max == 1) {
4305 quantifier = '?';
4306 } else {
4307 quantifier = '{' + min + ',' + max + '}';
4308 }
4309
4310 if (!node.greedy) {
4311 quantifier += '?';
4312 }
4313
4314 return generateAtom(node.body[0]) + quantifier;
4315 }
4316
4317 function generateReference(node) {
4318 assertType(node.type, 'reference');
4319
4320 return '\\' + node.matchIndex;
4321 }
4322
4323 function generateTerm(node) {
4324 assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value');
4325
4326 return generate(node);
4327 }
4328
4329 function generateValue(node) {
4330 assertType(node.type, 'value');
4331
4332 var kind = node.kind,
4333 codePoint = node.codePoint;
4334
4335 switch (kind) {
4336 case 'controlLetter':
4337 return '\\c' + fromCodePoint(codePoint + 64);
4338 case 'hexadecimalEscape':
4339 return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
4340 case 'identifier':
4341 return '\\' + fromCodePoint(codePoint);
4342 case 'null':
4343 return '\\' + codePoint;
4344 case 'octal':
4345 return '\\' + codePoint.toString(8);
4346 case 'singleEscape':
4347 switch (codePoint) {
4348 case 0x0008:
4349 return '\\b';
4350 case 0x0009:
4351 return '\\t';
4352 case 0x000A:
4353 return '\\n';
4354 case 0x000B:
4355 return '\\v';
4356 case 0x000C:
4357 return '\\f';
4358 case 0x000D:
4359 return '\\r';
4360 default:
4361 throw Error('Invalid codepoint: ' + codePoint);
4362 }
4363 case 'symbol':
4364 return fromCodePoint(codePoint);
4365 case 'unicodeEscape':
4366 return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
4367 case 'unicodeCodePointEscape':
4368 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
4369 default:
4370 throw Error('Unsupported node kind: ' + kind);
4371 }
4372 }
4373
4374 /*--------------------------------------------------------------------------*/
4375
4376 // Used to generate strings for each node type.
4377 var generators = {
4378 'alternative': generateAlternative,
4379 'anchor': generateAnchor,
4380 'characterClass': generateCharacterClass,
4381 'characterClassEscape': generateCharacterClassEscape,
4382 'characterClassRange': generateCharacterClassRange,
4383 'unicodePropertyEscape': generateUnicodePropertyEscape,
4384 'disjunction': generateDisjunction,
4385 'dot': generateDot,
4386 'group': generateGroup,
4387 'quantifier': generateQuantifier,
4388 'reference': generateReference,
4389 'value': generateValue
4390 };
4391
4392 /*--------------------------------------------------------------------------*/
4393
4394 // Export regjsgen.
4395 // Some AMD build optimizers, like r.js, check for condition patterns like the following:
4396 if (typeof undefined == 'function' && typeof undefined.amd == 'object' && undefined.amd) {
4397 // Define as an anonymous module so it can be aliased through path mapping.
4398 undefined(function() {
4399 return {
4400 'generate': generate
4401 };
4402 });
4403 }
4404 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
4405 else if (freeExports && freeModule) {
4406 // Export for CommonJS support.
4407 freeExports.generate = generate;
4408 }
4409 else {
4410 // Export to the global object.
4411 root.regjsgen = {
4412 'generate': generate
4413 };
4414 }
4415}.call(commonjsGlobal));
4416});
4417
4418var parser = createCommonjsModule(function (module) {
4419// regjsparser
4420//
4421// ==================================================================
4422//
4423// See ECMA-262 Standard: 15.10.1
4424//
4425// NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the
4426// term "Anchor" is used.
4427//
4428// Pattern ::
4429// Disjunction
4430//
4431// Disjunction ::
4432// Alternative
4433// Alternative | Disjunction
4434//
4435// Alternative ::
4436// [empty]
4437// Alternative Term
4438//
4439// Term ::
4440// Anchor
4441// Atom
4442// Atom Quantifier
4443//
4444// Anchor ::
4445// ^
4446// $
4447// \ b
4448// \ B
4449// ( ? = Disjunction )
4450// ( ? ! Disjunction )
4451//
4452// Quantifier ::
4453// QuantifierPrefix
4454// QuantifierPrefix ?
4455//
4456// QuantifierPrefix ::
4457// *
4458// +
4459// ?
4460// { DecimalDigits }
4461// { DecimalDigits , }
4462// { DecimalDigits , DecimalDigits }
4463//
4464// Atom ::
4465// PatternCharacter
4466// .
4467// \ AtomEscape
4468// CharacterClass
4469// ( Disjunction )
4470// ( ? : Disjunction )
4471//
4472// PatternCharacter ::
4473// SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |
4474//
4475// AtomEscape ::
4476// DecimalEscape
4477// CharacterEscape
4478// CharacterClassEscape
4479//
4480// CharacterEscape[U] ::
4481// ControlEscape
4482// c ControlLetter
4483// HexEscapeSequence
4484// RegExpUnicodeEscapeSequence[?U] (ES6)
4485// IdentityEscape[?U]
4486//
4487// ControlEscape ::
4488// one of f n r t v
4489// ControlLetter ::
4490// one of
4491// a b c d e f g h i j k l m n o p q r s t u v w x y z
4492// A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
4493//
4494// IdentityEscape ::
4495// SourceCharacter but not IdentifierPart
4496// <ZWJ>
4497// <ZWNJ>
4498//
4499// DecimalEscape ::
4500// DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
4501//
4502// CharacterClassEscape ::
4503// one of d D s S w W
4504//
4505// CharacterClass ::
4506// [ [lookahead ∉ {^}] ClassRanges ]
4507// [ ^ ClassRanges ]
4508//
4509// ClassRanges ::
4510// [empty]
4511// NonemptyClassRanges
4512//
4513// NonemptyClassRanges ::
4514// ClassAtom
4515// ClassAtom NonemptyClassRangesNoDash
4516// ClassAtom - ClassAtom ClassRanges
4517//
4518// NonemptyClassRangesNoDash ::
4519// ClassAtom
4520// ClassAtomNoDash NonemptyClassRangesNoDash
4521// ClassAtomNoDash - ClassAtom ClassRanges
4522//
4523// ClassAtom ::
4524// -
4525// ClassAtomNoDash
4526//
4527// ClassAtomNoDash ::
4528// SourceCharacter but not one of \ or ] or -
4529// \ ClassEscape
4530//
4531// ClassEscape ::
4532// DecimalEscape
4533// b
4534// CharacterEscape
4535// CharacterClassEscape
4536
4537(function() {
4538
4539 function parse(str, flags, features) {
4540 if (!features) {
4541 features = {};
4542 }
4543 function addRaw(node) {
4544 node.raw = str.substring(node.range[0], node.range[1]);
4545 return node;
4546 }
4547
4548 function updateRawStart(node, start) {
4549 node.range[0] = start;
4550 return addRaw(node);
4551 }
4552
4553 function createAnchor(kind, rawLength) {
4554 return addRaw({
4555 type: 'anchor',
4556 kind: kind,
4557 range: [
4558 pos - rawLength,
4559 pos
4560 ]
4561 });
4562 }
4563
4564 function createValue(kind, codePoint, from, to) {
4565 return addRaw({
4566 type: 'value',
4567 kind: kind,
4568 codePoint: codePoint,
4569 range: [from, to]
4570 });
4571 }
4572
4573 function createEscaped(kind, codePoint, value, fromOffset) {
4574 fromOffset = fromOffset || 0;
4575 return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);
4576 }
4577
4578 function createCharacter(matches) {
4579 var _char = matches[0];
4580 var first = _char.charCodeAt(0);
4581 if (hasUnicodeFlag) {
4582 var second;
4583 if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
4584 second = lookahead().charCodeAt(0);
4585 if (second >= 0xDC00 && second <= 0xDFFF) {
4586 // Unicode surrogate pair
4587 pos++;
4588 return createValue(
4589 'symbol',
4590 (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,
4591 pos - 2, pos);
4592 }
4593 }
4594 }
4595 return createValue('symbol', first, pos - 1, pos);
4596 }
4597
4598 function createDisjunction(alternatives, from, to) {
4599 return addRaw({
4600 type: 'disjunction',
4601 body: alternatives,
4602 range: [
4603 from,
4604 to
4605 ]
4606 });
4607 }
4608
4609 function createDot() {
4610 return addRaw({
4611 type: 'dot',
4612 range: [
4613 pos - 1,
4614 pos
4615 ]
4616 });
4617 }
4618
4619 function createCharacterClassEscape(value) {
4620 return addRaw({
4621 type: 'characterClassEscape',
4622 value: value,
4623 range: [
4624 pos - 2,
4625 pos
4626 ]
4627 });
4628 }
4629
4630 function createReference(matchIndex) {
4631 return addRaw({
4632 type: 'reference',
4633 matchIndex: parseInt(matchIndex, 10),
4634 range: [
4635 pos - 1 - matchIndex.length,
4636 pos
4637 ]
4638 });
4639 }
4640
4641 function createGroup(behavior, disjunction, from, to) {
4642 return addRaw({
4643 type: 'group',
4644 behavior: behavior,
4645 body: disjunction,
4646 range: [
4647 from,
4648 to
4649 ]
4650 });
4651 }
4652
4653 function createQuantifier(min, max, from, to) {
4654 if (to == null) {
4655 from = pos - 1;
4656 to = pos;
4657 }
4658
4659 return addRaw({
4660 type: 'quantifier',
4661 min: min,
4662 max: max,
4663 greedy: true,
4664 body: null, // set later on
4665 range: [
4666 from,
4667 to
4668 ]
4669 });
4670 }
4671
4672 function createAlternative(terms, from, to) {
4673 return addRaw({
4674 type: 'alternative',
4675 body: terms,
4676 range: [
4677 from,
4678 to
4679 ]
4680 });
4681 }
4682
4683 function createCharacterClass(classRanges, negative, from, to) {
4684 return addRaw({
4685 type: 'characterClass',
4686 body: classRanges,
4687 negative: negative,
4688 range: [
4689 from,
4690 to
4691 ]
4692 });
4693 }
4694
4695 function createClassRange(min, max, from, to) {
4696 // See 15.10.2.15:
4697 if (min.codePoint > max.codePoint) {
4698 bail('invalid range in character class', min.raw + '-' + max.raw, from, to);
4699 }
4700
4701 return addRaw({
4702 type: 'characterClassRange',
4703 min: min,
4704 max: max,
4705 range: [
4706 from,
4707 to
4708 ]
4709 });
4710 }
4711
4712 function flattenBody(body) {
4713 if (body.type === 'alternative') {
4714 return body.body;
4715 } else {
4716 return [body];
4717 }
4718 }
4719
4720 function incr(amount) {
4721 amount = (amount || 1);
4722 var res = str.substring(pos, pos + amount);
4723 pos += (amount || 1);
4724 return res;
4725 }
4726
4727 function skip(value) {
4728 if (!match(value)) {
4729 bail('character', value);
4730 }
4731 }
4732
4733 function match(value) {
4734 if (str.indexOf(value, pos) === pos) {
4735 return incr(value.length);
4736 }
4737 }
4738
4739 function lookahead() {
4740 return str[pos];
4741 }
4742
4743 function current(value) {
4744 return str.indexOf(value, pos) === pos;
4745 }
4746
4747 function next(value) {
4748 return str[pos + 1] === value;
4749 }
4750
4751 function matchReg(regExp) {
4752 var subStr = str.substring(pos);
4753 var res = subStr.match(regExp);
4754 if (res) {
4755 res.range = [];
4756 res.range[0] = pos;
4757 incr(res[0].length);
4758 res.range[1] = pos;
4759 }
4760 return res;
4761 }
4762
4763 function parseDisjunction() {
4764 // Disjunction ::
4765 // Alternative
4766 // Alternative | Disjunction
4767 var res = [], from = pos;
4768 res.push(parseAlternative());
4769
4770 while (match('|')) {
4771 res.push(parseAlternative());
4772 }
4773
4774 if (res.length === 1) {
4775 return res[0];
4776 }
4777
4778 return createDisjunction(res, from, pos);
4779 }
4780
4781 function parseAlternative() {
4782 var res = [], from = pos;
4783 var term;
4784
4785 // Alternative ::
4786 // [empty]
4787 // Alternative Term
4788 while (term = parseTerm()) {
4789 res.push(term);
4790 }
4791
4792 if (res.length === 1) {
4793 return res[0];
4794 }
4795
4796 return createAlternative(res, from, pos);
4797 }
4798
4799 function parseTerm() {
4800 // Term ::
4801 // Anchor
4802 // Atom
4803 // Atom Quantifier
4804
4805 if (pos >= str.length || current('|') || current(')')) {
4806 return null; /* Means: The term is empty */
4807 }
4808
4809 var anchor = parseAnchor();
4810
4811 if (anchor) {
4812 return anchor;
4813 }
4814
4815 var atom = parseAtom();
4816 if (!atom) {
4817 bail('Expected atom');
4818 }
4819 var quantifier = parseQuantifier() || false;
4820 if (quantifier) {
4821 quantifier.body = flattenBody(atom);
4822 // The quantifier contains the atom. Therefore, the beginning of the
4823 // quantifier range is given by the beginning of the atom.
4824 updateRawStart(quantifier, atom.range[0]);
4825 return quantifier;
4826 }
4827 return atom;
4828 }
4829
4830 function parseGroup(matchA, typeA, matchB, typeB) {
4831 var type = null, from = pos;
4832
4833 if (match(matchA)) {
4834 type = typeA;
4835 } else if (match(matchB)) {
4836 type = typeB;
4837 } else {
4838 return false;
4839 }
4840
4841 var body = parseDisjunction();
4842 if (!body) {
4843 bail('Expected disjunction');
4844 }
4845 skip(')');
4846 var group = createGroup(type, flattenBody(body), from, pos);
4847
4848 if (type == 'normal') {
4849 // Keep track of the number of closed groups. This is required for
4850 // parseDecimalEscape(). In case the string is parsed a second time the
4851 // value already holds the total count and no incrementation is required.
4852 if (firstIteration) {
4853 closedCaptureCounter++;
4854 }
4855 }
4856 return group;
4857 }
4858
4859 function parseAnchor() {
4860 // Anchor ::
4861 // ^
4862 // $
4863 // \ b
4864 // \ B
4865 // ( ? = Disjunction )
4866 // ( ? ! Disjunction )
4867 if (match('^')) {
4868 return createAnchor('start', 1 /* rawLength */);
4869 } else if (match('$')) {
4870 return createAnchor('end', 1 /* rawLength */);
4871 } else if (match('\\b')) {
4872 return createAnchor('boundary', 2 /* rawLength */);
4873 } else if (match('\\B')) {
4874 return createAnchor('not-boundary', 2 /* rawLength */);
4875 } else {
4876 return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');
4877 }
4878 }
4879
4880 function parseQuantifier() {
4881 // Quantifier ::
4882 // QuantifierPrefix
4883 // QuantifierPrefix ?
4884 //
4885 // QuantifierPrefix ::
4886 // *
4887 // +
4888 // ?
4889 // { DecimalDigits }
4890 // { DecimalDigits , }
4891 // { DecimalDigits , DecimalDigits }
4892
4893 var res, from = pos;
4894 var quantifier;
4895 var min, max;
4896
4897 if (match('*')) {
4898 quantifier = createQuantifier(0);
4899 }
4900 else if (match('+')) {
4901 quantifier = createQuantifier(1);
4902 }
4903 else if (match('?')) {
4904 quantifier = createQuantifier(0, 1);
4905 }
4906 else if (res = matchReg(/^\{([0-9]+)\}/)) {
4907 min = parseInt(res[1], 10);
4908 quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
4909 }
4910 else if (res = matchReg(/^\{([0-9]+),\}/)) {
4911 min = parseInt(res[1], 10);
4912 quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
4913 }
4914 else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
4915 min = parseInt(res[1], 10);
4916 max = parseInt(res[2], 10);
4917 if (min > max) {
4918 bail('numbers out of order in {} quantifier', '', from, pos);
4919 }
4920 quantifier = createQuantifier(min, max, res.range[0], res.range[1]);
4921 }
4922
4923 if (quantifier) {
4924 if (match('?')) {
4925 quantifier.greedy = false;
4926 quantifier.range[1] += 1;
4927 }
4928 }
4929
4930 return quantifier;
4931 }
4932
4933 function parseAtom() {
4934 // Atom ::
4935 // PatternCharacter
4936 // .
4937 // \ AtomEscape
4938 // CharacterClass
4939 // ( Disjunction )
4940 // ( ? : Disjunction )
4941
4942 var res;
4943
4944 // jviereck: allow ']', '}' here as well to be compatible with browser's
4945 // implementations: ']'.match(/]/);
4946 // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) {
4947 if (res = matchReg(/^[^^$\\.*+?(){[|]/)) {
4948 // PatternCharacter
4949 return createCharacter(res);
4950 }
4951 else if (match('.')) {
4952 // .
4953 return createDot();
4954 }
4955 else if (match('\\')) {
4956 // \ AtomEscape
4957 res = parseAtomEscape();
4958 if (!res) {
4959 bail('atomEscape');
4960 }
4961 return res;
4962 }
4963 else if (res = parseCharacterClass()) {
4964 return res;
4965 }
4966 else {
4967 // ( Disjunction )
4968 // ( ? : Disjunction )
4969 return parseGroup('(?:', 'ignore', '(', 'normal');
4970 }
4971 }
4972
4973 function parseUnicodeSurrogatePairEscape(firstEscape) {
4974 if (hasUnicodeFlag) {
4975 var first, second;
4976 if (firstEscape.kind == 'unicodeEscape' &&
4977 (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&
4978 current('\\') && next('u') ) {
4979 var prevPos = pos;
4980 pos++;
4981 var secondEscape = parseClassEscape();
4982 if (secondEscape.kind == 'unicodeEscape' &&
4983 (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {
4984 // Unicode surrogate pair
4985 firstEscape.range[1] = secondEscape.range[1];
4986 firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
4987 firstEscape.type = 'value';
4988 firstEscape.kind = 'unicodeCodePointEscape';
4989 addRaw(firstEscape);
4990 }
4991 else {
4992 pos = prevPos;
4993 }
4994 }
4995 }
4996 return firstEscape;
4997 }
4998
4999 function parseClassEscape() {
5000 return parseAtomEscape(true);
5001 }
5002
5003 function parseAtomEscape(insideCharacterClass) {
5004 // AtomEscape ::
5005 // DecimalEscape
5006 // CharacterEscape
5007 // CharacterClassEscape
5008
5009 var res, from = pos;
5010
5011 res = parseDecimalEscape();
5012 if (res) {
5013 return res;
5014 }
5015
5016 // For ClassEscape
5017 if (insideCharacterClass) {
5018 if (match('b')) {
5019 // 15.10.2.19
5020 // The production ClassEscape :: b evaluates by returning the
5021 // CharSet containing the one character <BS> (Unicode value 0008).
5022 return createEscaped('singleEscape', 0x0008, '\\b');
5023 } else if (match('B')) {
5024 bail('\\B not possible inside of CharacterClass', '', from);
5025 }
5026 }
5027
5028 res = parseCharacterEscape();
5029
5030 return res;
5031 }
5032
5033
5034 function parseDecimalEscape() {
5035 // DecimalEscape ::
5036 // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
5037 // CharacterClassEscape :: one of d D s S w W
5038
5039 var res, match;
5040
5041 if (res = matchReg(/^(?!0)\d+/)) {
5042 match = res[0];
5043 var refIdx = parseInt(res[0], 10);
5044 if (refIdx <= closedCaptureCounter) {
5045 // If the number is smaller than the normal-groups found so
5046 // far, then it is a reference...
5047 return createReference(res[0]);
5048 } else {
5049 // ... otherwise it needs to be interpreted as a octal (if the
5050 // number is in an octal format). If it is NOT octal format,
5051 // then the slash is ignored and the number is matched later
5052 // as normal characters.
5053
5054 // Recall the negative decision to decide if the input must be parsed
5055 // a second time with the total normal-groups.
5056 backrefDenied.push(refIdx);
5057
5058 // Reset the position again, as maybe only parts of the previous
5059 // matched numbers are actual octal numbers. E.g. in '019' only
5060 // the '01' should be matched.
5061 incr(-res[0].length);
5062 if (res = matchReg(/^[0-7]{1,3}/)) {
5063 return createEscaped('octal', parseInt(res[0], 8), res[0], 1);
5064 } else {
5065 // If we end up here, we have a case like /\91/. Then the
5066 // first slash is to be ignored and the 9 & 1 to be treated
5067 // like ordinary characters. Create a character for the
5068 // first number only here - other number-characters
5069 // (if available) will be matched later.
5070 res = createCharacter(matchReg(/^[89]/));
5071 return updateRawStart(res, res.range[0] - 1);
5072 }
5073 }
5074 }
5075 // Only allow octal numbers in the following. All matched numbers start
5076 // with a zero (if the do not, the previous if-branch is executed).
5077 // If the number is not octal format and starts with zero (e.g. `091`)
5078 // then only the zeros `0` is treated here and the `91` are ordinary
5079 // characters.
5080 // Example:
5081 // /\091/.exec('\091')[0].length === 3
5082 else if (res = matchReg(/^[0-7]{1,3}/)) {
5083 match = res[0];
5084 if (/^0{1,3}$/.test(match)) {
5085 // If they are all zeros, then only take the first one.
5086 return createEscaped('null', 0x0000, '0', match.length + 1);
5087 } else {
5088 return createEscaped('octal', parseInt(match, 8), match, 1);
5089 }
5090 } else if (res = matchReg(/^[dDsSwW]/)) {
5091 return createCharacterClassEscape(res[0]);
5092 }
5093 return false;
5094 }
5095
5096 function parseCharacterEscape() {
5097 // CharacterEscape ::
5098 // ControlEscape
5099 // c ControlLetter
5100 // HexEscapeSequence
5101 // UnicodeEscapeSequence
5102 // IdentityEscape
5103
5104 var res;
5105 if (res = matchReg(/^[fnrtv]/)) {
5106 // ControlEscape
5107 var codePoint = 0;
5108 switch (res[0]) {
5109 case 't': codePoint = 0x009; break;
5110 case 'n': codePoint = 0x00A; break;
5111 case 'v': codePoint = 0x00B; break;
5112 case 'f': codePoint = 0x00C; break;
5113 case 'r': codePoint = 0x00D; break;
5114 }
5115 return createEscaped('singleEscape', codePoint, '\\' + res[0]);
5116 } else if (res = matchReg(/^c([a-zA-Z])/)) {
5117 // c ControlLetter
5118 return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);
5119 } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) {
5120 // HexEscapeSequence
5121 return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2);
5122 } else if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {
5123 // UnicodeEscapeSequence
5124 return parseUnicodeSurrogatePairEscape(
5125 createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2)
5126 );
5127 } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {
5128 // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)
5129 return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);
5130 } else if (features.unicodePropertyEscape && hasUnicodeFlag && (res = matchReg(/^([pP])\{([^\}]+)\}/))) {
5131 // https://github.com/jviereck/regjsparser/issues/77
5132 return addRaw({
5133 type: 'unicodePropertyEscape',
5134 negative: res[1] === 'P',
5135 value: res[2],
5136 range: [res.range[0] - 1, res.range[1]],
5137 raw: res[0]
5138 });
5139 } else {
5140 // IdentityEscape
5141 return parseIdentityEscape();
5142 }
5143 }
5144
5145 // Taken from the Esprima parser.
5146 function isIdentifierPart(ch) {
5147 // Generated by `tools/generate-identifier-regex.js`.
5148 var NonAsciiIdentifierPart = new RegExp('[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B2\u08E4-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2D\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]');
5149
5150 return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
5151 (ch >= 65 && ch <= 90) || // A..Z
5152 (ch >= 97 && ch <= 122) || // a..z
5153 (ch >= 48 && ch <= 57) || // 0..9
5154 (ch === 92) || // \ (backslash)
5155 ((ch >= 0x80) && NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
5156 }
5157
5158 function parseIdentityEscape() {
5159 // IdentityEscape ::
5160 // SourceCharacter but not IdentifierPart
5161 // <ZWJ>
5162 // <ZWNJ>
5163
5164 var ZWJ = '\u200C';
5165 var ZWNJ = '\u200D';
5166
5167 var tmp;
5168
5169 if (!isIdentifierPart(lookahead())) {
5170 tmp = incr();
5171 return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1);
5172 }
5173
5174 if (match(ZWJ)) {
5175 // <ZWJ>
5176 return createEscaped('identifier', 0x200C, ZWJ);
5177 } else if (match(ZWNJ)) {
5178 // <ZWNJ>
5179 return createEscaped('identifier', 0x200D, ZWNJ);
5180 }
5181
5182 return null;
5183 }
5184
5185 function parseCharacterClass() {
5186 // CharacterClass ::
5187 // [ [lookahead ∉ {^}] ClassRanges ]
5188 // [ ^ ClassRanges ]
5189
5190 var res, from = pos;
5191 if (res = matchReg(/^\[\^/)) {
5192 res = parseClassRanges();
5193 skip(']');
5194 return createCharacterClass(res, true, from, pos);
5195 } else if (match('[')) {
5196 res = parseClassRanges();
5197 skip(']');
5198 return createCharacterClass(res, false, from, pos);
5199 }
5200
5201 return null;
5202 }
5203
5204 function parseClassRanges() {
5205 // ClassRanges ::
5206 // [empty]
5207 // NonemptyClassRanges
5208
5209 var res;
5210 if (current(']')) {
5211 // Empty array means nothing insinde of the ClassRange.
5212 return [];
5213 } else {
5214 res = parseNonemptyClassRanges();
5215 if (!res) {
5216 bail('nonEmptyClassRanges');
5217 }
5218 return res;
5219 }
5220 }
5221
5222 function parseHelperClassRanges(atom) {
5223 var from, to, res;
5224 if (current('-') && !next(']')) {
5225 // ClassAtom - ClassAtom ClassRanges
5226 skip('-');
5227
5228 res = parseClassAtom();
5229 if (!res) {
5230 bail('classAtom');
5231 }
5232 to = pos;
5233 var classRanges = parseClassRanges();
5234 if (!classRanges) {
5235 bail('classRanges');
5236 }
5237 from = atom.range[0];
5238 if (classRanges.type === 'empty') {
5239 return [createClassRange(atom, res, from, to)];
5240 }
5241 return [createClassRange(atom, res, from, to)].concat(classRanges);
5242 }
5243
5244 res = parseNonemptyClassRangesNoDash();
5245 if (!res) {
5246 bail('nonEmptyClassRangesNoDash');
5247 }
5248
5249 return [atom].concat(res);
5250 }
5251
5252 function parseNonemptyClassRanges() {
5253 // NonemptyClassRanges ::
5254 // ClassAtom
5255 // ClassAtom NonemptyClassRangesNoDash
5256 // ClassAtom - ClassAtom ClassRanges
5257
5258 var atom = parseClassAtom();
5259 if (!atom) {
5260 bail('classAtom');
5261 }
5262
5263 if (current(']')) {
5264 // ClassAtom
5265 return [atom];
5266 }
5267
5268 // ClassAtom NonemptyClassRangesNoDash
5269 // ClassAtom - ClassAtom ClassRanges
5270 return parseHelperClassRanges(atom);
5271 }
5272
5273 function parseNonemptyClassRangesNoDash() {
5274 // NonemptyClassRangesNoDash ::
5275 // ClassAtom
5276 // ClassAtomNoDash NonemptyClassRangesNoDash
5277 // ClassAtomNoDash - ClassAtom ClassRanges
5278
5279 var res = parseClassAtom();
5280 if (!res) {
5281 bail('classAtom');
5282 }
5283 if (current(']')) {
5284 // ClassAtom
5285 return res;
5286 }
5287
5288 // ClassAtomNoDash NonemptyClassRangesNoDash
5289 // ClassAtomNoDash - ClassAtom ClassRanges
5290 return parseHelperClassRanges(res);
5291 }
5292
5293 function parseClassAtom() {
5294 // ClassAtom ::
5295 // -
5296 // ClassAtomNoDash
5297 if (match('-')) {
5298 return createCharacter('-');
5299 } else {
5300 return parseClassAtomNoDash();
5301 }
5302 }
5303
5304 function parseClassAtomNoDash() {
5305 // ClassAtomNoDash ::
5306 // SourceCharacter but not one of \ or ] or -
5307 // \ ClassEscape
5308
5309 var res;
5310 if (res = matchReg(/^[^\\\]-]/)) {
5311 return createCharacter(res[0]);
5312 } else if (match('\\')) {
5313 res = parseClassEscape();
5314 if (!res) {
5315 bail('classEscape');
5316 }
5317
5318 return parseUnicodeSurrogatePairEscape(res);
5319 }
5320 }
5321
5322 function bail(message, details, from, to) {
5323 from = from == null ? pos : from;
5324 to = to == null ? from : to;
5325
5326 var contextStart = Math.max(0, from - 10);
5327 var contextEnd = Math.min(to + 10, str.length);
5328
5329 // Output a bit of context and a line pointing to where our error is.
5330 //
5331 // We are assuming that there are no actual newlines in the content as this is a regular expression.
5332 var context = ' ' + str.substring(contextStart, contextEnd);
5333 var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^';
5334
5335 throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer);
5336 }
5337
5338 var backrefDenied = [];
5339 var closedCaptureCounter = 0;
5340 var firstIteration = true;
5341 var hasUnicodeFlag = (flags || "").indexOf("u") !== -1;
5342 var pos = 0;
5343
5344 // Convert the input to a string and treat the empty string special.
5345 str = String(str);
5346 if (str === '') {
5347 str = '(?:)';
5348 }
5349
5350 var result = parseDisjunction();
5351
5352 if (result.range[1] !== str.length) {
5353 bail('Could not parse entire input - got stuck', '', result.range[1]);
5354 }
5355
5356 // The spec requires to interpret the `\2` in `/\2()()/` as backreference.
5357 // As the parser collects the number of capture groups as the string is
5358 // parsed it is impossible to make these decisions at the point when the
5359 // `\2` is handled. In case the local decision turns out to be wrong after
5360 // the parsing has finished, the input string is parsed a second time with
5361 // the total number of capture groups set.
5362 //
5363 // SEE: https://github.com/jviereck/regjsparser/issues/70
5364 for (var i = 0; i < backrefDenied.length; i++) {
5365 if (backrefDenied[i] <= closedCaptureCounter) {
5366 // Parse the input a second time.
5367 pos = 0;
5368 firstIteration = false;
5369 return parseDisjunction();
5370 }
5371 }
5372
5373 return result;
5374 }
5375
5376 var regjsparser = {
5377 parse: parse
5378 };
5379
5380 if ('object' !== 'undefined' && module.exports) {
5381 module.exports = regjsparser;
5382 } else {
5383 window.regjsparser = regjsparser;
5384 }
5385
5386}());
5387});
5388
5389var regenerate = createCommonjsModule(function (module, exports) {
5390/*! https://mths.be/regenerate v1.3.3 by @mathias | MIT license */
5391(function(root) {
5392
5393 // Detect free variables `exports`.
5394 var freeExports = 'object' == 'object' && exports;
5395
5396 // Detect free variable `module`.
5397 var freeModule = 'object' == 'object' && module &&
5398 module.exports == freeExports && module;
5399
5400 // Detect free variable `global`, from Node.js/io.js or Browserified code,
5401 // and use it as `root`.
5402 var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
5403 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
5404 root = freeGlobal;
5405 }
5406
5407 /*--------------------------------------------------------------------------*/
5408
5409 var ERRORS = {
5410 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
5411 'to the `start` value.',
5412 'codePointRange': 'Invalid code point value. Code points range from ' +
5413 'U+000000 to U+10FFFF.'
5414 };
5415
5416 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
5417 var HIGH_SURROGATE_MIN = 0xD800;
5418 var HIGH_SURROGATE_MAX = 0xDBFF;
5419 var LOW_SURROGATE_MIN = 0xDC00;
5420 var LOW_SURROGATE_MAX = 0xDFFF;
5421
5422 // In Regenerate output, `\0` is never preceded by `\` because we sort by
5423 // code point value, so let’s keep this regular expression simple.
5424 var regexNull = /\\x00([^0123456789]|$)/g;
5425
5426 var object = {};
5427 var hasOwnProperty = object.hasOwnProperty;
5428 var extend = function(destination, source) {
5429 var key;
5430 for (key in source) {
5431 if (hasOwnProperty.call(source, key)) {
5432 destination[key] = source[key];
5433 }
5434 }
5435 return destination;
5436 };
5437
5438 var forEach = function(array, callback) {
5439 var index = -1;
5440 var length = array.length;
5441 while (++index < length) {
5442 callback(array[index], index);
5443 }
5444 };
5445
5446 var toString = object.toString;
5447 var isArray = function(value) {
5448 return toString.call(value) == '[object Array]';
5449 };
5450 var isNumber = function(value) {
5451 return typeof value == 'number' ||
5452 toString.call(value) == '[object Number]';
5453 };
5454
5455 // This assumes that `number` is a positive integer that `toString()`s nicely
5456 // (which is the case for all code point values).
5457 var zeroes = '0000';
5458 var pad = function(number, totalCharacters) {
5459 var string = String(number);
5460 return string.length < totalCharacters
5461 ? (zeroes + string).slice(-totalCharacters)
5462 : string;
5463 };
5464
5465 var hex = function(number) {
5466 return Number(number).toString(16).toUpperCase();
5467 };
5468
5469 var slice = [].slice;
5470
5471 /*--------------------------------------------------------------------------*/
5472
5473 var dataFromCodePoints = function(codePoints) {
5474 var index = -1;
5475 var length = codePoints.length;
5476 var max = length - 1;
5477 var result = [];
5478 var isStart = true;
5479 var tmp;
5480 var previous = 0;
5481 while (++index < length) {
5482 tmp = codePoints[index];
5483 if (isStart) {
5484 result.push(tmp);
5485 previous = tmp;
5486 isStart = false;
5487 } else {
5488 if (tmp == previous + 1) {
5489 if (index != max) {
5490 previous = tmp;
5491 continue;
5492 } else {
5493 isStart = true;
5494 result.push(tmp + 1);
5495 }
5496 } else {
5497 // End the previous range and start a new one.
5498 result.push(previous + 1, tmp);
5499 previous = tmp;
5500 }
5501 }
5502 }
5503 if (!isStart) {
5504 result.push(tmp + 1);
5505 }
5506 return result;
5507 };
5508
5509 var dataRemove = function(data, codePoint) {
5510 // Iterate over the data per `(start, end)` pair.
5511 var index = 0;
5512 var start;
5513 var end;
5514 var length = data.length;
5515 while (index < length) {
5516 start = data[index];
5517 end = data[index + 1];
5518 if (codePoint >= start && codePoint < end) {
5519 // Modify this pair.
5520 if (codePoint == start) {
5521 if (end == start + 1) {
5522 // Just remove `start` and `end`.
5523 data.splice(index, 2);
5524 return data;
5525 } else {
5526 // Just replace `start` with a new value.
5527 data[index] = codePoint + 1;
5528 return data;
5529 }
5530 } else if (codePoint == end - 1) {
5531 // Just replace `end` with a new value.
5532 data[index + 1] = codePoint;
5533 return data;
5534 } else {
5535 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
5536 data.splice(index, 2, start, codePoint, codePoint + 1, end);
5537 return data;
5538 }
5539 }
5540 index += 2;
5541 }
5542 return data;
5543 };
5544
5545 var dataRemoveRange = function(data, rangeStart, rangeEnd) {
5546 if (rangeEnd < rangeStart) {
5547 throw Error(ERRORS.rangeOrder);
5548 }
5549 // Iterate over the data per `(start, end)` pair.
5550 var index = 0;
5551 var start;
5552 var end;
5553 while (index < data.length) {
5554 start = data[index];
5555 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
5556
5557 // Exit as soon as no more matching pairs can be found.
5558 if (start > rangeEnd) {
5559 return data;
5560 }
5561
5562 // Check if this range pair is equal to, or forms a subset of, the range
5563 // to be removed.
5564 // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
5565 // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
5566 if (rangeStart <= start && rangeEnd >= end) {
5567 // Remove this pair.
5568 data.splice(index, 2);
5569 continue;
5570 }
5571
5572 // Check if both `rangeStart` and `rangeEnd` are within the bounds of
5573 // this pair.
5574 // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
5575 if (rangeStart >= start && rangeEnd < end) {
5576 if (rangeStart == start) {
5577 // Replace `[start, end]` with `[startB, endB]`.
5578 data[index] = rangeEnd + 1;
5579 data[index + 1] = end + 1;
5580 return data;
5581 }
5582 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
5583 data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
5584 return data;
5585 }
5586
5587 // Check if only `rangeStart` is within the bounds of this pair.
5588 // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
5589 if (rangeStart >= start && rangeStart <= end) {
5590 // Replace `end` with `rangeStart`.
5591 data[index + 1] = rangeStart;
5592 // Note: we cannot `return` just yet, in case any following pairs still
5593 // contain matching code points.
5594 // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
5595 // → `[0, 4, 21, 31]`.
5596 }
5597
5598 // Check if only `rangeEnd` is within the bounds of this pair.
5599 // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
5600 else if (rangeEnd >= start && rangeEnd <= end) {
5601 // Just replace `start`.
5602 data[index] = rangeEnd + 1;
5603 return data;
5604 }
5605
5606 index += 2;
5607 }
5608 return data;
5609 };
5610
5611 var dataAdd = function(data, codePoint) {
5612 // Iterate over the data per `(start, end)` pair.
5613 var index = 0;
5614 var start;
5615 var end;
5616 var lastIndex = null;
5617 var length = data.length;
5618 if (codePoint < 0x0 || codePoint > 0x10FFFF) {
5619 throw RangeError(ERRORS.codePointRange);
5620 }
5621 while (index < length) {
5622 start = data[index];
5623 end = data[index + 1];
5624
5625 // Check if the code point is already in the set.
5626 if (codePoint >= start && codePoint < end) {
5627 return data;
5628 }
5629
5630 if (codePoint == start - 1) {
5631 // Just replace `start` with a new value.
5632 data[index] = codePoint;
5633 return data;
5634 }
5635
5636 // At this point, if `start` is `greater` than `codePoint`, insert a new
5637 // `[start, end]` pair before the current pair, or after the current pair
5638 // if there is a known `lastIndex`.
5639 if (start > codePoint) {
5640 data.splice(
5641 lastIndex != null ? lastIndex + 2 : 0,
5642 0,
5643 codePoint,
5644 codePoint + 1
5645 );
5646 return data;
5647 }
5648
5649 if (codePoint == end) {
5650 // Check if adding this code point causes two separate ranges to become
5651 // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
5652 if (codePoint + 1 == data[index + 2]) {
5653 data.splice(index, 4, start, data[index + 3]);
5654 return data;
5655 }
5656 // Else, just replace `end` with a new value.
5657 data[index + 1] = codePoint + 1;
5658 return data;
5659 }
5660 lastIndex = index;
5661 index += 2;
5662 }
5663 // The loop has finished; add the new pair to the end of the data set.
5664 data.push(codePoint, codePoint + 1);
5665 return data;
5666 };
5667
5668 var dataAddData = function(dataA, dataB) {
5669 // Iterate over the data per `(start, end)` pair.
5670 var index = 0;
5671 var start;
5672 var end;
5673 var data = dataA.slice();
5674 var length = dataB.length;
5675 while (index < length) {
5676 start = dataB[index];
5677 end = dataB[index + 1] - 1;
5678 if (start == end) {
5679 data = dataAdd(data, start);
5680 } else {
5681 data = dataAddRange(data, start, end);
5682 }
5683 index += 2;
5684 }
5685 return data;
5686 };
5687
5688 var dataRemoveData = function(dataA, dataB) {
5689 // Iterate over the data per `(start, end)` pair.
5690 var index = 0;
5691 var start;
5692 var end;
5693 var data = dataA.slice();
5694 var length = dataB.length;
5695 while (index < length) {
5696 start = dataB[index];
5697 end = dataB[index + 1] - 1;
5698 if (start == end) {
5699 data = dataRemove(data, start);
5700 } else {
5701 data = dataRemoveRange(data, start, end);
5702 }
5703 index += 2;
5704 }
5705 return data;
5706 };
5707
5708 var dataAddRange = function(data, rangeStart, rangeEnd) {
5709 if (rangeEnd < rangeStart) {
5710 throw Error(ERRORS.rangeOrder);
5711 }
5712 if (
5713 rangeStart < 0x0 || rangeStart > 0x10FFFF ||
5714 rangeEnd < 0x0 || rangeEnd > 0x10FFFF
5715 ) {
5716 throw RangeError(ERRORS.codePointRange);
5717 }
5718 // Iterate over the data per `(start, end)` pair.
5719 var index = 0;
5720 var start;
5721 var end;
5722 var added = false;
5723 var length = data.length;
5724 while (index < length) {
5725 start = data[index];
5726 end = data[index + 1];
5727
5728 if (added) {
5729 // The range has already been added to the set; at this point, we just
5730 // need to get rid of the following ranges in case they overlap.
5731
5732 // Check if this range can be combined with the previous range.
5733 if (start == rangeEnd + 1) {
5734 data.splice(index - 1, 2);
5735 return data;
5736 }
5737
5738 // Exit as soon as no more possibly overlapping pairs can be found.
5739 if (start > rangeEnd) {
5740 return data;
5741 }
5742
5743 // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
5744 // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
5745 // `0,16` range that was previously added.
5746 if (start >= rangeStart && start <= rangeEnd) {
5747 // `start` lies within the range that was previously added.
5748
5749 if (end > rangeStart && end - 1 <= rangeEnd) {
5750 // `end` lies within the range that was previously added as well,
5751 // so remove this pair.
5752 data.splice(index, 2);
5753 index -= 2;
5754 // Note: we cannot `return` just yet, as there may still be other
5755 // overlapping pairs.
5756 } else {
5757 // `start` lies within the range that was previously added, but
5758 // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
5759 // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
5760 // Remove the previously added `end` and the current `start`.
5761 data.splice(index - 1, 2);
5762 index -= 2;
5763 }
5764
5765 // Note: we cannot return yet.
5766 }
5767
5768 }
5769
5770 else if (start == rangeEnd + 1) {
5771 data[index] = rangeStart;
5772 return data;
5773 }
5774
5775 // Check if a new pair must be inserted *before* the current one.
5776 else if (start > rangeEnd) {
5777 data.splice(index, 0, rangeStart, rangeEnd + 1);
5778 return data;
5779 }
5780
5781 else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
5782 // The new range lies entirely within an existing range pair. No action
5783 // needed.
5784 return data;
5785 }
5786
5787 else if (
5788 // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
5789 (rangeStart >= start && rangeStart < end) ||
5790 // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
5791 end == rangeStart
5792 ) {
5793 // Replace `end` with the new value.
5794 data[index + 1] = rangeEnd + 1;
5795 // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
5796 // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
5797 added = true;
5798 // Note: we cannot `return` just yet.
5799 }
5800
5801 else if (rangeStart <= start && rangeEnd + 1 >= end) {
5802 // The new range is a superset of the old range.
5803 data[index] = rangeStart;
5804 data[index + 1] = rangeEnd + 1;
5805 added = true;
5806 }
5807
5808 index += 2;
5809 }
5810 // The loop has finished without doing anything; add the new pair to the end
5811 // of the data set.
5812 if (!added) {
5813 data.push(rangeStart, rangeEnd + 1);
5814 }
5815 return data;
5816 };
5817
5818 var dataContains = function(data, codePoint) {
5819 var index = 0;
5820 var length = data.length;
5821 // Exit early if `codePoint` is not within `data`’s overall range.
5822 var start = data[index];
5823 var end = data[length - 1];
5824 if (length >= 2) {
5825 if (codePoint < start || codePoint > end) {
5826 return false;
5827 }
5828 }
5829 // Iterate over the data per `(start, end)` pair.
5830 while (index < length) {
5831 start = data[index];
5832 end = data[index + 1];
5833 if (codePoint >= start && codePoint < end) {
5834 return true;
5835 }
5836 index += 2;
5837 }
5838 return false;
5839 };
5840
5841 var dataIntersection = function(data, codePoints) {
5842 var index = 0;
5843 var length = codePoints.length;
5844 var codePoint;
5845 var result = [];
5846 while (index < length) {
5847 codePoint = codePoints[index];
5848 if (dataContains(data, codePoint)) {
5849 result.push(codePoint);
5850 }
5851 ++index;
5852 }
5853 return dataFromCodePoints(result);
5854 };
5855
5856 var dataIsEmpty = function(data) {
5857 return !data.length;
5858 };
5859
5860 var dataIsSingleton = function(data) {
5861 // Check if the set only represents a single code point.
5862 return data.length == 2 && data[0] + 1 == data[1];
5863 };
5864
5865 var dataToArray = function(data) {
5866 // Iterate over the data per `(start, end)` pair.
5867 var index = 0;
5868 var start;
5869 var end;
5870 var result = [];
5871 var length = data.length;
5872 while (index < length) {
5873 start = data[index];
5874 end = data[index + 1];
5875 while (start < end) {
5876 result.push(start);
5877 ++start;
5878 }
5879 index += 2;
5880 }
5881 return result;
5882 };
5883
5884 /*--------------------------------------------------------------------------*/
5885
5886 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
5887 var floor = Math.floor;
5888 var highSurrogate = function(codePoint) {
5889 return parseInt(
5890 floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
5891 10
5892 );
5893 };
5894
5895 var lowSurrogate = function(codePoint) {
5896 return parseInt(
5897 (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
5898 10
5899 );
5900 };
5901
5902 var stringFromCharCode = String.fromCharCode;
5903 var codePointToString = function(codePoint) {
5904 var string;
5905 // https://mathiasbynens.be/notes/javascript-escapes#single
5906 // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
5907 // different meaning in regular expressions (word boundary), so it cannot
5908 // be used here.
5909 if (codePoint == 0x09) {
5910 string = '\\t';
5911 }
5912 // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
5913 // else if (codePoint == 0x0B) {
5914 // string = '\\v';
5915 // }
5916 else if (codePoint == 0x0A) {
5917 string = '\\n';
5918 }
5919 else if (codePoint == 0x0C) {
5920 string = '\\f';
5921 }
5922 else if (codePoint == 0x0D) {
5923 string = '\\r';
5924 }
5925 else if (codePoint == 0x5C) {
5926 string = '\\\\';
5927 }
5928 else if (
5929 codePoint == 0x24 ||
5930 (codePoint >= 0x28 && codePoint <= 0x2B) ||
5931 (codePoint >= 0x2D && codePoint <= 0x2F) ||
5932 codePoint == 0x3F ||
5933 (codePoint >= 0x5B && codePoint <= 0x5E) ||
5934 (codePoint >= 0x7B && codePoint <= 0x7D)
5935 ) {
5936 // The code point maps to an unsafe printable ASCII character;
5937 // backslash-escape it. Here’s the list of those symbols:
5938 //
5939 // $()*+-./?[\]^{|}
5940 //
5941 // See #7 for more info.
5942 string = '\\' + stringFromCharCode(codePoint);
5943 }
5944 else if (codePoint >= 0x20 && codePoint <= 0x7E) {
5945 // The code point maps to one of these printable ASCII symbols
5946 // (including the space character):
5947 //
5948 // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
5949 // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
5950 //
5951 // These can safely be used directly.
5952 string = stringFromCharCode(codePoint);
5953 }
5954 else if (codePoint <= 0xFF) {
5955 // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
5956 string = '\\x' + pad(hex(codePoint), 2);
5957 }
5958 else { // `codePoint <= 0xFFFF` holds true.
5959 // https://mathiasbynens.be/notes/javascript-escapes#unicode
5960 string = '\\u' + pad(hex(codePoint), 4);
5961 }
5962
5963 // There’s no need to account for astral symbols / surrogate pairs here,
5964 // since `codePointToString` is private and only used for BMP code points.
5965 // But if that’s what you need, just add an `else` block with this code:
5966 //
5967 // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
5968 // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
5969
5970 return string;
5971 };
5972
5973 var codePointToStringUnicode = function(codePoint) {
5974 if (codePoint <= 0xFFFF) {
5975 return codePointToString(codePoint);
5976 }
5977 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
5978 };
5979
5980 var symbolToCodePoint = function(symbol) {
5981 var length = symbol.length;
5982 var first = symbol.charCodeAt(0);
5983 var second;
5984 if (
5985 first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
5986 length > 1 // There is a next code unit.
5987 ) {
5988 // `first` is a high surrogate, and there is a next character. Assume
5989 // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
5990 second = symbol.charCodeAt(1);
5991 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
5992 return (first - HIGH_SURROGATE_MIN) * 0x400 +
5993 second - LOW_SURROGATE_MIN + 0x10000;
5994 }
5995 return first;
5996 };
5997
5998 var createBMPCharacterClasses = function(data) {
5999 // Iterate over the data per `(start, end)` pair.
6000 var result = '';
6001 var index = 0;
6002 var start;
6003 var end;
6004 var length = data.length;
6005 if (dataIsSingleton(data)) {
6006 return codePointToString(data[0]);
6007 }
6008 while (index < length) {
6009 start = data[index];
6010 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
6011 if (start == end) {
6012 result += codePointToString(start);
6013 } else if (start + 1 == end) {
6014 result += codePointToString(start) + codePointToString(end);
6015 } else {
6016 result += codePointToString(start) + '-' + codePointToString(end);
6017 }
6018 index += 2;
6019 }
6020 return '[' + result + ']';
6021 };
6022
6023 var createUnicodeCharacterClasses = function(data) {
6024 // Iterate over the data per `(start, end)` pair.
6025 var result = '';
6026 var index = 0;
6027 var start;
6028 var end;
6029 var length = data.length;
6030 if (dataIsSingleton(data)) {
6031 return codePointToStringUnicode(data[0]);
6032 }
6033 while (index < length) {
6034 start = data[index];
6035 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
6036 if (start == end) {
6037 result += codePointToStringUnicode(start);
6038 } else if (start + 1 == end) {
6039 result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
6040 } else {
6041 result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
6042 }
6043 index += 2;
6044 }
6045 return '[' + result + ']';
6046 };
6047
6048 var splitAtBMP = function(data) {
6049 // Iterate over the data per `(start, end)` pair.
6050 var loneHighSurrogates = [];
6051 var loneLowSurrogates = [];
6052 var bmp = [];
6053 var astral = [];
6054 var index = 0;
6055 var start;
6056 var end;
6057 var length = data.length;
6058 while (index < length) {
6059 start = data[index];
6060 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
6061
6062 if (start < HIGH_SURROGATE_MIN) {
6063
6064 // The range starts and ends before the high surrogate range.
6065 // E.g. (0, 0x10).
6066 if (end < HIGH_SURROGATE_MIN) {
6067 bmp.push(start, end + 1);
6068 }
6069
6070 // The range starts before the high surrogate range and ends within it.
6071 // E.g. (0, 0xD855).
6072 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
6073 bmp.push(start, HIGH_SURROGATE_MIN);
6074 loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
6075 }
6076
6077 // The range starts before the high surrogate range and ends in the low
6078 // surrogate range. E.g. (0, 0xDCFF).
6079 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
6080 bmp.push(start, HIGH_SURROGATE_MIN);
6081 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
6082 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
6083 }
6084
6085 // The range starts before the high surrogate range and ends after the
6086 // low surrogate range. E.g. (0, 0x10FFFF).
6087 if (end > LOW_SURROGATE_MAX) {
6088 bmp.push(start, HIGH_SURROGATE_MIN);
6089 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
6090 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
6091 if (end <= 0xFFFF) {
6092 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
6093 } else {
6094 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
6095 astral.push(0xFFFF + 1, end + 1);
6096 }
6097 }
6098
6099 } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
6100
6101 // The range starts and ends in the high surrogate range.
6102 // E.g. (0xD855, 0xD866).
6103 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
6104 loneHighSurrogates.push(start, end + 1);
6105 }
6106
6107 // The range starts in the high surrogate range and ends in the low
6108 // surrogate range. E.g. (0xD855, 0xDCFF).
6109 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
6110 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
6111 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
6112 }
6113
6114 // The range starts in the high surrogate range and ends after the low
6115 // surrogate range. E.g. (0xD855, 0x10FFFF).
6116 if (end > LOW_SURROGATE_MAX) {
6117 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
6118 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
6119 if (end <= 0xFFFF) {
6120 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
6121 } else {
6122 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
6123 astral.push(0xFFFF + 1, end + 1);
6124 }
6125 }
6126
6127 } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
6128
6129 // The range starts and ends in the low surrogate range.
6130 // E.g. (0xDCFF, 0xDDFF).
6131 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
6132 loneLowSurrogates.push(start, end + 1);
6133 }
6134
6135 // The range starts in the low surrogate range and ends after the low
6136 // surrogate range. E.g. (0xDCFF, 0x10FFFF).
6137 if (end > LOW_SURROGATE_MAX) {
6138 loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
6139 if (end <= 0xFFFF) {
6140 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
6141 } else {
6142 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
6143 astral.push(0xFFFF + 1, end + 1);
6144 }
6145 }
6146
6147 } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
6148
6149 // The range starts and ends after the low surrogate range.
6150 // E.g. (0xFFAA, 0x10FFFF).
6151 if (end <= 0xFFFF) {
6152 bmp.push(start, end + 1);
6153 } else {
6154 bmp.push(start, 0xFFFF + 1);
6155 astral.push(0xFFFF + 1, end + 1);
6156 }
6157
6158 } else {
6159
6160 // The range starts and ends in the astral range.
6161 astral.push(start, end + 1);
6162
6163 }
6164
6165 index += 2;
6166 }
6167 return {
6168 'loneHighSurrogates': loneHighSurrogates,
6169 'loneLowSurrogates': loneLowSurrogates,
6170 'bmp': bmp,
6171 'astral': astral
6172 };
6173 };
6174
6175 var optimizeSurrogateMappings = function(surrogateMappings) {
6176 var result = [];
6177 var tmpLow = [];
6178 var addLow = false;
6179 var mapping;
6180 var nextMapping;
6181 var highSurrogates;
6182 var lowSurrogates;
6183 var nextHighSurrogates;
6184 var nextLowSurrogates;
6185 var index = -1;
6186 var length = surrogateMappings.length;
6187 while (++index < length) {
6188 mapping = surrogateMappings[index];
6189 nextMapping = surrogateMappings[index + 1];
6190 if (!nextMapping) {
6191 result.push(mapping);
6192 continue;
6193 }
6194 highSurrogates = mapping[0];
6195 lowSurrogates = mapping[1];
6196 nextHighSurrogates = nextMapping[0];
6197 nextLowSurrogates = nextMapping[1];
6198
6199 // Check for identical high surrogate ranges.
6200 tmpLow = lowSurrogates;
6201 while (
6202 nextHighSurrogates &&
6203 highSurrogates[0] == nextHighSurrogates[0] &&
6204 highSurrogates[1] == nextHighSurrogates[1]
6205 ) {
6206 // Merge with the next item.
6207 if (dataIsSingleton(nextLowSurrogates)) {
6208 tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
6209 } else {
6210 tmpLow = dataAddRange(
6211 tmpLow,
6212 nextLowSurrogates[0],
6213 nextLowSurrogates[1] - 1
6214 );
6215 }
6216 ++index;
6217 mapping = surrogateMappings[index];
6218 highSurrogates = mapping[0];
6219 lowSurrogates = mapping[1];
6220 nextMapping = surrogateMappings[index + 1];
6221 nextHighSurrogates = nextMapping && nextMapping[0];
6222 nextLowSurrogates = nextMapping && nextMapping[1];
6223 addLow = true;
6224 }
6225 result.push([
6226 highSurrogates,
6227 addLow ? tmpLow : lowSurrogates
6228 ]);
6229 addLow = false;
6230 }
6231 return optimizeByLowSurrogates(result);
6232 };
6233
6234 var optimizeByLowSurrogates = function(surrogateMappings) {
6235 if (surrogateMappings.length == 1) {
6236 return surrogateMappings;
6237 }
6238 var index = -1;
6239 var innerIndex = -1;
6240 while (++index < surrogateMappings.length) {
6241 var mapping = surrogateMappings[index];
6242 var lowSurrogates = mapping[1];
6243 var lowSurrogateStart = lowSurrogates[0];
6244 var lowSurrogateEnd = lowSurrogates[1];
6245 innerIndex = index; // Note: the loop starts at the next index.
6246 while (++innerIndex < surrogateMappings.length) {
6247 var otherMapping = surrogateMappings[innerIndex];
6248 var otherLowSurrogates = otherMapping[1];
6249 var otherLowSurrogateStart = otherLowSurrogates[0];
6250 var otherLowSurrogateEnd = otherLowSurrogates[1];
6251 if (
6252 lowSurrogateStart == otherLowSurrogateStart &&
6253 lowSurrogateEnd == otherLowSurrogateEnd
6254 ) {
6255 // Add the code points in the other item to this one.
6256 if (dataIsSingleton(otherMapping[0])) {
6257 mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
6258 } else {
6259 mapping[0] = dataAddRange(
6260 mapping[0],
6261 otherMapping[0][0],
6262 otherMapping[0][1] - 1
6263 );
6264 }
6265 // Remove the other, now redundant, item.
6266 surrogateMappings.splice(innerIndex, 1);
6267 --innerIndex;
6268 }
6269 }
6270 }
6271 return surrogateMappings;
6272 };
6273
6274 var surrogateSet = function(data) {
6275 // Exit early if `data` is an empty set.
6276 if (!data.length) {
6277 return [];
6278 }
6279
6280 // Iterate over the data per `(start, end)` pair.
6281 var index = 0;
6282 var start;
6283 var end;
6284 var startHigh;
6285 var startLow;
6286 var endHigh;
6287 var endLow;
6288 var surrogateMappings = [];
6289 var length = data.length;
6290 while (index < length) {
6291 start = data[index];
6292 end = data[index + 1] - 1;
6293
6294 startHigh = highSurrogate(start);
6295 startLow = lowSurrogate(start);
6296 endHigh = highSurrogate(end);
6297 endLow = lowSurrogate(end);
6298
6299 var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
6300 var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
6301 var complete = false;
6302
6303 // Append the previous high-surrogate-to-low-surrogate mappings.
6304 // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
6305 if (
6306 startHigh == endHigh ||
6307 startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
6308 ) {
6309 surrogateMappings.push([
6310 [startHigh, endHigh + 1],
6311 [startLow, endLow + 1]
6312 ]);
6313 complete = true;
6314 } else {
6315 surrogateMappings.push([
6316 [startHigh, startHigh + 1],
6317 [startLow, LOW_SURROGATE_MAX + 1]
6318 ]);
6319 }
6320
6321 // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
6322 // `(endHigh - 1, LOW_SURROGATE_MAX)`.
6323 if (!complete && startHigh + 1 < endHigh) {
6324 if (endsWithHighestLowSurrogate) {
6325 // Combine step 2 and step 3.
6326 surrogateMappings.push([
6327 [startHigh + 1, endHigh + 1],
6328 [LOW_SURROGATE_MIN, endLow + 1]
6329 ]);
6330 complete = true;
6331 } else {
6332 surrogateMappings.push([
6333 [startHigh + 1, endHigh],
6334 [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
6335 ]);
6336 }
6337 }
6338
6339 // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
6340 if (!complete) {
6341 surrogateMappings.push([
6342 [endHigh, endHigh + 1],
6343 [LOW_SURROGATE_MIN, endLow + 1]
6344 ]);
6345 }
6346
6347 index += 2;
6348 }
6349
6350 // The format of `surrogateMappings` is as follows:
6351 //
6352 // [ surrogateMapping1, surrogateMapping2 ]
6353 //
6354 // i.e.:
6355 //
6356 // [
6357 // [ highSurrogates1, lowSurrogates1 ],
6358 // [ highSurrogates2, lowSurrogates2 ]
6359 // ]
6360 return optimizeSurrogateMappings(surrogateMappings);
6361 };
6362
6363 var createSurrogateCharacterClasses = function(surrogateMappings) {
6364 var result = [];
6365 forEach(surrogateMappings, function(surrogateMapping) {
6366 var highSurrogates = surrogateMapping[0];
6367 var lowSurrogates = surrogateMapping[1];
6368 result.push(
6369 createBMPCharacterClasses(highSurrogates) +
6370 createBMPCharacterClasses(lowSurrogates)
6371 );
6372 });
6373 return result.join('|');
6374 };
6375
6376 var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
6377 if (hasUnicodeFlag) {
6378 return createUnicodeCharacterClasses(data);
6379 }
6380 var result = [];
6381
6382 var parts = splitAtBMP(data);
6383 var loneHighSurrogates = parts.loneHighSurrogates;
6384 var loneLowSurrogates = parts.loneLowSurrogates;
6385 var bmp = parts.bmp;
6386 var astral = parts.astral;
6387 var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
6388 var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
6389
6390 var surrogateMappings = surrogateSet(astral);
6391
6392 if (bmpOnly) {
6393 bmp = dataAddData(bmp, loneHighSurrogates);
6394 hasLoneHighSurrogates = false;
6395 bmp = dataAddData(bmp, loneLowSurrogates);
6396 hasLoneLowSurrogates = false;
6397 }
6398
6399 if (!dataIsEmpty(bmp)) {
6400 // The data set contains BMP code points that are not high surrogates
6401 // needed for astral code points in the set.
6402 result.push(createBMPCharacterClasses(bmp));
6403 }
6404 if (surrogateMappings.length) {
6405 // The data set contains astral code points; append character classes
6406 // based on their surrogate pairs.
6407 result.push(createSurrogateCharacterClasses(surrogateMappings));
6408 }
6409 // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
6410 if (hasLoneHighSurrogates) {
6411 result.push(
6412 createBMPCharacterClasses(loneHighSurrogates) +
6413 // Make sure the high surrogates aren’t part of a surrogate pair.
6414 '(?![\\uDC00-\\uDFFF])'
6415 );
6416 }
6417 if (hasLoneLowSurrogates) {
6418 result.push(
6419 // It is not possible to accurately assert the low surrogates aren’t
6420 // part of a surrogate pair, since JavaScript regular expressions do
6421 // not support lookbehind.
6422 '(?:[^\\uD800-\\uDBFF]|^)' +
6423 createBMPCharacterClasses(loneLowSurrogates)
6424 );
6425 }
6426 return result.join('|');
6427 };
6428
6429 /*--------------------------------------------------------------------------*/
6430
6431 // `regenerate` can be used as a constructor (and new methods can be added to
6432 // its prototype) but also as a regular function, the latter of which is the
6433 // documented and most common usage. For that reason, it’s not capitalized.
6434 var regenerate = function(value) {
6435 if (arguments.length > 1) {
6436 value = slice.call(arguments);
6437 }
6438 if (this instanceof regenerate) {
6439 this.data = [];
6440 return value ? this.add(value) : this;
6441 }
6442 return (new regenerate).add(value);
6443 };
6444
6445 regenerate.version = '1.3.3';
6446
6447 var proto = regenerate.prototype;
6448 extend(proto, {
6449 'add': function(value) {
6450 var $this = this;
6451 if (value == null) {
6452 return $this;
6453 }
6454 if (value instanceof regenerate) {
6455 // Allow passing other Regenerate instances.
6456 $this.data = dataAddData($this.data, value.data);
6457 return $this;
6458 }
6459 if (arguments.length > 1) {
6460 value = slice.call(arguments);
6461 }
6462 if (isArray(value)) {
6463 forEach(value, function(item) {
6464 $this.add(item);
6465 });
6466 return $this;
6467 }
6468 $this.data = dataAdd(
6469 $this.data,
6470 isNumber(value) ? value : symbolToCodePoint(value)
6471 );
6472 return $this;
6473 },
6474 'remove': function(value) {
6475 var $this = this;
6476 if (value == null) {
6477 return $this;
6478 }
6479 if (value instanceof regenerate) {
6480 // Allow passing other Regenerate instances.
6481 $this.data = dataRemoveData($this.data, value.data);
6482 return $this;
6483 }
6484 if (arguments.length > 1) {
6485 value = slice.call(arguments);
6486 }
6487 if (isArray(value)) {
6488 forEach(value, function(item) {
6489 $this.remove(item);
6490 });
6491 return $this;
6492 }
6493 $this.data = dataRemove(
6494 $this.data,
6495 isNumber(value) ? value : symbolToCodePoint(value)
6496 );
6497 return $this;
6498 },
6499 'addRange': function(start, end) {
6500 var $this = this;
6501 $this.data = dataAddRange($this.data,
6502 isNumber(start) ? start : symbolToCodePoint(start),
6503 isNumber(end) ? end : symbolToCodePoint(end)
6504 );
6505 return $this;
6506 },
6507 'removeRange': function(start, end) {
6508 var $this = this;
6509 var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
6510 var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
6511 $this.data = dataRemoveRange(
6512 $this.data,
6513 startCodePoint,
6514 endCodePoint
6515 );
6516 return $this;
6517 },
6518 'intersection': function(argument) {
6519 var $this = this;
6520 // Allow passing other Regenerate instances.
6521 // TODO: Optimize this by writing and using `dataIntersectionData()`.
6522 var array = argument instanceof regenerate ?
6523 dataToArray(argument.data) :
6524 argument;
6525 $this.data = dataIntersection($this.data, array);
6526 return $this;
6527 },
6528 'contains': function(codePoint) {
6529 return dataContains(
6530 this.data,
6531 isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
6532 );
6533 },
6534 'clone': function() {
6535 var set = new regenerate;
6536 set.data = this.data.slice(0);
6537 return set;
6538 },
6539 'toString': function(options) {
6540 var result = createCharacterClassesFromData(
6541 this.data,
6542 options ? options.bmpOnly : false,
6543 options ? options.hasUnicodeFlag : false
6544 );
6545 if (!result) {
6546 // For an empty set, return something that can be inserted `/here/` to
6547 // form a valid regular expression. Avoid `(?:)` since that matches the
6548 // empty string.
6549 return '[]';
6550 }
6551 // Use `\0` instead of `\x00` where possible.
6552 return result.replace(regexNull, '\\0$1');
6553 },
6554 'toRegExp': function(flags) {
6555 var pattern = this.toString(
6556 flags && flags.indexOf('u') != -1 ?
6557 { 'hasUnicodeFlag': true } :
6558 null
6559 );
6560 return RegExp(pattern, flags || '');
6561 },
6562 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
6563 return dataToArray(this.data);
6564 }
6565 });
6566
6567 proto.toArray = proto.valueOf;
6568
6569 // Some AMD build optimizers, like r.js, check for specific condition patterns
6570 // like the following:
6571 if (
6572 typeof undefined == 'function' &&
6573 typeof undefined.amd == 'object' &&
6574 undefined.amd
6575 ) {
6576 undefined(function() {
6577 return regenerate;
6578 });
6579 } else if (freeExports && !freeExports.nodeType) {
6580 if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
6581 freeModule.exports = regenerate;
6582 } else { // in Narwhal or RingoJS v0.7.0-
6583 freeExports.regenerate = regenerate;
6584 }
6585 } else { // in Rhino or a web browser
6586 root.regenerate = regenerate;
6587 }
6588
6589}(commonjsGlobal));
6590});
6591
6592var unicodeCanonicalPropertyNamesEcmascript = new Set([
6593 // Non-binary properties:
6594 'General_Category',
6595 'Script',
6596 'Script_Extensions',
6597 // Binary properties:
6598 'Alphabetic',
6599 'Any',
6600 'ASCII',
6601 'ASCII_Hex_Digit',
6602 'Assigned',
6603 'Bidi_Control',
6604 'Bidi_Mirrored',
6605 'Case_Ignorable',
6606 'Cased',
6607 'Changes_When_Casefolded',
6608 'Changes_When_Casemapped',
6609 'Changes_When_Lowercased',
6610 'Changes_When_NFKC_Casefolded',
6611 'Changes_When_Titlecased',
6612 'Changes_When_Uppercased',
6613 'Dash',
6614 'Default_Ignorable_Code_Point',
6615 'Deprecated',
6616 'Diacritic',
6617 'Emoji',
6618 'Emoji_Component',
6619 'Emoji_Modifier',
6620 'Emoji_Modifier_Base',
6621 'Emoji_Presentation',
6622 'Extender',
6623 'Grapheme_Base',
6624 'Grapheme_Extend',
6625 'Hex_Digit',
6626 'ID_Continue',
6627 'ID_Start',
6628 'Ideographic',
6629 'IDS_Binary_Operator',
6630 'IDS_Trinary_Operator',
6631 'Join_Control',
6632 'Logical_Order_Exception',
6633 'Lowercase',
6634 'Math',
6635 'Noncharacter_Code_Point',
6636 'Pattern_Syntax',
6637 'Pattern_White_Space',
6638 'Quotation_Mark',
6639 'Radical',
6640 'Regional_Indicator',
6641 'Sentence_Terminal',
6642 'Soft_Dotted',
6643 'Terminal_Punctuation',
6644 'Unified_Ideograph',
6645 'Uppercase',
6646 'Variation_Selector',
6647 'White_Space',
6648 'XID_Continue',
6649 'XID_Start'
6650]);
6651
6652// Generated using `npm run build`. Do not edit!
6653var unicodePropertyAliasesEcmascript = new Map([
6654 ['scx', 'Script_Extensions'],
6655 ['sc', 'Script'],
6656 ['gc', 'General_Category'],
6657 ['AHex', 'ASCII_Hex_Digit'],
6658 ['Alpha', 'Alphabetic'],
6659 ['Bidi_C', 'Bidi_Control'],
6660 ['Bidi_M', 'Bidi_Mirrored'],
6661 ['Cased', 'Cased'],
6662 ['CI', 'Case_Ignorable'],
6663 ['CWCF', 'Changes_When_Casefolded'],
6664 ['CWCM', 'Changes_When_Casemapped'],
6665 ['CWKCF', 'Changes_When_NFKC_Casefolded'],
6666 ['CWL', 'Changes_When_Lowercased'],
6667 ['CWT', 'Changes_When_Titlecased'],
6668 ['CWU', 'Changes_When_Uppercased'],
6669 ['Dash', 'Dash'],
6670 ['Dep', 'Deprecated'],
6671 ['DI', 'Default_Ignorable_Code_Point'],
6672 ['Dia', 'Diacritic'],
6673 ['Ext', 'Extender'],
6674 ['Gr_Base', 'Grapheme_Base'],
6675 ['Gr_Ext', 'Grapheme_Extend'],
6676 ['Hex', 'Hex_Digit'],
6677 ['IDC', 'ID_Continue'],
6678 ['Ideo', 'Ideographic'],
6679 ['IDS', 'ID_Start'],
6680 ['IDSB', 'IDS_Binary_Operator'],
6681 ['IDST', 'IDS_Trinary_Operator'],
6682 ['Join_C', 'Join_Control'],
6683 ['LOE', 'Logical_Order_Exception'],
6684 ['Lower', 'Lowercase'],
6685 ['Math', 'Math'],
6686 ['NChar', 'Noncharacter_Code_Point'],
6687 ['Pat_Syn', 'Pattern_Syntax'],
6688 ['Pat_WS', 'Pattern_White_Space'],
6689 ['QMark', 'Quotation_Mark'],
6690 ['Radical', 'Radical'],
6691 ['RI', 'Regional_Indicator'],
6692 ['SD', 'Soft_Dotted'],
6693 ['STerm', 'Sentence_Terminal'],
6694 ['Term', 'Terminal_Punctuation'],
6695 ['UIdeo', 'Unified_Ideograph'],
6696 ['Upper', 'Uppercase'],
6697 ['VS', 'Variation_Selector'],
6698 ['WSpace', 'White_Space'],
6699 ['space', 'White_Space'],
6700 ['XIDC', 'XID_Continue'],
6701 ['XIDS', 'XID_Start']
6702]);
6703
6704var matchProperty = function(property) {
6705 if (unicodeCanonicalPropertyNamesEcmascript.has(property)) {
6706 return property;
6707 }
6708 if (unicodePropertyAliasesEcmascript.has(property)) {
6709 return unicodePropertyAliasesEcmascript.get(property);
6710 }
6711 throw new Error(("Unknown property: " + property));
6712};
6713
6714var unicodeMatchPropertyEcmascript = matchProperty;
6715
6716var mappings = new Map([
6717 ['General_Category', new Map([
6718 ['C', 'Other'],
6719 ['Cc', 'Control'],
6720 ['cntrl', 'Control'],
6721 ['Cf', 'Format'],
6722 ['Cn', 'Unassigned'],
6723 ['Co', 'Private_Use'],
6724 ['Cs', 'Surrogate'],
6725 ['L', 'Letter'],
6726 ['LC', 'Cased_Letter'],
6727 ['Ll', 'Lowercase_Letter'],
6728 ['Lm', 'Modifier_Letter'],
6729 ['Lo', 'Other_Letter'],
6730 ['Lt', 'Titlecase_Letter'],
6731 ['Lu', 'Uppercase_Letter'],
6732 ['M', 'Mark'],
6733 ['Combining_Mark', 'Mark'],
6734 ['Mc', 'Spacing_Mark'],
6735 ['Me', 'Enclosing_Mark'],
6736 ['Mn', 'Nonspacing_Mark'],
6737 ['N', 'Number'],
6738 ['Nd', 'Decimal_Number'],
6739 ['digit', 'Decimal_Number'],
6740 ['Nl', 'Letter_Number'],
6741 ['No', 'Other_Number'],
6742 ['P', 'Punctuation'],
6743 ['punct', 'Punctuation'],
6744 ['Pc', 'Connector_Punctuation'],
6745 ['Pd', 'Dash_Punctuation'],
6746 ['Pe', 'Close_Punctuation'],
6747 ['Pf', 'Final_Punctuation'],
6748 ['Pi', 'Initial_Punctuation'],
6749 ['Po', 'Other_Punctuation'],
6750 ['Ps', 'Open_Punctuation'],
6751 ['S', 'Symbol'],
6752 ['Sc', 'Currency_Symbol'],
6753 ['Sk', 'Modifier_Symbol'],
6754 ['Sm', 'Math_Symbol'],
6755 ['So', 'Other_Symbol'],
6756 ['Z', 'Separator'],
6757 ['Zl', 'Line_Separator'],
6758 ['Zp', 'Paragraph_Separator'],
6759 ['Zs', 'Space_Separator'],
6760 ['Other', 'Other'],
6761 ['Control', 'Control'],
6762 ['Format', 'Format'],
6763 ['Unassigned', 'Unassigned'],
6764 ['Private_Use', 'Private_Use'],
6765 ['Surrogate', 'Surrogate'],
6766 ['Letter', 'Letter'],
6767 ['Cased_Letter', 'Cased_Letter'],
6768 ['Lowercase_Letter', 'Lowercase_Letter'],
6769 ['Modifier_Letter', 'Modifier_Letter'],
6770 ['Other_Letter', 'Other_Letter'],
6771 ['Titlecase_Letter', 'Titlecase_Letter'],
6772 ['Uppercase_Letter', 'Uppercase_Letter'],
6773 ['Mark', 'Mark'],
6774 ['Spacing_Mark', 'Spacing_Mark'],
6775 ['Enclosing_Mark', 'Enclosing_Mark'],
6776 ['Nonspacing_Mark', 'Nonspacing_Mark'],
6777 ['Number', 'Number'],
6778 ['Decimal_Number', 'Decimal_Number'],
6779 ['Letter_Number', 'Letter_Number'],
6780 ['Other_Number', 'Other_Number'],
6781 ['Punctuation', 'Punctuation'],
6782 ['Connector_Punctuation', 'Connector_Punctuation'],
6783 ['Dash_Punctuation', 'Dash_Punctuation'],
6784 ['Close_Punctuation', 'Close_Punctuation'],
6785 ['Final_Punctuation', 'Final_Punctuation'],
6786 ['Initial_Punctuation', 'Initial_Punctuation'],
6787 ['Other_Punctuation', 'Other_Punctuation'],
6788 ['Open_Punctuation', 'Open_Punctuation'],
6789 ['Symbol', 'Symbol'],
6790 ['Currency_Symbol', 'Currency_Symbol'],
6791 ['Modifier_Symbol', 'Modifier_Symbol'],
6792 ['Math_Symbol', 'Math_Symbol'],
6793 ['Other_Symbol', 'Other_Symbol'],
6794 ['Separator', 'Separator'],
6795 ['Line_Separator', 'Line_Separator'],
6796 ['Paragraph_Separator', 'Paragraph_Separator'],
6797 ['Space_Separator', 'Space_Separator']
6798 ])],
6799 ['Script', new Map([
6800 ['Adlm', 'Adlam'],
6801 ['Aghb', 'Caucasian_Albanian'],
6802 ['Ahom', 'Ahom'],
6803 ['Arab', 'Arabic'],
6804 ['Armi', 'Imperial_Aramaic'],
6805 ['Armn', 'Armenian'],
6806 ['Avst', 'Avestan'],
6807 ['Bali', 'Balinese'],
6808 ['Bamu', 'Bamum'],
6809 ['Bass', 'Bassa_Vah'],
6810 ['Batk', 'Batak'],
6811 ['Beng', 'Bengali'],
6812 ['Bhks', 'Bhaiksuki'],
6813 ['Bopo', 'Bopomofo'],
6814 ['Brah', 'Brahmi'],
6815 ['Brai', 'Braille'],
6816 ['Bugi', 'Buginese'],
6817 ['Buhd', 'Buhid'],
6818 ['Cakm', 'Chakma'],
6819 ['Cans', 'Canadian_Aboriginal'],
6820 ['Cari', 'Carian'],
6821 ['Cham', 'Cham'],
6822 ['Cher', 'Cherokee'],
6823 ['Copt', 'Coptic'],
6824 ['Qaac', 'Coptic'],
6825 ['Cprt', 'Cypriot'],
6826 ['Cyrl', 'Cyrillic'],
6827 ['Deva', 'Devanagari'],
6828 ['Dsrt', 'Deseret'],
6829 ['Dupl', 'Duployan'],
6830 ['Egyp', 'Egyptian_Hieroglyphs'],
6831 ['Elba', 'Elbasan'],
6832 ['Ethi', 'Ethiopic'],
6833 ['Geor', 'Georgian'],
6834 ['Glag', 'Glagolitic'],
6835 ['Gonm', 'Masaram_Gondi'],
6836 ['Goth', 'Gothic'],
6837 ['Gran', 'Grantha'],
6838 ['Grek', 'Greek'],
6839 ['Gujr', 'Gujarati'],
6840 ['Guru', 'Gurmukhi'],
6841 ['Hang', 'Hangul'],
6842 ['Hani', 'Han'],
6843 ['Hano', 'Hanunoo'],
6844 ['Hatr', 'Hatran'],
6845 ['Hebr', 'Hebrew'],
6846 ['Hira', 'Hiragana'],
6847 ['Hluw', 'Anatolian_Hieroglyphs'],
6848 ['Hmng', 'Pahawh_Hmong'],
6849 ['Hrkt', 'Katakana_Or_Hiragana'],
6850 ['Hung', 'Old_Hungarian'],
6851 ['Ital', 'Old_Italic'],
6852 ['Java', 'Javanese'],
6853 ['Kali', 'Kayah_Li'],
6854 ['Kana', 'Katakana'],
6855 ['Khar', 'Kharoshthi'],
6856 ['Khmr', 'Khmer'],
6857 ['Khoj', 'Khojki'],
6858 ['Knda', 'Kannada'],
6859 ['Kthi', 'Kaithi'],
6860 ['Lana', 'Tai_Tham'],
6861 ['Laoo', 'Lao'],
6862 ['Latn', 'Latin'],
6863 ['Lepc', 'Lepcha'],
6864 ['Limb', 'Limbu'],
6865 ['Lina', 'Linear_A'],
6866 ['Linb', 'Linear_B'],
6867 ['Lisu', 'Lisu'],
6868 ['Lyci', 'Lycian'],
6869 ['Lydi', 'Lydian'],
6870 ['Mahj', 'Mahajani'],
6871 ['Mand', 'Mandaic'],
6872 ['Mani', 'Manichaean'],
6873 ['Marc', 'Marchen'],
6874 ['Mend', 'Mende_Kikakui'],
6875 ['Merc', 'Meroitic_Cursive'],
6876 ['Mero', 'Meroitic_Hieroglyphs'],
6877 ['Mlym', 'Malayalam'],
6878 ['Modi', 'Modi'],
6879 ['Mong', 'Mongolian'],
6880 ['Mroo', 'Mro'],
6881 ['Mtei', 'Meetei_Mayek'],
6882 ['Mult', 'Multani'],
6883 ['Mymr', 'Myanmar'],
6884 ['Narb', 'Old_North_Arabian'],
6885 ['Nbat', 'Nabataean'],
6886 ['Newa', 'Newa'],
6887 ['Nkoo', 'Nko'],
6888 ['Nshu', 'Nushu'],
6889 ['Ogam', 'Ogham'],
6890 ['Olck', 'Ol_Chiki'],
6891 ['Orkh', 'Old_Turkic'],
6892 ['Orya', 'Oriya'],
6893 ['Osge', 'Osage'],
6894 ['Osma', 'Osmanya'],
6895 ['Palm', 'Palmyrene'],
6896 ['Pauc', 'Pau_Cin_Hau'],
6897 ['Perm', 'Old_Permic'],
6898 ['Phag', 'Phags_Pa'],
6899 ['Phli', 'Inscriptional_Pahlavi'],
6900 ['Phlp', 'Psalter_Pahlavi'],
6901 ['Phnx', 'Phoenician'],
6902 ['Plrd', 'Miao'],
6903 ['Prti', 'Inscriptional_Parthian'],
6904 ['Rjng', 'Rejang'],
6905 ['Runr', 'Runic'],
6906 ['Samr', 'Samaritan'],
6907 ['Sarb', 'Old_South_Arabian'],
6908 ['Saur', 'Saurashtra'],
6909 ['Sgnw', 'SignWriting'],
6910 ['Shaw', 'Shavian'],
6911 ['Shrd', 'Sharada'],
6912 ['Sidd', 'Siddham'],
6913 ['Sind', 'Khudawadi'],
6914 ['Sinh', 'Sinhala'],
6915 ['Sora', 'Sora_Sompeng'],
6916 ['Soyo', 'Soyombo'],
6917 ['Sund', 'Sundanese'],
6918 ['Sylo', 'Syloti_Nagri'],
6919 ['Syrc', 'Syriac'],
6920 ['Tagb', 'Tagbanwa'],
6921 ['Takr', 'Takri'],
6922 ['Tale', 'Tai_Le'],
6923 ['Talu', 'New_Tai_Lue'],
6924 ['Taml', 'Tamil'],
6925 ['Tang', 'Tangut'],
6926 ['Tavt', 'Tai_Viet'],
6927 ['Telu', 'Telugu'],
6928 ['Tfng', 'Tifinagh'],
6929 ['Tglg', 'Tagalog'],
6930 ['Thaa', 'Thaana'],
6931 ['Thai', 'Thai'],
6932 ['Tibt', 'Tibetan'],
6933 ['Tirh', 'Tirhuta'],
6934 ['Ugar', 'Ugaritic'],
6935 ['Vaii', 'Vai'],
6936 ['Wara', 'Warang_Citi'],
6937 ['Xpeo', 'Old_Persian'],
6938 ['Xsux', 'Cuneiform'],
6939 ['Yiii', 'Yi'],
6940 ['Zanb', 'Zanabazar_Square'],
6941 ['Zinh', 'Inherited'],
6942 ['Qaai', 'Inherited'],
6943 ['Zyyy', 'Common'],
6944 ['Zzzz', 'Unknown'],
6945 ['Adlam', 'Adlam'],
6946 ['Caucasian_Albanian', 'Caucasian_Albanian'],
6947 ['Arabic', 'Arabic'],
6948 ['Imperial_Aramaic', 'Imperial_Aramaic'],
6949 ['Armenian', 'Armenian'],
6950 ['Avestan', 'Avestan'],
6951 ['Balinese', 'Balinese'],
6952 ['Bamum', 'Bamum'],
6953 ['Bassa_Vah', 'Bassa_Vah'],
6954 ['Batak', 'Batak'],
6955 ['Bengali', 'Bengali'],
6956 ['Bhaiksuki', 'Bhaiksuki'],
6957 ['Bopomofo', 'Bopomofo'],
6958 ['Brahmi', 'Brahmi'],
6959 ['Braille', 'Braille'],
6960 ['Buginese', 'Buginese'],
6961 ['Buhid', 'Buhid'],
6962 ['Chakma', 'Chakma'],
6963 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
6964 ['Carian', 'Carian'],
6965 ['Cherokee', 'Cherokee'],
6966 ['Coptic', 'Coptic'],
6967 ['Cypriot', 'Cypriot'],
6968 ['Cyrillic', 'Cyrillic'],
6969 ['Devanagari', 'Devanagari'],
6970 ['Deseret', 'Deseret'],
6971 ['Duployan', 'Duployan'],
6972 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
6973 ['Elbasan', 'Elbasan'],
6974 ['Ethiopic', 'Ethiopic'],
6975 ['Georgian', 'Georgian'],
6976 ['Glagolitic', 'Glagolitic'],
6977 ['Masaram_Gondi', 'Masaram_Gondi'],
6978 ['Gothic', 'Gothic'],
6979 ['Grantha', 'Grantha'],
6980 ['Greek', 'Greek'],
6981 ['Gujarati', 'Gujarati'],
6982 ['Gurmukhi', 'Gurmukhi'],
6983 ['Hangul', 'Hangul'],
6984 ['Han', 'Han'],
6985 ['Hanunoo', 'Hanunoo'],
6986 ['Hatran', 'Hatran'],
6987 ['Hebrew', 'Hebrew'],
6988 ['Hiragana', 'Hiragana'],
6989 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
6990 ['Pahawh_Hmong', 'Pahawh_Hmong'],
6991 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
6992 ['Old_Hungarian', 'Old_Hungarian'],
6993 ['Old_Italic', 'Old_Italic'],
6994 ['Javanese', 'Javanese'],
6995 ['Kayah_Li', 'Kayah_Li'],
6996 ['Katakana', 'Katakana'],
6997 ['Kharoshthi', 'Kharoshthi'],
6998 ['Khmer', 'Khmer'],
6999 ['Khojki', 'Khojki'],
7000 ['Kannada', 'Kannada'],
7001 ['Kaithi', 'Kaithi'],
7002 ['Tai_Tham', 'Tai_Tham'],
7003 ['Lao', 'Lao'],
7004 ['Latin', 'Latin'],
7005 ['Lepcha', 'Lepcha'],
7006 ['Limbu', 'Limbu'],
7007 ['Linear_A', 'Linear_A'],
7008 ['Linear_B', 'Linear_B'],
7009 ['Lycian', 'Lycian'],
7010 ['Lydian', 'Lydian'],
7011 ['Mahajani', 'Mahajani'],
7012 ['Mandaic', 'Mandaic'],
7013 ['Manichaean', 'Manichaean'],
7014 ['Marchen', 'Marchen'],
7015 ['Mende_Kikakui', 'Mende_Kikakui'],
7016 ['Meroitic_Cursive', 'Meroitic_Cursive'],
7017 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
7018 ['Malayalam', 'Malayalam'],
7019 ['Mongolian', 'Mongolian'],
7020 ['Mro', 'Mro'],
7021 ['Meetei_Mayek', 'Meetei_Mayek'],
7022 ['Multani', 'Multani'],
7023 ['Myanmar', 'Myanmar'],
7024 ['Old_North_Arabian', 'Old_North_Arabian'],
7025 ['Nabataean', 'Nabataean'],
7026 ['Nko', 'Nko'],
7027 ['Nushu', 'Nushu'],
7028 ['Ogham', 'Ogham'],
7029 ['Ol_Chiki', 'Ol_Chiki'],
7030 ['Old_Turkic', 'Old_Turkic'],
7031 ['Oriya', 'Oriya'],
7032 ['Osage', 'Osage'],
7033 ['Osmanya', 'Osmanya'],
7034 ['Palmyrene', 'Palmyrene'],
7035 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
7036 ['Old_Permic', 'Old_Permic'],
7037 ['Phags_Pa', 'Phags_Pa'],
7038 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
7039 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
7040 ['Phoenician', 'Phoenician'],
7041 ['Miao', 'Miao'],
7042 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
7043 ['Rejang', 'Rejang'],
7044 ['Runic', 'Runic'],
7045 ['Samaritan', 'Samaritan'],
7046 ['Old_South_Arabian', 'Old_South_Arabian'],
7047 ['Saurashtra', 'Saurashtra'],
7048 ['SignWriting', 'SignWriting'],
7049 ['Shavian', 'Shavian'],
7050 ['Sharada', 'Sharada'],
7051 ['Siddham', 'Siddham'],
7052 ['Khudawadi', 'Khudawadi'],
7053 ['Sinhala', 'Sinhala'],
7054 ['Sora_Sompeng', 'Sora_Sompeng'],
7055 ['Soyombo', 'Soyombo'],
7056 ['Sundanese', 'Sundanese'],
7057 ['Syloti_Nagri', 'Syloti_Nagri'],
7058 ['Syriac', 'Syriac'],
7059 ['Tagbanwa', 'Tagbanwa'],
7060 ['Takri', 'Takri'],
7061 ['Tai_Le', 'Tai_Le'],
7062 ['New_Tai_Lue', 'New_Tai_Lue'],
7063 ['Tamil', 'Tamil'],
7064 ['Tangut', 'Tangut'],
7065 ['Tai_Viet', 'Tai_Viet'],
7066 ['Telugu', 'Telugu'],
7067 ['Tifinagh', 'Tifinagh'],
7068 ['Tagalog', 'Tagalog'],
7069 ['Thaana', 'Thaana'],
7070 ['Tibetan', 'Tibetan'],
7071 ['Tirhuta', 'Tirhuta'],
7072 ['Ugaritic', 'Ugaritic'],
7073 ['Vai', 'Vai'],
7074 ['Warang_Citi', 'Warang_Citi'],
7075 ['Old_Persian', 'Old_Persian'],
7076 ['Cuneiform', 'Cuneiform'],
7077 ['Yi', 'Yi'],
7078 ['Zanabazar_Square', 'Zanabazar_Square'],
7079 ['Inherited', 'Inherited'],
7080 ['Common', 'Common'],
7081 ['Unknown', 'Unknown']
7082 ])],
7083 ['Script_Extensions', new Map([
7084 ['Adlm', 'Adlam'],
7085 ['Aghb', 'Caucasian_Albanian'],
7086 ['Ahom', 'Ahom'],
7087 ['Arab', 'Arabic'],
7088 ['Armi', 'Imperial_Aramaic'],
7089 ['Armn', 'Armenian'],
7090 ['Avst', 'Avestan'],
7091 ['Bali', 'Balinese'],
7092 ['Bamu', 'Bamum'],
7093 ['Bass', 'Bassa_Vah'],
7094 ['Batk', 'Batak'],
7095 ['Beng', 'Bengali'],
7096 ['Bhks', 'Bhaiksuki'],
7097 ['Bopo', 'Bopomofo'],
7098 ['Brah', 'Brahmi'],
7099 ['Brai', 'Braille'],
7100 ['Bugi', 'Buginese'],
7101 ['Buhd', 'Buhid'],
7102 ['Cakm', 'Chakma'],
7103 ['Cans', 'Canadian_Aboriginal'],
7104 ['Cari', 'Carian'],
7105 ['Cham', 'Cham'],
7106 ['Cher', 'Cherokee'],
7107 ['Copt', 'Coptic'],
7108 ['Qaac', 'Coptic'],
7109 ['Cprt', 'Cypriot'],
7110 ['Cyrl', 'Cyrillic'],
7111 ['Deva', 'Devanagari'],
7112 ['Dsrt', 'Deseret'],
7113 ['Dupl', 'Duployan'],
7114 ['Egyp', 'Egyptian_Hieroglyphs'],
7115 ['Elba', 'Elbasan'],
7116 ['Ethi', 'Ethiopic'],
7117 ['Geor', 'Georgian'],
7118 ['Glag', 'Glagolitic'],
7119 ['Gonm', 'Masaram_Gondi'],
7120 ['Goth', 'Gothic'],
7121 ['Gran', 'Grantha'],
7122 ['Grek', 'Greek'],
7123 ['Gujr', 'Gujarati'],
7124 ['Guru', 'Gurmukhi'],
7125 ['Hang', 'Hangul'],
7126 ['Hani', 'Han'],
7127 ['Hano', 'Hanunoo'],
7128 ['Hatr', 'Hatran'],
7129 ['Hebr', 'Hebrew'],
7130 ['Hira', 'Hiragana'],
7131 ['Hluw', 'Anatolian_Hieroglyphs'],
7132 ['Hmng', 'Pahawh_Hmong'],
7133 ['Hrkt', 'Katakana_Or_Hiragana'],
7134 ['Hung', 'Old_Hungarian'],
7135 ['Ital', 'Old_Italic'],
7136 ['Java', 'Javanese'],
7137 ['Kali', 'Kayah_Li'],
7138 ['Kana', 'Katakana'],
7139 ['Khar', 'Kharoshthi'],
7140 ['Khmr', 'Khmer'],
7141 ['Khoj', 'Khojki'],
7142 ['Knda', 'Kannada'],
7143 ['Kthi', 'Kaithi'],
7144 ['Lana', 'Tai_Tham'],
7145 ['Laoo', 'Lao'],
7146 ['Latn', 'Latin'],
7147 ['Lepc', 'Lepcha'],
7148 ['Limb', 'Limbu'],
7149 ['Lina', 'Linear_A'],
7150 ['Linb', 'Linear_B'],
7151 ['Lisu', 'Lisu'],
7152 ['Lyci', 'Lycian'],
7153 ['Lydi', 'Lydian'],
7154 ['Mahj', 'Mahajani'],
7155 ['Mand', 'Mandaic'],
7156 ['Mani', 'Manichaean'],
7157 ['Marc', 'Marchen'],
7158 ['Mend', 'Mende_Kikakui'],
7159 ['Merc', 'Meroitic_Cursive'],
7160 ['Mero', 'Meroitic_Hieroglyphs'],
7161 ['Mlym', 'Malayalam'],
7162 ['Modi', 'Modi'],
7163 ['Mong', 'Mongolian'],
7164 ['Mroo', 'Mro'],
7165 ['Mtei', 'Meetei_Mayek'],
7166 ['Mult', 'Multani'],
7167 ['Mymr', 'Myanmar'],
7168 ['Narb', 'Old_North_Arabian'],
7169 ['Nbat', 'Nabataean'],
7170 ['Newa', 'Newa'],
7171 ['Nkoo', 'Nko'],
7172 ['Nshu', 'Nushu'],
7173 ['Ogam', 'Ogham'],
7174 ['Olck', 'Ol_Chiki'],
7175 ['Orkh', 'Old_Turkic'],
7176 ['Orya', 'Oriya'],
7177 ['Osge', 'Osage'],
7178 ['Osma', 'Osmanya'],
7179 ['Palm', 'Palmyrene'],
7180 ['Pauc', 'Pau_Cin_Hau'],
7181 ['Perm', 'Old_Permic'],
7182 ['Phag', 'Phags_Pa'],
7183 ['Phli', 'Inscriptional_Pahlavi'],
7184 ['Phlp', 'Psalter_Pahlavi'],
7185 ['Phnx', 'Phoenician'],
7186 ['Plrd', 'Miao'],
7187 ['Prti', 'Inscriptional_Parthian'],
7188 ['Rjng', 'Rejang'],
7189 ['Runr', 'Runic'],
7190 ['Samr', 'Samaritan'],
7191 ['Sarb', 'Old_South_Arabian'],
7192 ['Saur', 'Saurashtra'],
7193 ['Sgnw', 'SignWriting'],
7194 ['Shaw', 'Shavian'],
7195 ['Shrd', 'Sharada'],
7196 ['Sidd', 'Siddham'],
7197 ['Sind', 'Khudawadi'],
7198 ['Sinh', 'Sinhala'],
7199 ['Sora', 'Sora_Sompeng'],
7200 ['Soyo', 'Soyombo'],
7201 ['Sund', 'Sundanese'],
7202 ['Sylo', 'Syloti_Nagri'],
7203 ['Syrc', 'Syriac'],
7204 ['Tagb', 'Tagbanwa'],
7205 ['Takr', 'Takri'],
7206 ['Tale', 'Tai_Le'],
7207 ['Talu', 'New_Tai_Lue'],
7208 ['Taml', 'Tamil'],
7209 ['Tang', 'Tangut'],
7210 ['Tavt', 'Tai_Viet'],
7211 ['Telu', 'Telugu'],
7212 ['Tfng', 'Tifinagh'],
7213 ['Tglg', 'Tagalog'],
7214 ['Thaa', 'Thaana'],
7215 ['Thai', 'Thai'],
7216 ['Tibt', 'Tibetan'],
7217 ['Tirh', 'Tirhuta'],
7218 ['Ugar', 'Ugaritic'],
7219 ['Vaii', 'Vai'],
7220 ['Wara', 'Warang_Citi'],
7221 ['Xpeo', 'Old_Persian'],
7222 ['Xsux', 'Cuneiform'],
7223 ['Yiii', 'Yi'],
7224 ['Zanb', 'Zanabazar_Square'],
7225 ['Zinh', 'Inherited'],
7226 ['Qaai', 'Inherited'],
7227 ['Zyyy', 'Common'],
7228 ['Zzzz', 'Unknown'],
7229 ['Adlam', 'Adlam'],
7230 ['Caucasian_Albanian', 'Caucasian_Albanian'],
7231 ['Arabic', 'Arabic'],
7232 ['Imperial_Aramaic', 'Imperial_Aramaic'],
7233 ['Armenian', 'Armenian'],
7234 ['Avestan', 'Avestan'],
7235 ['Balinese', 'Balinese'],
7236 ['Bamum', 'Bamum'],
7237 ['Bassa_Vah', 'Bassa_Vah'],
7238 ['Batak', 'Batak'],
7239 ['Bengali', 'Bengali'],
7240 ['Bhaiksuki', 'Bhaiksuki'],
7241 ['Bopomofo', 'Bopomofo'],
7242 ['Brahmi', 'Brahmi'],
7243 ['Braille', 'Braille'],
7244 ['Buginese', 'Buginese'],
7245 ['Buhid', 'Buhid'],
7246 ['Chakma', 'Chakma'],
7247 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
7248 ['Carian', 'Carian'],
7249 ['Cherokee', 'Cherokee'],
7250 ['Coptic', 'Coptic'],
7251 ['Cypriot', 'Cypriot'],
7252 ['Cyrillic', 'Cyrillic'],
7253 ['Devanagari', 'Devanagari'],
7254 ['Deseret', 'Deseret'],
7255 ['Duployan', 'Duployan'],
7256 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
7257 ['Elbasan', 'Elbasan'],
7258 ['Ethiopic', 'Ethiopic'],
7259 ['Georgian', 'Georgian'],
7260 ['Glagolitic', 'Glagolitic'],
7261 ['Masaram_Gondi', 'Masaram_Gondi'],
7262 ['Gothic', 'Gothic'],
7263 ['Grantha', 'Grantha'],
7264 ['Greek', 'Greek'],
7265 ['Gujarati', 'Gujarati'],
7266 ['Gurmukhi', 'Gurmukhi'],
7267 ['Hangul', 'Hangul'],
7268 ['Han', 'Han'],
7269 ['Hanunoo', 'Hanunoo'],
7270 ['Hatran', 'Hatran'],
7271 ['Hebrew', 'Hebrew'],
7272 ['Hiragana', 'Hiragana'],
7273 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
7274 ['Pahawh_Hmong', 'Pahawh_Hmong'],
7275 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
7276 ['Old_Hungarian', 'Old_Hungarian'],
7277 ['Old_Italic', 'Old_Italic'],
7278 ['Javanese', 'Javanese'],
7279 ['Kayah_Li', 'Kayah_Li'],
7280 ['Katakana', 'Katakana'],
7281 ['Kharoshthi', 'Kharoshthi'],
7282 ['Khmer', 'Khmer'],
7283 ['Khojki', 'Khojki'],
7284 ['Kannada', 'Kannada'],
7285 ['Kaithi', 'Kaithi'],
7286 ['Tai_Tham', 'Tai_Tham'],
7287 ['Lao', 'Lao'],
7288 ['Latin', 'Latin'],
7289 ['Lepcha', 'Lepcha'],
7290 ['Limbu', 'Limbu'],
7291 ['Linear_A', 'Linear_A'],
7292 ['Linear_B', 'Linear_B'],
7293 ['Lycian', 'Lycian'],
7294 ['Lydian', 'Lydian'],
7295 ['Mahajani', 'Mahajani'],
7296 ['Mandaic', 'Mandaic'],
7297 ['Manichaean', 'Manichaean'],
7298 ['Marchen', 'Marchen'],
7299 ['Mende_Kikakui', 'Mende_Kikakui'],
7300 ['Meroitic_Cursive', 'Meroitic_Cursive'],
7301 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
7302 ['Malayalam', 'Malayalam'],
7303 ['Mongolian', 'Mongolian'],
7304 ['Mro', 'Mro'],
7305 ['Meetei_Mayek', 'Meetei_Mayek'],
7306 ['Multani', 'Multani'],
7307 ['Myanmar', 'Myanmar'],
7308 ['Old_North_Arabian', 'Old_North_Arabian'],
7309 ['Nabataean', 'Nabataean'],
7310 ['Nko', 'Nko'],
7311 ['Nushu', 'Nushu'],
7312 ['Ogham', 'Ogham'],
7313 ['Ol_Chiki', 'Ol_Chiki'],
7314 ['Old_Turkic', 'Old_Turkic'],
7315 ['Oriya', 'Oriya'],
7316 ['Osage', 'Osage'],
7317 ['Osmanya', 'Osmanya'],
7318 ['Palmyrene', 'Palmyrene'],
7319 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
7320 ['Old_Permic', 'Old_Permic'],
7321 ['Phags_Pa', 'Phags_Pa'],
7322 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
7323 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
7324 ['Phoenician', 'Phoenician'],
7325 ['Miao', 'Miao'],
7326 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
7327 ['Rejang', 'Rejang'],
7328 ['Runic', 'Runic'],
7329 ['Samaritan', 'Samaritan'],
7330 ['Old_South_Arabian', 'Old_South_Arabian'],
7331 ['Saurashtra', 'Saurashtra'],
7332 ['SignWriting', 'SignWriting'],
7333 ['Shavian', 'Shavian'],
7334 ['Sharada', 'Sharada'],
7335 ['Siddham', 'Siddham'],
7336 ['Khudawadi', 'Khudawadi'],
7337 ['Sinhala', 'Sinhala'],
7338 ['Sora_Sompeng', 'Sora_Sompeng'],
7339 ['Soyombo', 'Soyombo'],
7340 ['Sundanese', 'Sundanese'],
7341 ['Syloti_Nagri', 'Syloti_Nagri'],
7342 ['Syriac', 'Syriac'],
7343 ['Tagbanwa', 'Tagbanwa'],
7344 ['Takri', 'Takri'],
7345 ['Tai_Le', 'Tai_Le'],
7346 ['New_Tai_Lue', 'New_Tai_Lue'],
7347 ['Tamil', 'Tamil'],
7348 ['Tangut', 'Tangut'],
7349 ['Tai_Viet', 'Tai_Viet'],
7350 ['Telugu', 'Telugu'],
7351 ['Tifinagh', 'Tifinagh'],
7352 ['Tagalog', 'Tagalog'],
7353 ['Thaana', 'Thaana'],
7354 ['Tibetan', 'Tibetan'],
7355 ['Tirhuta', 'Tirhuta'],
7356 ['Ugaritic', 'Ugaritic'],
7357 ['Vai', 'Vai'],
7358 ['Warang_Citi', 'Warang_Citi'],
7359 ['Old_Persian', 'Old_Persian'],
7360 ['Cuneiform', 'Cuneiform'],
7361 ['Yi', 'Yi'],
7362 ['Zanabazar_Square', 'Zanabazar_Square'],
7363 ['Inherited', 'Inherited'],
7364 ['Common', 'Common'],
7365 ['Unknown', 'Unknown']
7366 ])]
7367]);
7368
7369var matchPropertyValue = function(property, value) {
7370 var aliasToValue = mappings.get(property);
7371 if (!aliasToValue) {
7372 throw new Error(("Unknown property `" + property + "`."));
7373 }
7374 var canonicalValue = aliasToValue.get(value);
7375 if (canonicalValue) {
7376 return canonicalValue;
7377 }
7378 throw new Error(
7379 ("Unknown value `" + value + "` for property `" + property + "`.")
7380 );
7381};
7382
7383var unicodeMatchPropertyValueEcmascript = matchPropertyValue;
7384
7385var iuMappings = new Map([
7386 [0x4B, 0x212A],
7387 [0x53, 0x17F],
7388 [0x6B, 0x212A],
7389 [0x73, 0x17F],
7390 [0xB5, 0x39C],
7391 [0xC5, 0x212B],
7392 [0xDF, 0x1E9E],
7393 [0xE5, 0x212B],
7394 [0x17F, 0x53],
7395 [0x1C4, 0x1C5],
7396 [0x1C5, 0x1C4],
7397 [0x1C7, 0x1C8],
7398 [0x1C8, 0x1C7],
7399 [0x1CA, 0x1CB],
7400 [0x1CB, 0x1CA],
7401 [0x1F1, 0x1F2],
7402 [0x1F2, 0x1F1],
7403 [0x26A, 0xA7AE],
7404 [0x29D, 0xA7B2],
7405 [0x345, 0x1FBE],
7406 [0x392, 0x3D0],
7407 [0x395, 0x3F5],
7408 [0x398, 0x3F4],
7409 [0x399, 0x1FBE],
7410 [0x39A, 0x3F0],
7411 [0x39C, 0xB5],
7412 [0x3A0, 0x3D6],
7413 [0x3A1, 0x3F1],
7414 [0x3A3, 0x3C2],
7415 [0x3A6, 0x3D5],
7416 [0x3A9, 0x2126],
7417 [0x3B8, 0x3F4],
7418 [0x3C2, 0x3A3],
7419 [0x3C9, 0x2126],
7420 [0x3D0, 0x392],
7421 [0x3D1, 0x3F4],
7422 [0x3D5, 0x3A6],
7423 [0x3D6, 0x3A0],
7424 [0x3F0, 0x39A],
7425 [0x3F1, 0x3A1],
7426 [0x3F4, [
7427 0x398,
7428 0x3D1,
7429 0x3B8
7430 ]],
7431 [0x3F5, 0x395],
7432 [0x412, 0x1C80],
7433 [0x414, 0x1C81],
7434 [0x41E, 0x1C82],
7435 [0x421, 0x1C83],
7436 [0x422, 0x1C85],
7437 [0x42A, 0x1C86],
7438 [0x432, 0x1C80],
7439 [0x434, 0x1C81],
7440 [0x43E, 0x1C82],
7441 [0x441, 0x1C83],
7442 [0x442, [
7443 0x1C84,
7444 0x1C85
7445 ]],
7446 [0x44A, 0x1C86],
7447 [0x462, 0x1C87],
7448 [0x463, 0x1C87],
7449 [0x13A0, 0xAB70],
7450 [0x13A1, 0xAB71],
7451 [0x13A2, 0xAB72],
7452 [0x13A3, 0xAB73],
7453 [0x13A4, 0xAB74],
7454 [0x13A5, 0xAB75],
7455 [0x13A6, 0xAB76],
7456 [0x13A7, 0xAB77],
7457 [0x13A8, 0xAB78],
7458 [0x13A9, 0xAB79],
7459 [0x13AA, 0xAB7A],
7460 [0x13AB, 0xAB7B],
7461 [0x13AC, 0xAB7C],
7462 [0x13AD, 0xAB7D],
7463 [0x13AE, 0xAB7E],
7464 [0x13AF, 0xAB7F],
7465 [0x13B0, 0xAB80],
7466 [0x13B1, 0xAB81],
7467 [0x13B2, 0xAB82],
7468 [0x13B3, 0xAB83],
7469 [0x13B4, 0xAB84],
7470 [0x13B5, 0xAB85],
7471 [0x13B6, 0xAB86],
7472 [0x13B7, 0xAB87],
7473 [0x13B8, 0xAB88],
7474 [0x13B9, 0xAB89],
7475 [0x13BA, 0xAB8A],
7476 [0x13BB, 0xAB8B],
7477 [0x13BC, 0xAB8C],
7478 [0x13BD, 0xAB8D],
7479 [0x13BE, 0xAB8E],
7480 [0x13BF, 0xAB8F],
7481 [0x13C0, 0xAB90],
7482 [0x13C1, 0xAB91],
7483 [0x13C2, 0xAB92],
7484 [0x13C3, 0xAB93],
7485 [0x13C4, 0xAB94],
7486 [0x13C5, 0xAB95],
7487 [0x13C6, 0xAB96],
7488 [0x13C7, 0xAB97],
7489 [0x13C8, 0xAB98],
7490 [0x13C9, 0xAB99],
7491 [0x13CA, 0xAB9A],
7492 [0x13CB, 0xAB9B],
7493 [0x13CC, 0xAB9C],
7494 [0x13CD, 0xAB9D],
7495 [0x13CE, 0xAB9E],
7496 [0x13CF, 0xAB9F],
7497 [0x13D0, 0xABA0],
7498 [0x13D1, 0xABA1],
7499 [0x13D2, 0xABA2],
7500 [0x13D3, 0xABA3],
7501 [0x13D4, 0xABA4],
7502 [0x13D5, 0xABA5],
7503 [0x13D6, 0xABA6],
7504 [0x13D7, 0xABA7],
7505 [0x13D8, 0xABA8],
7506 [0x13D9, 0xABA9],
7507 [0x13DA, 0xABAA],
7508 [0x13DB, 0xABAB],
7509 [0x13DC, 0xABAC],
7510 [0x13DD, 0xABAD],
7511 [0x13DE, 0xABAE],
7512 [0x13DF, 0xABAF],
7513 [0x13E0, 0xABB0],
7514 [0x13E1, 0xABB1],
7515 [0x13E2, 0xABB2],
7516 [0x13E3, 0xABB3],
7517 [0x13E4, 0xABB4],
7518 [0x13E5, 0xABB5],
7519 [0x13E6, 0xABB6],
7520 [0x13E7, 0xABB7],
7521 [0x13E8, 0xABB8],
7522 [0x13E9, 0xABB9],
7523 [0x13EA, 0xABBA],
7524 [0x13EB, 0xABBB],
7525 [0x13EC, 0xABBC],
7526 [0x13ED, 0xABBD],
7527 [0x13EE, 0xABBE],
7528 [0x13EF, 0xABBF],
7529 [0x13F0, 0x13F8],
7530 [0x13F1, 0x13F9],
7531 [0x13F2, 0x13FA],
7532 [0x13F3, 0x13FB],
7533 [0x13F4, 0x13FC],
7534 [0x13F5, 0x13FD],
7535 [0x13F8, 0x13F0],
7536 [0x13F9, 0x13F1],
7537 [0x13FA, 0x13F2],
7538 [0x13FB, 0x13F3],
7539 [0x13FC, 0x13F4],
7540 [0x13FD, 0x13F5],
7541 [0x1C80, [
7542 0x412,
7543 0x432
7544 ]],
7545 [0x1C81, [
7546 0x414,
7547 0x434
7548 ]],
7549 [0x1C82, [
7550 0x41E,
7551 0x43E
7552 ]],
7553 [0x1C83, [
7554 0x421,
7555 0x441
7556 ]],
7557 [0x1C84, [
7558 0x1C85,
7559 0x442
7560 ]],
7561 [0x1C85, [
7562 0x422,
7563 0x1C84,
7564 0x442
7565 ]],
7566 [0x1C86, [
7567 0x42A,
7568 0x44A
7569 ]],
7570 [0x1C87, [
7571 0x462,
7572 0x463
7573 ]],
7574 [0x1C88, [
7575 0xA64A,
7576 0xA64B
7577 ]],
7578 [0x1E60, 0x1E9B],
7579 [0x1E9B, 0x1E60],
7580 [0x1E9E, 0xDF],
7581 [0x1F80, 0x1F88],
7582 [0x1F81, 0x1F89],
7583 [0x1F82, 0x1F8A],
7584 [0x1F83, 0x1F8B],
7585 [0x1F84, 0x1F8C],
7586 [0x1F85, 0x1F8D],
7587 [0x1F86, 0x1F8E],
7588 [0x1F87, 0x1F8F],
7589 [0x1F88, 0x1F80],
7590 [0x1F89, 0x1F81],
7591 [0x1F8A, 0x1F82],
7592 [0x1F8B, 0x1F83],
7593 [0x1F8C, 0x1F84],
7594 [0x1F8D, 0x1F85],
7595 [0x1F8E, 0x1F86],
7596 [0x1F8F, 0x1F87],
7597 [0x1F90, 0x1F98],
7598 [0x1F91, 0x1F99],
7599 [0x1F92, 0x1F9A],
7600 [0x1F93, 0x1F9B],
7601 [0x1F94, 0x1F9C],
7602 [0x1F95, 0x1F9D],
7603 [0x1F96, 0x1F9E],
7604 [0x1F97, 0x1F9F],
7605 [0x1F98, 0x1F90],
7606 [0x1F99, 0x1F91],
7607 [0x1F9A, 0x1F92],
7608 [0x1F9B, 0x1F93],
7609 [0x1F9C, 0x1F94],
7610 [0x1F9D, 0x1F95],
7611 [0x1F9E, 0x1F96],
7612 [0x1F9F, 0x1F97],
7613 [0x1FA0, 0x1FA8],
7614 [0x1FA1, 0x1FA9],
7615 [0x1FA2, 0x1FAA],
7616 [0x1FA3, 0x1FAB],
7617 [0x1FA4, 0x1FAC],
7618 [0x1FA5, 0x1FAD],
7619 [0x1FA6, 0x1FAE],
7620 [0x1FA7, 0x1FAF],
7621 [0x1FA8, 0x1FA0],
7622 [0x1FA9, 0x1FA1],
7623 [0x1FAA, 0x1FA2],
7624 [0x1FAB, 0x1FA3],
7625 [0x1FAC, 0x1FA4],
7626 [0x1FAD, 0x1FA5],
7627 [0x1FAE, 0x1FA6],
7628 [0x1FAF, 0x1FA7],
7629 [0x1FB3, 0x1FBC],
7630 [0x1FBC, 0x1FB3],
7631 [0x1FBE, [
7632 0x345,
7633 0x399
7634 ]],
7635 [0x1FC3, 0x1FCC],
7636 [0x1FCC, 0x1FC3],
7637 [0x1FF3, 0x1FFC],
7638 [0x1FFC, 0x1FF3],
7639 [0x2126, [
7640 0x3A9,
7641 0x3C9
7642 ]],
7643 [0x212A, 0x4B],
7644 [0x212B, [
7645 0xC5,
7646 0xE5
7647 ]],
7648 [0xA64A, 0x1C88],
7649 [0xA64B, 0x1C88],
7650 [0xA7AE, 0x26A],
7651 [0xA7B2, 0x29D],
7652 [0xA7B3, 0xAB53],
7653 [0xA7B4, 0xA7B5],
7654 [0xA7B5, 0xA7B4],
7655 [0xA7B6, 0xA7B7],
7656 [0xA7B7, 0xA7B6],
7657 [0xAB53, 0xA7B3],
7658 [0xAB70, 0x13A0],
7659 [0xAB71, 0x13A1],
7660 [0xAB72, 0x13A2],
7661 [0xAB73, 0x13A3],
7662 [0xAB74, 0x13A4],
7663 [0xAB75, 0x13A5],
7664 [0xAB76, 0x13A6],
7665 [0xAB77, 0x13A7],
7666 [0xAB78, 0x13A8],
7667 [0xAB79, 0x13A9],
7668 [0xAB7A, 0x13AA],
7669 [0xAB7B, 0x13AB],
7670 [0xAB7C, 0x13AC],
7671 [0xAB7D, 0x13AD],
7672 [0xAB7E, 0x13AE],
7673 [0xAB7F, 0x13AF],
7674 [0xAB80, 0x13B0],
7675 [0xAB81, 0x13B1],
7676 [0xAB82, 0x13B2],
7677 [0xAB83, 0x13B3],
7678 [0xAB84, 0x13B4],
7679 [0xAB85, 0x13B5],
7680 [0xAB86, 0x13B6],
7681 [0xAB87, 0x13B7],
7682 [0xAB88, 0x13B8],
7683 [0xAB89, 0x13B9],
7684 [0xAB8A, 0x13BA],
7685 [0xAB8B, 0x13BB],
7686 [0xAB8C, 0x13BC],
7687 [0xAB8D, 0x13BD],
7688 [0xAB8E, 0x13BE],
7689 [0xAB8F, 0x13BF],
7690 [0xAB90, 0x13C0],
7691 [0xAB91, 0x13C1],
7692 [0xAB92, 0x13C2],
7693 [0xAB93, 0x13C3],
7694 [0xAB94, 0x13C4],
7695 [0xAB95, 0x13C5],
7696 [0xAB96, 0x13C6],
7697 [0xAB97, 0x13C7],
7698 [0xAB98, 0x13C8],
7699 [0xAB99, 0x13C9],
7700 [0xAB9A, 0x13CA],
7701 [0xAB9B, 0x13CB],
7702 [0xAB9C, 0x13CC],
7703 [0xAB9D, 0x13CD],
7704 [0xAB9E, 0x13CE],
7705 [0xAB9F, 0x13CF],
7706 [0xABA0, 0x13D0],
7707 [0xABA1, 0x13D1],
7708 [0xABA2, 0x13D2],
7709 [0xABA3, 0x13D3],
7710 [0xABA4, 0x13D4],
7711 [0xABA5, 0x13D5],
7712 [0xABA6, 0x13D6],
7713 [0xABA7, 0x13D7],
7714 [0xABA8, 0x13D8],
7715 [0xABA9, 0x13D9],
7716 [0xABAA, 0x13DA],
7717 [0xABAB, 0x13DB],
7718 [0xABAC, 0x13DC],
7719 [0xABAD, 0x13DD],
7720 [0xABAE, 0x13DE],
7721 [0xABAF, 0x13DF],
7722 [0xABB0, 0x13E0],
7723 [0xABB1, 0x13E1],
7724 [0xABB2, 0x13E2],
7725 [0xABB3, 0x13E3],
7726 [0xABB4, 0x13E4],
7727 [0xABB5, 0x13E5],
7728 [0xABB6, 0x13E6],
7729 [0xABB7, 0x13E7],
7730 [0xABB8, 0x13E8],
7731 [0xABB9, 0x13E9],
7732 [0xABBA, 0x13EA],
7733 [0xABBB, 0x13EB],
7734 [0xABBC, 0x13EC],
7735 [0xABBD, 0x13ED],
7736 [0xABBE, 0x13EE],
7737 [0xABBF, 0x13EF],
7738 [0x10400, 0x10428],
7739 [0x10401, 0x10429],
7740 [0x10402, 0x1042A],
7741 [0x10403, 0x1042B],
7742 [0x10404, 0x1042C],
7743 [0x10405, 0x1042D],
7744 [0x10406, 0x1042E],
7745 [0x10407, 0x1042F],
7746 [0x10408, 0x10430],
7747 [0x10409, 0x10431],
7748 [0x1040A, 0x10432],
7749 [0x1040B, 0x10433],
7750 [0x1040C, 0x10434],
7751 [0x1040D, 0x10435],
7752 [0x1040E, 0x10436],
7753 [0x1040F, 0x10437],
7754 [0x10410, 0x10438],
7755 [0x10411, 0x10439],
7756 [0x10412, 0x1043A],
7757 [0x10413, 0x1043B],
7758 [0x10414, 0x1043C],
7759 [0x10415, 0x1043D],
7760 [0x10416, 0x1043E],
7761 [0x10417, 0x1043F],
7762 [0x10418, 0x10440],
7763 [0x10419, 0x10441],
7764 [0x1041A, 0x10442],
7765 [0x1041B, 0x10443],
7766 [0x1041C, 0x10444],
7767 [0x1041D, 0x10445],
7768 [0x1041E, 0x10446],
7769 [0x1041F, 0x10447],
7770 [0x10420, 0x10448],
7771 [0x10421, 0x10449],
7772 [0x10422, 0x1044A],
7773 [0x10423, 0x1044B],
7774 [0x10424, 0x1044C],
7775 [0x10425, 0x1044D],
7776 [0x10426, 0x1044E],
7777 [0x10427, 0x1044F],
7778 [0x10428, 0x10400],
7779 [0x10429, 0x10401],
7780 [0x1042A, 0x10402],
7781 [0x1042B, 0x10403],
7782 [0x1042C, 0x10404],
7783 [0x1042D, 0x10405],
7784 [0x1042E, 0x10406],
7785 [0x1042F, 0x10407],
7786 [0x10430, 0x10408],
7787 [0x10431, 0x10409],
7788 [0x10432, 0x1040A],
7789 [0x10433, 0x1040B],
7790 [0x10434, 0x1040C],
7791 [0x10435, 0x1040D],
7792 [0x10436, 0x1040E],
7793 [0x10437, 0x1040F],
7794 [0x10438, 0x10410],
7795 [0x10439, 0x10411],
7796 [0x1043A, 0x10412],
7797 [0x1043B, 0x10413],
7798 [0x1043C, 0x10414],
7799 [0x1043D, 0x10415],
7800 [0x1043E, 0x10416],
7801 [0x1043F, 0x10417],
7802 [0x10440, 0x10418],
7803 [0x10441, 0x10419],
7804 [0x10442, 0x1041A],
7805 [0x10443, 0x1041B],
7806 [0x10444, 0x1041C],
7807 [0x10445, 0x1041D],
7808 [0x10446, 0x1041E],
7809 [0x10447, 0x1041F],
7810 [0x10448, 0x10420],
7811 [0x10449, 0x10421],
7812 [0x1044A, 0x10422],
7813 [0x1044B, 0x10423],
7814 [0x1044C, 0x10424],
7815 [0x1044D, 0x10425],
7816 [0x1044E, 0x10426],
7817 [0x1044F, 0x10427],
7818 [0x104B0, 0x104D8],
7819 [0x104B1, 0x104D9],
7820 [0x104B2, 0x104DA],
7821 [0x104B3, 0x104DB],
7822 [0x104B4, 0x104DC],
7823 [0x104B5, 0x104DD],
7824 [0x104B6, 0x104DE],
7825 [0x104B7, 0x104DF],
7826 [0x104B8, 0x104E0],
7827 [0x104B9, 0x104E1],
7828 [0x104BA, 0x104E2],
7829 [0x104BB, 0x104E3],
7830 [0x104BC, 0x104E4],
7831 [0x104BD, 0x104E5],
7832 [0x104BE, 0x104E6],
7833 [0x104BF, 0x104E7],
7834 [0x104C0, 0x104E8],
7835 [0x104C1, 0x104E9],
7836 [0x104C2, 0x104EA],
7837 [0x104C3, 0x104EB],
7838 [0x104C4, 0x104EC],
7839 [0x104C5, 0x104ED],
7840 [0x104C6, 0x104EE],
7841 [0x104C7, 0x104EF],
7842 [0x104C8, 0x104F0],
7843 [0x104C9, 0x104F1],
7844 [0x104CA, 0x104F2],
7845 [0x104CB, 0x104F3],
7846 [0x104CC, 0x104F4],
7847 [0x104CD, 0x104F5],
7848 [0x104CE, 0x104F6],
7849 [0x104CF, 0x104F7],
7850 [0x104D0, 0x104F8],
7851 [0x104D1, 0x104F9],
7852 [0x104D2, 0x104FA],
7853 [0x104D3, 0x104FB],
7854 [0x104D8, 0x104B0],
7855 [0x104D9, 0x104B1],
7856 [0x104DA, 0x104B2],
7857 [0x104DB, 0x104B3],
7858 [0x104DC, 0x104B4],
7859 [0x104DD, 0x104B5],
7860 [0x104DE, 0x104B6],
7861 [0x104DF, 0x104B7],
7862 [0x104E0, 0x104B8],
7863 [0x104E1, 0x104B9],
7864 [0x104E2, 0x104BA],
7865 [0x104E3, 0x104BB],
7866 [0x104E4, 0x104BC],
7867 [0x104E5, 0x104BD],
7868 [0x104E6, 0x104BE],
7869 [0x104E7, 0x104BF],
7870 [0x104E8, 0x104C0],
7871 [0x104E9, 0x104C1],
7872 [0x104EA, 0x104C2],
7873 [0x104EB, 0x104C3],
7874 [0x104EC, 0x104C4],
7875 [0x104ED, 0x104C5],
7876 [0x104EE, 0x104C6],
7877 [0x104EF, 0x104C7],
7878 [0x104F0, 0x104C8],
7879 [0x104F1, 0x104C9],
7880 [0x104F2, 0x104CA],
7881 [0x104F3, 0x104CB],
7882 [0x104F4, 0x104CC],
7883 [0x104F5, 0x104CD],
7884 [0x104F6, 0x104CE],
7885 [0x104F7, 0x104CF],
7886 [0x104F8, 0x104D0],
7887 [0x104F9, 0x104D1],
7888 [0x104FA, 0x104D2],
7889 [0x104FB, 0x104D3],
7890 [0x10C80, 0x10CC0],
7891 [0x10C81, 0x10CC1],
7892 [0x10C82, 0x10CC2],
7893 [0x10C83, 0x10CC3],
7894 [0x10C84, 0x10CC4],
7895 [0x10C85, 0x10CC5],
7896 [0x10C86, 0x10CC6],
7897 [0x10C87, 0x10CC7],
7898 [0x10C88, 0x10CC8],
7899 [0x10C89, 0x10CC9],
7900 [0x10C8A, 0x10CCA],
7901 [0x10C8B, 0x10CCB],
7902 [0x10C8C, 0x10CCC],
7903 [0x10C8D, 0x10CCD],
7904 [0x10C8E, 0x10CCE],
7905 [0x10C8F, 0x10CCF],
7906 [0x10C90, 0x10CD0],
7907 [0x10C91, 0x10CD1],
7908 [0x10C92, 0x10CD2],
7909 [0x10C93, 0x10CD3],
7910 [0x10C94, 0x10CD4],
7911 [0x10C95, 0x10CD5],
7912 [0x10C96, 0x10CD6],
7913 [0x10C97, 0x10CD7],
7914 [0x10C98, 0x10CD8],
7915 [0x10C99, 0x10CD9],
7916 [0x10C9A, 0x10CDA],
7917 [0x10C9B, 0x10CDB],
7918 [0x10C9C, 0x10CDC],
7919 [0x10C9D, 0x10CDD],
7920 [0x10C9E, 0x10CDE],
7921 [0x10C9F, 0x10CDF],
7922 [0x10CA0, 0x10CE0],
7923 [0x10CA1, 0x10CE1],
7924 [0x10CA2, 0x10CE2],
7925 [0x10CA3, 0x10CE3],
7926 [0x10CA4, 0x10CE4],
7927 [0x10CA5, 0x10CE5],
7928 [0x10CA6, 0x10CE6],
7929 [0x10CA7, 0x10CE7],
7930 [0x10CA8, 0x10CE8],
7931 [0x10CA9, 0x10CE9],
7932 [0x10CAA, 0x10CEA],
7933 [0x10CAB, 0x10CEB],
7934 [0x10CAC, 0x10CEC],
7935 [0x10CAD, 0x10CED],
7936 [0x10CAE, 0x10CEE],
7937 [0x10CAF, 0x10CEF],
7938 [0x10CB0, 0x10CF0],
7939 [0x10CB1, 0x10CF1],
7940 [0x10CB2, 0x10CF2],
7941 [0x10CC0, 0x10C80],
7942 [0x10CC1, 0x10C81],
7943 [0x10CC2, 0x10C82],
7944 [0x10CC3, 0x10C83],
7945 [0x10CC4, 0x10C84],
7946 [0x10CC5, 0x10C85],
7947 [0x10CC6, 0x10C86],
7948 [0x10CC7, 0x10C87],
7949 [0x10CC8, 0x10C88],
7950 [0x10CC9, 0x10C89],
7951 [0x10CCA, 0x10C8A],
7952 [0x10CCB, 0x10C8B],
7953 [0x10CCC, 0x10C8C],
7954 [0x10CCD, 0x10C8D],
7955 [0x10CCE, 0x10C8E],
7956 [0x10CCF, 0x10C8F],
7957 [0x10CD0, 0x10C90],
7958 [0x10CD1, 0x10C91],
7959 [0x10CD2, 0x10C92],
7960 [0x10CD3, 0x10C93],
7961 [0x10CD4, 0x10C94],
7962 [0x10CD5, 0x10C95],
7963 [0x10CD6, 0x10C96],
7964 [0x10CD7, 0x10C97],
7965 [0x10CD8, 0x10C98],
7966 [0x10CD9, 0x10C99],
7967 [0x10CDA, 0x10C9A],
7968 [0x10CDB, 0x10C9B],
7969 [0x10CDC, 0x10C9C],
7970 [0x10CDD, 0x10C9D],
7971 [0x10CDE, 0x10C9E],
7972 [0x10CDF, 0x10C9F],
7973 [0x10CE0, 0x10CA0],
7974 [0x10CE1, 0x10CA1],
7975 [0x10CE2, 0x10CA2],
7976 [0x10CE3, 0x10CA3],
7977 [0x10CE4, 0x10CA4],
7978 [0x10CE5, 0x10CA5],
7979 [0x10CE6, 0x10CA6],
7980 [0x10CE7, 0x10CA7],
7981 [0x10CE8, 0x10CA8],
7982 [0x10CE9, 0x10CA9],
7983 [0x10CEA, 0x10CAA],
7984 [0x10CEB, 0x10CAB],
7985 [0x10CEC, 0x10CAC],
7986 [0x10CED, 0x10CAD],
7987 [0x10CEE, 0x10CAE],
7988 [0x10CEF, 0x10CAF],
7989 [0x10CF0, 0x10CB0],
7990 [0x10CF1, 0x10CB1],
7991 [0x10CF2, 0x10CB2],
7992 [0x118A0, 0x118C0],
7993 [0x118A1, 0x118C1],
7994 [0x118A2, 0x118C2],
7995 [0x118A3, 0x118C3],
7996 [0x118A4, 0x118C4],
7997 [0x118A5, 0x118C5],
7998 [0x118A6, 0x118C6],
7999 [0x118A7, 0x118C7],
8000 [0x118A8, 0x118C8],
8001 [0x118A9, 0x118C9],
8002 [0x118AA, 0x118CA],
8003 [0x118AB, 0x118CB],
8004 [0x118AC, 0x118CC],
8005 [0x118AD, 0x118CD],
8006 [0x118AE, 0x118CE],
8007 [0x118AF, 0x118CF],
8008 [0x118B0, 0x118D0],
8009 [0x118B1, 0x118D1],
8010 [0x118B2, 0x118D2],
8011 [0x118B3, 0x118D3],
8012 [0x118B4, 0x118D4],
8013 [0x118B5, 0x118D5],
8014 [0x118B6, 0x118D6],
8015 [0x118B7, 0x118D7],
8016 [0x118B8, 0x118D8],
8017 [0x118B9, 0x118D9],
8018 [0x118BA, 0x118DA],
8019 [0x118BB, 0x118DB],
8020 [0x118BC, 0x118DC],
8021 [0x118BD, 0x118DD],
8022 [0x118BE, 0x118DE],
8023 [0x118BF, 0x118DF],
8024 [0x118C0, 0x118A0],
8025 [0x118C1, 0x118A1],
8026 [0x118C2, 0x118A2],
8027 [0x118C3, 0x118A3],
8028 [0x118C4, 0x118A4],
8029 [0x118C5, 0x118A5],
8030 [0x118C6, 0x118A6],
8031 [0x118C7, 0x118A7],
8032 [0x118C8, 0x118A8],
8033 [0x118C9, 0x118A9],
8034 [0x118CA, 0x118AA],
8035 [0x118CB, 0x118AB],
8036 [0x118CC, 0x118AC],
8037 [0x118CD, 0x118AD],
8038 [0x118CE, 0x118AE],
8039 [0x118CF, 0x118AF],
8040 [0x118D0, 0x118B0],
8041 [0x118D1, 0x118B1],
8042 [0x118D2, 0x118B2],
8043 [0x118D3, 0x118B3],
8044 [0x118D4, 0x118B4],
8045 [0x118D5, 0x118B5],
8046 [0x118D6, 0x118B6],
8047 [0x118D7, 0x118B7],
8048 [0x118D8, 0x118B8],
8049 [0x118D9, 0x118B9],
8050 [0x118DA, 0x118BA],
8051 [0x118DB, 0x118BB],
8052 [0x118DC, 0x118BC],
8053 [0x118DD, 0x118BD],
8054 [0x118DE, 0x118BE],
8055 [0x118DF, 0x118BF],
8056 [0x1E900, 0x1E922],
8057 [0x1E901, 0x1E923],
8058 [0x1E902, 0x1E924],
8059 [0x1E903, 0x1E925],
8060 [0x1E904, 0x1E926],
8061 [0x1E905, 0x1E927],
8062 [0x1E906, 0x1E928],
8063 [0x1E907, 0x1E929],
8064 [0x1E908, 0x1E92A],
8065 [0x1E909, 0x1E92B],
8066 [0x1E90A, 0x1E92C],
8067 [0x1E90B, 0x1E92D],
8068 [0x1E90C, 0x1E92E],
8069 [0x1E90D, 0x1E92F],
8070 [0x1E90E, 0x1E930],
8071 [0x1E90F, 0x1E931],
8072 [0x1E910, 0x1E932],
8073 [0x1E911, 0x1E933],
8074 [0x1E912, 0x1E934],
8075 [0x1E913, 0x1E935],
8076 [0x1E914, 0x1E936],
8077 [0x1E915, 0x1E937],
8078 [0x1E916, 0x1E938],
8079 [0x1E917, 0x1E939],
8080 [0x1E918, 0x1E93A],
8081 [0x1E919, 0x1E93B],
8082 [0x1E91A, 0x1E93C],
8083 [0x1E91B, 0x1E93D],
8084 [0x1E91C, 0x1E93E],
8085 [0x1E91D, 0x1E93F],
8086 [0x1E91E, 0x1E940],
8087 [0x1E91F, 0x1E941],
8088 [0x1E920, 0x1E942],
8089 [0x1E921, 0x1E943],
8090 [0x1E922, 0x1E900],
8091 [0x1E923, 0x1E901],
8092 [0x1E924, 0x1E902],
8093 [0x1E925, 0x1E903],
8094 [0x1E926, 0x1E904],
8095 [0x1E927, 0x1E905],
8096 [0x1E928, 0x1E906],
8097 [0x1E929, 0x1E907],
8098 [0x1E92A, 0x1E908],
8099 [0x1E92B, 0x1E909],
8100 [0x1E92C, 0x1E90A],
8101 [0x1E92D, 0x1E90B],
8102 [0x1E92E, 0x1E90C],
8103 [0x1E92F, 0x1E90D],
8104 [0x1E930, 0x1E90E],
8105 [0x1E931, 0x1E90F],
8106 [0x1E932, 0x1E910],
8107 [0x1E933, 0x1E911],
8108 [0x1E934, 0x1E912],
8109 [0x1E935, 0x1E913],
8110 [0x1E936, 0x1E914],
8111 [0x1E937, 0x1E915],
8112 [0x1E938, 0x1E916],
8113 [0x1E939, 0x1E917],
8114 [0x1E93A, 0x1E918],
8115 [0x1E93B, 0x1E919],
8116 [0x1E93C, 0x1E91A],
8117 [0x1E93D, 0x1E91B],
8118 [0x1E93E, 0x1E91C],
8119 [0x1E93F, 0x1E91D],
8120 [0x1E940, 0x1E91E],
8121 [0x1E941, 0x1E91F],
8122 [0x1E942, 0x1E920],
8123 [0x1E943, 0x1E921]
8124]);
8125
8126var REGULAR = new Map([
8127 ['d', regenerate()
8128 .addRange(0x30, 0x39)],
8129 ['D', regenerate()
8130 .addRange(0x0, 0x2F)
8131 .addRange(0x3A, 0xFFFF)],
8132 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
8133 .addRange(0x9, 0xD)
8134 .addRange(0x2000, 0x200A)
8135 .addRange(0x2028, 0x2029)],
8136 ['S', regenerate()
8137 .addRange(0x0, 0x8)
8138 .addRange(0xE, 0x1F)
8139 .addRange(0x21, 0x9F)
8140 .addRange(0xA1, 0x167F)
8141 .addRange(0x1681, 0x1FFF)
8142 .addRange(0x200B, 0x2027)
8143 .addRange(0x202A, 0x202E)
8144 .addRange(0x2030, 0x205E)
8145 .addRange(0x2060, 0x2FFF)
8146 .addRange(0x3001, 0xFEFE)
8147 .addRange(0xFF00, 0xFFFF)],
8148 ['w', regenerate(0x5F)
8149 .addRange(0x30, 0x39)
8150 .addRange(0x41, 0x5A)
8151 .addRange(0x61, 0x7A)],
8152 ['W', regenerate(0x60)
8153 .addRange(0x0, 0x2F)
8154 .addRange(0x3A, 0x40)
8155 .addRange(0x5B, 0x5E)
8156 .addRange(0x7B, 0xFFFF)]
8157]);
8158
8159var UNICODE = new Map([
8160 ['d', regenerate()
8161 .addRange(0x30, 0x39)],
8162 ['D', regenerate()
8163 .addRange(0x0, 0x2F)
8164 .addRange(0x3A, 0x10FFFF)],
8165 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
8166 .addRange(0x9, 0xD)
8167 .addRange(0x2000, 0x200A)
8168 .addRange(0x2028, 0x2029)],
8169 ['S', regenerate()
8170 .addRange(0x0, 0x8)
8171 .addRange(0xE, 0x1F)
8172 .addRange(0x21, 0x9F)
8173 .addRange(0xA1, 0x167F)
8174 .addRange(0x1681, 0x1FFF)
8175 .addRange(0x200B, 0x2027)
8176 .addRange(0x202A, 0x202E)
8177 .addRange(0x2030, 0x205E)
8178 .addRange(0x2060, 0x2FFF)
8179 .addRange(0x3001, 0xFEFE)
8180 .addRange(0xFF00, 0x10FFFF)],
8181 ['w', regenerate(0x5F)
8182 .addRange(0x30, 0x39)
8183 .addRange(0x41, 0x5A)
8184 .addRange(0x61, 0x7A)],
8185 ['W', regenerate(0x60)
8186 .addRange(0x0, 0x2F)
8187 .addRange(0x3A, 0x40)
8188 .addRange(0x5B, 0x5E)
8189 .addRange(0x7B, 0x10FFFF)]
8190]);
8191
8192var UNICODE_IGNORE_CASE = new Map([
8193 ['d', regenerate()
8194 .addRange(0x30, 0x39)],
8195 ['D', regenerate()
8196 .addRange(0x0, 0x2F)
8197 .addRange(0x3A, 0x10FFFF)],
8198 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
8199 .addRange(0x9, 0xD)
8200 .addRange(0x2000, 0x200A)
8201 .addRange(0x2028, 0x2029)],
8202 ['S', regenerate()
8203 .addRange(0x0, 0x8)
8204 .addRange(0xE, 0x1F)
8205 .addRange(0x21, 0x9F)
8206 .addRange(0xA1, 0x167F)
8207 .addRange(0x1681, 0x1FFF)
8208 .addRange(0x200B, 0x2027)
8209 .addRange(0x202A, 0x202E)
8210 .addRange(0x2030, 0x205E)
8211 .addRange(0x2060, 0x2FFF)
8212 .addRange(0x3001, 0xFEFE)
8213 .addRange(0xFF00, 0x10FFFF)],
8214 ['w', regenerate(0x5F, 0x17F, 0x212A)
8215 .addRange(0x30, 0x39)
8216 .addRange(0x41, 0x5A)
8217 .addRange(0x61, 0x7A)],
8218 ['W', regenerate(0x60)
8219 .addRange(0x0, 0x2F)
8220 .addRange(0x3A, 0x40)
8221 .addRange(0x5B, 0x5E)
8222 .addRange(0x7B, 0x17E)
8223 .addRange(0x180, 0x2129)
8224 .addRange(0x212B, 0x10FFFF)]
8225]);
8226
8227var characterClassEscapeSets = {
8228 REGULAR: REGULAR,
8229 UNICODE: UNICODE,
8230 UNICODE_IGNORE_CASE: UNICODE_IGNORE_CASE
8231};
8232
8233var rewritePattern_1 = createCommonjsModule(function (module) {
8234var generate = regjsgen.generate;
8235var parse = parser.parse;
8236
8237
8238
8239
8240
8241
8242// Prepare a Regenerate set containing all code points, used for negative
8243// character classes (if any).
8244var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
8245// Without the `u` flag, the range stops at 0xFFFF.
8246// https://mths.be/es6#sec-pattern-semantics
8247var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
8248
8249// Prepare a Regenerate set containing all code points that are supposed to be
8250// matched by `/./u`. https://mths.be/es6#sec-atom
8251var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
8252 .remove(
8253 // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
8254 0x000A, // Line Feed <LF>
8255 0x000D, // Carriage Return <CR>
8256 0x2028, // Line Separator <LS>
8257 0x2029 // Paragraph Separator <PS>
8258 );
8259// Prepare a Regenerate set containing all code points that are supposed to be
8260// matched by `/./` (only BMP code points).
8261var DOT_SET = DOT_SET_UNICODE.clone()
8262 .intersection(BMP_SET);
8263
8264var getCharacterClassEscapeSet = function (character, unicode, ignoreCase) {
8265 if (unicode) {
8266 if (ignoreCase) {
8267 return characterClassEscapeSets.UNICODE_IGNORE_CASE.get(character);
8268 }
8269 return characterClassEscapeSets.UNICODE.get(character);
8270 }
8271 return characterClassEscapeSets.REGULAR.get(character);
8272};
8273
8274var getDotSet = function (unicode, dotAll) {
8275 if (dotAll) {
8276 return unicode ? UNICODE_SET : BMP_SET;
8277 }
8278 return unicode ? DOT_SET_UNICODE : DOT_SET;
8279};
8280
8281var getUnicodePropertyValueSet = function (property, value) {
8282 var path = value ?
8283 (property + "/" + value) :
8284 ("Binary_Property/" + property);
8285 try {
8286 return commonjsRequire(("regenerate-unicode-properties/" + path + ".js"));
8287 } catch (exception) {
8288 throw new Error(
8289 "Failed to recognize value `" + value + "` for property " +
8290 "`" + property + "`."
8291 );
8292 }
8293};
8294
8295var handleLoneUnicodePropertyNameOrValue = function (value) {
8296 // It could be a `General_Category` value or a binary property.
8297 // Note: `unicodeMatchPropertyValue` throws on invalid values.
8298 try {
8299 var property$1 = 'General_Category';
8300 var category = unicodeMatchPropertyValueEcmascript(property$1, value);
8301 return getUnicodePropertyValueSet(property$1, category);
8302 } catch (exception) {}
8303 // It’s not a `General_Category` value, so check if it’s a binary
8304 // property. Note: `unicodeMatchProperty` throws on invalid properties.
8305 var property = unicodeMatchPropertyEcmascript(value);
8306 return getUnicodePropertyValueSet(property);
8307};
8308
8309var getUnicodePropertyEscapeSet = function (value, isNegative) {
8310 var parts = value.split('=');
8311 var firstPart = parts[0];
8312 var set;
8313 if (parts.length == 1) {
8314 set = handleLoneUnicodePropertyNameOrValue(firstPart);
8315 } else {
8316 // The pattern consists of two parts, i.e. `Property=Value`.
8317 var property = unicodeMatchPropertyEcmascript(firstPart);
8318 var value$1 = unicodeMatchPropertyValueEcmascript(property, parts[1]);
8319 set = getUnicodePropertyValueSet(property, value$1);
8320 }
8321 if (isNegative) {
8322 return UNICODE_SET.clone().remove(set);
8323 }
8324 return set.clone();
8325};
8326
8327// Given a range of code points, add any case-folded code points in that range
8328// to a set.
8329regenerate.prototype.iuAddRange = function(min, max) {
8330 var $this = this;
8331 do {
8332 var folded = caseFold(min);
8333 if (folded) {
8334 $this.add(folded);
8335 }
8336 } while (++min <= max);
8337 return $this;
8338};
8339
8340var update = function (item, pattern) {
8341 var tree = parse(pattern, config.useUnicodeFlag ? 'u' : '');
8342 switch (tree.type) {
8343 case 'characterClass':
8344 case 'group':
8345 case 'value':
8346 // No wrapping needed.
8347 break;
8348 default:
8349 // Wrap the pattern in a non-capturing group.
8350 tree = wrap(tree, pattern);
8351 }
8352 Object.assign(item, tree);
8353};
8354
8355var wrap = function (tree, pattern) {
8356 // Wrap the pattern in a non-capturing group.
8357 return {
8358 'type': 'group',
8359 'behavior': 'ignore',
8360 'body': [tree],
8361 'raw': ("(?:" + pattern + ")")
8362 };
8363};
8364
8365var caseFold = function (codePoint) {
8366 return iuMappings.get(codePoint) || false;
8367};
8368
8369var processCharacterClass = function (characterClassItem, regenerateOptions) {
8370 var set = regenerate();
8371 for (var i = 0, list = characterClassItem.body; i < list.length; i += 1) {
8372 var item = list[i];
8373
8374 switch (item.type) {
8375 case 'value':
8376 set.add(item.codePoint);
8377 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
8378 var folded = caseFold(item.codePoint);
8379 if (folded) {
8380 set.add(folded);
8381 }
8382 }
8383 break;
8384 case 'characterClassRange':
8385 var min = item.min.codePoint;
8386 var max = item.max.codePoint;
8387 set.addRange(min, max);
8388 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
8389 set.iuAddRange(min, max);
8390 }
8391 break;
8392 case 'characterClassEscape':
8393 set.add(getCharacterClassEscapeSet(
8394 item.value,
8395 config.unicode,
8396 config.ignoreCase
8397 ));
8398 break;
8399 case 'unicodePropertyEscape':
8400 set.add(getUnicodePropertyEscapeSet(item.value, item.negative));
8401 break;
8402 // The `default` clause is only here as a safeguard; it should never be
8403 // reached. Code coverage tools should ignore it.
8404 /* istanbul ignore next */
8405 default:
8406 throw new Error(("Unknown term type: " + (item.type)));
8407 }
8408 }
8409 if (characterClassItem.negative) {
8410 set = (config.unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
8411 }
8412 update(characterClassItem, set.toString(regenerateOptions));
8413 return characterClassItem;
8414};
8415
8416var processTerm = function (item, regenerateOptions) {
8417 switch (item.type) {
8418 case 'dot':
8419 update(
8420 item,
8421 getDotSet(config.unicode, config.dotAll).toString(regenerateOptions)
8422 );
8423 break;
8424 case 'characterClass':
8425 item = processCharacterClass(item, regenerateOptions);
8426 break;
8427 case 'unicodePropertyEscape':
8428 update(
8429 item,
8430 getUnicodePropertyEscapeSet(item.value, item.negative)
8431 .toString(regenerateOptions)
8432 );
8433 break;
8434 case 'characterClassEscape':
8435 update(
8436 item,
8437 getCharacterClassEscapeSet(
8438 item.value,
8439 config.unicode,
8440 config.ignoreCase
8441 ).toString(regenerateOptions)
8442 );
8443 break;
8444 case 'alternative':
8445 case 'disjunction':
8446 case 'group':
8447 case 'quantifier':
8448 item.body = item.body.map(function (term) {
8449 return processTerm(term, regenerateOptions);
8450 });
8451 break;
8452 case 'value':
8453 var codePoint = item.codePoint;
8454 var set = regenerate(codePoint);
8455 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
8456 var folded = caseFold(codePoint);
8457 if (folded) {
8458 set.add(folded);
8459 }
8460 }
8461 update(item, set.toString(regenerateOptions));
8462 break;
8463 case 'anchor':
8464 case 'empty':
8465 case 'group':
8466 case 'reference':
8467 // Nothing to do here.
8468 break;
8469 // The `default` clause is only here as a safeguard; it should never be
8470 // reached. Code coverage tools should ignore it.
8471 /* istanbul ignore next */
8472 default:
8473 throw new Error(("Unknown term type: " + (item.type)));
8474 }
8475 return item;
8476};
8477
8478var config = {
8479 'ignoreCase': false,
8480 'unicode': false,
8481 'dotAll': false,
8482 'useUnicodeFlag': false
8483};
8484var rewritePattern = function (pattern, flags, options) {
8485 var regjsparserFeatures = {
8486 'unicodePropertyEscape': options && options.unicodePropertyEscape
8487 };
8488 config.ignoreCase = flags && flags.includes('i');
8489 config.unicode = flags && flags.includes('u');
8490 var supportDotAllFlag = options && options.dotAllFlag;
8491 config.dotAll = supportDotAllFlag && flags && flags.includes('s');
8492 config.useUnicodeFlag = options && options.useUnicodeFlag;
8493 var regenerateOptions = {
8494 'hasUnicodeFlag': config.useUnicodeFlag,
8495 'bmpOnly': !config.unicode
8496 };
8497 var tree = parse(pattern, flags, regjsparserFeatures);
8498 // Note: `processTerm` mutates `tree`.
8499 processTerm(tree, regenerateOptions);
8500 return generate(tree);
8501};
8502
8503module.exports = rewritePattern;
8504});
8505
8506var Literal = (function (Node$$1) {
8507 function Literal () {
8508 Node$$1.apply(this, arguments);
8509 }
8510
8511 if ( Node$$1 ) Literal.__proto__ = Node$$1;
8512 Literal.prototype = Object.create( Node$$1 && Node$$1.prototype );
8513 Literal.prototype.constructor = Literal;
8514
8515 Literal.prototype.initialise = function initialise () {
8516 if (typeof this.value === 'string') {
8517 this.program.indentExclusionElements.push(this);
8518 }
8519 };
8520
8521 Literal.prototype.transpile = function transpile (code, transforms) {
8522 if (transforms.numericLiteral) {
8523 var leading = this.raw.slice(0, 2);
8524 if (leading === '0b' || leading === '0o') {
8525 code.overwrite(this.start, this.end, String(this.value), {
8526 storeName: true,
8527 contentOnly: true
8528 });
8529 }
8530 }
8531
8532 if (this.regex) {
8533 var ref = this.regex;
8534 var pattern = ref.pattern;
8535 var flags = ref.flags;
8536
8537 if (transforms.stickyRegExp && /y/.test(flags))
8538 { throw new CompileError(
8539 'Regular expression sticky flag is not supported',
8540 this
8541 ); }
8542 if (transforms.unicodeRegExp && /u/.test(flags)) {
8543 code.overwrite(
8544 this.start,
8545 this.end,
8546 ("/" + (rewritePattern_1(pattern, flags)) + "/" + (flags.replace('u', ''))),
8547 {
8548 contentOnly: true
8549 }
8550 );
8551 }
8552 }
8553 };
8554
8555 return Literal;
8556}(Node));
8557
8558var MemberExpression = (function (Node$$1) {
8559 function MemberExpression () {
8560 Node$$1.apply(this, arguments);
8561 }
8562
8563 if ( Node$$1 ) MemberExpression.__proto__ = Node$$1;
8564 MemberExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
8565 MemberExpression.prototype.constructor = MemberExpression;
8566
8567 MemberExpression.prototype.transpile = function transpile (code, transforms) {
8568 if (transforms.reservedProperties && reserved[this.property.name]) {
8569 code.overwrite(this.object.end, this.property.start, "['");
8570 code.appendLeft(this.property.end, "']");
8571 }
8572
8573 Node$$1.prototype.transpile.call(this, code, transforms);
8574 };
8575
8576 return MemberExpression;
8577}(Node));
8578
8579var NewExpression = (function (Node$$1) {
8580 function NewExpression () {
8581 Node$$1.apply(this, arguments);
8582 }
8583
8584 if ( Node$$1 ) NewExpression.__proto__ = Node$$1;
8585 NewExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
8586 NewExpression.prototype.constructor = NewExpression;
8587
8588 NewExpression.prototype.initialise = function initialise (transforms) {
8589 var this$1 = this;
8590
8591 if (transforms.spreadRest && this.arguments.length) {
8592 var lexicalBoundary = this.findLexicalBoundary();
8593
8594 var i = this.arguments.length;
8595 while (i--) {
8596 var arg = this$1.arguments[i];
8597 if (arg.type === 'SpreadElement' && isArguments(arg.argument)) {
8598 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
8599 break;
8600 }
8601 }
8602 }
8603
8604 Node$$1.prototype.initialise.call(this, transforms);
8605 };
8606
8607 NewExpression.prototype.transpile = function transpile (code, transforms) {
8608 Node$$1.prototype.transpile.call(this, code, transforms);
8609
8610 if (transforms.spreadRest && this.arguments.length) {
8611 var firstArgument = this.arguments[0];
8612 var isNew = true;
8613 var hasSpreadElements = spread(
8614 code,
8615 this.arguments,
8616 firstArgument.start,
8617 this.argumentsArrayAlias,
8618 isNew
8619 );
8620
8621 if (hasSpreadElements) {
8622 code.prependRight(
8623 this.start + 'new'.length,
8624 ' (Function.prototype.bind.apply('
8625 );
8626 code.overwrite(
8627 this.callee.end,
8628 firstArgument.start,
8629 ', [ null ].concat( '
8630 );
8631 code.appendLeft(this.end, ' ))');
8632 }
8633 }
8634
8635 if (this.arguments.length) {
8636 removeTrailingComma(code, this.arguments[this.arguments.length - 1].end);
8637 }
8638 };
8639
8640 return NewExpression;
8641}(Node));
8642
8643var ObjectExpression = (function (Node$$1) {
8644 function ObjectExpression () {
8645 Node$$1.apply(this, arguments);
8646 }
8647
8648 if ( Node$$1 ) ObjectExpression.__proto__ = Node$$1;
8649 ObjectExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
8650 ObjectExpression.prototype.constructor = ObjectExpression;
8651
8652 ObjectExpression.prototype.transpile = function transpile (code, transforms) {
8653 var this$1 = this;
8654
8655 Node$$1.prototype.transpile.call(this, code, transforms);
8656
8657 var firstPropertyStart = this.start + 1;
8658 var regularPropertyCount = 0;
8659 var spreadPropertyCount = 0;
8660 var computedPropertyCount = 0;
8661 var firstSpreadProperty = null;
8662 var firstComputedProperty = null;
8663
8664 for (var i = 0; i < this.properties.length; ++i) {
8665 var prop = this$1.properties[i];
8666 if (prop.type === 'SpreadElement') {
8667 spreadPropertyCount += 1;
8668 if (firstSpreadProperty === null) { firstSpreadProperty = i; }
8669 } else if (prop.computed) {
8670 computedPropertyCount += 1;
8671 if (firstComputedProperty === null) { firstComputedProperty = i; }
8672 } else if (prop.type === 'Property') {
8673 regularPropertyCount += 1;
8674 }
8675 }
8676
8677 if (spreadPropertyCount) {
8678 if (!this.program.options.objectAssign) {
8679 throw new CompileError(
8680 "Object spread operator requires specified objectAssign option with 'Object.assign' or polyfill helper.",
8681 this
8682 );
8683 }
8684 // enclose run of non-spread properties in curlies
8685 var i$1 = this.properties.length;
8686 if (regularPropertyCount && !computedPropertyCount) {
8687 while (i$1--) {
8688 var prop$1 = this$1.properties[i$1];
8689
8690 if (prop$1.type === 'Property' && !prop$1.computed) {
8691 var lastProp = this$1.properties[i$1 - 1];
8692 var nextProp = this$1.properties[i$1 + 1];
8693
8694 if (
8695 !lastProp ||
8696 lastProp.type !== 'Property' ||
8697 lastProp.computed
8698 ) {
8699 code.prependRight(prop$1.start, '{');
8700 }
8701
8702 if (
8703 !nextProp ||
8704 nextProp.type !== 'Property' ||
8705 nextProp.computed
8706 ) {
8707 code.appendLeft(prop$1.end, '}');
8708 }
8709 }
8710 }
8711 }
8712
8713 // wrap the whole thing in Object.assign
8714 firstPropertyStart = this.properties[0].start;
8715 if (!computedPropertyCount) {
8716 code.overwrite(
8717 this.start,
8718 firstPropertyStart,
8719 ((this.program.options.objectAssign) + "({}, ")
8720 );
8721 code.overwrite(
8722 this.properties[this.properties.length - 1].end,
8723 this.end,
8724 ')'
8725 );
8726 } else if (this.properties[0].type === 'SpreadElement') {
8727 code.overwrite(
8728 this.start,
8729 firstPropertyStart,
8730 ((this.program.options.objectAssign) + "({}, ")
8731 );
8732 code.remove(this.end - 1, this.end);
8733 code.appendRight(this.end, ')');
8734 } else {
8735 code.prependLeft(this.start, ((this.program.options.objectAssign) + "("));
8736 code.appendRight(this.end, ')');
8737 }
8738 }
8739
8740 if (computedPropertyCount && transforms.computedProperty) {
8741 var i0 = this.getIndentation();
8742
8743 var isSimpleAssignment;
8744 var name;
8745
8746 if (
8747 this.parent.type === 'VariableDeclarator' &&
8748 this.parent.parent.declarations.length === 1 &&
8749 this.parent.id.type === 'Identifier'
8750 ) {
8751 isSimpleAssignment = true;
8752 name = this.parent.id.alias || this.parent.id.name; // TODO is this right?
8753 } else if (
8754 this.parent.type === 'AssignmentExpression' &&
8755 this.parent.parent.type === 'ExpressionStatement' &&
8756 this.parent.left.type === 'Identifier'
8757 ) {
8758 isSimpleAssignment = true;
8759 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
8760 } else if (
8761 this.parent.type === 'AssignmentPattern' &&
8762 this.parent.left.type === 'Identifier'
8763 ) {
8764 isSimpleAssignment = true;
8765 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
8766 }
8767
8768 if (spreadPropertyCount) { isSimpleAssignment = false; }
8769
8770 // handle block scoping
8771 name = this.findScope(false).resolveName(name);
8772
8773 var start = firstPropertyStart;
8774 var end = this.end;
8775
8776 if (isSimpleAssignment) {
8777 // ???
8778 } else {
8779 if (
8780 firstSpreadProperty === null ||
8781 firstComputedProperty < firstSpreadProperty
8782 ) {
8783 name = this.findScope(true).createDeclaration('obj');
8784
8785 code.prependRight(this.start, ("( " + name + " = "));
8786 } else { name = null; } // We don't actually need this variable
8787 }
8788
8789 var len = this.properties.length;
8790 var lastComputedProp;
8791 var sawNonComputedProperty = false;
8792 var isFirst = true;
8793
8794 for (var i$2 = 0; i$2 < len; i$2 += 1) {
8795 var prop$2 = this$1.properties[i$2];
8796 var moveStart = i$2 > 0 ? this$1.properties[i$2 - 1].end : start;
8797
8798 if (
8799 prop$2.type === 'Property' &&
8800 (prop$2.computed || (lastComputedProp && !spreadPropertyCount))
8801 ) {
8802 if (i$2 === 0) { moveStart = this$1.start + 1; } // Trim leading whitespace
8803 lastComputedProp = prop$2;
8804
8805 if (!name) {
8806 name = this$1.findScope(true).createDeclaration('obj');
8807
8808 var propId = name + (prop$2.computed ? '' : '.');
8809 code.appendRight(prop$2.start, ("( " + name + " = {}, " + propId));
8810 } else {
8811 var propId$1 =
8812 (isSimpleAssignment ? (";\n" + i0 + name) : (", " + name)) +
8813 (prop$2.key.type === 'Literal' || prop$2.computed ? '' : '.');
8814
8815 if (moveStart < prop$2.start) {
8816 code.overwrite(moveStart, prop$2.start, propId$1);
8817 } else {
8818 code.prependRight(prop$2.start, propId$1);
8819 }
8820 }
8821
8822 var c = prop$2.key.end;
8823 if (prop$2.computed) {
8824 while (code.original[c] !== ']') { c += 1; }
8825 c += 1;
8826 }
8827 if (prop$2.key.type === 'Literal' && !prop$2.computed) {
8828 code.overwrite(
8829 prop$2.start,
8830 prop$2.key.end + 1,
8831 '[' + code.slice(prop$2.start, prop$2.key.end) + '] = '
8832 );
8833 } else if (prop$2.shorthand || (prop$2.method && !prop$2.computed && transforms.conciseMethodProperty)) {
8834 // Replace : with = if Property::transpile inserted the :
8835 code.overwrite(
8836 prop$2.key.start,
8837 prop$2.key.end,
8838 code.slice(prop$2.key.start, prop$2.key.end).replace(/:/, ' =')
8839 );
8840 } else {
8841 if (prop$2.value.start > c) { code.remove(c, prop$2.value.start); }
8842 code.prependLeft(c, ' = ');
8843 }
8844
8845 // This duplicates behavior from Property::transpile which is disabled
8846 // for computed properties or if conciseMethodProperty is false
8847 if (prop$2.method && (prop$2.computed || !transforms.conciseMethodProperty)) {
8848 if (prop$2.value.generator) { code.remove(prop$2.start, prop$2.key.start); }
8849 code.prependRight(prop$2.value.start, ("function" + (prop$2.value.generator ? '*' : '') + " "));
8850 }
8851 } else if (prop$2.type === 'SpreadElement') {
8852 if (name && i$2 > 0) {
8853 if (!lastComputedProp) {
8854 lastComputedProp = this$1.properties[i$2 - 1];
8855 }
8856 code.appendLeft(lastComputedProp.end, (", " + name + " )"));
8857
8858 lastComputedProp = null;
8859 name = null;
8860 }
8861 } else {
8862 if (!isFirst && spreadPropertyCount) {
8863 // We are in an Object.assign context, so we need to wrap regular properties
8864 code.prependRight(prop$2.start, '{');
8865 code.appendLeft(prop$2.end, '}');
8866 }
8867 sawNonComputedProperty = true;
8868 }
8869 if (isFirst && (prop$2.type === 'SpreadElement' || prop$2.computed)) {
8870 var beginEnd = sawNonComputedProperty
8871 ? this$1.properties[this$1.properties.length - 1].end
8872 : this$1.end - 1;
8873 // Trim trailing comma because it can easily become a leading comma which is illegal
8874 if (code.original[beginEnd] == ',') { ++beginEnd; }
8875 var closing = code.slice(beginEnd, end);
8876 code.prependLeft(moveStart, closing);
8877 code.remove(beginEnd, end);
8878 isFirst = false;
8879 }
8880
8881 // Clean up some extranous whitespace
8882 var c$1 = prop$2.end;
8883 if (i$2 < len - 1 && !sawNonComputedProperty) {
8884 while (code.original[c$1] !== ',') { c$1 += 1; }
8885 } else if (i$2 == len - 1) { c$1 = this$1.end; }
8886 code.remove(prop$2.end, c$1);
8887 }
8888
8889 // special case
8890 if (computedPropertyCount === len) {
8891 code.remove(this.properties[len - 1].end, this.end - 1);
8892 }
8893
8894 if (!isSimpleAssignment && name) {
8895 code.appendLeft(lastComputedProp.end, (", " + name + " )"));
8896 }
8897 }
8898 };
8899
8900 return ObjectExpression;
8901}(Node));
8902
8903var Property = (function (Node$$1) {
8904 function Property () {
8905 Node$$1.apply(this, arguments);
8906 }
8907
8908 if ( Node$$1 ) Property.__proto__ = Node$$1;
8909 Property.prototype = Object.create( Node$$1 && Node$$1.prototype );
8910 Property.prototype.constructor = Property;
8911
8912 Property.prototype.transpile = function transpile (code, transforms) {
8913 Node$$1.prototype.transpile.call(this, code, transforms);
8914
8915 if (
8916 transforms.conciseMethodProperty &&
8917 !this.computed &&
8918 this.parent.type !== 'ObjectPattern'
8919 ) {
8920 if (this.shorthand) {
8921 code.prependRight(this.start, ((this.key.name) + ": "));
8922 } else if (this.method) {
8923 var name = '';
8924 if (this.program.options.namedFunctionExpressions !== false) {
8925 if (
8926 this.key.type === 'Literal' &&
8927 typeof this.key.value === 'number'
8928 ) {
8929 name = '';
8930 } else if (this.key.type === 'Identifier') {
8931 if (
8932 reserved[this.key.name] ||
8933 !/^[a-z_$][a-z0-9_$]*$/i.test(this.key.name) ||
8934 this.value.body.scope.references[this.key.name]
8935 ) {
8936 name = this.findScope(true).createIdentifier(this.key.name);
8937 } else {
8938 name = this.key.name;
8939 }
8940 } else {
8941 name = this.findScope(true).createIdentifier(this.key.value);
8942 }
8943 name = ' ' + name;
8944 }
8945
8946 if (this.value.generator) { code.remove(this.start, this.key.start); }
8947 code.appendLeft(
8948 this.key.end,
8949 (": function" + (this.value.generator ? '*' : '') + name)
8950 );
8951 }
8952 }
8953
8954 if (transforms.reservedProperties && reserved[this.key.name]) {
8955 code.prependRight(this.key.start, "'");
8956 code.appendLeft(this.key.end, "'");
8957 }
8958 };
8959
8960 return Property;
8961}(Node));
8962
8963var ReturnStatement = (function (Node$$1) {
8964 function ReturnStatement () {
8965 Node$$1.apply(this, arguments);
8966 }
8967
8968 if ( Node$$1 ) ReturnStatement.__proto__ = Node$$1;
8969 ReturnStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
8970 ReturnStatement.prototype.constructor = ReturnStatement;
8971
8972 ReturnStatement.prototype.initialise = function initialise (transforms) {
8973 this.loop = this.findNearest(loopStatement);
8974 this.nearestFunction = this.findNearest(/Function/);
8975
8976 if (
8977 this.loop &&
8978 (!this.nearestFunction || this.loop.depth > this.nearestFunction.depth)
8979 ) {
8980 this.loop.canReturn = true;
8981 this.shouldWrap = true;
8982 }
8983
8984 if (this.argument) { this.argument.initialise(transforms); }
8985 };
8986
8987 ReturnStatement.prototype.transpile = function transpile (code, transforms) {
8988 var shouldWrap =
8989 this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;
8990
8991 if (this.argument) {
8992 if (shouldWrap) { code.prependRight(this.argument.start, "{ v: "); }
8993 this.argument.transpile(code, transforms);
8994 if (shouldWrap) { code.appendLeft(this.argument.end, " }"); }
8995 } else if (shouldWrap) {
8996 code.appendLeft(this.start + 6, ' {}');
8997 }
8998 };
8999
9000 return ReturnStatement;
9001}(Node));
9002
9003var SpreadElement = (function (Node$$1) {
9004 function SpreadElement () {
9005 Node$$1.apply(this, arguments);
9006 }
9007
9008 if ( Node$$1 ) SpreadElement.__proto__ = Node$$1;
9009 SpreadElement.prototype = Object.create( Node$$1 && Node$$1.prototype );
9010 SpreadElement.prototype.constructor = SpreadElement;
9011
9012 SpreadElement.prototype.transpile = function transpile (code, transforms) {
9013 if (this.parent.type == 'ObjectExpression') {
9014 code.remove(this.start, this.argument.start);
9015 code.remove(this.argument.end, this.end);
9016 }
9017
9018 Node$$1.prototype.transpile.call(this, code, transforms);
9019 };
9020
9021 return SpreadElement;
9022}(Node));
9023
9024var Super = (function (Node$$1) {
9025 function Super () {
9026 Node$$1.apply(this, arguments);
9027 }
9028
9029 if ( Node$$1 ) Super.__proto__ = Node$$1;
9030 Super.prototype = Object.create( Node$$1 && Node$$1.prototype );
9031 Super.prototype.constructor = Super;
9032
9033 Super.prototype.initialise = function initialise (transforms) {
9034 if (transforms.classes) {
9035 this.method = this.findNearest('MethodDefinition');
9036 if (!this.method)
9037 { throw new CompileError('use of super outside class method', this); }
9038
9039 var parentClass = this.findNearest('ClassBody').parent;
9040 this.superClassName =
9041 parentClass.superClass && (parentClass.superClass.name || 'superclass');
9042
9043 if (!this.superClassName)
9044 { throw new CompileError('super used in base class', this); }
9045
9046 this.isCalled =
9047 this.parent.type === 'CallExpression' && this === this.parent.callee;
9048
9049 if (this.method.kind !== 'constructor' && this.isCalled) {
9050 throw new CompileError(
9051 'super() not allowed outside class constructor',
9052 this
9053 );
9054 }
9055
9056 this.isMember = this.parent.type === 'MemberExpression';
9057
9058 if (!this.isCalled && !this.isMember) {
9059 throw new CompileError(
9060 'Unexpected use of `super` (expected `super(...)` or `super.*`)',
9061 this
9062 );
9063 }
9064 }
9065
9066 if (transforms.arrow) {
9067 var lexicalBoundary = this.findLexicalBoundary();
9068 var arrowFunction = this.findNearest('ArrowFunctionExpression');
9069 var loop = this.findNearest(loopStatement);
9070
9071 if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) {
9072 this.thisAlias = lexicalBoundary.getThisAlias();
9073 }
9074
9075 if (
9076 loop &&
9077 loop.body.contains(this) &&
9078 loop.depth > lexicalBoundary.depth
9079 ) {
9080 this.thisAlias = lexicalBoundary.getThisAlias();
9081 }
9082 }
9083 };
9084
9085 Super.prototype.transpile = function transpile (code, transforms) {
9086 if (transforms.classes) {
9087 var expression =
9088 this.isCalled || this.method.static
9089 ? this.superClassName
9090 : ((this.superClassName) + ".prototype");
9091
9092 code.overwrite(this.start, this.end, expression, {
9093 storeName: true,
9094 contentOnly: true
9095 });
9096
9097 var callExpression = this.isCalled ? this.parent : this.parent.parent;
9098
9099 if (callExpression && callExpression.type === 'CallExpression') {
9100 if (!this.noCall) {
9101 // special case – `super( ...args )`
9102 code.appendLeft(callExpression.callee.end, '.call');
9103 }
9104
9105 var thisAlias = this.thisAlias || 'this';
9106
9107 if (callExpression.arguments.length) {
9108 code.appendLeft(callExpression.arguments[0].start, (thisAlias + ", "));
9109 } else {
9110 code.appendLeft(callExpression.end - 1, ("" + thisAlias));
9111 }
9112 }
9113 }
9114 };
9115
9116 return Super;
9117}(Node));
9118
9119var TaggedTemplateExpression = (function (Node$$1) {
9120 function TaggedTemplateExpression () {
9121 Node$$1.apply(this, arguments);
9122 }
9123
9124 if ( Node$$1 ) TaggedTemplateExpression.__proto__ = Node$$1;
9125 TaggedTemplateExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
9126 TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
9127
9128 TaggedTemplateExpression.prototype.initialise = function initialise (transforms) {
9129 if (
9130 transforms.templateString &&
9131 !transforms.dangerousTaggedTemplateString
9132 ) {
9133 throw new CompileError(
9134 "Tagged template strings are not supported. Use `transforms: { templateString: false }` to skip transformation and disable this error, or `transforms: { dangerousTaggedTemplateString: true }` if you know what you're doing",
9135 this
9136 );
9137 }
9138
9139 Node$$1.prototype.initialise.call(this, transforms);
9140 };
9141
9142 TaggedTemplateExpression.prototype.transpile = function transpile (code, transforms) {
9143 if (transforms.templateString && transforms.dangerousTaggedTemplateString) {
9144 var ordered = this.quasi.expressions
9145 .concat(this.quasi.quasis)
9146 .sort(function (a, b) { return a.start - b.start; });
9147
9148 var program = this.program;
9149 var rootScope = program.body.scope;
9150
9151 // insert strings at start
9152 var templateStrings = this.quasi.quasis.map(function (quasi) { return JSON.stringify(quasi.value.cooked); }
9153 ).join(', ');
9154
9155 var templateObject = this.program.templateLiteralQuasis[templateStrings];
9156 if (!templateObject) {
9157 templateObject = rootScope.createIdentifier('templateObject');
9158 code.prependRight(this.program.prependAt, ("var " + templateObject + " = Object.freeze([" + templateStrings + "]);\n"));
9159
9160 this.program.templateLiteralQuasis[templateStrings] = templateObject;
9161 }
9162
9163 code.overwrite(
9164 this.tag.end,
9165 ordered[0].start,
9166 ("(" + templateObject)
9167 );
9168
9169 var lastIndex = ordered[0].start;
9170 ordered.forEach(function (node) {
9171 if (node.type === 'TemplateElement') {
9172 code.remove(lastIndex, node.end);
9173 } else {
9174 code.overwrite(lastIndex, node.start, ', ');
9175 }
9176
9177 lastIndex = node.end;
9178 });
9179
9180 code.overwrite(lastIndex, this.end, ')');
9181 }
9182
9183 Node$$1.prototype.transpile.call(this, code, transforms);
9184 };
9185
9186 return TaggedTemplateExpression;
9187}(Node));
9188
9189var TemplateElement = (function (Node$$1) {
9190 function TemplateElement () {
9191 Node$$1.apply(this, arguments);
9192 }
9193
9194 if ( Node$$1 ) TemplateElement.__proto__ = Node$$1;
9195 TemplateElement.prototype = Object.create( Node$$1 && Node$$1.prototype );
9196 TemplateElement.prototype.constructor = TemplateElement;
9197
9198 TemplateElement.prototype.initialise = function initialise () {
9199 this.program.indentExclusionElements.push(this);
9200 };
9201
9202 return TemplateElement;
9203}(Node));
9204
9205var TemplateLiteral = (function (Node$$1) {
9206 function TemplateLiteral () {
9207 Node$$1.apply(this, arguments);
9208 }
9209
9210 if ( Node$$1 ) TemplateLiteral.__proto__ = Node$$1;
9211 TemplateLiteral.prototype = Object.create( Node$$1 && Node$$1.prototype );
9212 TemplateLiteral.prototype.constructor = TemplateLiteral;
9213
9214 TemplateLiteral.prototype.transpile = function transpile (code, transforms) {
9215 Node$$1.prototype.transpile.call(this, code, transforms);
9216
9217 if (
9218 transforms.templateString &&
9219 this.parent.type !== 'TaggedTemplateExpression'
9220 ) {
9221 var ordered = this.expressions
9222 .concat(this.quasis)
9223 .sort(function (a, b) { return a.start - b.start || a.end - b.end; })
9224 .filter(function (node, i) {
9225 // include all expressions
9226 if (node.type !== 'TemplateElement') { return true; }
9227
9228 // include all non-empty strings
9229 if (node.value.raw) { return true; }
9230
9231 // exclude all empty strings not at the head
9232 return !i;
9233 });
9234
9235 // special case – we may be able to skip the first element,
9236 // if it's the empty string, but only if the second and
9237 // third elements aren't both expressions (since they maybe
9238 // be numeric, and `1 + 2 + '3' === '33'`)
9239 if (ordered.length >= 3) {
9240 var first = ordered[0];
9241 var third = ordered[2];
9242 if (
9243 first.type === 'TemplateElement' &&
9244 first.value.raw === '' &&
9245 third.type === 'TemplateElement'
9246 ) {
9247 ordered.shift();
9248 }
9249 }
9250
9251 var parenthesise =
9252 (this.quasis.length !== 1 || this.expressions.length !== 0) &&
9253 this.parent.type !== 'TemplateLiteral' &&
9254 this.parent.type !== 'AssignmentExpression' &&
9255 this.parent.type !== 'AssignmentPattern' &&
9256 this.parent.type !== 'VariableDeclarator' &&
9257 (this.parent.type !== 'BinaryExpression' ||
9258 this.parent.operator !== '+');
9259
9260 if (parenthesise) { code.appendRight(this.start, '('); }
9261
9262 var lastIndex = this.start;
9263
9264 ordered.forEach(function (node, i) {
9265 var prefix = i === 0 ? (parenthesise ? '(' : '') : ' + ';
9266
9267 if (node.type === 'TemplateElement') {
9268 code.overwrite(
9269 lastIndex,
9270 node.end,
9271 prefix + JSON.stringify(node.value.cooked)
9272 );
9273 } else {
9274 var parenthesise$1 = node.type !== 'Identifier'; // TODO other cases where it's safe
9275
9276 if (parenthesise$1) { prefix += '('; }
9277
9278 code.remove(lastIndex, node.start);
9279
9280 if (prefix) { code.prependRight(node.start, prefix); }
9281 if (parenthesise$1) { code.appendLeft(node.end, ')'); }
9282 }
9283
9284 lastIndex = node.end;
9285 });
9286
9287 if (parenthesise) { code.appendLeft(lastIndex, ')'); }
9288 code.overwrite(lastIndex, this.end, "", { contentOnly: true } );
9289 }
9290 };
9291
9292 return TemplateLiteral;
9293}(Node));
9294
9295var ThisExpression = (function (Node$$1) {
9296 function ThisExpression () {
9297 Node$$1.apply(this, arguments);
9298 }
9299
9300 if ( Node$$1 ) ThisExpression.__proto__ = Node$$1;
9301 ThisExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
9302 ThisExpression.prototype.constructor = ThisExpression;
9303
9304 ThisExpression.prototype.initialise = function initialise (transforms) {
9305 if (transforms.arrow) {
9306 var lexicalBoundary = this.findLexicalBoundary();
9307 var arrowFunction = this.findNearest('ArrowFunctionExpression');
9308 var loop = this.findNearest(loopStatement);
9309
9310 if (
9311 (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) ||
9312 (loop &&
9313 loop.body.contains(this) &&
9314 loop.depth > lexicalBoundary.depth) ||
9315 (loop && loop.right && loop.right.contains(this))
9316 ) {
9317 this.alias = lexicalBoundary.getThisAlias();
9318 }
9319 }
9320 };
9321
9322 ThisExpression.prototype.transpile = function transpile (code) {
9323 if (this.alias) {
9324 code.overwrite(this.start, this.end, this.alias, {
9325 storeName: true,
9326 contentOnly: true
9327 });
9328 }
9329 };
9330
9331 return ThisExpression;
9332}(Node));
9333
9334var UpdateExpression = (function (Node$$1) {
9335 function UpdateExpression () {
9336 Node$$1.apply(this, arguments);
9337 }
9338
9339 if ( Node$$1 ) UpdateExpression.__proto__ = Node$$1;
9340 UpdateExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
9341 UpdateExpression.prototype.constructor = UpdateExpression;
9342
9343 UpdateExpression.prototype.initialise = function initialise (transforms) {
9344 if (this.argument.type === 'Identifier') {
9345 var declaration = this.findScope(false).findDeclaration(
9346 this.argument.name
9347 );
9348 // special case – https://gitlab.com/Rich-Harris/buble/issues/150
9349 var statement = declaration && declaration.node.ancestor(3);
9350 if (
9351 statement &&
9352 statement.type === 'ForStatement' &&
9353 statement.body.contains(this)
9354 ) {
9355 statement.reassigned[this.argument.name] = true;
9356 }
9357 }
9358
9359 Node$$1.prototype.initialise.call(this, transforms);
9360 };
9361
9362 UpdateExpression.prototype.transpile = function transpile (code, transforms) {
9363 if (this.argument.type === 'Identifier') {
9364 // Do this check after everything has been initialized to find
9365 // shadowing declarations after this expression
9366 checkConst(this.argument, this.findScope(false));
9367 }
9368 Node$$1.prototype.transpile.call(this, code, transforms);
9369 };
9370
9371 return UpdateExpression;
9372}(Node));
9373
9374var VariableDeclaration = (function (Node$$1) {
9375 function VariableDeclaration () {
9376 Node$$1.apply(this, arguments);
9377 }
9378
9379 if ( Node$$1 ) VariableDeclaration.__proto__ = Node$$1;
9380 VariableDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
9381 VariableDeclaration.prototype.constructor = VariableDeclaration;
9382
9383 VariableDeclaration.prototype.initialise = function initialise (transforms) {
9384 this.scope = this.findScope(this.kind === 'var');
9385 this.declarations.forEach(function (declarator) { return declarator.initialise(transforms); });
9386 };
9387
9388 VariableDeclaration.prototype.transpile = function transpile (code, transforms) {
9389 var this$1 = this;
9390
9391 var i0 = this.getIndentation();
9392 var kind = this.kind;
9393
9394 if (transforms.letConst && kind !== 'var') {
9395 kind = 'var';
9396 code.overwrite(this.start, this.start + this.kind.length, kind, {
9397 storeName: true
9398 });
9399 }
9400
9401 if (transforms.destructuring && this.parent.type !== 'ForOfStatement' && this.parent.type !== 'ForInStatement') {
9402 var c = this.start;
9403 var lastDeclaratorIsPattern;
9404
9405 this.declarations.forEach(function (declarator, i) {
9406 declarator.transpile(code, transforms);
9407
9408 if (declarator.id.type === 'Identifier') {
9409 if (i > 0 && this$1.declarations[i - 1].id.type !== 'Identifier') {
9410 code.overwrite(c, declarator.id.start, "var ");
9411 }
9412 } else {
9413 var inline = loopStatement.test(this$1.parent.type);
9414
9415 if (i === 0) {
9416 code.remove(c, declarator.id.start);
9417 } else {
9418 code.overwrite(c, declarator.id.start, (";\n" + i0));
9419 }
9420
9421 var simple =
9422 declarator.init.type === 'Identifier' && !declarator.init.rewritten;
9423
9424 var name = simple
9425 ? (declarator.init.alias || declarator.init.name)
9426 : declarator.findScope(true).createIdentifier('ref');
9427
9428 c = declarator.start;
9429
9430 var statementGenerators = [];
9431
9432 if (simple) {
9433 code.remove(declarator.id.end, declarator.end);
9434 } else {
9435 statementGenerators.push(function (start, prefix, suffix) {
9436 code.prependRight(declarator.id.end, ("var " + name));
9437 code.appendLeft(declarator.init.end, ("" + suffix));
9438 code.move(declarator.id.end, declarator.end, start);
9439 });
9440 }
9441
9442 var scope = declarator.findScope(false);
9443 destructure(
9444 code,
9445 function (id) { return scope.createIdentifier(id); },
9446 function (ref) {
9447 var name = ref.name;
9448
9449 return scope.resolveName(name);
9450 },
9451 declarator.id,
9452 name,
9453 inline,
9454 statementGenerators
9455 );
9456
9457 var prefix = inline ? 'var ' : '';
9458 var suffix = inline ? ", " : (";\n" + i0);
9459 statementGenerators.forEach(function (fn, j) {
9460 if (
9461 i === this$1.declarations.length - 1 &&
9462 j === statementGenerators.length - 1
9463 ) {
9464 suffix = inline ? '' : ';';
9465 }
9466
9467 fn(declarator.start, j === 0 ? prefix : '', suffix);
9468 });
9469 }
9470
9471 c = declarator.end;
9472 lastDeclaratorIsPattern = declarator.id.type !== 'Identifier';
9473 });
9474
9475 if (lastDeclaratorIsPattern && this.end > c) {
9476 code.overwrite(c, this.end, '', { contentOnly: true });
9477 }
9478 } else {
9479 this.declarations.forEach(function (declarator) {
9480 declarator.transpile(code, transforms);
9481 });
9482 }
9483 };
9484
9485 return VariableDeclaration;
9486}(Node));
9487
9488var VariableDeclarator = (function (Node$$1) {
9489 function VariableDeclarator () {
9490 Node$$1.apply(this, arguments);
9491 }
9492
9493 if ( Node$$1 ) VariableDeclarator.__proto__ = Node$$1;
9494 VariableDeclarator.prototype = Object.create( Node$$1 && Node$$1.prototype );
9495 VariableDeclarator.prototype.constructor = VariableDeclarator;
9496
9497 VariableDeclarator.prototype.initialise = function initialise (transforms) {
9498 var kind = this.parent.kind;
9499 if (kind === 'let' && this.parent.parent.type === 'ForStatement') {
9500 kind = 'for.let'; // special case...
9501 }
9502
9503 this.parent.scope.addDeclaration(this.id, kind);
9504 Node$$1.prototype.initialise.call(this, transforms);
9505 };
9506
9507 VariableDeclarator.prototype.transpile = function transpile (code, transforms) {
9508 if (!this.init && transforms.letConst && this.parent.kind !== 'var') {
9509 var inLoop = this.findNearest(
9510 /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/
9511 );
9512 if (
9513 inLoop &&
9514 !/Function/.test(inLoop.type) &&
9515 !this.isLeftDeclaratorOfLoop()
9516 ) {
9517 code.appendLeft(this.id.end, ' = (void 0)');
9518 }
9519 }
9520
9521 if (this.id) { this.id.transpile(code, transforms); }
9522 if (this.init) { this.init.transpile(code, transforms); }
9523 };
9524
9525 VariableDeclarator.prototype.isLeftDeclaratorOfLoop = function isLeftDeclaratorOfLoop () {
9526 return (
9527 this.parent &&
9528 this.parent.type === 'VariableDeclaration' &&
9529 this.parent.parent &&
9530 (this.parent.parent.type === 'ForInStatement' ||
9531 this.parent.parent.type === 'ForOfStatement') &&
9532 this.parent.parent.left &&
9533 this.parent.parent.left.declarations[0] === this
9534 );
9535 };
9536
9537 return VariableDeclarator;
9538}(Node));
9539
9540var types = {
9541 ArrayExpression: ArrayExpression,
9542 ArrowFunctionExpression: ArrowFunctionExpression,
9543 AssignmentExpression: AssignmentExpression,
9544 BinaryExpression: BinaryExpression,
9545 BreakStatement: BreakStatement,
9546 CallExpression: CallExpression,
9547 ClassBody: ClassBody,
9548 ClassDeclaration: ClassDeclaration,
9549 ClassExpression: ClassExpression,
9550 ContinueStatement: ContinueStatement,
9551 DoWhileStatement: LoopStatement,
9552 ExportNamedDeclaration: ExportNamedDeclaration,
9553 ExportDefaultDeclaration: ExportDefaultDeclaration,
9554 ForStatement: ForStatement,
9555 ForInStatement: ForInStatement,
9556 ForOfStatement: ForOfStatement,
9557 FunctionDeclaration: FunctionDeclaration,
9558 FunctionExpression: FunctionExpression,
9559 Identifier: Identifier,
9560 IfStatement: IfStatement,
9561 ImportDeclaration: ImportDeclaration,
9562 ImportDefaultSpecifier: ImportDefaultSpecifier,
9563 ImportSpecifier: ImportSpecifier,
9564 JSXAttribute: JSXAttribute,
9565 JSXClosingElement: JSXClosingElement,
9566 JSXClosingFragment: JSXClosingFragment,
9567 JSXElement: JSXElement,
9568 JSXExpressionContainer: JSXExpressionContainer,
9569 JSXFragment: JSXFragment,
9570 JSXOpeningElement: JSXOpeningElement,
9571 JSXOpeningFragment: JSXOpeningFragment,
9572 JSXSpreadAttribute: JSXSpreadAttribute,
9573 Literal: Literal,
9574 MemberExpression: MemberExpression,
9575 NewExpression: NewExpression,
9576 ObjectExpression: ObjectExpression,
9577 Property: Property,
9578 ReturnStatement: ReturnStatement,
9579 SpreadElement: SpreadElement,
9580 Super: Super,
9581 TaggedTemplateExpression: TaggedTemplateExpression,
9582 TemplateElement: TemplateElement,
9583 TemplateLiteral: TemplateLiteral,
9584 ThisExpression: ThisExpression,
9585 UpdateExpression: UpdateExpression,
9586 VariableDeclaration: VariableDeclaration,
9587 VariableDeclarator: VariableDeclarator,
9588 WhileStatement: LoopStatement
9589};
9590
9591var keys = {
9592 Program: ['body'],
9593 Literal: []
9594};
9595
9596var statementsWithBlocks = {
9597 IfStatement: 'consequent',
9598 ForStatement: 'body',
9599 ForInStatement: 'body',
9600 ForOfStatement: 'body',
9601 WhileStatement: 'body',
9602 DoWhileStatement: 'body',
9603 ArrowFunctionExpression: 'body'
9604};
9605
9606function wrap(raw, parent) {
9607 if (!raw) { return; }
9608
9609 if ('length' in raw) {
9610 var i = raw.length;
9611 while (i--) { wrap(raw[i], parent); }
9612 return;
9613 }
9614
9615 // with e.g. shorthand properties, key and value are
9616 // the same node. We don't want to wrap an object twice
9617 if (raw.__wrapped) { return; }
9618 raw.__wrapped = true;
9619
9620 if (!keys[raw.type]) {
9621 keys[raw.type] = Object.keys(raw).filter(
9622 function (key) { return typeof raw[key] === 'object'; }
9623 );
9624 }
9625
9626 // special case – body-less if/for/while statements. TODO others?
9627 var bodyType = statementsWithBlocks[raw.type];
9628 if (bodyType && raw[bodyType].type !== 'BlockStatement') {
9629 var expression = raw[bodyType];
9630
9631 // create a synthetic block statement, otherwise all hell
9632 // breaks loose when it comes to block scoping
9633 raw[bodyType] = {
9634 start: expression.start,
9635 end: expression.end,
9636 type: 'BlockStatement',
9637 body: [expression],
9638 synthetic: true
9639 };
9640 }
9641
9642 raw.parent = parent;
9643 raw.program = parent.program || parent;
9644 raw.depth = parent.depth + 1;
9645 raw.keys = keys[raw.type];
9646 raw.indentation = undefined;
9647
9648 for (var i$1 = 0, list = keys[raw.type]; i$1 < list.length; i$1 += 1) {
9649 var key = list[i$1];
9650
9651 wrap(raw[key], raw);
9652 }
9653
9654 raw.program.magicString.addSourcemapLocation(raw.start);
9655 raw.program.magicString.addSourcemapLocation(raw.end);
9656
9657 var type =
9658 (raw.type === 'BlockStatement' ? BlockStatement : types[raw.type]) || Node;
9659 raw.__proto__ = type.prototype;
9660}
9661
9662function Program(source, ast, transforms, options) {
9663 var this$1 = this;
9664
9665 this.type = 'Root';
9666
9667 // options
9668 this.jsx = options.jsx || 'React.createElement';
9669 this.options = options;
9670
9671 this.source = source;
9672 this.magicString = new MagicString(source);
9673
9674 this.ast = ast;
9675 this.depth = 0;
9676
9677 wrap((this.body = ast), this);
9678 this.body.__proto__ = BlockStatement.prototype;
9679
9680 this.templateLiteralQuasis = Object.create(null);
9681 for (var i = 0; i < this.body.body.length; ++i) {
9682 if (!this$1.body.body[i].directive) {
9683 this$1.prependAt = this$1.body.body[i].start;
9684 break;
9685 }
9686 }
9687 this.objectWithoutPropertiesHelper = null;
9688
9689 this.indentExclusionElements = [];
9690 this.body.initialise(transforms);
9691
9692 this.indentExclusions = Object.create(null);
9693 for (var i$2 = 0, list = this$1.indentExclusionElements; i$2 < list.length; i$2 += 1) {
9694 var node = list[i$2];
9695
9696 for (var i$1 = node.start; i$1 < node.end; i$1 += 1) {
9697 this$1.indentExclusions[i$1] = true;
9698 }
9699 }
9700
9701 this.body.transpile(this.magicString, transforms);
9702}
9703
9704Program.prototype = {
9705 export: function export$1(options) {
9706 if ( options === void 0 ) options = {};
9707
9708 return {
9709 code: this.magicString.toString(),
9710 map: this.magicString.generateMap({
9711 file: options.file,
9712 source: options.source,
9713 includeContent: options.includeContent !== false
9714 })
9715 };
9716 },
9717
9718 findNearest: function findNearest() {
9719 return null;
9720 },
9721
9722 findScope: function findScope() {
9723 return null;
9724 },
9725
9726 getObjectWithoutPropertiesHelper: function getObjectWithoutPropertiesHelper(code) {
9727 if (!this.objectWithoutPropertiesHelper) {
9728 this.objectWithoutPropertiesHelper = this.body.scope.createIdentifier('objectWithoutProperties');
9729 code.prependLeft(this.prependAt, "function " + (this.objectWithoutPropertiesHelper) + " (obj, exclude) { " +
9730 "var target = {}; for (var k in obj) " +
9731 "if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) " +
9732 "target[k] = obj[k]; return target; }\n"
9733 );
9734 }
9735 return this.objectWithoutPropertiesHelper;
9736 }
9737};
9738
9739var matrix = {
9740 chrome: {
9741 48: 305357,
9742 49: 326143,
9743 50: 391679,
9744 51: 391679,
9745 52: 522751,
9746 53: 522751,
9747 54: 522751,
9748 55: 522751,
9749 56: 522751,
9750 57: 522751,
9751 58: 1047039,
9752 59: 1047039,
9753 60: 1047039,
9754 61: 1047039,
9755 62: 1047039,
9756 63: 1047039
9757 },
9758 firefox: {
9759 43: 325853,
9760 44: 326109,
9761 45: 326111,
9762 46: 391647,
9763 47: 391679,
9764 48: 391679,
9765 49: 387583,
9766 50: 387583,
9767 51: 387583,
9768 52: 1047039,
9769 53: 1047039,
9770 54: 1047039,
9771 55: 1047039,
9772 56: 1047039,
9773 57: 1047039,
9774 58: 1047039
9775 },
9776 safari: {
9777 8: 262148,
9778 9: 301166,
9779 10: 915967,
9780 '10.1': 1047039,
9781 11: 1047039
9782 },
9783 ie: {
9784 8: 0,
9785 9: 262144,
9786 10: 262144,
9787 11: 262400
9788 },
9789 edge: {
9790 12: 305485,
9791 13: 387535,
9792 14: 1042943,
9793 15: 1042943,
9794 16: 1042943
9795 },
9796 node: {
9797 '0.10': 262144,
9798 '0.12': 262208,
9799 4: 297167,
9800 5: 297167,
9801 6: 391679,
9802 8: 1047039,
9803 '8.3': 1047039,
9804 '8.7': 1047039
9805 }
9806};
9807
9808var features = [
9809 'arrow',
9810 'classes',
9811 'computedProperty',
9812 'conciseMethodProperty',
9813 'defaultParameter',
9814 'destructuring',
9815 'forOf',
9816 'generator',
9817 'letConst',
9818 'moduleExport',
9819 'moduleImport',
9820 'numericLiteral',
9821 'parameterDestructuring',
9822 'spreadRest',
9823 'stickyRegExp',
9824 'templateString',
9825 'unicodeRegExp',
9826
9827 // ES2016
9828 'exponentiation',
9829
9830 // additional transforms, not from
9831 // https://featuretests.io
9832 'reservedProperties',
9833
9834 'trailingFunctionCommas'
9835];
9836
9837var version = "0.19.3";
9838
9839var ref = [inject, acornDynamicImport].reduce(
9840 function (final, plugin) { return plugin(final); },
9841 acorn
9842);
9843var parse = ref.parse;
9844
9845var dangerousTransforms = ['dangerousTaggedTemplateString', 'dangerousForOf'];
9846
9847function target(target) {
9848 var targets = Object.keys(target);
9849 var bitmask = targets.length
9850 ? 1048575
9851 : 262144;
9852
9853 Object.keys(target).forEach(function (environment) {
9854 var versions = matrix[environment];
9855 if (!versions)
9856 { throw new Error(
9857 ("Unknown environment '" + environment + "'. Please raise an issue at https://github.com/Rich-Harris/buble/issues")
9858 ); }
9859
9860 var targetVersion = target[environment];
9861 if (!(targetVersion in versions))
9862 { throw new Error(
9863 ("Support data exists for the following versions of " + environment + ": " + (Object.keys(
9864 versions
9865 ).join(
9866 ', '
9867 )) + ". Please raise an issue at https://github.com/Rich-Harris/buble/issues")
9868 ); }
9869 var support = versions[targetVersion];
9870
9871 bitmask &= support;
9872 });
9873
9874 var transforms = Object.create(null);
9875 features.forEach(function (name, i) {
9876 transforms[name] = !(bitmask & (1 << i));
9877 });
9878
9879 dangerousTransforms.forEach(function (name) {
9880 transforms[name] = false;
9881 });
9882
9883 return transforms;
9884}
9885
9886function transform(source, options) {
9887 if ( options === void 0 ) options = {};
9888
9889 var ast;
9890 var jsx = null;
9891
9892 try {
9893 ast = parse(source, {
9894 ecmaVersion: 9,
9895 preserveParens: true,
9896 sourceType: 'module',
9897 onComment: function (block, text) {
9898 if (!jsx) {
9899 var match = /@jsx\s+([^\s]+)/.exec(text);
9900 if (match) { jsx = match[1]; }
9901 }
9902 },
9903 plugins: {
9904 jsx: true,
9905 dynamicImport: true
9906 }
9907 });
9908 options.jsx = jsx || options.jsx;
9909 } catch (err) {
9910 err.snippet = getSnippet(source, err.loc);
9911 err.toString = function () { return ((err.name) + ": " + (err.message) + "\n" + (err.snippet)); };
9912 throw err;
9913 }
9914
9915 var transforms = target(options.target || {});
9916 Object.keys(options.transforms || {}).forEach(function (name) {
9917 if (name === 'modules') {
9918 if (!('moduleImport' in options.transforms))
9919 { transforms.moduleImport = options.transforms.modules; }
9920 if (!('moduleExport' in options.transforms))
9921 { transforms.moduleExport = options.transforms.modules; }
9922 return;
9923 }
9924
9925 if (!(name in transforms)) { throw new Error(("Unknown transform '" + name + "'")); }
9926 transforms[name] = options.transforms[name];
9927 });
9928
9929 return new Program(source, ast, transforms, options).export(options);
9930}
9931
9932export { target, transform, version as VERSION };
9933//# sourceMappingURL=buble-browser.es.js.map