UNPKG

406 kBJavaScriptView Raw
1import MagicString from 'magic-string';
2
3// Reserved word lists for various dialects of the language
4
5var reservedWords = {
6 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
7 5: "class enum extends super const export import",
8 6: "enum",
9 strict: "implements interface let package private protected public static yield",
10 strictBind: "eval arguments"
11};
12
13// And the keywords
14
15var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
16
17var keywords = {
18 5: ecma5AndLessKeywords,
19 6: ecma5AndLessKeywords + " const class extends export import super"
20};
21
22// ## Character categories
23
24// Big ugly regular expressions that match characters in the
25// whitespace, identifier, and identifier-start categories. These
26// are only applied when a character is found to actually have a
27// code point above 128.
28// Generated by `bin/generate-identifier-regex.js`.
29
30var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\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\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\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\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fd5\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ae\ua7b0-\ua7b7\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
31var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d4-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d01-\u0d03\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1cf8\u1cf9\u1dc0-\u1df5\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
32
33var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
34var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
35
36nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
37
38// These are a run-length and offset encoded representation of the
39// >0xffff code points that are a valid part of identifiers. The
40// offset starts at 0x10000, and each pair of numbers represents an
41// offset to the next range, and then a size of the range. They were
42// generated by bin/generate-identifier-regex.js
43
44// eslint-disable-next-line comma-spacing
45var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,25,391,63,32,0,449,56,264,8,2,36,18,0,50,29,881,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,65,0,32,6124,20,754,9486,1,3071,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,10591,541];
46
47// eslint-disable-next-line comma-spacing
48var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,7,0,161,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,87,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,9,838,7,2,7,17,9,57,21,2,13,19882,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239];
49
50// This has a complexity linear to the value of the code. The
51// assumption is that looking up astral identifier characters is
52// rare.
53function isInAstralSet(code, set) {
54 var pos = 0x10000;
55 for (var i = 0; i < set.length; i += 2) {
56 pos += set[i];
57 if (pos > code) { return false }
58 pos += set[i + 1];
59 if (pos >= code) { return true }
60 }
61}
62
63// Test whether a given character code starts an identifier.
64
65function isIdentifierStart(code, astral) {
66 if (code < 65) { return code === 36 }
67 if (code < 91) { return true }
68 if (code < 97) { return code === 95 }
69 if (code < 123) { return true }
70 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
71 if (astral === false) { return false }
72 return isInAstralSet(code, astralIdentifierStartCodes)
73}
74
75// Test whether a given character is part of an identifier.
76
77function isIdentifierChar(code, astral) {
78 if (code < 48) { return code === 36 }
79 if (code < 58) { return true }
80 if (code < 65) { return false }
81 if (code < 91) { return true }
82 if (code < 97) { return code === 95 }
83 if (code < 123) { return true }
84 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
85 if (astral === false) { return false }
86 return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
87}
88
89// ## Token types
90
91// The assignment of fine-grained, information-carrying type objects
92// allows the tokenizer to store the information it has about a
93// token in a way that is very cheap for the parser to look up.
94
95// All token type variables start with an underscore, to make them
96// easy to recognize.
97
98// The `beforeExpr` property is used to disambiguate between regular
99// expressions and divisions. It is set on all token types that can
100// be followed by an expression (thus, a slash after them would be a
101// regular expression).
102//
103// The `startsExpr` property is used to check if the token ends a
104// `yield` expression. It is set on all token types that either can
105// directly start an expression (like a quotation mark) or can
106// continue an expression (like the body of a string).
107//
108// `isLoop` marks a keyword as starting a loop, which is important
109// to know when parsing a label, in order to allow or disallow
110// continue jumps to that label.
111
112var TokenType = function TokenType(label, conf) {
113 if ( conf === void 0 ) conf = {};
114
115 this.label = label;
116 this.keyword = conf.keyword;
117 this.beforeExpr = !!conf.beforeExpr;
118 this.startsExpr = !!conf.startsExpr;
119 this.isLoop = !!conf.isLoop;
120 this.isAssign = !!conf.isAssign;
121 this.prefix = !!conf.prefix;
122 this.postfix = !!conf.postfix;
123 this.binop = conf.binop || null;
124 this.updateContext = null;
125};
126
127function binop(name, prec) {
128 return new TokenType(name, {beforeExpr: true, binop: prec})
129}
130var beforeExpr = {beforeExpr: true};
131var startsExpr = {startsExpr: true};
132
133// Map keyword names to token types.
134
135var keywords$1 = {};
136
137// Succinct definitions of keyword token types
138function kw(name, options) {
139 if ( options === void 0 ) options = {};
140
141 options.keyword = name;
142 return keywords$1[name] = new TokenType(name, options)
143}
144
145var types = {
146 num: new TokenType("num", startsExpr),
147 regexp: new TokenType("regexp", startsExpr),
148 string: new TokenType("string", startsExpr),
149 name: new TokenType("name", startsExpr),
150 eof: new TokenType("eof"),
151
152 // Punctuation token types.
153 bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
154 bracketR: new TokenType("]"),
155 braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
156 braceR: new TokenType("}"),
157 parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
158 parenR: new TokenType(")"),
159 comma: new TokenType(",", beforeExpr),
160 semi: new TokenType(";", beforeExpr),
161 colon: new TokenType(":", beforeExpr),
162 dot: new TokenType("."),
163 question: new TokenType("?", beforeExpr),
164 arrow: new TokenType("=>", beforeExpr),
165 template: new TokenType("template"),
166 invalidTemplate: new TokenType("invalidTemplate"),
167 ellipsis: new TokenType("...", beforeExpr),
168 backQuote: new TokenType("`", startsExpr),
169 dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
170
171 // Operators. These carry several kinds of properties to help the
172 // parser use them properly (the presence of these properties is
173 // what categorizes them as operators).
174 //
175 // `binop`, when present, specifies that this operator is a binary
176 // operator, and will refer to its precedence.
177 //
178 // `prefix` and `postfix` mark the operator as a prefix or postfix
179 // unary operator.
180 //
181 // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
182 // binary operators with a very low precedence, that should result
183 // in AssignmentExpression nodes.
184
185 eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
186 assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
187 incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
188 prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
189 logicalOR: binop("||", 1),
190 logicalAND: binop("&&", 2),
191 bitwiseOR: binop("|", 3),
192 bitwiseXOR: binop("^", 4),
193 bitwiseAND: binop("&", 5),
194 equality: binop("==/!=/===/!==", 6),
195 relational: binop("</>/<=/>=", 7),
196 bitShift: binop("<</>>/>>>", 8),
197 plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
198 modulo: binop("%", 10),
199 star: binop("*", 10),
200 slash: binop("/", 10),
201 starstar: new TokenType("**", {beforeExpr: true}),
202
203 // Keyword token types.
204 _break: kw("break"),
205 _case: kw("case", beforeExpr),
206 _catch: kw("catch"),
207 _continue: kw("continue"),
208 _debugger: kw("debugger"),
209 _default: kw("default", beforeExpr),
210 _do: kw("do", {isLoop: true, beforeExpr: true}),
211 _else: kw("else", beforeExpr),
212 _finally: kw("finally"),
213 _for: kw("for", {isLoop: true}),
214 _function: kw("function", startsExpr),
215 _if: kw("if"),
216 _return: kw("return", beforeExpr),
217 _switch: kw("switch"),
218 _throw: kw("throw", beforeExpr),
219 _try: kw("try"),
220 _var: kw("var"),
221 _const: kw("const"),
222 _while: kw("while", {isLoop: true}),
223 _with: kw("with"),
224 _new: kw("new", {beforeExpr: true, startsExpr: true}),
225 _this: kw("this", startsExpr),
226 _super: kw("super", startsExpr),
227 _class: kw("class", startsExpr),
228 _extends: kw("extends", beforeExpr),
229 _export: kw("export"),
230 _import: kw("import"),
231 _null: kw("null", startsExpr),
232 _true: kw("true", startsExpr),
233 _false: kw("false", startsExpr),
234 _in: kw("in", {beforeExpr: true, binop: 7}),
235 _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
236 _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
237 _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
238 _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
239};
240
241// Matches a whole line break (where CRLF is considered a single
242// line break). Used to count lines.
243
244var lineBreak = /\r\n?|\n|\u2028|\u2029/;
245var lineBreakG = new RegExp(lineBreak.source, "g");
246
247function isNewLine(code) {
248 return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
249}
250
251var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
252
253var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
254
255var ref$1 = Object.prototype;
256var hasOwnProperty = ref$1.hasOwnProperty;
257var toString = ref$1.toString;
258
259// Checks if an object has a property.
260
261function has(obj, propName) {
262 return hasOwnProperty.call(obj, propName)
263}
264
265var isArray = Array.isArray || (function (obj) { return (
266 toString.call(obj) === "[object Array]"
267); });
268
269// These are used when `options.locations` is on, for the
270// `startLoc` and `endLoc` properties.
271
272var Position = function Position(line, col) {
273 this.line = line;
274 this.column = col;
275};
276
277Position.prototype.offset = function offset (n) {
278 return new Position(this.line, this.column + n)
279};
280
281var SourceLocation = function SourceLocation(p, start, end) {
282 this.start = start;
283 this.end = end;
284 if (p.sourceFile !== null) { this.source = p.sourceFile; }
285};
286
287// The `getLineInfo` function is mostly useful when the
288// `locations` option is off (for performance reasons) and you
289// want to find the line/column position for a given character
290// offset. `input` should be the code string that the offset refers
291// into.
292
293function getLineInfo(input, offset) {
294 for (var line = 1, cur = 0;;) {
295 lineBreakG.lastIndex = cur;
296 var match = lineBreakG.exec(input);
297 if (match && match.index < offset) {
298 ++line;
299 cur = match.index + match[0].length;
300 } else {
301 return new Position(line, offset - cur)
302 }
303 }
304}
305
306// A second optional argument can be given to further configure
307// the parser process. These options are recognized:
308
309var defaultOptions = {
310 // `ecmaVersion` indicates the ECMAScript version to parse. Must
311 // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
312 // for strict mode, the set of reserved words, and support for
313 // new syntax features. The default is 7.
314 ecmaVersion: 7,
315 // `sourceType` indicates the mode the code should be parsed in.
316 // Can be either `"script"` or `"module"`. This influences global
317 // strict mode and parsing of `import` and `export` declarations.
318 sourceType: "script",
319 // `onInsertedSemicolon` can be a callback that will be called
320 // when a semicolon is automatically inserted. It will be passed
321 // th position of the comma as an offset, and if `locations` is
322 // enabled, it is given the location as a `{line, column}` object
323 // as second argument.
324 onInsertedSemicolon: null,
325 // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
326 // trailing commas.
327 onTrailingComma: null,
328 // By default, reserved words are only enforced if ecmaVersion >= 5.
329 // Set `allowReserved` to a boolean value to explicitly turn this on
330 // an off. When this option has the value "never", reserved words
331 // and keywords can also not be used as property names.
332 allowReserved: null,
333 // When enabled, a return at the top level is not considered an
334 // error.
335 allowReturnOutsideFunction: false,
336 // When enabled, import/export statements are not constrained to
337 // appearing at the top of the program.
338 allowImportExportEverywhere: false,
339 // When enabled, hashbang directive in the beginning of file
340 // is allowed and treated as a line comment.
341 allowHashBang: false,
342 // When `locations` is on, `loc` properties holding objects with
343 // `start` and `end` properties in `{line, column}` form (with
344 // line being 1-based and column 0-based) will be attached to the
345 // nodes.
346 locations: false,
347 // A function can be passed as `onToken` option, which will
348 // cause Acorn to call that function with object in the same
349 // format as tokens returned from `tokenizer().getToken()`. Note
350 // that you are not allowed to call the parser from the
351 // callback—that will corrupt its internal state.
352 onToken: null,
353 // A function can be passed as `onComment` option, which will
354 // cause Acorn to call that function with `(block, text, start,
355 // end)` parameters whenever a comment is skipped. `block` is a
356 // boolean indicating whether this is a block (`/* */`) comment,
357 // `text` is the content of the comment, and `start` and `end` are
358 // character offsets that denote the start and end of the comment.
359 // When the `locations` option is on, two more parameters are
360 // passed, the full `{line, column}` locations of the start and
361 // end of the comments. Note that you are not allowed to call the
362 // parser from the callback—that will corrupt its internal state.
363 onComment: null,
364 // Nodes have their start and end characters offsets recorded in
365 // `start` and `end` properties (directly on the node, rather than
366 // the `loc` object, which holds line/column data. To also add a
367 // [semi-standardized][range] `range` property holding a `[start,
368 // end]` array with the same numbers, set the `ranges` option to
369 // `true`.
370 //
371 // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
372 ranges: false,
373 // It is possible to parse multiple files into a single AST by
374 // passing the tree produced by parsing the first file as
375 // `program` option in subsequent parses. This will add the
376 // toplevel forms of the parsed file to the `Program` (top) node
377 // of an existing parse tree.
378 program: null,
379 // When `locations` is on, you can pass this to record the source
380 // file in every node's `loc` object.
381 sourceFile: null,
382 // This value, if given, is stored in every node, whether
383 // `locations` is on or off.
384 directSourceFile: null,
385 // When enabled, parenthesized expressions are represented by
386 // (non-standard) ParenthesizedExpression nodes
387 preserveParens: false,
388 plugins: {}
389};
390
391// Interpret and default an options object
392
393function getOptions(opts) {
394 var options = {};
395
396 for (var opt in defaultOptions)
397 { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
398
399 if (options.ecmaVersion >= 2015)
400 { options.ecmaVersion -= 2009; }
401
402 if (options.allowReserved == null)
403 { options.allowReserved = options.ecmaVersion < 5; }
404
405 if (isArray(options.onToken)) {
406 var tokens = options.onToken;
407 options.onToken = function (token) { return tokens.push(token); };
408 }
409 if (isArray(options.onComment))
410 { options.onComment = pushComment(options, options.onComment); }
411
412 return options
413}
414
415function pushComment(options, array) {
416 return function(block, text, start, end, startLoc, endLoc) {
417 var comment = {
418 type: block ? "Block" : "Line",
419 value: text,
420 start: start,
421 end: end
422 };
423 if (options.locations)
424 { comment.loc = new SourceLocation(this, startLoc, endLoc); }
425 if (options.ranges)
426 { comment.range = [start, end]; }
427 array.push(comment);
428 }
429}
430
431// Registered plugins
432var plugins = {};
433
434function keywordRegexp(words) {
435 return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
436}
437
438var Parser = function Parser(options, input, startPos) {
439 this.options = options = getOptions(options);
440 this.sourceFile = options.sourceFile;
441 this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
442 var reserved = "";
443 if (!options.allowReserved) {
444 for (var v = options.ecmaVersion;; v--)
445 { if (reserved = reservedWords[v]) { break } }
446 if (options.sourceType == "module") { reserved += " await"; }
447 }
448 this.reservedWords = keywordRegexp(reserved);
449 var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
450 this.reservedWordsStrict = keywordRegexp(reservedStrict);
451 this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
452 this.input = String(input);
453
454 // Used to signal to callers of `readWord1` whether the word
455 // contained any escape sequences. This is needed because words with
456 // escape sequences must not be interpreted as keywords.
457 this.containsEsc = false;
458
459 // Load plugins
460 this.loadPlugins(options.plugins);
461
462 // Set up token state
463
464 // The current position of the tokenizer in the input.
465 if (startPos) {
466 this.pos = startPos;
467 this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
468 this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
469 } else {
470 this.pos = this.lineStart = 0;
471 this.curLine = 1;
472 }
473
474 // Properties of the current token:
475 // Its type
476 this.type = types.eof;
477 // For tokens that include more information than their type, the value
478 this.value = null;
479 // Its start and end offset
480 this.start = this.end = this.pos;
481 // And, if locations are used, the {line, column} object
482 // corresponding to those offsets
483 this.startLoc = this.endLoc = this.curPosition();
484
485 // Position information for the previous token
486 this.lastTokEndLoc = this.lastTokStartLoc = null;
487 this.lastTokStart = this.lastTokEnd = this.pos;
488
489 // The context stack is used to superficially track syntactic
490 // context to predict whether a regular expression is allowed in a
491 // given position.
492 this.context = this.initialContext();
493 this.exprAllowed = true;
494
495 // Figure out if it's a module code.
496 this.inModule = options.sourceType === "module";
497 this.strict = this.inModule || this.strictDirective(this.pos);
498
499 // Used to signify the start of a potential arrow function
500 this.potentialArrowAt = -1;
501
502 // Flags to track whether we are in a function, a generator, an async function.
503 this.inFunction = this.inGenerator = this.inAsync = false;
504 // Positions to delayed-check that yield/await does not exist in default parameters.
505 this.yieldPos = this.awaitPos = 0;
506 // Labels in scope.
507 this.labels = [];
508
509 // If enabled, skip leading hashbang line.
510 if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
511 { this.skipLineComment(2); }
512
513 // Scope tracking for duplicate variable names (see scope.js)
514 this.scopeStack = [];
515 this.enterFunctionScope();
516};
517
518// DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
519Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
520Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
521
522Parser.prototype.extend = function extend (name, f) {
523 this[name] = f(this[name]);
524};
525
526Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
527 var this$1 = this;
528
529 for (var name in pluginConfigs) {
530 var plugin = plugins[name];
531 if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
532 plugin(this$1, pluginConfigs[name]);
533 }
534};
535
536Parser.prototype.parse = function parse () {
537 var node = this.options.program || this.startNode();
538 this.nextToken();
539 return this.parseTopLevel(node)
540};
541
542var pp = Parser.prototype;
543
544// ## Parser utilities
545
546var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
547pp.strictDirective = function(start) {
548 var this$1 = this;
549
550 for (;;) {
551 skipWhiteSpace.lastIndex = start;
552 start += skipWhiteSpace.exec(this$1.input)[0].length;
553 var match = literal.exec(this$1.input.slice(start));
554 if (!match) { return false }
555 if ((match[1] || match[2]) == "use strict") { return true }
556 start += match[0].length;
557 }
558};
559
560// Predicate that tests whether the next token is of the given
561// type, and if yes, consumes it as a side effect.
562
563pp.eat = function(type) {
564 if (this.type === type) {
565 this.next();
566 return true
567 } else {
568 return false
569 }
570};
571
572// Tests whether parsed token is a contextual keyword.
573
574pp.isContextual = function(name) {
575 return this.type === types.name && this.value === name
576};
577
578// Consumes contextual keyword if possible.
579
580pp.eatContextual = function(name) {
581 return this.value === name && this.eat(types.name)
582};
583
584// Asserts that following token is given contextual keyword.
585
586pp.expectContextual = function(name) {
587 if (!this.eatContextual(name)) { this.unexpected(); }
588};
589
590// Test whether a semicolon can be inserted at the current position.
591
592pp.canInsertSemicolon = function() {
593 return this.type === types.eof ||
594 this.type === types.braceR ||
595 lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
596};
597
598pp.insertSemicolon = function() {
599 if (this.canInsertSemicolon()) {
600 if (this.options.onInsertedSemicolon)
601 { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
602 return true
603 }
604};
605
606// Consume a semicolon, or, failing that, see if we are allowed to
607// pretend that there is a semicolon at this position.
608
609pp.semicolon = function() {
610 if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
611};
612
613pp.afterTrailingComma = function(tokType, notNext) {
614 if (this.type == tokType) {
615 if (this.options.onTrailingComma)
616 { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
617 if (!notNext)
618 { this.next(); }
619 return true
620 }
621};
622
623// Expect a token of a given type. If found, consume it, otherwise,
624// raise an unexpected token error.
625
626pp.expect = function(type) {
627 this.eat(type) || this.unexpected();
628};
629
630// Raise an unexpected token error.
631
632pp.unexpected = function(pos) {
633 this.raise(pos != null ? pos : this.start, "Unexpected token");
634};
635
636function DestructuringErrors() {
637 this.shorthandAssign =
638 this.trailingComma =
639 this.parenthesizedAssign =
640 this.parenthesizedBind =
641 -1;
642}
643
644pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
645 if (!refDestructuringErrors) { return }
646 if (refDestructuringErrors.trailingComma > -1)
647 { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
648 var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
649 if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
650};
651
652pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
653 var pos = refDestructuringErrors ? refDestructuringErrors.shorthandAssign : -1;
654 if (!andThrow) { return pos >= 0 }
655 if (pos > -1) { this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns"); }
656};
657
658pp.checkYieldAwaitInDefaultParams = function() {
659 if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
660 { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
661 if (this.awaitPos)
662 { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
663};
664
665pp.isSimpleAssignTarget = function(expr) {
666 if (expr.type === "ParenthesizedExpression")
667 { return this.isSimpleAssignTarget(expr.expression) }
668 return expr.type === "Identifier" || expr.type === "MemberExpression"
669};
670
671var pp$1 = Parser.prototype;
672
673// ### Statement parsing
674
675// Parse a program. Initializes the parser, reads any number of
676// statements, and wraps them in a Program node. Optionally takes a
677// `program` argument. If present, the statements will be appended
678// to its body instead of creating a new node.
679
680pp$1.parseTopLevel = function(node) {
681 var this$1 = this;
682
683 var exports = {};
684 if (!node.body) { node.body = []; }
685 while (this.type !== types.eof) {
686 var stmt = this$1.parseStatement(true, true, exports);
687 node.body.push(stmt);
688 }
689 this.next();
690 if (this.options.ecmaVersion >= 6) {
691 node.sourceType = this.options.sourceType;
692 }
693 return this.finishNode(node, "Program")
694};
695
696var loopLabel = {kind: "loop"};
697var switchLabel = {kind: "switch"};
698
699pp$1.isLet = function() {
700 if (this.type !== types.name || this.options.ecmaVersion < 6 || this.value != "let") { return false }
701 skipWhiteSpace.lastIndex = this.pos;
702 var skip = skipWhiteSpace.exec(this.input);
703 var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
704 if (nextCh === 91 || nextCh == 123) { return true } // '{' and '['
705 if (isIdentifierStart(nextCh, true)) {
706 var pos = next + 1;
707 while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
708 var ident = this.input.slice(next, pos);
709 if (!this.isKeyword(ident)) { return true }
710 }
711 return false
712};
713
714// check 'async [no LineTerminator here] function'
715// - 'async /*foo*/ function' is OK.
716// - 'async /*\n*/ function' is invalid.
717pp$1.isAsyncFunction = function() {
718 if (this.type !== types.name || this.options.ecmaVersion < 8 || this.value != "async")
719 { return false }
720
721 skipWhiteSpace.lastIndex = this.pos;
722 var skip = skipWhiteSpace.exec(this.input);
723 var next = this.pos + skip[0].length;
724 return !lineBreak.test(this.input.slice(this.pos, next)) &&
725 this.input.slice(next, next + 8) === "function" &&
726 (next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
727};
728
729// Parse a single statement.
730//
731// If expecting a statement and finding a slash operator, parse a
732// regular expression literal. This is to handle cases like
733// `if (foo) /blah/.exec(foo)`, where looking at the previous token
734// does not help.
735
736pp$1.parseStatement = function(declaration, topLevel, exports) {
737 var starttype = this.type, node = this.startNode(), kind;
738
739 if (this.isLet()) {
740 starttype = types._var;
741 kind = "let";
742 }
743
744 // Most types of statements are recognized by the keyword they
745 // start with. Many are trivial to parse, some require a bit of
746 // complexity.
747
748 switch (starttype) {
749 case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
750 case types._debugger: return this.parseDebuggerStatement(node)
751 case types._do: return this.parseDoStatement(node)
752 case types._for: return this.parseForStatement(node)
753 case types._function:
754 if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
755 return this.parseFunctionStatement(node, false)
756 case types._class:
757 if (!declaration) { this.unexpected(); }
758 return this.parseClass(node, true)
759 case types._if: return this.parseIfStatement(node)
760 case types._return: return this.parseReturnStatement(node)
761 case types._switch: return this.parseSwitchStatement(node)
762 case types._throw: return this.parseThrowStatement(node)
763 case types._try: return this.parseTryStatement(node)
764 case types._const: case types._var:
765 kind = kind || this.value;
766 if (!declaration && kind != "var") { this.unexpected(); }
767 return this.parseVarStatement(node, kind)
768 case types._while: return this.parseWhileStatement(node)
769 case types._with: return this.parseWithStatement(node)
770 case types.braceL: return this.parseBlock()
771 case types.semi: return this.parseEmptyStatement(node)
772 case types._export:
773 case types._import:
774 if (!this.options.allowImportExportEverywhere) {
775 if (!topLevel)
776 { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
777 if (!this.inModule)
778 { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
779 }
780 return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
781
782 // If the statement does not start with a statement keyword or a
783 // brace, it's an ExpressionStatement or LabeledStatement. We
784 // simply start parsing an expression, and afterwards, if the
785 // next token is a colon and the expression was a simple
786 // Identifier node, we switch to interpreting it as a label.
787 default:
788 if (this.isAsyncFunction() && declaration) {
789 this.next();
790 return this.parseFunctionStatement(node, true)
791 }
792
793 var maybeName = this.value, expr = this.parseExpression();
794 if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
795 { return this.parseLabeledStatement(node, maybeName, expr) }
796 else { return this.parseExpressionStatement(node, expr) }
797 }
798};
799
800pp$1.parseBreakContinueStatement = function(node, keyword) {
801 var this$1 = this;
802
803 var isBreak = keyword == "break";
804 this.next();
805 if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
806 else if (this.type !== types.name) { this.unexpected(); }
807 else {
808 node.label = this.parseIdent();
809 this.semicolon();
810 }
811
812 // Verify that there is an actual destination to break or
813 // continue to.
814 var i = 0;
815 for (; i < this.labels.length; ++i) {
816 var lab = this$1.labels[i];
817 if (node.label == null || lab.name === node.label.name) {
818 if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
819 if (node.label && isBreak) { break }
820 }
821 }
822 if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
823 return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
824};
825
826pp$1.parseDebuggerStatement = function(node) {
827 this.next();
828 this.semicolon();
829 return this.finishNode(node, "DebuggerStatement")
830};
831
832pp$1.parseDoStatement = function(node) {
833 this.next();
834 this.labels.push(loopLabel);
835 node.body = this.parseStatement(false);
836 this.labels.pop();
837 this.expect(types._while);
838 node.test = this.parseParenExpression();
839 if (this.options.ecmaVersion >= 6)
840 { this.eat(types.semi); }
841 else
842 { this.semicolon(); }
843 return this.finishNode(node, "DoWhileStatement")
844};
845
846// Disambiguating between a `for` and a `for`/`in` or `for`/`of`
847// loop is non-trivial. Basically, we have to parse the init `var`
848// statement or expression, disallowing the `in` operator (see
849// the second parameter to `parseExpression`), and then check
850// whether the next token is `in` or `of`. When there is no init
851// part (semicolon immediately after the opening parenthesis), it
852// is a regular `for` loop.
853
854pp$1.parseForStatement = function(node) {
855 this.next();
856 this.labels.push(loopLabel);
857 this.enterLexicalScope();
858 this.expect(types.parenL);
859 if (this.type === types.semi) { return this.parseFor(node, null) }
860 var isLet = this.isLet();
861 if (this.type === types._var || this.type === types._const || isLet) {
862 var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
863 this.next();
864 this.parseVar(init$1, true, kind);
865 this.finishNode(init$1, "VariableDeclaration");
866 if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
867 !(kind !== "var" && init$1.declarations[0].init))
868 { return this.parseForIn(node, init$1) }
869 return this.parseFor(node, init$1)
870 }
871 var refDestructuringErrors = new DestructuringErrors;
872 var init = this.parseExpression(true, refDestructuringErrors);
873 if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
874 this.toAssignable(init);
875 this.checkLVal(init);
876 this.checkPatternErrors(refDestructuringErrors, true);
877 return this.parseForIn(node, init)
878 } else {
879 this.checkExpressionErrors(refDestructuringErrors, true);
880 }
881 return this.parseFor(node, init)
882};
883
884pp$1.parseFunctionStatement = function(node, isAsync) {
885 this.next();
886 return this.parseFunction(node, true, false, isAsync)
887};
888
889pp$1.isFunction = function() {
890 return this.type === types._function || this.isAsyncFunction()
891};
892
893pp$1.parseIfStatement = function(node) {
894 this.next();
895 node.test = this.parseParenExpression();
896 // allow function declarations in branches, but only in non-strict mode
897 node.consequent = this.parseStatement(!this.strict && this.isFunction());
898 node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.isFunction()) : null;
899 return this.finishNode(node, "IfStatement")
900};
901
902pp$1.parseReturnStatement = function(node) {
903 if (!this.inFunction && !this.options.allowReturnOutsideFunction)
904 { this.raise(this.start, "'return' outside of function"); }
905 this.next();
906
907 // In `return` (and `break`/`continue`), the keywords with
908 // optional arguments, we eagerly look for a semicolon or the
909 // possibility to insert one.
910
911 if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
912 else { node.argument = this.parseExpression(); this.semicolon(); }
913 return this.finishNode(node, "ReturnStatement")
914};
915
916pp$1.parseSwitchStatement = function(node) {
917 var this$1 = this;
918
919 this.next();
920 node.discriminant = this.parseParenExpression();
921 node.cases = [];
922 this.expect(types.braceL);
923 this.labels.push(switchLabel);
924 this.enterLexicalScope();
925
926 // Statements under must be grouped (by label) in SwitchCase
927 // nodes. `cur` is used to keep the node that we are currently
928 // adding statements to.
929
930 var cur;
931 for (var sawDefault = false; this.type != types.braceR;) {
932 if (this$1.type === types._case || this$1.type === types._default) {
933 var isCase = this$1.type === types._case;
934 if (cur) { this$1.finishNode(cur, "SwitchCase"); }
935 node.cases.push(cur = this$1.startNode());
936 cur.consequent = [];
937 this$1.next();
938 if (isCase) {
939 cur.test = this$1.parseExpression();
940 } else {
941 if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
942 sawDefault = true;
943 cur.test = null;
944 }
945 this$1.expect(types.colon);
946 } else {
947 if (!cur) { this$1.unexpected(); }
948 cur.consequent.push(this$1.parseStatement(true));
949 }
950 }
951 this.exitLexicalScope();
952 if (cur) { this.finishNode(cur, "SwitchCase"); }
953 this.next(); // Closing brace
954 this.labels.pop();
955 return this.finishNode(node, "SwitchStatement")
956};
957
958pp$1.parseThrowStatement = function(node) {
959 this.next();
960 if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
961 { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
962 node.argument = this.parseExpression();
963 this.semicolon();
964 return this.finishNode(node, "ThrowStatement")
965};
966
967// Reused empty array added for node fields that are always empty.
968
969var empty = [];
970
971pp$1.parseTryStatement = function(node) {
972 this.next();
973 node.block = this.parseBlock();
974 node.handler = null;
975 if (this.type === types._catch) {
976 var clause = this.startNode();
977 this.next();
978 this.expect(types.parenL);
979 clause.param = this.parseBindingAtom();
980 this.enterLexicalScope();
981 this.checkLVal(clause.param, "let");
982 this.expect(types.parenR);
983 clause.body = this.parseBlock(false);
984 this.exitLexicalScope();
985 node.handler = this.finishNode(clause, "CatchClause");
986 }
987 node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
988 if (!node.handler && !node.finalizer)
989 { this.raise(node.start, "Missing catch or finally clause"); }
990 return this.finishNode(node, "TryStatement")
991};
992
993pp$1.parseVarStatement = function(node, kind) {
994 this.next();
995 this.parseVar(node, false, kind);
996 this.semicolon();
997 return this.finishNode(node, "VariableDeclaration")
998};
999
1000pp$1.parseWhileStatement = function(node) {
1001 this.next();
1002 node.test = this.parseParenExpression();
1003 this.labels.push(loopLabel);
1004 node.body = this.parseStatement(false);
1005 this.labels.pop();
1006 return this.finishNode(node, "WhileStatement")
1007};
1008
1009pp$1.parseWithStatement = function(node) {
1010 if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
1011 this.next();
1012 node.object = this.parseParenExpression();
1013 node.body = this.parseStatement(false);
1014 return this.finishNode(node, "WithStatement")
1015};
1016
1017pp$1.parseEmptyStatement = function(node) {
1018 this.next();
1019 return this.finishNode(node, "EmptyStatement")
1020};
1021
1022pp$1.parseLabeledStatement = function(node, maybeName, expr) {
1023 var this$1 = this;
1024
1025 for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
1026 {
1027 var label = list[i$1];
1028
1029 if (label.name === maybeName)
1030 { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
1031 } }
1032 var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
1033 for (var i = this.labels.length - 1; i >= 0; i--) {
1034 var label$1 = this$1.labels[i];
1035 if (label$1.statementStart == node.start) {
1036 label$1.statementStart = this$1.start;
1037 label$1.kind = kind;
1038 } else { break }
1039 }
1040 this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
1041 node.body = this.parseStatement(true);
1042 if (node.body.type == "ClassDeclaration" ||
1043 node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
1044 node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator))
1045 { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
1046 this.labels.pop();
1047 node.label = expr;
1048 return this.finishNode(node, "LabeledStatement")
1049};
1050
1051pp$1.parseExpressionStatement = function(node, expr) {
1052 node.expression = expr;
1053 this.semicolon();
1054 return this.finishNode(node, "ExpressionStatement")
1055};
1056
1057// Parse a semicolon-enclosed block of statements, handling `"use
1058// strict"` declarations when `allowStrict` is true (used for
1059// function bodies).
1060
1061pp$1.parseBlock = function(createNewLexicalScope) {
1062 var this$1 = this;
1063 if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
1064
1065 var node = this.startNode();
1066 node.body = [];
1067 this.expect(types.braceL);
1068 if (createNewLexicalScope) {
1069 this.enterLexicalScope();
1070 }
1071 while (!this.eat(types.braceR)) {
1072 var stmt = this$1.parseStatement(true);
1073 node.body.push(stmt);
1074 }
1075 if (createNewLexicalScope) {
1076 this.exitLexicalScope();
1077 }
1078 return this.finishNode(node, "BlockStatement")
1079};
1080
1081// Parse a regular `for` loop. The disambiguation code in
1082// `parseStatement` will already have parsed the init statement or
1083// expression.
1084
1085pp$1.parseFor = function(node, init) {
1086 node.init = init;
1087 this.expect(types.semi);
1088 node.test = this.type === types.semi ? null : this.parseExpression();
1089 this.expect(types.semi);
1090 node.update = this.type === types.parenR ? null : this.parseExpression();
1091 this.expect(types.parenR);
1092 this.exitLexicalScope();
1093 node.body = this.parseStatement(false);
1094 this.labels.pop();
1095 return this.finishNode(node, "ForStatement")
1096};
1097
1098// Parse a `for`/`in` and `for`/`of` loop, which are almost
1099// same from parser's perspective.
1100
1101pp$1.parseForIn = function(node, init) {
1102 var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
1103 this.next();
1104 node.left = init;
1105 node.right = this.parseExpression();
1106 this.expect(types.parenR);
1107 this.exitLexicalScope();
1108 node.body = this.parseStatement(false);
1109 this.labels.pop();
1110 return this.finishNode(node, type)
1111};
1112
1113// Parse a list of variable declarations.
1114
1115pp$1.parseVar = function(node, isFor, kind) {
1116 var this$1 = this;
1117
1118 node.declarations = [];
1119 node.kind = kind;
1120 for (;;) {
1121 var decl = this$1.startNode();
1122 this$1.parseVarId(decl, kind);
1123 if (this$1.eat(types.eq)) {
1124 decl.init = this$1.parseMaybeAssign(isFor);
1125 } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
1126 this$1.unexpected();
1127 } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
1128 this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
1129 } else {
1130 decl.init = null;
1131 }
1132 node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
1133 if (!this$1.eat(types.comma)) { break }
1134 }
1135 return node
1136};
1137
1138pp$1.parseVarId = function(decl, kind) {
1139 decl.id = this.parseBindingAtom(kind);
1140 this.checkLVal(decl.id, kind, false);
1141};
1142
1143// Parse a function declaration or literal (depending on the
1144// `isStatement` parameter).
1145
1146pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
1147 this.initFunction(node);
1148 if (this.options.ecmaVersion >= 6 && !isAsync)
1149 { node.generator = this.eat(types.star); }
1150 if (this.options.ecmaVersion >= 8)
1151 { node.async = !!isAsync; }
1152
1153 if (isStatement) {
1154 node.id = isStatement === "nullableID" && this.type != types.name ? null : this.parseIdent();
1155 if (node.id) {
1156 this.checkLVal(node.id, "var");
1157 }
1158 }
1159
1160 var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
1161 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
1162 this.inGenerator = node.generator;
1163 this.inAsync = node.async;
1164 this.yieldPos = 0;
1165 this.awaitPos = 0;
1166 this.inFunction = true;
1167 this.enterFunctionScope();
1168
1169 if (!isStatement)
1170 { node.id = this.type == types.name ? this.parseIdent() : null; }
1171
1172 this.parseFunctionParams(node);
1173 this.parseFunctionBody(node, allowExpressionBody);
1174
1175 this.inGenerator = oldInGen;
1176 this.inAsync = oldInAsync;
1177 this.yieldPos = oldYieldPos;
1178 this.awaitPos = oldAwaitPos;
1179 this.inFunction = oldInFunc;
1180 return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
1181};
1182
1183pp$1.parseFunctionParams = function(node) {
1184 this.expect(types.parenL);
1185 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
1186 this.checkYieldAwaitInDefaultParams();
1187};
1188
1189// Parse a class declaration or literal (depending on the
1190// `isStatement` parameter).
1191
1192pp$1.parseClass = function(node, isStatement) {
1193 var this$1 = this;
1194
1195 this.next();
1196
1197 this.parseClassId(node, isStatement);
1198 this.parseClassSuper(node);
1199 var classBody = this.startNode();
1200 var hadConstructor = false;
1201 classBody.body = [];
1202 this.expect(types.braceL);
1203 while (!this.eat(types.braceR)) {
1204 if (this$1.eat(types.semi)) { continue }
1205 var method = this$1.startNode();
1206 var isGenerator = this$1.eat(types.star);
1207 var isAsync = false;
1208 var isMaybeStatic = this$1.type === types.name && this$1.value === "static";
1209 this$1.parsePropertyName(method);
1210 method.static = isMaybeStatic && this$1.type !== types.parenL;
1211 if (method.static) {
1212 if (isGenerator) { this$1.unexpected(); }
1213 isGenerator = this$1.eat(types.star);
1214 this$1.parsePropertyName(method);
1215 }
1216 if (this$1.options.ecmaVersion >= 8 && !isGenerator && !method.computed &&
1217 method.key.type === "Identifier" && method.key.name === "async" && this$1.type !== types.parenL &&
1218 !this$1.canInsertSemicolon()) {
1219 isAsync = true;
1220 this$1.parsePropertyName(method);
1221 }
1222 method.kind = "method";
1223 var isGetSet = false;
1224 if (!method.computed) {
1225 var key = method.key;
1226 if (!isGenerator && !isAsync && key.type === "Identifier" && this$1.type !== types.parenL && (key.name === "get" || key.name === "set")) {
1227 isGetSet = true;
1228 method.kind = key.name;
1229 key = this$1.parsePropertyName(method);
1230 }
1231 if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
1232 key.type === "Literal" && key.value === "constructor")) {
1233 if (hadConstructor) { this$1.raise(key.start, "Duplicate constructor in the same class"); }
1234 if (isGetSet) { this$1.raise(key.start, "Constructor can't have get/set modifier"); }
1235 if (isGenerator) { this$1.raise(key.start, "Constructor can't be a generator"); }
1236 if (isAsync) { this$1.raise(key.start, "Constructor can't be an async method"); }
1237 method.kind = "constructor";
1238 hadConstructor = true;
1239 }
1240 }
1241 this$1.parseClassMethod(classBody, method, isGenerator, isAsync);
1242 if (isGetSet) {
1243 var paramCount = method.kind === "get" ? 0 : 1;
1244 if (method.value.params.length !== paramCount) {
1245 var start = method.value.start;
1246 if (method.kind === "get")
1247 { this$1.raiseRecoverable(start, "getter should have no params"); }
1248 else
1249 { this$1.raiseRecoverable(start, "setter should have exactly one param"); }
1250 } else {
1251 if (method.kind === "set" && method.value.params[0].type === "RestElement")
1252 { this$1.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
1253 }
1254 }
1255 }
1256 node.body = this.finishNode(classBody, "ClassBody");
1257 return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
1258};
1259
1260pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
1261 method.value = this.parseMethod(isGenerator, isAsync);
1262 classBody.body.push(this.finishNode(method, "MethodDefinition"));
1263};
1264
1265pp$1.parseClassId = function(node, isStatement) {
1266 node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
1267};
1268
1269pp$1.parseClassSuper = function(node) {
1270 node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
1271};
1272
1273// Parses module export declaration.
1274
1275pp$1.parseExport = function(node, exports) {
1276 var this$1 = this;
1277
1278 this.next();
1279 // export * from '...'
1280 if (this.eat(types.star)) {
1281 this.expectContextual("from");
1282 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1283 this.semicolon();
1284 return this.finishNode(node, "ExportAllDeclaration")
1285 }
1286 if (this.eat(types._default)) { // export default ...
1287 this.checkExport(exports, "default", this.lastTokStart);
1288 var isAsync;
1289 if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
1290 var fNode = this.startNode();
1291 this.next();
1292 if (isAsync) { this.next(); }
1293 node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
1294 } else if (this.type === types._class) {
1295 var cNode = this.startNode();
1296 node.declaration = this.parseClass(cNode, "nullableID");
1297 } else {
1298 node.declaration = this.parseMaybeAssign();
1299 this.semicolon();
1300 }
1301 return this.finishNode(node, "ExportDefaultDeclaration")
1302 }
1303 // export var|const|let|function|class ...
1304 if (this.shouldParseExportStatement()) {
1305 node.declaration = this.parseStatement(true);
1306 if (node.declaration.type === "VariableDeclaration")
1307 { this.checkVariableExport(exports, node.declaration.declarations); }
1308 else
1309 { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
1310 node.specifiers = [];
1311 node.source = null;
1312 } else { // export { x, y as z } [from '...']
1313 node.declaration = null;
1314 node.specifiers = this.parseExportSpecifiers(exports);
1315 if (this.eatContextual("from")) {
1316 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1317 } else {
1318 // check for keywords used as local names
1319 for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
1320 var spec = list[i];
1321
1322 this$1.checkUnreserved(spec.local);
1323 }
1324
1325 node.source = null;
1326 }
1327 this.semicolon();
1328 }
1329 return this.finishNode(node, "ExportNamedDeclaration")
1330};
1331
1332pp$1.checkExport = function(exports, name, pos) {
1333 if (!exports) { return }
1334 if (has(exports, name))
1335 { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
1336 exports[name] = true;
1337};
1338
1339pp$1.checkPatternExport = function(exports, pat) {
1340 var this$1 = this;
1341
1342 var type = pat.type;
1343 if (type == "Identifier")
1344 { this.checkExport(exports, pat.name, pat.start); }
1345 else if (type == "ObjectPattern")
1346 { for (var i = 0, list = pat.properties; i < list.length; i += 1)
1347 {
1348 var prop = list[i];
1349
1350 this$1.checkPatternExport(exports, prop.value);
1351 } }
1352 else if (type == "ArrayPattern")
1353 { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
1354 var elt = list$1[i$1];
1355
1356 if (elt) { this$1.checkPatternExport(exports, elt); }
1357 } }
1358 else if (type == "AssignmentPattern")
1359 { this.checkPatternExport(exports, pat.left); }
1360 else if (type == "ParenthesizedExpression")
1361 { this.checkPatternExport(exports, pat.expression); }
1362};
1363
1364pp$1.checkVariableExport = function(exports, decls) {
1365 var this$1 = this;
1366
1367 if (!exports) { return }
1368 for (var i = 0, list = decls; i < list.length; i += 1)
1369 {
1370 var decl = list[i];
1371
1372 this$1.checkPatternExport(exports, decl.id);
1373 }
1374};
1375
1376pp$1.shouldParseExportStatement = function() {
1377 return this.type.keyword === "var" ||
1378 this.type.keyword === "const" ||
1379 this.type.keyword === "class" ||
1380 this.type.keyword === "function" ||
1381 this.isLet() ||
1382 this.isAsyncFunction()
1383};
1384
1385// Parses a comma-separated list of module exports.
1386
1387pp$1.parseExportSpecifiers = function(exports) {
1388 var this$1 = this;
1389
1390 var nodes = [], first = true;
1391 // export { x, y as z } [from '...']
1392 this.expect(types.braceL);
1393 while (!this.eat(types.braceR)) {
1394 if (!first) {
1395 this$1.expect(types.comma);
1396 if (this$1.afterTrailingComma(types.braceR)) { break }
1397 } else { first = false; }
1398
1399 var node = this$1.startNode();
1400 node.local = this$1.parseIdent(true);
1401 node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
1402 this$1.checkExport(exports, node.exported.name, node.exported.start);
1403 nodes.push(this$1.finishNode(node, "ExportSpecifier"));
1404 }
1405 return nodes
1406};
1407
1408// Parses import declaration.
1409
1410pp$1.parseImport = function(node) {
1411 this.next();
1412 // import '...'
1413 if (this.type === types.string) {
1414 node.specifiers = empty;
1415 node.source = this.parseExprAtom();
1416 } else {
1417 node.specifiers = this.parseImportSpecifiers();
1418 this.expectContextual("from");
1419 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1420 }
1421 this.semicolon();
1422 return this.finishNode(node, "ImportDeclaration")
1423};
1424
1425// Parses a comma-separated list of module imports.
1426
1427pp$1.parseImportSpecifiers = function() {
1428 var this$1 = this;
1429
1430 var nodes = [], first = true;
1431 if (this.type === types.name) {
1432 // import defaultObj, { x, y as z } from '...'
1433 var node = this.startNode();
1434 node.local = this.parseIdent();
1435 this.checkLVal(node.local, "let");
1436 nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
1437 if (!this.eat(types.comma)) { return nodes }
1438 }
1439 if (this.type === types.star) {
1440 var node$1 = this.startNode();
1441 this.next();
1442 this.expectContextual("as");
1443 node$1.local = this.parseIdent();
1444 this.checkLVal(node$1.local, "let");
1445 nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
1446 return nodes
1447 }
1448 this.expect(types.braceL);
1449 while (!this.eat(types.braceR)) {
1450 if (!first) {
1451 this$1.expect(types.comma);
1452 if (this$1.afterTrailingComma(types.braceR)) { break }
1453 } else { first = false; }
1454
1455 var node$2 = this$1.startNode();
1456 node$2.imported = this$1.parseIdent(true);
1457 if (this$1.eatContextual("as")) {
1458 node$2.local = this$1.parseIdent();
1459 } else {
1460 this$1.checkUnreserved(node$2.imported);
1461 node$2.local = node$2.imported;
1462 }
1463 this$1.checkLVal(node$2.local, "let");
1464 nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
1465 }
1466 return nodes
1467};
1468
1469var pp$2 = Parser.prototype;
1470
1471// Convert existing expression atom to assignable pattern
1472// if possible.
1473
1474pp$2.toAssignable = function(node, isBinding) {
1475 var this$1 = this;
1476
1477 if (this.options.ecmaVersion >= 6 && node) {
1478 switch (node.type) {
1479 case "Identifier":
1480 if (this.inAsync && node.name === "await")
1481 { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
1482 break
1483
1484 case "ObjectPattern":
1485 case "ArrayPattern":
1486 break
1487
1488 case "ObjectExpression":
1489 node.type = "ObjectPattern";
1490 for (var i = 0, list = node.properties; i < list.length; i += 1) {
1491 var prop = list[i];
1492
1493 if (prop.kind !== "init") { this$1.raise(prop.key.start, "Object pattern can't contain getter or setter"); }
1494 this$1.toAssignable(prop.value, isBinding);
1495 }
1496 break
1497
1498 case "ArrayExpression":
1499 node.type = "ArrayPattern";
1500 this.toAssignableList(node.elements, isBinding);
1501 break
1502
1503 case "AssignmentExpression":
1504 if (node.operator === "=") {
1505 node.type = "AssignmentPattern";
1506 delete node.operator;
1507 this.toAssignable(node.left, isBinding);
1508 // falls through to AssignmentPattern
1509 } else {
1510 this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
1511 break
1512 }
1513
1514 case "AssignmentPattern":
1515 break
1516
1517 case "ParenthesizedExpression":
1518 this.toAssignable(node.expression, isBinding);
1519 break
1520
1521 case "MemberExpression":
1522 if (!isBinding) { break }
1523
1524 default:
1525 this.raise(node.start, "Assigning to rvalue");
1526 }
1527 }
1528 return node
1529};
1530
1531// Convert list of expression atoms to binding list.
1532
1533pp$2.toAssignableList = function(exprList, isBinding) {
1534 var this$1 = this;
1535
1536 var end = exprList.length;
1537 if (end) {
1538 var last = exprList[end - 1];
1539 if (last && last.type == "RestElement") {
1540 --end;
1541 } else if (last && last.type == "SpreadElement") {
1542 last.type = "RestElement";
1543 var arg = last.argument;
1544 this.toAssignable(arg, isBinding);
1545 --end;
1546 }
1547
1548 if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
1549 { this.unexpected(last.argument.start); }
1550 }
1551 for (var i = 0; i < end; i++) {
1552 var elt = exprList[i];
1553 if (elt) { this$1.toAssignable(elt, isBinding); }
1554 }
1555 return exprList
1556};
1557
1558// Parses spread element.
1559
1560pp$2.parseSpread = function(refDestructuringErrors) {
1561 var node = this.startNode();
1562 this.next();
1563 node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
1564 return this.finishNode(node, "SpreadElement")
1565};
1566
1567pp$2.parseRestBinding = function() {
1568 var node = this.startNode();
1569 this.next();
1570
1571 // RestElement inside of a function parameter must be an identifier
1572 if (this.options.ecmaVersion === 6 && this.type !== types.name)
1573 { this.unexpected(); }
1574
1575 node.argument = this.parseBindingAtom();
1576
1577 return this.finishNode(node, "RestElement")
1578};
1579
1580// Parses lvalue (assignable) atom.
1581
1582pp$2.parseBindingAtom = function() {
1583 if (this.options.ecmaVersion < 6) { return this.parseIdent() }
1584 switch (this.type) {
1585 case types.name:
1586 return this.parseIdent()
1587
1588 case types.bracketL:
1589 var node = this.startNode();
1590 this.next();
1591 node.elements = this.parseBindingList(types.bracketR, true, true);
1592 return this.finishNode(node, "ArrayPattern")
1593
1594 case types.braceL:
1595 return this.parseObj(true)
1596
1597 default:
1598 this.unexpected();
1599 }
1600};
1601
1602pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
1603 var this$1 = this;
1604
1605 var elts = [], first = true;
1606 while (!this.eat(close)) {
1607 if (first) { first = false; }
1608 else { this$1.expect(types.comma); }
1609 if (allowEmpty && this$1.type === types.comma) {
1610 elts.push(null);
1611 } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
1612 break
1613 } else if (this$1.type === types.ellipsis) {
1614 var rest = this$1.parseRestBinding();
1615 this$1.parseBindingListItem(rest);
1616 elts.push(rest);
1617 if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
1618 this$1.expect(close);
1619 break
1620 } else {
1621 var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
1622 this$1.parseBindingListItem(elem);
1623 elts.push(elem);
1624 }
1625 }
1626 return elts
1627};
1628
1629pp$2.parseBindingListItem = function(param) {
1630 return param
1631};
1632
1633// Parses assignment pattern around given atom if possible.
1634
1635pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
1636 left = left || this.parseBindingAtom();
1637 if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
1638 var node = this.startNodeAt(startPos, startLoc);
1639 node.left = left;
1640 node.right = this.parseMaybeAssign();
1641 return this.finishNode(node, "AssignmentPattern")
1642};
1643
1644// Verify that a node is an lval — something that can be assigned
1645// to.
1646// bindingType can be either:
1647// 'var' indicating that the lval creates a 'var' binding
1648// 'let' indicating that the lval creates a lexical ('let' or 'const') binding
1649// 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
1650
1651pp$2.checkLVal = function(expr, bindingType, checkClashes) {
1652 var this$1 = this;
1653
1654 switch (expr.type) {
1655 case "Identifier":
1656 if (this.strict && this.reservedWordsStrictBind.test(expr.name))
1657 { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
1658 if (checkClashes) {
1659 if (has(checkClashes, expr.name))
1660 { this.raiseRecoverable(expr.start, "Argument name clash"); }
1661 checkClashes[expr.name] = true;
1662 }
1663 if (bindingType && bindingType !== "none") {
1664 if (
1665 bindingType === "var" && !this.canDeclareVarName(expr.name) ||
1666 bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
1667 ) {
1668 this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
1669 }
1670 if (bindingType === "var") {
1671 this.declareVarName(expr.name);
1672 } else {
1673 this.declareLexicalName(expr.name);
1674 }
1675 }
1676 break
1677
1678 case "MemberExpression":
1679 if (bindingType) { this.raiseRecoverable(expr.start, (bindingType ? "Binding" : "Assigning to") + " member expression"); }
1680 break
1681
1682 case "ObjectPattern":
1683 for (var i = 0, list = expr.properties; i < list.length; i += 1)
1684 {
1685 var prop = list[i];
1686
1687 this$1.checkLVal(prop.value, bindingType, checkClashes);
1688 }
1689 break
1690
1691 case "ArrayPattern":
1692 for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
1693 var elem = list$1[i$1];
1694
1695 if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
1696 }
1697 break
1698
1699 case "AssignmentPattern":
1700 this.checkLVal(expr.left, bindingType, checkClashes);
1701 break
1702
1703 case "RestElement":
1704 this.checkLVal(expr.argument, bindingType, checkClashes);
1705 break
1706
1707 case "ParenthesizedExpression":
1708 this.checkLVal(expr.expression, bindingType, checkClashes);
1709 break
1710
1711 default:
1712 this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
1713 }
1714};
1715
1716// A recursive descent parser operates by defining functions for all
1717// syntactic elements, and recursively calling those, each function
1718// advancing the input stream and returning an AST node. Precedence
1719// of constructs (for example, the fact that `!x[1]` means `!(x[1])`
1720// instead of `(!x)[1]` is handled by the fact that the parser
1721// function that parses unary prefix operators is called first, and
1722// in turn calls the function that parses `[]` subscripts — that
1723// way, it'll receive the node for `x[1]` already parsed, and wraps
1724// *that* in the unary operator node.
1725//
1726// Acorn uses an [operator precedence parser][opp] to handle binary
1727// operator precedence, because it is much more compact than using
1728// the technique outlined above, which uses different, nesting
1729// functions to specify precedence, for all of the ten binary
1730// precedence levels that JavaScript defines.
1731//
1732// [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
1733
1734var pp$3 = Parser.prototype;
1735
1736// Check if property name clashes with already added.
1737// Object/class getters and setters are not allowed to clash —
1738// either with each other or with an init property — and in
1739// strict mode, init properties are also not allowed to be repeated.
1740
1741pp$3.checkPropClash = function(prop, propHash) {
1742 if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
1743 { return }
1744 var key = prop.key;
1745 var name;
1746 switch (key.type) {
1747 case "Identifier": name = key.name; break
1748 case "Literal": name = String(key.value); break
1749 default: return
1750 }
1751 var kind = prop.kind;
1752 if (this.options.ecmaVersion >= 6) {
1753 if (name === "__proto__" && kind === "init") {
1754 if (propHash.proto) { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
1755 propHash.proto = true;
1756 }
1757 return
1758 }
1759 name = "$" + name;
1760 var other = propHash[name];
1761 if (other) {
1762 var redefinition;
1763 if (kind === "init") {
1764 redefinition = this.strict && other.init || other.get || other.set;
1765 } else {
1766 redefinition = other.init || other[kind];
1767 }
1768 if (redefinition)
1769 { this.raiseRecoverable(key.start, "Redefinition of property"); }
1770 } else {
1771 other = propHash[name] = {
1772 init: false,
1773 get: false,
1774 set: false
1775 };
1776 }
1777 other[kind] = true;
1778};
1779
1780// ### Expression parsing
1781
1782// These nest, from the most general expression type at the top to
1783// 'atomic', nondivisible expression types at the bottom. Most of
1784// the functions will simply let the function(s) below them parse,
1785// and, *if* the syntactic construct they handle is present, wrap
1786// the AST node that the inner parser gave them in another node.
1787
1788// Parse a full expression. The optional arguments are used to
1789// forbid the `in` operator (in for loops initalization expressions)
1790// and provide reference for storing '=' operator inside shorthand
1791// property assignment in contexts where both object expression
1792// and object pattern might appear (so it's possible to raise
1793// delayed syntax error at correct position).
1794
1795pp$3.parseExpression = function(noIn, refDestructuringErrors) {
1796 var this$1 = this;
1797
1798 var startPos = this.start, startLoc = this.startLoc;
1799 var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
1800 if (this.type === types.comma) {
1801 var node = this.startNodeAt(startPos, startLoc);
1802 node.expressions = [expr];
1803 while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
1804 return this.finishNode(node, "SequenceExpression")
1805 }
1806 return expr
1807};
1808
1809// Parse an assignment expression. This includes applications of
1810// operators like `+=`.
1811
1812pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
1813 if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
1814
1815 var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
1816 if (refDestructuringErrors) {
1817 oldParenAssign = refDestructuringErrors.parenthesizedAssign;
1818 oldTrailingComma = refDestructuringErrors.trailingComma;
1819 refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
1820 } else {
1821 refDestructuringErrors = new DestructuringErrors;
1822 ownDestructuringErrors = true;
1823 }
1824
1825 var startPos = this.start, startLoc = this.startLoc;
1826 if (this.type == types.parenL || this.type == types.name)
1827 { this.potentialArrowAt = this.start; }
1828 var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
1829 if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
1830 if (this.type.isAssign) {
1831 this.checkPatternErrors(refDestructuringErrors, true);
1832 if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
1833 var node = this.startNodeAt(startPos, startLoc);
1834 node.operator = this.value;
1835 node.left = this.type === types.eq ? this.toAssignable(left) : left;
1836 refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
1837 this.checkLVal(left);
1838 this.next();
1839 node.right = this.parseMaybeAssign(noIn);
1840 return this.finishNode(node, "AssignmentExpression")
1841 } else {
1842 if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
1843 }
1844 if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
1845 if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
1846 return left
1847};
1848
1849// Parse a ternary conditional (`?:`) operator.
1850
1851pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
1852 var startPos = this.start, startLoc = this.startLoc;
1853 var expr = this.parseExprOps(noIn, refDestructuringErrors);
1854 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1855 if (this.eat(types.question)) {
1856 var node = this.startNodeAt(startPos, startLoc);
1857 node.test = expr;
1858 node.consequent = this.parseMaybeAssign();
1859 this.expect(types.colon);
1860 node.alternate = this.parseMaybeAssign(noIn);
1861 return this.finishNode(node, "ConditionalExpression")
1862 }
1863 return expr
1864};
1865
1866// Start the precedence parser.
1867
1868pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
1869 var startPos = this.start, startLoc = this.startLoc;
1870 var expr = this.parseMaybeUnary(refDestructuringErrors, false);
1871 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1872 return expr.start == startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
1873};
1874
1875// Parse binary operators with the operator precedence parsing
1876// algorithm. `left` is the left-hand side of the operator.
1877// `minPrec` provides context that allows the function to stop and
1878// defer further parser to one of its callers when it encounters an
1879// operator that has a lower precedence than the set it is parsing.
1880
1881pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
1882 var prec = this.type.binop;
1883 if (prec != null && (!noIn || this.type !== types._in)) {
1884 if (prec > minPrec) {
1885 var logical = this.type === types.logicalOR || this.type === types.logicalAND;
1886 var op = this.value;
1887 this.next();
1888 var startPos = this.start, startLoc = this.startLoc;
1889 var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
1890 var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
1891 return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
1892 }
1893 }
1894 return left
1895};
1896
1897pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
1898 var node = this.startNodeAt(startPos, startLoc);
1899 node.left = left;
1900 node.operator = op;
1901 node.right = right;
1902 return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
1903};
1904
1905// Parse unary operators, both prefix and postfix.
1906
1907pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
1908 var this$1 = this;
1909
1910 var startPos = this.start, startLoc = this.startLoc, expr;
1911 if (this.inAsync && this.isContextual("await")) {
1912 expr = this.parseAwait(refDestructuringErrors);
1913 sawUnary = true;
1914 } else if (this.type.prefix) {
1915 var node = this.startNode(), update = this.type === types.incDec;
1916 node.operator = this.value;
1917 node.prefix = true;
1918 this.next();
1919 node.argument = this.parseMaybeUnary(null, true);
1920 this.checkExpressionErrors(refDestructuringErrors, true);
1921 if (update) { this.checkLVal(node.argument); }
1922 else if (this.strict && node.operator === "delete" &&
1923 node.argument.type === "Identifier")
1924 { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
1925 else { sawUnary = true; }
1926 expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
1927 } else {
1928 expr = this.parseExprSubscripts(refDestructuringErrors);
1929 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1930 while (this.type.postfix && !this.canInsertSemicolon()) {
1931 var node$1 = this$1.startNodeAt(startPos, startLoc);
1932 node$1.operator = this$1.value;
1933 node$1.prefix = false;
1934 node$1.argument = expr;
1935 this$1.checkLVal(expr);
1936 this$1.next();
1937 expr = this$1.finishNode(node$1, "UpdateExpression");
1938 }
1939 }
1940
1941 if (!sawUnary && this.eat(types.starstar))
1942 { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
1943 else
1944 { return expr }
1945};
1946
1947// Parse call, dot, and `[]`-subscript expressions.
1948
1949pp$3.parseExprSubscripts = function(refDestructuringErrors) {
1950 var startPos = this.start, startLoc = this.startLoc;
1951 var expr = this.parseExprAtom(refDestructuringErrors);
1952 var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
1953 if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
1954 var result = this.parseSubscripts(expr, startPos, startLoc);
1955 if (refDestructuringErrors && result.type === "MemberExpression") {
1956 if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
1957 if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
1958 }
1959 return result
1960};
1961
1962pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
1963 var this$1 = this;
1964
1965 var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
1966 this.lastTokEnd == base.end && !this.canInsertSemicolon();
1967 for (var computed = (void 0);;) {
1968 if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
1969 var node = this$1.startNodeAt(startPos, startLoc);
1970 node.object = base;
1971 node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
1972 node.computed = !!computed;
1973 if (computed) { this$1.expect(types.bracketR); }
1974 base = this$1.finishNode(node, "MemberExpression");
1975 } else if (!noCalls && this$1.eat(types.parenL)) {
1976 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
1977 this$1.yieldPos = 0;
1978 this$1.awaitPos = 0;
1979 var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
1980 if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
1981 this$1.checkPatternErrors(refDestructuringErrors, false);
1982 this$1.checkYieldAwaitInDefaultParams();
1983 this$1.yieldPos = oldYieldPos;
1984 this$1.awaitPos = oldAwaitPos;
1985 return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
1986 }
1987 this$1.checkExpressionErrors(refDestructuringErrors, true);
1988 this$1.yieldPos = oldYieldPos || this$1.yieldPos;
1989 this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
1990 var node$1 = this$1.startNodeAt(startPos, startLoc);
1991 node$1.callee = base;
1992 node$1.arguments = exprList;
1993 base = this$1.finishNode(node$1, "CallExpression");
1994 } else if (this$1.type === types.backQuote) {
1995 var node$2 = this$1.startNodeAt(startPos, startLoc);
1996 node$2.tag = base;
1997 node$2.quasi = this$1.parseTemplate({isTagged: true});
1998 base = this$1.finishNode(node$2, "TaggedTemplateExpression");
1999 } else {
2000 return base
2001 }
2002 }
2003};
2004
2005// Parse an atomic expression — either a single token that is an
2006// expression, an expression started by a keyword like `function` or
2007// `new`, or an expression wrapped in punctuation like `()`, `[]`,
2008// or `{}`.
2009
2010pp$3.parseExprAtom = function(refDestructuringErrors) {
2011 var node, canBeArrow = this.potentialArrowAt == this.start;
2012 switch (this.type) {
2013 case types._super:
2014 if (!this.inFunction)
2015 { this.raise(this.start, "'super' outside of function or class"); }
2016
2017 case types._this:
2018 var type = this.type === types._this ? "ThisExpression" : "Super";
2019 node = this.startNode();
2020 this.next();
2021 return this.finishNode(node, type)
2022
2023 case types.name:
2024 var startPos = this.start, startLoc = this.startLoc;
2025 var id = this.parseIdent(this.type !== types.name);
2026 if (this.options.ecmaVersion >= 8 && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
2027 { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
2028 if (canBeArrow && !this.canInsertSemicolon()) {
2029 if (this.eat(types.arrow))
2030 { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
2031 if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name) {
2032 id = this.parseIdent();
2033 if (this.canInsertSemicolon() || !this.eat(types.arrow))
2034 { this.unexpected(); }
2035 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
2036 }
2037 }
2038 return id
2039
2040 case types.regexp:
2041 var value = this.value;
2042 node = this.parseLiteral(value.value);
2043 node.regex = {pattern: value.pattern, flags: value.flags};
2044 return node
2045
2046 case types.num: case types.string:
2047 return this.parseLiteral(this.value)
2048
2049 case types._null: case types._true: case types._false:
2050 node = this.startNode();
2051 node.value = this.type === types._null ? null : this.type === types._true;
2052 node.raw = this.type.keyword;
2053 this.next();
2054 return this.finishNode(node, "Literal")
2055
2056 case types.parenL:
2057 var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
2058 if (refDestructuringErrors) {
2059 if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
2060 { refDestructuringErrors.parenthesizedAssign = start; }
2061 if (refDestructuringErrors.parenthesizedBind < 0)
2062 { refDestructuringErrors.parenthesizedBind = start; }
2063 }
2064 return expr
2065
2066 case types.bracketL:
2067 node = this.startNode();
2068 this.next();
2069 node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
2070 return this.finishNode(node, "ArrayExpression")
2071
2072 case types.braceL:
2073 return this.parseObj(false, refDestructuringErrors)
2074
2075 case types._function:
2076 node = this.startNode();
2077 this.next();
2078 return this.parseFunction(node, false)
2079
2080 case types._class:
2081 return this.parseClass(this.startNode(), false)
2082
2083 case types._new:
2084 return this.parseNew()
2085
2086 case types.backQuote:
2087 return this.parseTemplate()
2088
2089 default:
2090 this.unexpected();
2091 }
2092};
2093
2094pp$3.parseLiteral = function(value) {
2095 var node = this.startNode();
2096 node.value = value;
2097 node.raw = this.input.slice(this.start, this.end);
2098 this.next();
2099 return this.finishNode(node, "Literal")
2100};
2101
2102pp$3.parseParenExpression = function() {
2103 this.expect(types.parenL);
2104 var val = this.parseExpression();
2105 this.expect(types.parenR);
2106 return val
2107};
2108
2109pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
2110 var this$1 = this;
2111
2112 var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
2113 if (this.options.ecmaVersion >= 6) {
2114 this.next();
2115
2116 var innerStartPos = this.start, innerStartLoc = this.startLoc;
2117 var exprList = [], first = true, lastIsComma = false;
2118 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart, innerParenStart;
2119 this.yieldPos = 0;
2120 this.awaitPos = 0;
2121 while (this.type !== types.parenR) {
2122 first ? first = false : this$1.expect(types.comma);
2123 if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
2124 lastIsComma = true;
2125 break
2126 } else if (this$1.type === types.ellipsis) {
2127 spreadStart = this$1.start;
2128 exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
2129 if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
2130 break
2131 } else {
2132 if (this$1.type === types.parenL && !innerParenStart) {
2133 innerParenStart = this$1.start;
2134 }
2135 exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
2136 }
2137 }
2138 var innerEndPos = this.start, innerEndLoc = this.startLoc;
2139 this.expect(types.parenR);
2140
2141 if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2142 this.checkPatternErrors(refDestructuringErrors, false);
2143 this.checkYieldAwaitInDefaultParams();
2144 if (innerParenStart) { this.unexpected(innerParenStart); }
2145 this.yieldPos = oldYieldPos;
2146 this.awaitPos = oldAwaitPos;
2147 return this.parseParenArrowList(startPos, startLoc, exprList)
2148 }
2149
2150 if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
2151 if (spreadStart) { this.unexpected(spreadStart); }
2152 this.checkExpressionErrors(refDestructuringErrors, true);
2153 this.yieldPos = oldYieldPos || this.yieldPos;
2154 this.awaitPos = oldAwaitPos || this.awaitPos;
2155
2156 if (exprList.length > 1) {
2157 val = this.startNodeAt(innerStartPos, innerStartLoc);
2158 val.expressions = exprList;
2159 this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
2160 } else {
2161 val = exprList[0];
2162 }
2163 } else {
2164 val = this.parseParenExpression();
2165 }
2166
2167 if (this.options.preserveParens) {
2168 var par = this.startNodeAt(startPos, startLoc);
2169 par.expression = val;
2170 return this.finishNode(par, "ParenthesizedExpression")
2171 } else {
2172 return val
2173 }
2174};
2175
2176pp$3.parseParenItem = function(item) {
2177 return item
2178};
2179
2180pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
2181 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
2182};
2183
2184// New's precedence is slightly tricky. It must allow its argument to
2185// be a `[]` or dot subscript expression, but not a call — at least,
2186// not without wrapping it in parentheses. Thus, it uses the noCalls
2187// argument to parseSubscripts to prevent it from consuming the
2188// argument list.
2189
2190var empty$1 = [];
2191
2192pp$3.parseNew = function() {
2193 var node = this.startNode();
2194 var meta = this.parseIdent(true);
2195 if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
2196 node.meta = meta;
2197 node.property = this.parseIdent(true);
2198 if (node.property.name !== "target")
2199 { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
2200 if (!this.inFunction)
2201 { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
2202 return this.finishNode(node, "MetaProperty")
2203 }
2204 var startPos = this.start, startLoc = this.startLoc;
2205 node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
2206 if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
2207 else { node.arguments = empty$1; }
2208 return this.finishNode(node, "NewExpression")
2209};
2210
2211// Parse template expression.
2212
2213pp$3.parseTemplateElement = function(ref) {
2214 var isTagged = ref.isTagged;
2215
2216 var elem = this.startNode();
2217 if (this.type === types.invalidTemplate) {
2218 if (!isTagged) {
2219 this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
2220 }
2221 elem.value = {
2222 raw: this.value,
2223 cooked: null
2224 };
2225 } else {
2226 elem.value = {
2227 raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
2228 cooked: this.value
2229 };
2230 }
2231 this.next();
2232 elem.tail = this.type === types.backQuote;
2233 return this.finishNode(elem, "TemplateElement")
2234};
2235
2236pp$3.parseTemplate = function(ref) {
2237 var this$1 = this;
2238 if ( ref === void 0 ) ref = {};
2239 var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
2240
2241 var node = this.startNode();
2242 this.next();
2243 node.expressions = [];
2244 var curElt = this.parseTemplateElement({isTagged: isTagged});
2245 node.quasis = [curElt];
2246 while (!curElt.tail) {
2247 this$1.expect(types.dollarBraceL);
2248 node.expressions.push(this$1.parseExpression());
2249 this$1.expect(types.braceR);
2250 node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
2251 }
2252 this.next();
2253 return this.finishNode(node, "TemplateLiteral")
2254};
2255
2256// Parse an object literal or binding pattern.
2257
2258pp$3.isAsyncProp = function(prop) {
2259 return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
2260 (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword) &&
2261 !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
2262};
2263
2264pp$3.parseObj = function(isPattern, refDestructuringErrors) {
2265 var this$1 = this;
2266
2267 var node = this.startNode(), first = true, propHash = {};
2268 node.properties = [];
2269 this.next();
2270 while (!this.eat(types.braceR)) {
2271 if (!first) {
2272 this$1.expect(types.comma);
2273 if (this$1.afterTrailingComma(types.braceR)) { break }
2274 } else { first = false; }
2275
2276 var prop = this$1.startNode(), isGenerator = (void 0), isAsync = (void 0), startPos = (void 0), startLoc = (void 0);
2277 if (this$1.options.ecmaVersion >= 6) {
2278 prop.method = false;
2279 prop.shorthand = false;
2280 if (isPattern || refDestructuringErrors) {
2281 startPos = this$1.start;
2282 startLoc = this$1.startLoc;
2283 }
2284 if (!isPattern)
2285 { isGenerator = this$1.eat(types.star); }
2286 }
2287 this$1.parsePropertyName(prop);
2288 if (!isPattern && this$1.options.ecmaVersion >= 8 && !isGenerator && this$1.isAsyncProp(prop)) {
2289 isAsync = true;
2290 this$1.parsePropertyName(prop, refDestructuringErrors);
2291 } else {
2292 isAsync = false;
2293 }
2294 this$1.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
2295 this$1.checkPropClash(prop, propHash);
2296 node.properties.push(this$1.finishNode(prop, "Property"));
2297 }
2298 return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
2299};
2300
2301pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) {
2302 if ((isGenerator || isAsync) && this.type === types.colon)
2303 { this.unexpected(); }
2304
2305 if (this.eat(types.colon)) {
2306 prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
2307 prop.kind = "init";
2308 } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
2309 if (isPattern) { this.unexpected(); }
2310 prop.kind = "init";
2311 prop.method = true;
2312 prop.value = this.parseMethod(isGenerator, isAsync);
2313 } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
2314 (prop.key.name === "get" || prop.key.name === "set") &&
2315 (this.type != types.comma && this.type != types.braceR)) {
2316 if (isGenerator || isAsync || isPattern) { this.unexpected(); }
2317 prop.kind = prop.key.name;
2318 this.parsePropertyName(prop);
2319 prop.value = this.parseMethod(false);
2320 var paramCount = prop.kind === "get" ? 0 : 1;
2321 if (prop.value.params.length !== paramCount) {
2322 var start = prop.value.start;
2323 if (prop.kind === "get")
2324 { this.raiseRecoverable(start, "getter should have no params"); }
2325 else
2326 { this.raiseRecoverable(start, "setter should have exactly one param"); }
2327 } else {
2328 if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
2329 { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
2330 }
2331 } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
2332 this.checkUnreserved(prop.key);
2333 prop.kind = "init";
2334 if (isPattern) {
2335 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2336 } else if (this.type === types.eq && refDestructuringErrors) {
2337 if (refDestructuringErrors.shorthandAssign < 0)
2338 { refDestructuringErrors.shorthandAssign = this.start; }
2339 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2340 } else {
2341 prop.value = prop.key;
2342 }
2343 prop.shorthand = true;
2344 } else { this.unexpected(); }
2345};
2346
2347pp$3.parsePropertyName = function(prop) {
2348 if (this.options.ecmaVersion >= 6) {
2349 if (this.eat(types.bracketL)) {
2350 prop.computed = true;
2351 prop.key = this.parseMaybeAssign();
2352 this.expect(types.bracketR);
2353 return prop.key
2354 } else {
2355 prop.computed = false;
2356 }
2357 }
2358 return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
2359};
2360
2361// Initialize empty function node.
2362
2363pp$3.initFunction = function(node) {
2364 node.id = null;
2365 if (this.options.ecmaVersion >= 6) {
2366 node.generator = false;
2367 node.expression = false;
2368 }
2369 if (this.options.ecmaVersion >= 8)
2370 { node.async = false; }
2371};
2372
2373// Parse object or class method.
2374
2375pp$3.parseMethod = function(isGenerator, isAsync) {
2376 var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
2377 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
2378
2379 this.initFunction(node);
2380 if (this.options.ecmaVersion >= 6)
2381 { node.generator = isGenerator; }
2382 if (this.options.ecmaVersion >= 8)
2383 { node.async = !!isAsync; }
2384
2385 this.inGenerator = node.generator;
2386 this.inAsync = node.async;
2387 this.yieldPos = 0;
2388 this.awaitPos = 0;
2389 this.inFunction = true;
2390 this.enterFunctionScope();
2391
2392 this.expect(types.parenL);
2393 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
2394 this.checkYieldAwaitInDefaultParams();
2395 this.parseFunctionBody(node, false);
2396
2397 this.inGenerator = oldInGen;
2398 this.inAsync = oldInAsync;
2399 this.yieldPos = oldYieldPos;
2400 this.awaitPos = oldAwaitPos;
2401 this.inFunction = oldInFunc;
2402 return this.finishNode(node, "FunctionExpression")
2403};
2404
2405// Parse arrow function expression with given parameters.
2406
2407pp$3.parseArrowExpression = function(node, params, isAsync) {
2408 var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
2409 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
2410
2411 this.enterFunctionScope();
2412 this.initFunction(node);
2413 if (this.options.ecmaVersion >= 8)
2414 { node.async = !!isAsync; }
2415
2416 this.inGenerator = false;
2417 this.inAsync = node.async;
2418 this.yieldPos = 0;
2419 this.awaitPos = 0;
2420 this.inFunction = true;
2421
2422 node.params = this.toAssignableList(params, true);
2423 this.parseFunctionBody(node, true);
2424
2425 this.inGenerator = oldInGen;
2426 this.inAsync = oldInAsync;
2427 this.yieldPos = oldYieldPos;
2428 this.awaitPos = oldAwaitPos;
2429 this.inFunction = oldInFunc;
2430 return this.finishNode(node, "ArrowFunctionExpression")
2431};
2432
2433// Parse function body and check parameters.
2434
2435pp$3.parseFunctionBody = function(node, isArrowFunction) {
2436 var isExpression = isArrowFunction && this.type !== types.braceL;
2437 var oldStrict = this.strict, useStrict = false;
2438
2439 if (isExpression) {
2440 node.body = this.parseMaybeAssign();
2441 node.expression = true;
2442 this.checkParams(node, false);
2443 } else {
2444 var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
2445 if (!oldStrict || nonSimple) {
2446 useStrict = this.strictDirective(this.end);
2447 // If this is a strict mode function, verify that argument names
2448 // are not repeated, and it does not try to bind the words `eval`
2449 // or `arguments`.
2450 if (useStrict && nonSimple)
2451 { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
2452 }
2453 // Start a new scope with regard to labels and the `inFunction`
2454 // flag (restore them to their old value afterwards).
2455 var oldLabels = this.labels;
2456 this.labels = [];
2457 if (useStrict) { this.strict = true; }
2458
2459 // Add the params to varDeclaredNames to ensure that an error is thrown
2460 // if a let/const declaration in the function clashes with one of the params.
2461 this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
2462 node.body = this.parseBlock(false);
2463 node.expression = false;
2464 this.labels = oldLabels;
2465 }
2466 this.exitFunctionScope();
2467
2468 if (this.strict && node.id) {
2469 // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
2470 this.checkLVal(node.id, "none");
2471 }
2472 this.strict = oldStrict;
2473};
2474
2475pp$3.isSimpleParamList = function(params) {
2476 for (var i = 0, list = params; i < list.length; i += 1)
2477 {
2478 var param = list[i];
2479
2480 if (param.type !== "Identifier") { return false
2481 } }
2482 return true
2483};
2484
2485// Checks function params for various disallowed patterns such as using "eval"
2486// or "arguments" and duplicate parameters.
2487
2488pp$3.checkParams = function(node, allowDuplicates) {
2489 var this$1 = this;
2490
2491 var nameHash = {};
2492 for (var i = 0, list = node.params; i < list.length; i += 1)
2493 {
2494 var param = list[i];
2495
2496 this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
2497 }
2498};
2499
2500// Parses a comma-separated list of expressions, and returns them as
2501// an array. `close` is the token type that ends the list, and
2502// `allowEmpty` can be turned on to allow subsequent commas with
2503// nothing in between them to be parsed as `null` (which is needed
2504// for array literals).
2505
2506pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
2507 var this$1 = this;
2508
2509 var elts = [], first = true;
2510 while (!this.eat(close)) {
2511 if (!first) {
2512 this$1.expect(types.comma);
2513 if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
2514 } else { first = false; }
2515
2516 var elt = (void 0);
2517 if (allowEmpty && this$1.type === types.comma)
2518 { elt = null; }
2519 else if (this$1.type === types.ellipsis) {
2520 elt = this$1.parseSpread(refDestructuringErrors);
2521 if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
2522 { refDestructuringErrors.trailingComma = this$1.start; }
2523 } else {
2524 elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
2525 }
2526 elts.push(elt);
2527 }
2528 return elts
2529};
2530
2531// Parse the next token as an identifier. If `liberal` is true (used
2532// when parsing properties), it will also convert keywords into
2533// identifiers.
2534
2535pp$3.checkUnreserved = function(ref) {
2536 var start = ref.start;
2537 var end = ref.end;
2538 var name = ref.name;
2539
2540 if (this.inGenerator && name === "yield")
2541 { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
2542 if (this.inAsync && name === "await")
2543 { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
2544 if (this.isKeyword(name))
2545 { this.raise(start, ("Unexpected keyword '" + name + "'")); }
2546 if (this.options.ecmaVersion < 6 &&
2547 this.input.slice(start, end).indexOf("\\") != -1) { return }
2548 var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
2549 if (re.test(name))
2550 { this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved")); }
2551};
2552
2553pp$3.parseIdent = function(liberal, isBinding) {
2554 var node = this.startNode();
2555 if (liberal && this.options.allowReserved == "never") { liberal = false; }
2556 if (this.type === types.name) {
2557 node.name = this.value;
2558 } else if (this.type.keyword) {
2559 node.name = this.type.keyword;
2560 } else {
2561 this.unexpected();
2562 }
2563 this.next();
2564 this.finishNode(node, "Identifier");
2565 if (!liberal) { this.checkUnreserved(node); }
2566 return node
2567};
2568
2569// Parses yield expression inside generator.
2570
2571pp$3.parseYield = function() {
2572 if (!this.yieldPos) { this.yieldPos = this.start; }
2573
2574 var node = this.startNode();
2575 this.next();
2576 if (this.type == types.semi || this.canInsertSemicolon() || (this.type != types.star && !this.type.startsExpr)) {
2577 node.delegate = false;
2578 node.argument = null;
2579 } else {
2580 node.delegate = this.eat(types.star);
2581 node.argument = this.parseMaybeAssign();
2582 }
2583 return this.finishNode(node, "YieldExpression")
2584};
2585
2586pp$3.parseAwait = function() {
2587 if (!this.awaitPos) { this.awaitPos = this.start; }
2588
2589 var node = this.startNode();
2590 this.next();
2591 node.argument = this.parseMaybeUnary(null, true);
2592 return this.finishNode(node, "AwaitExpression")
2593};
2594
2595var pp$4 = Parser.prototype;
2596
2597// This function is used to raise exceptions on parse errors. It
2598// takes an offset integer (into the current `input`) to indicate
2599// the location of the error, attaches the position to the end
2600// of the error message, and then raises a `SyntaxError` with that
2601// message.
2602
2603pp$4.raise = function(pos, message) {
2604 var loc = getLineInfo(this.input, pos);
2605 message += " (" + loc.line + ":" + loc.column + ")";
2606 var err = new SyntaxError(message);
2607 err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
2608 throw err
2609};
2610
2611pp$4.raiseRecoverable = pp$4.raise;
2612
2613pp$4.curPosition = function() {
2614 if (this.options.locations) {
2615 return new Position(this.curLine, this.pos - this.lineStart)
2616 }
2617};
2618
2619var pp$5 = Parser.prototype;
2620
2621// Object.assign polyfill
2622var assign = Object.assign || function(target) {
2623 var sources = [], len = arguments.length - 1;
2624 while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
2625
2626 for (var i = 0, list = sources; i < list.length; i += 1) {
2627 var source = list[i];
2628
2629 for (var key in source) {
2630 if (has(source, key)) {
2631 target[key] = source[key];
2632 }
2633 }
2634 }
2635 return target
2636};
2637
2638// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
2639
2640pp$5.enterFunctionScope = function() {
2641 // var: a hash of var-declared names in the current lexical scope
2642 // lexical: a hash of lexically-declared names in the current lexical scope
2643 // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
2644 // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
2645 this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
2646};
2647
2648pp$5.exitFunctionScope = function() {
2649 this.scopeStack.pop();
2650};
2651
2652pp$5.enterLexicalScope = function() {
2653 var parentScope = this.scopeStack[this.scopeStack.length - 1];
2654 var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
2655
2656 this.scopeStack.push(childScope);
2657 assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
2658};
2659
2660pp$5.exitLexicalScope = function() {
2661 var childScope = this.scopeStack.pop();
2662 var parentScope = this.scopeStack[this.scopeStack.length - 1];
2663
2664 assign(parentScope.childVar, childScope.var, childScope.childVar);
2665};
2666
2667/**
2668 * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
2669 * in the current lexical scope or any of the parent lexical scopes in this function.
2670 */
2671pp$5.canDeclareVarName = function(name) {
2672 var currentScope = this.scopeStack[this.scopeStack.length - 1];
2673
2674 return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
2675};
2676
2677/**
2678 * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
2679 * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
2680 * any child lexical scopes in this function.
2681 */
2682pp$5.canDeclareLexicalName = function(name) {
2683 var currentScope = this.scopeStack[this.scopeStack.length - 1];
2684
2685 return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
2686};
2687
2688pp$5.declareVarName = function(name) {
2689 this.scopeStack[this.scopeStack.length - 1].var[name] = true;
2690};
2691
2692pp$5.declareLexicalName = function(name) {
2693 this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
2694};
2695
2696var Node = function Node(parser, pos, loc) {
2697 this.type = "";
2698 this.start = pos;
2699 this.end = 0;
2700 if (parser.options.locations)
2701 { this.loc = new SourceLocation(parser, loc); }
2702 if (parser.options.directSourceFile)
2703 { this.sourceFile = parser.options.directSourceFile; }
2704 if (parser.options.ranges)
2705 { this.range = [pos, 0]; }
2706};
2707
2708// Start an AST node, attaching a start offset.
2709
2710var pp$6 = Parser.prototype;
2711
2712pp$6.startNode = function() {
2713 return new Node(this, this.start, this.startLoc)
2714};
2715
2716pp$6.startNodeAt = function(pos, loc) {
2717 return new Node(this, pos, loc)
2718};
2719
2720// Finish an AST node, adding `type` and `end` properties.
2721
2722function finishNodeAt(node, type, pos, loc) {
2723 node.type = type;
2724 node.end = pos;
2725 if (this.options.locations)
2726 { node.loc.end = loc; }
2727 if (this.options.ranges)
2728 { node.range[1] = pos; }
2729 return node
2730}
2731
2732pp$6.finishNode = function(node, type) {
2733 return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
2734};
2735
2736// Finish node at given position
2737
2738pp$6.finishNodeAt = function(node, type, pos, loc) {
2739 return finishNodeAt.call(this, node, type, pos, loc)
2740};
2741
2742// The algorithm used to determine whether a regexp can appear at a
2743// given point in the program is loosely based on sweet.js' approach.
2744// See https://github.com/mozilla/sweet.js/wiki/design
2745
2746var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
2747 this.token = token;
2748 this.isExpr = !!isExpr;
2749 this.preserveSpace = !!preserveSpace;
2750 this.override = override;
2751 this.generator = !!generator;
2752};
2753
2754var types$1 = {
2755 b_stat: new TokContext("{", false),
2756 b_expr: new TokContext("{", true),
2757 b_tmpl: new TokContext("${", false),
2758 p_stat: new TokContext("(", false),
2759 p_expr: new TokContext("(", true),
2760 q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
2761 f_stat: new TokContext("function", false),
2762 f_expr: new TokContext("function", true),
2763 f_expr_gen: new TokContext("function", true, false, null, true),
2764 f_gen: new TokContext("function", false, false, null, true)
2765};
2766
2767var pp$7 = Parser.prototype;
2768
2769pp$7.initialContext = function() {
2770 return [types$1.b_stat]
2771};
2772
2773pp$7.braceIsBlock = function(prevType) {
2774 var parent = this.curContext();
2775 if (parent === types$1.f_expr || parent === types$1.f_stat)
2776 { return true }
2777 if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
2778 { return !parent.isExpr }
2779
2780 // The check for `tt.name && exprAllowed` detects whether we are
2781 // after a `yield` or `of` construct. See the `updateContext` for
2782 // `tt.name`.
2783 if (prevType === types._return || prevType == types.name && this.exprAllowed)
2784 { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
2785 if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType == types.arrow)
2786 { return true }
2787 if (prevType == types.braceL)
2788 { return parent === types$1.b_stat }
2789 if (prevType == types._var || prevType == types.name)
2790 { return false }
2791 return !this.exprAllowed
2792};
2793
2794pp$7.inGeneratorContext = function() {
2795 var this$1 = this;
2796
2797 for (var i = this.context.length - 1; i >= 1; i--) {
2798 var context = this$1.context[i];
2799 if (context.token === "function")
2800 { return context.generator }
2801 }
2802 return false
2803};
2804
2805pp$7.updateContext = function(prevType) {
2806 var update, type = this.type;
2807 if (type.keyword && prevType == types.dot)
2808 { this.exprAllowed = false; }
2809 else if (update = type.updateContext)
2810 { update.call(this, prevType); }
2811 else
2812 { this.exprAllowed = type.beforeExpr; }
2813};
2814
2815// Token-specific context update code
2816
2817types.parenR.updateContext = types.braceR.updateContext = function() {
2818 if (this.context.length == 1) {
2819 this.exprAllowed = true;
2820 return
2821 }
2822 var out = this.context.pop();
2823 if (out === types$1.b_stat && this.curContext().token === "function") {
2824 out = this.context.pop();
2825 }
2826 this.exprAllowed = !out.isExpr;
2827};
2828
2829types.braceL.updateContext = function(prevType) {
2830 this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
2831 this.exprAllowed = true;
2832};
2833
2834types.dollarBraceL.updateContext = function() {
2835 this.context.push(types$1.b_tmpl);
2836 this.exprAllowed = true;
2837};
2838
2839types.parenL.updateContext = function(prevType) {
2840 var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
2841 this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
2842 this.exprAllowed = true;
2843};
2844
2845types.incDec.updateContext = function() {
2846 // tokExprAllowed stays unchanged
2847};
2848
2849types._function.updateContext = types._class.updateContext = function(prevType) {
2850 if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
2851 !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
2852 { this.context.push(types$1.f_expr); }
2853 else
2854 { this.context.push(types$1.f_stat); }
2855 this.exprAllowed = false;
2856};
2857
2858types.backQuote.updateContext = function() {
2859 if (this.curContext() === types$1.q_tmpl)
2860 { this.context.pop(); }
2861 else
2862 { this.context.push(types$1.q_tmpl); }
2863 this.exprAllowed = false;
2864};
2865
2866types.star.updateContext = function(prevType) {
2867 if (prevType == types._function) {
2868 var index = this.context.length - 1;
2869 if (this.context[index] === types$1.f_expr)
2870 { this.context[index] = types$1.f_expr_gen; }
2871 else
2872 { this.context[index] = types$1.f_gen; }
2873 }
2874 this.exprAllowed = true;
2875};
2876
2877types.name.updateContext = function(prevType) {
2878 var allowed = false;
2879 if (this.options.ecmaVersion >= 6) {
2880 if (this.value == "of" && !this.exprAllowed ||
2881 this.value == "yield" && this.inGeneratorContext())
2882 { allowed = true; }
2883 }
2884 this.exprAllowed = allowed;
2885};
2886
2887// Object type used to represent tokens. Note that normally, tokens
2888// simply exist as properties on the parser object. This is only
2889// used for the onToken callback and the external tokenizer.
2890
2891var Token = function Token(p) {
2892 this.type = p.type;
2893 this.value = p.value;
2894 this.start = p.start;
2895 this.end = p.end;
2896 if (p.options.locations)
2897 { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
2898 if (p.options.ranges)
2899 { this.range = [p.start, p.end]; }
2900};
2901
2902// ## Tokenizer
2903
2904var pp$8 = Parser.prototype;
2905
2906// Are we running under Rhino?
2907var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
2908
2909// Move to the next token
2910
2911pp$8.next = function() {
2912 if (this.options.onToken)
2913 { this.options.onToken(new Token(this)); }
2914
2915 this.lastTokEnd = this.end;
2916 this.lastTokStart = this.start;
2917 this.lastTokEndLoc = this.endLoc;
2918 this.lastTokStartLoc = this.startLoc;
2919 this.nextToken();
2920};
2921
2922pp$8.getToken = function() {
2923 this.next();
2924 return new Token(this)
2925};
2926
2927// If we're in an ES6 environment, make parsers iterable
2928if (typeof Symbol !== "undefined")
2929 { pp$8[Symbol.iterator] = function() {
2930 var this$1 = this;
2931
2932 return {
2933 next: function () {
2934 var token = this$1.getToken();
2935 return {
2936 done: token.type === types.eof,
2937 value: token
2938 }
2939 }
2940 }
2941 }; }
2942
2943// Toggle strict mode. Re-reads the next number or string to please
2944// pedantic tests (`"use strict"; 010;` should fail).
2945
2946pp$8.curContext = function() {
2947 return this.context[this.context.length - 1]
2948};
2949
2950// Read a single token, updating the parser object's token-related
2951// properties.
2952
2953pp$8.nextToken = function() {
2954 var curContext = this.curContext();
2955 if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
2956
2957 this.start = this.pos;
2958 if (this.options.locations) { this.startLoc = this.curPosition(); }
2959 if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
2960
2961 if (curContext.override) { return curContext.override(this) }
2962 else { this.readToken(this.fullCharCodeAtPos()); }
2963};
2964
2965pp$8.readToken = function(code) {
2966 // Identifier or keyword. '\uXXXX' sequences are allowed in
2967 // identifiers, so '\' also dispatches to that.
2968 if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
2969 { return this.readWord() }
2970
2971 return this.getTokenFromCode(code)
2972};
2973
2974pp$8.fullCharCodeAtPos = function() {
2975 var code = this.input.charCodeAt(this.pos);
2976 if (code <= 0xd7ff || code >= 0xe000) { return code }
2977 var next = this.input.charCodeAt(this.pos + 1);
2978 return (code << 10) + next - 0x35fdc00
2979};
2980
2981pp$8.skipBlockComment = function() {
2982 var this$1 = this;
2983
2984 var startLoc = this.options.onComment && this.curPosition();
2985 var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
2986 if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
2987 this.pos = end + 2;
2988 if (this.options.locations) {
2989 lineBreakG.lastIndex = start;
2990 var match;
2991 while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
2992 ++this$1.curLine;
2993 this$1.lineStart = match.index + match[0].length;
2994 }
2995 }
2996 if (this.options.onComment)
2997 { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
2998 startLoc, this.curPosition()); }
2999};
3000
3001pp$8.skipLineComment = function(startSkip) {
3002 var this$1 = this;
3003
3004 var start = this.pos;
3005 var startLoc = this.options.onComment && this.curPosition();
3006 var ch = this.input.charCodeAt(this.pos += startSkip);
3007 while (this.pos < this.input.length && !isNewLine(ch)) {
3008 ch = this$1.input.charCodeAt(++this$1.pos);
3009 }
3010 if (this.options.onComment)
3011 { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
3012 startLoc, this.curPosition()); }
3013};
3014
3015// Called at the start of the parse and after every token. Skips
3016// whitespace and comments, and.
3017
3018pp$8.skipSpace = function() {
3019 var this$1 = this;
3020
3021 loop: while (this.pos < this.input.length) {
3022 var ch = this$1.input.charCodeAt(this$1.pos);
3023 switch (ch) {
3024 case 32: case 160: // ' '
3025 ++this$1.pos;
3026 break
3027 case 13:
3028 if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
3029 ++this$1.pos;
3030 }
3031 case 10: case 8232: case 8233:
3032 ++this$1.pos;
3033 if (this$1.options.locations) {
3034 ++this$1.curLine;
3035 this$1.lineStart = this$1.pos;
3036 }
3037 break
3038 case 47: // '/'
3039 switch (this$1.input.charCodeAt(this$1.pos + 1)) {
3040 case 42: // '*'
3041 this$1.skipBlockComment();
3042 break
3043 case 47:
3044 this$1.skipLineComment(2);
3045 break
3046 default:
3047 break loop
3048 }
3049 break
3050 default:
3051 if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
3052 ++this$1.pos;
3053 } else {
3054 break loop
3055 }
3056 }
3057 }
3058};
3059
3060// Called at the end of every token. Sets `end`, `val`, and
3061// maintains `context` and `exprAllowed`, and skips the space after
3062// the token, so that the next one's `start` will point at the
3063// right position.
3064
3065pp$8.finishToken = function(type, val) {
3066 this.end = this.pos;
3067 if (this.options.locations) { this.endLoc = this.curPosition(); }
3068 var prevType = this.type;
3069 this.type = type;
3070 this.value = val;
3071
3072 this.updateContext(prevType);
3073};
3074
3075// ### Token reading
3076
3077// This is the function that is called to fetch the next token. It
3078// is somewhat obscure, because it works in character codes rather
3079// than characters, and because operator parsing has been inlined
3080// into it.
3081//
3082// All in the name of speed.
3083//
3084pp$8.readToken_dot = function() {
3085 var next = this.input.charCodeAt(this.pos + 1);
3086 if (next >= 48 && next <= 57) { return this.readNumber(true) }
3087 var next2 = this.input.charCodeAt(this.pos + 2);
3088 if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
3089 this.pos += 3;
3090 return this.finishToken(types.ellipsis)
3091 } else {
3092 ++this.pos;
3093 return this.finishToken(types.dot)
3094 }
3095};
3096
3097pp$8.readToken_slash = function() { // '/'
3098 var next = this.input.charCodeAt(this.pos + 1);
3099 if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
3100 if (next === 61) { return this.finishOp(types.assign, 2) }
3101 return this.finishOp(types.slash, 1)
3102};
3103
3104pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
3105 var next = this.input.charCodeAt(this.pos + 1);
3106 var size = 1;
3107 var tokentype = code === 42 ? types.star : types.modulo;
3108
3109 // exponentiation operator ** and **=
3110 if (this.options.ecmaVersion >= 7 && next === 42) {
3111 ++size;
3112 tokentype = types.starstar;
3113 next = this.input.charCodeAt(this.pos + 2);
3114 }
3115
3116 if (next === 61) { return this.finishOp(types.assign, size + 1) }
3117 return this.finishOp(tokentype, size)
3118};
3119
3120pp$8.readToken_pipe_amp = function(code) { // '|&'
3121 var next = this.input.charCodeAt(this.pos + 1);
3122 if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
3123 if (next === 61) { return this.finishOp(types.assign, 2) }
3124 return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
3125};
3126
3127pp$8.readToken_caret = function() { // '^'
3128 var next = this.input.charCodeAt(this.pos + 1);
3129 if (next === 61) { return this.finishOp(types.assign, 2) }
3130 return this.finishOp(types.bitwiseXOR, 1)
3131};
3132
3133pp$8.readToken_plus_min = function(code) { // '+-'
3134 var next = this.input.charCodeAt(this.pos + 1);
3135 if (next === code) {
3136 if (next == 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 62 &&
3137 (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
3138 // A `-->` line comment
3139 this.skipLineComment(3);
3140 this.skipSpace();
3141 return this.nextToken()
3142 }
3143 return this.finishOp(types.incDec, 2)
3144 }
3145 if (next === 61) { return this.finishOp(types.assign, 2) }
3146 return this.finishOp(types.plusMin, 1)
3147};
3148
3149pp$8.readToken_lt_gt = function(code) { // '<>'
3150 var next = this.input.charCodeAt(this.pos + 1);
3151 var size = 1;
3152 if (next === code) {
3153 size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
3154 if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
3155 return this.finishOp(types.bitShift, size)
3156 }
3157 if (next == 33 && code == 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 45 &&
3158 this.input.charCodeAt(this.pos + 3) == 45) {
3159 // `<!--`, an XML-style comment that should be interpreted as a line comment
3160 this.skipLineComment(4);
3161 this.skipSpace();
3162 return this.nextToken()
3163 }
3164 if (next === 61) { size = 2; }
3165 return this.finishOp(types.relational, size)
3166};
3167
3168pp$8.readToken_eq_excl = function(code) { // '=!'
3169 var next = this.input.charCodeAt(this.pos + 1);
3170 if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
3171 if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
3172 this.pos += 2;
3173 return this.finishToken(types.arrow)
3174 }
3175 return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
3176};
3177
3178pp$8.getTokenFromCode = function(code) {
3179 switch (code) {
3180 // The interpretation of a dot depends on whether it is followed
3181 // by a digit or another two dots.
3182 case 46: // '.'
3183 return this.readToken_dot()
3184
3185 // Punctuation tokens.
3186 case 40: ++this.pos; return this.finishToken(types.parenL)
3187 case 41: ++this.pos; return this.finishToken(types.parenR)
3188 case 59: ++this.pos; return this.finishToken(types.semi)
3189 case 44: ++this.pos; return this.finishToken(types.comma)
3190 case 91: ++this.pos; return this.finishToken(types.bracketL)
3191 case 93: ++this.pos; return this.finishToken(types.bracketR)
3192 case 123: ++this.pos; return this.finishToken(types.braceL)
3193 case 125: ++this.pos; return this.finishToken(types.braceR)
3194 case 58: ++this.pos; return this.finishToken(types.colon)
3195 case 63: ++this.pos; return this.finishToken(types.question)
3196
3197 case 96: // '`'
3198 if (this.options.ecmaVersion < 6) { break }
3199 ++this.pos;
3200 return this.finishToken(types.backQuote)
3201
3202 case 48: // '0'
3203 var next = this.input.charCodeAt(this.pos + 1);
3204 if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
3205 if (this.options.ecmaVersion >= 6) {
3206 if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
3207 if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
3208 }
3209 // Anything else beginning with a digit is an integer, octal
3210 // number, or float.
3211 case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
3212 return this.readNumber(false)
3213
3214 // Quotes produce strings.
3215 case 34: case 39: // '"', "'"
3216 return this.readString(code)
3217
3218 // Operators are parsed inline in tiny state machines. '=' (61) is
3219 // often referred to. `finishOp` simply skips the amount of
3220 // characters it is given as second argument, and returns a token
3221 // of the type given by its first argument.
3222
3223 case 47: // '/'
3224 return this.readToken_slash()
3225
3226 case 37: case 42: // '%*'
3227 return this.readToken_mult_modulo_exp(code)
3228
3229 case 124: case 38: // '|&'
3230 return this.readToken_pipe_amp(code)
3231
3232 case 94: // '^'
3233 return this.readToken_caret()
3234
3235 case 43: case 45: // '+-'
3236 return this.readToken_plus_min(code)
3237
3238 case 60: case 62: // '<>'
3239 return this.readToken_lt_gt(code)
3240
3241 case 61: case 33: // '=!'
3242 return this.readToken_eq_excl(code)
3243
3244 case 126: // '~'
3245 return this.finishOp(types.prefix, 1)
3246 }
3247
3248 this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
3249};
3250
3251pp$8.finishOp = function(type, size) {
3252 var str = this.input.slice(this.pos, this.pos + size);
3253 this.pos += size;
3254 return this.finishToken(type, str)
3255};
3256
3257// Parse a regular expression. Some context-awareness is necessary,
3258// since a '/' inside a '[]' set does not end the expression.
3259
3260function tryCreateRegexp(src, flags, throwErrorAt, parser) {
3261 try {
3262 return new RegExp(src, flags)
3263 } catch (e) {
3264 if (throwErrorAt !== undefined) {
3265 if (e instanceof SyntaxError) { parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message); }
3266 throw e
3267 }
3268 }
3269}
3270
3271var regexpUnicodeSupport = !!tryCreateRegexp("\uffff", "u");
3272
3273pp$8.readRegexp = function() {
3274 var this$1 = this;
3275
3276 var escaped, inClass, start = this.pos;
3277 for (;;) {
3278 if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
3279 var ch = this$1.input.charAt(this$1.pos);
3280 if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
3281 if (!escaped) {
3282 if (ch === "[") { inClass = true; }
3283 else if (ch === "]" && inClass) { inClass = false; }
3284 else if (ch === "/" && !inClass) { break }
3285 escaped = ch === "\\";
3286 } else { escaped = false; }
3287 ++this$1.pos;
3288 }
3289 var content = this.input.slice(start, this.pos);
3290 ++this.pos;
3291 // Need to use `readWord1` because '\uXXXX' sequences are allowed
3292 // here (don't ask).
3293 var mods = this.readWord1();
3294 var tmp = content, tmpFlags = "";
3295 if (mods) {
3296 var validFlags = /^[gim]*$/;
3297 if (this.options.ecmaVersion >= 6) { validFlags = /^[gimuy]*$/; }
3298 if (!validFlags.test(mods)) { this.raise(start, "Invalid regular expression flag"); }
3299 if (mods.indexOf("u") >= 0) {
3300 if (regexpUnicodeSupport) {
3301 tmpFlags = "u";
3302 } else {
3303 // Replace each astral symbol and every Unicode escape sequence that
3304 // possibly represents an astral symbol or a paired surrogate with a
3305 // single ASCII symbol to avoid throwing on regular expressions that
3306 // are only valid in combination with the `/u` flag.
3307 // Note: replacing with the ASCII symbol `x` might cause false
3308 // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
3309 // perfectly valid pattern that is equivalent to `[a-b]`, but it would
3310 // be replaced by `[x-b]` which throws an error.
3311 tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
3312 code = Number("0x" + code);
3313 if (code > 0x10FFFF) { this$1.raise(start + offset + 3, "Code point out of bounds"); }
3314 return "x"
3315 });
3316 tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
3317 tmpFlags = tmpFlags.replace("u", "");
3318 }
3319 }
3320 }
3321 // Detect invalid regular expressions.
3322 var value = null;
3323 // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
3324 // so don't do detection if we are running under Rhino
3325 if (!isRhino) {
3326 tryCreateRegexp(tmp, tmpFlags, start, this);
3327 // Get a regular expression object for this pattern-flag pair, or `null` in
3328 // case the current environment doesn't support the flags it uses.
3329 value = tryCreateRegexp(content, mods);
3330 }
3331 return this.finishToken(types.regexp, {pattern: content, flags: mods, value: value})
3332};
3333
3334// Read an integer in the given radix. Return null if zero digits
3335// were read, the integer value otherwise. When `len` is given, this
3336// will return `null` unless the integer has exactly `len` digits.
3337
3338pp$8.readInt = function(radix, len) {
3339 var this$1 = this;
3340
3341 var start = this.pos, total = 0;
3342 for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
3343 var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
3344 if (code >= 97) { val = code - 97 + 10; } // a
3345 else if (code >= 65) { val = code - 65 + 10; } // A
3346 else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
3347 else { val = Infinity; }
3348 if (val >= radix) { break }
3349 ++this$1.pos;
3350 total = total * radix + val;
3351 }
3352 if (this.pos === start || len != null && this.pos - start !== len) { return null }
3353
3354 return total
3355};
3356
3357pp$8.readRadixNumber = function(radix) {
3358 this.pos += 2; // 0x
3359 var val = this.readInt(radix);
3360 if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
3361 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
3362 return this.finishToken(types.num, val)
3363};
3364
3365// Read an integer, octal integer, or floating-point number.
3366
3367pp$8.readNumber = function(startsWithDot) {
3368 var start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48;
3369 if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
3370 if (octal && this.pos == start + 1) { octal = false; }
3371 var next = this.input.charCodeAt(this.pos);
3372 if (next === 46 && !octal) { // '.'
3373 ++this.pos;
3374 this.readInt(10);
3375 isFloat = true;
3376 next = this.input.charCodeAt(this.pos);
3377 }
3378 if ((next === 69 || next === 101) && !octal) { // 'eE'
3379 next = this.input.charCodeAt(++this.pos);
3380 if (next === 43 || next === 45) { ++this.pos; } // '+-'
3381 if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
3382 isFloat = true;
3383 }
3384 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
3385
3386 var str = this.input.slice(start, this.pos), val;
3387 if (isFloat) { val = parseFloat(str); }
3388 else if (!octal || str.length === 1) { val = parseInt(str, 10); }
3389 else if (this.strict) { this.raise(start, "Invalid number"); }
3390 else if (/[89]/.test(str)) { val = parseInt(str, 10); }
3391 else { val = parseInt(str, 8); }
3392 return this.finishToken(types.num, val)
3393};
3394
3395// Read a string value, interpreting backslash-escapes.
3396
3397pp$8.readCodePoint = function() {
3398 var ch = this.input.charCodeAt(this.pos), code;
3399
3400 if (ch === 123) { // '{'
3401 if (this.options.ecmaVersion < 6) { this.unexpected(); }
3402 var codePos = ++this.pos;
3403 code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
3404 ++this.pos;
3405 if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
3406 } else {
3407 code = this.readHexChar(4);
3408 }
3409 return code
3410};
3411
3412function codePointToString(code) {
3413 // UTF-16 Decoding
3414 if (code <= 0xFFFF) { return String.fromCharCode(code) }
3415 code -= 0x10000;
3416 return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
3417}
3418
3419pp$8.readString = function(quote) {
3420 var this$1 = this;
3421
3422 var out = "", chunkStart = ++this.pos;
3423 for (;;) {
3424 if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
3425 var ch = this$1.input.charCodeAt(this$1.pos);
3426 if (ch === quote) { break }
3427 if (ch === 92) { // '\'
3428 out += this$1.input.slice(chunkStart, this$1.pos);
3429 out += this$1.readEscapedChar(false);
3430 chunkStart = this$1.pos;
3431 } else {
3432 if (isNewLine(ch)) { this$1.raise(this$1.start, "Unterminated string constant"); }
3433 ++this$1.pos;
3434 }
3435 }
3436 out += this.input.slice(chunkStart, this.pos++);
3437 return this.finishToken(types.string, out)
3438};
3439
3440// Reads template string tokens.
3441
3442var INVALID_TEMPLATE_ESCAPE_ERROR = {};
3443
3444pp$8.tryReadTemplateToken = function() {
3445 this.inTemplateElement = true;
3446 try {
3447 this.readTmplToken();
3448 } catch (err) {
3449 if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
3450 this.readInvalidTemplateToken();
3451 } else {
3452 throw err
3453 }
3454 }
3455
3456 this.inTemplateElement = false;
3457};
3458
3459pp$8.invalidStringToken = function(position, message) {
3460 if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
3461 throw INVALID_TEMPLATE_ESCAPE_ERROR
3462 } else {
3463 this.raise(position, message);
3464 }
3465};
3466
3467pp$8.readTmplToken = function() {
3468 var this$1 = this;
3469
3470 var out = "", chunkStart = this.pos;
3471 for (;;) {
3472 if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
3473 var ch = this$1.input.charCodeAt(this$1.pos);
3474 if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
3475 if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
3476 if (ch === 36) {
3477 this$1.pos += 2;
3478 return this$1.finishToken(types.dollarBraceL)
3479 } else {
3480 ++this$1.pos;
3481 return this$1.finishToken(types.backQuote)
3482 }
3483 }
3484 out += this$1.input.slice(chunkStart, this$1.pos);
3485 return this$1.finishToken(types.template, out)
3486 }
3487 if (ch === 92) { // '\'
3488 out += this$1.input.slice(chunkStart, this$1.pos);
3489 out += this$1.readEscapedChar(true);
3490 chunkStart = this$1.pos;
3491 } else if (isNewLine(ch)) {
3492 out += this$1.input.slice(chunkStart, this$1.pos);
3493 ++this$1.pos;
3494 switch (ch) {
3495 case 13:
3496 if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
3497 case 10:
3498 out += "\n";
3499 break
3500 default:
3501 out += String.fromCharCode(ch);
3502 break
3503 }
3504 if (this$1.options.locations) {
3505 ++this$1.curLine;
3506 this$1.lineStart = this$1.pos;
3507 }
3508 chunkStart = this$1.pos;
3509 } else {
3510 ++this$1.pos;
3511 }
3512 }
3513};
3514
3515// Reads a template token to search for the end, without validating any escape sequences
3516pp$8.readInvalidTemplateToken = function() {
3517 var this$1 = this;
3518
3519 for (; this.pos < this.input.length; this.pos++) {
3520 switch (this$1.input[this$1.pos]) {
3521 case "\\":
3522 ++this$1.pos;
3523 break
3524
3525 case "$":
3526 if (this$1.input[this$1.pos + 1] !== "{") {
3527 break
3528 }
3529 // falls through
3530
3531 case "`":
3532 return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
3533
3534 // no default
3535 }
3536 }
3537 this.raise(this.start, "Unterminated template");
3538};
3539
3540// Used to read escaped characters
3541
3542pp$8.readEscapedChar = function(inTemplate) {
3543 var ch = this.input.charCodeAt(++this.pos);
3544 ++this.pos;
3545 switch (ch) {
3546 case 110: return "\n" // 'n' -> '\n'
3547 case 114: return "\r" // 'r' -> '\r'
3548 case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
3549 case 117: return codePointToString(this.readCodePoint()) // 'u'
3550 case 116: return "\t" // 't' -> '\t'
3551 case 98: return "\b" // 'b' -> '\b'
3552 case 118: return "\u000b" // 'v' -> '\u000b'
3553 case 102: return "\f" // 'f' -> '\f'
3554 case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
3555 case 10: // ' \n'
3556 if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
3557 return ""
3558 default:
3559 if (ch >= 48 && ch <= 55) {
3560 var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
3561 var octal = parseInt(octalStr, 8);
3562 if (octal > 255) {
3563 octalStr = octalStr.slice(0, -1);
3564 octal = parseInt(octalStr, 8);
3565 }
3566 if (octalStr !== "0" && (this.strict || inTemplate)) {
3567 this.invalidStringToken(this.pos - 2, "Octal literal in strict mode");
3568 }
3569 this.pos += octalStr.length - 1;
3570 return String.fromCharCode(octal)
3571 }
3572 return String.fromCharCode(ch)
3573 }
3574};
3575
3576// Used to read character escape sequences ('\x', '\u', '\U').
3577
3578pp$8.readHexChar = function(len) {
3579 var codePos = this.pos;
3580 var n = this.readInt(16, len);
3581 if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
3582 return n
3583};
3584
3585// Read an identifier, and return it as a string. Sets `this.containsEsc`
3586// to whether the word contained a '\u' escape.
3587//
3588// Incrementally adds only escaped chars, adding other chunks as-is
3589// as a micro-optimization.
3590
3591pp$8.readWord1 = function() {
3592 var this$1 = this;
3593
3594 this.containsEsc = false;
3595 var word = "", first = true, chunkStart = this.pos;
3596 var astral = this.options.ecmaVersion >= 6;
3597 while (this.pos < this.input.length) {
3598 var ch = this$1.fullCharCodeAtPos();
3599 if (isIdentifierChar(ch, astral)) {
3600 this$1.pos += ch <= 0xffff ? 1 : 2;
3601 } else if (ch === 92) { // "\"
3602 this$1.containsEsc = true;
3603 word += this$1.input.slice(chunkStart, this$1.pos);
3604 var escStart = this$1.pos;
3605 if (this$1.input.charCodeAt(++this$1.pos) != 117) // "u"
3606 { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
3607 ++this$1.pos;
3608 var esc = this$1.readCodePoint();
3609 if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
3610 { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
3611 word += codePointToString(esc);
3612 chunkStart = this$1.pos;
3613 } else {
3614 break
3615 }
3616 first = false;
3617 }
3618 return word + this.input.slice(chunkStart, this.pos)
3619};
3620
3621// Read an identifier or keyword token. Will check for reserved
3622// words when necessary.
3623
3624pp$8.readWord = function() {
3625 var word = this.readWord1();
3626 var type = types.name;
3627 if (this.keywords.test(word)) {
3628 if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
3629 type = keywords$1[word];
3630 }
3631 return this.finishToken(type, word)
3632};
3633
3634// Acorn is a tiny, fast JavaScript parser written in JavaScript.
3635//
3636// Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
3637// various contributors and released under an MIT license.
3638//
3639// Git repositories for Acorn are available at
3640//
3641// http://marijnhaverbeke.nl/git/acorn
3642// https://github.com/ternjs/acorn.git
3643//
3644// Please use the [github bug tracker][ghbt] to report issues.
3645//
3646// [ghbt]: https://github.com/ternjs/acorn/issues
3647//
3648// This file defines the main parser interface. The library also comes
3649// with a [error-tolerant parser][dammit] and an
3650// [abstract syntax tree walker][walk], defined in other files.
3651//
3652// [dammit]: acorn_loose.js
3653// [walk]: util/walk.js
3654
3655var version = "5.1.2";
3656
3657// The main exported interface (under `self.acorn` when in the
3658// browser) is a `parse` function that takes a code string and
3659// returns an abstract syntax tree as specified by [Mozilla parser
3660// API][api].
3661//
3662// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
3663
3664function parse$1(input, options) {
3665 return new Parser(options, input).parse()
3666}
3667
3668// This function tries to parse a single expression at a given
3669// offset in a string. Useful for parsing mixed-language formats
3670// that embed JavaScript expressions.
3671
3672function parseExpressionAt(input, pos, options) {
3673 var p = new Parser(options, input, pos);
3674 p.nextToken();
3675 return p.parseExpression()
3676}
3677
3678// Acorn is organized as a tokenizer and a recursive-descent parser.
3679// The `tokenizer` export provides an interface to the tokenizer.
3680
3681function tokenizer(input, options) {
3682 return new Parser(options, input)
3683}
3684
3685// This is a terrible kludge to support the existing, pre-ES6
3686// interface where the loose parser module retroactively adds exports
3687// to this module.
3688var parse_dammit;
3689var LooseParser;
3690var pluginsLoose; // eslint-disable-line camelcase
3691function addLooseExports(parse, Parser$$1, plugins$$1) {
3692 parse_dammit = parse; // eslint-disable-line camelcase
3693 LooseParser = Parser$$1;
3694 pluginsLoose = plugins$$1;
3695}
3696
3697
3698
3699
3700var acorn = Object.freeze({
3701 version: version,
3702 parse: parse$1,
3703 parseExpressionAt: parseExpressionAt,
3704 tokenizer: tokenizer,
3705 get parse_dammit () { return parse_dammit; },
3706 get LooseParser () { return LooseParser; },
3707 get pluginsLoose () { return pluginsLoose; },
3708 addLooseExports: addLooseExports,
3709 Parser: Parser,
3710 plugins: plugins,
3711 defaultOptions: defaultOptions,
3712 Position: Position,
3713 SourceLocation: SourceLocation,
3714 getLineInfo: getLineInfo,
3715 Node: Node,
3716 TokenType: TokenType,
3717 tokTypes: types,
3718 keywordTypes: keywords$1,
3719 TokContext: TokContext,
3720 tokContexts: types$1,
3721 isIdentifierChar: isIdentifierChar,
3722 isIdentifierStart: isIdentifierStart,
3723 Token: Token,
3724 isNewLine: isNewLine,
3725 lineBreak: lineBreak,
3726 lineBreakG: lineBreakG,
3727 nonASCIIwhitespace: nonASCIIwhitespace
3728});
3729
3730var xhtml = {
3731 quot: '\u0022',
3732 amp: '&',
3733 apos: '\u0027',
3734 lt: '<',
3735 gt: '>',
3736 nbsp: '\u00A0',
3737 iexcl: '\u00A1',
3738 cent: '\u00A2',
3739 pound: '\u00A3',
3740 curren: '\u00A4',
3741 yen: '\u00A5',
3742 brvbar: '\u00A6',
3743 sect: '\u00A7',
3744 uml: '\u00A8',
3745 copy: '\u00A9',
3746 ordf: '\u00AA',
3747 laquo: '\u00AB',
3748 not: '\u00AC',
3749 shy: '\u00AD',
3750 reg: '\u00AE',
3751 macr: '\u00AF',
3752 deg: '\u00B0',
3753 plusmn: '\u00B1',
3754 sup2: '\u00B2',
3755 sup3: '\u00B3',
3756 acute: '\u00B4',
3757 micro: '\u00B5',
3758 para: '\u00B6',
3759 middot: '\u00B7',
3760 cedil: '\u00B8',
3761 sup1: '\u00B9',
3762 ordm: '\u00BA',
3763 raquo: '\u00BB',
3764 frac14: '\u00BC',
3765 frac12: '\u00BD',
3766 frac34: '\u00BE',
3767 iquest: '\u00BF',
3768 Agrave: '\u00C0',
3769 Aacute: '\u00C1',
3770 Acirc: '\u00C2',
3771 Atilde: '\u00C3',
3772 Auml: '\u00C4',
3773 Aring: '\u00C5',
3774 AElig: '\u00C6',
3775 Ccedil: '\u00C7',
3776 Egrave: '\u00C8',
3777 Eacute: '\u00C9',
3778 Ecirc: '\u00CA',
3779 Euml: '\u00CB',
3780 Igrave: '\u00CC',
3781 Iacute: '\u00CD',
3782 Icirc: '\u00CE',
3783 Iuml: '\u00CF',
3784 ETH: '\u00D0',
3785 Ntilde: '\u00D1',
3786 Ograve: '\u00D2',
3787 Oacute: '\u00D3',
3788 Ocirc: '\u00D4',
3789 Otilde: '\u00D5',
3790 Ouml: '\u00D6',
3791 times: '\u00D7',
3792 Oslash: '\u00D8',
3793 Ugrave: '\u00D9',
3794 Uacute: '\u00DA',
3795 Ucirc: '\u00DB',
3796 Uuml: '\u00DC',
3797 Yacute: '\u00DD',
3798 THORN: '\u00DE',
3799 szlig: '\u00DF',
3800 agrave: '\u00E0',
3801 aacute: '\u00E1',
3802 acirc: '\u00E2',
3803 atilde: '\u00E3',
3804 auml: '\u00E4',
3805 aring: '\u00E5',
3806 aelig: '\u00E6',
3807 ccedil: '\u00E7',
3808 egrave: '\u00E8',
3809 eacute: '\u00E9',
3810 ecirc: '\u00EA',
3811 euml: '\u00EB',
3812 igrave: '\u00EC',
3813 iacute: '\u00ED',
3814 icirc: '\u00EE',
3815 iuml: '\u00EF',
3816 eth: '\u00F0',
3817 ntilde: '\u00F1',
3818 ograve: '\u00F2',
3819 oacute: '\u00F3',
3820 ocirc: '\u00F4',
3821 otilde: '\u00F5',
3822 ouml: '\u00F6',
3823 divide: '\u00F7',
3824 oslash: '\u00F8',
3825 ugrave: '\u00F9',
3826 uacute: '\u00FA',
3827 ucirc: '\u00FB',
3828 uuml: '\u00FC',
3829 yacute: '\u00FD',
3830 thorn: '\u00FE',
3831 yuml: '\u00FF',
3832 OElig: '\u0152',
3833 oelig: '\u0153',
3834 Scaron: '\u0160',
3835 scaron: '\u0161',
3836 Yuml: '\u0178',
3837 fnof: '\u0192',
3838 circ: '\u02C6',
3839 tilde: '\u02DC',
3840 Alpha: '\u0391',
3841 Beta: '\u0392',
3842 Gamma: '\u0393',
3843 Delta: '\u0394',
3844 Epsilon: '\u0395',
3845 Zeta: '\u0396',
3846 Eta: '\u0397',
3847 Theta: '\u0398',
3848 Iota: '\u0399',
3849 Kappa: '\u039A',
3850 Lambda: '\u039B',
3851 Mu: '\u039C',
3852 Nu: '\u039D',
3853 Xi: '\u039E',
3854 Omicron: '\u039F',
3855 Pi: '\u03A0',
3856 Rho: '\u03A1',
3857 Sigma: '\u03A3',
3858 Tau: '\u03A4',
3859 Upsilon: '\u03A5',
3860 Phi: '\u03A6',
3861 Chi: '\u03A7',
3862 Psi: '\u03A8',
3863 Omega: '\u03A9',
3864 alpha: '\u03B1',
3865 beta: '\u03B2',
3866 gamma: '\u03B3',
3867 delta: '\u03B4',
3868 epsilon: '\u03B5',
3869 zeta: '\u03B6',
3870 eta: '\u03B7',
3871 theta: '\u03B8',
3872 iota: '\u03B9',
3873 kappa: '\u03BA',
3874 lambda: '\u03BB',
3875 mu: '\u03BC',
3876 nu: '\u03BD',
3877 xi: '\u03BE',
3878 omicron: '\u03BF',
3879 pi: '\u03C0',
3880 rho: '\u03C1',
3881 sigmaf: '\u03C2',
3882 sigma: '\u03C3',
3883 tau: '\u03C4',
3884 upsilon: '\u03C5',
3885 phi: '\u03C6',
3886 chi: '\u03C7',
3887 psi: '\u03C8',
3888 omega: '\u03C9',
3889 thetasym: '\u03D1',
3890 upsih: '\u03D2',
3891 piv: '\u03D6',
3892 ensp: '\u2002',
3893 emsp: '\u2003',
3894 thinsp: '\u2009',
3895 zwnj: '\u200C',
3896 zwj: '\u200D',
3897 lrm: '\u200E',
3898 rlm: '\u200F',
3899 ndash: '\u2013',
3900 mdash: '\u2014',
3901 lsquo: '\u2018',
3902 rsquo: '\u2019',
3903 sbquo: '\u201A',
3904 ldquo: '\u201C',
3905 rdquo: '\u201D',
3906 bdquo: '\u201E',
3907 dagger: '\u2020',
3908 Dagger: '\u2021',
3909 bull: '\u2022',
3910 hellip: '\u2026',
3911 permil: '\u2030',
3912 prime: '\u2032',
3913 Prime: '\u2033',
3914 lsaquo: '\u2039',
3915 rsaquo: '\u203A',
3916 oline: '\u203E',
3917 frasl: '\u2044',
3918 euro: '\u20AC',
3919 image: '\u2111',
3920 weierp: '\u2118',
3921 real: '\u211C',
3922 trade: '\u2122',
3923 alefsym: '\u2135',
3924 larr: '\u2190',
3925 uarr: '\u2191',
3926 rarr: '\u2192',
3927 darr: '\u2193',
3928 harr: '\u2194',
3929 crarr: '\u21B5',
3930 lArr: '\u21D0',
3931 uArr: '\u21D1',
3932 rArr: '\u21D2',
3933 dArr: '\u21D3',
3934 hArr: '\u21D4',
3935 forall: '\u2200',
3936 part: '\u2202',
3937 exist: '\u2203',
3938 empty: '\u2205',
3939 nabla: '\u2207',
3940 isin: '\u2208',
3941 notin: '\u2209',
3942 ni: '\u220B',
3943 prod: '\u220F',
3944 sum: '\u2211',
3945 minus: '\u2212',
3946 lowast: '\u2217',
3947 radic: '\u221A',
3948 prop: '\u221D',
3949 infin: '\u221E',
3950 ang: '\u2220',
3951 and: '\u2227',
3952 or: '\u2228',
3953 cap: '\u2229',
3954 cup: '\u222A',
3955 'int': '\u222B',
3956 there4: '\u2234',
3957 sim: '\u223C',
3958 cong: '\u2245',
3959 asymp: '\u2248',
3960 ne: '\u2260',
3961 equiv: '\u2261',
3962 le: '\u2264',
3963 ge: '\u2265',
3964 sub: '\u2282',
3965 sup: '\u2283',
3966 nsub: '\u2284',
3967 sube: '\u2286',
3968 supe: '\u2287',
3969 oplus: '\u2295',
3970 otimes: '\u2297',
3971 perp: '\u22A5',
3972 sdot: '\u22C5',
3973 lceil: '\u2308',
3974 rceil: '\u2309',
3975 lfloor: '\u230A',
3976 rfloor: '\u230B',
3977 lang: '\u2329',
3978 rang: '\u232A',
3979 loz: '\u25CA',
3980 spades: '\u2660',
3981 clubs: '\u2663',
3982 hearts: '\u2665',
3983 diams: '\u2666'
3984};
3985
3986'use strict';
3987
3988
3989
3990var hexNumber = /^[\da-fA-F]+$/;
3991var decimalNumber = /^\d+$/;
3992
3993var inject = function(acorn) {
3994 var tt = acorn.tokTypes;
3995 var tc = acorn.tokContexts;
3996
3997 tc.j_oTag = new acorn.TokContext('<tag', false);
3998 tc.j_cTag = new acorn.TokContext('</tag', false);
3999 tc.j_expr = new acorn.TokContext('<tag>...</tag>', true, true);
4000
4001 tt.jsxName = new acorn.TokenType('jsxName');
4002 tt.jsxText = new acorn.TokenType('jsxText', {beforeExpr: true});
4003 tt.jsxTagStart = new acorn.TokenType('jsxTagStart');
4004 tt.jsxTagEnd = new acorn.TokenType('jsxTagEnd');
4005
4006 tt.jsxTagStart.updateContext = function() {
4007 this.context.push(tc.j_expr); // treat as beginning of JSX expression
4008 this.context.push(tc.j_oTag); // start opening tag context
4009 this.exprAllowed = false;
4010 };
4011 tt.jsxTagEnd.updateContext = function(prevType) {
4012 var out = this.context.pop();
4013 if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) {
4014 this.context.pop();
4015 this.exprAllowed = this.curContext() === tc.j_expr;
4016 } else {
4017 this.exprAllowed = true;
4018 }
4019 };
4020
4021 var pp = acorn.Parser.prototype;
4022
4023 // Reads inline JSX contents token.
4024
4025 pp.jsx_readToken = function() {
4026 var out = '', chunkStart = this.pos;
4027 for (;;) {
4028 if (this.pos >= this.input.length)
4029 this.raise(this.start, 'Unterminated JSX contents');
4030 var ch = this.input.charCodeAt(this.pos);
4031
4032 switch (ch) {
4033 case 60: // '<'
4034 case 123: // '{'
4035 if (this.pos === this.start) {
4036 if (ch === 60 && this.exprAllowed) {
4037 ++this.pos;
4038 return this.finishToken(tt.jsxTagStart);
4039 }
4040 return this.getTokenFromCode(ch);
4041 }
4042 out += this.input.slice(chunkStart, this.pos);
4043 return this.finishToken(tt.jsxText, out);
4044
4045 case 38: // '&'
4046 out += this.input.slice(chunkStart, this.pos);
4047 out += this.jsx_readEntity();
4048 chunkStart = this.pos;
4049 break;
4050
4051 default:
4052 if (acorn.isNewLine(ch)) {
4053 out += this.input.slice(chunkStart, this.pos);
4054 out += this.jsx_readNewLine(true);
4055 chunkStart = this.pos;
4056 } else {
4057 ++this.pos;
4058 }
4059 }
4060 }
4061 };
4062
4063 pp.jsx_readNewLine = function(normalizeCRLF) {
4064 var ch = this.input.charCodeAt(this.pos);
4065 var out;
4066 ++this.pos;
4067 if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
4068 ++this.pos;
4069 out = normalizeCRLF ? '\n' : '\r\n';
4070 } else {
4071 out = String.fromCharCode(ch);
4072 }
4073 if (this.options.locations) {
4074 ++this.curLine;
4075 this.lineStart = this.pos;
4076 }
4077
4078 return out;
4079 };
4080
4081 pp.jsx_readString = function(quote) {
4082 var out = '', chunkStart = ++this.pos;
4083 for (;;) {
4084 if (this.pos >= this.input.length)
4085 this.raise(this.start, 'Unterminated string constant');
4086 var ch = this.input.charCodeAt(this.pos);
4087 if (ch === quote) break;
4088 if (ch === 38) { // '&'
4089 out += this.input.slice(chunkStart, this.pos);
4090 out += this.jsx_readEntity();
4091 chunkStart = this.pos;
4092 } else if (acorn.isNewLine(ch)) {
4093 out += this.input.slice(chunkStart, this.pos);
4094 out += this.jsx_readNewLine(false);
4095 chunkStart = this.pos;
4096 } else {
4097 ++this.pos;
4098 }
4099 }
4100 out += this.input.slice(chunkStart, this.pos++);
4101 return this.finishToken(tt.string, out);
4102 };
4103
4104 pp.jsx_readEntity = function() {
4105 var str = '', count = 0, entity;
4106 var ch = this.input[this.pos];
4107 if (ch !== '&')
4108 this.raise(this.pos, 'Entity must start with an ampersand');
4109 var startPos = ++this.pos;
4110 while (this.pos < this.input.length && count++ < 10) {
4111 ch = this.input[this.pos++];
4112 if (ch === ';') {
4113 if (str[0] === '#') {
4114 if (str[1] === 'x') {
4115 str = str.substr(2);
4116 if (hexNumber.test(str))
4117 entity = String.fromCharCode(parseInt(str, 16));
4118 } else {
4119 str = str.substr(1);
4120 if (decimalNumber.test(str))
4121 entity = String.fromCharCode(parseInt(str, 10));
4122 }
4123 } else {
4124 entity = xhtml[str];
4125 }
4126 break;
4127 }
4128 str += ch;
4129 }
4130 if (!entity) {
4131 this.pos = startPos;
4132 return '&';
4133 }
4134 return entity;
4135 };
4136
4137
4138 // Read a JSX identifier (valid tag or attribute name).
4139 //
4140 // Optimized version since JSX identifiers can't contain
4141 // escape characters and so can be read as single slice.
4142 // Also assumes that first character was already checked
4143 // by isIdentifierStart in readToken.
4144
4145 pp.jsx_readWord = function() {
4146 var ch, start = this.pos;
4147 do {
4148 ch = this.input.charCodeAt(++this.pos);
4149 } while (acorn.isIdentifierChar(ch) || ch === 45); // '-'
4150 return this.finishToken(tt.jsxName, this.input.slice(start, this.pos));
4151 };
4152
4153 // Transforms JSX element name to string.
4154
4155 function getQualifiedJSXName(object) {
4156 if (object.type === 'JSXIdentifier')
4157 return object.name;
4158
4159 if (object.type === 'JSXNamespacedName')
4160 return object.namespace.name + ':' + object.name.name;
4161
4162 if (object.type === 'JSXMemberExpression')
4163 return getQualifiedJSXName(object.object) + '.' +
4164 getQualifiedJSXName(object.property);
4165 }
4166
4167 // Parse next token as JSX identifier
4168
4169 pp.jsx_parseIdentifier = function() {
4170 var node = this.startNode();
4171 if (this.type === tt.jsxName)
4172 node.name = this.value;
4173 else if (this.type.keyword)
4174 node.name = this.type.keyword;
4175 else
4176 this.unexpected();
4177 this.next();
4178 return this.finishNode(node, 'JSXIdentifier');
4179 };
4180
4181 // Parse namespaced identifier.
4182
4183 pp.jsx_parseNamespacedName = function() {
4184 var startPos = this.start, startLoc = this.startLoc;
4185 var name = this.jsx_parseIdentifier();
4186 if (!this.options.plugins.jsx.allowNamespaces || !this.eat(tt.colon)) return name;
4187 var node = this.startNodeAt(startPos, startLoc);
4188 node.namespace = name;
4189 node.name = this.jsx_parseIdentifier();
4190 return this.finishNode(node, 'JSXNamespacedName');
4191 };
4192
4193 // Parses element name in any form - namespaced, member
4194 // or single identifier.
4195
4196 pp.jsx_parseElementName = function() {
4197 var startPos = this.start, startLoc = this.startLoc;
4198 var node = this.jsx_parseNamespacedName();
4199 if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !this.options.plugins.jsx.allowNamespacedObjects) {
4200 this.unexpected();
4201 }
4202 while (this.eat(tt.dot)) {
4203 var newNode = this.startNodeAt(startPos, startLoc);
4204 newNode.object = node;
4205 newNode.property = this.jsx_parseIdentifier();
4206 node = this.finishNode(newNode, 'JSXMemberExpression');
4207 }
4208 return node;
4209 };
4210
4211 // Parses any type of JSX attribute value.
4212
4213 pp.jsx_parseAttributeValue = function() {
4214 switch (this.type) {
4215 case tt.braceL:
4216 var node = this.jsx_parseExpressionContainer();
4217 if (node.expression.type === 'JSXEmptyExpression')
4218 this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression');
4219 return node;
4220
4221 case tt.jsxTagStart:
4222 case tt.string:
4223 return this.parseExprAtom();
4224
4225 default:
4226 this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
4227 }
4228 };
4229
4230 // JSXEmptyExpression is unique type since it doesn't actually parse anything,
4231 // and so it should start at the end of last read token (left brace) and finish
4232 // at the beginning of the next one (right brace).
4233
4234 pp.jsx_parseEmptyExpression = function() {
4235 var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
4236 return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
4237 };
4238
4239 // Parses JSX expression enclosed into curly brackets.
4240
4241
4242 pp.jsx_parseExpressionContainer = function() {
4243 var node = this.startNode();
4244 this.next();
4245 node.expression = this.type === tt.braceR
4246 ? this.jsx_parseEmptyExpression()
4247 : this.parseExpression();
4248 this.expect(tt.braceR);
4249 return this.finishNode(node, 'JSXExpressionContainer');
4250 };
4251
4252 // Parses following JSX attribute name-value pair.
4253
4254 pp.jsx_parseAttribute = function() {
4255 var node = this.startNode();
4256 if (this.eat(tt.braceL)) {
4257 this.expect(tt.ellipsis);
4258 node.argument = this.parseMaybeAssign();
4259 this.expect(tt.braceR);
4260 return this.finishNode(node, 'JSXSpreadAttribute');
4261 }
4262 node.name = this.jsx_parseNamespacedName();
4263 node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
4264 return this.finishNode(node, 'JSXAttribute');
4265 };
4266
4267 // Parses JSX opening tag starting after '<'.
4268
4269 pp.jsx_parseOpeningElementAt = function(startPos, startLoc) {
4270 var node = this.startNodeAt(startPos, startLoc);
4271 node.attributes = [];
4272 node.name = this.jsx_parseElementName();
4273 while (this.type !== tt.slash && this.type !== tt.jsxTagEnd)
4274 node.attributes.push(this.jsx_parseAttribute());
4275 node.selfClosing = this.eat(tt.slash);
4276 this.expect(tt.jsxTagEnd);
4277 return this.finishNode(node, 'JSXOpeningElement');
4278 };
4279
4280 // Parses JSX closing tag starting after '</'.
4281
4282 pp.jsx_parseClosingElementAt = function(startPos, startLoc) {
4283 var node = this.startNodeAt(startPos, startLoc);
4284 node.name = this.jsx_parseElementName();
4285 this.expect(tt.jsxTagEnd);
4286 return this.finishNode(node, 'JSXClosingElement');
4287 };
4288
4289 // Parses entire JSX element, including it's opening tag
4290 // (starting after '<'), attributes, contents and closing tag.
4291
4292 pp.jsx_parseElementAt = function(startPos, startLoc) {
4293 var node = this.startNodeAt(startPos, startLoc);
4294 var children = [];
4295 var openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
4296 var closingElement = null;
4297
4298 if (!openingElement.selfClosing) {
4299 contents: for (;;) {
4300 switch (this.type) {
4301 case tt.jsxTagStart:
4302 startPos = this.start; startLoc = this.startLoc;
4303 this.next();
4304 if (this.eat(tt.slash)) {
4305 closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
4306 break contents;
4307 }
4308 children.push(this.jsx_parseElementAt(startPos, startLoc));
4309 break;
4310
4311 case tt.jsxText:
4312 children.push(this.parseExprAtom());
4313 break;
4314
4315 case tt.braceL:
4316 children.push(this.jsx_parseExpressionContainer());
4317 break;
4318
4319 default:
4320 this.unexpected();
4321 }
4322 }
4323 if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
4324 this.raise(
4325 closingElement.start,
4326 'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
4327 }
4328 }
4329
4330 node.openingElement = openingElement;
4331 node.closingElement = closingElement;
4332 node.children = children;
4333 if (this.type === tt.relational && this.value === "<") {
4334 this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
4335 }
4336 return this.finishNode(node, 'JSXElement');
4337 };
4338
4339 // Parses entire JSX element from current position.
4340
4341 pp.jsx_parseElement = function() {
4342 var startPos = this.start, startLoc = this.startLoc;
4343 this.next();
4344 return this.jsx_parseElementAt(startPos, startLoc);
4345 };
4346
4347 acorn.plugins.jsx = function(instance, opts) {
4348 if (!opts) {
4349 return;
4350 }
4351
4352 if (typeof opts !== 'object') {
4353 opts = {};
4354 }
4355
4356 instance.options.plugins.jsx = {
4357 allowNamespaces: opts.allowNamespaces !== false,
4358 allowNamespacedObjects: !!opts.allowNamespacedObjects
4359 };
4360
4361 instance.extend('parseExprAtom', function(inner) {
4362 return function(refShortHandDefaultPos) {
4363 if (this.type === tt.jsxText)
4364 return this.parseLiteral(this.value);
4365 else if (this.type === tt.jsxTagStart)
4366 return this.jsx_parseElement();
4367 else
4368 return inner.call(this, refShortHandDefaultPos);
4369 };
4370 });
4371
4372 instance.extend('readToken', function(inner) {
4373 return function(code) {
4374 var context = this.curContext();
4375
4376 if (context === tc.j_expr) return this.jsx_readToken();
4377
4378 if (context === tc.j_oTag || context === tc.j_cTag) {
4379 if (acorn.isIdentifierStart(code)) return this.jsx_readWord();
4380
4381 if (code == 62) {
4382 ++this.pos;
4383 return this.finishToken(tt.jsxTagEnd);
4384 }
4385
4386 if ((code === 34 || code === 39) && context == tc.j_oTag)
4387 return this.jsx_readString(code);
4388 }
4389
4390 if (code === 60 && this.exprAllowed) {
4391 ++this.pos;
4392 return this.finishToken(tt.jsxTagStart);
4393 }
4394 return inner.call(this, code);
4395 };
4396 });
4397
4398 instance.extend('updateContext', function(inner) {
4399 return function(prevType) {
4400 if (this.type == tt.braceL) {
4401 var curContext = this.curContext();
4402 if (curContext == tc.j_oTag) this.context.push(tc.b_expr);
4403 else if (curContext == tc.j_expr) this.context.push(tc.b_tmpl);
4404 else inner.call(this, prevType);
4405 this.exprAllowed = true;
4406 } else if (this.type === tt.slash && prevType === tt.jsxTagStart) {
4407 this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
4408 this.context.push(tc.j_cTag); // reconsider as closing tag context
4409 this.exprAllowed = false;
4410 } else {
4411 return inner.call(this, prevType);
4412 }
4413 };
4414 });
4415 };
4416
4417 return acorn;
4418};
4419
4420'use strict';
4421
4422var inject$1 = function(acorn) {
4423 if (acorn.version.substr(0, 1) !== "5") {
4424 throw new Error("Unsupported acorn version " + acorn.version + ", please use acorn 5");
4425 }
4426 var tt = acorn.tokTypes;
4427 var pp = acorn.Parser.prototype;
4428
4429 // this is the same parseObj that acorn has with...
4430 function parseObj(isPattern, refDestructuringErrors) {
4431 let node = this.startNode(), first = true, propHash = {};
4432 node.properties = [];
4433 this.next();
4434 while (!this.eat(tt.braceR)) {
4435 if (!first) {
4436 this.expect(tt.comma);
4437 if (this.afterTrailingComma(tt.braceR)) break
4438 } else first = false;
4439
4440 let prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
4441 if (this.options.ecmaVersion >= 6) {
4442 // ...the spread logic borrowed from babylon :)
4443 if (this.type === tt.ellipsis) {
4444 prop = isPattern ? this.parseRestBinding() : this.parseSpread(refDestructuringErrors);
4445 node.properties.push(prop);
4446 if (this.type === tt.comma) {
4447 if (isPattern) {
4448 this.raise(this.start, "Comma is not permitted after the rest element");
4449 } else if (refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
4450 refDestructuringErrors.trailingComma = this.start;
4451 }
4452 }
4453 continue
4454 }
4455
4456 prop.method = false;
4457 prop.shorthand = false;
4458 if (isPattern || refDestructuringErrors) {
4459 startPos = this.start;
4460 startLoc = this.startLoc;
4461 }
4462 if (!isPattern)
4463 isGenerator = this.eat(tt.star);
4464 }
4465 this.parsePropertyName(prop);
4466 if (!isPattern && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
4467 isAsync = true;
4468 this.parsePropertyName(prop, refDestructuringErrors);
4469 } else {
4470 isAsync = false;
4471 }
4472 this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
4473 if (!isPattern) this.checkPropClash(prop, propHash);
4474 node.properties.push(this.finishNode(prop, "Property"));
4475 }
4476 return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
4477 }
4478
4479 const getCheckLVal = origCheckLVal => function (expr, bindingType, checkClashes) {
4480 if (expr.type == "ObjectPattern") {
4481 for (let prop of expr.properties)
4482 this.checkLVal(prop, bindingType, checkClashes);
4483 return
4484 } else if (expr.type === "Property") {
4485 // AssignmentProperty has type == "Property"
4486 return this.checkLVal(expr.value, bindingType, checkClashes)
4487 }
4488 return origCheckLVal.apply(this, arguments)
4489 };
4490
4491 acorn.plugins.objectSpread = function objectSpreadPlugin(instance) {
4492 pp.parseObj = parseObj;
4493 instance.extend("checkLVal", getCheckLVal);
4494 instance.extend("toAssignable", nextMethod => function(node, isBinding) {
4495 if (this.options.ecmaVersion >= 6 && node) {
4496 if (node.type == "ObjectExpression") {
4497 node.type = "ObjectPattern";
4498 for (let prop of node.properties)
4499 this.toAssignable(prop, isBinding);
4500 return node
4501 } else if (node.type === "Property") {
4502 // AssignmentProperty has type == "Property"
4503 if (node.kind !== "init") this.raise(node.key.start, "Object pattern can't contain getter or setter");
4504 return this.toAssignable(node.value, isBinding)
4505 } else if (node.type === "SpreadElement") {
4506 node.type = "RestElement";
4507 return this.toAssignable(node.argument, isBinding)
4508 }
4509 }
4510 return nextMethod.apply(this, arguments)
4511 });
4512 instance.extend("checkPatternExport", nextMethod => function(exports, pat) {
4513 if (pat.type == "ObjectPattern") {
4514 for (let prop of pat.properties)
4515 this.checkPatternExport(exports, prop);
4516 return
4517 } else if (pat.type === "Property") {
4518 return this.checkPatternExport(exports, pat.value)
4519 } else if (pat.type === "RestElement") {
4520 return this.checkPatternExport(exports, pat.argument)
4521 }
4522 nextMethod.apply(this, arguments);
4523 });
4524 };
4525
4526 return acorn;
4527};
4528
4529var keys = {
4530 Program: [ 'body' ],
4531 Literal: []
4532};
4533
4534// used for debugging, without the noise created by
4535// circular references
4536function toJSON ( node ) {
4537 var obj = {};
4538
4539 Object.keys( node ).forEach( function ( key ) {
4540 if ( key === 'parent' || key === 'program' || key === 'keys' || key === '__wrapped' ) return;
4541
4542 if ( Array.isArray( node[ key ] ) ) {
4543 obj[ key ] = node[ key ].map( toJSON );
4544 } else if ( node[ key ] && node[ key ].toJSON ) {
4545 obj[ key ] = node[ key ].toJSON();
4546 } else {
4547 obj[ key ] = node[ key ];
4548 }
4549 });
4550
4551 return obj;
4552}
4553
4554var Node$1 = function Node ( raw, parent ) {
4555 raw.parent = parent;
4556 raw.program = parent.program || parent;
4557 raw.depth = parent.depth + 1;
4558 raw.keys = keys[ raw.type ];
4559 raw.indentation = undefined;
4560
4561 for ( var i = 0, list = keys[ raw.type ]; i < list.length; i += 1 ) {
4562 var key = list[i];
4563
4564 wrap( raw[ key ], raw );
4565 }
4566
4567 raw.program.magicString.addSourcemapLocation( raw.start );
4568 raw.program.magicString.addSourcemapLocation( raw.end );
4569};
4570
4571Node$1.prototype.ancestor = function ancestor ( level ) {
4572 var node = this;
4573 while ( level-- ) {
4574 node = node.parent;
4575 if ( !node ) return null;
4576 }
4577
4578 return node;
4579};
4580
4581Node$1.prototype.contains = function contains ( node ) {
4582 var this$1 = this;
4583
4584 while ( node ) {
4585 if ( node === this$1 ) return true;
4586 node = node.parent;
4587 }
4588
4589 return false;
4590};
4591
4592Node$1.prototype.findLexicalBoundary = function findLexicalBoundary () {
4593 return this.parent.findLexicalBoundary();
4594};
4595
4596Node$1.prototype.findNearest = function findNearest ( type ) {
4597 if ( typeof type === 'string' ) type = new RegExp( ("^" + type + "$") );
4598 if ( type.test( this.type ) ) return this;
4599 return this.parent.findNearest( type );
4600};
4601
4602Node$1.prototype.unparenthesizedParent = function unparenthesizedParent () {
4603 var node = this.parent;
4604 while ( node && node.type === 'ParenthesizedExpression' ) {
4605 node = node.parent;
4606 }
4607 return node;
4608};
4609
4610Node$1.prototype.unparenthesize = function unparenthesize () {
4611 var node = this;
4612 while ( node.type === 'ParenthesizedExpression' ) {
4613 node = node.expression;
4614 }
4615 return node;
4616};
4617
4618Node$1.prototype.findScope = function findScope ( functionScope ) {
4619 return this.parent.findScope( functionScope );
4620};
4621
4622Node$1.prototype.getIndentation = function getIndentation () {
4623 return this.parent.getIndentation();
4624};
4625
4626Node$1.prototype.initialise = function initialise ( transforms ) {
4627 for ( var i = 0, list = this.keys; i < list.length; i += 1 ) {
4628 var key = list[i];
4629
4630 var value = this[ key ];
4631
4632 if ( Array.isArray( value ) ) {
4633 value.forEach( function ( node ) { return node && node.initialise( transforms ); } );
4634 } else if ( value && typeof value === 'object' ) {
4635 value.initialise( transforms );
4636 }
4637 }
4638};
4639
4640Node$1.prototype.toJSON = function toJSON$1 () {
4641 return toJSON( this );
4642};
4643
4644Node$1.prototype.toString = function toString () {
4645 return this.program.magicString.original.slice( this.start, this.end );
4646};
4647
4648Node$1.prototype.transpile = function transpile ( code, transforms ) {
4649 for ( var i = 0, list = this.keys; i < list.length; i += 1 ) {
4650 var key = list[i];
4651
4652 var value = this[ key ];
4653
4654 if ( Array.isArray( value ) ) {
4655 value.forEach( function ( node ) { return node && node.transpile( code, transforms ); } );
4656 } else if ( value && typeof value === 'object' ) {
4657 value.transpile( code, transforms );
4658 }
4659 }
4660};
4661
4662function isArguments ( node ) {
4663 return node.type === 'Identifier' && node.name === 'arguments';
4664}
4665
4666function spread ( code, elements, start, argumentsArrayAlias, isNew ) {
4667 var i = elements.length;
4668 var firstSpreadIndex = -1;
4669
4670 while ( i-- ) {
4671 var element$1 = elements[i];
4672 if ( element$1 && element$1.type === 'SpreadElement' ) {
4673 if ( isArguments( element$1.argument ) ) {
4674 code.overwrite( element$1.argument.start, element$1.argument.end, argumentsArrayAlias );
4675 }
4676
4677 firstSpreadIndex = i;
4678 }
4679 }
4680
4681 if ( firstSpreadIndex === -1 ) return false; // false indicates no spread elements
4682
4683 if (isNew) {
4684 for ( i = 0; i < elements.length; i += 1 ) {
4685 var element$2 = elements[i];
4686 if ( element$2.type === 'SpreadElement' ) {
4687 code.remove( element$2.start, element$2.argument.start );
4688 } else {
4689 code.prependRight( element$2.start, '[' );
4690 code.prependRight( element$2.end, ']' );
4691 }
4692 }
4693
4694 return true; // true indicates some spread elements
4695 }
4696
4697 var element = elements[ firstSpreadIndex ];
4698 var previousElement = elements[ firstSpreadIndex - 1 ];
4699
4700 if ( !previousElement ) {
4701 code.remove( start, element.start );
4702 code.overwrite( element.end, elements[1].start, '.concat( ' );
4703 } else {
4704 code.overwrite( previousElement.end, element.start, ' ].concat( ' );
4705 }
4706
4707 for ( i = firstSpreadIndex; i < elements.length; i += 1 ) {
4708 element = elements[i];
4709
4710 if ( element ) {
4711 if ( element.type === 'SpreadElement' ) {
4712 code.remove( element.start, element.argument.start );
4713 } else {
4714 code.appendLeft( element.start, '[' );
4715 code.appendLeft( element.end, ']' );
4716 }
4717 }
4718 }
4719
4720 return true; // true indicates some spread elements
4721}
4722
4723var ArrayExpression = (function (Node) {
4724 function ArrayExpression () {
4725 Node.apply(this, arguments);
4726 }
4727
4728 if ( Node ) ArrayExpression.__proto__ = Node;
4729 ArrayExpression.prototype = Object.create( Node && Node.prototype );
4730 ArrayExpression.prototype.constructor = ArrayExpression;
4731
4732 ArrayExpression.prototype.initialise = function initialise ( transforms ) {
4733 var this$1 = this;
4734
4735 if ( transforms.spreadRest && this.elements.length ) {
4736 var lexicalBoundary = this.findLexicalBoundary();
4737
4738 var i = this.elements.length;
4739 while ( i-- ) {
4740 var element = this$1.elements[i];
4741 if ( element && element.type === 'SpreadElement' && isArguments( element.argument ) ) {
4742 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
4743 }
4744 }
4745 }
4746
4747 Node.prototype.initialise.call( this, transforms );
4748 };
4749
4750 ArrayExpression.prototype.transpile = function transpile ( code, transforms ) {
4751 if ( transforms.spreadRest ) {
4752 // erase trailing comma after last array element if not an array hole
4753 if ( this.elements.length ) {
4754 var lastElement = this.elements[ this.elements.length - 1 ];
4755 if ( lastElement && /\s*,/.test( code.original.slice( lastElement.end, this.end ) ) ) {
4756 code.overwrite( lastElement.end, this.end - 1, ' ' );
4757 }
4758 }
4759
4760 if ( this.elements.length === 1 ) {
4761 var element = this.elements[0];
4762
4763 if ( element && element.type === 'SpreadElement' ) {
4764 // special case – [ ...arguments ]
4765 if ( isArguments( element.argument ) ) {
4766 code.overwrite( this.start, this.end, ("[].concat( " + (this.argumentsArrayAlias) + " )") ); // TODO if this is the only use of argsArray, don't bother concating
4767 } else {
4768 code.overwrite( this.start, element.argument.start, '[].concat( ' );
4769 code.overwrite( element.end, this.end, ' )' );
4770 }
4771 }
4772 }
4773 else {
4774 var hasSpreadElements = spread( code, this.elements, this.start, this.argumentsArrayAlias );
4775
4776 if ( hasSpreadElements ) {
4777 code.overwrite( this.end - 1, this.end, ')' );
4778 }
4779 }
4780 }
4781
4782 Node.prototype.transpile.call( this, code, transforms );
4783 };
4784
4785 return ArrayExpression;
4786}(Node$1));
4787
4788var ArrowFunctionExpression = (function (Node) {
4789 function ArrowFunctionExpression () {
4790 Node.apply(this, arguments);
4791 }
4792
4793 if ( Node ) ArrowFunctionExpression.__proto__ = Node;
4794 ArrowFunctionExpression.prototype = Object.create( Node && Node.prototype );
4795 ArrowFunctionExpression.prototype.constructor = ArrowFunctionExpression;
4796
4797 ArrowFunctionExpression.prototype.initialise = function initialise ( transforms ) {
4798 this.body.createScope();
4799 Node.prototype.initialise.call( this, transforms );
4800 };
4801
4802 ArrowFunctionExpression.prototype.transpile = function transpile ( code, transforms ) {
4803 if ( transforms.arrow || this.needsArguments(transforms) ) {
4804 // remove arrow
4805 var charIndex = this.body.start;
4806 while ( code.original[ charIndex ] !== '=' ) {
4807 charIndex -= 1;
4808 }
4809 code.remove( charIndex, this.body.start );
4810
4811 Node.prototype.transpile.call( this, code, transforms );
4812
4813 // wrap naked parameter
4814 if ( this.params.length === 1 && this.start === this.params[0].start ) {
4815 code.prependRight( this.params[0].start, '(' );
4816 code.appendLeft( this.params[0].end, ')' );
4817 }
4818
4819 // add function
4820 if ( this.parent && this.parent.type === 'ExpressionStatement' ) {
4821 // standalone expression statement
4822 code.prependRight( this.start, '!function' );
4823 } else {
4824 code.prependRight( this.start, 'function ' );
4825 }
4826 }
4827
4828 else {
4829 Node.prototype.transpile.call( this, code, transforms );
4830 }
4831 };
4832
4833 // Returns whether any transforms that will happen use `arguments`
4834 ArrowFunctionExpression.prototype.needsArguments = function needsArguments(transforms) {
4835 return transforms.spreadRest && this.params.filter( function ( param ) { return param.type === 'RestElement'; } ).length > 0
4836 };
4837
4838 return ArrowFunctionExpression;
4839}(Node$1));
4840
4841function locate ( source, index ) {
4842 var lines = source.split( '\n' );
4843 var len = lines.length;
4844
4845 var lineStart = 0;
4846 var i;
4847
4848 for ( i = 0; i < len; i += 1 ) {
4849 var line = lines[i];
4850 var lineEnd = lineStart + line.length + 1; // +1 for newline
4851
4852 if ( lineEnd > index ) {
4853 return { line: i + 1, column: index - lineStart, char: i };
4854 }
4855
4856 lineStart = lineEnd;
4857 }
4858
4859 throw new Error( 'Could not determine location of character' );
4860}
4861
4862function pad ( num, len ) {
4863 var result = String( num );
4864 return result + repeat( ' ', len - result.length );
4865}
4866
4867function repeat ( str, times ) {
4868 var result = '';
4869 while ( times-- ) result += str;
4870 return result;
4871}
4872
4873function getSnippet ( source, loc, length ) {
4874 if ( length === void 0 ) length = 1;
4875
4876 var first = Math.max( loc.line - 5, 0 );
4877 var last = loc.line;
4878
4879 var numDigits = String( last ).length;
4880
4881 var lines = source.split( '\n' ).slice( first, last );
4882
4883 var lastLine = lines[ lines.length - 1 ];
4884 var offset = lastLine.slice( 0, loc.column ).replace( /\t/g, ' ' ).length;
4885
4886 var snippet = lines
4887 .map( function ( line, i ) { return ((pad( i + first + 1, numDigits )) + " : " + (line.replace( /\t/g, ' '))); } )
4888 .join( '\n' );
4889
4890 snippet += '\n' + repeat( ' ', numDigits + 3 + offset ) + repeat( '^', length );
4891
4892 return snippet;
4893}
4894
4895var CompileError$1 = (function (Error) {
4896 function CompileError ( message, node ) {
4897 Error.call( this, message );
4898
4899 this.name = 'CompileError';
4900 if ( !node ) { return; }
4901
4902 var source = node.program.magicString.original;
4903 var loc = locate( source, node.start );
4904
4905 this.message = message + " (" + (loc.line) + ":" + (loc.column) + ")";
4906
4907 this.stack = new Error().stack.replace( new RegExp( (".+new " + (this.name) + ".+\\n"), 'm' ), '' );
4908
4909 this.loc = loc;
4910 this.snippet = getSnippet( source, loc, node.end - node.start );
4911 }
4912
4913 if ( Error ) CompileError.__proto__ = Error;
4914 CompileError.prototype = Object.create( Error && Error.prototype );
4915 CompileError.prototype.constructor = CompileError;
4916
4917 CompileError.prototype.toString = function toString () {
4918 return ((this.name) + ": " + (this.message) + "\n" + (this.snippet));
4919 };
4920
4921 return CompileError;
4922}(Error));
4923
4924var AssignmentExpression = (function (Node) {
4925 function AssignmentExpression () {
4926 Node.apply(this, arguments);
4927 }
4928
4929 if ( Node ) AssignmentExpression.__proto__ = Node;
4930 AssignmentExpression.prototype = Object.create( Node && Node.prototype );
4931 AssignmentExpression.prototype.constructor = AssignmentExpression;
4932
4933 AssignmentExpression.prototype.initialise = function initialise ( transforms ) {
4934 if ( this.left.type === 'Identifier' ) {
4935 var declaration = this.findScope( false ).findDeclaration( this.left.name );
4936 if ( declaration && declaration.kind === 'const' ) {
4937 throw new CompileError$1( ((this.left.name) + " is read-only"), this.left );
4938 }
4939
4940 // special case – https://gitlab.com/Rich-Harris/buble/issues/11
4941 var statement = declaration && declaration.node.ancestor( 3 );
4942 if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
4943 statement.reassigned[ this.left.name ] = true;
4944 }
4945 }
4946
4947 Node.prototype.initialise.call( this, transforms );
4948 };
4949
4950 AssignmentExpression.prototype.transpile = function transpile ( code, transforms ) {
4951 if ( this.operator === '**=' && transforms.exponentiation ) {
4952 this.transpileExponentiation( code, transforms );
4953 }
4954
4955 else if ( /Pattern/.test( this.left.type ) && transforms.destructuring ) {
4956 this.transpileDestructuring( code, transforms );
4957 }
4958
4959 Node.prototype.transpile.call( this, code, transforms );
4960 };
4961
4962 AssignmentExpression.prototype.transpileDestructuring = function transpileDestructuring ( code ) {
4963 var scope = this.findScope( true );
4964 var assign = scope.createIdentifier( 'assign' );
4965 var temporaries = [ assign ];
4966
4967 var start = this.start;
4968
4969 // We need to pick out some elements from the original code,
4970 // interleaved with generated code. These helpers are used to
4971 // easily do that while keeping the order of the output
4972 // predictable.
4973 var text = '';
4974 function use ( node ) {
4975 code.prependRight( node.start, text );
4976 code.move( node.start, node.end, start );
4977 text = '';
4978 }
4979 function write ( string ) {
4980 text += string;
4981 }
4982
4983 write( ("(" + assign + " = ") );
4984 use( this.right );
4985
4986 // Walk `pattern`, generating code that assigns the value in
4987 // `ref` to it. When `mayDuplicate` is false, the function
4988 // must take care to only output `ref` once.
4989 function destructure ( pattern, ref, mayDuplicate ) {
4990 if ( pattern.type === 'Identifier' || pattern.type === 'MemberExpression' ) {
4991 write( ', ' );
4992 use( pattern );
4993 write( (" = " + ref) );
4994 }
4995
4996 else if ( pattern.type === 'AssignmentPattern' ) {
4997 if ( pattern.left.type === 'Identifier' ) {
4998 code.remove( pattern.start, pattern.right.start );
4999
5000 var target = pattern.left.name;
5001 var source = ref;
5002 if ( !mayDuplicate ) {
5003 write( (", " + target + " = " + ref) );
5004 source = target;
5005 }
5006 write( (", " + target + " = " + source + " === void 0 ? ") );
5007 use( pattern.right );
5008 write( (" : " + source) );
5009 } else {
5010 code.remove( pattern.left.end, pattern.right.start );
5011
5012 var target$1 = scope.createIdentifier( 'temp' );
5013 var source$1 = ref;
5014 temporaries.push( target$1 );
5015 if ( !mayDuplicate ) {
5016 write( (", " + target$1 + " = " + ref) );
5017 source$1 = target$1;
5018 }
5019 write( (", " + target$1 + " = " + source$1 + " === void 0 ? ") );
5020 use( pattern.right );
5021 write( (" : " + source$1) );
5022 destructure( pattern.left, target$1, true );
5023 }
5024 }
5025
5026 else if ( pattern.type === 'ArrayPattern' ) {
5027 var elements = pattern.elements;
5028 if ( elements.length === 1 ) {
5029 code.remove( pattern.start, elements[0].start );
5030 destructure( elements[0], (ref + "[0]"), false );
5031 code.remove( elements[0].end, pattern.end );
5032 }
5033 else {
5034 if ( !mayDuplicate ) {
5035 var temp = scope.createIdentifier( 'array' );
5036 temporaries.push( temp );
5037 write( (", " + temp + " = " + ref) );
5038 ref = temp;
5039 }
5040
5041 var c = pattern.start;
5042 elements.forEach( function ( element, i ) {
5043 if (!element) return;
5044
5045 code.remove(c, element.start);
5046 c = element.end;
5047
5048 if ( element.type === 'RestElement' ) {
5049 code.remove( element.start, element.argument.start );
5050 destructure( element.argument, (ref + ".slice(" + i + ")"), false );
5051 } else {
5052 destructure( element, (ref + "[" + i + "]"), false );
5053 }
5054 });
5055
5056 code.remove(c, pattern.end);
5057 }
5058 }
5059
5060 else if ( pattern.type === 'ObjectPattern' ) {
5061 var props = pattern.properties;
5062 if ( props.length == 1 ) {
5063 var prop = props[0];
5064 var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
5065
5066 code.remove( pattern.start, prop.value.start );
5067 destructure( prop.value, value, false );
5068 code.remove( prop.end, pattern.end );
5069 }
5070 else {
5071 if ( !mayDuplicate ) {
5072 var temp$1 = scope.createIdentifier( 'obj' );
5073 temporaries.push( temp$1 );
5074 write( (", " + temp$1 + " = " + ref) );
5075 ref = temp$1;
5076 }
5077
5078 var c$1 = pattern.start;
5079
5080 props.forEach( function ( prop ) {
5081 var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
5082
5083 code.remove(c$1, prop.value.start);
5084 c$1 = prop.end;
5085
5086 destructure( prop.value, value, false );
5087 });
5088
5089 code.remove(c$1, pattern.end);
5090 }
5091 }
5092
5093 else {
5094 throw new Error( ("Unexpected node type in destructuring assignment (" + (pattern.type) + ")") );
5095 }
5096 }
5097
5098 destructure( this.left, assign, true );
5099 code.remove( this.left.end, this.right.start );
5100
5101 if ( this.unparenthesizedParent().type === 'ExpressionStatement' ) {
5102 // no rvalue needed for expression statement
5103 code.prependRight( start, (text + ")") );
5104 } else {
5105 // destructuring is part of an expression - need an rvalue
5106 code.prependRight( start, (text + ", " + assign + ")") );
5107 }
5108
5109 var statement = this.findNearest( /(?:Statement|Declaration)$/ );
5110 code.appendLeft( statement.start, ("var " + (temporaries.join( ', ' )) + ";\n" + (statement.getIndentation())) );
5111 };
5112
5113 AssignmentExpression.prototype.transpileExponentiation = function transpileExponentiation ( code ) {
5114 var scope = this.findScope( false );
5115 var getAlias = function ( name ) {
5116 var declaration = scope.findDeclaration( name );
5117 return declaration ? declaration.name : name;
5118 };
5119
5120 // first, the easy part – `**=` -> `=`
5121 var charIndex = this.left.end;
5122 while ( code.original[ charIndex ] !== '*' ) charIndex += 1;
5123 code.remove( charIndex, charIndex + 2 );
5124
5125 // how we do the next part depends on a number of factors – whether
5126 // this is a top-level statement, and whether we're updating a
5127 // simple or complex reference
5128 var base;
5129
5130 var left = this.left.unparenthesize();
5131
5132 if ( left.type === 'Identifier' ) {
5133 base = getAlias( left.name );
5134 } else if ( left.type === 'MemberExpression' ) {
5135 var object;
5136 var needsObjectVar = false;
5137 var property;
5138 var needsPropertyVar = false;
5139
5140 var statement = this.findNearest( /(?:Statement|Declaration)$/ );
5141 var i0 = statement.getIndentation();
5142
5143 if ( left.property.type === 'Identifier' ) {
5144 property = left.computed ? getAlias( left.property.name ) : left.property.name;
5145 } else {
5146 property = scope.createIdentifier( 'property' );
5147 needsPropertyVar = true;
5148 }
5149
5150 if ( left.object.type === 'Identifier' ) {
5151 object = getAlias( left.object.name );
5152 } else {
5153 object = scope.createIdentifier( 'object' );
5154 needsObjectVar = true;
5155 }
5156
5157 if ( left.start === statement.start ) {
5158 if ( needsObjectVar && needsPropertyVar ) {
5159 code.prependRight( statement.start, ("var " + object + " = ") );
5160 code.overwrite( left.object.end, left.property.start, (";\n" + i0 + "var " + property + " = ") );
5161 code.overwrite( left.property.end, left.end, (";\n" + i0 + object + "[" + property + "]") );
5162 }
5163
5164 else if ( needsObjectVar ) {
5165 code.prependRight( statement.start, ("var " + object + " = ") );
5166 code.appendLeft( left.object.end, (";\n" + i0) );
5167 code.appendLeft( left.object.end, object );
5168 }
5169
5170 else if ( needsPropertyVar ) {
5171 code.prependRight( left.property.start, ("var " + property + " = ") );
5172 code.appendLeft( left.property.end, (";\n" + i0) );
5173 code.move( left.property.start, left.property.end, this.start );
5174
5175 code.appendLeft( left.object.end, ("[" + property + "]") );
5176 code.remove( left.object.end, left.property.start );
5177 code.remove( left.property.end, left.end );
5178 }
5179 }
5180
5181 else {
5182 var declarators = [];
5183 if ( needsObjectVar ) declarators.push( object );
5184 if ( needsPropertyVar ) declarators.push( property );
5185
5186 if ( declarators.length ) {
5187 code.prependRight( statement.start, ("var " + (declarators.join( ', ' )) + ";\n" + i0) );
5188 }
5189
5190 if ( needsObjectVar && needsPropertyVar ) {
5191 code.prependRight( left.start, ("( " + object + " = ") );
5192 code.overwrite( left.object.end, left.property.start, (", " + property + " = ") );
5193 code.overwrite( left.property.end, left.end, (", " + object + "[" + property + "]") );
5194 }
5195
5196 else if ( needsObjectVar ) {
5197 code.prependRight( left.start, ("( " + object + " = ") );
5198 code.appendLeft( left.object.end, (", " + object) );
5199 }
5200
5201 else if ( needsPropertyVar ) {
5202 code.prependRight( left.property.start, ("( " + property + " = ") );
5203 code.appendLeft( left.property.end, ", " );
5204 code.move( left.property.start, left.property.end, left.start );
5205
5206 code.overwrite( left.object.end, left.property.start, ("[" + property + "]") );
5207 code.remove( left.property.end, left.end );
5208 }
5209
5210 if ( needsPropertyVar ) {
5211 code.appendLeft( this.end, " )" );
5212 }
5213 }
5214
5215 base = object + ( left.computed || needsPropertyVar ? ("[" + property + "]") : ("." + property) );
5216 }
5217
5218 code.prependRight( this.right.start, ("Math.pow( " + base + ", ") );
5219 code.appendLeft( this.right.end, " )" );
5220 };
5221
5222 return AssignmentExpression;
5223}(Node$1));
5224
5225var BinaryExpression = (function (Node) {
5226 function BinaryExpression () {
5227 Node.apply(this, arguments);
5228 }
5229
5230 if ( Node ) BinaryExpression.__proto__ = Node;
5231 BinaryExpression.prototype = Object.create( Node && Node.prototype );
5232 BinaryExpression.prototype.constructor = BinaryExpression;
5233
5234 BinaryExpression.prototype.transpile = function transpile ( code, transforms ) {
5235 if ( this.operator === '**' && transforms.exponentiation ) {
5236 code.prependRight( this.start, "Math.pow( " );
5237 code.overwrite( this.left.end, this.right.start, ", " );
5238 code.appendLeft( this.end, " )" );
5239 }
5240 Node.prototype.transpile.call( this, code, transforms );
5241 };
5242
5243 return BinaryExpression;
5244}(Node$1));
5245
5246var loopStatement = /(?:For(?:In|Of)?|While)Statement/;
5247
5248var BreakStatement = (function (Node) {
5249 function BreakStatement () {
5250 Node.apply(this, arguments);
5251 }
5252
5253 if ( Node ) BreakStatement.__proto__ = Node;
5254 BreakStatement.prototype = Object.create( Node && Node.prototype );
5255 BreakStatement.prototype.constructor = BreakStatement;
5256
5257 BreakStatement.prototype.initialise = function initialise () {
5258 var loop = this.findNearest( loopStatement );
5259 var switchCase = this.findNearest( 'SwitchCase' );
5260
5261 if ( loop && ( !switchCase || loop.depth > switchCase.depth ) ) {
5262 loop.canBreak = true;
5263 this.loop = loop;
5264 }
5265 };
5266
5267 BreakStatement.prototype.transpile = function transpile ( code ) {
5268 if ( this.loop && this.loop.shouldRewriteAsFunction ) {
5269 if ( this.label ) throw new CompileError$1( 'Labels are not currently supported in a loop with locally-scoped variables', this );
5270 code.overwrite( this.start, this.start + 5, "return 'break'" );
5271 }
5272 };
5273
5274 return BreakStatement;
5275}(Node$1));
5276
5277var CallExpression = (function (Node) {
5278 function CallExpression () {
5279 Node.apply(this, arguments);
5280 }
5281
5282 if ( Node ) CallExpression.__proto__ = Node;
5283 CallExpression.prototype = Object.create( Node && Node.prototype );
5284 CallExpression.prototype.constructor = CallExpression;
5285
5286 CallExpression.prototype.initialise = function initialise ( transforms ) {
5287 var this$1 = this;
5288
5289 if ( transforms.spreadRest && this.arguments.length > 1 ) {
5290 var lexicalBoundary = this.findLexicalBoundary();
5291
5292 var i = this.arguments.length;
5293 while ( i-- ) {
5294 var arg = this$1.arguments[i];
5295 if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
5296 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
5297 }
5298 }
5299 }
5300
5301 Node.prototype.initialise.call( this, transforms );
5302 };
5303
5304 CallExpression.prototype.transpile = function transpile ( code, transforms ) {
5305 if ( transforms.spreadRest && this.arguments.length ) {
5306 var hasSpreadElements = false;
5307 var context;
5308
5309 var firstArgument = this.arguments[0];
5310
5311 if ( this.arguments.length === 1 ) {
5312 if ( firstArgument.type === 'SpreadElement' ) {
5313 code.remove( firstArgument.start, firstArgument.argument.start );
5314 hasSpreadElements = true;
5315 }
5316 } else {
5317 hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias );
5318 }
5319
5320 if ( hasSpreadElements ) {
5321
5322 // we need to handle super() and super.method() differently
5323 // due to its instance
5324 var _super = null;
5325 if ( this.callee.type === 'Super' ) {
5326 _super = this.callee;
5327 }
5328 else if ( this.callee.type === 'MemberExpression' && this.callee.object.type === 'Super' ) {
5329 _super = this.callee.object;
5330 }
5331
5332 if ( !_super && this.callee.type === 'MemberExpression' ) {
5333 if ( this.callee.object.type === 'Identifier' ) {
5334 context = this.callee.object.name;
5335 } else {
5336 context = this.findScope( true ).createIdentifier( 'ref' );
5337 var callExpression = this.callee.object;
5338 var enclosure = callExpression.findNearest( /Function/ );
5339 var block = enclosure ? enclosure.body.body
5340 : callExpression.findNearest( /^Program$/ ).body;
5341 var lastStatementInBlock = block[ block.length - 1 ];
5342 var i0 = lastStatementInBlock.getIndentation();
5343 code.prependRight( callExpression.start, ("(" + context + " = ") );
5344 code.appendLeft( callExpression.end, ")" );
5345 code.appendLeft( lastStatementInBlock.end, ("\n" + i0 + "var " + context + ";") );
5346 }
5347 } else {
5348 context = 'void 0';
5349 }
5350
5351 code.appendLeft( this.callee.end, '.apply' );
5352
5353 if ( _super ) {
5354 _super.noCall = true; // bit hacky...
5355
5356 if ( this.arguments.length > 1 ) {
5357 if ( firstArgument.type !== 'SpreadElement' ) {
5358 code.prependRight( firstArgument.start, "[ " );
5359 }
5360
5361 code.appendLeft( this.arguments[ this.arguments.length - 1 ].end, ' )' );
5362 }
5363 }
5364
5365 else if ( this.arguments.length === 1 ) {
5366 code.prependRight( firstArgument.start, (context + ", ") );
5367 } else {
5368 if ( firstArgument.type === 'SpreadElement' ) {
5369 code.appendLeft( firstArgument.start, (context + ", ") );
5370 } else {
5371 code.appendLeft( firstArgument.start, (context + ", [ ") );
5372 }
5373
5374 code.appendLeft( this.arguments[ this.arguments.length - 1 ].end, ' )' );
5375 }
5376 }
5377 }
5378
5379 Node.prototype.transpile.call( this, code, transforms );
5380 };
5381
5382 return CallExpression;
5383}(Node$1));
5384
5385function findIndex ( array, fn ) {
5386 for ( var i = 0; i < array.length; i += 1 ) {
5387 if ( fn( array[i], i ) ) return i;
5388 }
5389
5390 return -1;
5391}
5392
5393var reserved = Object.create( null );
5394'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'.split( ' ' )
5395 .forEach( function ( word ) { return reserved[ word ] = true; } );
5396
5397// TODO this code is pretty wild, tidy it up
5398var ClassBody = (function (Node) {
5399 function ClassBody () {
5400 Node.apply(this, arguments);
5401 }
5402
5403 if ( Node ) ClassBody.__proto__ = Node;
5404 ClassBody.prototype = Object.create( Node && Node.prototype );
5405 ClassBody.prototype.constructor = ClassBody;
5406
5407 ClassBody.prototype.transpile = function transpile ( code, transforms, inFunctionExpression, superName ) {
5408 var this$1 = this;
5409
5410 if ( transforms.classes ) {
5411 var name = this.parent.name;
5412
5413 var indentStr = code.getIndentString();
5414 var i0 = this.getIndentation() + ( inFunctionExpression ? indentStr : '' );
5415 var i1 = i0 + indentStr;
5416
5417 var constructorIndex = findIndex( this.body, function ( node ) { return node.kind === 'constructor'; } );
5418 var constructor = this.body[ constructorIndex ];
5419
5420 var introBlock = '';
5421 var outroBlock = '';
5422
5423 if ( this.body.length ) {
5424 code.remove( this.start, this.body[0].start );
5425 code.remove( this.body[ this.body.length - 1 ].end, this.end );
5426 } else {
5427 code.remove( this.start, this.end );
5428 }
5429
5430 if ( constructor ) {
5431 constructor.value.body.isConstructorBody = true;
5432
5433 var previousMethod = this.body[ constructorIndex - 1 ];
5434 var nextMethod = this.body[ constructorIndex + 1 ];
5435
5436 // ensure constructor is first
5437 if ( constructorIndex > 0 ) {
5438 code.remove( previousMethod.end, constructor.start );
5439 code.move( constructor.start, nextMethod ? nextMethod.start : this.end - 1, this.body[0].start );
5440 }
5441
5442 if ( !inFunctionExpression ) code.appendLeft( constructor.end, ';' );
5443 }
5444
5445 var namedFunctions = this.program.options.namedFunctionExpressions !== false;
5446 var namedConstructor = namedFunctions || this.parent.superClass || this.parent.type !== 'ClassDeclaration';
5447 if ( this.parent.superClass ) {
5448 var inheritanceBlock = "if ( " + superName + " ) " + name + ".__proto__ = " + superName + ";\n" + i0 + name + ".prototype = Object.create( " + superName + " && " + superName + ".prototype );\n" + i0 + name + ".prototype.constructor = " + name + ";";
5449
5450 if ( constructor ) {
5451 introBlock += "\n\n" + i0 + inheritanceBlock;
5452 } else {
5453 var fn = "function " + name + " () {" + ( superName ?
5454 ("\n" + i1 + superName + ".apply(this, arguments);\n" + i0 + "}") :
5455 "}" ) + ( inFunctionExpression ? '' : ';' ) + ( this.body.length ? ("\n\n" + i0) : '' );
5456
5457 inheritanceBlock = fn + inheritanceBlock;
5458 introBlock += inheritanceBlock + "\n\n" + i0;
5459 }
5460 } else if ( !constructor ) {
5461 var fn$1 = 'function ' + (namedConstructor ? name + ' ' : '') + '() {}';
5462 if ( this.parent.type === 'ClassDeclaration' ) fn$1 += ';';
5463 if ( this.body.length ) fn$1 += "\n\n" + i0;
5464
5465 introBlock += fn$1;
5466 }
5467
5468 var scope = this.findScope( false );
5469
5470 var prototypeGettersAndSetters = [];
5471 var staticGettersAndSetters = [];
5472 var prototypeAccessors;
5473 var staticAccessors;
5474
5475 this.body.forEach( function ( method, i ) {
5476 if ( method.kind === 'constructor' ) {
5477 var constructorName = namedConstructor ? ' ' + name : '';
5478 code.overwrite( method.key.start, method.key.end, ("function" + constructorName) );
5479 return;
5480 }
5481
5482 if ( method.static ) {
5483 var len = code.original[ method.start + 6 ] == ' ' ? 7 : 6;
5484 code.remove( method.start, method.start + len );
5485 }
5486
5487 var isAccessor = method.kind !== 'method';
5488 var lhs;
5489
5490 var methodName = method.key.name;
5491 if ( reserved[ methodName ] || method.value.body.scope.references[methodName] ) {
5492 methodName = scope.createIdentifier( methodName );
5493 }
5494
5495 // when method name is a string or a number let's pretend it's a computed method
5496
5497 var fake_computed = false;
5498 if ( ! method.computed && method.key.type === 'Literal' ) {
5499 fake_computed = true;
5500 method.computed = true;
5501 }
5502
5503 if ( isAccessor ) {
5504 if ( method.computed ) {
5505 throw new Error( 'Computed accessor properties are not currently supported' );
5506 }
5507
5508 code.remove( method.start, method.key.start );
5509
5510 if ( method.static ) {
5511 if ( !~staticGettersAndSetters.indexOf( method.key.name ) ) staticGettersAndSetters.push( method.key.name );
5512 if ( !staticAccessors ) staticAccessors = scope.createIdentifier( 'staticAccessors' );
5513
5514 lhs = "" + staticAccessors;
5515 } else {
5516 if ( !~prototypeGettersAndSetters.indexOf( method.key.name ) ) prototypeGettersAndSetters.push( method.key.name );
5517 if ( !prototypeAccessors ) prototypeAccessors = scope.createIdentifier( 'prototypeAccessors' );
5518
5519 lhs = "" + prototypeAccessors;
5520 }
5521 } else {
5522 lhs = method.static ?
5523 ("" + name) :
5524 (name + ".prototype");
5525 }
5526
5527 if ( !method.computed ) lhs += '.';
5528
5529 var insertNewlines = ( constructorIndex > 0 && i === constructorIndex + 1 ) ||
5530 ( i === 0 && constructorIndex === this$1.body.length - 1 );
5531
5532 if ( insertNewlines ) lhs = "\n\n" + i0 + lhs;
5533
5534 var c = method.key.end;
5535 if ( method.computed ) {
5536 if ( fake_computed ) {
5537 code.prependRight( method.key.start, '[' );
5538 code.appendLeft( method.key.end, ']' );
5539 } else {
5540 while ( code.original[c] !== ']' ) c += 1;
5541 c += 1;
5542 }
5543 }
5544
5545 var funcName = method.computed || isAccessor || !namedFunctions ? '' : (methodName + " ");
5546 var rhs = ( isAccessor ? ("." + (method.kind)) : '' ) + " = function" + ( method.value.generator ? '* ' : ' ' ) + funcName;
5547 code.remove( c, method.value.start );
5548 code.prependRight( method.value.start, rhs );
5549 code.appendLeft( method.end, ';' );
5550
5551 if ( method.value.generator ) code.remove( method.start, method.key.start );
5552
5553 code.prependRight( method.start, lhs );
5554 });
5555
5556 if ( prototypeGettersAndSetters.length || staticGettersAndSetters.length ) {
5557 var intro = [];
5558 var outro = [];
5559
5560 if ( prototypeGettersAndSetters.length ) {
5561 intro.push( ("var " + prototypeAccessors + " = { " + (prototypeGettersAndSetters.map( function ( name ) { return (name + ": { configurable: true }"); } ).join( ',' )) + " };") );
5562 outro.push( ("Object.defineProperties( " + name + ".prototype, " + prototypeAccessors + " );") );
5563 }
5564
5565 if ( staticGettersAndSetters.length ) {
5566 intro.push( ("var " + staticAccessors + " = { " + (staticGettersAndSetters.map( function ( name ) { return (name + ": { configurable: true }"); } ).join( ',' )) + " };") );
5567 outro.push( ("Object.defineProperties( " + name + ", " + staticAccessors + " );") );
5568 }
5569
5570 if ( constructor ) introBlock += "\n\n" + i0;
5571 introBlock += intro.join( ("\n" + i0) );
5572 if ( !constructor ) introBlock += "\n\n" + i0;
5573
5574 outroBlock += "\n\n" + i0 + outro.join( ("\n" + i0) );
5575 }
5576
5577 if ( constructor ) {
5578 code.appendLeft( constructor.end, introBlock );
5579 } else {
5580 code.prependRight( this.start, introBlock );
5581 }
5582
5583 code.appendLeft( this.end, outroBlock );
5584 }
5585
5586 Node.prototype.transpile.call( this, code, transforms );
5587 };
5588
5589 return ClassBody;
5590}(Node$1));
5591
5592// TODO this function is slightly flawed – it works on the original string,
5593// not its current edited state.
5594// That's not a problem for the way that it's currently used, but it could
5595// be in future...
5596function deindent ( node, code ) {
5597 var start = node.start;
5598 var end = node.end;
5599
5600 var indentStr = code.getIndentString();
5601 var indentStrLen = indentStr.length;
5602 var indentStart = start - indentStrLen;
5603
5604 if ( !node.program.indentExclusions[ indentStart ]
5605 && code.original.slice( indentStart, start ) === indentStr ) {
5606 code.remove( indentStart, start );
5607 }
5608
5609 var pattern = new RegExp( indentStr + '\\S', 'g' );
5610 var slice = code.original.slice( start, end );
5611 var match;
5612
5613 while ( match = pattern.exec( slice ) ) {
5614 var removeStart = start + match.index;
5615 if ( !node.program.indentExclusions[ removeStart ] ) {
5616 code.remove( removeStart, removeStart + indentStrLen );
5617 }
5618 }
5619}
5620
5621var ClassDeclaration = (function (Node) {
5622 function ClassDeclaration () {
5623 Node.apply(this, arguments);
5624 }
5625
5626 if ( Node ) ClassDeclaration.__proto__ = Node;
5627 ClassDeclaration.prototype = Object.create( Node && Node.prototype );
5628 ClassDeclaration.prototype.constructor = ClassDeclaration;
5629
5630 ClassDeclaration.prototype.initialise = function initialise ( transforms ) {
5631 this.name = this.id.name;
5632 this.findScope( true ).addDeclaration( this.id, 'class' );
5633
5634 Node.prototype.initialise.call( this, transforms );
5635 };
5636
5637 ClassDeclaration.prototype.transpile = function transpile ( code, transforms ) {
5638 if ( transforms.classes ) {
5639 if ( !this.superClass ) deindent( this.body, code );
5640
5641 var superName = this.superClass && ( this.superClass.name || 'superclass' );
5642
5643 var i0 = this.getIndentation();
5644 var i1 = i0 + code.getIndentString();
5645
5646 // if this is an export default statement, we have to move the export to
5647 // after the declaration, because `export default var Foo = ...` is illegal
5648 var syntheticDefaultExport = this.parent.type === 'ExportDefaultDeclaration' ?
5649 ("\n\n" + i0 + "export default " + (this.id.name) + ";") :
5650 '';
5651
5652 if ( syntheticDefaultExport ) code.remove( this.parent.start, this.start );
5653
5654 code.overwrite( this.start, this.id.start, 'var ' );
5655
5656 if ( this.superClass ) {
5657 if ( this.superClass.end === this.body.start ) {
5658 code.remove( this.id.end, this.superClass.start );
5659 code.appendLeft( this.id.end, (" = (function (" + superName + ") {\n" + i1) );
5660 } else {
5661 code.overwrite( this.id.end, this.superClass.start, ' = ' );
5662 code.overwrite( this.superClass.end, this.body.start, ("(function (" + superName + ") {\n" + i1) );
5663 }
5664 } else {
5665 if ( this.id.end === this.body.start ) {
5666 code.appendLeft( this.id.end, ' = ' );
5667 } else {
5668 code.overwrite( this.id.end, this.body.start, ' = ' );
5669 }
5670 }
5671
5672 this.body.transpile( code, transforms, !!this.superClass, superName );
5673
5674 if ( this.superClass ) {
5675 code.appendLeft( this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(") );
5676 code.move( this.superClass.start, this.superClass.end, this.end );
5677 code.prependRight( this.end, ("));" + syntheticDefaultExport) );
5678 } else if ( syntheticDefaultExport ) {
5679 code.prependRight( this.end, syntheticDefaultExport );
5680 }
5681 }
5682
5683 else {
5684 this.body.transpile( code, transforms, false, null );
5685 }
5686 };
5687
5688 return ClassDeclaration;
5689}(Node$1));
5690
5691var ClassExpression = (function (Node) {
5692 function ClassExpression () {
5693 Node.apply(this, arguments);
5694 }
5695
5696 if ( Node ) ClassExpression.__proto__ = Node;
5697 ClassExpression.prototype = Object.create( Node && Node.prototype );
5698 ClassExpression.prototype.constructor = ClassExpression;
5699
5700 ClassExpression.prototype.initialise = function initialise ( transforms ) {
5701 this.name = this.id ? this.id.name :
5702 this.parent.type === 'VariableDeclarator' ? this.parent.id.name :
5703 this.parent.type === 'AssignmentExpression' ? this.parent.left.name :
5704 this.findScope( true ).createIdentifier( 'anonymous' );
5705
5706 Node.prototype.initialise.call( this, transforms );
5707 };
5708
5709 ClassExpression.prototype.transpile = function transpile ( code, transforms ) {
5710 if ( transforms.classes ) {
5711 var superName = this.superClass && ( this.superClass.name || 'superclass' );
5712
5713 var i0 = this.getIndentation();
5714 var i1 = i0 + code.getIndentString();
5715
5716 if ( this.superClass ) {
5717 code.remove( this.start, this.superClass.start );
5718 code.remove( this.superClass.end, this.body.start );
5719 code.appendLeft( this.start, ("(function (" + superName + ") {\n" + i1) );
5720 } else {
5721 code.overwrite( this.start, this.body.start, ("(function () {\n" + i1) );
5722 }
5723
5724 this.body.transpile( code, transforms, true, superName );
5725
5726 var outro = "\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(";
5727
5728 if ( this.superClass ) {
5729 code.appendLeft( this.end, outro );
5730 code.move( this.superClass.start, this.superClass.end, this.end );
5731 code.prependRight( this.end, '))' );
5732 } else {
5733 code.appendLeft( this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}())") );
5734 }
5735 }
5736
5737 else {
5738 this.body.transpile( code, transforms, false );
5739 }
5740 };
5741
5742 return ClassExpression;
5743}(Node$1));
5744
5745var ContinueStatement = (function (Node) {
5746 function ContinueStatement () {
5747 Node.apply(this, arguments);
5748 }
5749
5750 if ( Node ) ContinueStatement.__proto__ = Node;
5751 ContinueStatement.prototype = Object.create( Node && Node.prototype );
5752 ContinueStatement.prototype.constructor = ContinueStatement;
5753
5754 ContinueStatement.prototype.transpile = function transpile ( code ) {
5755 var loop = this.findNearest( loopStatement );
5756 if ( loop.shouldRewriteAsFunction ) {
5757 if ( this.label ) throw new CompileError$1( 'Labels are not currently supported in a loop with locally-scoped variables', this );
5758 code.overwrite( this.start, this.start + 8, 'return' );
5759 }
5760 };
5761
5762 return ContinueStatement;
5763}(Node$1));
5764
5765var ExportDefaultDeclaration = (function (Node) {
5766 function ExportDefaultDeclaration () {
5767 Node.apply(this, arguments);
5768 }
5769
5770 if ( Node ) ExportDefaultDeclaration.__proto__ = Node;
5771 ExportDefaultDeclaration.prototype = Object.create( Node && Node.prototype );
5772 ExportDefaultDeclaration.prototype.constructor = ExportDefaultDeclaration;
5773
5774 ExportDefaultDeclaration.prototype.initialise = function initialise ( transforms ) {
5775 if ( transforms.moduleExport ) throw new CompileError$1( 'export is not supported', this );
5776 Node.prototype.initialise.call( this, transforms );
5777 };
5778
5779 return ExportDefaultDeclaration;
5780}(Node$1));
5781
5782var ExportNamedDeclaration = (function (Node) {
5783 function ExportNamedDeclaration () {
5784 Node.apply(this, arguments);
5785 }
5786
5787 if ( Node ) ExportNamedDeclaration.__proto__ = Node;
5788 ExportNamedDeclaration.prototype = Object.create( Node && Node.prototype );
5789 ExportNamedDeclaration.prototype.constructor = ExportNamedDeclaration;
5790
5791 ExportNamedDeclaration.prototype.initialise = function initialise ( transforms ) {
5792 if ( transforms.moduleExport ) throw new CompileError$1( 'export is not supported', this );
5793 Node.prototype.initialise.call( this, transforms );
5794 };
5795
5796 return ExportNamedDeclaration;
5797}(Node$1));
5798
5799var LoopStatement = (function (Node) {
5800 function LoopStatement () {
5801 Node.apply(this, arguments);
5802 }
5803
5804 if ( Node ) LoopStatement.__proto__ = Node;
5805 LoopStatement.prototype = Object.create( Node && Node.prototype );
5806 LoopStatement.prototype.constructor = LoopStatement;
5807
5808 LoopStatement.prototype.findScope = function findScope ( functionScope ) {
5809 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
5810 };
5811
5812 LoopStatement.prototype.initialise = function initialise ( transforms ) {
5813 var this$1 = this;
5814
5815 this.body.createScope();
5816 this.createdScope = true;
5817
5818 // this is populated as and when reassignments occur
5819 this.reassigned = Object.create( null );
5820 this.aliases = Object.create( null );
5821
5822 Node.prototype.initialise.call( this, transforms );
5823
5824 if ( transforms.letConst ) {
5825 // see if any block-scoped declarations are referenced
5826 // inside function expressions
5827 var names = Object.keys( this.body.scope.declarations );
5828
5829 var i = names.length;
5830 while ( i-- ) {
5831 var name = names[i];
5832 var declaration = this$1.body.scope.declarations[ name ];
5833
5834 var j = declaration.instances.length;
5835 while ( j-- ) {
5836 var instance = declaration.instances[j];
5837 var nearestFunctionExpression = instance.findNearest( /Function/ );
5838
5839 if ( nearestFunctionExpression && nearestFunctionExpression.depth > this$1.depth ) {
5840 this$1.shouldRewriteAsFunction = true;
5841 break;
5842 }
5843 }
5844
5845 if ( this$1.shouldRewriteAsFunction ) break;
5846 }
5847 }
5848 };
5849
5850 LoopStatement.prototype.transpile = function transpile ( code, transforms ) {
5851 var needsBlock = this.type != 'ForOfStatement' && (
5852 this.body.type !== 'BlockStatement'
5853 || this.body.type === 'BlockStatement' && this.body.synthetic );
5854
5855 if ( this.shouldRewriteAsFunction ) {
5856 var i0 = this.getIndentation();
5857 var i1 = i0 + code.getIndentString();
5858
5859 var argString = this.args ? (" " + (this.args.join( ', ' )) + " ") : '';
5860 var paramString = this.params ? (" " + (this.params.join( ', ' )) + " ") : '';
5861
5862 var functionScope = this.findScope( true );
5863 var loop = functionScope.createIdentifier( 'loop' );
5864
5865 var before = "var " + loop + " = function (" + paramString + ") " + ( this.body.synthetic ? ("{\n" + i0 + (code.getIndentString())) : '' );
5866 var after = ( this.body.synthetic ? ("\n" + i0 + "}") : '' ) + ";\n\n" + i0;
5867
5868 code.prependRight( this.body.start, before );
5869 code.appendLeft( this.body.end, after );
5870 code.move( this.start, this.body.start, this.body.end );
5871
5872 if ( this.canBreak || this.canReturn ) {
5873 var returned = functionScope.createIdentifier( 'returned' );
5874
5875 var insert = "{\n" + i1 + "var " + returned + " = " + loop + "(" + argString + ");\n";
5876 if ( this.canBreak ) insert += "\n" + i1 + "if ( " + returned + " === 'break' ) break;";
5877 if ( this.canReturn ) insert += "\n" + i1 + "if ( " + returned + " ) return " + returned + ".v;";
5878 insert += "\n" + i0 + "}";
5879
5880 code.prependRight( this.body.end, insert );
5881 } else {
5882 var callExpression = loop + "(" + argString + ");";
5883
5884 if ( this.type === 'DoWhileStatement' ) {
5885 code.overwrite( this.start, this.body.start, ("do {\n" + i1 + callExpression + "\n" + i0 + "}") );
5886 } else {
5887 code.prependRight( this.body.end, callExpression );
5888 }
5889 }
5890 } else if ( needsBlock ) {
5891 code.appendLeft( this.body.start, '{ ' );
5892 code.prependRight( this.body.end, ' }' );
5893 }
5894
5895 Node.prototype.transpile.call( this, code, transforms );
5896 };
5897
5898 return LoopStatement;
5899}(Node$1));
5900
5901function extractNames ( node ) {
5902 var names = [];
5903 extractors[ node.type ]( names, node );
5904 return names;
5905}
5906
5907var extractors = {
5908 Identifier: function Identifier ( names, node ) {
5909 names.push( node );
5910 },
5911
5912 ObjectPattern: function ObjectPattern ( names, node ) {
5913 for ( var i = 0, list = node.properties; i < list.length; i += 1 ) {
5914 var prop = list[i];
5915
5916 extractors[ prop.type ]( names, prop );
5917 }
5918 },
5919
5920 Property: function Property ( names, node ) {
5921 extractors[ node.value.type ]( names, node.value );
5922 },
5923
5924 ArrayPattern: function ArrayPattern ( names, node ) {
5925 for ( var i = 0, list = node.elements; i < list.length; i += 1 ) {
5926 var element = list[i];
5927
5928 if ( element ) extractors[ element.type ]( names, element );
5929 }
5930 },
5931
5932 RestElement: function RestElement ( names, node ) {
5933 extractors[ node.argument.type ]( names, node.argument );
5934 },
5935
5936 AssignmentPattern: function AssignmentPattern ( names, node ) {
5937 extractors[ node.left.type ]( names, node.left );
5938 }
5939};
5940
5941var ForStatement = (function (LoopStatement$$1) {
5942 function ForStatement () {
5943 LoopStatement$$1.apply(this, arguments);
5944 }
5945
5946 if ( LoopStatement$$1 ) ForStatement.__proto__ = LoopStatement$$1;
5947 ForStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
5948 ForStatement.prototype.constructor = ForStatement;
5949
5950 ForStatement.prototype.findScope = function findScope ( functionScope ) {
5951 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
5952 };
5953
5954 ForStatement.prototype.transpile = function transpile ( code, transforms ) {
5955 var this$1 = this;
5956
5957 var i1 = this.getIndentation() + code.getIndentString();
5958
5959 if ( this.shouldRewriteAsFunction ) {
5960 // which variables are declared in the init statement?
5961 var names = this.init.type === 'VariableDeclaration' ?
5962 [].concat.apply( [], this.init.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
5963 [];
5964
5965 var aliases = this.aliases;
5966
5967 this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
5968 this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
5969
5970 var updates = Object.keys( this.reassigned )
5971 .map( function ( name ) { return ((aliases[ name ].outer) + " = " + (aliases[ name ].inner) + ";"); } );
5972
5973 if ( updates.length ) {
5974 if ( this.body.synthetic ) {
5975 code.appendLeft( this.body.body[0].end, ("; " + (updates.join(" "))) );
5976 } else {
5977 var lastStatement = this.body.body[ this.body.body.length - 1 ];
5978 code.appendLeft( lastStatement.end, ("\n\n" + i1 + (updates.join(("\n" + i1)))) );
5979 }
5980 }
5981 }
5982
5983 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
5984 };
5985
5986 return ForStatement;
5987}(LoopStatement));
5988
5989var ForInStatement = (function (LoopStatement$$1) {
5990 function ForInStatement () {
5991 LoopStatement$$1.apply(this, arguments);
5992 }
5993
5994 if ( LoopStatement$$1 ) ForInStatement.__proto__ = LoopStatement$$1;
5995 ForInStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
5996 ForInStatement.prototype.constructor = ForInStatement;
5997
5998 ForInStatement.prototype.findScope = function findScope ( functionScope ) {
5999 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
6000 };
6001
6002 ForInStatement.prototype.transpile = function transpile ( code, transforms ) {
6003 var this$1 = this;
6004
6005 if ( this.shouldRewriteAsFunction ) {
6006 // which variables are declared in the init statement?
6007 var names = this.left.type === 'VariableDeclaration' ?
6008 [].concat.apply( [], this.left.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
6009 [];
6010
6011 this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
6012 this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
6013 }
6014
6015 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
6016 };
6017
6018 return ForInStatement;
6019}(LoopStatement));
6020
6021var handlers = {
6022 Identifier: destructureIdentifier,
6023 AssignmentPattern: destructureAssignmentPattern,
6024 ArrayPattern: destructureArrayPattern,
6025 ObjectPattern: destructureObjectPattern
6026};
6027
6028function destructure ( code, scope, node, ref, inline, statementGenerators ) {
6029 handlers[ node.type ]( code, scope, node, ref, inline, statementGenerators );
6030}
6031
6032function destructureIdentifier ( code, scope, node, ref, inline, statementGenerators ) {
6033 statementGenerators.push( function ( start, prefix, suffix ) {
6034 code.prependRight( node.start, inline ? prefix : (prefix + "var ") );
6035 code.appendLeft( node.end, (" = " + ref + suffix) );
6036 code.move( node.start, node.end, start );
6037 });
6038}
6039
6040function destructureAssignmentPattern ( code, scope, node, ref, inline, statementGenerators ) {
6041 var isIdentifier = node.left.type === 'Identifier';
6042 var name = isIdentifier ? node.left.name : ref;
6043
6044 if ( !inline ) {
6045 statementGenerators.push( function ( start, prefix, suffix ) {
6046 code.prependRight( node.left.end, (prefix + "if ( " + name + " === void 0 ) " + name) );
6047 code.move( node.left.end, node.right.end, start );
6048 code.appendLeft( node.right.end, suffix );
6049 });
6050 }
6051
6052 if ( !isIdentifier ) {
6053 destructure( code, scope, node.left, ref, inline, statementGenerators );
6054 }
6055}
6056
6057function destructureArrayPattern ( code, scope, node, ref, inline, statementGenerators ) {
6058 var c = node.start;
6059
6060 node.elements.forEach( function ( element, i ) {
6061 if ( !element ) return;
6062
6063 if ( element.type === 'RestElement' ) {
6064 handleProperty( code, scope, c, element.argument, (ref + ".slice(" + i + ")"), inline, statementGenerators );
6065 } else {
6066 handleProperty( code, scope, c, element, (ref + "[" + i + "]"), inline, statementGenerators );
6067 }
6068 c = element.end;
6069 });
6070
6071 code.remove( c, node.end );
6072}
6073
6074function destructureObjectPattern ( code, scope, node, ref, inline, statementGenerators ) {
6075 var this$1 = this;
6076
6077 var c = node.start;
6078
6079 var nonRestKeys = [];
6080 node.properties.forEach( function ( prop ) {
6081 var value;
6082 var content;
6083 if (prop.type === "Property") {
6084 var isComputedKey = prop.computed || prop.key.type !== 'Identifier';
6085 var key = isComputedKey ? code.slice(prop.key.start, prop.key.end) : prop.key.name;
6086 value = isComputedKey ? (ref + "[" + key + "]") : (ref + "." + key);
6087 content = prop.value;
6088 nonRestKeys.push(isComputedKey ? key : '"' + key + '"');
6089 } else if (prop.type === "RestElement") {
6090 content = prop.argument;
6091 value = scope.createIdentifier( 'rest' );
6092 var n = scope.createIdentifier( 'n' );
6093 statementGenerators.push( function ( start, prefix, suffix ) {
6094 code.overwrite(prop.start, c = prop.argument.start, (prefix + "var " + value + " = {}; for (var " + n + " in " + ref + ") if([" + (nonRestKeys.join(", ")) + "].indexOf(" + n + ") === -1) " + value + "[" + n + "] = " + ref + "[" + n + "]" + suffix));
6095 code.move(prop.start, c, start);
6096 } );
6097 } else {
6098 throw new CompileError( this$1, ("Unexpected node of type " + (prop.type) + " in object pattern"))
6099 }
6100 handleProperty( code, scope, c, content, value, inline, statementGenerators );
6101 c = prop.end;
6102 });
6103
6104 code.remove( c, node.end );
6105}
6106
6107function handleProperty ( code, scope, c, node, value, inline, statementGenerators ) {
6108 switch ( node.type ) {
6109 case 'Identifier': {
6110 code.remove( c, node.start );
6111 destructureIdentifier( code, scope, node, value, inline, statementGenerators );
6112 break;
6113 }
6114
6115 case 'AssignmentPattern': {
6116 var name;
6117
6118 var isIdentifier = node.left.type === 'Identifier';
6119
6120 if ( isIdentifier ) {
6121 name = node.left.name;
6122 var declaration = scope.findDeclaration( name );
6123 if ( declaration ) name = declaration.name;
6124 } else {
6125 name = scope.createIdentifier( value );
6126 }
6127
6128 statementGenerators.push( function ( start, prefix, suffix ) {
6129 if ( inline ) {
6130 code.prependRight( node.right.start, (name + " = " + value + " === undefined ? ") );
6131 code.appendLeft( node.right.end, (" : " + value) );
6132 } else {
6133 code.prependRight( node.right.start, (prefix + "var " + name + " = " + value + "; if ( " + name + " === void 0 ) " + name + " = ") );
6134 code.appendLeft( node.right.end, suffix );
6135 }
6136
6137 code.move( node.right.start, node.right.end, start );
6138 });
6139
6140 if ( isIdentifier ) {
6141 code.remove( c, node.right.start );
6142 } else {
6143 code.remove( c, node.left.start );
6144 code.remove( node.left.end, node.right.start );
6145 handleProperty( code, scope, c, node.left, name, inline, statementGenerators );
6146 }
6147
6148 break;
6149 }
6150
6151 case 'ObjectPattern': {
6152 code.remove( c, c = node.start );
6153
6154 var ref = value;
6155 if ( node.properties.length > 1 ) {
6156 ref = scope.createIdentifier( value );
6157
6158 statementGenerators.push( function ( start, prefix, suffix ) {
6159 // this feels a tiny bit hacky, but we can't do a
6160 // straightforward appendLeft and keep correct order...
6161 code.prependRight( node.start, (prefix + "var " + ref + " = ") );
6162 code.overwrite( node.start, c = node.start + 1, value );
6163 code.appendLeft( c, suffix );
6164
6165 code.overwrite( node.start, c = node.start + 1, (prefix + "var " + ref + " = " + value + suffix) );
6166 code.move( node.start, c, start );
6167 });
6168 }
6169
6170 destructureObjectPattern( code, scope, node, ref, inline, statementGenerators );
6171
6172 break;
6173 }
6174
6175 case 'ArrayPattern': {
6176 code.remove( c, c = node.start );
6177
6178 if ( node.elements.filter( Boolean ).length > 1 ) {
6179 var ref$1 = scope.createIdentifier( value );
6180
6181 statementGenerators.push( function ( start, prefix, suffix ) {
6182 code.prependRight( node.start, (prefix + "var " + ref$1 + " = ") );
6183 code.overwrite( node.start, c = node.start + 1, value, { contentOnly: true });
6184 code.appendLeft( c, suffix );
6185
6186 code.move( node.start, c, start );
6187 });
6188
6189 node.elements.forEach( function ( element, i ) {
6190 if ( !element ) return;
6191
6192 if ( element.type === 'RestElement' ) {
6193 handleProperty( code, scope, c, element.argument, (ref$1 + ".slice(" + i + ")"), inline, statementGenerators );
6194 } else {
6195 handleProperty( code, scope, c, element, (ref$1 + "[" + i + "]"), inline, statementGenerators );
6196 }
6197 c = element.end;
6198 });
6199 } else {
6200 var index = findIndex( node.elements, Boolean );
6201 var element = node.elements[ index ];
6202 if ( element.type === 'RestElement' ) {
6203 handleProperty( code, scope, c, element.argument, (value + ".slice(" + index + ")"), inline, statementGenerators );
6204 } else {
6205 handleProperty( code, scope, c, element, (value + "[" + index + "]"), inline, statementGenerators );
6206 }
6207 c = element.end;
6208 }
6209
6210 code.remove( c, node.end );
6211 break;
6212 }
6213
6214 default: {
6215 throw new Error( ("Unexpected node type in destructuring (" + (node.type) + ")") );
6216 }
6217 }
6218}
6219
6220var ForOfStatement = (function (LoopStatement$$1) {
6221 function ForOfStatement () {
6222 LoopStatement$$1.apply(this, arguments);
6223 }
6224
6225 if ( LoopStatement$$1 ) ForOfStatement.__proto__ = LoopStatement$$1;
6226 ForOfStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
6227 ForOfStatement.prototype.constructor = ForOfStatement;
6228
6229 ForOfStatement.prototype.initialise = function initialise ( transforms ) {
6230 if ( transforms.forOf && !transforms.dangerousForOf ) throw new CompileError$1( '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', this );
6231 LoopStatement$$1.prototype.initialise.call( this, transforms );
6232 };
6233
6234 ForOfStatement.prototype.transpile = function transpile ( code, transforms ) {
6235 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
6236 if ( !transforms.dangerousForOf ) return;
6237
6238 // edge case (#80)
6239 if ( !this.body.body[0] ) {
6240 if ( this.left.type === 'VariableDeclaration' && this.left.kind === 'var' ) {
6241 code.remove( this.start, this.left.start );
6242 code.appendLeft( this.left.end, ';' );
6243 code.remove( this.left.end, this.end );
6244 } else {
6245 code.remove( this.start, this.end );
6246 }
6247
6248 return;
6249 }
6250
6251 var scope = this.findScope( true );
6252 var i0 = this.getIndentation();
6253 var i1 = i0 + code.getIndentString();
6254
6255 var key = scope.createIdentifier( 'i' );
6256 var list = scope.createIdentifier( 'list' );
6257
6258 if ( this.body.synthetic ) {
6259 code.prependRight( this.left.start, ("{\n" + i1) );
6260 code.appendLeft( this.body.body[0].end, ("\n" + i0 + "}") );
6261 }
6262
6263 var bodyStart = this.body.body[0].start;
6264
6265 code.remove( this.left.end, this.right.start );
6266 code.move( this.left.start, this.left.end, bodyStart );
6267
6268
6269 code.prependRight( this.right.start, ("var " + key + " = 0, " + list + " = ") );
6270 code.appendLeft( this.right.end, ("; " + key + " < " + list + ".length; " + key + " += 1") );
6271
6272 // destructuring. TODO non declaration destructuring
6273 var declarator = this.left.type === 'VariableDeclaration' && this.left.declarations[0];
6274 if ( declarator && declarator.id.type !== 'Identifier' ) {
6275 var statementGenerators = [];
6276 var ref = scope.createIdentifier( 'ref' );
6277 destructure( code, scope, declarator.id, ref, false, statementGenerators );
6278
6279 var suffix = ";\n" + i1;
6280 statementGenerators.forEach( function ( fn, i ) {
6281 if ( i === statementGenerators.length - 1 ) {
6282 suffix = ";\n\n" + i1;
6283 }
6284
6285 fn( bodyStart, '', suffix );
6286 });
6287
6288 code.appendLeft( this.left.start + this.left.kind.length + 1, ref );
6289 code.appendLeft( this.left.end, (" = " + list + "[" + key + "];\n" + i1) );
6290 } else {
6291 code.appendLeft( this.left.end, (" = " + list + "[" + key + "];\n\n" + i1) );
6292 }
6293 };
6294
6295 return ForOfStatement;
6296}(LoopStatement));
6297
6298var FunctionDeclaration = (function (Node) {
6299 function FunctionDeclaration () {
6300 Node.apply(this, arguments);
6301 }
6302
6303 if ( Node ) FunctionDeclaration.__proto__ = Node;
6304 FunctionDeclaration.prototype = Object.create( Node && Node.prototype );
6305 FunctionDeclaration.prototype.constructor = FunctionDeclaration;
6306
6307 FunctionDeclaration.prototype.initialise = function initialise ( transforms ) {
6308 if ( this.generator && transforms.generator ) {
6309 throw new CompileError$1( 'Generators are not supported', this );
6310 }
6311
6312 this.body.createScope();
6313
6314 this.findScope( true ).addDeclaration( this.id, 'function' );
6315 Node.prototype.initialise.call( this, transforms );
6316 };
6317
6318 return FunctionDeclaration;
6319}(Node$1));
6320
6321var FunctionExpression = (function (Node) {
6322 function FunctionExpression () {
6323 Node.apply(this, arguments);
6324 }
6325
6326 if ( Node ) FunctionExpression.__proto__ = Node;
6327 FunctionExpression.prototype = Object.create( Node && Node.prototype );
6328 FunctionExpression.prototype.constructor = FunctionExpression;
6329
6330 FunctionExpression.prototype.initialise = function initialise ( transforms ) {
6331 if ( this.generator && transforms.generator ) {
6332 throw new CompileError$1( 'Generators are not supported', this );
6333 }
6334
6335 this.body.createScope();
6336
6337 if ( this.id ) {
6338 // function expression IDs belong to the child scope...
6339 this.body.scope.addDeclaration( this.id, 'function' );
6340 }
6341
6342 Node.prototype.initialise.call( this, transforms );
6343
6344 var parent = this.parent;
6345 var methodName;
6346
6347 if ( transforms.conciseMethodProperty
6348 && parent.type === 'Property'
6349 && parent.kind === 'init'
6350 && parent.method
6351 && parent.key.type === 'Identifier' ) {
6352 // object literal concise method
6353 methodName = parent.key.name;
6354 }
6355 else if ( transforms.classes
6356 && parent.type === 'MethodDefinition'
6357 && parent.kind === 'method'
6358 && parent.key.type === 'Identifier' ) {
6359 // method definition in a class
6360 methodName = parent.key.name;
6361 }
6362 else if ( this.id && this.id.type === 'Identifier' ) {
6363 // naked function expression
6364 methodName = this.id.alias || this.id.name;
6365 }
6366
6367 if ( methodName ) {
6368 for ( var i = 0, list = this.params; i < list.length; i += 1 ) {
6369 var param = list[i];
6370
6371 if ( param.type === 'Identifier' && methodName === param.name ) {
6372 // workaround for Safari 9/WebKit bug:
6373 // https://gitlab.com/Rich-Harris/buble/issues/154
6374 // change parameter name when same as method name
6375
6376 var scope = this.body.scope;
6377 var declaration = scope.declarations[ methodName ];
6378
6379 var alias = scope.createIdentifier( methodName );
6380 param.alias = alias;
6381
6382 for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
6383 var identifier = list$1[i$1];
6384
6385 identifier.alias = alias;
6386 }
6387
6388 break;
6389 }
6390 }
6391 }
6392 };
6393
6394 return FunctionExpression;
6395}(Node$1));
6396
6397function isReference ( node, parent ) {
6398 if ( node.type === 'MemberExpression' ) {
6399 return !node.computed && isReference( node.object, node );
6400 }
6401
6402 if ( node.type === 'Identifier' ) {
6403 // the only time we could have an identifier node without a parent is
6404 // if it's the entire body of a function without a block statement –
6405 // i.e. an arrow function expression like `a => a`
6406 if ( !parent ) return true;
6407
6408 if ( /(Function|Class)Expression/.test( parent.type ) ) return false;
6409
6410 if ( parent.type === 'VariableDeclarator' ) return node === parent.init;
6411
6412 // TODO is this right?
6413 if ( parent.type === 'MemberExpression' || parent.type === 'MethodDefinition' ) {
6414 return parent.computed || node === parent.object;
6415 }
6416
6417 if ( parent.type === 'ArrayPattern' ) return false;
6418
6419 // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
6420 if ( parent.type === 'Property' ) {
6421 if ( parent.parent.type === 'ObjectPattern' ) return false;
6422 return parent.computed || node === parent.value;
6423 }
6424
6425 // disregard the `bar` in `class Foo { bar () {...} }`
6426 if ( parent.type === 'MethodDefinition' ) return false;
6427
6428 // disregard the `bar` in `export { foo as bar }`
6429 if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return false;
6430
6431 return true;
6432 }
6433}
6434
6435var Identifier = (function (Node) {
6436 function Identifier () {
6437 Node.apply(this, arguments);
6438 }
6439
6440 if ( Node ) Identifier.__proto__ = Node;
6441 Identifier.prototype = Object.create( Node && Node.prototype );
6442 Identifier.prototype.constructor = Identifier;
6443
6444 Identifier.prototype.findScope = function findScope ( functionScope ) {
6445 if ( this.parent.params && ~this.parent.params.indexOf( this ) ) {
6446 return this.parent.body.scope;
6447 }
6448
6449 if ( this.parent.type === 'FunctionExpression' && this === this.parent.id ) {
6450 return this.parent.body.scope;
6451 }
6452
6453 return this.parent.findScope( functionScope );
6454 };
6455
6456 Identifier.prototype.initialise = function initialise ( transforms ) {
6457 if ( transforms.arrow && isReference( this, this.parent ) ) {
6458 if ( this.name === 'arguments' && !this.findScope( false ).contains( this.name ) ) {
6459 var lexicalBoundary = this.findLexicalBoundary();
6460 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
6461 var loop = this.findNearest( loopStatement );
6462
6463 if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
6464 this.alias = lexicalBoundary.getArgumentsAlias();
6465 }
6466
6467 if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
6468 this.alias = lexicalBoundary.getArgumentsAlias();
6469 }
6470 }
6471
6472 this.findScope( false ).addReference( this );
6473 }
6474 };
6475
6476 Identifier.prototype.transpile = function transpile ( code ) {
6477 if ( this.alias ) {
6478 code.overwrite( this.start, this.end, this.alias, { storeName: true, contentOnly: true });
6479 }
6480 };
6481
6482 return Identifier;
6483}(Node$1));
6484
6485var IfStatement = (function (Node) {
6486 function IfStatement () {
6487 Node.apply(this, arguments);
6488 }
6489
6490 if ( Node ) IfStatement.__proto__ = Node;
6491 IfStatement.prototype = Object.create( Node && Node.prototype );
6492 IfStatement.prototype.constructor = IfStatement;
6493
6494 IfStatement.prototype.initialise = function initialise ( transforms ) {
6495 Node.prototype.initialise.call( this, transforms );
6496 };
6497
6498 IfStatement.prototype.transpile = function transpile ( code, transforms ) {
6499 if ( this.consequent.type !== 'BlockStatement'
6500 || this.consequent.type === 'BlockStatement' && this.consequent.synthetic ) {
6501 code.appendLeft( this.consequent.start, '{ ' );
6502 code.prependRight( this.consequent.end, ' }' );
6503 }
6504
6505 if ( this.alternate && this.alternate.type !== 'IfStatement' && (
6506 this.alternate.type !== 'BlockStatement'
6507 || this.alternate.type === 'BlockStatement' && this.alternate.synthetic ) ) {
6508 code.appendLeft( this.alternate.start, '{ ' );
6509 code.prependRight( this.alternate.end, ' }' );
6510 }
6511
6512 Node.prototype.transpile.call( this, code, transforms );
6513 };
6514
6515 return IfStatement;
6516}(Node$1));
6517
6518var ImportDeclaration = (function (Node) {
6519 function ImportDeclaration () {
6520 Node.apply(this, arguments);
6521 }
6522
6523 if ( Node ) ImportDeclaration.__proto__ = Node;
6524 ImportDeclaration.prototype = Object.create( Node && Node.prototype );
6525 ImportDeclaration.prototype.constructor = ImportDeclaration;
6526
6527 ImportDeclaration.prototype.initialise = function initialise ( transforms ) {
6528 if ( transforms.moduleImport ) throw new CompileError$1( 'import is not supported', this );
6529 Node.prototype.initialise.call( this, transforms );
6530 };
6531
6532 return ImportDeclaration;
6533}(Node$1));
6534
6535var ImportDefaultSpecifier = (function (Node) {
6536 function ImportDefaultSpecifier () {
6537 Node.apply(this, arguments);
6538 }
6539
6540 if ( Node ) ImportDefaultSpecifier.__proto__ = Node;
6541 ImportDefaultSpecifier.prototype = Object.create( Node && Node.prototype );
6542 ImportDefaultSpecifier.prototype.constructor = ImportDefaultSpecifier;
6543
6544 ImportDefaultSpecifier.prototype.initialise = function initialise ( transforms ) {
6545 this.findScope( true ).addDeclaration( this.local, 'import' );
6546 Node.prototype.initialise.call( this, transforms );
6547 };
6548
6549 return ImportDefaultSpecifier;
6550}(Node$1));
6551
6552var ImportSpecifier = (function (Node) {
6553 function ImportSpecifier () {
6554 Node.apply(this, arguments);
6555 }
6556
6557 if ( Node ) ImportSpecifier.__proto__ = Node;
6558 ImportSpecifier.prototype = Object.create( Node && Node.prototype );
6559 ImportSpecifier.prototype.constructor = ImportSpecifier;
6560
6561 ImportSpecifier.prototype.initialise = function initialise ( transforms ) {
6562 this.findScope( true ).addDeclaration( this.local, 'import' );
6563 Node.prototype.initialise.call( this, transforms );
6564 };
6565
6566 return ImportSpecifier;
6567}(Node$1));
6568
6569var hasDashes = function ( val ) { return /-/.test(val); };
6570
6571var formatKey = function ( key ) { return hasDashes(key) ? ("'" + key + "'") : key; };
6572
6573var formatVal = function ( val ) { return val ? '' : 'true'; };
6574
6575var JSXAttribute = (function (Node) {
6576 function JSXAttribute () {
6577 Node.apply(this, arguments);
6578 }
6579
6580 if ( Node ) JSXAttribute.__proto__ = Node;
6581 JSXAttribute.prototype = Object.create( Node && Node.prototype );
6582 JSXAttribute.prototype.constructor = JSXAttribute;
6583
6584 JSXAttribute.prototype.transpile = function transpile ( code, transforms ) {
6585 var ref = this.name;
6586 var start = ref.start;
6587 var name = ref.name;
6588
6589 // Overwrite equals sign if value is present.
6590 var end = this.value ? this.value.start : this.name.end;
6591
6592 code.overwrite( start, end, ((formatKey(name)) + ": " + (formatVal(this.value))) );
6593
6594 Node.prototype.transpile.call( this, code, transforms );
6595 };
6596
6597 return JSXAttribute;
6598}(Node$1));
6599
6600function containsNewLine ( node ) {
6601 return node.type === 'Literal' && !/\S/.test( node.value ) && /\n/.test( node.value );
6602}
6603
6604var JSXClosingElement = (function (Node) {
6605 function JSXClosingElement () {
6606 Node.apply(this, arguments);
6607 }
6608
6609 if ( Node ) JSXClosingElement.__proto__ = Node;
6610 JSXClosingElement.prototype = Object.create( Node && Node.prototype );
6611 JSXClosingElement.prototype.constructor = JSXClosingElement;
6612
6613 JSXClosingElement.prototype.transpile = function transpile ( code ) {
6614 var spaceBeforeParen = true;
6615
6616 var lastChild = this.parent.children[ this.parent.children.length - 1 ];
6617
6618 // omit space before closing paren if
6619 // a) this is on a separate line, or
6620 // b) there are no children but there are attributes
6621 if ( ( lastChild && containsNewLine( lastChild ) ) || ( this.parent.openingElement.attributes.length ) ) {
6622 spaceBeforeParen = false;
6623 }
6624
6625 code.overwrite( this.start, this.end, spaceBeforeParen ? ' )' : ')' );
6626 };
6627
6628 return JSXClosingElement;
6629}(Node$1));
6630
6631function normalise ( str, removeTrailingWhitespace ) {
6632 if ( removeTrailingWhitespace && /\n/.test( str ) ) {
6633 str = str.replace( /\s+$/, '' );
6634 }
6635
6636 str = str
6637 .replace( /^\n\r?\s+/, '' ) // remove leading newline + space
6638 .replace( /\s*\n\r?\s*/gm, ' ' ); // replace newlines with spaces
6639
6640 // TODO prefer single quotes?
6641 return JSON.stringify( str );
6642}
6643
6644var JSXElement = (function (Node) {
6645 function JSXElement () {
6646 Node.apply(this, arguments);
6647 }
6648
6649 if ( Node ) JSXElement.__proto__ = Node;
6650 JSXElement.prototype = Object.create( Node && Node.prototype );
6651 JSXElement.prototype.constructor = JSXElement;
6652
6653 JSXElement.prototype.transpile = function transpile ( code, transforms ) {
6654 Node.prototype.transpile.call( this, code, transforms );
6655
6656 var children = this.children.filter( function ( child ) {
6657 if ( child.type !== 'Literal' ) return true;
6658
6659 // remove whitespace-only literals, unless on a single line
6660 return /\S/.test( child.value ) || !/\n/.test( child.value );
6661 });
6662
6663 if ( children.length ) {
6664 var c = this.openingElement.end;
6665
6666 var i;
6667 for ( i = 0; i < children.length; i += 1 ) {
6668 var child = children[i];
6669
6670 if ( child.type === 'JSXExpressionContainer' && child.expression.type === 'JSXEmptyExpression' ) {
6671 // empty block is a no op
6672 } else {
6673 var tail = code.original[ c ] === '\n' && child.type !== 'Literal' ? '' : ' ';
6674 code.appendLeft( c, ("," + tail) );
6675 }
6676
6677 if ( child.type === 'Literal' ) {
6678 var str = normalise( child.value, i === children.length - 1 );
6679 code.overwrite( child.start, child.end, str );
6680 }
6681
6682 c = child.end;
6683 }
6684 }
6685 };
6686
6687 return JSXElement;
6688}(Node$1));
6689
6690var JSXExpressionContainer = (function (Node) {
6691 function JSXExpressionContainer () {
6692 Node.apply(this, arguments);
6693 }
6694
6695 if ( Node ) JSXExpressionContainer.__proto__ = Node;
6696 JSXExpressionContainer.prototype = Object.create( Node && Node.prototype );
6697 JSXExpressionContainer.prototype.constructor = JSXExpressionContainer;
6698
6699 JSXExpressionContainer.prototype.transpile = function transpile ( code, transforms ) {
6700 code.remove( this.start, this.expression.start );
6701 code.remove( this.expression.end, this.end );
6702
6703 Node.prototype.transpile.call( this, code, transforms );
6704 };
6705
6706 return JSXExpressionContainer;
6707}(Node$1));
6708
6709var JSXOpeningElement = (function (Node) {
6710 function JSXOpeningElement () {
6711 Node.apply(this, arguments);
6712 }
6713
6714 if ( Node ) JSXOpeningElement.__proto__ = Node;
6715 JSXOpeningElement.prototype = Object.create( Node && Node.prototype );
6716 JSXOpeningElement.prototype.constructor = JSXOpeningElement;
6717
6718 JSXOpeningElement.prototype.transpile = function transpile ( code, transforms ) {
6719 var this$1 = this;
6720
6721 Node.prototype.transpile.call( this, code, transforms );
6722
6723 code.overwrite( this.start, this.name.start, ((this.program.jsx) + "( ") );
6724
6725 var html = this.name.type === 'JSXIdentifier' && this.name.name[0] === this.name.name[0].toLowerCase();
6726 if ( html ) code.prependRight( this.name.start, "'" );
6727
6728 var len = this.attributes.length;
6729 var c = this.name.end;
6730
6731 if ( len ) {
6732 var i;
6733
6734 var hasSpread = false;
6735 for ( i = 0; i < len; i += 1 ) {
6736 if ( this$1.attributes[i].type === 'JSXSpreadAttribute' ) {
6737 hasSpread = true;
6738 break;
6739 }
6740 }
6741
6742 c = this.attributes[0].end;
6743
6744 for ( i = 0; i < len; i += 1 ) {
6745 var attr = this$1.attributes[i];
6746
6747 if ( i > 0 ) {
6748 if ( attr.start === c )
6749 code.prependRight( c, ', ' );
6750 else
6751 code.overwrite( c, attr.start, ', ' );
6752 }
6753
6754 if ( hasSpread && attr.type !== 'JSXSpreadAttribute' ) {
6755 var lastAttr = this$1.attributes[ i - 1 ];
6756 var nextAttr = this$1.attributes[ i + 1 ];
6757
6758 if ( !lastAttr || lastAttr.type === 'JSXSpreadAttribute' ) {
6759 code.prependRight( attr.start, '{ ' );
6760 }
6761
6762 if ( !nextAttr || nextAttr.type === 'JSXSpreadAttribute' ) {
6763 code.appendLeft( attr.end, ' }' );
6764 }
6765 }
6766
6767 c = attr.end;
6768 }
6769
6770 var after;
6771 var before;
6772 if ( hasSpread ) {
6773 if ( len === 1 ) {
6774 before = html ? "'," : ',';
6775 } else {
6776 if (!this.program.options.objectAssign) {
6777 throw new CompileError$1( 'Mixed JSX attributes ending in spread requires specified objectAssign option with \'Object.assign\' or polyfill helper.', this );
6778 }
6779 before = html ? ("', " + (this.program.options.objectAssign) + "({},") : (", " + (this.program.options.objectAssign) + "({},");
6780 after = ')';
6781 }
6782 } else {
6783 before = html ? "', {" : ', {';
6784 after = ' }';
6785 }
6786
6787 code.prependRight( this.name.end, before );
6788
6789 if ( after ) {
6790 code.appendLeft( this.attributes[ len - 1 ].end, after );
6791 }
6792 } else {
6793 code.appendLeft( this.name.end, html ? "', null" : ", null" );
6794 c = this.name.end;
6795 }
6796
6797 if ( this.selfClosing ) {
6798 code.overwrite( c, this.end, this.attributes.length ? ")" : " )" );
6799 } else {
6800 code.remove( c, this.end );
6801 }
6802 };
6803
6804 return JSXOpeningElement;
6805}(Node$1));
6806
6807var JSXSpreadAttribute = (function (Node) {
6808 function JSXSpreadAttribute () {
6809 Node.apply(this, arguments);
6810 }
6811
6812 if ( Node ) JSXSpreadAttribute.__proto__ = Node;
6813 JSXSpreadAttribute.prototype = Object.create( Node && Node.prototype );
6814 JSXSpreadAttribute.prototype.constructor = JSXSpreadAttribute;
6815
6816 JSXSpreadAttribute.prototype.transpile = function transpile ( code, transforms ) {
6817 code.remove( this.start, this.argument.start );
6818 code.remove( this.argument.end, this.end );
6819
6820 Node.prototype.transpile.call( this, code, transforms );
6821 };
6822
6823 return JSXSpreadAttribute;
6824}(Node$1));
6825
6826var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6827
6828function commonjsRequire () {
6829 throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
6830}
6831
6832
6833
6834function createCommonjsModule(fn, module) {
6835 return module = { exports: {} }, fn(module, module.exports), module.exports;
6836}
6837
6838var regjsgen = createCommonjsModule(function (module, exports) {
6839/*!
6840 * regjsgen 0.3.0
6841 * Copyright 2014-2016 Benjamin Tan <https://demoneaux.github.io/>
6842 * Available under MIT license <https://github.com/demoneaux/regjsgen/blob/master/LICENSE>
6843 */
6844(function() {
6845 'use strict';
6846
6847 // Used to determine if values are of the language type `Object`.
6848 var objectTypes = {
6849 'function': true,
6850 'object': true
6851 };
6852
6853 // Used as a reference to the global object.
6854 var root = (objectTypes[typeof window] && window) || this;
6855
6856 // Detect free variable `exports`.
6857 var freeExports = objectTypes['object'] && exports;
6858
6859 // Detect free variable `module`.
6860 var freeModule = objectTypes['object'] && module && !module.nodeType && module;
6861
6862 // Detect free variable `global` from Node.js or Browserified code and use it as `root`.
6863 var freeGlobal = freeExports && freeModule && typeof commonjsGlobal == 'object' && commonjsGlobal;
6864 if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
6865 root = freeGlobal;
6866 }
6867
6868 // Used to check objects for own properties.
6869 var hasOwnProperty = Object.prototype.hasOwnProperty;
6870
6871 /*--------------------------------------------------------------------------*/
6872
6873 // Generates strings based on the given code points.
6874 // Based on https://mths.be/fromcodepoint v0.2.0 by @mathias.
6875 var stringFromCharCode = String.fromCharCode;
6876 var floor = Math.floor;
6877 function fromCodePoint() {
6878 var MAX_SIZE = 0x4000;
6879 var codeUnits = [];
6880 var highSurrogate;
6881 var lowSurrogate;
6882 var index = -1;
6883 var length = arguments.length;
6884 if (!length) {
6885 return '';
6886 }
6887 var result = '';
6888 while (++index < length) {
6889 var codePoint = Number(arguments[index]);
6890 if (
6891 !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
6892 codePoint < 0 || // not a valid Unicode code point
6893 codePoint > 0x10FFFF || // not a valid Unicode code point
6894 floor(codePoint) != codePoint // not an integer
6895 ) {
6896 throw RangeError('Invalid code point: ' + codePoint);
6897 }
6898 if (codePoint <= 0xFFFF) {
6899 // BMP code point
6900 codeUnits.push(codePoint);
6901 } else {
6902 // Astral code point; split in surrogate halves
6903 // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
6904 codePoint -= 0x10000;
6905 highSurrogate = (codePoint >> 10) + 0xD800;
6906 lowSurrogate = (codePoint % 0x400) + 0xDC00;
6907 codeUnits.push(highSurrogate, lowSurrogate);
6908 }
6909 if (index + 1 == length || codeUnits.length > MAX_SIZE) {
6910 result += stringFromCharCode.apply(null, codeUnits);
6911 codeUnits.length = 0;
6912 }
6913 }
6914 return result;
6915 }
6916
6917 /*--------------------------------------------------------------------------*/
6918
6919 // Ensures that nodes have the correct types.
6920 var assertTypeRegexMap = {};
6921 function assertType(type, expected) {
6922 if (expected.indexOf('|') == -1) {
6923 if (type == expected) {
6924 return;
6925 }
6926
6927 throw Error('Invalid node type: ' + type + '; expected type: ' + expected);
6928 }
6929
6930 expected = hasOwnProperty.call(assertTypeRegexMap, expected)
6931 ? assertTypeRegexMap[expected]
6932 : (assertTypeRegexMap[expected] = RegExp('^(?:' + expected + ')$'));
6933
6934 if (expected.test(type)) {
6935 return;
6936 }
6937
6938 throw Error('Invalid node type: ' + type + '; expected types: ' + expected);
6939 }
6940
6941 /*--------------------------------------------------------------------------*/
6942
6943 // Generates a regular expression string based on an AST.
6944 function generate(node) {
6945 var type = node.type;
6946
6947 if (hasOwnProperty.call(generators, type)) {
6948 return generators[type](node);
6949 }
6950
6951 throw Error('Invalid node type: ' + type);
6952 }
6953
6954 /*--------------------------------------------------------------------------*/
6955
6956 function generateAlternative(node) {
6957 assertType(node.type, 'alternative');
6958
6959 var terms = node.body,
6960 i = -1,
6961 length = terms.length,
6962 result = '';
6963
6964 while (++i < length) {
6965 result += generateTerm(terms[i]);
6966 }
6967
6968 return result;
6969 }
6970
6971 function generateAnchor(node) {
6972 assertType(node.type, 'anchor');
6973
6974 switch (node.kind) {
6975 case 'start':
6976 return '^';
6977 case 'end':
6978 return '$';
6979 case 'boundary':
6980 return '\\b';
6981 case 'not-boundary':
6982 return '\\B';
6983 default:
6984 throw Error('Invalid assertion');
6985 }
6986 }
6987
6988 function generateAtom(node) {
6989 assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
6990
6991 return generate(node);
6992 }
6993
6994 function generateCharacterClass(node) {
6995 assertType(node.type, 'characterClass');
6996
6997 var classRanges = node.body,
6998 i = -1,
6999 length = classRanges.length,
7000 result = '';
7001
7002 if (node.negative) {
7003 result += '^';
7004 }
7005
7006 while (++i < length) {
7007 result += generateClassAtom(classRanges[i]);
7008 }
7009
7010 return '[' + result + ']';
7011 }
7012
7013 function generateCharacterClassEscape(node) {
7014 assertType(node.type, 'characterClassEscape');
7015
7016 return '\\' + node.value;
7017 }
7018
7019 function generateUnicodePropertyEscape(node) {
7020 assertType(node.type, 'unicodePropertyEscape');
7021
7022 return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
7023 }
7024
7025 function generateCharacterClassRange(node) {
7026 assertType(node.type, 'characterClassRange');
7027
7028 var min = node.min,
7029 max = node.max;
7030
7031 if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
7032 throw Error('Invalid character class range');
7033 }
7034
7035 return generateClassAtom(min) + '-' + generateClassAtom(max);
7036 }
7037
7038 function generateClassAtom(node) {
7039 assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value');
7040
7041 return generate(node);
7042 }
7043
7044 function generateDisjunction(node) {
7045 assertType(node.type, 'disjunction');
7046
7047 var body = node.body,
7048 i = -1,
7049 length = body.length,
7050 result = '';
7051
7052 while (++i < length) {
7053 if (i != 0) {
7054 result += '|';
7055 }
7056 result += generate(body[i]);
7057 }
7058
7059 return result;
7060 }
7061
7062 function generateDot(node) {
7063 assertType(node.type, 'dot');
7064
7065 return '.';
7066 }
7067
7068 function generateGroup(node) {
7069 assertType(node.type, 'group');
7070
7071 var result = '';
7072
7073 switch (node.behavior) {
7074 case 'normal':
7075 break;
7076 case 'ignore':
7077 result += '?:';
7078 break;
7079 case 'lookahead':
7080 result += '?=';
7081 break;
7082 case 'negativeLookahead':
7083 result += '?!';
7084 break;
7085 default:
7086 throw Error('Invalid behaviour: ' + node.behaviour);
7087 }
7088
7089 var body = node.body,
7090 i = -1,
7091 length = body.length;
7092
7093 while (++i < length) {
7094 result += generate(body[i]);
7095 }
7096
7097 return '(' + result + ')';
7098 }
7099
7100 function generateQuantifier(node) {
7101 assertType(node.type, 'quantifier');
7102
7103 var quantifier = '',
7104 min = node.min,
7105 max = node.max;
7106
7107 if (max == null) {
7108 if (min == 0) {
7109 quantifier = '*';
7110 } else if (min == 1) {
7111 quantifier = '+';
7112 } else {
7113 quantifier = '{' + min + ',}';
7114 }
7115 } else if (min == max) {
7116 quantifier = '{' + min + '}';
7117 } else if (min == 0 && max == 1) {
7118 quantifier = '?';
7119 } else {
7120 quantifier = '{' + min + ',' + max + '}';
7121 }
7122
7123 if (!node.greedy) {
7124 quantifier += '?';
7125 }
7126
7127 return generateAtom(node.body[0]) + quantifier;
7128 }
7129
7130 function generateReference(node) {
7131 assertType(node.type, 'reference');
7132
7133 return '\\' + node.matchIndex;
7134 }
7135
7136 function generateTerm(node) {
7137 assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value');
7138
7139 return generate(node);
7140 }
7141
7142 function generateValue(node) {
7143 assertType(node.type, 'value');
7144
7145 var kind = node.kind,
7146 codePoint = node.codePoint;
7147
7148 switch (kind) {
7149 case 'controlLetter':
7150 return '\\c' + fromCodePoint(codePoint + 64);
7151 case 'hexadecimalEscape':
7152 return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
7153 case 'identifier':
7154 return '\\' + fromCodePoint(codePoint);
7155 case 'null':
7156 return '\\' + codePoint;
7157 case 'octal':
7158 return '\\' + codePoint.toString(8);
7159 case 'singleEscape':
7160 switch (codePoint) {
7161 case 0x0008:
7162 return '\\b';
7163 case 0x0009:
7164 return '\\t';
7165 case 0x000A:
7166 return '\\n';
7167 case 0x000B:
7168 return '\\v';
7169 case 0x000C:
7170 return '\\f';
7171 case 0x000D:
7172 return '\\r';
7173 default:
7174 throw Error('Invalid codepoint: ' + codePoint);
7175 }
7176 case 'symbol':
7177 return fromCodePoint(codePoint);
7178 case 'unicodeEscape':
7179 return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
7180 case 'unicodeCodePointEscape':
7181 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
7182 default:
7183 throw Error('Unsupported node kind: ' + kind);
7184 }
7185 }
7186
7187 /*--------------------------------------------------------------------------*/
7188
7189 // Used to generate strings for each node type.
7190 var generators = {
7191 'alternative': generateAlternative,
7192 'anchor': generateAnchor,
7193 'characterClass': generateCharacterClass,
7194 'characterClassEscape': generateCharacterClassEscape,
7195 'characterClassRange': generateCharacterClassRange,
7196 'unicodePropertyEscape': generateUnicodePropertyEscape,
7197 'disjunction': generateDisjunction,
7198 'dot': generateDot,
7199 'group': generateGroup,
7200 'quantifier': generateQuantifier,
7201 'reference': generateReference,
7202 'value': generateValue
7203 };
7204
7205 /*--------------------------------------------------------------------------*/
7206
7207 // Export regjsgen.
7208 // Some AMD build optimizers, like r.js, check for condition patterns like the following:
7209 if (typeof undefined == 'function' && typeof undefined.amd == 'object' && undefined.amd) {
7210 // Define as an anonymous module so it can be aliased through path mapping.
7211 undefined(function() {
7212 return {
7213 'generate': generate
7214 };
7215 });
7216 }
7217 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
7218 else if (freeExports && freeModule) {
7219 // Export for CommonJS support.
7220 freeExports.generate = generate;
7221 }
7222 else {
7223 // Export to the global object.
7224 root.regjsgen = {
7225 'generate': generate
7226 };
7227 }
7228}.call(commonjsGlobal));
7229});
7230
7231var parser = createCommonjsModule(function (module) {
7232// regjsparser
7233//
7234// ==================================================================
7235//
7236// See ECMA-262 Standard: 15.10.1
7237//
7238// NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the
7239// term "Anchor" is used.
7240//
7241// Pattern ::
7242// Disjunction
7243//
7244// Disjunction ::
7245// Alternative
7246// Alternative | Disjunction
7247//
7248// Alternative ::
7249// [empty]
7250// Alternative Term
7251//
7252// Term ::
7253// Anchor
7254// Atom
7255// Atom Quantifier
7256//
7257// Anchor ::
7258// ^
7259// $
7260// \ b
7261// \ B
7262// ( ? = Disjunction )
7263// ( ? ! Disjunction )
7264//
7265// Quantifier ::
7266// QuantifierPrefix
7267// QuantifierPrefix ?
7268//
7269// QuantifierPrefix ::
7270// *
7271// +
7272// ?
7273// { DecimalDigits }
7274// { DecimalDigits , }
7275// { DecimalDigits , DecimalDigits }
7276//
7277// Atom ::
7278// PatternCharacter
7279// .
7280// \ AtomEscape
7281// CharacterClass
7282// ( Disjunction )
7283// ( ? : Disjunction )
7284//
7285// PatternCharacter ::
7286// SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |
7287//
7288// AtomEscape ::
7289// DecimalEscape
7290// CharacterEscape
7291// CharacterClassEscape
7292//
7293// CharacterEscape[U] ::
7294// ControlEscape
7295// c ControlLetter
7296// HexEscapeSequence
7297// RegExpUnicodeEscapeSequence[?U] (ES6)
7298// IdentityEscape[?U]
7299//
7300// ControlEscape ::
7301// one of f n r t v
7302// ControlLetter ::
7303// one of
7304// 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
7305// 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
7306//
7307// IdentityEscape ::
7308// SourceCharacter but not IdentifierPart
7309// <ZWJ>
7310// <ZWNJ>
7311//
7312// DecimalEscape ::
7313// DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
7314//
7315// CharacterClassEscape ::
7316// one of d D s S w W
7317//
7318// CharacterClass ::
7319// [ [lookahead ∉ {^}] ClassRanges ]
7320// [ ^ ClassRanges ]
7321//
7322// ClassRanges ::
7323// [empty]
7324// NonemptyClassRanges
7325//
7326// NonemptyClassRanges ::
7327// ClassAtom
7328// ClassAtom NonemptyClassRangesNoDash
7329// ClassAtom - ClassAtom ClassRanges
7330//
7331// NonemptyClassRangesNoDash ::
7332// ClassAtom
7333// ClassAtomNoDash NonemptyClassRangesNoDash
7334// ClassAtomNoDash - ClassAtom ClassRanges
7335//
7336// ClassAtom ::
7337// -
7338// ClassAtomNoDash
7339//
7340// ClassAtomNoDash ::
7341// SourceCharacter but not one of \ or ] or -
7342// \ ClassEscape
7343//
7344// ClassEscape ::
7345// DecimalEscape
7346// b
7347// CharacterEscape
7348// CharacterClassEscape
7349
7350(function() {
7351
7352 function parse(str, flags, features) {
7353 if (!features) {
7354 features = {};
7355 }
7356 function addRaw(node) {
7357 node.raw = str.substring(node.range[0], node.range[1]);
7358 return node;
7359 }
7360
7361 function updateRawStart(node, start) {
7362 node.range[0] = start;
7363 return addRaw(node);
7364 }
7365
7366 function createAnchor(kind, rawLength) {
7367 return addRaw({
7368 type: 'anchor',
7369 kind: kind,
7370 range: [
7371 pos - rawLength,
7372 pos
7373 ]
7374 });
7375 }
7376
7377 function createValue(kind, codePoint, from, to) {
7378 return addRaw({
7379 type: 'value',
7380 kind: kind,
7381 codePoint: codePoint,
7382 range: [from, to]
7383 });
7384 }
7385
7386 function createEscaped(kind, codePoint, value, fromOffset) {
7387 fromOffset = fromOffset || 0;
7388 return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);
7389 }
7390
7391 function createCharacter(matches) {
7392 var _char = matches[0];
7393 var first = _char.charCodeAt(0);
7394 if (hasUnicodeFlag) {
7395 var second;
7396 if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
7397 second = lookahead().charCodeAt(0);
7398 if (second >= 0xDC00 && second <= 0xDFFF) {
7399 // Unicode surrogate pair
7400 pos++;
7401 return createValue(
7402 'symbol',
7403 (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,
7404 pos - 2, pos);
7405 }
7406 }
7407 }
7408 return createValue('symbol', first, pos - 1, pos);
7409 }
7410
7411 function createDisjunction(alternatives, from, to) {
7412 return addRaw({
7413 type: 'disjunction',
7414 body: alternatives,
7415 range: [
7416 from,
7417 to
7418 ]
7419 });
7420 }
7421
7422 function createDot() {
7423 return addRaw({
7424 type: 'dot',
7425 range: [
7426 pos - 1,
7427 pos
7428 ]
7429 });
7430 }
7431
7432 function createCharacterClassEscape(value) {
7433 return addRaw({
7434 type: 'characterClassEscape',
7435 value: value,
7436 range: [
7437 pos - 2,
7438 pos
7439 ]
7440 });
7441 }
7442
7443 function createReference(matchIndex) {
7444 return addRaw({
7445 type: 'reference',
7446 matchIndex: parseInt(matchIndex, 10),
7447 range: [
7448 pos - 1 - matchIndex.length,
7449 pos
7450 ]
7451 });
7452 }
7453
7454 function createGroup(behavior, disjunction, from, to) {
7455 return addRaw({
7456 type: 'group',
7457 behavior: behavior,
7458 body: disjunction,
7459 range: [
7460 from,
7461 to
7462 ]
7463 });
7464 }
7465
7466 function createQuantifier(min, max, from, to) {
7467 if (to == null) {
7468 from = pos - 1;
7469 to = pos;
7470 }
7471
7472 return addRaw({
7473 type: 'quantifier',
7474 min: min,
7475 max: max,
7476 greedy: true,
7477 body: null, // set later on
7478 range: [
7479 from,
7480 to
7481 ]
7482 });
7483 }
7484
7485 function createAlternative(terms, from, to) {
7486 return addRaw({
7487 type: 'alternative',
7488 body: terms,
7489 range: [
7490 from,
7491 to
7492 ]
7493 });
7494 }
7495
7496 function createCharacterClass(classRanges, negative, from, to) {
7497 return addRaw({
7498 type: 'characterClass',
7499 body: classRanges,
7500 negative: negative,
7501 range: [
7502 from,
7503 to
7504 ]
7505 });
7506 }
7507
7508 function createClassRange(min, max, from, to) {
7509 // See 15.10.2.15:
7510 if (min.codePoint > max.codePoint) {
7511 bail('invalid range in character class', min.raw + '-' + max.raw, from, to);
7512 }
7513
7514 return addRaw({
7515 type: 'characterClassRange',
7516 min: min,
7517 max: max,
7518 range: [
7519 from,
7520 to
7521 ]
7522 });
7523 }
7524
7525 function flattenBody(body) {
7526 if (body.type === 'alternative') {
7527 return body.body;
7528 } else {
7529 return [body];
7530 }
7531 }
7532
7533 function incr(amount) {
7534 amount = (amount || 1);
7535 var res = str.substring(pos, pos + amount);
7536 pos += (amount || 1);
7537 return res;
7538 }
7539
7540 function skip(value) {
7541 if (!match(value)) {
7542 bail('character', value);
7543 }
7544 }
7545
7546 function match(value) {
7547 if (str.indexOf(value, pos) === pos) {
7548 return incr(value.length);
7549 }
7550 }
7551
7552 function lookahead() {
7553 return str[pos];
7554 }
7555
7556 function current(value) {
7557 return str.indexOf(value, pos) === pos;
7558 }
7559
7560 function next(value) {
7561 return str[pos + 1] === value;
7562 }
7563
7564 function matchReg(regExp) {
7565 var subStr = str.substring(pos);
7566 var res = subStr.match(regExp);
7567 if (res) {
7568 res.range = [];
7569 res.range[0] = pos;
7570 incr(res[0].length);
7571 res.range[1] = pos;
7572 }
7573 return res;
7574 }
7575
7576 function parseDisjunction() {
7577 // Disjunction ::
7578 // Alternative
7579 // Alternative | Disjunction
7580 var res = [], from = pos;
7581 res.push(parseAlternative());
7582
7583 while (match('|')) {
7584 res.push(parseAlternative());
7585 }
7586
7587 if (res.length === 1) {
7588 return res[0];
7589 }
7590
7591 return createDisjunction(res, from, pos);
7592 }
7593
7594 function parseAlternative() {
7595 var res = [], from = pos;
7596 var term;
7597
7598 // Alternative ::
7599 // [empty]
7600 // Alternative Term
7601 while (term = parseTerm()) {
7602 res.push(term);
7603 }
7604
7605 if (res.length === 1) {
7606 return res[0];
7607 }
7608
7609 return createAlternative(res, from, pos);
7610 }
7611
7612 function parseTerm() {
7613 // Term ::
7614 // Anchor
7615 // Atom
7616 // Atom Quantifier
7617
7618 if (pos >= str.length || current('|') || current(')')) {
7619 return null; /* Means: The term is empty */
7620 }
7621
7622 var anchor = parseAnchor();
7623
7624 if (anchor) {
7625 return anchor;
7626 }
7627
7628 var atom = parseAtom();
7629 if (!atom) {
7630 bail('Expected atom');
7631 }
7632 var quantifier = parseQuantifier() || false;
7633 if (quantifier) {
7634 quantifier.body = flattenBody(atom);
7635 // The quantifier contains the atom. Therefore, the beginning of the
7636 // quantifier range is given by the beginning of the atom.
7637 updateRawStart(quantifier, atom.range[0]);
7638 return quantifier;
7639 }
7640 return atom;
7641 }
7642
7643 function parseGroup(matchA, typeA, matchB, typeB) {
7644 var type = null, from = pos;
7645
7646 if (match(matchA)) {
7647 type = typeA;
7648 } else if (match(matchB)) {
7649 type = typeB;
7650 } else {
7651 return false;
7652 }
7653
7654 var body = parseDisjunction();
7655 if (!body) {
7656 bail('Expected disjunction');
7657 }
7658 skip(')');
7659 var group = createGroup(type, flattenBody(body), from, pos);
7660
7661 if (type == 'normal') {
7662 // Keep track of the number of closed groups. This is required for
7663 // parseDecimalEscape(). In case the string is parsed a second time the
7664 // value already holds the total count and no incrementation is required.
7665 if (firstIteration) {
7666 closedCaptureCounter++;
7667 }
7668 }
7669 return group;
7670 }
7671
7672 function parseAnchor() {
7673 // Anchor ::
7674 // ^
7675 // $
7676 // \ b
7677 // \ B
7678 // ( ? = Disjunction )
7679 // ( ? ! Disjunction )
7680 if (match('^')) {
7681 return createAnchor('start', 1 /* rawLength */);
7682 } else if (match('$')) {
7683 return createAnchor('end', 1 /* rawLength */);
7684 } else if (match('\\b')) {
7685 return createAnchor('boundary', 2 /* rawLength */);
7686 } else if (match('\\B')) {
7687 return createAnchor('not-boundary', 2 /* rawLength */);
7688 } else {
7689 return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');
7690 }
7691 }
7692
7693 function parseQuantifier() {
7694 // Quantifier ::
7695 // QuantifierPrefix
7696 // QuantifierPrefix ?
7697 //
7698 // QuantifierPrefix ::
7699 // *
7700 // +
7701 // ?
7702 // { DecimalDigits }
7703 // { DecimalDigits , }
7704 // { DecimalDigits , DecimalDigits }
7705
7706 var res, from = pos;
7707 var quantifier;
7708 var min, max;
7709
7710 if (match('*')) {
7711 quantifier = createQuantifier(0);
7712 }
7713 else if (match('+')) {
7714 quantifier = createQuantifier(1);
7715 }
7716 else if (match('?')) {
7717 quantifier = createQuantifier(0, 1);
7718 }
7719 else if (res = matchReg(/^\{([0-9]+)\}/)) {
7720 min = parseInt(res[1], 10);
7721 quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
7722 }
7723 else if (res = matchReg(/^\{([0-9]+),\}/)) {
7724 min = parseInt(res[1], 10);
7725 quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
7726 }
7727 else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
7728 min = parseInt(res[1], 10);
7729 max = parseInt(res[2], 10);
7730 if (min > max) {
7731 bail('numbers out of order in {} quantifier', '', from, pos);
7732 }
7733 quantifier = createQuantifier(min, max, res.range[0], res.range[1]);
7734 }
7735
7736 if (quantifier) {
7737 if (match('?')) {
7738 quantifier.greedy = false;
7739 quantifier.range[1] += 1;
7740 }
7741 }
7742
7743 return quantifier;
7744 }
7745
7746 function parseAtom() {
7747 // Atom ::
7748 // PatternCharacter
7749 // .
7750 // \ AtomEscape
7751 // CharacterClass
7752 // ( Disjunction )
7753 // ( ? : Disjunction )
7754
7755 var res;
7756
7757 // jviereck: allow ']', '}' here as well to be compatible with browser's
7758 // implementations: ']'.match(/]/);
7759 // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) {
7760 if (res = matchReg(/^[^^$\\.*+?(){[|]/)) {
7761 // PatternCharacter
7762 return createCharacter(res);
7763 }
7764 else if (match('.')) {
7765 // .
7766 return createDot();
7767 }
7768 else if (match('\\')) {
7769 // \ AtomEscape
7770 res = parseAtomEscape();
7771 if (!res) {
7772 bail('atomEscape');
7773 }
7774 return res;
7775 }
7776 else if (res = parseCharacterClass()) {
7777 return res;
7778 }
7779 else {
7780 // ( Disjunction )
7781 // ( ? : Disjunction )
7782 return parseGroup('(?:', 'ignore', '(', 'normal');
7783 }
7784 }
7785
7786 function parseUnicodeSurrogatePairEscape(firstEscape) {
7787 if (hasUnicodeFlag) {
7788 var first, second;
7789 if (firstEscape.kind == 'unicodeEscape' &&
7790 (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&
7791 current('\\') && next('u') ) {
7792 var prevPos = pos;
7793 pos++;
7794 var secondEscape = parseClassEscape();
7795 if (secondEscape.kind == 'unicodeEscape' &&
7796 (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {
7797 // Unicode surrogate pair
7798 firstEscape.range[1] = secondEscape.range[1];
7799 firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
7800 firstEscape.type = 'value';
7801 firstEscape.kind = 'unicodeCodePointEscape';
7802 addRaw(firstEscape);
7803 }
7804 else {
7805 pos = prevPos;
7806 }
7807 }
7808 }
7809 return firstEscape;
7810 }
7811
7812 function parseClassEscape() {
7813 return parseAtomEscape(true);
7814 }
7815
7816 function parseAtomEscape(insideCharacterClass) {
7817 // AtomEscape ::
7818 // DecimalEscape
7819 // CharacterEscape
7820 // CharacterClassEscape
7821
7822 var res, from = pos;
7823
7824 res = parseDecimalEscape();
7825 if (res) {
7826 return res;
7827 }
7828
7829 // For ClassEscape
7830 if (insideCharacterClass) {
7831 if (match('b')) {
7832 // 15.10.2.19
7833 // The production ClassEscape :: b evaluates by returning the
7834 // CharSet containing the one character <BS> (Unicode value 0008).
7835 return createEscaped('singleEscape', 0x0008, '\\b');
7836 } else if (match('B')) {
7837 bail('\\B not possible inside of CharacterClass', '', from);
7838 }
7839 }
7840
7841 res = parseCharacterEscape();
7842
7843 return res;
7844 }
7845
7846
7847 function parseDecimalEscape() {
7848 // DecimalEscape ::
7849 // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
7850 // CharacterClassEscape :: one of d D s S w W
7851
7852 var res, match;
7853
7854 if (res = matchReg(/^(?!0)\d+/)) {
7855 match = res[0];
7856 var refIdx = parseInt(res[0], 10);
7857 if (refIdx <= closedCaptureCounter) {
7858 // If the number is smaller than the normal-groups found so
7859 // far, then it is a reference...
7860 return createReference(res[0]);
7861 } else {
7862 // ... otherwise it needs to be interpreted as a octal (if the
7863 // number is in an octal format). If it is NOT octal format,
7864 // then the slash is ignored and the number is matched later
7865 // as normal characters.
7866
7867 // Recall the negative decision to decide if the input must be parsed
7868 // a second time with the total normal-groups.
7869 backrefDenied.push(refIdx);
7870
7871 // Reset the position again, as maybe only parts of the previous
7872 // matched numbers are actual octal numbers. E.g. in '019' only
7873 // the '01' should be matched.
7874 incr(-res[0].length);
7875 if (res = matchReg(/^[0-7]{1,3}/)) {
7876 return createEscaped('octal', parseInt(res[0], 8), res[0], 1);
7877 } else {
7878 // If we end up here, we have a case like /\91/. Then the
7879 // first slash is to be ignored and the 9 & 1 to be treated
7880 // like ordinary characters. Create a character for the
7881 // first number only here - other number-characters
7882 // (if available) will be matched later.
7883 res = createCharacter(matchReg(/^[89]/));
7884 return updateRawStart(res, res.range[0] - 1);
7885 }
7886 }
7887 }
7888 // Only allow octal numbers in the following. All matched numbers start
7889 // with a zero (if the do not, the previous if-branch is executed).
7890 // If the number is not octal format and starts with zero (e.g. `091`)
7891 // then only the zeros `0` is treated here and the `91` are ordinary
7892 // characters.
7893 // Example:
7894 // /\091/.exec('\091')[0].length === 3
7895 else if (res = matchReg(/^[0-7]{1,3}/)) {
7896 match = res[0];
7897 if (/^0{1,3}$/.test(match)) {
7898 // If they are all zeros, then only take the first one.
7899 return createEscaped('null', 0x0000, '0', match.length + 1);
7900 } else {
7901 return createEscaped('octal', parseInt(match, 8), match, 1);
7902 }
7903 } else if (res = matchReg(/^[dDsSwW]/)) {
7904 return createCharacterClassEscape(res[0]);
7905 }
7906 return false;
7907 }
7908
7909 function parseCharacterEscape() {
7910 // CharacterEscape ::
7911 // ControlEscape
7912 // c ControlLetter
7913 // HexEscapeSequence
7914 // UnicodeEscapeSequence
7915 // IdentityEscape
7916
7917 var res;
7918 if (res = matchReg(/^[fnrtv]/)) {
7919 // ControlEscape
7920 var codePoint = 0;
7921 switch (res[0]) {
7922 case 't': codePoint = 0x009; break;
7923 case 'n': codePoint = 0x00A; break;
7924 case 'v': codePoint = 0x00B; break;
7925 case 'f': codePoint = 0x00C; break;
7926 case 'r': codePoint = 0x00D; break;
7927 }
7928 return createEscaped('singleEscape', codePoint, '\\' + res[0]);
7929 } else if (res = matchReg(/^c([a-zA-Z])/)) {
7930 // c ControlLetter
7931 return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);
7932 } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) {
7933 // HexEscapeSequence
7934 return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2);
7935 } else if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {
7936 // UnicodeEscapeSequence
7937 return parseUnicodeSurrogatePairEscape(
7938 createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2)
7939 );
7940 } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {
7941 // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)
7942 return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);
7943 } else if (features.unicodePropertyEscape && hasUnicodeFlag && (res = matchReg(/^([pP])\{([^\}]+)\}/))) {
7944 // https://github.com/jviereck/regjsparser/issues/77
7945 return addRaw({
7946 type: 'unicodePropertyEscape',
7947 negative: res[1] === 'P',
7948 value: res[2],
7949 range: [res.range[0] - 1, res.range[1]],
7950 raw: res[0]
7951 });
7952 } else {
7953 // IdentityEscape
7954 return parseIdentityEscape();
7955 }
7956 }
7957
7958 // Taken from the Esprima parser.
7959 function isIdentifierPart(ch) {
7960 // Generated by `tools/generate-identifier-regex.js`.
7961 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]');
7962
7963 return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
7964 (ch >= 65 && ch <= 90) || // A..Z
7965 (ch >= 97 && ch <= 122) || // a..z
7966 (ch >= 48 && ch <= 57) || // 0..9
7967 (ch === 92) || // \ (backslash)
7968 ((ch >= 0x80) && NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
7969 }
7970
7971 function parseIdentityEscape() {
7972 // IdentityEscape ::
7973 // SourceCharacter but not IdentifierPart
7974 // <ZWJ>
7975 // <ZWNJ>
7976
7977 var ZWJ = '\u200C';
7978 var ZWNJ = '\u200D';
7979
7980 var tmp;
7981
7982 if (!isIdentifierPart(lookahead())) {
7983 tmp = incr();
7984 return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1);
7985 }
7986
7987 if (match(ZWJ)) {
7988 // <ZWJ>
7989 return createEscaped('identifier', 0x200C, ZWJ);
7990 } else if (match(ZWNJ)) {
7991 // <ZWNJ>
7992 return createEscaped('identifier', 0x200D, ZWNJ);
7993 }
7994
7995 return null;
7996 }
7997
7998 function parseCharacterClass() {
7999 // CharacterClass ::
8000 // [ [lookahead ∉ {^}] ClassRanges ]
8001 // [ ^ ClassRanges ]
8002
8003 var res, from = pos;
8004 if (res = matchReg(/^\[\^/)) {
8005 res = parseClassRanges();
8006 skip(']');
8007 return createCharacterClass(res, true, from, pos);
8008 } else if (match('[')) {
8009 res = parseClassRanges();
8010 skip(']');
8011 return createCharacterClass(res, false, from, pos);
8012 }
8013
8014 return null;
8015 }
8016
8017 function parseClassRanges() {
8018 // ClassRanges ::
8019 // [empty]
8020 // NonemptyClassRanges
8021
8022 var res;
8023 if (current(']')) {
8024 // Empty array means nothing insinde of the ClassRange.
8025 return [];
8026 } else {
8027 res = parseNonemptyClassRanges();
8028 if (!res) {
8029 bail('nonEmptyClassRanges');
8030 }
8031 return res;
8032 }
8033 }
8034
8035 function parseHelperClassRanges(atom) {
8036 var from, to, res;
8037 if (current('-') && !next(']')) {
8038 // ClassAtom - ClassAtom ClassRanges
8039 skip('-');
8040
8041 res = parseClassAtom();
8042 if (!res) {
8043 bail('classAtom');
8044 }
8045 to = pos;
8046 var classRanges = parseClassRanges();
8047 if (!classRanges) {
8048 bail('classRanges');
8049 }
8050 from = atom.range[0];
8051 if (classRanges.type === 'empty') {
8052 return [createClassRange(atom, res, from, to)];
8053 }
8054 return [createClassRange(atom, res, from, to)].concat(classRanges);
8055 }
8056
8057 res = parseNonemptyClassRangesNoDash();
8058 if (!res) {
8059 bail('nonEmptyClassRangesNoDash');
8060 }
8061
8062 return [atom].concat(res);
8063 }
8064
8065 function parseNonemptyClassRanges() {
8066 // NonemptyClassRanges ::
8067 // ClassAtom
8068 // ClassAtom NonemptyClassRangesNoDash
8069 // ClassAtom - ClassAtom ClassRanges
8070
8071 var atom = parseClassAtom();
8072 if (!atom) {
8073 bail('classAtom');
8074 }
8075
8076 if (current(']')) {
8077 // ClassAtom
8078 return [atom];
8079 }
8080
8081 // ClassAtom NonemptyClassRangesNoDash
8082 // ClassAtom - ClassAtom ClassRanges
8083 return parseHelperClassRanges(atom);
8084 }
8085
8086 function parseNonemptyClassRangesNoDash() {
8087 // NonemptyClassRangesNoDash ::
8088 // ClassAtom
8089 // ClassAtomNoDash NonemptyClassRangesNoDash
8090 // ClassAtomNoDash - ClassAtom ClassRanges
8091
8092 var res = parseClassAtom();
8093 if (!res) {
8094 bail('classAtom');
8095 }
8096 if (current(']')) {
8097 // ClassAtom
8098 return res;
8099 }
8100
8101 // ClassAtomNoDash NonemptyClassRangesNoDash
8102 // ClassAtomNoDash - ClassAtom ClassRanges
8103 return parseHelperClassRanges(res);
8104 }
8105
8106 function parseClassAtom() {
8107 // ClassAtom ::
8108 // -
8109 // ClassAtomNoDash
8110 if (match('-')) {
8111 return createCharacter('-');
8112 } else {
8113 return parseClassAtomNoDash();
8114 }
8115 }
8116
8117 function parseClassAtomNoDash() {
8118 // ClassAtomNoDash ::
8119 // SourceCharacter but not one of \ or ] or -
8120 // \ ClassEscape
8121
8122 var res;
8123 if (res = matchReg(/^[^\\\]-]/)) {
8124 return createCharacter(res[0]);
8125 } else if (match('\\')) {
8126 res = parseClassEscape();
8127 if (!res) {
8128 bail('classEscape');
8129 }
8130
8131 return parseUnicodeSurrogatePairEscape(res);
8132 }
8133 }
8134
8135 function bail(message, details, from, to) {
8136 from = from == null ? pos : from;
8137 to = to == null ? from : to;
8138
8139 var contextStart = Math.max(0, from - 10);
8140 var contextEnd = Math.min(to + 10, str.length);
8141
8142 // Output a bit of context and a line pointing to where our error is.
8143 //
8144 // We are assuming that there are no actual newlines in the content as this is a regular expression.
8145 var context = ' ' + str.substring(contextStart, contextEnd);
8146 var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^';
8147
8148 throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer);
8149 }
8150
8151 var backrefDenied = [];
8152 var closedCaptureCounter = 0;
8153 var firstIteration = true;
8154 var hasUnicodeFlag = (flags || "").indexOf("u") !== -1;
8155 var pos = 0;
8156
8157 // Convert the input to a string and treat the empty string special.
8158 str = String(str);
8159 if (str === '') {
8160 str = '(?:)';
8161 }
8162
8163 var result = parseDisjunction();
8164
8165 if (result.range[1] !== str.length) {
8166 bail('Could not parse entire input - got stuck', '', result.range[1]);
8167 }
8168
8169 // The spec requires to interpret the `\2` in `/\2()()/` as backreference.
8170 // As the parser collects the number of capture groups as the string is
8171 // parsed it is impossible to make these decisions at the point when the
8172 // `\2` is handled. In case the local decision turns out to be wrong after
8173 // the parsing has finished, the input string is parsed a second time with
8174 // the total number of capture groups set.
8175 //
8176 // SEE: https://github.com/jviereck/regjsparser/issues/70
8177 for (var i = 0; i < backrefDenied.length; i++) {
8178 if (backrefDenied[i] <= closedCaptureCounter) {
8179 // Parse the input a second time.
8180 pos = 0;
8181 firstIteration = false;
8182 return parseDisjunction();
8183 }
8184 }
8185
8186 return result;
8187 }
8188
8189 var regjsparser = {
8190 parse: parse
8191 };
8192
8193 if ('object' !== 'undefined' && module.exports) {
8194 module.exports = regjsparser;
8195 } else {
8196 window.regjsparser = regjsparser;
8197 }
8198
8199}());
8200});
8201
8202var regenerate = createCommonjsModule(function (module, exports) {
8203/*! https://mths.be/regenerate v1.3.3 by @mathias | MIT license */
8204(function(root) {
8205
8206 // Detect free variables `exports`.
8207 var freeExports = 'object' == 'object' && exports;
8208
8209 // Detect free variable `module`.
8210 var freeModule = 'object' == 'object' && module &&
8211 module.exports == freeExports && module;
8212
8213 // Detect free variable `global`, from Node.js/io.js or Browserified code,
8214 // and use it as `root`.
8215 var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
8216 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
8217 root = freeGlobal;
8218 }
8219
8220 /*--------------------------------------------------------------------------*/
8221
8222 var ERRORS = {
8223 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
8224 'to the `start` value.',
8225 'codePointRange': 'Invalid code point value. Code points range from ' +
8226 'U+000000 to U+10FFFF.'
8227 };
8228
8229 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
8230 var HIGH_SURROGATE_MIN = 0xD800;
8231 var HIGH_SURROGATE_MAX = 0xDBFF;
8232 var LOW_SURROGATE_MIN = 0xDC00;
8233 var LOW_SURROGATE_MAX = 0xDFFF;
8234
8235 // In Regenerate output, `\0` is never preceded by `\` because we sort by
8236 // code point value, so let’s keep this regular expression simple.
8237 var regexNull = /\\x00([^0123456789]|$)/g;
8238
8239 var object = {};
8240 var hasOwnProperty = object.hasOwnProperty;
8241 var extend = function(destination, source) {
8242 var key;
8243 for (key in source) {
8244 if (hasOwnProperty.call(source, key)) {
8245 destination[key] = source[key];
8246 }
8247 }
8248 return destination;
8249 };
8250
8251 var forEach = function(array, callback) {
8252 var index = -1;
8253 var length = array.length;
8254 while (++index < length) {
8255 callback(array[index], index);
8256 }
8257 };
8258
8259 var toString = object.toString;
8260 var isArray = function(value) {
8261 return toString.call(value) == '[object Array]';
8262 };
8263 var isNumber = function(value) {
8264 return typeof value == 'number' ||
8265 toString.call(value) == '[object Number]';
8266 };
8267
8268 // This assumes that `number` is a positive integer that `toString()`s nicely
8269 // (which is the case for all code point values).
8270 var zeroes = '0000';
8271 var pad = function(number, totalCharacters) {
8272 var string = String(number);
8273 return string.length < totalCharacters
8274 ? (zeroes + string).slice(-totalCharacters)
8275 : string;
8276 };
8277
8278 var hex = function(number) {
8279 return Number(number).toString(16).toUpperCase();
8280 };
8281
8282 var slice = [].slice;
8283
8284 /*--------------------------------------------------------------------------*/
8285
8286 var dataFromCodePoints = function(codePoints) {
8287 var index = -1;
8288 var length = codePoints.length;
8289 var max = length - 1;
8290 var result = [];
8291 var isStart = true;
8292 var tmp;
8293 var previous = 0;
8294 while (++index < length) {
8295 tmp = codePoints[index];
8296 if (isStart) {
8297 result.push(tmp);
8298 previous = tmp;
8299 isStart = false;
8300 } else {
8301 if (tmp == previous + 1) {
8302 if (index != max) {
8303 previous = tmp;
8304 continue;
8305 } else {
8306 isStart = true;
8307 result.push(tmp + 1);
8308 }
8309 } else {
8310 // End the previous range and start a new one.
8311 result.push(previous + 1, tmp);
8312 previous = tmp;
8313 }
8314 }
8315 }
8316 if (!isStart) {
8317 result.push(tmp + 1);
8318 }
8319 return result;
8320 };
8321
8322 var dataRemove = function(data, codePoint) {
8323 // Iterate over the data per `(start, end)` pair.
8324 var index = 0;
8325 var start;
8326 var end;
8327 var length = data.length;
8328 while (index < length) {
8329 start = data[index];
8330 end = data[index + 1];
8331 if (codePoint >= start && codePoint < end) {
8332 // Modify this pair.
8333 if (codePoint == start) {
8334 if (end == start + 1) {
8335 // Just remove `start` and `end`.
8336 data.splice(index, 2);
8337 return data;
8338 } else {
8339 // Just replace `start` with a new value.
8340 data[index] = codePoint + 1;
8341 return data;
8342 }
8343 } else if (codePoint == end - 1) {
8344 // Just replace `end` with a new value.
8345 data[index + 1] = codePoint;
8346 return data;
8347 } else {
8348 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
8349 data.splice(index, 2, start, codePoint, codePoint + 1, end);
8350 return data;
8351 }
8352 }
8353 index += 2;
8354 }
8355 return data;
8356 };
8357
8358 var dataRemoveRange = function(data, rangeStart, rangeEnd) {
8359 if (rangeEnd < rangeStart) {
8360 throw Error(ERRORS.rangeOrder);
8361 }
8362 // Iterate over the data per `(start, end)` pair.
8363 var index = 0;
8364 var start;
8365 var end;
8366 while (index < data.length) {
8367 start = data[index];
8368 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8369
8370 // Exit as soon as no more matching pairs can be found.
8371 if (start > rangeEnd) {
8372 return data;
8373 }
8374
8375 // Check if this range pair is equal to, or forms a subset of, the range
8376 // to be removed.
8377 // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
8378 // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
8379 if (rangeStart <= start && rangeEnd >= end) {
8380 // Remove this pair.
8381 data.splice(index, 2);
8382 continue;
8383 }
8384
8385 // Check if both `rangeStart` and `rangeEnd` are within the bounds of
8386 // this pair.
8387 // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
8388 if (rangeStart >= start && rangeEnd < end) {
8389 if (rangeStart == start) {
8390 // Replace `[start, end]` with `[startB, endB]`.
8391 data[index] = rangeEnd + 1;
8392 data[index + 1] = end + 1;
8393 return data;
8394 }
8395 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
8396 data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
8397 return data;
8398 }
8399
8400 // Check if only `rangeStart` is within the bounds of this pair.
8401 // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
8402 if (rangeStart >= start && rangeStart <= end) {
8403 // Replace `end` with `rangeStart`.
8404 data[index + 1] = rangeStart;
8405 // Note: we cannot `return` just yet, in case any following pairs still
8406 // contain matching code points.
8407 // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
8408 // → `[0, 4, 21, 31]`.
8409 }
8410
8411 // Check if only `rangeEnd` is within the bounds of this pair.
8412 // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
8413 else if (rangeEnd >= start && rangeEnd <= end) {
8414 // Just replace `start`.
8415 data[index] = rangeEnd + 1;
8416 return data;
8417 }
8418
8419 index += 2;
8420 }
8421 return data;
8422 };
8423
8424 var dataAdd = function(data, codePoint) {
8425 // Iterate over the data per `(start, end)` pair.
8426 var index = 0;
8427 var start;
8428 var end;
8429 var lastIndex = null;
8430 var length = data.length;
8431 if (codePoint < 0x0 || codePoint > 0x10FFFF) {
8432 throw RangeError(ERRORS.codePointRange);
8433 }
8434 while (index < length) {
8435 start = data[index];
8436 end = data[index + 1];
8437
8438 // Check if the code point is already in the set.
8439 if (codePoint >= start && codePoint < end) {
8440 return data;
8441 }
8442
8443 if (codePoint == start - 1) {
8444 // Just replace `start` with a new value.
8445 data[index] = codePoint;
8446 return data;
8447 }
8448
8449 // At this point, if `start` is `greater` than `codePoint`, insert a new
8450 // `[start, end]` pair before the current pair, or after the current pair
8451 // if there is a known `lastIndex`.
8452 if (start > codePoint) {
8453 data.splice(
8454 lastIndex != null ? lastIndex + 2 : 0,
8455 0,
8456 codePoint,
8457 codePoint + 1
8458 );
8459 return data;
8460 }
8461
8462 if (codePoint == end) {
8463 // Check if adding this code point causes two separate ranges to become
8464 // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
8465 if (codePoint + 1 == data[index + 2]) {
8466 data.splice(index, 4, start, data[index + 3]);
8467 return data;
8468 }
8469 // Else, just replace `end` with a new value.
8470 data[index + 1] = codePoint + 1;
8471 return data;
8472 }
8473 lastIndex = index;
8474 index += 2;
8475 }
8476 // The loop has finished; add the new pair to the end of the data set.
8477 data.push(codePoint, codePoint + 1);
8478 return data;
8479 };
8480
8481 var dataAddData = function(dataA, dataB) {
8482 // Iterate over the data per `(start, end)` pair.
8483 var index = 0;
8484 var start;
8485 var end;
8486 var data = dataA.slice();
8487 var length = dataB.length;
8488 while (index < length) {
8489 start = dataB[index];
8490 end = dataB[index + 1] - 1;
8491 if (start == end) {
8492 data = dataAdd(data, start);
8493 } else {
8494 data = dataAddRange(data, start, end);
8495 }
8496 index += 2;
8497 }
8498 return data;
8499 };
8500
8501 var dataRemoveData = function(dataA, dataB) {
8502 // Iterate over the data per `(start, end)` pair.
8503 var index = 0;
8504 var start;
8505 var end;
8506 var data = dataA.slice();
8507 var length = dataB.length;
8508 while (index < length) {
8509 start = dataB[index];
8510 end = dataB[index + 1] - 1;
8511 if (start == end) {
8512 data = dataRemove(data, start);
8513 } else {
8514 data = dataRemoveRange(data, start, end);
8515 }
8516 index += 2;
8517 }
8518 return data;
8519 };
8520
8521 var dataAddRange = function(data, rangeStart, rangeEnd) {
8522 if (rangeEnd < rangeStart) {
8523 throw Error(ERRORS.rangeOrder);
8524 }
8525 if (
8526 rangeStart < 0x0 || rangeStart > 0x10FFFF ||
8527 rangeEnd < 0x0 || rangeEnd > 0x10FFFF
8528 ) {
8529 throw RangeError(ERRORS.codePointRange);
8530 }
8531 // Iterate over the data per `(start, end)` pair.
8532 var index = 0;
8533 var start;
8534 var end;
8535 var added = false;
8536 var length = data.length;
8537 while (index < length) {
8538 start = data[index];
8539 end = data[index + 1];
8540
8541 if (added) {
8542 // The range has already been added to the set; at this point, we just
8543 // need to get rid of the following ranges in case they overlap.
8544
8545 // Check if this range can be combined with the previous range.
8546 if (start == rangeEnd + 1) {
8547 data.splice(index - 1, 2);
8548 return data;
8549 }
8550
8551 // Exit as soon as no more possibly overlapping pairs can be found.
8552 if (start > rangeEnd) {
8553 return data;
8554 }
8555
8556 // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
8557 // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
8558 // `0,16` range that was previously added.
8559 if (start >= rangeStart && start <= rangeEnd) {
8560 // `start` lies within the range that was previously added.
8561
8562 if (end > rangeStart && end - 1 <= rangeEnd) {
8563 // `end` lies within the range that was previously added as well,
8564 // so remove this pair.
8565 data.splice(index, 2);
8566 index -= 2;
8567 // Note: we cannot `return` just yet, as there may still be other
8568 // overlapping pairs.
8569 } else {
8570 // `start` lies within the range that was previously added, but
8571 // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
8572 // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
8573 // Remove the previously added `end` and the current `start`.
8574 data.splice(index - 1, 2);
8575 index -= 2;
8576 }
8577
8578 // Note: we cannot return yet.
8579 }
8580
8581 }
8582
8583 else if (start == rangeEnd + 1) {
8584 data[index] = rangeStart;
8585 return data;
8586 }
8587
8588 // Check if a new pair must be inserted *before* the current one.
8589 else if (start > rangeEnd) {
8590 data.splice(index, 0, rangeStart, rangeEnd + 1);
8591 return data;
8592 }
8593
8594 else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
8595 // The new range lies entirely within an existing range pair. No action
8596 // needed.
8597 return data;
8598 }
8599
8600 else if (
8601 // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
8602 (rangeStart >= start && rangeStart < end) ||
8603 // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
8604 end == rangeStart
8605 ) {
8606 // Replace `end` with the new value.
8607 data[index + 1] = rangeEnd + 1;
8608 // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
8609 // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
8610 added = true;
8611 // Note: we cannot `return` just yet.
8612 }
8613
8614 else if (rangeStart <= start && rangeEnd + 1 >= end) {
8615 // The new range is a superset of the old range.
8616 data[index] = rangeStart;
8617 data[index + 1] = rangeEnd + 1;
8618 added = true;
8619 }
8620
8621 index += 2;
8622 }
8623 // The loop has finished without doing anything; add the new pair to the end
8624 // of the data set.
8625 if (!added) {
8626 data.push(rangeStart, rangeEnd + 1);
8627 }
8628 return data;
8629 };
8630
8631 var dataContains = function(data, codePoint) {
8632 var index = 0;
8633 var length = data.length;
8634 // Exit early if `codePoint` is not within `data`’s overall range.
8635 var start = data[index];
8636 var end = data[length - 1];
8637 if (length >= 2) {
8638 if (codePoint < start || codePoint > end) {
8639 return false;
8640 }
8641 }
8642 // Iterate over the data per `(start, end)` pair.
8643 while (index < length) {
8644 start = data[index];
8645 end = data[index + 1];
8646 if (codePoint >= start && codePoint < end) {
8647 return true;
8648 }
8649 index += 2;
8650 }
8651 return false;
8652 };
8653
8654 var dataIntersection = function(data, codePoints) {
8655 var index = 0;
8656 var length = codePoints.length;
8657 var codePoint;
8658 var result = [];
8659 while (index < length) {
8660 codePoint = codePoints[index];
8661 if (dataContains(data, codePoint)) {
8662 result.push(codePoint);
8663 }
8664 ++index;
8665 }
8666 return dataFromCodePoints(result);
8667 };
8668
8669 var dataIsEmpty = function(data) {
8670 return !data.length;
8671 };
8672
8673 var dataIsSingleton = function(data) {
8674 // Check if the set only represents a single code point.
8675 return data.length == 2 && data[0] + 1 == data[1];
8676 };
8677
8678 var dataToArray = function(data) {
8679 // Iterate over the data per `(start, end)` pair.
8680 var index = 0;
8681 var start;
8682 var end;
8683 var result = [];
8684 var length = data.length;
8685 while (index < length) {
8686 start = data[index];
8687 end = data[index + 1];
8688 while (start < end) {
8689 result.push(start);
8690 ++start;
8691 }
8692 index += 2;
8693 }
8694 return result;
8695 };
8696
8697 /*--------------------------------------------------------------------------*/
8698
8699 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
8700 var floor = Math.floor;
8701 var highSurrogate = function(codePoint) {
8702 return parseInt(
8703 floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
8704 10
8705 );
8706 };
8707
8708 var lowSurrogate = function(codePoint) {
8709 return parseInt(
8710 (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
8711 10
8712 );
8713 };
8714
8715 var stringFromCharCode = String.fromCharCode;
8716 var codePointToString = function(codePoint) {
8717 var string;
8718 // https://mathiasbynens.be/notes/javascript-escapes#single
8719 // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
8720 // different meaning in regular expressions (word boundary), so it cannot
8721 // be used here.
8722 if (codePoint == 0x09) {
8723 string = '\\t';
8724 }
8725 // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
8726 // else if (codePoint == 0x0B) {
8727 // string = '\\v';
8728 // }
8729 else if (codePoint == 0x0A) {
8730 string = '\\n';
8731 }
8732 else if (codePoint == 0x0C) {
8733 string = '\\f';
8734 }
8735 else if (codePoint == 0x0D) {
8736 string = '\\r';
8737 }
8738 else if (codePoint == 0x5C) {
8739 string = '\\\\';
8740 }
8741 else if (
8742 codePoint == 0x24 ||
8743 (codePoint >= 0x28 && codePoint <= 0x2B) ||
8744 (codePoint >= 0x2D && codePoint <= 0x2F) ||
8745 codePoint == 0x3F ||
8746 (codePoint >= 0x5B && codePoint <= 0x5E) ||
8747 (codePoint >= 0x7B && codePoint <= 0x7D)
8748 ) {
8749 // The code point maps to an unsafe printable ASCII character;
8750 // backslash-escape it. Here’s the list of those symbols:
8751 //
8752 // $()*+-./?[\]^{|}
8753 //
8754 // See #7 for more info.
8755 string = '\\' + stringFromCharCode(codePoint);
8756 }
8757 else if (codePoint >= 0x20 && codePoint <= 0x7E) {
8758 // The code point maps to one of these printable ASCII symbols
8759 // (including the space character):
8760 //
8761 // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
8762 // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
8763 //
8764 // These can safely be used directly.
8765 string = stringFromCharCode(codePoint);
8766 }
8767 else if (codePoint <= 0xFF) {
8768 // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
8769 string = '\\x' + pad(hex(codePoint), 2);
8770 }
8771 else { // `codePoint <= 0xFFFF` holds true.
8772 // https://mathiasbynens.be/notes/javascript-escapes#unicode
8773 string = '\\u' + pad(hex(codePoint), 4);
8774 }
8775
8776 // There’s no need to account for astral symbols / surrogate pairs here,
8777 // since `codePointToString` is private and only used for BMP code points.
8778 // But if that’s what you need, just add an `else` block with this code:
8779 //
8780 // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
8781 // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
8782
8783 return string;
8784 };
8785
8786 var codePointToStringUnicode = function(codePoint) {
8787 if (codePoint <= 0xFFFF) {
8788 return codePointToString(codePoint);
8789 }
8790 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
8791 };
8792
8793 var symbolToCodePoint = function(symbol) {
8794 var length = symbol.length;
8795 var first = symbol.charCodeAt(0);
8796 var second;
8797 if (
8798 first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
8799 length > 1 // There is a next code unit.
8800 ) {
8801 // `first` is a high surrogate, and there is a next character. Assume
8802 // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
8803 second = symbol.charCodeAt(1);
8804 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
8805 return (first - HIGH_SURROGATE_MIN) * 0x400 +
8806 second - LOW_SURROGATE_MIN + 0x10000;
8807 }
8808 return first;
8809 };
8810
8811 var createBMPCharacterClasses = function(data) {
8812 // Iterate over the data per `(start, end)` pair.
8813 var result = '';
8814 var index = 0;
8815 var start;
8816 var end;
8817 var length = data.length;
8818 if (dataIsSingleton(data)) {
8819 return codePointToString(data[0]);
8820 }
8821 while (index < length) {
8822 start = data[index];
8823 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8824 if (start == end) {
8825 result += codePointToString(start);
8826 } else if (start + 1 == end) {
8827 result += codePointToString(start) + codePointToString(end);
8828 } else {
8829 result += codePointToString(start) + '-' + codePointToString(end);
8830 }
8831 index += 2;
8832 }
8833 return '[' + result + ']';
8834 };
8835
8836 var createUnicodeCharacterClasses = function(data) {
8837 // Iterate over the data per `(start, end)` pair.
8838 var result = '';
8839 var index = 0;
8840 var start;
8841 var end;
8842 var length = data.length;
8843 if (dataIsSingleton(data)) {
8844 return codePointToStringUnicode(data[0]);
8845 }
8846 while (index < length) {
8847 start = data[index];
8848 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8849 if (start == end) {
8850 result += codePointToStringUnicode(start);
8851 } else if (start + 1 == end) {
8852 result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
8853 } else {
8854 result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
8855 }
8856 index += 2;
8857 }
8858 return '[' + result + ']';
8859 };
8860
8861 var splitAtBMP = function(data) {
8862 // Iterate over the data per `(start, end)` pair.
8863 var loneHighSurrogates = [];
8864 var loneLowSurrogates = [];
8865 var bmp = [];
8866 var astral = [];
8867 var index = 0;
8868 var start;
8869 var end;
8870 var length = data.length;
8871 while (index < length) {
8872 start = data[index];
8873 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8874
8875 if (start < HIGH_SURROGATE_MIN) {
8876
8877 // The range starts and ends before the high surrogate range.
8878 // E.g. (0, 0x10).
8879 if (end < HIGH_SURROGATE_MIN) {
8880 bmp.push(start, end + 1);
8881 }
8882
8883 // The range starts before the high surrogate range and ends within it.
8884 // E.g. (0, 0xD855).
8885 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
8886 bmp.push(start, HIGH_SURROGATE_MIN);
8887 loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
8888 }
8889
8890 // The range starts before the high surrogate range and ends in the low
8891 // surrogate range. E.g. (0, 0xDCFF).
8892 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8893 bmp.push(start, HIGH_SURROGATE_MIN);
8894 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
8895 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
8896 }
8897
8898 // The range starts before the high surrogate range and ends after the
8899 // low surrogate range. E.g. (0, 0x10FFFF).
8900 if (end > LOW_SURROGATE_MAX) {
8901 bmp.push(start, HIGH_SURROGATE_MIN);
8902 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
8903 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
8904 if (end <= 0xFFFF) {
8905 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8906 } else {
8907 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8908 astral.push(0xFFFF + 1, end + 1);
8909 }
8910 }
8911
8912 } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
8913
8914 // The range starts and ends in the high surrogate range.
8915 // E.g. (0xD855, 0xD866).
8916 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
8917 loneHighSurrogates.push(start, end + 1);
8918 }
8919
8920 // The range starts in the high surrogate range and ends in the low
8921 // surrogate range. E.g. (0xD855, 0xDCFF).
8922 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8923 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
8924 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
8925 }
8926
8927 // The range starts in the high surrogate range and ends after the low
8928 // surrogate range. E.g. (0xD855, 0x10FFFF).
8929 if (end > LOW_SURROGATE_MAX) {
8930 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
8931 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
8932 if (end <= 0xFFFF) {
8933 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8934 } else {
8935 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8936 astral.push(0xFFFF + 1, end + 1);
8937 }
8938 }
8939
8940 } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
8941
8942 // The range starts and ends in the low surrogate range.
8943 // E.g. (0xDCFF, 0xDDFF).
8944 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8945 loneLowSurrogates.push(start, end + 1);
8946 }
8947
8948 // The range starts in the low surrogate range and ends after the low
8949 // surrogate range. E.g. (0xDCFF, 0x10FFFF).
8950 if (end > LOW_SURROGATE_MAX) {
8951 loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
8952 if (end <= 0xFFFF) {
8953 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8954 } else {
8955 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8956 astral.push(0xFFFF + 1, end + 1);
8957 }
8958 }
8959
8960 } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
8961
8962 // The range starts and ends after the low surrogate range.
8963 // E.g. (0xFFAA, 0x10FFFF).
8964 if (end <= 0xFFFF) {
8965 bmp.push(start, end + 1);
8966 } else {
8967 bmp.push(start, 0xFFFF + 1);
8968 astral.push(0xFFFF + 1, end + 1);
8969 }
8970
8971 } else {
8972
8973 // The range starts and ends in the astral range.
8974 astral.push(start, end + 1);
8975
8976 }
8977
8978 index += 2;
8979 }
8980 return {
8981 'loneHighSurrogates': loneHighSurrogates,
8982 'loneLowSurrogates': loneLowSurrogates,
8983 'bmp': bmp,
8984 'astral': astral
8985 };
8986 };
8987
8988 var optimizeSurrogateMappings = function(surrogateMappings) {
8989 var result = [];
8990 var tmpLow = [];
8991 var addLow = false;
8992 var mapping;
8993 var nextMapping;
8994 var highSurrogates;
8995 var lowSurrogates;
8996 var nextHighSurrogates;
8997 var nextLowSurrogates;
8998 var index = -1;
8999 var length = surrogateMappings.length;
9000 while (++index < length) {
9001 mapping = surrogateMappings[index];
9002 nextMapping = surrogateMappings[index + 1];
9003 if (!nextMapping) {
9004 result.push(mapping);
9005 continue;
9006 }
9007 highSurrogates = mapping[0];
9008 lowSurrogates = mapping[1];
9009 nextHighSurrogates = nextMapping[0];
9010 nextLowSurrogates = nextMapping[1];
9011
9012 // Check for identical high surrogate ranges.
9013 tmpLow = lowSurrogates;
9014 while (
9015 nextHighSurrogates &&
9016 highSurrogates[0] == nextHighSurrogates[0] &&
9017 highSurrogates[1] == nextHighSurrogates[1]
9018 ) {
9019 // Merge with the next item.
9020 if (dataIsSingleton(nextLowSurrogates)) {
9021 tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
9022 } else {
9023 tmpLow = dataAddRange(
9024 tmpLow,
9025 nextLowSurrogates[0],
9026 nextLowSurrogates[1] - 1
9027 );
9028 }
9029 ++index;
9030 mapping = surrogateMappings[index];
9031 highSurrogates = mapping[0];
9032 lowSurrogates = mapping[1];
9033 nextMapping = surrogateMappings[index + 1];
9034 nextHighSurrogates = nextMapping && nextMapping[0];
9035 nextLowSurrogates = nextMapping && nextMapping[1];
9036 addLow = true;
9037 }
9038 result.push([
9039 highSurrogates,
9040 addLow ? tmpLow : lowSurrogates
9041 ]);
9042 addLow = false;
9043 }
9044 return optimizeByLowSurrogates(result);
9045 };
9046
9047 var optimizeByLowSurrogates = function(surrogateMappings) {
9048 if (surrogateMappings.length == 1) {
9049 return surrogateMappings;
9050 }
9051 var index = -1;
9052 var innerIndex = -1;
9053 while (++index < surrogateMappings.length) {
9054 var mapping = surrogateMappings[index];
9055 var lowSurrogates = mapping[1];
9056 var lowSurrogateStart = lowSurrogates[0];
9057 var lowSurrogateEnd = lowSurrogates[1];
9058 innerIndex = index; // Note: the loop starts at the next index.
9059 while (++innerIndex < surrogateMappings.length) {
9060 var otherMapping = surrogateMappings[innerIndex];
9061 var otherLowSurrogates = otherMapping[1];
9062 var otherLowSurrogateStart = otherLowSurrogates[0];
9063 var otherLowSurrogateEnd = otherLowSurrogates[1];
9064 if (
9065 lowSurrogateStart == otherLowSurrogateStart &&
9066 lowSurrogateEnd == otherLowSurrogateEnd
9067 ) {
9068 // Add the code points in the other item to this one.
9069 if (dataIsSingleton(otherMapping[0])) {
9070 mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
9071 } else {
9072 mapping[0] = dataAddRange(
9073 mapping[0],
9074 otherMapping[0][0],
9075 otherMapping[0][1] - 1
9076 );
9077 }
9078 // Remove the other, now redundant, item.
9079 surrogateMappings.splice(innerIndex, 1);
9080 --innerIndex;
9081 }
9082 }
9083 }
9084 return surrogateMappings;
9085 };
9086
9087 var surrogateSet = function(data) {
9088 // Exit early if `data` is an empty set.
9089 if (!data.length) {
9090 return [];
9091 }
9092
9093 // Iterate over the data per `(start, end)` pair.
9094 var index = 0;
9095 var start;
9096 var end;
9097 var startHigh;
9098 var startLow;
9099 var endHigh;
9100 var endLow;
9101 var surrogateMappings = [];
9102 var length = data.length;
9103 while (index < length) {
9104 start = data[index];
9105 end = data[index + 1] - 1;
9106
9107 startHigh = highSurrogate(start);
9108 startLow = lowSurrogate(start);
9109 endHigh = highSurrogate(end);
9110 endLow = lowSurrogate(end);
9111
9112 var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
9113 var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
9114 var complete = false;
9115
9116 // Append the previous high-surrogate-to-low-surrogate mappings.
9117 // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
9118 if (
9119 startHigh == endHigh ||
9120 startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
9121 ) {
9122 surrogateMappings.push([
9123 [startHigh, endHigh + 1],
9124 [startLow, endLow + 1]
9125 ]);
9126 complete = true;
9127 } else {
9128 surrogateMappings.push([
9129 [startHigh, startHigh + 1],
9130 [startLow, LOW_SURROGATE_MAX + 1]
9131 ]);
9132 }
9133
9134 // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
9135 // `(endHigh - 1, LOW_SURROGATE_MAX)`.
9136 if (!complete && startHigh + 1 < endHigh) {
9137 if (endsWithHighestLowSurrogate) {
9138 // Combine step 2 and step 3.
9139 surrogateMappings.push([
9140 [startHigh + 1, endHigh + 1],
9141 [LOW_SURROGATE_MIN, endLow + 1]
9142 ]);
9143 complete = true;
9144 } else {
9145 surrogateMappings.push([
9146 [startHigh + 1, endHigh],
9147 [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
9148 ]);
9149 }
9150 }
9151
9152 // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
9153 if (!complete) {
9154 surrogateMappings.push([
9155 [endHigh, endHigh + 1],
9156 [LOW_SURROGATE_MIN, endLow + 1]
9157 ]);
9158 }
9159
9160 index += 2;
9161 }
9162
9163 // The format of `surrogateMappings` is as follows:
9164 //
9165 // [ surrogateMapping1, surrogateMapping2 ]
9166 //
9167 // i.e.:
9168 //
9169 // [
9170 // [ highSurrogates1, lowSurrogates1 ],
9171 // [ highSurrogates2, lowSurrogates2 ]
9172 // ]
9173 return optimizeSurrogateMappings(surrogateMappings);
9174 };
9175
9176 var createSurrogateCharacterClasses = function(surrogateMappings) {
9177 var result = [];
9178 forEach(surrogateMappings, function(surrogateMapping) {
9179 var highSurrogates = surrogateMapping[0];
9180 var lowSurrogates = surrogateMapping[1];
9181 result.push(
9182 createBMPCharacterClasses(highSurrogates) +
9183 createBMPCharacterClasses(lowSurrogates)
9184 );
9185 });
9186 return result.join('|');
9187 };
9188
9189 var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
9190 if (hasUnicodeFlag) {
9191 return createUnicodeCharacterClasses(data);
9192 }
9193 var result = [];
9194
9195 var parts = splitAtBMP(data);
9196 var loneHighSurrogates = parts.loneHighSurrogates;
9197 var loneLowSurrogates = parts.loneLowSurrogates;
9198 var bmp = parts.bmp;
9199 var astral = parts.astral;
9200 var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
9201 var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
9202
9203 var surrogateMappings = surrogateSet(astral);
9204
9205 if (bmpOnly) {
9206 bmp = dataAddData(bmp, loneHighSurrogates);
9207 hasLoneHighSurrogates = false;
9208 bmp = dataAddData(bmp, loneLowSurrogates);
9209 hasLoneLowSurrogates = false;
9210 }
9211
9212 if (!dataIsEmpty(bmp)) {
9213 // The data set contains BMP code points that are not high surrogates
9214 // needed for astral code points in the set.
9215 result.push(createBMPCharacterClasses(bmp));
9216 }
9217 if (surrogateMappings.length) {
9218 // The data set contains astral code points; append character classes
9219 // based on their surrogate pairs.
9220 result.push(createSurrogateCharacterClasses(surrogateMappings));
9221 }
9222 // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
9223 if (hasLoneHighSurrogates) {
9224 result.push(
9225 createBMPCharacterClasses(loneHighSurrogates) +
9226 // Make sure the high surrogates aren’t part of a surrogate pair.
9227 '(?![\\uDC00-\\uDFFF])'
9228 );
9229 }
9230 if (hasLoneLowSurrogates) {
9231 result.push(
9232 // It is not possible to accurately assert the low surrogates aren’t
9233 // part of a surrogate pair, since JavaScript regular expressions do
9234 // not support lookbehind.
9235 '(?:[^\\uD800-\\uDBFF]|^)' +
9236 createBMPCharacterClasses(loneLowSurrogates)
9237 );
9238 }
9239 return result.join('|');
9240 };
9241
9242 /*--------------------------------------------------------------------------*/
9243
9244 // `regenerate` can be used as a constructor (and new methods can be added to
9245 // its prototype) but also as a regular function, the latter of which is the
9246 // documented and most common usage. For that reason, it’s not capitalized.
9247 var regenerate = function(value) {
9248 if (arguments.length > 1) {
9249 value = slice.call(arguments);
9250 }
9251 if (this instanceof regenerate) {
9252 this.data = [];
9253 return value ? this.add(value) : this;
9254 }
9255 return (new regenerate).add(value);
9256 };
9257
9258 regenerate.version = '1.3.3';
9259
9260 var proto = regenerate.prototype;
9261 extend(proto, {
9262 'add': function(value) {
9263 var $this = this;
9264 if (value == null) {
9265 return $this;
9266 }
9267 if (value instanceof regenerate) {
9268 // Allow passing other Regenerate instances.
9269 $this.data = dataAddData($this.data, value.data);
9270 return $this;
9271 }
9272 if (arguments.length > 1) {
9273 value = slice.call(arguments);
9274 }
9275 if (isArray(value)) {
9276 forEach(value, function(item) {
9277 $this.add(item);
9278 });
9279 return $this;
9280 }
9281 $this.data = dataAdd(
9282 $this.data,
9283 isNumber(value) ? value : symbolToCodePoint(value)
9284 );
9285 return $this;
9286 },
9287 'remove': function(value) {
9288 var $this = this;
9289 if (value == null) {
9290 return $this;
9291 }
9292 if (value instanceof regenerate) {
9293 // Allow passing other Regenerate instances.
9294 $this.data = dataRemoveData($this.data, value.data);
9295 return $this;
9296 }
9297 if (arguments.length > 1) {
9298 value = slice.call(arguments);
9299 }
9300 if (isArray(value)) {
9301 forEach(value, function(item) {
9302 $this.remove(item);
9303 });
9304 return $this;
9305 }
9306 $this.data = dataRemove(
9307 $this.data,
9308 isNumber(value) ? value : symbolToCodePoint(value)
9309 );
9310 return $this;
9311 },
9312 'addRange': function(start, end) {
9313 var $this = this;
9314 $this.data = dataAddRange($this.data,
9315 isNumber(start) ? start : symbolToCodePoint(start),
9316 isNumber(end) ? end : symbolToCodePoint(end)
9317 );
9318 return $this;
9319 },
9320 'removeRange': function(start, end) {
9321 var $this = this;
9322 var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
9323 var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
9324 $this.data = dataRemoveRange(
9325 $this.data,
9326 startCodePoint,
9327 endCodePoint
9328 );
9329 return $this;
9330 },
9331 'intersection': function(argument) {
9332 var $this = this;
9333 // Allow passing other Regenerate instances.
9334 // TODO: Optimize this by writing and using `dataIntersectionData()`.
9335 var array = argument instanceof regenerate ?
9336 dataToArray(argument.data) :
9337 argument;
9338 $this.data = dataIntersection($this.data, array);
9339 return $this;
9340 },
9341 'contains': function(codePoint) {
9342 return dataContains(
9343 this.data,
9344 isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
9345 );
9346 },
9347 'clone': function() {
9348 var set = new regenerate;
9349 set.data = this.data.slice(0);
9350 return set;
9351 },
9352 'toString': function(options) {
9353 var result = createCharacterClassesFromData(
9354 this.data,
9355 options ? options.bmpOnly : false,
9356 options ? options.hasUnicodeFlag : false
9357 );
9358 if (!result) {
9359 // For an empty set, return something that can be inserted `/here/` to
9360 // form a valid regular expression. Avoid `(?:)` since that matches the
9361 // empty string.
9362 return '[]';
9363 }
9364 // Use `\0` instead of `\x00` where possible.
9365 return result.replace(regexNull, '\\0$1');
9366 },
9367 'toRegExp': function(flags) {
9368 var pattern = this.toString(
9369 flags && flags.indexOf('u') != -1 ?
9370 { 'hasUnicodeFlag': true } :
9371 null
9372 );
9373 return RegExp(pattern, flags || '');
9374 },
9375 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
9376 return dataToArray(this.data);
9377 }
9378 });
9379
9380 proto.toArray = proto.valueOf;
9381
9382 // Some AMD build optimizers, like r.js, check for specific condition patterns
9383 // like the following:
9384 if (
9385 typeof undefined == 'function' &&
9386 typeof undefined.amd == 'object' &&
9387 undefined.amd
9388 ) {
9389 undefined(function() {
9390 return regenerate;
9391 });
9392 } else if (freeExports && !freeExports.nodeType) {
9393 if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
9394 freeModule.exports = regenerate;
9395 } else { // in Narwhal or RingoJS v0.7.0-
9396 freeExports.regenerate = regenerate;
9397 }
9398 } else { // in Rhino or a web browser
9399 root.regenerate = regenerate;
9400 }
9401
9402}(commonjsGlobal));
9403});
9404
9405var unicodeCanonicalPropertyNamesEcmascript = new Set([
9406 // Non-binary properties:
9407 'General_Category',
9408 'Script',
9409 'Script_Extensions',
9410 // Binary properties:
9411 'Alphabetic',
9412 'Any',
9413 'ASCII',
9414 'ASCII_Hex_Digit',
9415 'Assigned',
9416 'Bidi_Control',
9417 'Bidi_Mirrored',
9418 'Case_Ignorable',
9419 'Cased',
9420 'Changes_When_Casefolded',
9421 'Changes_When_Casemapped',
9422 'Changes_When_Lowercased',
9423 'Changes_When_NFKC_Casefolded',
9424 'Changes_When_Titlecased',
9425 'Changes_When_Uppercased',
9426 'Dash',
9427 'Default_Ignorable_Code_Point',
9428 'Deprecated',
9429 'Diacritic',
9430 'Emoji',
9431 'Emoji_Component',
9432 'Emoji_Modifier',
9433 'Emoji_Modifier_Base',
9434 'Emoji_Presentation',
9435 'Extended_Pictographic',
9436 'Extender',
9437 'Grapheme_Base',
9438 'Grapheme_Extend',
9439 'Hex_Digit',
9440 'ID_Continue',
9441 'ID_Start',
9442 'Ideographic',
9443 'IDS_Binary_Operator',
9444 'IDS_Trinary_Operator',
9445 'Join_Control',
9446 'Logical_Order_Exception',
9447 'Lowercase',
9448 'Math',
9449 'Noncharacter_Code_Point',
9450 'Pattern_Syntax',
9451 'Pattern_White_Space',
9452 'Quotation_Mark',
9453 'Radical',
9454 'Regional_Indicator',
9455 'Sentence_Terminal',
9456 'Soft_Dotted',
9457 'Terminal_Punctuation',
9458 'Unified_Ideograph',
9459 'Uppercase',
9460 'Variation_Selector',
9461 'White_Space',
9462 'XID_Continue',
9463 'XID_Start'
9464]);
9465
9466// Generated using `npm run build`. Do not edit!
9467var unicodePropertyAliasesEcmascript = new Map([
9468 ['scx', 'Script_Extensions'],
9469 ['sc', 'Script'],
9470 ['gc', 'General_Category'],
9471 ['AHex', 'ASCII_Hex_Digit'],
9472 ['Alpha', 'Alphabetic'],
9473 ['Bidi_C', 'Bidi_Control'],
9474 ['Bidi_M', 'Bidi_Mirrored'],
9475 ['Cased', 'Cased'],
9476 ['CI', 'Case_Ignorable'],
9477 ['CWCF', 'Changes_When_Casefolded'],
9478 ['CWCM', 'Changes_When_Casemapped'],
9479 ['CWKCF', 'Changes_When_NFKC_Casefolded'],
9480 ['CWL', 'Changes_When_Lowercased'],
9481 ['CWT', 'Changes_When_Titlecased'],
9482 ['CWU', 'Changes_When_Uppercased'],
9483 ['Dash', 'Dash'],
9484 ['Dep', 'Deprecated'],
9485 ['DI', 'Default_Ignorable_Code_Point'],
9486 ['Dia', 'Diacritic'],
9487 ['Ext', 'Extender'],
9488 ['Gr_Base', 'Grapheme_Base'],
9489 ['Gr_Ext', 'Grapheme_Extend'],
9490 ['Hex', 'Hex_Digit'],
9491 ['IDC', 'ID_Continue'],
9492 ['Ideo', 'Ideographic'],
9493 ['IDS', 'ID_Start'],
9494 ['IDSB', 'IDS_Binary_Operator'],
9495 ['IDST', 'IDS_Trinary_Operator'],
9496 ['Join_C', 'Join_Control'],
9497 ['LOE', 'Logical_Order_Exception'],
9498 ['Lower', 'Lowercase'],
9499 ['Math', 'Math'],
9500 ['NChar', 'Noncharacter_Code_Point'],
9501 ['Pat_Syn', 'Pattern_Syntax'],
9502 ['Pat_WS', 'Pattern_White_Space'],
9503 ['QMark', 'Quotation_Mark'],
9504 ['Radical', 'Radical'],
9505 ['RI', 'Regional_Indicator'],
9506 ['SD', 'Soft_Dotted'],
9507 ['STerm', 'Sentence_Terminal'],
9508 ['Term', 'Terminal_Punctuation'],
9509 ['UIdeo', 'Unified_Ideograph'],
9510 ['Upper', 'Uppercase'],
9511 ['VS', 'Variation_Selector'],
9512 ['WSpace', 'White_Space'],
9513 ['space', 'White_Space'],
9514 ['XIDC', 'XID_Continue'],
9515 ['XIDS', 'XID_Start']
9516]);
9517
9518'use strict';
9519
9520
9521
9522
9523const matchProperty = function(property) {
9524 if (unicodeCanonicalPropertyNamesEcmascript.has(property)) {
9525 return property;
9526 }
9527 if (unicodePropertyAliasesEcmascript.has(property)) {
9528 return unicodePropertyAliasesEcmascript.get(property);
9529 }
9530 throw new Error(`Unknown property: ${ property }`);
9531};
9532
9533var unicodeMatchPropertyEcmascript = matchProperty;
9534
9535var mappings = new Map([
9536 ['General_Category', new Map([
9537 ['C', 'Other'],
9538 ['Cc', 'Control'],
9539 ['cntrl', 'Control'],
9540 ['Cf', 'Format'],
9541 ['Cn', 'Unassigned'],
9542 ['Co', 'Private_Use'],
9543 ['Cs', 'Surrogate'],
9544 ['L', 'Letter'],
9545 ['LC', 'Cased_Letter'],
9546 ['Ll', 'Lowercase_Letter'],
9547 ['Lm', 'Modifier_Letter'],
9548 ['Lo', 'Other_Letter'],
9549 ['Lt', 'Titlecase_Letter'],
9550 ['Lu', 'Uppercase_Letter'],
9551 ['M', 'Mark'],
9552 ['Combining_Mark', 'Mark'],
9553 ['Mc', 'Spacing_Mark'],
9554 ['Me', 'Enclosing_Mark'],
9555 ['Mn', 'Nonspacing_Mark'],
9556 ['N', 'Number'],
9557 ['Nd', 'Decimal_Number'],
9558 ['digit', 'Decimal_Number'],
9559 ['Nl', 'Letter_Number'],
9560 ['No', 'Other_Number'],
9561 ['P', 'Punctuation'],
9562 ['punct', 'Punctuation'],
9563 ['Pc', 'Connector_Punctuation'],
9564 ['Pd', 'Dash_Punctuation'],
9565 ['Pe', 'Close_Punctuation'],
9566 ['Pf', 'Final_Punctuation'],
9567 ['Pi', 'Initial_Punctuation'],
9568 ['Po', 'Other_Punctuation'],
9569 ['Ps', 'Open_Punctuation'],
9570 ['S', 'Symbol'],
9571 ['Sc', 'Currency_Symbol'],
9572 ['Sk', 'Modifier_Symbol'],
9573 ['Sm', 'Math_Symbol'],
9574 ['So', 'Other_Symbol'],
9575 ['Z', 'Separator'],
9576 ['Zl', 'Line_Separator'],
9577 ['Zp', 'Paragraph_Separator'],
9578 ['Zs', 'Space_Separator'],
9579 ['Other', 'Other'],
9580 ['Control', 'Control'],
9581 ['Format', 'Format'],
9582 ['Unassigned', 'Unassigned'],
9583 ['Private_Use', 'Private_Use'],
9584 ['Surrogate', 'Surrogate'],
9585 ['Letter', 'Letter'],
9586 ['Cased_Letter', 'Cased_Letter'],
9587 ['Lowercase_Letter', 'Lowercase_Letter'],
9588 ['Modifier_Letter', 'Modifier_Letter'],
9589 ['Other_Letter', 'Other_Letter'],
9590 ['Titlecase_Letter', 'Titlecase_Letter'],
9591 ['Uppercase_Letter', 'Uppercase_Letter'],
9592 ['Mark', 'Mark'],
9593 ['Spacing_Mark', 'Spacing_Mark'],
9594 ['Enclosing_Mark', 'Enclosing_Mark'],
9595 ['Nonspacing_Mark', 'Nonspacing_Mark'],
9596 ['Number', 'Number'],
9597 ['Decimal_Number', 'Decimal_Number'],
9598 ['Letter_Number', 'Letter_Number'],
9599 ['Other_Number', 'Other_Number'],
9600 ['Punctuation', 'Punctuation'],
9601 ['Connector_Punctuation', 'Connector_Punctuation'],
9602 ['Dash_Punctuation', 'Dash_Punctuation'],
9603 ['Close_Punctuation', 'Close_Punctuation'],
9604 ['Final_Punctuation', 'Final_Punctuation'],
9605 ['Initial_Punctuation', 'Initial_Punctuation'],
9606 ['Other_Punctuation', 'Other_Punctuation'],
9607 ['Open_Punctuation', 'Open_Punctuation'],
9608 ['Symbol', 'Symbol'],
9609 ['Currency_Symbol', 'Currency_Symbol'],
9610 ['Modifier_Symbol', 'Modifier_Symbol'],
9611 ['Math_Symbol', 'Math_Symbol'],
9612 ['Other_Symbol', 'Other_Symbol'],
9613 ['Separator', 'Separator'],
9614 ['Line_Separator', 'Line_Separator'],
9615 ['Paragraph_Separator', 'Paragraph_Separator'],
9616 ['Space_Separator', 'Space_Separator']
9617 ])],
9618 ['Script', new Map([
9619 ['Adlm', 'Adlam'],
9620 ['Aghb', 'Caucasian_Albanian'],
9621 ['Ahom', 'Ahom'],
9622 ['Arab', 'Arabic'],
9623 ['Armi', 'Imperial_Aramaic'],
9624 ['Armn', 'Armenian'],
9625 ['Avst', 'Avestan'],
9626 ['Bali', 'Balinese'],
9627 ['Bamu', 'Bamum'],
9628 ['Bass', 'Bassa_Vah'],
9629 ['Batk', 'Batak'],
9630 ['Beng', 'Bengali'],
9631 ['Bhks', 'Bhaiksuki'],
9632 ['Bopo', 'Bopomofo'],
9633 ['Brah', 'Brahmi'],
9634 ['Brai', 'Braille'],
9635 ['Bugi', 'Buginese'],
9636 ['Buhd', 'Buhid'],
9637 ['Cakm', 'Chakma'],
9638 ['Cans', 'Canadian_Aboriginal'],
9639 ['Cari', 'Carian'],
9640 ['Cham', 'Cham'],
9641 ['Cher', 'Cherokee'],
9642 ['Copt', 'Coptic'],
9643 ['Qaac', 'Coptic'],
9644 ['Cprt', 'Cypriot'],
9645 ['Cyrl', 'Cyrillic'],
9646 ['Deva', 'Devanagari'],
9647 ['Dsrt', 'Deseret'],
9648 ['Dupl', 'Duployan'],
9649 ['Egyp', 'Egyptian_Hieroglyphs'],
9650 ['Elba', 'Elbasan'],
9651 ['Ethi', 'Ethiopic'],
9652 ['Geor', 'Georgian'],
9653 ['Glag', 'Glagolitic'],
9654 ['Gonm', 'Masaram_Gondi'],
9655 ['Goth', 'Gothic'],
9656 ['Gran', 'Grantha'],
9657 ['Grek', 'Greek'],
9658 ['Gujr', 'Gujarati'],
9659 ['Guru', 'Gurmukhi'],
9660 ['Hang', 'Hangul'],
9661 ['Hani', 'Han'],
9662 ['Hano', 'Hanunoo'],
9663 ['Hatr', 'Hatran'],
9664 ['Hebr', 'Hebrew'],
9665 ['Hira', 'Hiragana'],
9666 ['Hluw', 'Anatolian_Hieroglyphs'],
9667 ['Hmng', 'Pahawh_Hmong'],
9668 ['Hrkt', 'Katakana_Or_Hiragana'],
9669 ['Hung', 'Old_Hungarian'],
9670 ['Ital', 'Old_Italic'],
9671 ['Java', 'Javanese'],
9672 ['Kali', 'Kayah_Li'],
9673 ['Kana', 'Katakana'],
9674 ['Khar', 'Kharoshthi'],
9675 ['Khmr', 'Khmer'],
9676 ['Khoj', 'Khojki'],
9677 ['Knda', 'Kannada'],
9678 ['Kthi', 'Kaithi'],
9679 ['Lana', 'Tai_Tham'],
9680 ['Laoo', 'Lao'],
9681 ['Latn', 'Latin'],
9682 ['Lepc', 'Lepcha'],
9683 ['Limb', 'Limbu'],
9684 ['Lina', 'Linear_A'],
9685 ['Linb', 'Linear_B'],
9686 ['Lisu', 'Lisu'],
9687 ['Lyci', 'Lycian'],
9688 ['Lydi', 'Lydian'],
9689 ['Mahj', 'Mahajani'],
9690 ['Mand', 'Mandaic'],
9691 ['Mani', 'Manichaean'],
9692 ['Marc', 'Marchen'],
9693 ['Mend', 'Mende_Kikakui'],
9694 ['Merc', 'Meroitic_Cursive'],
9695 ['Mero', 'Meroitic_Hieroglyphs'],
9696 ['Mlym', 'Malayalam'],
9697 ['Modi', 'Modi'],
9698 ['Mong', 'Mongolian'],
9699 ['Mroo', 'Mro'],
9700 ['Mtei', 'Meetei_Mayek'],
9701 ['Mult', 'Multani'],
9702 ['Mymr', 'Myanmar'],
9703 ['Narb', 'Old_North_Arabian'],
9704 ['Nbat', 'Nabataean'],
9705 ['Newa', 'Newa'],
9706 ['Nkoo', 'Nko'],
9707 ['Nshu', 'Nushu'],
9708 ['Ogam', 'Ogham'],
9709 ['Olck', 'Ol_Chiki'],
9710 ['Orkh', 'Old_Turkic'],
9711 ['Orya', 'Oriya'],
9712 ['Osge', 'Osage'],
9713 ['Osma', 'Osmanya'],
9714 ['Palm', 'Palmyrene'],
9715 ['Pauc', 'Pau_Cin_Hau'],
9716 ['Perm', 'Old_Permic'],
9717 ['Phag', 'Phags_Pa'],
9718 ['Phli', 'Inscriptional_Pahlavi'],
9719 ['Phlp', 'Psalter_Pahlavi'],
9720 ['Phnx', 'Phoenician'],
9721 ['Plrd', 'Miao'],
9722 ['Prti', 'Inscriptional_Parthian'],
9723 ['Rjng', 'Rejang'],
9724 ['Runr', 'Runic'],
9725 ['Samr', 'Samaritan'],
9726 ['Sarb', 'Old_South_Arabian'],
9727 ['Saur', 'Saurashtra'],
9728 ['Sgnw', 'SignWriting'],
9729 ['Shaw', 'Shavian'],
9730 ['Shrd', 'Sharada'],
9731 ['Sidd', 'Siddham'],
9732 ['Sind', 'Khudawadi'],
9733 ['Sinh', 'Sinhala'],
9734 ['Sora', 'Sora_Sompeng'],
9735 ['Soyo', 'Soyombo'],
9736 ['Sund', 'Sundanese'],
9737 ['Sylo', 'Syloti_Nagri'],
9738 ['Syrc', 'Syriac'],
9739 ['Tagb', 'Tagbanwa'],
9740 ['Takr', 'Takri'],
9741 ['Tale', 'Tai_Le'],
9742 ['Talu', 'New_Tai_Lue'],
9743 ['Taml', 'Tamil'],
9744 ['Tang', 'Tangut'],
9745 ['Tavt', 'Tai_Viet'],
9746 ['Telu', 'Telugu'],
9747 ['Tfng', 'Tifinagh'],
9748 ['Tglg', 'Tagalog'],
9749 ['Thaa', 'Thaana'],
9750 ['Thai', 'Thai'],
9751 ['Tibt', 'Tibetan'],
9752 ['Tirh', 'Tirhuta'],
9753 ['Ugar', 'Ugaritic'],
9754 ['Vaii', 'Vai'],
9755 ['Wara', 'Warang_Citi'],
9756 ['Xpeo', 'Old_Persian'],
9757 ['Xsux', 'Cuneiform'],
9758 ['Yiii', 'Yi'],
9759 ['Zanb', 'Zanabazar_Square'],
9760 ['Zinh', 'Inherited'],
9761 ['Qaai', 'Inherited'],
9762 ['Zyyy', 'Common'],
9763 ['Zzzz', 'Unknown'],
9764 ['Adlam', 'Adlam'],
9765 ['Caucasian_Albanian', 'Caucasian_Albanian'],
9766 ['Arabic', 'Arabic'],
9767 ['Imperial_Aramaic', 'Imperial_Aramaic'],
9768 ['Armenian', 'Armenian'],
9769 ['Avestan', 'Avestan'],
9770 ['Balinese', 'Balinese'],
9771 ['Bamum', 'Bamum'],
9772 ['Bassa_Vah', 'Bassa_Vah'],
9773 ['Batak', 'Batak'],
9774 ['Bengali', 'Bengali'],
9775 ['Bhaiksuki', 'Bhaiksuki'],
9776 ['Bopomofo', 'Bopomofo'],
9777 ['Brahmi', 'Brahmi'],
9778 ['Braille', 'Braille'],
9779 ['Buginese', 'Buginese'],
9780 ['Buhid', 'Buhid'],
9781 ['Chakma', 'Chakma'],
9782 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
9783 ['Carian', 'Carian'],
9784 ['Cherokee', 'Cherokee'],
9785 ['Coptic', 'Coptic'],
9786 ['Cypriot', 'Cypriot'],
9787 ['Cyrillic', 'Cyrillic'],
9788 ['Devanagari', 'Devanagari'],
9789 ['Deseret', 'Deseret'],
9790 ['Duployan', 'Duployan'],
9791 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
9792 ['Elbasan', 'Elbasan'],
9793 ['Ethiopic', 'Ethiopic'],
9794 ['Georgian', 'Georgian'],
9795 ['Glagolitic', 'Glagolitic'],
9796 ['Masaram_Gondi', 'Masaram_Gondi'],
9797 ['Gothic', 'Gothic'],
9798 ['Grantha', 'Grantha'],
9799 ['Greek', 'Greek'],
9800 ['Gujarati', 'Gujarati'],
9801 ['Gurmukhi', 'Gurmukhi'],
9802 ['Hangul', 'Hangul'],
9803 ['Han', 'Han'],
9804 ['Hanunoo', 'Hanunoo'],
9805 ['Hatran', 'Hatran'],
9806 ['Hebrew', 'Hebrew'],
9807 ['Hiragana', 'Hiragana'],
9808 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
9809 ['Pahawh_Hmong', 'Pahawh_Hmong'],
9810 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
9811 ['Old_Hungarian', 'Old_Hungarian'],
9812 ['Old_Italic', 'Old_Italic'],
9813 ['Javanese', 'Javanese'],
9814 ['Kayah_Li', 'Kayah_Li'],
9815 ['Katakana', 'Katakana'],
9816 ['Kharoshthi', 'Kharoshthi'],
9817 ['Khmer', 'Khmer'],
9818 ['Khojki', 'Khojki'],
9819 ['Kannada', 'Kannada'],
9820 ['Kaithi', 'Kaithi'],
9821 ['Tai_Tham', 'Tai_Tham'],
9822 ['Lao', 'Lao'],
9823 ['Latin', 'Latin'],
9824 ['Lepcha', 'Lepcha'],
9825 ['Limbu', 'Limbu'],
9826 ['Linear_A', 'Linear_A'],
9827 ['Linear_B', 'Linear_B'],
9828 ['Lycian', 'Lycian'],
9829 ['Lydian', 'Lydian'],
9830 ['Mahajani', 'Mahajani'],
9831 ['Mandaic', 'Mandaic'],
9832 ['Manichaean', 'Manichaean'],
9833 ['Marchen', 'Marchen'],
9834 ['Mende_Kikakui', 'Mende_Kikakui'],
9835 ['Meroitic_Cursive', 'Meroitic_Cursive'],
9836 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
9837 ['Malayalam', 'Malayalam'],
9838 ['Mongolian', 'Mongolian'],
9839 ['Mro', 'Mro'],
9840 ['Meetei_Mayek', 'Meetei_Mayek'],
9841 ['Multani', 'Multani'],
9842 ['Myanmar', 'Myanmar'],
9843 ['Old_North_Arabian', 'Old_North_Arabian'],
9844 ['Nabataean', 'Nabataean'],
9845 ['Nko', 'Nko'],
9846 ['Nushu', 'Nushu'],
9847 ['Ogham', 'Ogham'],
9848 ['Ol_Chiki', 'Ol_Chiki'],
9849 ['Old_Turkic', 'Old_Turkic'],
9850 ['Oriya', 'Oriya'],
9851 ['Osage', 'Osage'],
9852 ['Osmanya', 'Osmanya'],
9853 ['Palmyrene', 'Palmyrene'],
9854 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
9855 ['Old_Permic', 'Old_Permic'],
9856 ['Phags_Pa', 'Phags_Pa'],
9857 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
9858 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
9859 ['Phoenician', 'Phoenician'],
9860 ['Miao', 'Miao'],
9861 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
9862 ['Rejang', 'Rejang'],
9863 ['Runic', 'Runic'],
9864 ['Samaritan', 'Samaritan'],
9865 ['Old_South_Arabian', 'Old_South_Arabian'],
9866 ['Saurashtra', 'Saurashtra'],
9867 ['SignWriting', 'SignWriting'],
9868 ['Shavian', 'Shavian'],
9869 ['Sharada', 'Sharada'],
9870 ['Siddham', 'Siddham'],
9871 ['Khudawadi', 'Khudawadi'],
9872 ['Sinhala', 'Sinhala'],
9873 ['Sora_Sompeng', 'Sora_Sompeng'],
9874 ['Soyombo', 'Soyombo'],
9875 ['Sundanese', 'Sundanese'],
9876 ['Syloti_Nagri', 'Syloti_Nagri'],
9877 ['Syriac', 'Syriac'],
9878 ['Tagbanwa', 'Tagbanwa'],
9879 ['Takri', 'Takri'],
9880 ['Tai_Le', 'Tai_Le'],
9881 ['New_Tai_Lue', 'New_Tai_Lue'],
9882 ['Tamil', 'Tamil'],
9883 ['Tangut', 'Tangut'],
9884 ['Tai_Viet', 'Tai_Viet'],
9885 ['Telugu', 'Telugu'],
9886 ['Tifinagh', 'Tifinagh'],
9887 ['Tagalog', 'Tagalog'],
9888 ['Thaana', 'Thaana'],
9889 ['Tibetan', 'Tibetan'],
9890 ['Tirhuta', 'Tirhuta'],
9891 ['Ugaritic', 'Ugaritic'],
9892 ['Vai', 'Vai'],
9893 ['Warang_Citi', 'Warang_Citi'],
9894 ['Old_Persian', 'Old_Persian'],
9895 ['Cuneiform', 'Cuneiform'],
9896 ['Yi', 'Yi'],
9897 ['Zanabazar_Square', 'Zanabazar_Square'],
9898 ['Inherited', 'Inherited'],
9899 ['Common', 'Common'],
9900 ['Unknown', 'Unknown']
9901 ])],
9902 ['Script_Extensions', new Map([
9903 ['Adlm', 'Adlam'],
9904 ['Aghb', 'Caucasian_Albanian'],
9905 ['Ahom', 'Ahom'],
9906 ['Arab', 'Arabic'],
9907 ['Armi', 'Imperial_Aramaic'],
9908 ['Armn', 'Armenian'],
9909 ['Avst', 'Avestan'],
9910 ['Bali', 'Balinese'],
9911 ['Bamu', 'Bamum'],
9912 ['Bass', 'Bassa_Vah'],
9913 ['Batk', 'Batak'],
9914 ['Beng', 'Bengali'],
9915 ['Bhks', 'Bhaiksuki'],
9916 ['Bopo', 'Bopomofo'],
9917 ['Brah', 'Brahmi'],
9918 ['Brai', 'Braille'],
9919 ['Bugi', 'Buginese'],
9920 ['Buhd', 'Buhid'],
9921 ['Cakm', 'Chakma'],
9922 ['Cans', 'Canadian_Aboriginal'],
9923 ['Cari', 'Carian'],
9924 ['Cham', 'Cham'],
9925 ['Cher', 'Cherokee'],
9926 ['Copt', 'Coptic'],
9927 ['Qaac', 'Coptic'],
9928 ['Cprt', 'Cypriot'],
9929 ['Cyrl', 'Cyrillic'],
9930 ['Deva', 'Devanagari'],
9931 ['Dsrt', 'Deseret'],
9932 ['Dupl', 'Duployan'],
9933 ['Egyp', 'Egyptian_Hieroglyphs'],
9934 ['Elba', 'Elbasan'],
9935 ['Ethi', 'Ethiopic'],
9936 ['Geor', 'Georgian'],
9937 ['Glag', 'Glagolitic'],
9938 ['Gonm', 'Masaram_Gondi'],
9939 ['Goth', 'Gothic'],
9940 ['Gran', 'Grantha'],
9941 ['Grek', 'Greek'],
9942 ['Gujr', 'Gujarati'],
9943 ['Guru', 'Gurmukhi'],
9944 ['Hang', 'Hangul'],
9945 ['Hani', 'Han'],
9946 ['Hano', 'Hanunoo'],
9947 ['Hatr', 'Hatran'],
9948 ['Hebr', 'Hebrew'],
9949 ['Hira', 'Hiragana'],
9950 ['Hluw', 'Anatolian_Hieroglyphs'],
9951 ['Hmng', 'Pahawh_Hmong'],
9952 ['Hrkt', 'Katakana_Or_Hiragana'],
9953 ['Hung', 'Old_Hungarian'],
9954 ['Ital', 'Old_Italic'],
9955 ['Java', 'Javanese'],
9956 ['Kali', 'Kayah_Li'],
9957 ['Kana', 'Katakana'],
9958 ['Khar', 'Kharoshthi'],
9959 ['Khmr', 'Khmer'],
9960 ['Khoj', 'Khojki'],
9961 ['Knda', 'Kannada'],
9962 ['Kthi', 'Kaithi'],
9963 ['Lana', 'Tai_Tham'],
9964 ['Laoo', 'Lao'],
9965 ['Latn', 'Latin'],
9966 ['Lepc', 'Lepcha'],
9967 ['Limb', 'Limbu'],
9968 ['Lina', 'Linear_A'],
9969 ['Linb', 'Linear_B'],
9970 ['Lisu', 'Lisu'],
9971 ['Lyci', 'Lycian'],
9972 ['Lydi', 'Lydian'],
9973 ['Mahj', 'Mahajani'],
9974 ['Mand', 'Mandaic'],
9975 ['Mani', 'Manichaean'],
9976 ['Marc', 'Marchen'],
9977 ['Mend', 'Mende_Kikakui'],
9978 ['Merc', 'Meroitic_Cursive'],
9979 ['Mero', 'Meroitic_Hieroglyphs'],
9980 ['Mlym', 'Malayalam'],
9981 ['Modi', 'Modi'],
9982 ['Mong', 'Mongolian'],
9983 ['Mroo', 'Mro'],
9984 ['Mtei', 'Meetei_Mayek'],
9985 ['Mult', 'Multani'],
9986 ['Mymr', 'Myanmar'],
9987 ['Narb', 'Old_North_Arabian'],
9988 ['Nbat', 'Nabataean'],
9989 ['Newa', 'Newa'],
9990 ['Nkoo', 'Nko'],
9991 ['Nshu', 'Nushu'],
9992 ['Ogam', 'Ogham'],
9993 ['Olck', 'Ol_Chiki'],
9994 ['Orkh', 'Old_Turkic'],
9995 ['Orya', 'Oriya'],
9996 ['Osge', 'Osage'],
9997 ['Osma', 'Osmanya'],
9998 ['Palm', 'Palmyrene'],
9999 ['Pauc', 'Pau_Cin_Hau'],
10000 ['Perm', 'Old_Permic'],
10001 ['Phag', 'Phags_Pa'],
10002 ['Phli', 'Inscriptional_Pahlavi'],
10003 ['Phlp', 'Psalter_Pahlavi'],
10004 ['Phnx', 'Phoenician'],
10005 ['Plrd', 'Miao'],
10006 ['Prti', 'Inscriptional_Parthian'],
10007 ['Rjng', 'Rejang'],
10008 ['Runr', 'Runic'],
10009 ['Samr', 'Samaritan'],
10010 ['Sarb', 'Old_South_Arabian'],
10011 ['Saur', 'Saurashtra'],
10012 ['Sgnw', 'SignWriting'],
10013 ['Shaw', 'Shavian'],
10014 ['Shrd', 'Sharada'],
10015 ['Sidd', 'Siddham'],
10016 ['Sind', 'Khudawadi'],
10017 ['Sinh', 'Sinhala'],
10018 ['Sora', 'Sora_Sompeng'],
10019 ['Soyo', 'Soyombo'],
10020 ['Sund', 'Sundanese'],
10021 ['Sylo', 'Syloti_Nagri'],
10022 ['Syrc', 'Syriac'],
10023 ['Tagb', 'Tagbanwa'],
10024 ['Takr', 'Takri'],
10025 ['Tale', 'Tai_Le'],
10026 ['Talu', 'New_Tai_Lue'],
10027 ['Taml', 'Tamil'],
10028 ['Tang', 'Tangut'],
10029 ['Tavt', 'Tai_Viet'],
10030 ['Telu', 'Telugu'],
10031 ['Tfng', 'Tifinagh'],
10032 ['Tglg', 'Tagalog'],
10033 ['Thaa', 'Thaana'],
10034 ['Thai', 'Thai'],
10035 ['Tibt', 'Tibetan'],
10036 ['Tirh', 'Tirhuta'],
10037 ['Ugar', 'Ugaritic'],
10038 ['Vaii', 'Vai'],
10039 ['Wara', 'Warang_Citi'],
10040 ['Xpeo', 'Old_Persian'],
10041 ['Xsux', 'Cuneiform'],
10042 ['Yiii', 'Yi'],
10043 ['Zanb', 'Zanabazar_Square'],
10044 ['Zinh', 'Inherited'],
10045 ['Qaai', 'Inherited'],
10046 ['Zyyy', 'Common'],
10047 ['Zzzz', 'Unknown'],
10048 ['Adlam', 'Adlam'],
10049 ['Caucasian_Albanian', 'Caucasian_Albanian'],
10050 ['Arabic', 'Arabic'],
10051 ['Imperial_Aramaic', 'Imperial_Aramaic'],
10052 ['Armenian', 'Armenian'],
10053 ['Avestan', 'Avestan'],
10054 ['Balinese', 'Balinese'],
10055 ['Bamum', 'Bamum'],
10056 ['Bassa_Vah', 'Bassa_Vah'],
10057 ['Batak', 'Batak'],
10058 ['Bengali', 'Bengali'],
10059 ['Bhaiksuki', 'Bhaiksuki'],
10060 ['Bopomofo', 'Bopomofo'],
10061 ['Brahmi', 'Brahmi'],
10062 ['Braille', 'Braille'],
10063 ['Buginese', 'Buginese'],
10064 ['Buhid', 'Buhid'],
10065 ['Chakma', 'Chakma'],
10066 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
10067 ['Carian', 'Carian'],
10068 ['Cherokee', 'Cherokee'],
10069 ['Coptic', 'Coptic'],
10070 ['Cypriot', 'Cypriot'],
10071 ['Cyrillic', 'Cyrillic'],
10072 ['Devanagari', 'Devanagari'],
10073 ['Deseret', 'Deseret'],
10074 ['Duployan', 'Duployan'],
10075 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
10076 ['Elbasan', 'Elbasan'],
10077 ['Ethiopic', 'Ethiopic'],
10078 ['Georgian', 'Georgian'],
10079 ['Glagolitic', 'Glagolitic'],
10080 ['Masaram_Gondi', 'Masaram_Gondi'],
10081 ['Gothic', 'Gothic'],
10082 ['Grantha', 'Grantha'],
10083 ['Greek', 'Greek'],
10084 ['Gujarati', 'Gujarati'],
10085 ['Gurmukhi', 'Gurmukhi'],
10086 ['Hangul', 'Hangul'],
10087 ['Han', 'Han'],
10088 ['Hanunoo', 'Hanunoo'],
10089 ['Hatran', 'Hatran'],
10090 ['Hebrew', 'Hebrew'],
10091 ['Hiragana', 'Hiragana'],
10092 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
10093 ['Pahawh_Hmong', 'Pahawh_Hmong'],
10094 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
10095 ['Old_Hungarian', 'Old_Hungarian'],
10096 ['Old_Italic', 'Old_Italic'],
10097 ['Javanese', 'Javanese'],
10098 ['Kayah_Li', 'Kayah_Li'],
10099 ['Katakana', 'Katakana'],
10100 ['Kharoshthi', 'Kharoshthi'],
10101 ['Khmer', 'Khmer'],
10102 ['Khojki', 'Khojki'],
10103 ['Kannada', 'Kannada'],
10104 ['Kaithi', 'Kaithi'],
10105 ['Tai_Tham', 'Tai_Tham'],
10106 ['Lao', 'Lao'],
10107 ['Latin', 'Latin'],
10108 ['Lepcha', 'Lepcha'],
10109 ['Limbu', 'Limbu'],
10110 ['Linear_A', 'Linear_A'],
10111 ['Linear_B', 'Linear_B'],
10112 ['Lycian', 'Lycian'],
10113 ['Lydian', 'Lydian'],
10114 ['Mahajani', 'Mahajani'],
10115 ['Mandaic', 'Mandaic'],
10116 ['Manichaean', 'Manichaean'],
10117 ['Marchen', 'Marchen'],
10118 ['Mende_Kikakui', 'Mende_Kikakui'],
10119 ['Meroitic_Cursive', 'Meroitic_Cursive'],
10120 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
10121 ['Malayalam', 'Malayalam'],
10122 ['Mongolian', 'Mongolian'],
10123 ['Mro', 'Mro'],
10124 ['Meetei_Mayek', 'Meetei_Mayek'],
10125 ['Multani', 'Multani'],
10126 ['Myanmar', 'Myanmar'],
10127 ['Old_North_Arabian', 'Old_North_Arabian'],
10128 ['Nabataean', 'Nabataean'],
10129 ['Nko', 'Nko'],
10130 ['Nushu', 'Nushu'],
10131 ['Ogham', 'Ogham'],
10132 ['Ol_Chiki', 'Ol_Chiki'],
10133 ['Old_Turkic', 'Old_Turkic'],
10134 ['Oriya', 'Oriya'],
10135 ['Osage', 'Osage'],
10136 ['Osmanya', 'Osmanya'],
10137 ['Palmyrene', 'Palmyrene'],
10138 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
10139 ['Old_Permic', 'Old_Permic'],
10140 ['Phags_Pa', 'Phags_Pa'],
10141 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
10142 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
10143 ['Phoenician', 'Phoenician'],
10144 ['Miao', 'Miao'],
10145 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
10146 ['Rejang', 'Rejang'],
10147 ['Runic', 'Runic'],
10148 ['Samaritan', 'Samaritan'],
10149 ['Old_South_Arabian', 'Old_South_Arabian'],
10150 ['Saurashtra', 'Saurashtra'],
10151 ['SignWriting', 'SignWriting'],
10152 ['Shavian', 'Shavian'],
10153 ['Sharada', 'Sharada'],
10154 ['Siddham', 'Siddham'],
10155 ['Khudawadi', 'Khudawadi'],
10156 ['Sinhala', 'Sinhala'],
10157 ['Sora_Sompeng', 'Sora_Sompeng'],
10158 ['Soyombo', 'Soyombo'],
10159 ['Sundanese', 'Sundanese'],
10160 ['Syloti_Nagri', 'Syloti_Nagri'],
10161 ['Syriac', 'Syriac'],
10162 ['Tagbanwa', 'Tagbanwa'],
10163 ['Takri', 'Takri'],
10164 ['Tai_Le', 'Tai_Le'],
10165 ['New_Tai_Lue', 'New_Tai_Lue'],
10166 ['Tamil', 'Tamil'],
10167 ['Tangut', 'Tangut'],
10168 ['Tai_Viet', 'Tai_Viet'],
10169 ['Telugu', 'Telugu'],
10170 ['Tifinagh', 'Tifinagh'],
10171 ['Tagalog', 'Tagalog'],
10172 ['Thaana', 'Thaana'],
10173 ['Tibetan', 'Tibetan'],
10174 ['Tirhuta', 'Tirhuta'],
10175 ['Ugaritic', 'Ugaritic'],
10176 ['Vai', 'Vai'],
10177 ['Warang_Citi', 'Warang_Citi'],
10178 ['Old_Persian', 'Old_Persian'],
10179 ['Cuneiform', 'Cuneiform'],
10180 ['Yi', 'Yi'],
10181 ['Zanabazar_Square', 'Zanabazar_Square'],
10182 ['Inherited', 'Inherited'],
10183 ['Common', 'Common'],
10184 ['Unknown', 'Unknown']
10185 ])]
10186]);
10187
10188'use strict';
10189
10190
10191
10192const matchPropertyValue = function(property, value) {
10193 const aliasToValue = mappings.get(property);
10194 if (!aliasToValue) {
10195 throw new Error(`Unknown property \`${ property }\`.`);
10196 }
10197 const canonicalValue = aliasToValue.get(value);
10198 if (canonicalValue) {
10199 return canonicalValue;
10200 }
10201 throw new Error(
10202 `Unknown value \`${ value }\` for property \`${ property }\`.`
10203 );
10204};
10205
10206var unicodeMatchPropertyValueEcmascript = matchPropertyValue;
10207
10208var iuMappings = new Map([
10209 [0x4B, 0x212A],
10210 [0x53, 0x17F],
10211 [0x6B, 0x212A],
10212 [0x73, 0x17F],
10213 [0xB5, 0x39C],
10214 [0xC5, 0x212B],
10215 [0xDF, 0x1E9E],
10216 [0xE5, 0x212B],
10217 [0x17F, 0x53],
10218 [0x1C4, 0x1C5],
10219 [0x1C5, 0x1C4],
10220 [0x1C7, 0x1C8],
10221 [0x1C8, 0x1C7],
10222 [0x1CA, 0x1CB],
10223 [0x1CB, 0x1CA],
10224 [0x1F1, 0x1F2],
10225 [0x1F2, 0x1F1],
10226 [0x26A, 0xA7AE],
10227 [0x29D, 0xA7B2],
10228 [0x345, 0x1FBE],
10229 [0x392, 0x3D0],
10230 [0x395, 0x3F5],
10231 [0x398, 0x3F4],
10232 [0x399, 0x1FBE],
10233 [0x39A, 0x3F0],
10234 [0x39C, 0xB5],
10235 [0x3A0, 0x3D6],
10236 [0x3A1, 0x3F1],
10237 [0x3A3, 0x3C2],
10238 [0x3A6, 0x3D5],
10239 [0x3A9, 0x2126],
10240 [0x3B8, 0x3F4],
10241 [0x3C2, 0x3A3],
10242 [0x3C9, 0x2126],
10243 [0x3D0, 0x392],
10244 [0x3D1, 0x3F4],
10245 [0x3D5, 0x3A6],
10246 [0x3D6, 0x3A0],
10247 [0x3F0, 0x39A],
10248 [0x3F1, 0x3A1],
10249 [0x3F4, [
10250 0x398,
10251 0x3D1,
10252 0x3B8
10253 ]],
10254 [0x3F5, 0x395],
10255 [0x412, 0x1C80],
10256 [0x414, 0x1C81],
10257 [0x41E, 0x1C82],
10258 [0x421, 0x1C83],
10259 [0x422, 0x1C85],
10260 [0x42A, 0x1C86],
10261 [0x432, 0x1C80],
10262 [0x434, 0x1C81],
10263 [0x43E, 0x1C82],
10264 [0x441, 0x1C83],
10265 [0x442, [
10266 0x1C84,
10267 0x1C85
10268 ]],
10269 [0x44A, 0x1C86],
10270 [0x462, 0x1C87],
10271 [0x463, 0x1C87],
10272 [0x13A0, 0xAB70],
10273 [0x13A1, 0xAB71],
10274 [0x13A2, 0xAB72],
10275 [0x13A3, 0xAB73],
10276 [0x13A4, 0xAB74],
10277 [0x13A5, 0xAB75],
10278 [0x13A6, 0xAB76],
10279 [0x13A7, 0xAB77],
10280 [0x13A8, 0xAB78],
10281 [0x13A9, 0xAB79],
10282 [0x13AA, 0xAB7A],
10283 [0x13AB, 0xAB7B],
10284 [0x13AC, 0xAB7C],
10285 [0x13AD, 0xAB7D],
10286 [0x13AE, 0xAB7E],
10287 [0x13AF, 0xAB7F],
10288 [0x13B0, 0xAB80],
10289 [0x13B1, 0xAB81],
10290 [0x13B2, 0xAB82],
10291 [0x13B3, 0xAB83],
10292 [0x13B4, 0xAB84],
10293 [0x13B5, 0xAB85],
10294 [0x13B6, 0xAB86],
10295 [0x13B7, 0xAB87],
10296 [0x13B8, 0xAB88],
10297 [0x13B9, 0xAB89],
10298 [0x13BA, 0xAB8A],
10299 [0x13BB, 0xAB8B],
10300 [0x13BC, 0xAB8C],
10301 [0x13BD, 0xAB8D],
10302 [0x13BE, 0xAB8E],
10303 [0x13BF, 0xAB8F],
10304 [0x13C0, 0xAB90],
10305 [0x13C1, 0xAB91],
10306 [0x13C2, 0xAB92],
10307 [0x13C3, 0xAB93],
10308 [0x13C4, 0xAB94],
10309 [0x13C5, 0xAB95],
10310 [0x13C6, 0xAB96],
10311 [0x13C7, 0xAB97],
10312 [0x13C8, 0xAB98],
10313 [0x13C9, 0xAB99],
10314 [0x13CA, 0xAB9A],
10315 [0x13CB, 0xAB9B],
10316 [0x13CC, 0xAB9C],
10317 [0x13CD, 0xAB9D],
10318 [0x13CE, 0xAB9E],
10319 [0x13CF, 0xAB9F],
10320 [0x13D0, 0xABA0],
10321 [0x13D1, 0xABA1],
10322 [0x13D2, 0xABA2],
10323 [0x13D3, 0xABA3],
10324 [0x13D4, 0xABA4],
10325 [0x13D5, 0xABA5],
10326 [0x13D6, 0xABA6],
10327 [0x13D7, 0xABA7],
10328 [0x13D8, 0xABA8],
10329 [0x13D9, 0xABA9],
10330 [0x13DA, 0xABAA],
10331 [0x13DB, 0xABAB],
10332 [0x13DC, 0xABAC],
10333 [0x13DD, 0xABAD],
10334 [0x13DE, 0xABAE],
10335 [0x13DF, 0xABAF],
10336 [0x13E0, 0xABB0],
10337 [0x13E1, 0xABB1],
10338 [0x13E2, 0xABB2],
10339 [0x13E3, 0xABB3],
10340 [0x13E4, 0xABB4],
10341 [0x13E5, 0xABB5],
10342 [0x13E6, 0xABB6],
10343 [0x13E7, 0xABB7],
10344 [0x13E8, 0xABB8],
10345 [0x13E9, 0xABB9],
10346 [0x13EA, 0xABBA],
10347 [0x13EB, 0xABBB],
10348 [0x13EC, 0xABBC],
10349 [0x13ED, 0xABBD],
10350 [0x13EE, 0xABBE],
10351 [0x13EF, 0xABBF],
10352 [0x13F0, 0x13F8],
10353 [0x13F1, 0x13F9],
10354 [0x13F2, 0x13FA],
10355 [0x13F3, 0x13FB],
10356 [0x13F4, 0x13FC],
10357 [0x13F5, 0x13FD],
10358 [0x13F8, 0x13F0],
10359 [0x13F9, 0x13F1],
10360 [0x13FA, 0x13F2],
10361 [0x13FB, 0x13F3],
10362 [0x13FC, 0x13F4],
10363 [0x13FD, 0x13F5],
10364 [0x1C80, [
10365 0x412,
10366 0x432
10367 ]],
10368 [0x1C81, [
10369 0x414,
10370 0x434
10371 ]],
10372 [0x1C82, [
10373 0x41E,
10374 0x43E
10375 ]],
10376 [0x1C83, [
10377 0x421,
10378 0x441
10379 ]],
10380 [0x1C84, [
10381 0x1C85,
10382 0x442
10383 ]],
10384 [0x1C85, [
10385 0x422,
10386 0x1C84,
10387 0x442
10388 ]],
10389 [0x1C86, [
10390 0x42A,
10391 0x44A
10392 ]],
10393 [0x1C87, [
10394 0x462,
10395 0x463
10396 ]],
10397 [0x1C88, [
10398 0xA64A,
10399 0xA64B
10400 ]],
10401 [0x1E60, 0x1E9B],
10402 [0x1E9B, 0x1E60],
10403 [0x1E9E, 0xDF],
10404 [0x1F80, 0x1F88],
10405 [0x1F81, 0x1F89],
10406 [0x1F82, 0x1F8A],
10407 [0x1F83, 0x1F8B],
10408 [0x1F84, 0x1F8C],
10409 [0x1F85, 0x1F8D],
10410 [0x1F86, 0x1F8E],
10411 [0x1F87, 0x1F8F],
10412 [0x1F88, 0x1F80],
10413 [0x1F89, 0x1F81],
10414 [0x1F8A, 0x1F82],
10415 [0x1F8B, 0x1F83],
10416 [0x1F8C, 0x1F84],
10417 [0x1F8D, 0x1F85],
10418 [0x1F8E, 0x1F86],
10419 [0x1F8F, 0x1F87],
10420 [0x1F90, 0x1F98],
10421 [0x1F91, 0x1F99],
10422 [0x1F92, 0x1F9A],
10423 [0x1F93, 0x1F9B],
10424 [0x1F94, 0x1F9C],
10425 [0x1F95, 0x1F9D],
10426 [0x1F96, 0x1F9E],
10427 [0x1F97, 0x1F9F],
10428 [0x1F98, 0x1F90],
10429 [0x1F99, 0x1F91],
10430 [0x1F9A, 0x1F92],
10431 [0x1F9B, 0x1F93],
10432 [0x1F9C, 0x1F94],
10433 [0x1F9D, 0x1F95],
10434 [0x1F9E, 0x1F96],
10435 [0x1F9F, 0x1F97],
10436 [0x1FA0, 0x1FA8],
10437 [0x1FA1, 0x1FA9],
10438 [0x1FA2, 0x1FAA],
10439 [0x1FA3, 0x1FAB],
10440 [0x1FA4, 0x1FAC],
10441 [0x1FA5, 0x1FAD],
10442 [0x1FA6, 0x1FAE],
10443 [0x1FA7, 0x1FAF],
10444 [0x1FA8, 0x1FA0],
10445 [0x1FA9, 0x1FA1],
10446 [0x1FAA, 0x1FA2],
10447 [0x1FAB, 0x1FA3],
10448 [0x1FAC, 0x1FA4],
10449 [0x1FAD, 0x1FA5],
10450 [0x1FAE, 0x1FA6],
10451 [0x1FAF, 0x1FA7],
10452 [0x1FB3, 0x1FBC],
10453 [0x1FBC, 0x1FB3],
10454 [0x1FBE, [
10455 0x345,
10456 0x399
10457 ]],
10458 [0x1FC3, 0x1FCC],
10459 [0x1FCC, 0x1FC3],
10460 [0x1FF3, 0x1FFC],
10461 [0x1FFC, 0x1FF3],
10462 [0x2126, [
10463 0x3A9,
10464 0x3C9
10465 ]],
10466 [0x212A, 0x4B],
10467 [0x212B, [
10468 0xC5,
10469 0xE5
10470 ]],
10471 [0xA64A, 0x1C88],
10472 [0xA64B, 0x1C88],
10473 [0xA7AE, 0x26A],
10474 [0xA7B2, 0x29D],
10475 [0xA7B3, 0xAB53],
10476 [0xA7B4, 0xA7B5],
10477 [0xA7B5, 0xA7B4],
10478 [0xA7B6, 0xA7B7],
10479 [0xA7B7, 0xA7B6],
10480 [0xAB53, 0xA7B3],
10481 [0xAB70, 0x13A0],
10482 [0xAB71, 0x13A1],
10483 [0xAB72, 0x13A2],
10484 [0xAB73, 0x13A3],
10485 [0xAB74, 0x13A4],
10486 [0xAB75, 0x13A5],
10487 [0xAB76, 0x13A6],
10488 [0xAB77, 0x13A7],
10489 [0xAB78, 0x13A8],
10490 [0xAB79, 0x13A9],
10491 [0xAB7A, 0x13AA],
10492 [0xAB7B, 0x13AB],
10493 [0xAB7C, 0x13AC],
10494 [0xAB7D, 0x13AD],
10495 [0xAB7E, 0x13AE],
10496 [0xAB7F, 0x13AF],
10497 [0xAB80, 0x13B0],
10498 [0xAB81, 0x13B1],
10499 [0xAB82, 0x13B2],
10500 [0xAB83, 0x13B3],
10501 [0xAB84, 0x13B4],
10502 [0xAB85, 0x13B5],
10503 [0xAB86, 0x13B6],
10504 [0xAB87, 0x13B7],
10505 [0xAB88, 0x13B8],
10506 [0xAB89, 0x13B9],
10507 [0xAB8A, 0x13BA],
10508 [0xAB8B, 0x13BB],
10509 [0xAB8C, 0x13BC],
10510 [0xAB8D, 0x13BD],
10511 [0xAB8E, 0x13BE],
10512 [0xAB8F, 0x13BF],
10513 [0xAB90, 0x13C0],
10514 [0xAB91, 0x13C1],
10515 [0xAB92, 0x13C2],
10516 [0xAB93, 0x13C3],
10517 [0xAB94, 0x13C4],
10518 [0xAB95, 0x13C5],
10519 [0xAB96, 0x13C6],
10520 [0xAB97, 0x13C7],
10521 [0xAB98, 0x13C8],
10522 [0xAB99, 0x13C9],
10523 [0xAB9A, 0x13CA],
10524 [0xAB9B, 0x13CB],
10525 [0xAB9C, 0x13CC],
10526 [0xAB9D, 0x13CD],
10527 [0xAB9E, 0x13CE],
10528 [0xAB9F, 0x13CF],
10529 [0xABA0, 0x13D0],
10530 [0xABA1, 0x13D1],
10531 [0xABA2, 0x13D2],
10532 [0xABA3, 0x13D3],
10533 [0xABA4, 0x13D4],
10534 [0xABA5, 0x13D5],
10535 [0xABA6, 0x13D6],
10536 [0xABA7, 0x13D7],
10537 [0xABA8, 0x13D8],
10538 [0xABA9, 0x13D9],
10539 [0xABAA, 0x13DA],
10540 [0xABAB, 0x13DB],
10541 [0xABAC, 0x13DC],
10542 [0xABAD, 0x13DD],
10543 [0xABAE, 0x13DE],
10544 [0xABAF, 0x13DF],
10545 [0xABB0, 0x13E0],
10546 [0xABB1, 0x13E1],
10547 [0xABB2, 0x13E2],
10548 [0xABB3, 0x13E3],
10549 [0xABB4, 0x13E4],
10550 [0xABB5, 0x13E5],
10551 [0xABB6, 0x13E6],
10552 [0xABB7, 0x13E7],
10553 [0xABB8, 0x13E8],
10554 [0xABB9, 0x13E9],
10555 [0xABBA, 0x13EA],
10556 [0xABBB, 0x13EB],
10557 [0xABBC, 0x13EC],
10558 [0xABBD, 0x13ED],
10559 [0xABBE, 0x13EE],
10560 [0xABBF, 0x13EF],
10561 [0x10400, 0x10428],
10562 [0x10401, 0x10429],
10563 [0x10402, 0x1042A],
10564 [0x10403, 0x1042B],
10565 [0x10404, 0x1042C],
10566 [0x10405, 0x1042D],
10567 [0x10406, 0x1042E],
10568 [0x10407, 0x1042F],
10569 [0x10408, 0x10430],
10570 [0x10409, 0x10431],
10571 [0x1040A, 0x10432],
10572 [0x1040B, 0x10433],
10573 [0x1040C, 0x10434],
10574 [0x1040D, 0x10435],
10575 [0x1040E, 0x10436],
10576 [0x1040F, 0x10437],
10577 [0x10410, 0x10438],
10578 [0x10411, 0x10439],
10579 [0x10412, 0x1043A],
10580 [0x10413, 0x1043B],
10581 [0x10414, 0x1043C],
10582 [0x10415, 0x1043D],
10583 [0x10416, 0x1043E],
10584 [0x10417, 0x1043F],
10585 [0x10418, 0x10440],
10586 [0x10419, 0x10441],
10587 [0x1041A, 0x10442],
10588 [0x1041B, 0x10443],
10589 [0x1041C, 0x10444],
10590 [0x1041D, 0x10445],
10591 [0x1041E, 0x10446],
10592 [0x1041F, 0x10447],
10593 [0x10420, 0x10448],
10594 [0x10421, 0x10449],
10595 [0x10422, 0x1044A],
10596 [0x10423, 0x1044B],
10597 [0x10424, 0x1044C],
10598 [0x10425, 0x1044D],
10599 [0x10426, 0x1044E],
10600 [0x10427, 0x1044F],
10601 [0x10428, 0x10400],
10602 [0x10429, 0x10401],
10603 [0x1042A, 0x10402],
10604 [0x1042B, 0x10403],
10605 [0x1042C, 0x10404],
10606 [0x1042D, 0x10405],
10607 [0x1042E, 0x10406],
10608 [0x1042F, 0x10407],
10609 [0x10430, 0x10408],
10610 [0x10431, 0x10409],
10611 [0x10432, 0x1040A],
10612 [0x10433, 0x1040B],
10613 [0x10434, 0x1040C],
10614 [0x10435, 0x1040D],
10615 [0x10436, 0x1040E],
10616 [0x10437, 0x1040F],
10617 [0x10438, 0x10410],
10618 [0x10439, 0x10411],
10619 [0x1043A, 0x10412],
10620 [0x1043B, 0x10413],
10621 [0x1043C, 0x10414],
10622 [0x1043D, 0x10415],
10623 [0x1043E, 0x10416],
10624 [0x1043F, 0x10417],
10625 [0x10440, 0x10418],
10626 [0x10441, 0x10419],
10627 [0x10442, 0x1041A],
10628 [0x10443, 0x1041B],
10629 [0x10444, 0x1041C],
10630 [0x10445, 0x1041D],
10631 [0x10446, 0x1041E],
10632 [0x10447, 0x1041F],
10633 [0x10448, 0x10420],
10634 [0x10449, 0x10421],
10635 [0x1044A, 0x10422],
10636 [0x1044B, 0x10423],
10637 [0x1044C, 0x10424],
10638 [0x1044D, 0x10425],
10639 [0x1044E, 0x10426],
10640 [0x1044F, 0x10427],
10641 [0x104B0, 0x104D8],
10642 [0x104B1, 0x104D9],
10643 [0x104B2, 0x104DA],
10644 [0x104B3, 0x104DB],
10645 [0x104B4, 0x104DC],
10646 [0x104B5, 0x104DD],
10647 [0x104B6, 0x104DE],
10648 [0x104B7, 0x104DF],
10649 [0x104B8, 0x104E0],
10650 [0x104B9, 0x104E1],
10651 [0x104BA, 0x104E2],
10652 [0x104BB, 0x104E3],
10653 [0x104BC, 0x104E4],
10654 [0x104BD, 0x104E5],
10655 [0x104BE, 0x104E6],
10656 [0x104BF, 0x104E7],
10657 [0x104C0, 0x104E8],
10658 [0x104C1, 0x104E9],
10659 [0x104C2, 0x104EA],
10660 [0x104C3, 0x104EB],
10661 [0x104C4, 0x104EC],
10662 [0x104C5, 0x104ED],
10663 [0x104C6, 0x104EE],
10664 [0x104C7, 0x104EF],
10665 [0x104C8, 0x104F0],
10666 [0x104C9, 0x104F1],
10667 [0x104CA, 0x104F2],
10668 [0x104CB, 0x104F3],
10669 [0x104CC, 0x104F4],
10670 [0x104CD, 0x104F5],
10671 [0x104CE, 0x104F6],
10672 [0x104CF, 0x104F7],
10673 [0x104D0, 0x104F8],
10674 [0x104D1, 0x104F9],
10675 [0x104D2, 0x104FA],
10676 [0x104D3, 0x104FB],
10677 [0x104D8, 0x104B0],
10678 [0x104D9, 0x104B1],
10679 [0x104DA, 0x104B2],
10680 [0x104DB, 0x104B3],
10681 [0x104DC, 0x104B4],
10682 [0x104DD, 0x104B5],
10683 [0x104DE, 0x104B6],
10684 [0x104DF, 0x104B7],
10685 [0x104E0, 0x104B8],
10686 [0x104E1, 0x104B9],
10687 [0x104E2, 0x104BA],
10688 [0x104E3, 0x104BB],
10689 [0x104E4, 0x104BC],
10690 [0x104E5, 0x104BD],
10691 [0x104E6, 0x104BE],
10692 [0x104E7, 0x104BF],
10693 [0x104E8, 0x104C0],
10694 [0x104E9, 0x104C1],
10695 [0x104EA, 0x104C2],
10696 [0x104EB, 0x104C3],
10697 [0x104EC, 0x104C4],
10698 [0x104ED, 0x104C5],
10699 [0x104EE, 0x104C6],
10700 [0x104EF, 0x104C7],
10701 [0x104F0, 0x104C8],
10702 [0x104F1, 0x104C9],
10703 [0x104F2, 0x104CA],
10704 [0x104F3, 0x104CB],
10705 [0x104F4, 0x104CC],
10706 [0x104F5, 0x104CD],
10707 [0x104F6, 0x104CE],
10708 [0x104F7, 0x104CF],
10709 [0x104F8, 0x104D0],
10710 [0x104F9, 0x104D1],
10711 [0x104FA, 0x104D2],
10712 [0x104FB, 0x104D3],
10713 [0x10C80, 0x10CC0],
10714 [0x10C81, 0x10CC1],
10715 [0x10C82, 0x10CC2],
10716 [0x10C83, 0x10CC3],
10717 [0x10C84, 0x10CC4],
10718 [0x10C85, 0x10CC5],
10719 [0x10C86, 0x10CC6],
10720 [0x10C87, 0x10CC7],
10721 [0x10C88, 0x10CC8],
10722 [0x10C89, 0x10CC9],
10723 [0x10C8A, 0x10CCA],
10724 [0x10C8B, 0x10CCB],
10725 [0x10C8C, 0x10CCC],
10726 [0x10C8D, 0x10CCD],
10727 [0x10C8E, 0x10CCE],
10728 [0x10C8F, 0x10CCF],
10729 [0x10C90, 0x10CD0],
10730 [0x10C91, 0x10CD1],
10731 [0x10C92, 0x10CD2],
10732 [0x10C93, 0x10CD3],
10733 [0x10C94, 0x10CD4],
10734 [0x10C95, 0x10CD5],
10735 [0x10C96, 0x10CD6],
10736 [0x10C97, 0x10CD7],
10737 [0x10C98, 0x10CD8],
10738 [0x10C99, 0x10CD9],
10739 [0x10C9A, 0x10CDA],
10740 [0x10C9B, 0x10CDB],
10741 [0x10C9C, 0x10CDC],
10742 [0x10C9D, 0x10CDD],
10743 [0x10C9E, 0x10CDE],
10744 [0x10C9F, 0x10CDF],
10745 [0x10CA0, 0x10CE0],
10746 [0x10CA1, 0x10CE1],
10747 [0x10CA2, 0x10CE2],
10748 [0x10CA3, 0x10CE3],
10749 [0x10CA4, 0x10CE4],
10750 [0x10CA5, 0x10CE5],
10751 [0x10CA6, 0x10CE6],
10752 [0x10CA7, 0x10CE7],
10753 [0x10CA8, 0x10CE8],
10754 [0x10CA9, 0x10CE9],
10755 [0x10CAA, 0x10CEA],
10756 [0x10CAB, 0x10CEB],
10757 [0x10CAC, 0x10CEC],
10758 [0x10CAD, 0x10CED],
10759 [0x10CAE, 0x10CEE],
10760 [0x10CAF, 0x10CEF],
10761 [0x10CB0, 0x10CF0],
10762 [0x10CB1, 0x10CF1],
10763 [0x10CB2, 0x10CF2],
10764 [0x10CC0, 0x10C80],
10765 [0x10CC1, 0x10C81],
10766 [0x10CC2, 0x10C82],
10767 [0x10CC3, 0x10C83],
10768 [0x10CC4, 0x10C84],
10769 [0x10CC5, 0x10C85],
10770 [0x10CC6, 0x10C86],
10771 [0x10CC7, 0x10C87],
10772 [0x10CC8, 0x10C88],
10773 [0x10CC9, 0x10C89],
10774 [0x10CCA, 0x10C8A],
10775 [0x10CCB, 0x10C8B],
10776 [0x10CCC, 0x10C8C],
10777 [0x10CCD, 0x10C8D],
10778 [0x10CCE, 0x10C8E],
10779 [0x10CCF, 0x10C8F],
10780 [0x10CD0, 0x10C90],
10781 [0x10CD1, 0x10C91],
10782 [0x10CD2, 0x10C92],
10783 [0x10CD3, 0x10C93],
10784 [0x10CD4, 0x10C94],
10785 [0x10CD5, 0x10C95],
10786 [0x10CD6, 0x10C96],
10787 [0x10CD7, 0x10C97],
10788 [0x10CD8, 0x10C98],
10789 [0x10CD9, 0x10C99],
10790 [0x10CDA, 0x10C9A],
10791 [0x10CDB, 0x10C9B],
10792 [0x10CDC, 0x10C9C],
10793 [0x10CDD, 0x10C9D],
10794 [0x10CDE, 0x10C9E],
10795 [0x10CDF, 0x10C9F],
10796 [0x10CE0, 0x10CA0],
10797 [0x10CE1, 0x10CA1],
10798 [0x10CE2, 0x10CA2],
10799 [0x10CE3, 0x10CA3],
10800 [0x10CE4, 0x10CA4],
10801 [0x10CE5, 0x10CA5],
10802 [0x10CE6, 0x10CA6],
10803 [0x10CE7, 0x10CA7],
10804 [0x10CE8, 0x10CA8],
10805 [0x10CE9, 0x10CA9],
10806 [0x10CEA, 0x10CAA],
10807 [0x10CEB, 0x10CAB],
10808 [0x10CEC, 0x10CAC],
10809 [0x10CED, 0x10CAD],
10810 [0x10CEE, 0x10CAE],
10811 [0x10CEF, 0x10CAF],
10812 [0x10CF0, 0x10CB0],
10813 [0x10CF1, 0x10CB1],
10814 [0x10CF2, 0x10CB2],
10815 [0x118A0, 0x118C0],
10816 [0x118A1, 0x118C1],
10817 [0x118A2, 0x118C2],
10818 [0x118A3, 0x118C3],
10819 [0x118A4, 0x118C4],
10820 [0x118A5, 0x118C5],
10821 [0x118A6, 0x118C6],
10822 [0x118A7, 0x118C7],
10823 [0x118A8, 0x118C8],
10824 [0x118A9, 0x118C9],
10825 [0x118AA, 0x118CA],
10826 [0x118AB, 0x118CB],
10827 [0x118AC, 0x118CC],
10828 [0x118AD, 0x118CD],
10829 [0x118AE, 0x118CE],
10830 [0x118AF, 0x118CF],
10831 [0x118B0, 0x118D0],
10832 [0x118B1, 0x118D1],
10833 [0x118B2, 0x118D2],
10834 [0x118B3, 0x118D3],
10835 [0x118B4, 0x118D4],
10836 [0x118B5, 0x118D5],
10837 [0x118B6, 0x118D6],
10838 [0x118B7, 0x118D7],
10839 [0x118B8, 0x118D8],
10840 [0x118B9, 0x118D9],
10841 [0x118BA, 0x118DA],
10842 [0x118BB, 0x118DB],
10843 [0x118BC, 0x118DC],
10844 [0x118BD, 0x118DD],
10845 [0x118BE, 0x118DE],
10846 [0x118BF, 0x118DF],
10847 [0x118C0, 0x118A0],
10848 [0x118C1, 0x118A1],
10849 [0x118C2, 0x118A2],
10850 [0x118C3, 0x118A3],
10851 [0x118C4, 0x118A4],
10852 [0x118C5, 0x118A5],
10853 [0x118C6, 0x118A6],
10854 [0x118C7, 0x118A7],
10855 [0x118C8, 0x118A8],
10856 [0x118C9, 0x118A9],
10857 [0x118CA, 0x118AA],
10858 [0x118CB, 0x118AB],
10859 [0x118CC, 0x118AC],
10860 [0x118CD, 0x118AD],
10861 [0x118CE, 0x118AE],
10862 [0x118CF, 0x118AF],
10863 [0x118D0, 0x118B0],
10864 [0x118D1, 0x118B1],
10865 [0x118D2, 0x118B2],
10866 [0x118D3, 0x118B3],
10867 [0x118D4, 0x118B4],
10868 [0x118D5, 0x118B5],
10869 [0x118D6, 0x118B6],
10870 [0x118D7, 0x118B7],
10871 [0x118D8, 0x118B8],
10872 [0x118D9, 0x118B9],
10873 [0x118DA, 0x118BA],
10874 [0x118DB, 0x118BB],
10875 [0x118DC, 0x118BC],
10876 [0x118DD, 0x118BD],
10877 [0x118DE, 0x118BE],
10878 [0x118DF, 0x118BF],
10879 [0x1E900, 0x1E922],
10880 [0x1E901, 0x1E923],
10881 [0x1E902, 0x1E924],
10882 [0x1E903, 0x1E925],
10883 [0x1E904, 0x1E926],
10884 [0x1E905, 0x1E927],
10885 [0x1E906, 0x1E928],
10886 [0x1E907, 0x1E929],
10887 [0x1E908, 0x1E92A],
10888 [0x1E909, 0x1E92B],
10889 [0x1E90A, 0x1E92C],
10890 [0x1E90B, 0x1E92D],
10891 [0x1E90C, 0x1E92E],
10892 [0x1E90D, 0x1E92F],
10893 [0x1E90E, 0x1E930],
10894 [0x1E90F, 0x1E931],
10895 [0x1E910, 0x1E932],
10896 [0x1E911, 0x1E933],
10897 [0x1E912, 0x1E934],
10898 [0x1E913, 0x1E935],
10899 [0x1E914, 0x1E936],
10900 [0x1E915, 0x1E937],
10901 [0x1E916, 0x1E938],
10902 [0x1E917, 0x1E939],
10903 [0x1E918, 0x1E93A],
10904 [0x1E919, 0x1E93B],
10905 [0x1E91A, 0x1E93C],
10906 [0x1E91B, 0x1E93D],
10907 [0x1E91C, 0x1E93E],
10908 [0x1E91D, 0x1E93F],
10909 [0x1E91E, 0x1E940],
10910 [0x1E91F, 0x1E941],
10911 [0x1E920, 0x1E942],
10912 [0x1E921, 0x1E943],
10913 [0x1E922, 0x1E900],
10914 [0x1E923, 0x1E901],
10915 [0x1E924, 0x1E902],
10916 [0x1E925, 0x1E903],
10917 [0x1E926, 0x1E904],
10918 [0x1E927, 0x1E905],
10919 [0x1E928, 0x1E906],
10920 [0x1E929, 0x1E907],
10921 [0x1E92A, 0x1E908],
10922 [0x1E92B, 0x1E909],
10923 [0x1E92C, 0x1E90A],
10924 [0x1E92D, 0x1E90B],
10925 [0x1E92E, 0x1E90C],
10926 [0x1E92F, 0x1E90D],
10927 [0x1E930, 0x1E90E],
10928 [0x1E931, 0x1E90F],
10929 [0x1E932, 0x1E910],
10930 [0x1E933, 0x1E911],
10931 [0x1E934, 0x1E912],
10932 [0x1E935, 0x1E913],
10933 [0x1E936, 0x1E914],
10934 [0x1E937, 0x1E915],
10935 [0x1E938, 0x1E916],
10936 [0x1E939, 0x1E917],
10937 [0x1E93A, 0x1E918],
10938 [0x1E93B, 0x1E919],
10939 [0x1E93C, 0x1E91A],
10940 [0x1E93D, 0x1E91B],
10941 [0x1E93E, 0x1E91C],
10942 [0x1E93F, 0x1E91D],
10943 [0x1E940, 0x1E91E],
10944 [0x1E941, 0x1E91F],
10945 [0x1E942, 0x1E920],
10946 [0x1E943, 0x1E921]
10947]);
10948
10949// Generated using `npm run build`. Do not edit.
10950'use strict';
10951
10952
10953
10954var REGULAR = new Map([
10955 ['d', regenerate()
10956 .addRange(0x30, 0x39)],
10957 ['D', regenerate()
10958 .addRange(0x0, 0x2F)
10959 .addRange(0x3A, 0xFFFF)],
10960 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
10961 .addRange(0x9, 0xD)
10962 .addRange(0x2000, 0x200A)
10963 .addRange(0x2028, 0x2029)],
10964 ['S', regenerate()
10965 .addRange(0x0, 0x8)
10966 .addRange(0xE, 0x1F)
10967 .addRange(0x21, 0x9F)
10968 .addRange(0xA1, 0x167F)
10969 .addRange(0x1681, 0x1FFF)
10970 .addRange(0x200B, 0x2027)
10971 .addRange(0x202A, 0x202E)
10972 .addRange(0x2030, 0x205E)
10973 .addRange(0x2060, 0x2FFF)
10974 .addRange(0x3001, 0xFEFE)
10975 .addRange(0xFF00, 0xFFFF)],
10976 ['w', regenerate(0x5F)
10977 .addRange(0x30, 0x39)
10978 .addRange(0x41, 0x5A)
10979 .addRange(0x61, 0x7A)],
10980 ['W', regenerate(0x60)
10981 .addRange(0x0, 0x2F)
10982 .addRange(0x3A, 0x40)
10983 .addRange(0x5B, 0x5E)
10984 .addRange(0x7B, 0xFFFF)]
10985]);
10986
10987var UNICODE = new Map([
10988 ['d', regenerate()
10989 .addRange(0x30, 0x39)],
10990 ['D', regenerate()
10991 .addRange(0x0, 0x2F)
10992 .addRange(0x3A, 0x10FFFF)],
10993 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
10994 .addRange(0x9, 0xD)
10995 .addRange(0x2000, 0x200A)
10996 .addRange(0x2028, 0x2029)],
10997 ['S', regenerate()
10998 .addRange(0x0, 0x8)
10999 .addRange(0xE, 0x1F)
11000 .addRange(0x21, 0x9F)
11001 .addRange(0xA1, 0x167F)
11002 .addRange(0x1681, 0x1FFF)
11003 .addRange(0x200B, 0x2027)
11004 .addRange(0x202A, 0x202E)
11005 .addRange(0x2030, 0x205E)
11006 .addRange(0x2060, 0x2FFF)
11007 .addRange(0x3001, 0xFEFE)
11008 .addRange(0xFF00, 0x10FFFF)],
11009 ['w', regenerate(0x5F)
11010 .addRange(0x30, 0x39)
11011 .addRange(0x41, 0x5A)
11012 .addRange(0x61, 0x7A)],
11013 ['W', regenerate(0x60)
11014 .addRange(0x0, 0x2F)
11015 .addRange(0x3A, 0x40)
11016 .addRange(0x5B, 0x5E)
11017 .addRange(0x7B, 0x10FFFF)]
11018]);
11019
11020var UNICODE_IGNORE_CASE = new Map([
11021 ['d', regenerate()
11022 .addRange(0x30, 0x39)],
11023 ['D', regenerate()
11024 .addRange(0x0, 0x2F)
11025 .addRange(0x3A, 0x10FFFF)],
11026 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
11027 .addRange(0x9, 0xD)
11028 .addRange(0x2000, 0x200A)
11029 .addRange(0x2028, 0x2029)],
11030 ['S', regenerate()
11031 .addRange(0x0, 0x8)
11032 .addRange(0xE, 0x1F)
11033 .addRange(0x21, 0x9F)
11034 .addRange(0xA1, 0x167F)
11035 .addRange(0x1681, 0x1FFF)
11036 .addRange(0x200B, 0x2027)
11037 .addRange(0x202A, 0x202E)
11038 .addRange(0x2030, 0x205E)
11039 .addRange(0x2060, 0x2FFF)
11040 .addRange(0x3001, 0xFEFE)
11041 .addRange(0xFF00, 0x10FFFF)],
11042 ['w', regenerate(0x5F, 0x17F, 0x212A)
11043 .addRange(0x30, 0x39)
11044 .addRange(0x41, 0x5A)
11045 .addRange(0x61, 0x7A)],
11046 ['W', regenerate(0x60)
11047 .addRange(0x0, 0x2F)
11048 .addRange(0x3A, 0x40)
11049 .addRange(0x5B, 0x5E)
11050 .addRange(0x7B, 0x17E)
11051 .addRange(0x180, 0x2129)
11052 .addRange(0x212B, 0x10FFFF)]
11053]);
11054
11055var characterClassEscapeSets = {
11056 REGULAR: REGULAR,
11057 UNICODE: UNICODE,
11058 UNICODE_IGNORE_CASE: UNICODE_IGNORE_CASE
11059};
11060
11061var rewritePattern_1 = createCommonjsModule(function (module) {
11062'use strict';
11063
11064var generate = regjsgen.generate;
11065var parse = parser.parse;
11066
11067
11068
11069
11070
11071
11072// Prepare a Regenerate set containing all code points, used for negative
11073// character classes (if any).
11074var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
11075// Without the `u` flag, the range stops at 0xFFFF.
11076// https://mths.be/es6#sec-pattern-semantics
11077var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
11078
11079// Prepare a Regenerate set containing all code points that are supposed to be
11080// matched by `/./u`. https://mths.be/es6#sec-atom
11081var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
11082 .remove(
11083 // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
11084 0x000A, // Line Feed <LF>
11085 0x000D, // Carriage Return <CR>
11086 0x2028, // Line Separator <LS>
11087 0x2029 // Paragraph Separator <PS>
11088 );
11089// Prepare a Regenerate set containing all code points that are supposed to be
11090// matched by `/./` (only BMP code points).
11091var DOT_SET = DOT_SET_UNICODE.clone()
11092 .intersection(BMP_SET);
11093
11094var getCharacterClassEscapeSet = function (character, unicode, ignoreCase) {
11095 if (unicode) {
11096 if (ignoreCase) {
11097 return characterClassEscapeSets.UNICODE_IGNORE_CASE.get(character);
11098 }
11099 return characterClassEscapeSets.UNICODE.get(character);
11100 }
11101 return characterClassEscapeSets.REGULAR.get(character);
11102};
11103
11104var getDotSet = function (unicode, dotAll) {
11105 if (dotAll) {
11106 return unicode ? UNICODE_SET : BMP_SET;
11107 }
11108 return unicode ? DOT_SET_UNICODE : DOT_SET;
11109};
11110
11111var getUnicodePropertyValueSet = function (property, value) {
11112 var path = value ?
11113 (property + "/" + value) :
11114 ("Binary_Property/" + property);
11115 try {
11116 return commonjsRequire(("regenerate-unicode-properties/" + path + ".js"));
11117 } catch (exception) {
11118 throw new Error(
11119 "Failed to recognize value `" + value + "` for property " +
11120 "`" + property + "`."
11121 );
11122 }
11123};
11124
11125var handleLoneUnicodePropertyNameOrValue = function (value) {
11126 // It could be a `General_Category` value or a binary property.
11127 // Note: `unicodeMatchPropertyValue` throws on invalid values.
11128 try {
11129 var property$1 = 'General_Category';
11130 var category = unicodeMatchPropertyValueEcmascript(property$1, value);
11131 return getUnicodePropertyValueSet(property$1, category);
11132 } catch (exception) {}
11133 // It’s not a `General_Category` value, so check if it’s a binary
11134 // property. Note: `unicodeMatchProperty` throws on invalid properties.
11135 var property = unicodeMatchPropertyEcmascript(value);
11136 return getUnicodePropertyValueSet(property);
11137};
11138
11139var getUnicodePropertyEscapeSet = function (value, isNegative) {
11140 var parts = value.split('=');
11141 var firstPart = parts[0];
11142 var set;
11143 if (parts.length == 1) {
11144 set = handleLoneUnicodePropertyNameOrValue(firstPart);
11145 } else {
11146 // The pattern consists of two parts, i.e. `Property=Value`.
11147 var property = unicodeMatchPropertyEcmascript(firstPart);
11148 var value$1 = unicodeMatchPropertyValueEcmascript(property, parts[1]);
11149 set = getUnicodePropertyValueSet(property, value$1);
11150 }
11151 if (isNegative) {
11152 return UNICODE_SET.clone().remove(set);
11153 }
11154 return set.clone();
11155};
11156
11157// Given a range of code points, add any case-folded code points in that range
11158// to a set.
11159regenerate.prototype.iuAddRange = function(min, max) {
11160 var $this = this;
11161 do {
11162 var folded = caseFold(min);
11163 if (folded) {
11164 $this.add(folded);
11165 }
11166 } while (++min <= max);
11167 return $this;
11168};
11169
11170var update = function (item, pattern) {
11171 var tree = parse(pattern, config.useUnicodeFlag ? 'u' : '');
11172 switch (tree.type) {
11173 case 'characterClass':
11174 case 'group':
11175 case 'value':
11176 // No wrapping needed.
11177 break;
11178 default:
11179 // Wrap the pattern in a non-capturing group.
11180 tree = wrap(tree, pattern);
11181 }
11182 Object.assign(item, tree);
11183};
11184
11185var wrap = function (tree, pattern) {
11186 // Wrap the pattern in a non-capturing group.
11187 return {
11188 'type': 'group',
11189 'behavior': 'ignore',
11190 'body': [tree],
11191 'raw': ("(?:" + pattern + ")")
11192 };
11193};
11194
11195var caseFold = function (codePoint) {
11196 return iuMappings.get(codePoint) || false;
11197};
11198
11199var processCharacterClass = function (characterClassItem, regenerateOptions) {
11200 var set = regenerate();
11201 for (var i = 0, list = characterClassItem.body; i < list.length; i += 1) {
11202 var item = list[i];
11203
11204 switch (item.type) {
11205 case 'value':
11206 set.add(item.codePoint);
11207 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11208 var folded = caseFold(item.codePoint);
11209 if (folded) {
11210 set.add(folded);
11211 }
11212 }
11213 break;
11214 case 'characterClassRange':
11215 var min = item.min.codePoint;
11216 var max = item.max.codePoint;
11217 set.addRange(min, max);
11218 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11219 set.iuAddRange(min, max);
11220 }
11221 break;
11222 case 'characterClassEscape':
11223 set.add(getCharacterClassEscapeSet(
11224 item.value,
11225 config.unicode,
11226 config.ignoreCase
11227 ));
11228 break;
11229 case 'unicodePropertyEscape':
11230 set.add(getUnicodePropertyEscapeSet(item.value, item.negative));
11231 break;
11232 // The `default` clause is only here as a safeguard; it should never be
11233 // reached. Code coverage tools should ignore it.
11234 /* istanbul ignore next */
11235 default:
11236 throw new Error(("Unknown term type: " + (item.type)));
11237 }
11238 }
11239 if (characterClassItem.negative) {
11240 set = (config.unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
11241 }
11242 update(characterClassItem, set.toString(regenerateOptions));
11243 return characterClassItem;
11244};
11245
11246var processTerm = function (item, regenerateOptions) {
11247 switch (item.type) {
11248 case 'dot':
11249 update(
11250 item,
11251 getDotSet(config.unicode, config.dotAll).toString(regenerateOptions)
11252 );
11253 break;
11254 case 'characterClass':
11255 item = processCharacterClass(item, regenerateOptions);
11256 break;
11257 case 'unicodePropertyEscape':
11258 update(
11259 item,
11260 getUnicodePropertyEscapeSet(item.value, item.negative)
11261 .toString(regenerateOptions)
11262 );
11263 break;
11264 case 'characterClassEscape':
11265 update(
11266 item,
11267 getCharacterClassEscapeSet(
11268 item.value,
11269 config.unicode,
11270 config.ignoreCase
11271 ).toString(regenerateOptions)
11272 );
11273 break;
11274 case 'alternative':
11275 case 'disjunction':
11276 case 'group':
11277 case 'quantifier':
11278 item.body = item.body.map(function ( term ) {
11279 return processTerm(term, regenerateOptions);
11280 });
11281 break;
11282 case 'value':
11283 var codePoint = item.codePoint;
11284 var set = regenerate(codePoint);
11285 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11286 var folded = caseFold(codePoint);
11287 if (folded) {
11288 set.add(folded);
11289 }
11290 }
11291 update(item, set.toString(regenerateOptions));
11292 break;
11293 case 'anchor':
11294 case 'empty':
11295 case 'group':
11296 case 'reference':
11297 // Nothing to do here.
11298 break;
11299 // The `default` clause is only here as a safeguard; it should never be
11300 // reached. Code coverage tools should ignore it.
11301 /* istanbul ignore next */
11302 default:
11303 throw new Error(("Unknown term type: " + (item.type)));
11304 }
11305 return item;
11306};
11307
11308var config = {
11309 'ignoreCase': false,
11310 'unicode': false,
11311 'dotAll': false,
11312 'useUnicodeFlag': false
11313};
11314var rewritePattern = function (pattern, flags, options) {
11315 var regjsparserFeatures = {
11316 'unicodePropertyEscape': options && options.unicodePropertyEscape
11317 };
11318 config.ignoreCase = flags && flags.includes('i');
11319 config.unicode = flags && flags.includes('u');
11320 var supportDotAllFlag = options && options.dotAllFlag;
11321 config.dotAll = supportDotAllFlag && flags && flags.includes('s');
11322 config.useUnicodeFlag = options && options.useUnicodeFlag;
11323 var regenerateOptions = {
11324 'hasUnicodeFlag': config.useUnicodeFlag,
11325 'bmpOnly': !config.unicode
11326 };
11327 var tree = parse(pattern, flags, regjsparserFeatures);
11328 // Note: `processTerm` mutates `tree`.
11329 processTerm(tree, regenerateOptions);
11330 return generate(tree);
11331};
11332
11333module.exports = rewritePattern;
11334});
11335
11336var Literal = (function (Node) {
11337 function Literal () {
11338 Node.apply(this, arguments);
11339 }
11340
11341 if ( Node ) Literal.__proto__ = Node;
11342 Literal.prototype = Object.create( Node && Node.prototype );
11343 Literal.prototype.constructor = Literal;
11344
11345 Literal.prototype.initialise = function initialise () {
11346 if ( typeof this.value === 'string' ) {
11347 this.program.indentExclusionElements.push( this );
11348 }
11349 };
11350
11351 Literal.prototype.transpile = function transpile ( code, transforms ) {
11352 if ( transforms.numericLiteral ) {
11353 var leading = this.raw.slice( 0, 2 );
11354 if ( leading === '0b' || leading === '0o' ) {
11355 code.overwrite( this.start, this.end, String( this.value ), {
11356 storeName: true,
11357 contentOnly: true
11358 });
11359 }
11360 }
11361
11362 if ( this.regex ) {
11363 var ref = this.regex;
11364 var pattern = ref.pattern;
11365 var flags = ref.flags;
11366
11367 if ( transforms.stickyRegExp && /y/.test( flags ) ) throw new CompileError$1( 'Regular expression sticky flag is not supported', this );
11368 if ( transforms.unicodeRegExp && /u/.test( flags ) ) {
11369 code.overwrite( this.start, this.end, ("/" + (rewritePattern_1( pattern, flags )) + "/" + (flags.replace( 'u', '' ))), {
11370 contentOnly: true
11371 });
11372 }
11373 }
11374 };
11375
11376 return Literal;
11377}(Node$1));
11378
11379var MemberExpression = (function (Node) {
11380 function MemberExpression () {
11381 Node.apply(this, arguments);
11382 }
11383
11384 if ( Node ) MemberExpression.__proto__ = Node;
11385 MemberExpression.prototype = Object.create( Node && Node.prototype );
11386 MemberExpression.prototype.constructor = MemberExpression;
11387
11388 MemberExpression.prototype.transpile = function transpile ( code, transforms ) {
11389 if ( transforms.reservedProperties && reserved[ this.property.name ] ) {
11390 code.overwrite( this.object.end, this.property.start, "['" );
11391 code.appendLeft( this.property.end, "']" );
11392 }
11393
11394 Node.prototype.transpile.call( this, code, transforms );
11395 };
11396
11397 return MemberExpression;
11398}(Node$1));
11399
11400var NewExpression = (function (Node) {
11401 function NewExpression () {
11402 Node.apply(this, arguments);
11403 }
11404
11405 if ( Node ) NewExpression.__proto__ = Node;
11406 NewExpression.prototype = Object.create( Node && Node.prototype );
11407 NewExpression.prototype.constructor = NewExpression;
11408
11409 NewExpression.prototype.initialise = function initialise ( transforms ) {
11410 var this$1 = this;
11411
11412 if ( transforms.spreadRest && this.arguments.length ) {
11413 var lexicalBoundary = this.findLexicalBoundary();
11414
11415 var i = this.arguments.length;
11416 while ( i-- ) {
11417 var arg = this$1.arguments[i];
11418 if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
11419 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
11420 break;
11421 }
11422 }
11423 }
11424
11425 Node.prototype.initialise.call( this, transforms );
11426 };
11427
11428 NewExpression.prototype.transpile = function transpile ( code, transforms ) {
11429 if ( transforms.spreadRest && this.arguments.length ) {
11430 var firstArgument = this.arguments[0];
11431 var isNew = true;
11432 var hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias, isNew );
11433
11434 if ( hasSpreadElements ) {
11435 code.prependRight( this.start + 'new'.length, ' (Function.prototype.bind.apply(' );
11436 code.overwrite( this.callee.end, firstArgument.start, ', [ null ].concat( ' );
11437 code.appendLeft( this.end, ' ))' );
11438 }
11439 }
11440
11441 Node.prototype.transpile.call( this, code, transforms );
11442 };
11443
11444 return NewExpression;
11445}(Node$1));
11446
11447var ObjectExpression = (function (Node) {
11448 function ObjectExpression () {
11449 Node.apply(this, arguments);
11450 }
11451
11452 if ( Node ) ObjectExpression.__proto__ = Node;
11453 ObjectExpression.prototype = Object.create( Node && Node.prototype );
11454 ObjectExpression.prototype.constructor = ObjectExpression;
11455
11456 ObjectExpression.prototype.transpile = function transpile ( code, transforms ) {
11457 var this$1 = this;
11458
11459 Node.prototype.transpile.call( this, code, transforms );
11460
11461 var firstPropertyStart = this.start + 1;
11462 var regularPropertyCount = 0;
11463 var spreadPropertyCount = 0;
11464 var computedPropertyCount = 0;
11465 var firstSpreadProperty = null;
11466 var firstComputedProperty = null;
11467
11468 for ( var i = 0; i < this$1.properties.length; ++i ) {
11469 var prop = this$1.properties[ i ];
11470 if ( prop.type === 'SpreadElement' ) {
11471 spreadPropertyCount += 1;
11472 if ( firstSpreadProperty === null ) firstSpreadProperty = i;
11473 } else if ( prop.computed ) {
11474 computedPropertyCount += 1;
11475 if ( firstComputedProperty === null ) firstComputedProperty = i;
11476 } else if ( prop.type === 'Property' ) {
11477 regularPropertyCount += 1;
11478 }
11479 }
11480
11481 if ( spreadPropertyCount ) {
11482 if ( !this.program.options.objectAssign ) {
11483 throw new CompileError$1( 'Object spread operator requires specified objectAssign option with \'Object.assign\' or polyfill helper.', this );
11484 }
11485 // enclose run of non-spread properties in curlies
11486 var i$1 = this.properties.length;
11487 if ( regularPropertyCount && !computedPropertyCount ) {
11488 while ( i$1-- ) {
11489 var prop$1 = this$1.properties[i$1];
11490
11491 if ( prop$1.type === 'Property' && !prop$1.computed ) {
11492 var lastProp = this$1.properties[ i$1 - 1 ];
11493 var nextProp = this$1.properties[ i$1 + 1 ];
11494
11495 if ( !lastProp || lastProp.type !== 'Property' || lastProp.computed ) {
11496 code.prependRight( prop$1.start, '{' );
11497 }
11498
11499 if ( !nextProp || nextProp.type !== 'Property' || nextProp.computed ) {
11500 code.appendLeft( prop$1.end, '}' );
11501 }
11502 }
11503 }
11504 }
11505
11506 // wrap the whole thing in Object.assign
11507 firstPropertyStart = this.properties[0].start;
11508 if ( !computedPropertyCount ) {
11509 code.overwrite( this.start, firstPropertyStart, ((this.program.options.objectAssign) + "({}, ") );
11510 code.overwrite( this.properties[ this.properties.length - 1 ].end, this.end, ')' );
11511 } else if ( this.properties[0].type === "SpreadElement" ) {
11512 code.overwrite( this.start, firstPropertyStart, ((this.program.options.objectAssign) + "({}, ") );
11513 code.remove( this.end - 1, this.end );
11514 code.appendRight( this.end, ')' );
11515 } else {
11516 code.prependLeft( this.start, ((this.program.options.objectAssign) + "(") );
11517 code.appendRight( this.end, ')' );
11518 }
11519 }
11520
11521 if ( computedPropertyCount && transforms.computedProperty ) {
11522 var i0 = this.getIndentation();
11523
11524 var isSimpleAssignment;
11525 var name;
11526
11527 if ( this.parent.type === 'VariableDeclarator' && this.parent.parent.declarations.length === 1 && this.parent.id.type === 'Identifier' ) {
11528 isSimpleAssignment = true;
11529 name = this.parent.id.alias || this.parent.id.name; // TODO is this right?
11530 } else if ( this.parent.type === 'AssignmentExpression' && this.parent.parent.type === 'ExpressionStatement' && this.parent.left.type === 'Identifier' ) {
11531 isSimpleAssignment = true;
11532 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
11533 } else if ( this.parent.type === 'AssignmentPattern' && this.parent.left.type === 'Identifier' ) {
11534 isSimpleAssignment = true;
11535 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
11536 }
11537
11538 if ( spreadPropertyCount ) isSimpleAssignment = false;
11539
11540 // handle block scoping
11541 var declaration = this.findScope( false ).findDeclaration( name );
11542 if ( declaration ) name = declaration.name;
11543
11544 var start = firstPropertyStart;
11545 var end = this.end;
11546
11547 if ( isSimpleAssignment ) {
11548 // ???
11549 } else {
11550 if ( firstSpreadProperty === null || firstComputedProperty < firstSpreadProperty ) {
11551 name = this.findScope( true ).createIdentifier( 'obj' );
11552
11553 code.prependRight( this.start, ("( " + name + " = ") );
11554 } else name = null; // We don't actually need this variable
11555 }
11556
11557 var len = this.properties.length;
11558 var lastComputedProp;
11559 var sawNonComputedProperty = false;
11560 var isFirst = true;
11561
11562 for ( var i$2 = 0; i$2 < len; i$2 += 1 ) {
11563 var prop$2 = this$1.properties[i$2];
11564 var moveStart = i$2 > 0 ? this$1.properties[ i$2 - 1 ].end : start;
11565
11566 if ( prop$2.type === "Property" && ( prop$2.computed || ( lastComputedProp && !spreadPropertyCount ) ) ) {
11567 if ( i$2 === 0 ) moveStart = this$1.start + 1; // Trim leading whitespace
11568 lastComputedProp = prop$2;
11569
11570 if ( !name ) {
11571 name = this$1.findScope( true ).createIdentifier( 'obj' );
11572
11573 var propId = name + ( prop$2.computed ? "" : "." );
11574 code.appendRight( prop$2.start, ("( " + name + " = {}, " + propId) );
11575 } else {
11576
11577 var propId$1 = ( isSimpleAssignment ? (";\n" + i0 + name) : (", " + name) ) + ( prop$2.computed ? "" : "." );
11578
11579 if ( moveStart < prop$2.start ) {
11580 code.overwrite( moveStart, prop$2.start, propId$1 );
11581 } else {
11582 code.prependRight( prop$2.start, propId$1 );
11583 }
11584 }
11585
11586 var c = prop$2.key.end;
11587 if ( prop$2.computed ) {
11588 while ( code.original[c] !== ']' ) c += 1;
11589 c += 1;
11590 }
11591 if ( prop$2.shorthand ) {
11592 code.overwrite( prop$2.start, prop$2.key.end, code.slice( prop$2.start, prop$2.key.end ).replace( /:/, ' =' ) );
11593 } else {
11594 if ( prop$2.value.start > c ) code.remove( c, prop$2.value.start );
11595 code.appendLeft( c, ' = ' );
11596 }
11597
11598 if ( prop$2.method && transforms.conciseMethodProperty ) {
11599 code.prependRight( prop$2.value.start, 'function ' );
11600 }
11601 } else if ( prop$2.type === "SpreadElement" ) {
11602 if ( name && i$2 > 0 ) {
11603 if ( !lastComputedProp ) {
11604 lastComputedProp = this$1.properties[ i$2 - 1 ];
11605 }
11606 code.appendLeft( lastComputedProp.end, (", " + name + " )") );
11607
11608 var statement = this$1.findNearest( /(?:Statement|Declaration)$/ );
11609 code.appendLeft( statement.end, ("\n" + i0 + "var " + name + ";") );
11610
11611 lastComputedProp = null;
11612 name = null;
11613 }
11614 } else {
11615 if ( !isFirst && spreadPropertyCount ) {
11616 // We are in an Object.assign context, so we need to wrap regular properties
11617 code.prependRight( prop$2.start, '{' );
11618 code.appendLeft( prop$2.end, '}' );
11619 }
11620 sawNonComputedProperty = true;
11621 }
11622 if (isFirst && ( prop$2.type === "SpreadElement" || prop$2.computed ) ) {
11623 var beginEnd = sawNonComputedProperty ? this$1.properties[this$1.properties.length - 1].end : this$1.end - 1;
11624 // Trim trailing comma because it can easily become a leading comma which is illegal
11625 if ( code.original[beginEnd] == ',' ) ++beginEnd;
11626 var closing = code.slice( beginEnd, end );
11627 code.prependLeft( moveStart, closing );
11628 code.remove( beginEnd, end );
11629 isFirst = false;
11630 }
11631
11632 // Clean up some extranous whitespace
11633 var c$1 = prop$2.end;
11634 if ( i$2 < len - 1 && ! sawNonComputedProperty ) {
11635 while ( code.original[c$1] !== ',' ) c$1 += 1;
11636 } else if ( i$2 == len - 1 ) c$1 = this$1.end;
11637 code.remove( prop$2.end, c$1 );
11638 }
11639
11640 // special case
11641 if ( computedPropertyCount === len ) {
11642 code.remove( this.properties[ len - 1 ].end, this.end - 1 );
11643 }
11644
11645 if ( !isSimpleAssignment && name ) {
11646 code.appendLeft( lastComputedProp.end, (", " + name + " )") );
11647
11648 var statement$1 = this.findNearest( /(?:Statement|Declaration)$/ );
11649 code.appendLeft( statement$1.end, ("\n" + i0 + "var " + name + ";") );
11650 }
11651 }
11652 };
11653
11654 return ObjectExpression;
11655}(Node$1));
11656
11657var Property = (function (Node) {
11658 function Property () {
11659 Node.apply(this, arguments);
11660 }
11661
11662 if ( Node ) Property.__proto__ = Node;
11663 Property.prototype = Object.create( Node && Node.prototype );
11664 Property.prototype.constructor = Property;
11665
11666 Property.prototype.transpile = function transpile ( code, transforms ) {
11667 Node.prototype.transpile.call( this, code, transforms );
11668
11669 if ( transforms.conciseMethodProperty && !this.computed && this.parent.type !== 'ObjectPattern' ) {
11670 if ( this.shorthand ) {
11671 code.prependRight( this.start, ((this.key.name) + ": ") );
11672 } else if ( this.method ) {
11673 var name = '';
11674 if ( this.program.options.namedFunctionExpressions !== false ) {
11675 if ( this.key.type === 'Literal' && typeof this.key.value === 'number' ) {
11676 name = "";
11677 } else if ( this.key.type === 'Identifier' ) {
11678 if ( reserved[ this.key.name ] ||
11679 ! /^[a-z_$][a-z0-9_$]*$/i.test( this.key.name ) ||
11680 this.value.body.scope.references[this.key.name] ) {
11681 name = this.findScope( true ).createIdentifier( this.key.name );
11682 } else {
11683 name = this.key.name;
11684 }
11685 } else {
11686 name = this.findScope( true ).createIdentifier( this.key.value );
11687 }
11688 name = ' ' + name;
11689 }
11690
11691 if ( this.value.generator ) code.remove( this.start, this.key.start );
11692 code.appendLeft( this.key.end, (": function" + (this.value.generator ? '*' : '') + name) );
11693 }
11694 }
11695
11696 if ( transforms.reservedProperties && reserved[ this.key.name ] ) {
11697 code.prependRight( this.key.start, "'" );
11698 code.appendLeft( this.key.end, "'" );
11699 }
11700 };
11701
11702 return Property;
11703}(Node$1));
11704
11705var ReturnStatement = (function (Node) {
11706 function ReturnStatement () {
11707 Node.apply(this, arguments);
11708 }
11709
11710 if ( Node ) ReturnStatement.__proto__ = Node;
11711 ReturnStatement.prototype = Object.create( Node && Node.prototype );
11712 ReturnStatement.prototype.constructor = ReturnStatement;
11713
11714 ReturnStatement.prototype.initialise = function initialise ( transforms ) {
11715 this.loop = this.findNearest( loopStatement );
11716 this.nearestFunction = this.findNearest( /Function/ );
11717
11718 if ( this.loop && ( !this.nearestFunction || this.loop.depth > this.nearestFunction.depth ) ) {
11719 this.loop.canReturn = true;
11720 this.shouldWrap = true;
11721 }
11722
11723 if ( this.argument ) this.argument.initialise( transforms );
11724 };
11725
11726 ReturnStatement.prototype.transpile = function transpile ( code, transforms ) {
11727 var shouldWrap = this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;
11728
11729 if ( this.argument ) {
11730 if ( shouldWrap ) code.prependRight( this.argument.start, "{ v: " );
11731 this.argument.transpile( code, transforms );
11732 if ( shouldWrap ) code.appendLeft( this.argument.end, " }" );
11733 } else if ( shouldWrap ) {
11734 code.appendLeft( this.start + 6, ' {}' );
11735 }
11736 };
11737
11738 return ReturnStatement;
11739}(Node$1));
11740
11741var SpreadElement = (function (Node) {
11742 function SpreadElement () {
11743 Node.apply(this, arguments);
11744 }
11745
11746 if ( Node ) SpreadElement.__proto__ = Node;
11747 SpreadElement.prototype = Object.create( Node && Node.prototype );
11748 SpreadElement.prototype.constructor = SpreadElement;
11749
11750 SpreadElement.prototype.transpile = function transpile ( code, transforms ) {
11751 if (this.parent.type == "ObjectExpression") {
11752 code.remove( this.start, this.argument.start );
11753 code.remove( this.argument.end, this.end );
11754 }
11755
11756 Node.prototype.transpile.call( this, code, transforms );
11757 };
11758
11759 return SpreadElement;
11760}(Node$1));
11761
11762var Super = (function (Node) {
11763 function Super () {
11764 Node.apply(this, arguments);
11765 }
11766
11767 if ( Node ) Super.__proto__ = Node;
11768 Super.prototype = Object.create( Node && Node.prototype );
11769 Super.prototype.constructor = Super;
11770
11771 Super.prototype.initialise = function initialise ( transforms ) {
11772 if ( transforms.classes ) {
11773 this.method = this.findNearest( 'MethodDefinition' );
11774 if ( !this.method ) throw new CompileError$1( this, 'use of super outside class method' );
11775
11776 var parentClass = this.findNearest( 'ClassBody' ).parent;
11777 this.superClassName = parentClass.superClass && (parentClass.superClass.name || 'superclass');
11778
11779 if ( !this.superClassName ) throw new CompileError$1( 'super used in base class', this );
11780
11781 this.isCalled = this.parent.type === 'CallExpression' && this === this.parent.callee;
11782
11783 if ( this.method.kind !== 'constructor' && this.isCalled ) {
11784 throw new CompileError$1( 'super() not allowed outside class constructor', this );
11785 }
11786
11787 this.isMember = this.parent.type === 'MemberExpression';
11788
11789 if ( !this.isCalled && !this.isMember ) {
11790 throw new CompileError$1( 'Unexpected use of `super` (expected `super(...)` or `super.*`)', this );
11791 }
11792 }
11793
11794 if ( transforms.arrow ) {
11795 var lexicalBoundary = this.findLexicalBoundary();
11796 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
11797 var loop = this.findNearest( loopStatement );
11798
11799 if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
11800 this.thisAlias = lexicalBoundary.getThisAlias();
11801 }
11802
11803 if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
11804 this.thisAlias = lexicalBoundary.getThisAlias();
11805 }
11806 }
11807 };
11808
11809 Super.prototype.transpile = function transpile ( code, transforms ) {
11810 if ( transforms.classes ) {
11811 var expression = ( this.isCalled || this.method.static ) ?
11812 this.superClassName :
11813 ((this.superClassName) + ".prototype");
11814
11815 code.overwrite( this.start, this.end, expression, { storeName: true, contentOnly: true });
11816
11817 var callExpression = this.isCalled ? this.parent : this.parent.parent;
11818
11819 if ( callExpression && callExpression.type === 'CallExpression' ) {
11820 if ( !this.noCall ) { // special case – `super( ...args )`
11821 code.appendLeft( callExpression.callee.end, '.call' );
11822 }
11823
11824 var thisAlias = this.thisAlias || 'this';
11825
11826 if ( callExpression.arguments.length ) {
11827 code.appendLeft( callExpression.arguments[0].start, (thisAlias + ", ") );
11828 } else {
11829 code.appendLeft( callExpression.end - 1, ("" + thisAlias) );
11830 }
11831 }
11832 }
11833 };
11834
11835 return Super;
11836}(Node$1));
11837
11838var TaggedTemplateExpression = (function (Node) {
11839 function TaggedTemplateExpression () {
11840 Node.apply(this, arguments);
11841 }
11842
11843 if ( Node ) TaggedTemplateExpression.__proto__ = Node;
11844 TaggedTemplateExpression.prototype = Object.create( Node && Node.prototype );
11845 TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
11846
11847 TaggedTemplateExpression.prototype.initialise = function initialise ( transforms ) {
11848 if ( transforms.templateString && !transforms.dangerousTaggedTemplateString ) {
11849 throw new CompileError$1( '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', this );
11850 }
11851
11852 Node.prototype.initialise.call( this, transforms );
11853 };
11854
11855 TaggedTemplateExpression.prototype.transpile = function transpile ( code, transforms ) {
11856 if ( transforms.templateString && transforms.dangerousTaggedTemplateString ) {
11857 var ordered = this.quasi.expressions.concat( this.quasi.quasis ).sort( function ( a, b ) { return a.start - b.start; } );
11858
11859 // insert strings at start
11860 var templateStrings = this.quasi.quasis.map( function ( quasi ) { return JSON.stringify( quasi.value.cooked ); } );
11861 code.overwrite( this.tag.end, ordered[0].start, ("([" + (templateStrings.join(', ')) + "]") );
11862
11863 var lastIndex = ordered[0].start;
11864 ordered.forEach( function ( node ) {
11865 if ( node.type === 'TemplateElement' ) {
11866 code.remove( lastIndex, node.end );
11867 } else {
11868 code.overwrite( lastIndex, node.start, ', ' );
11869 }
11870
11871 lastIndex = node.end;
11872 });
11873
11874 code.overwrite( lastIndex, this.end, ')' );
11875 }
11876
11877 Node.prototype.transpile.call( this, code, transforms );
11878 };
11879
11880 return TaggedTemplateExpression;
11881}(Node$1));
11882
11883var TemplateElement = (function (Node) {
11884 function TemplateElement () {
11885 Node.apply(this, arguments);
11886 }
11887
11888 if ( Node ) TemplateElement.__proto__ = Node;
11889 TemplateElement.prototype = Object.create( Node && Node.prototype );
11890 TemplateElement.prototype.constructor = TemplateElement;
11891
11892 TemplateElement.prototype.initialise = function initialise () {
11893 this.program.indentExclusionElements.push( this );
11894 };
11895
11896 return TemplateElement;
11897}(Node$1));
11898
11899var TemplateLiteral = (function (Node) {
11900 function TemplateLiteral () {
11901 Node.apply(this, arguments);
11902 }
11903
11904 if ( Node ) TemplateLiteral.__proto__ = Node;
11905 TemplateLiteral.prototype = Object.create( Node && Node.prototype );
11906 TemplateLiteral.prototype.constructor = TemplateLiteral;
11907
11908 TemplateLiteral.prototype.transpile = function transpile ( code, transforms ) {
11909 if ( transforms.templateString && this.parent.type !== 'TaggedTemplateExpression' ) {
11910 var ordered = this.expressions.concat( this.quasis )
11911 .sort( function ( a, b ) { return a.start - b.start || a.end - b.end; } )
11912 .filter( function ( node, i ) {
11913 // include all expressions
11914 if ( node.type !== 'TemplateElement' ) return true;
11915
11916 // include all non-empty strings
11917 if ( node.value.raw ) return true;
11918
11919 // exclude all empty strings not at the head
11920 return !i;
11921 });
11922
11923 // special case – we may be able to skip the first element,
11924 // if it's the empty string, but only if the second and
11925 // third elements aren't both expressions (since they maybe
11926 // be numeric, and `1 + 2 + '3' === '33'`)
11927 if ( ordered.length >= 3 ) {
11928 var first = ordered[0];
11929 var third = ordered[2];
11930 if ( first.type === 'TemplateElement' && first.value.raw === '' && third.type === 'TemplateElement' ) {
11931 ordered.shift();
11932 }
11933 }
11934
11935 var parenthesise = ( this.quasis.length !== 1 || this.expressions.length !== 0 ) &&
11936 this.parent.type !== 'AssignmentExpression' &&
11937 this.parent.type !== 'AssignmentPattern' &&
11938 this.parent.type !== 'VariableDeclarator' &&
11939 ( this.parent.type !== 'BinaryExpression' || this.parent.operator !== '+' );
11940
11941 if ( parenthesise ) code.appendRight( this.start, '(' );
11942
11943 var lastIndex = this.start;
11944
11945 ordered.forEach( function ( node, i ) {
11946 var prefix = i === 0 ?
11947 parenthesise ? '(' : '' :
11948 ' + ';
11949
11950 if ( node.type === 'TemplateElement' ) {
11951 code.overwrite( lastIndex, node.end, prefix + JSON.stringify( node.value.cooked ) );
11952 } else {
11953 var parenthesise$1 = node.type !== 'Identifier'; // TODO other cases where it's safe
11954
11955 if ( parenthesise$1 ) prefix += '(';
11956
11957 code.remove( lastIndex, node.start );
11958
11959 if ( prefix ) code.prependRight( node.start, prefix );
11960 if ( parenthesise$1 ) code.appendLeft( node.end, ')' );
11961 }
11962
11963 lastIndex = node.end;
11964 });
11965
11966 if ( parenthesise ) code.appendLeft( lastIndex, ')' );
11967 code.remove( lastIndex, this.end );
11968 }
11969
11970 Node.prototype.transpile.call( this, code, transforms );
11971 };
11972
11973 return TemplateLiteral;
11974}(Node$1));
11975
11976var ThisExpression = (function (Node) {
11977 function ThisExpression () {
11978 Node.apply(this, arguments);
11979 }
11980
11981 if ( Node ) ThisExpression.__proto__ = Node;
11982 ThisExpression.prototype = Object.create( Node && Node.prototype );
11983 ThisExpression.prototype.constructor = ThisExpression;
11984
11985 ThisExpression.prototype.initialise = function initialise ( transforms ) {
11986 if ( transforms.arrow ) {
11987 var lexicalBoundary = this.findLexicalBoundary();
11988 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
11989 var loop = this.findNearest( loopStatement );
11990
11991 if ( ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth )
11992 || ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth )
11993 || ( loop && loop.right && loop.right.contains( this ) ) ) {
11994 this.alias = lexicalBoundary.getThisAlias();
11995 }
11996 }
11997 };
11998
11999 ThisExpression.prototype.transpile = function transpile ( code ) {
12000 if ( this.alias ) {
12001 code.overwrite( this.start, this.end, this.alias, {
12002 storeName: true,
12003 contentOnly: true
12004 });
12005 }
12006 };
12007
12008 return ThisExpression;
12009}(Node$1));
12010
12011var UpdateExpression = (function (Node) {
12012 function UpdateExpression () {
12013 Node.apply(this, arguments);
12014 }
12015
12016 if ( Node ) UpdateExpression.__proto__ = Node;
12017 UpdateExpression.prototype = Object.create( Node && Node.prototype );
12018 UpdateExpression.prototype.constructor = UpdateExpression;
12019
12020 UpdateExpression.prototype.initialise = function initialise ( transforms ) {
12021 if ( this.argument.type === 'Identifier' ) {
12022 var declaration = this.findScope( false ).findDeclaration( this.argument.name );
12023 if ( declaration && declaration.kind === 'const' ) {
12024 throw new CompileError$1( ((this.argument.name) + " is read-only"), this );
12025 }
12026
12027 // special case – https://gitlab.com/Rich-Harris/buble/issues/150
12028 var statement = declaration && declaration.node.ancestor( 3 );
12029 if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
12030 statement.reassigned[ this.argument.name ] = true;
12031 }
12032 }
12033
12034 Node.prototype.initialise.call( this, transforms );
12035 };
12036
12037 return UpdateExpression;
12038}(Node$1));
12039
12040var VariableDeclaration = (function (Node) {
12041 function VariableDeclaration () {
12042 Node.apply(this, arguments);
12043 }
12044
12045 if ( Node ) VariableDeclaration.__proto__ = Node;
12046 VariableDeclaration.prototype = Object.create( Node && Node.prototype );
12047 VariableDeclaration.prototype.constructor = VariableDeclaration;
12048
12049 VariableDeclaration.prototype.initialise = function initialise ( transforms ) {
12050 this.scope = this.findScope( this.kind === 'var' );
12051 this.declarations.forEach( function ( declarator ) { return declarator.initialise( transforms ); } );
12052 };
12053
12054 VariableDeclaration.prototype.transpile = function transpile ( code, transforms ) {
12055 var this$1 = this;
12056
12057 var i0 = this.getIndentation();
12058 var kind = this.kind;
12059
12060 if ( transforms.letConst && kind !== 'var' ) {
12061 kind = 'var';
12062 code.overwrite( this.start, this.start + this.kind.length, kind, { storeName: true });
12063 }
12064
12065 if ( transforms.destructuring && this.parent.type !== 'ForOfStatement' ) {
12066 var c = this.start;
12067 var lastDeclaratorIsPattern;
12068
12069 this.declarations.forEach( function ( declarator, i ) {
12070 declarator.transpile( code, transforms );
12071
12072 if ( declarator.id.type === 'Identifier' ) {
12073 if ( i > 0 && this$1.declarations[ i - 1 ].id.type !== 'Identifier' ) {
12074 code.overwrite( c, declarator.id.start, "var " );
12075 }
12076 } else {
12077 var inline = loopStatement.test( this$1.parent.type );
12078
12079 if ( i === 0 ) {
12080 code.remove( c, declarator.id.start );
12081 } else {
12082 code.overwrite( c, declarator.id.start, (";\n" + i0) );
12083 }
12084
12085 var simple = declarator.init.type === 'Identifier' && !declarator.init.rewritten;
12086
12087 var name = simple ? declarator.init.name : declarator.findScope( true ).createIdentifier( 'ref' );
12088
12089 var statementGenerators = [];
12090
12091 if ( simple ) {
12092 code.remove( declarator.id.end, declarator.end );
12093 } else {
12094 statementGenerators.push( function ( start, prefix, suffix ) {
12095 code.prependRight( declarator.id.end, ("var " + name) );
12096 code.appendLeft( declarator.init.end, ("" + suffix) );
12097 code.move( declarator.id.end, declarator.end, start );
12098 });
12099 }
12100
12101 destructure( code, declarator.findScope( false ), declarator.id, name, inline, statementGenerators );
12102
12103 var prefix = inline ? 'var ' : '';
12104 var suffix = inline ? ", " : (";\n" + i0);
12105 statementGenerators.forEach( function ( fn, j ) {
12106 if ( i === this$1.declarations.length - 1 && j === statementGenerators.length - 1 ) {
12107 suffix = inline ? '' : ';';
12108 }
12109
12110 fn( declarator.start, j === 0 ? prefix : '', suffix );
12111 });
12112 }
12113
12114 c = declarator.end;
12115 lastDeclaratorIsPattern = declarator.id.type !== 'Identifier';
12116 });
12117
12118 if ( lastDeclaratorIsPattern && this.end > c ) {
12119 code.overwrite( c, this.end, '', { contentOnly: true });
12120 }
12121 }
12122
12123 else {
12124 this.declarations.forEach( function ( declarator ) {
12125 declarator.transpile( code, transforms );
12126 });
12127 }
12128 };
12129
12130 return VariableDeclaration;
12131}(Node$1));
12132
12133var VariableDeclarator = (function (Node) {
12134 function VariableDeclarator () {
12135 Node.apply(this, arguments);
12136 }
12137
12138 if ( Node ) VariableDeclarator.__proto__ = Node;
12139 VariableDeclarator.prototype = Object.create( Node && Node.prototype );
12140 VariableDeclarator.prototype.constructor = VariableDeclarator;
12141
12142 VariableDeclarator.prototype.initialise = function initialise ( transforms ) {
12143 var kind = this.parent.kind;
12144 if ( kind === 'let' && this.parent.parent.type === 'ForStatement' ) {
12145 kind = 'for.let'; // special case...
12146 }
12147
12148 this.parent.scope.addDeclaration( this.id, kind );
12149 Node.prototype.initialise.call( this, transforms );
12150 };
12151
12152 VariableDeclarator.prototype.transpile = function transpile ( code, transforms ) {
12153 if ( !this.init && transforms.letConst && this.parent.kind !== 'var' ) {
12154 var inLoop = this.findNearest( /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/ );
12155 if ( inLoop && ! /Function/.test( inLoop.type ) && ! this.isLeftDeclaratorOfLoop() ) {
12156 code.appendLeft( this.id.end, ' = (void 0)' );
12157 }
12158 }
12159
12160 if ( this.id ) this.id.transpile( code, transforms );
12161 if ( this.init ) this.init.transpile( code, transforms );
12162 };
12163
12164 VariableDeclarator.prototype.isLeftDeclaratorOfLoop = function isLeftDeclaratorOfLoop () {
12165 return this.parent
12166 && this.parent.type === 'VariableDeclaration'
12167 && this.parent.parent
12168 && (this.parent.parent.type === 'ForInStatement'
12169 || this.parent.parent.type === 'ForOfStatement')
12170 && this.parent.parent.left
12171 && this.parent.parent.left.declarations[0] === this;
12172 };
12173
12174 return VariableDeclarator;
12175}(Node$1));
12176
12177var types$1$1 = {
12178 ArrayExpression: ArrayExpression,
12179 ArrowFunctionExpression: ArrowFunctionExpression,
12180 AssignmentExpression: AssignmentExpression,
12181 BinaryExpression: BinaryExpression,
12182 BreakStatement: BreakStatement,
12183 CallExpression: CallExpression,
12184 ClassBody: ClassBody,
12185 ClassDeclaration: ClassDeclaration,
12186 ClassExpression: ClassExpression,
12187 ContinueStatement: ContinueStatement,
12188 DoWhileStatement: LoopStatement,
12189 ExportNamedDeclaration: ExportNamedDeclaration,
12190 ExportDefaultDeclaration: ExportDefaultDeclaration,
12191 ForStatement: ForStatement,
12192 ForInStatement: ForInStatement,
12193 ForOfStatement: ForOfStatement,
12194 FunctionDeclaration: FunctionDeclaration,
12195 FunctionExpression: FunctionExpression,
12196 Identifier: Identifier,
12197 IfStatement: IfStatement,
12198 ImportDeclaration: ImportDeclaration,
12199 ImportDefaultSpecifier: ImportDefaultSpecifier,
12200 ImportSpecifier: ImportSpecifier,
12201 JSXAttribute: JSXAttribute,
12202 JSXClosingElement: JSXClosingElement,
12203 JSXElement: JSXElement,
12204 JSXExpressionContainer: JSXExpressionContainer,
12205 JSXOpeningElement: JSXOpeningElement,
12206 JSXSpreadAttribute: JSXSpreadAttribute,
12207 Literal: Literal,
12208 MemberExpression: MemberExpression,
12209 NewExpression: NewExpression,
12210 ObjectExpression: ObjectExpression,
12211 Property: Property,
12212 ReturnStatement: ReturnStatement,
12213 SpreadElement: SpreadElement,
12214 Super: Super,
12215 TaggedTemplateExpression: TaggedTemplateExpression,
12216 TemplateElement: TemplateElement,
12217 TemplateLiteral: TemplateLiteral,
12218 ThisExpression: ThisExpression,
12219 UpdateExpression: UpdateExpression,
12220 VariableDeclaration: VariableDeclaration,
12221 VariableDeclarator: VariableDeclarator,
12222 WhileStatement: LoopStatement
12223};
12224
12225var statementsWithBlocks = {
12226 IfStatement: 'consequent',
12227 ForStatement: 'body',
12228 ForInStatement: 'body',
12229 ForOfStatement: 'body',
12230 WhileStatement: 'body',
12231 DoWhileStatement: 'body',
12232 ArrowFunctionExpression: 'body'
12233};
12234
12235function wrap ( raw, parent ) {
12236 if ( !raw ) return;
12237
12238 if ( 'length' in raw ) {
12239 var i = raw.length;
12240 while ( i-- ) wrap( raw[i], parent );
12241 return;
12242 }
12243
12244 // with e.g. shorthand properties, key and value are
12245 // the same node. We don't want to wrap an object twice
12246 if ( raw.__wrapped ) return;
12247 raw.__wrapped = true;
12248
12249 if ( !keys[ raw.type ] ) {
12250 keys[ raw.type ] = Object.keys( raw ).filter( function ( key ) { return typeof raw[ key ] === 'object'; } );
12251 }
12252
12253 // special case – body-less if/for/while statements. TODO others?
12254 var bodyType = statementsWithBlocks[ raw.type ];
12255 if ( bodyType && raw[ bodyType ].type !== 'BlockStatement' ) {
12256 var expression = raw[ bodyType ];
12257
12258 // create a synthetic block statement, otherwise all hell
12259 // breaks loose when it comes to block scoping
12260 raw[ bodyType ] = {
12261 start: expression.start,
12262 end: expression.end,
12263 type: 'BlockStatement',
12264 body: [ expression ],
12265 synthetic: true
12266 };
12267 }
12268
12269 new Node$1( raw, parent );
12270
12271 var type = ( raw.type === 'BlockStatement' ? BlockStatement : types$1$1[ raw.type ] ) || Node$1;
12272 raw.__proto__ = type.prototype;
12273}
12274
12275function Scope ( options ) {
12276 options = options || {};
12277
12278 this.parent = options.parent;
12279 this.isBlockScope = !!options.block;
12280
12281 var scope = this;
12282 while ( scope.isBlockScope ) scope = scope.parent;
12283 this.functionScope = scope;
12284
12285 this.identifiers = [];
12286 this.declarations = Object.create( null );
12287 this.references = Object.create( null );
12288 this.blockScopedDeclarations = this.isBlockScope ? null : Object.create( null );
12289 this.aliases = this.isBlockScope ? null : Object.create( null );
12290}
12291
12292Scope.prototype = {
12293 addDeclaration: function addDeclaration ( node, kind ) {
12294 for ( var i = 0, list = extractNames( node ); i < list.length; i += 1 ) {
12295 var identifier = list[i];
12296
12297 var name = identifier.name;
12298
12299 var declaration = { name: name, node: identifier, kind: kind, instances: [] };
12300 this.declarations[ name ] = declaration;
12301
12302 if ( this.isBlockScope ) {
12303 if ( !this.functionScope.blockScopedDeclarations[ name ] ) this.functionScope.blockScopedDeclarations[ name ] = [];
12304 this.functionScope.blockScopedDeclarations[ name ].push( declaration );
12305 }
12306 }
12307 },
12308
12309 addReference: function addReference ( identifier ) {
12310 if ( this.consolidated ) {
12311 this.consolidateReference( identifier );
12312 } else {
12313 this.identifiers.push( identifier );
12314 }
12315 },
12316
12317 consolidate: function consolidate () {
12318 var this$1 = this;
12319
12320 for ( var i = 0; i < this$1.identifiers.length; i += 1 ) { // we might push to the array during consolidation, so don't cache length
12321 var identifier = this$1.identifiers[i];
12322 this$1.consolidateReference( identifier );
12323 }
12324
12325 this.consolidated = true; // TODO understand why this is necessary... seems bad
12326 },
12327
12328 consolidateReference: function consolidateReference ( identifier ) {
12329 var declaration = this.declarations[ identifier.name ];
12330 if ( declaration ) {
12331 declaration.instances.push( identifier );
12332 } else {
12333 this.references[ identifier.name ] = true;
12334 if ( this.parent ) this.parent.addReference( identifier );
12335 }
12336 },
12337
12338 contains: function contains ( name ) {
12339 return this.declarations[ name ] ||
12340 ( this.parent ? this.parent.contains( name ) : false );
12341 },
12342
12343 createIdentifier: function createIdentifier ( base ) {
12344 var this$1 = this;
12345
12346 if ( typeof base === 'number' ) base = base.toString();
12347
12348 base = base
12349 .replace( /\s/g, '' )
12350 .replace( /\[([^\]]+)\]/g, '_$1' )
12351 .replace( /[^a-zA-Z0-9_$]/g, '_' )
12352 .replace( /_{2,}/, '_' );
12353
12354 var name = base;
12355 var counter = 1;
12356
12357 while ( this$1.declarations[ name ] || this$1.references[ name ] || this$1.aliases[ name ] || name in reserved ) {
12358 name = base + "$" + (counter++);
12359 }
12360
12361 this.aliases[ name ] = true;
12362 return name;
12363 },
12364
12365 findDeclaration: function findDeclaration ( name ) {
12366 return this.declarations[ name ] ||
12367 ( this.parent && this.parent.findDeclaration( name ) );
12368 }
12369};
12370
12371function isUseStrict ( node ) {
12372 if ( !node ) return false;
12373 if ( node.type !== 'ExpressionStatement' ) return false;
12374 if ( node.expression.type !== 'Literal' ) return false;
12375 return node.expression.value === 'use strict';
12376}
12377
12378var BlockStatement = (function (Node) {
12379 function BlockStatement () {
12380 Node.apply(this, arguments);
12381 }
12382
12383 if ( Node ) BlockStatement.__proto__ = Node;
12384 BlockStatement.prototype = Object.create( Node && Node.prototype );
12385 BlockStatement.prototype.constructor = BlockStatement;
12386
12387 BlockStatement.prototype.createScope = function createScope () {
12388 var this$1 = this;
12389
12390 this.parentIsFunction = /Function/.test( this.parent.type );
12391 this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root';
12392 this.scope = new Scope({
12393 block: !this.isFunctionBlock,
12394 parent: this.parent.findScope( false )
12395 });
12396
12397 if ( this.parentIsFunction ) {
12398 this.parent.params.forEach( function ( node ) {
12399 this$1.scope.addDeclaration( node, 'param' );
12400 });
12401 }
12402 };
12403
12404 BlockStatement.prototype.initialise = function initialise ( transforms ) {
12405 this.thisAlias = null;
12406 this.argumentsAlias = null;
12407 this.defaultParameters = [];
12408
12409 // normally the scope gets created here, during initialisation,
12410 // but in some cases (e.g. `for` statements), we need to create
12411 // the scope early, as it pertains to both the init block and
12412 // the body of the statement
12413 if ( !this.scope ) this.createScope();
12414
12415 this.body.forEach( function ( node ) { return node.initialise( transforms ); } );
12416
12417 this.scope.consolidate();
12418 };
12419
12420 BlockStatement.prototype.findLexicalBoundary = function findLexicalBoundary () {
12421 if ( this.type === 'Program' ) return this;
12422 if ( /^Function/.test( this.parent.type ) ) return this;
12423
12424 return this.parent.findLexicalBoundary();
12425 };
12426
12427 BlockStatement.prototype.findScope = function findScope ( functionScope ) {
12428 if ( functionScope && !this.isFunctionBlock ) return this.parent.findScope( functionScope );
12429 return this.scope;
12430 };
12431
12432 BlockStatement.prototype.getArgumentsAlias = function getArgumentsAlias () {
12433 if ( !this.argumentsAlias ) {
12434 this.argumentsAlias = this.scope.createIdentifier( 'arguments' );
12435 }
12436
12437 return this.argumentsAlias;
12438 };
12439
12440 BlockStatement.prototype.getArgumentsArrayAlias = function getArgumentsArrayAlias () {
12441 if ( !this.argumentsArrayAlias ) {
12442 this.argumentsArrayAlias = this.scope.createIdentifier( 'argsArray' );
12443 }
12444
12445 return this.argumentsArrayAlias;
12446 };
12447
12448 BlockStatement.prototype.getThisAlias = function getThisAlias () {
12449 if ( !this.thisAlias ) {
12450 this.thisAlias = this.scope.createIdentifier( 'this' );
12451 }
12452
12453 return this.thisAlias;
12454 };
12455
12456 BlockStatement.prototype.getIndentation = function getIndentation () {
12457 var this$1 = this;
12458
12459 if ( this.indentation === undefined ) {
12460 var source = this.program.magicString.original;
12461
12462 var useOuter = this.synthetic || !this.body.length;
12463 var c = useOuter ? this.start : this.body[0].start;
12464
12465 while ( c && source[c] !== '\n' ) c -= 1;
12466
12467 this.indentation = '';
12468
12469 while ( true ) { // eslint-disable-line no-constant-condition
12470 c += 1;
12471 var char = source[c];
12472
12473 if ( char !== ' ' && char !== '\t' ) break;
12474
12475 this$1.indentation += char;
12476 }
12477
12478 var indentString = this.program.magicString.getIndentString();
12479
12480 // account for dedented class constructors
12481 var parent = this.parent;
12482 while ( parent ) {
12483 if ( parent.kind === 'constructor' && !parent.parent.parent.superClass ) {
12484 this$1.indentation = this$1.indentation.replace( indentString, '' );
12485 }
12486
12487 parent = parent.parent;
12488 }
12489
12490 if ( useOuter ) this.indentation += indentString;
12491 }
12492
12493 return this.indentation;
12494 };
12495
12496 BlockStatement.prototype.transpile = function transpile ( code, transforms ) {
12497 var this$1 = this;
12498
12499 var indentation = this.getIndentation();
12500
12501 var introStatementGenerators = [];
12502
12503 if ( this.argumentsAlias ) {
12504 introStatementGenerators.push( function ( start, prefix, suffix ) {
12505 var assignment = prefix + "var " + (this$1.argumentsAlias) + " = arguments" + suffix;
12506 code.appendLeft( start, assignment );
12507 });
12508 }
12509
12510 if ( this.thisAlias ) {
12511 introStatementGenerators.push( function ( start, prefix, suffix ) {
12512 var assignment = prefix + "var " + (this$1.thisAlias) + " = this" + suffix;
12513 code.appendLeft( start, assignment );
12514 });
12515 }
12516
12517 if ( this.argumentsArrayAlias ) {
12518 introStatementGenerators.push( function ( start, prefix, suffix ) {
12519 var i = this$1.scope.createIdentifier( 'i' );
12520 var assignment = prefix + "var " + i + " = arguments.length, " + (this$1.argumentsArrayAlias) + " = Array(" + i + ");\n" + indentation + "while ( " + i + "-- ) " + (this$1.argumentsArrayAlias) + "[" + i + "] = arguments[" + i + "]" + suffix;
12521 code.appendLeft( start, assignment );
12522 });
12523 }
12524
12525 if ( /Function/.test( this.parent.type ) ) {
12526 this.transpileParameters( code, transforms, indentation, introStatementGenerators );
12527 }
12528
12529 if ( transforms.letConst && this.isFunctionBlock ) {
12530 this.transpileBlockScopedIdentifiers( code );
12531 }
12532
12533 Node.prototype.transpile.call( this, code, transforms );
12534
12535 if ( this.synthetic ) {
12536 if ( this.parent.type === 'ArrowFunctionExpression' ) {
12537 var expr = this.body[0];
12538
12539 if ( introStatementGenerators.length ) {
12540 code.appendLeft( this.start, "{" ).prependRight( this.end, ((this.parent.getIndentation()) + "}") );
12541
12542 code.prependRight( expr.start, ("\n" + indentation + "return ") );
12543 code.appendLeft( expr.end, ";\n" );
12544 } else if ( transforms.arrow ) {
12545 code.prependRight( expr.start, "{ return " );
12546 code.appendLeft( expr.end, "; }" );
12547 }
12548 }
12549
12550 else if ( introStatementGenerators.length ) {
12551 code.prependRight( this.start, "{" ).appendLeft( this.end, "}" );
12552 }
12553 }
12554
12555 var start;
12556 if ( isUseStrict( this.body[0] ) ) {
12557 start = this.body[0].end;
12558 } else if ( this.synthetic || this.parent.type === 'Root' ) {
12559 start = this.start;
12560 } else {
12561 start = this.start + 1;
12562 }
12563
12564 var prefix = "\n" + indentation;
12565 var suffix = ';';
12566 introStatementGenerators.forEach( function ( fn, i ) {
12567 if ( i === introStatementGenerators.length - 1 ) suffix = ";\n";
12568 fn( start, prefix, suffix );
12569 });
12570 };
12571
12572 BlockStatement.prototype.transpileParameters = function transpileParameters ( code, transforms, indentation, introStatementGenerators ) {
12573 var this$1 = this;
12574
12575 var params = this.parent.params;
12576
12577 params.forEach( function ( param ) {
12578 if ( param.type === 'AssignmentPattern' && param.left.type === 'Identifier' ) {
12579 if ( transforms.defaultParameter ) {
12580 introStatementGenerators.push( function ( start, prefix, suffix ) {
12581 var lhs = prefix + "if ( " + (param.left.name) + " === void 0 ) " + (param.left.name);
12582
12583 code
12584 .prependRight( param.left.end, lhs )
12585 .move( param.left.end, param.right.end, start )
12586 .appendLeft( param.right.end, suffix );
12587 });
12588 }
12589 }
12590
12591 else if ( param.type === 'RestElement' ) {
12592 if ( transforms.spreadRest ) {
12593 introStatementGenerators.push( function ( start, prefix, suffix ) {
12594 var penultimateParam = params[ params.length - 2 ];
12595
12596 if ( penultimateParam ) {
12597 code.remove( penultimateParam ? penultimateParam.end : param.start, param.end );
12598 } else {
12599 var start$1 = param.start, end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8
12600
12601 while ( /\s/.test( code.original[ start$1 - 1 ] ) ) start$1 -= 1;
12602 while ( /\s/.test( code.original[ end ] ) ) end += 1;
12603
12604 code.remove( start$1, end );
12605 }
12606
12607 var name = param.argument.name;
12608 var len = this$1.scope.createIdentifier( 'len' );
12609 var count = params.length - 1;
12610
12611 if ( count ) {
12612 code.prependRight( start, (prefix + "var " + name + " = [], " + len + " = arguments.length - " + count + ";\n" + indentation + "while ( " + len + "-- > 0 ) " + name + "[ " + len + " ] = arguments[ " + len + " + " + count + " ]" + suffix) );
12613 } else {
12614 code.prependRight( start, (prefix + "var " + name + " = [], " + len + " = arguments.length;\n" + indentation + "while ( " + len + "-- ) " + name + "[ " + len + " ] = arguments[ " + len + " ]" + suffix) );
12615 }
12616 });
12617 }
12618 }
12619
12620 else if ( param.type !== 'Identifier' ) {
12621 if ( transforms.parameterDestructuring ) {
12622 var ref = this$1.scope.createIdentifier( 'ref' );
12623 destructure( code, this$1.scope, param, ref, false, introStatementGenerators );
12624 code.prependRight( param.start, ref );
12625 }
12626 }
12627 });
12628 };
12629
12630 BlockStatement.prototype.transpileBlockScopedIdentifiers = function transpileBlockScopedIdentifiers ( code ) {
12631 var this$1 = this;
12632
12633 Object.keys( this.scope.blockScopedDeclarations ).forEach( function ( name ) {
12634 var declarations = this$1.scope.blockScopedDeclarations[ name ];
12635
12636 for ( var i = 0, list = declarations; i < list.length; i += 1 ) {
12637 var declaration = list[i];
12638
12639 var cont = false; // TODO implement proper continue...
12640
12641 if ( declaration.kind === 'for.let' ) {
12642 // special case
12643 var forStatement = declaration.node.findNearest( 'ForStatement' );
12644
12645 if ( forStatement.shouldRewriteAsFunction ) {
12646 var outerAlias = this$1.scope.createIdentifier( name );
12647 var innerAlias = forStatement.reassigned[ name ] ?
12648 this$1.scope.createIdentifier( name ) :
12649 name;
12650
12651 declaration.name = outerAlias;
12652 code.overwrite( declaration.node.start, declaration.node.end, outerAlias, { storeName: true });
12653
12654 forStatement.aliases[ name ] = {
12655 outer: outerAlias,
12656 inner: innerAlias
12657 };
12658
12659 for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
12660 var identifier = list$1[i$1];
12661
12662 var alias = forStatement.body.contains( identifier ) ?
12663 innerAlias :
12664 outerAlias;
12665
12666 if ( name !== alias ) {
12667 code.overwrite( identifier.start, identifier.end, alias, { storeName: true });
12668 }
12669 }
12670
12671 cont = true;
12672 }
12673 }
12674
12675 if ( !cont ) {
12676 var alias$1 = this$1.scope.createIdentifier( name );
12677
12678 if ( name !== alias$1 ) {
12679 declaration.name = alias$1;
12680 code.overwrite( declaration.node.start, declaration.node.end, alias$1, { storeName: true });
12681
12682 for ( var i$2 = 0, list$2 = declaration.instances; i$2 < list$2.length; i$2 += 1 ) {
12683 var identifier$1 = list$2[i$2];
12684
12685 identifier$1.rewritten = true;
12686 code.overwrite( identifier$1.start, identifier$1.end, alias$1, { storeName: true });
12687 }
12688 }
12689 }
12690 }
12691 });
12692 };
12693
12694 return BlockStatement;
12695}(Node$1));
12696
12697function Program ( source, ast, transforms, options ) {
12698 var this$1 = this;
12699
12700 this.type = 'Root';
12701
12702 // options
12703 this.jsx = options.jsx || 'React.createElement';
12704 this.options = options;
12705
12706 this.source = source;
12707 this.magicString = new MagicString( source );
12708
12709 this.ast = ast;
12710 this.depth = 0;
12711
12712 wrap( this.body = ast, this );
12713 this.body.__proto__ = BlockStatement.prototype;
12714
12715 this.indentExclusionElements = [];
12716 this.body.initialise( transforms );
12717
12718 this.indentExclusions = Object.create( null );
12719 for ( var i$1 = 0, list = this.indentExclusionElements; i$1 < list.length; i$1 += 1 ) {
12720 var node = list[i$1];
12721
12722 for ( var i = node.start; i < node.end; i += 1 ) {
12723 this$1.indentExclusions[ i ] = true;
12724 }
12725 }
12726
12727 this.body.transpile( this.magicString, transforms );
12728}
12729
12730Program.prototype = {
12731 export: function export$1 ( options ) {
12732 if ( options === void 0 ) options = {};
12733
12734 return {
12735 code: this.magicString.toString(),
12736 map: this.magicString.generateMap({
12737 file: options.file,
12738 source: options.source,
12739 includeContent: options.includeContent !== false
12740 })
12741 };
12742 },
12743
12744 findNearest: function findNearest () {
12745 return null;
12746 },
12747
12748 findScope: function findScope () {
12749 return null;
12750 }
12751};
12752
12753var matrix = {
12754 chrome: {
12755 48: 1333689725,
12756 49: 1342078975,
12757 50: 1610514431,
12758 51: 1610514431,
12759 52: 2147385343
12760 },
12761 firefox: {
12762 43: 1207307741,
12763 44: 1207307741,
12764 45: 1207307741,
12765 46: 1476267485,
12766 47: 1476296671,
12767 48: 1476296671
12768 },
12769 safari: {
12770 8: 1073741824,
12771 9: 1328940894
12772 },
12773 ie: {
12774 8: 0,
12775 9: 1073741824,
12776 10: 1073741824,
12777 11: 1073770592
12778 },
12779 edge: {
12780 12: 1591620701,
12781 13: 1608400479
12782 },
12783 node: {
12784 '0.10': 1075052608,
12785 '0.12': 1091830852,
12786 4: 1327398527,
12787 5: 1327398527,
12788 6: 1610514431
12789 }
12790};
12791
12792var features = [
12793 'arrow',
12794 'classes',
12795 'collections',
12796 'computedProperty',
12797 'conciseMethodProperty',
12798 'constLoop',
12799 'constRedef',
12800 'defaultParameter',
12801 'destructuring',
12802 'extendNatives',
12803 'forOf',
12804 'generator',
12805 'letConst',
12806 'letLoop',
12807 'letLoopScope',
12808 'moduleExport',
12809 'moduleImport',
12810 'numericLiteral',
12811 'objectProto',
12812 'objectSuper',
12813 'oldOctalLiteral',
12814 'parameterDestructuring',
12815 'spreadRest',
12816 'stickyRegExp',
12817 'symbol',
12818 'templateString',
12819 'unicodeEscape',
12820 'unicodeIdentifier',
12821 'unicodeRegExp',
12822
12823 // ES2016
12824 'exponentiation',
12825
12826 // additional transforms, not from
12827 // https://featuretests.io
12828 'reservedProperties'
12829];
12830
12831var version$1 = "0.17.1";
12832
12833var ref = [
12834 inject$1,
12835 inject
12836].reduce( function ( final, plugin ) { return plugin( final ); }, acorn );
12837var parse = ref.parse;
12838
12839var dangerousTransforms = [
12840 'dangerousTaggedTemplateString',
12841 'dangerousForOf'
12842];
12843
12844function target ( target ) {
12845 var targets = Object.keys( target );
12846 var bitmask = targets.length ?
12847 2147483647 :
12848 1073741824;
12849
12850 Object.keys( target ).forEach( function ( environment ) {
12851 var versions = matrix[ environment ];
12852 if ( !versions ) throw new Error( ("Unknown environment '" + environment + "'. Please raise an issue at https://gitlab.com/Rich-Harris/buble/issues") );
12853
12854 var targetVersion = target[ environment ];
12855 if ( !( targetVersion in versions ) ) throw new Error( ("Support data exists for the following versions of " + environment + ": " + (Object.keys( versions ).join( ', ')) + ". Please raise an issue at https://gitlab.com/Rich-Harris/buble/issues") );
12856 var support = versions[ targetVersion ];
12857
12858 bitmask &= support;
12859 });
12860
12861 var transforms = Object.create( null );
12862 features.forEach( function ( name, i ) {
12863 transforms[ name ] = !( bitmask & 1 << i );
12864 });
12865
12866 dangerousTransforms.forEach( function ( name ) {
12867 transforms[ name ] = false;
12868 });
12869
12870 return transforms;
12871}
12872
12873function transform ( source, options ) {
12874 if ( options === void 0 ) options = {};
12875
12876 var ast;
12877 var jsx = null;
12878
12879 try {
12880 ast = parse( source, {
12881 ecmaVersion: 8,
12882 preserveParens: true,
12883 sourceType: 'module',
12884 onComment: function (block, text) {
12885 if ( !jsx ) {
12886 var match = /@jsx\s+([^\s]+)/.exec( text );
12887 if ( match ) jsx = match[1];
12888 }
12889 },
12890 plugins: {
12891 jsx: true,
12892 objectSpread: true
12893 }
12894 });
12895 options.jsx = jsx || options.jsx;
12896 } catch ( err ) {
12897 err.snippet = getSnippet( source, err.loc );
12898 err.toString = function () { return ((err.name) + ": " + (err.message) + "\n" + (err.snippet)); };
12899 throw err;
12900 }
12901
12902 var transforms = target( options.target || {} );
12903 Object.keys( options.transforms || {} ).forEach( function ( name ) {
12904 if ( name === 'modules' ) {
12905 if ( !( 'moduleImport' in options.transforms ) ) transforms.moduleImport = options.transforms.modules;
12906 if ( !( 'moduleExport' in options.transforms ) ) transforms.moduleExport = options.transforms.modules;
12907 return;
12908 }
12909
12910 if ( !( name in transforms ) ) throw new Error( ("Unknown transform '" + name + "'") );
12911 transforms[ name ] = options.transforms[ name ];
12912 });
12913
12914 return new Program( source, ast, transforms, options ).export( options );
12915}
12916
12917export { target, transform, version$1 as VERSION };
12918//# sourceMappingURL=buble.es.js.map