UNPKG

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