UNPKG

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