UNPKG

403 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 RestElement: function RestElement ( names, node ) {
5925 extractors[ node.argument.type ]( names, node.argument );
5926 },
5927
5928 ArrayPattern: function ArrayPattern ( names, node ) {
5929 for ( var i = 0, list = node.elements; i < list.length; i += 1 ) {
5930 var element = list[i];
5931
5932 if ( element ) extractors[ element.type ]( names, element );
5933 }
5934 },
5935
5936 RestElement: function RestElement$1 ( names, node ) {
5937 extractors[ node.argument.type ]( names, node.argument );
5938 },
5939
5940 AssignmentPattern: function AssignmentPattern ( names, node ) {
5941 extractors[ node.left.type ]( names, node.left );
5942 }
5943};
5944
5945var ForStatement = (function (LoopStatement$$1) {
5946 function ForStatement () {
5947 LoopStatement$$1.apply(this, arguments);
5948 }
5949
5950 if ( LoopStatement$$1 ) ForStatement.__proto__ = LoopStatement$$1;
5951 ForStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
5952 ForStatement.prototype.constructor = ForStatement;
5953
5954 ForStatement.prototype.findScope = function findScope ( functionScope ) {
5955 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
5956 };
5957
5958 ForStatement.prototype.transpile = function transpile ( code, transforms ) {
5959 var this$1 = this;
5960
5961 var i1 = this.getIndentation() + code.getIndentString();
5962
5963 if ( this.shouldRewriteAsFunction ) {
5964 // which variables are declared in the init statement?
5965 var names = this.init.type === 'VariableDeclaration' ?
5966 [].concat.apply( [], this.init.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
5967 [];
5968
5969 var aliases = this.aliases;
5970
5971 this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
5972 this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
5973
5974 var updates = Object.keys( this.reassigned )
5975 .map( function ( name ) { return ((aliases[ name ].outer) + " = " + (aliases[ name ].inner) + ";"); } );
5976
5977 if ( updates.length ) {
5978 if ( this.body.synthetic ) {
5979 code.appendLeft( this.body.body[0].end, ("; " + (updates.join(" "))) );
5980 } else {
5981 var lastStatement = this.body.body[ this.body.body.length - 1 ];
5982 code.appendLeft( lastStatement.end, ("\n\n" + i1 + (updates.join(("\n" + i1)))) );
5983 }
5984 }
5985 }
5986
5987 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
5988 };
5989
5990 return ForStatement;
5991}(LoopStatement));
5992
5993var ForInStatement = (function (LoopStatement$$1) {
5994 function ForInStatement () {
5995 LoopStatement$$1.apply(this, arguments);
5996 }
5997
5998 if ( LoopStatement$$1 ) ForInStatement.__proto__ = LoopStatement$$1;
5999 ForInStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
6000 ForInStatement.prototype.constructor = ForInStatement;
6001
6002 ForInStatement.prototype.findScope = function findScope ( functionScope ) {
6003 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
6004 };
6005
6006 ForInStatement.prototype.transpile = function transpile ( code, transforms ) {
6007 var this$1 = this;
6008
6009 if ( this.shouldRewriteAsFunction ) {
6010 // which variables are declared in the init statement?
6011 var names = this.left.type === 'VariableDeclaration' ?
6012 [].concat.apply( [], this.left.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
6013 [];
6014
6015 this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
6016 this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
6017 }
6018
6019 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
6020 };
6021
6022 return ForInStatement;
6023}(LoopStatement));
6024
6025var handlers = {
6026 Identifier: destructureIdentifier,
6027 AssignmentPattern: destructureAssignmentPattern,
6028 ArrayPattern: destructureArrayPattern,
6029 ObjectPattern: destructureObjectPattern
6030};
6031
6032function destructure ( code, scope, node, ref, inline, statementGenerators ) {
6033 handlers[ node.type ]( code, scope, node, ref, inline, statementGenerators );
6034}
6035
6036function destructureIdentifier ( code, scope, node, ref, inline, statementGenerators ) {
6037 statementGenerators.push( function ( start, prefix, suffix ) {
6038 code.prependRight( node.start, inline ? prefix : (prefix + "var ") );
6039 code.appendLeft( node.end, (" = " + ref + suffix) );
6040 code.move( node.start, node.end, start );
6041 });
6042}
6043
6044function destructureAssignmentPattern ( code, scope, node, ref, inline, statementGenerators ) {
6045 var isIdentifier = node.left.type === 'Identifier';
6046 var name = isIdentifier ? node.left.name : ref;
6047
6048 if ( !inline ) {
6049 statementGenerators.push( function ( start, prefix, suffix ) {
6050 code.prependRight( node.left.end, (prefix + "if ( " + name + " === void 0 ) " + name) );
6051 code.move( node.left.end, node.right.end, start );
6052 code.appendLeft( node.right.end, suffix );
6053 });
6054 }
6055
6056 if ( !isIdentifier ) {
6057 destructure( code, scope, node.left, ref, inline, statementGenerators );
6058 }
6059}
6060
6061function destructureArrayPattern ( code, scope, node, ref, inline, statementGenerators ) {
6062 var c = node.start;
6063
6064 node.elements.forEach( function ( element, i ) {
6065 if ( !element ) return;
6066
6067 if ( element.type === 'RestElement' ) {
6068 handleProperty( code, scope, c, element.argument, (ref + ".slice(" + i + ")"), inline, statementGenerators );
6069 } else {
6070 handleProperty( code, scope, c, element, (ref + "[" + i + "]"), inline, statementGenerators );
6071 }
6072 c = element.end;
6073 });
6074
6075 code.remove( c, node.end );
6076}
6077
6078function destructureObjectPattern ( code, scope, node, ref, inline, statementGenerators ) {
6079 var this$1 = this;
6080
6081 var c = node.start;
6082
6083 var nonRestKeys = [];
6084 node.properties.forEach( function ( prop ) {
6085 var value;
6086 var content;
6087 if (prop.type === "Property") {
6088 var isComputedKey = prop.computed || prop.key.type !== 'Identifier';
6089 var key = isComputedKey ? code.slice(prop.key.start, prop.key.end) : prop.key.name;
6090 value = isComputedKey ? (ref + "[" + key + "]") : (ref + "." + key);
6091 content = prop.value;
6092 nonRestKeys.push(isComputedKey ? key : '"' + key + '"');
6093 } else if (prop.type === "RestElement") {
6094 content = prop.argument;
6095 value = scope.createIdentifier( 'rest' );
6096 var n = scope.createIdentifier( 'n' );
6097 statementGenerators.push( function ( start, prefix, suffix ) {
6098 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));
6099 code.move(prop.start, c, start);
6100 } );
6101 } else {
6102 throw new CompileError( this$1, ("Unexpected node of type " + (prop.type) + " in object pattern"))
6103 }
6104 handleProperty( code, scope, c, content, value, inline, statementGenerators );
6105 c = prop.end;
6106 });
6107
6108 code.remove( c, node.end );
6109}
6110
6111function handleProperty ( code, scope, c, node, value, inline, statementGenerators ) {
6112 switch ( node.type ) {
6113 case 'Identifier': {
6114 code.remove( c, node.start );
6115 destructureIdentifier( code, scope, node, value, inline, statementGenerators );
6116 break;
6117 }
6118
6119 case 'AssignmentPattern': {
6120 var name;
6121
6122 var isIdentifier = node.left.type === 'Identifier';
6123
6124 if ( isIdentifier ) {
6125 name = node.left.name;
6126 var declaration = scope.findDeclaration( name );
6127 if ( declaration ) name = declaration.name;
6128 } else {
6129 name = scope.createIdentifier( value );
6130 }
6131
6132 statementGenerators.push( function ( start, prefix, suffix ) {
6133 if ( inline ) {
6134 code.prependRight( node.right.start, (name + " = " + value + " === undefined ? ") );
6135 code.appendLeft( node.right.end, (" : " + value) );
6136 } else {
6137 code.prependRight( node.right.start, (prefix + "var " + name + " = " + value + "; if ( " + name + " === void 0 ) " + name + " = ") );
6138 code.appendLeft( node.right.end, suffix );
6139 }
6140
6141 code.move( node.right.start, node.right.end, start );
6142 });
6143
6144 if ( isIdentifier ) {
6145 code.remove( c, node.right.start );
6146 } else {
6147 code.remove( c, node.left.start );
6148 code.remove( node.left.end, node.right.start );
6149 handleProperty( code, scope, c, node.left, name, inline, statementGenerators );
6150 }
6151
6152 break;
6153 }
6154
6155 case 'ObjectPattern': {
6156 code.remove( c, c = node.start );
6157
6158 var ref = value;
6159 if ( node.properties.length > 1 ) {
6160 ref = scope.createIdentifier( value );
6161
6162 statementGenerators.push( function ( start, prefix, suffix ) {
6163 // this feels a tiny bit hacky, but we can't do a
6164 // straightforward appendLeft and keep correct order...
6165 code.prependRight( node.start, (prefix + "var " + ref + " = ") );
6166 code.overwrite( node.start, c = node.start + 1, value );
6167 code.appendLeft( c, suffix );
6168
6169 code.overwrite( node.start, c = node.start + 1, (prefix + "var " + ref + " = " + value + suffix) );
6170 code.move( node.start, c, start );
6171 });
6172 }
6173
6174 destructureObjectPattern( code, scope, node, ref, inline, statementGenerators );
6175
6176 break;
6177 }
6178
6179 case 'ArrayPattern': {
6180 code.remove( c, c = node.start );
6181
6182 if ( node.elements.filter( Boolean ).length > 1 ) {
6183 var ref$1 = scope.createIdentifier( value );
6184
6185 statementGenerators.push( function ( start, prefix, suffix ) {
6186 code.prependRight( node.start, (prefix + "var " + ref$1 + " = ") );
6187 code.overwrite( node.start, c = node.start + 1, value, { contentOnly: true });
6188 code.appendLeft( c, suffix );
6189
6190 code.move( node.start, c, start );
6191 });
6192
6193 node.elements.forEach( function ( element, i ) {
6194 if ( !element ) return;
6195
6196 if ( element.type === 'RestElement' ) {
6197 handleProperty( code, scope, c, element.argument, (ref$1 + ".slice(" + i + ")"), inline, statementGenerators );
6198 } else {
6199 handleProperty( code, scope, c, element, (ref$1 + "[" + i + "]"), inline, statementGenerators );
6200 }
6201 c = element.end;
6202 });
6203 } else {
6204 var index = findIndex( node.elements, Boolean );
6205 var element = node.elements[ index ];
6206 if ( element.type === 'RestElement' ) {
6207 handleProperty( code, scope, c, element.argument, (value + ".slice(" + index + ")"), inline, statementGenerators );
6208 } else {
6209 handleProperty( code, scope, c, element, (value + "[" + index + "]"), inline, statementGenerators );
6210 }
6211 c = element.end;
6212 }
6213
6214 code.remove( c, node.end );
6215 break;
6216 }
6217
6218 default: {
6219 throw new Error( ("Unexpected node type in destructuring (" + (node.type) + ")") );
6220 }
6221 }
6222}
6223
6224var ForOfStatement = (function (LoopStatement$$1) {
6225 function ForOfStatement () {
6226 LoopStatement$$1.apply(this, arguments);
6227 }
6228
6229 if ( LoopStatement$$1 ) ForOfStatement.__proto__ = LoopStatement$$1;
6230 ForOfStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
6231 ForOfStatement.prototype.constructor = ForOfStatement;
6232
6233 ForOfStatement.prototype.initialise = function initialise ( transforms ) {
6234 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 );
6235 LoopStatement$$1.prototype.initialise.call( this, transforms );
6236 };
6237
6238 ForOfStatement.prototype.transpile = function transpile ( code, transforms ) {
6239 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
6240 if ( !transforms.dangerousForOf ) return;
6241
6242 // edge case (#80)
6243 if ( !this.body.body[0] ) {
6244 if ( this.left.type === 'VariableDeclaration' && this.left.kind === 'var' ) {
6245 code.remove( this.start, this.left.start );
6246 code.appendLeft( this.left.end, ';' );
6247 code.remove( this.left.end, this.end );
6248 } else {
6249 code.remove( this.start, this.end );
6250 }
6251
6252 return;
6253 }
6254
6255 var scope = this.findScope( true );
6256 var i0 = this.getIndentation();
6257 var i1 = i0 + code.getIndentString();
6258
6259 var key = scope.createIdentifier( 'i' );
6260 var list = scope.createIdentifier( 'list' );
6261
6262 if ( this.body.synthetic ) {
6263 code.prependRight( this.left.start, ("{\n" + i1) );
6264 code.appendLeft( this.body.body[0].end, ("\n" + i0 + "}") );
6265 }
6266
6267 var bodyStart = this.body.body[0].start;
6268
6269 code.remove( this.left.end, this.right.start );
6270 code.move( this.left.start, this.left.end, bodyStart );
6271
6272
6273 code.prependRight( this.right.start, ("var " + key + " = 0, " + list + " = ") );
6274 code.appendLeft( this.right.end, ("; " + key + " < " + list + ".length; " + key + " += 1") );
6275
6276 // destructuring. TODO non declaration destructuring
6277 var declarator = this.left.type === 'VariableDeclaration' && this.left.declarations[0];
6278 if ( declarator && declarator.id.type !== 'Identifier' ) {
6279 var statementGenerators = [];
6280 var ref = scope.createIdentifier( 'ref' );
6281 destructure( code, scope, declarator.id, ref, false, statementGenerators );
6282
6283 var suffix = ";\n" + i1;
6284 statementGenerators.forEach( function ( fn, i ) {
6285 if ( i === statementGenerators.length - 1 ) {
6286 suffix = ";\n\n" + i1;
6287 }
6288
6289 fn( bodyStart, '', suffix );
6290 });
6291
6292 code.appendLeft( this.left.start + this.left.kind.length + 1, ref );
6293 code.appendLeft( this.left.end, (" = " + list + "[" + key + "];\n" + i1) );
6294 } else {
6295 code.appendLeft( this.left.end, (" = " + list + "[" + key + "];\n\n" + i1) );
6296 }
6297 };
6298
6299 return ForOfStatement;
6300}(LoopStatement));
6301
6302var FunctionDeclaration = (function (Node) {
6303 function FunctionDeclaration () {
6304 Node.apply(this, arguments);
6305 }
6306
6307 if ( Node ) FunctionDeclaration.__proto__ = Node;
6308 FunctionDeclaration.prototype = Object.create( Node && Node.prototype );
6309 FunctionDeclaration.prototype.constructor = FunctionDeclaration;
6310
6311 FunctionDeclaration.prototype.initialise = function initialise ( transforms ) {
6312 if ( this.generator && transforms.generator ) {
6313 throw new CompileError$1( 'Generators are not supported', this );
6314 }
6315
6316 this.body.createScope();
6317
6318 this.findScope( true ).addDeclaration( this.id, 'function' );
6319 Node.prototype.initialise.call( this, transforms );
6320 };
6321
6322 return FunctionDeclaration;
6323}(Node$1));
6324
6325var FunctionExpression = (function (Node) {
6326 function FunctionExpression () {
6327 Node.apply(this, arguments);
6328 }
6329
6330 if ( Node ) FunctionExpression.__proto__ = Node;
6331 FunctionExpression.prototype = Object.create( Node && Node.prototype );
6332 FunctionExpression.prototype.constructor = FunctionExpression;
6333
6334 FunctionExpression.prototype.initialise = function initialise ( transforms ) {
6335 if ( this.generator && transforms.generator ) {
6336 throw new CompileError$1( 'Generators are not supported', this );
6337 }
6338
6339 this.body.createScope();
6340
6341 if ( this.id ) {
6342 // function expression IDs belong to the child scope...
6343 this.body.scope.addDeclaration( this.id, 'function' );
6344 }
6345
6346 Node.prototype.initialise.call( this, transforms );
6347
6348 var parent = this.parent;
6349 var methodName;
6350
6351 if ( transforms.conciseMethodProperty
6352 && parent.type === 'Property'
6353 && parent.kind === 'init'
6354 && parent.method
6355 && parent.key.type === 'Identifier' ) {
6356 // object literal concise method
6357 methodName = parent.key.name;
6358 }
6359 else if ( transforms.classes
6360 && parent.type === 'MethodDefinition'
6361 && parent.kind === 'method'
6362 && parent.key.type === 'Identifier' ) {
6363 // method definition in a class
6364 methodName = parent.key.name;
6365 }
6366 else if ( this.id && this.id.type === 'Identifier' ) {
6367 // naked function expression
6368 methodName = this.id.alias || this.id.name;
6369 }
6370
6371 if ( methodName ) {
6372 for ( var i = 0, list = this.params; i < list.length; i += 1 ) {
6373 var param = list[i];
6374
6375 if ( param.type === 'Identifier' && methodName === param.name ) {
6376 // workaround for Safari 9/WebKit bug:
6377 // https://gitlab.com/Rich-Harris/buble/issues/154
6378 // change parameter name when same as method name
6379
6380 var scope = this.body.scope;
6381 var declaration = scope.declarations[ methodName ];
6382
6383 var alias = scope.createIdentifier( methodName );
6384 param.alias = alias;
6385
6386 for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
6387 var identifier = list$1[i$1];
6388
6389 identifier.alias = alias;
6390 }
6391
6392 break;
6393 }
6394 }
6395 }
6396 };
6397
6398 return FunctionExpression;
6399}(Node$1));
6400
6401function isReference ( node, parent ) {
6402 if ( node.type === 'MemberExpression' ) {
6403 return !node.computed && isReference( node.object, node );
6404 }
6405
6406 if ( node.type === 'Identifier' ) {
6407 // the only time we could have an identifier node without a parent is
6408 // if it's the entire body of a function without a block statement –
6409 // i.e. an arrow function expression like `a => a`
6410 if ( !parent ) return true;
6411
6412 if ( /(Function|Class)Expression/.test( parent.type ) ) return false;
6413
6414 if ( parent.type === 'VariableDeclarator' ) return node === parent.init;
6415
6416 // TODO is this right?
6417 if ( parent.type === 'MemberExpression' || parent.type === 'MethodDefinition' ) {
6418 return parent.computed || node === parent.object;
6419 }
6420
6421 if ( parent.type === 'ArrayPattern' ) return false;
6422
6423 // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
6424 if ( parent.type === 'Property' ) {
6425 if ( parent.parent.type === 'ObjectPattern' ) return false;
6426 return parent.computed || node === parent.value;
6427 }
6428
6429 // disregard the `bar` in `class Foo { bar () {...} }`
6430 if ( parent.type === 'MethodDefinition' ) return false;
6431
6432 // disregard the `bar` in `export { foo as bar }`
6433 if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return false;
6434
6435 return true;
6436 }
6437}
6438
6439var Identifier = (function (Node) {
6440 function Identifier () {
6441 Node.apply(this, arguments);
6442 }
6443
6444 if ( Node ) Identifier.__proto__ = Node;
6445 Identifier.prototype = Object.create( Node && Node.prototype );
6446 Identifier.prototype.constructor = Identifier;
6447
6448 Identifier.prototype.findScope = function findScope ( functionScope ) {
6449 if ( this.parent.params && ~this.parent.params.indexOf( this ) ) {
6450 return this.parent.body.scope;
6451 }
6452
6453 if ( this.parent.type === 'FunctionExpression' && this === this.parent.id ) {
6454 return this.parent.body.scope;
6455 }
6456
6457 return this.parent.findScope( functionScope );
6458 };
6459
6460 Identifier.prototype.initialise = function initialise ( transforms ) {
6461 if ( transforms.arrow && isReference( this, this.parent ) ) {
6462 if ( this.name === 'arguments' && !this.findScope( false ).contains( this.name ) ) {
6463 var lexicalBoundary = this.findLexicalBoundary();
6464 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
6465 var loop = this.findNearest( loopStatement );
6466
6467 if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
6468 this.alias = lexicalBoundary.getArgumentsAlias();
6469 }
6470
6471 if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
6472 this.alias = lexicalBoundary.getArgumentsAlias();
6473 }
6474 }
6475
6476 this.findScope( false ).addReference( this );
6477 }
6478 };
6479
6480 Identifier.prototype.transpile = function transpile ( code ) {
6481 if ( this.alias ) {
6482 code.overwrite( this.start, this.end, this.alias, { storeName: true, contentOnly: true });
6483 }
6484 };
6485
6486 return Identifier;
6487}(Node$1));
6488
6489var IfStatement = (function (Node) {
6490 function IfStatement () {
6491 Node.apply(this, arguments);
6492 }
6493
6494 if ( Node ) IfStatement.__proto__ = Node;
6495 IfStatement.prototype = Object.create( Node && Node.prototype );
6496 IfStatement.prototype.constructor = IfStatement;
6497
6498 IfStatement.prototype.initialise = function initialise ( transforms ) {
6499 Node.prototype.initialise.call( this, transforms );
6500 };
6501
6502 IfStatement.prototype.transpile = function transpile ( code, transforms ) {
6503 if ( this.consequent.type !== 'BlockStatement'
6504 || this.consequent.type === 'BlockStatement' && this.consequent.synthetic ) {
6505 code.appendLeft( this.consequent.start, '{ ' );
6506 code.prependRight( this.consequent.end, ' }' );
6507 }
6508
6509 if ( this.alternate && this.alternate.type !== 'IfStatement' && (
6510 this.alternate.type !== 'BlockStatement'
6511 || this.alternate.type === 'BlockStatement' && this.alternate.synthetic ) ) {
6512 code.appendLeft( this.alternate.start, '{ ' );
6513 code.prependRight( this.alternate.end, ' }' );
6514 }
6515
6516 Node.prototype.transpile.call( this, code, transforms );
6517 };
6518
6519 return IfStatement;
6520}(Node$1));
6521
6522var ImportDeclaration = (function (Node) {
6523 function ImportDeclaration () {
6524 Node.apply(this, arguments);
6525 }
6526
6527 if ( Node ) ImportDeclaration.__proto__ = Node;
6528 ImportDeclaration.prototype = Object.create( Node && Node.prototype );
6529 ImportDeclaration.prototype.constructor = ImportDeclaration;
6530
6531 ImportDeclaration.prototype.initialise = function initialise ( transforms ) {
6532 if ( transforms.moduleImport ) throw new CompileError$1( 'import is not supported', this );
6533 Node.prototype.initialise.call( this, transforms );
6534 };
6535
6536 return ImportDeclaration;
6537}(Node$1));
6538
6539var ImportDefaultSpecifier = (function (Node) {
6540 function ImportDefaultSpecifier () {
6541 Node.apply(this, arguments);
6542 }
6543
6544 if ( Node ) ImportDefaultSpecifier.__proto__ = Node;
6545 ImportDefaultSpecifier.prototype = Object.create( Node && Node.prototype );
6546 ImportDefaultSpecifier.prototype.constructor = ImportDefaultSpecifier;
6547
6548 ImportDefaultSpecifier.prototype.initialise = function initialise ( transforms ) {
6549 this.findScope( true ).addDeclaration( this.local, 'import' );
6550 Node.prototype.initialise.call( this, transforms );
6551 };
6552
6553 return ImportDefaultSpecifier;
6554}(Node$1));
6555
6556var ImportSpecifier = (function (Node) {
6557 function ImportSpecifier () {
6558 Node.apply(this, arguments);
6559 }
6560
6561 if ( Node ) ImportSpecifier.__proto__ = Node;
6562 ImportSpecifier.prototype = Object.create( Node && Node.prototype );
6563 ImportSpecifier.prototype.constructor = ImportSpecifier;
6564
6565 ImportSpecifier.prototype.initialise = function initialise ( transforms ) {
6566 this.findScope( true ).addDeclaration( this.local, 'import' );
6567 Node.prototype.initialise.call( this, transforms );
6568 };
6569
6570 return ImportSpecifier;
6571}(Node$1));
6572
6573var hasDashes = function ( val ) { return /-/.test(val); };
6574
6575var formatKey = function ( key ) { return hasDashes(key) ? ("'" + key + "'") : key; };
6576
6577var formatVal = function ( val ) { return val ? '' : 'true'; };
6578
6579var JSXAttribute = (function (Node) {
6580 function JSXAttribute () {
6581 Node.apply(this, arguments);
6582 }
6583
6584 if ( Node ) JSXAttribute.__proto__ = Node;
6585 JSXAttribute.prototype = Object.create( Node && Node.prototype );
6586 JSXAttribute.prototype.constructor = JSXAttribute;
6587
6588 JSXAttribute.prototype.transpile = function transpile ( code, transforms ) {
6589 var ref = this.name;
6590 var start = ref.start;
6591 var name = ref.name;
6592
6593 // Overwrite equals sign if value is present.
6594 var end = this.value ? this.value.start : this.name.end;
6595
6596 code.overwrite( start, end, ((formatKey(name)) + ": " + (formatVal(this.value))) );
6597
6598 Node.prototype.transpile.call( this, code, transforms );
6599 };
6600
6601 return JSXAttribute;
6602}(Node$1));
6603
6604function containsNewLine ( node ) {
6605 return node.type === 'Literal' && !/\S/.test( node.value ) && /\n/.test( node.value );
6606}
6607
6608var JSXClosingElement = (function (Node) {
6609 function JSXClosingElement () {
6610 Node.apply(this, arguments);
6611 }
6612
6613 if ( Node ) JSXClosingElement.__proto__ = Node;
6614 JSXClosingElement.prototype = Object.create( Node && Node.prototype );
6615 JSXClosingElement.prototype.constructor = JSXClosingElement;
6616
6617 JSXClosingElement.prototype.transpile = function transpile ( code ) {
6618 var spaceBeforeParen = true;
6619
6620 var lastChild = this.parent.children[ this.parent.children.length - 1 ];
6621
6622 // omit space before closing paren if
6623 // a) this is on a separate line, or
6624 // b) there are no children but there are attributes
6625 if ( ( lastChild && containsNewLine( lastChild ) ) || ( this.parent.openingElement.attributes.length ) ) {
6626 spaceBeforeParen = false;
6627 }
6628
6629 code.overwrite( this.start, this.end, spaceBeforeParen ? ' )' : ')' );
6630 };
6631
6632 return JSXClosingElement;
6633}(Node$1));
6634
6635function normalise ( str, removeTrailingWhitespace ) {
6636 if ( removeTrailingWhitespace && /\n/.test( str ) ) {
6637 str = str.replace( /\s+$/, '' );
6638 }
6639
6640 str = str
6641 .replace( /^\n\r?\s+/, '' ) // remove leading newline + space
6642 .replace( /\s*\n\r?\s*/gm, ' ' ); // replace newlines with spaces
6643
6644 // TODO prefer single quotes?
6645 return JSON.stringify( str );
6646}
6647
6648var JSXElement = (function (Node) {
6649 function JSXElement () {
6650 Node.apply(this, arguments);
6651 }
6652
6653 if ( Node ) JSXElement.__proto__ = Node;
6654 JSXElement.prototype = Object.create( Node && Node.prototype );
6655 JSXElement.prototype.constructor = JSXElement;
6656
6657 JSXElement.prototype.transpile = function transpile ( code, transforms ) {
6658 Node.prototype.transpile.call( this, code, transforms );
6659
6660 var children = this.children.filter( function ( child ) {
6661 if ( child.type !== 'Literal' ) return true;
6662
6663 // remove whitespace-only literals, unless on a single line
6664 return /\S/.test( child.value ) || !/\n/.test( child.value );
6665 });
6666
6667 if ( children.length ) {
6668 var c = this.openingElement.end;
6669
6670 var i;
6671 for ( i = 0; i < children.length; i += 1 ) {
6672 var child = children[i];
6673
6674 if ( child.type === 'JSXExpressionContainer' && child.expression.type === 'JSXEmptyExpression' ) {
6675 // empty block is a no op
6676 } else {
6677 var tail = code.original[ c ] === '\n' && child.type !== 'Literal' ? '' : ' ';
6678 code.appendLeft( c, ("," + tail) );
6679 }
6680
6681 if ( child.type === 'Literal' ) {
6682 var str = normalise( child.value, i === children.length - 1 );
6683 code.overwrite( child.start, child.end, str );
6684 }
6685
6686 c = child.end;
6687 }
6688 }
6689 };
6690
6691 return JSXElement;
6692}(Node$1));
6693
6694var JSXExpressionContainer = (function (Node) {
6695 function JSXExpressionContainer () {
6696 Node.apply(this, arguments);
6697 }
6698
6699 if ( Node ) JSXExpressionContainer.__proto__ = Node;
6700 JSXExpressionContainer.prototype = Object.create( Node && Node.prototype );
6701 JSXExpressionContainer.prototype.constructor = JSXExpressionContainer;
6702
6703 JSXExpressionContainer.prototype.transpile = function transpile ( code, transforms ) {
6704 code.remove( this.start, this.expression.start );
6705 code.remove( this.expression.end, this.end );
6706
6707 Node.prototype.transpile.call( this, code, transforms );
6708 };
6709
6710 return JSXExpressionContainer;
6711}(Node$1));
6712
6713var JSXOpeningElement = (function (Node) {
6714 function JSXOpeningElement () {
6715 Node.apply(this, arguments);
6716 }
6717
6718 if ( Node ) JSXOpeningElement.__proto__ = Node;
6719 JSXOpeningElement.prototype = Object.create( Node && Node.prototype );
6720 JSXOpeningElement.prototype.constructor = JSXOpeningElement;
6721
6722 JSXOpeningElement.prototype.transpile = function transpile ( code, transforms ) {
6723 var this$1 = this;
6724
6725 Node.prototype.transpile.call( this, code, transforms );
6726
6727 code.overwrite( this.start, this.name.start, ((this.program.jsx) + "( ") );
6728
6729 var html = this.name.type === 'JSXIdentifier' && this.name.name[0] === this.name.name[0].toLowerCase();
6730 if ( html ) code.prependRight( this.name.start, "'" );
6731
6732 var len = this.attributes.length;
6733 var c = this.name.end;
6734
6735 if ( len ) {
6736 var i;
6737
6738 var hasSpread = false;
6739 for ( i = 0; i < len; i += 1 ) {
6740 if ( this$1.attributes[i].type === 'JSXSpreadAttribute' ) {
6741 hasSpread = true;
6742 break;
6743 }
6744 }
6745
6746 c = this.attributes[0].end;
6747
6748 for ( i = 0; i < len; i += 1 ) {
6749 var attr = this$1.attributes[i];
6750
6751 if ( i > 0 ) {
6752 if ( attr.start === c )
6753 code.prependRight( c, ', ' );
6754 else
6755 code.overwrite( c, attr.start, ', ' );
6756 }
6757
6758 if ( hasSpread && attr.type !== 'JSXSpreadAttribute' ) {
6759 var lastAttr = this$1.attributes[ i - 1 ];
6760 var nextAttr = this$1.attributes[ i + 1 ];
6761
6762 if ( !lastAttr || lastAttr.type === 'JSXSpreadAttribute' ) {
6763 code.prependRight( attr.start, '{ ' );
6764 }
6765
6766 if ( !nextAttr || nextAttr.type === 'JSXSpreadAttribute' ) {
6767 code.appendLeft( attr.end, ' }' );
6768 }
6769 }
6770
6771 c = attr.end;
6772 }
6773
6774 var after;
6775 var before;
6776 if ( hasSpread ) {
6777 if ( len === 1 ) {
6778 before = html ? "'," : ',';
6779 } else {
6780 if (!this.program.options.objectAssign) {
6781 throw new CompileError$1( 'Mixed JSX attributes ending in spread requires specified objectAssign option with \'Object.assign\' or polyfill helper.', this );
6782 }
6783 before = html ? ("', " + (this.program.options.objectAssign) + "({},") : (", " + (this.program.options.objectAssign) + "({},");
6784 after = ')';
6785 }
6786 } else {
6787 before = html ? "', {" : ', {';
6788 after = ' }';
6789 }
6790
6791 code.prependRight( this.name.end, before );
6792
6793 if ( after ) {
6794 code.appendLeft( this.attributes[ len - 1 ].end, after );
6795 }
6796 } else {
6797 code.appendLeft( this.name.end, html ? "', null" : ", null" );
6798 c = this.name.end;
6799 }
6800
6801 if ( this.selfClosing ) {
6802 code.overwrite( c, this.end, this.attributes.length ? ")" : " )" );
6803 } else {
6804 code.remove( c, this.end );
6805 }
6806 };
6807
6808 return JSXOpeningElement;
6809}(Node$1));
6810
6811var JSXSpreadAttribute = (function (Node) {
6812 function JSXSpreadAttribute () {
6813 Node.apply(this, arguments);
6814 }
6815
6816 if ( Node ) JSXSpreadAttribute.__proto__ = Node;
6817 JSXSpreadAttribute.prototype = Object.create( Node && Node.prototype );
6818 JSXSpreadAttribute.prototype.constructor = JSXSpreadAttribute;
6819
6820 JSXSpreadAttribute.prototype.transpile = function transpile ( code, transforms ) {
6821 code.remove( this.start, this.argument.start );
6822 code.remove( this.argument.end, this.end );
6823
6824 Node.prototype.transpile.call( this, code, transforms );
6825 };
6826
6827 return JSXSpreadAttribute;
6828}(Node$1));
6829
6830var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6831
6832function commonjsRequire () {
6833 throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
6834}
6835
6836
6837
6838function createCommonjsModule(fn, module) {
6839 return module = { exports: {} }, fn(module, module.exports), module.exports;
6840}
6841
6842var regjsgen = createCommonjsModule(function (module, exports) {
6843/*!
6844 * regjsgen 0.3.0
6845 * Copyright 2014-2016 Benjamin Tan <https://demoneaux.github.io/>
6846 * Available under MIT license <https://github.com/demoneaux/regjsgen/blob/master/LICENSE>
6847 */
6848(function() {
6849 'use strict';
6850
6851 // Used to determine if values are of the language type `Object`.
6852 var objectTypes = {
6853 'function': true,
6854 'object': true
6855 };
6856
6857 // Used as a reference to the global object.
6858 var root = (objectTypes[typeof window] && window) || this;
6859
6860 // Detect free variable `exports`.
6861 var freeExports = objectTypes['object'] && exports;
6862
6863 // Detect free variable `module`.
6864 var freeModule = objectTypes['object'] && module && !module.nodeType && module;
6865
6866 // Detect free variable `global` from Node.js or Browserified code and use it as `root`.
6867 var freeGlobal = freeExports && freeModule && typeof commonjsGlobal == 'object' && commonjsGlobal;
6868 if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
6869 root = freeGlobal;
6870 }
6871
6872 // Used to check objects for own properties.
6873 var hasOwnProperty = Object.prototype.hasOwnProperty;
6874
6875 /*--------------------------------------------------------------------------*/
6876
6877 // Generates strings based on the given code points.
6878 // Based on https://mths.be/fromcodepoint v0.2.0 by @mathias.
6879 var stringFromCharCode = String.fromCharCode;
6880 var floor = Math.floor;
6881 function fromCodePoint() {
6882 var MAX_SIZE = 0x4000;
6883 var codeUnits = [];
6884 var highSurrogate;
6885 var lowSurrogate;
6886 var index = -1;
6887 var length = arguments.length;
6888 if (!length) {
6889 return '';
6890 }
6891 var result = '';
6892 while (++index < length) {
6893 var codePoint = Number(arguments[index]);
6894 if (
6895 !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
6896 codePoint < 0 || // not a valid Unicode code point
6897 codePoint > 0x10FFFF || // not a valid Unicode code point
6898 floor(codePoint) != codePoint // not an integer
6899 ) {
6900 throw RangeError('Invalid code point: ' + codePoint);
6901 }
6902 if (codePoint <= 0xFFFF) {
6903 // BMP code point
6904 codeUnits.push(codePoint);
6905 } else {
6906 // Astral code point; split in surrogate halves
6907 // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
6908 codePoint -= 0x10000;
6909 highSurrogate = (codePoint >> 10) + 0xD800;
6910 lowSurrogate = (codePoint % 0x400) + 0xDC00;
6911 codeUnits.push(highSurrogate, lowSurrogate);
6912 }
6913 if (index + 1 == length || codeUnits.length > MAX_SIZE) {
6914 result += stringFromCharCode.apply(null, codeUnits);
6915 codeUnits.length = 0;
6916 }
6917 }
6918 return result;
6919 }
6920
6921 /*--------------------------------------------------------------------------*/
6922
6923 // Ensures that nodes have the correct types.
6924 var assertTypeRegexMap = {};
6925 function assertType(type, expected) {
6926 if (expected.indexOf('|') == -1) {
6927 if (type == expected) {
6928 return;
6929 }
6930
6931 throw Error('Invalid node type: ' + type + '; expected type: ' + expected);
6932 }
6933
6934 expected = hasOwnProperty.call(assertTypeRegexMap, expected)
6935 ? assertTypeRegexMap[expected]
6936 : (assertTypeRegexMap[expected] = RegExp('^(?:' + expected + ')$'));
6937
6938 if (expected.test(type)) {
6939 return;
6940 }
6941
6942 throw Error('Invalid node type: ' + type + '; expected types: ' + expected);
6943 }
6944
6945 /*--------------------------------------------------------------------------*/
6946
6947 // Generates a regular expression string based on an AST.
6948 function generate(node) {
6949 var type = node.type;
6950
6951 if (hasOwnProperty.call(generators, type)) {
6952 return generators[type](node);
6953 }
6954
6955 throw Error('Invalid node type: ' + type);
6956 }
6957
6958 /*--------------------------------------------------------------------------*/
6959
6960 function generateAlternative(node) {
6961 assertType(node.type, 'alternative');
6962
6963 var terms = node.body,
6964 i = -1,
6965 length = terms.length,
6966 result = '';
6967
6968 while (++i < length) {
6969 result += generateTerm(terms[i]);
6970 }
6971
6972 return result;
6973 }
6974
6975 function generateAnchor(node) {
6976 assertType(node.type, 'anchor');
6977
6978 switch (node.kind) {
6979 case 'start':
6980 return '^';
6981 case 'end':
6982 return '$';
6983 case 'boundary':
6984 return '\\b';
6985 case 'not-boundary':
6986 return '\\B';
6987 default:
6988 throw Error('Invalid assertion');
6989 }
6990 }
6991
6992 function generateAtom(node) {
6993 assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
6994
6995 return generate(node);
6996 }
6997
6998 function generateCharacterClass(node) {
6999 assertType(node.type, 'characterClass');
7000
7001 var classRanges = node.body,
7002 i = -1,
7003 length = classRanges.length,
7004 result = '';
7005
7006 if (node.negative) {
7007 result += '^';
7008 }
7009
7010 while (++i < length) {
7011 result += generateClassAtom(classRanges[i]);
7012 }
7013
7014 return '[' + result + ']';
7015 }
7016
7017 function generateCharacterClassEscape(node) {
7018 assertType(node.type, 'characterClassEscape');
7019
7020 return '\\' + node.value;
7021 }
7022
7023 function generateUnicodePropertyEscape(node) {
7024 assertType(node.type, 'unicodePropertyEscape');
7025
7026 return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
7027 }
7028
7029 function generateCharacterClassRange(node) {
7030 assertType(node.type, 'characterClassRange');
7031
7032 var min = node.min,
7033 max = node.max;
7034
7035 if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
7036 throw Error('Invalid character class range');
7037 }
7038
7039 return generateClassAtom(min) + '-' + generateClassAtom(max);
7040 }
7041
7042 function generateClassAtom(node) {
7043 assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value');
7044
7045 return generate(node);
7046 }
7047
7048 function generateDisjunction(node) {
7049 assertType(node.type, 'disjunction');
7050
7051 var body = node.body,
7052 i = -1,
7053 length = body.length,
7054 result = '';
7055
7056 while (++i < length) {
7057 if (i != 0) {
7058 result += '|';
7059 }
7060 result += generate(body[i]);
7061 }
7062
7063 return result;
7064 }
7065
7066 function generateDot(node) {
7067 assertType(node.type, 'dot');
7068
7069 return '.';
7070 }
7071
7072 function generateGroup(node) {
7073 assertType(node.type, 'group');
7074
7075 var result = '';
7076
7077 switch (node.behavior) {
7078 case 'normal':
7079 break;
7080 case 'ignore':
7081 result += '?:';
7082 break;
7083 case 'lookahead':
7084 result += '?=';
7085 break;
7086 case 'negativeLookahead':
7087 result += '?!';
7088 break;
7089 default:
7090 throw Error('Invalid behaviour: ' + node.behaviour);
7091 }
7092
7093 var body = node.body,
7094 i = -1,
7095 length = body.length;
7096
7097 while (++i < length) {
7098 result += generate(body[i]);
7099 }
7100
7101 return '(' + result + ')';
7102 }
7103
7104 function generateQuantifier(node) {
7105 assertType(node.type, 'quantifier');
7106
7107 var quantifier = '',
7108 min = node.min,
7109 max = node.max;
7110
7111 if (max == null) {
7112 if (min == 0) {
7113 quantifier = '*';
7114 } else if (min == 1) {
7115 quantifier = '+';
7116 } else {
7117 quantifier = '{' + min + ',}';
7118 }
7119 } else if (min == max) {
7120 quantifier = '{' + min + '}';
7121 } else if (min == 0 && max == 1) {
7122 quantifier = '?';
7123 } else {
7124 quantifier = '{' + min + ',' + max + '}';
7125 }
7126
7127 if (!node.greedy) {
7128 quantifier += '?';
7129 }
7130
7131 return generateAtom(node.body[0]) + quantifier;
7132 }
7133
7134 function generateReference(node) {
7135 assertType(node.type, 'reference');
7136
7137 return '\\' + node.matchIndex;
7138 }
7139
7140 function generateTerm(node) {
7141 assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value');
7142
7143 return generate(node);
7144 }
7145
7146 function generateValue(node) {
7147 assertType(node.type, 'value');
7148
7149 var kind = node.kind,
7150 codePoint = node.codePoint;
7151
7152 switch (kind) {
7153 case 'controlLetter':
7154 return '\\c' + fromCodePoint(codePoint + 64);
7155 case 'hexadecimalEscape':
7156 return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
7157 case 'identifier':
7158 return '\\' + fromCodePoint(codePoint);
7159 case 'null':
7160 return '\\' + codePoint;
7161 case 'octal':
7162 return '\\' + codePoint.toString(8);
7163 case 'singleEscape':
7164 switch (codePoint) {
7165 case 0x0008:
7166 return '\\b';
7167 case 0x0009:
7168 return '\\t';
7169 case 0x000A:
7170 return '\\n';
7171 case 0x000B:
7172 return '\\v';
7173 case 0x000C:
7174 return '\\f';
7175 case 0x000D:
7176 return '\\r';
7177 default:
7178 throw Error('Invalid codepoint: ' + codePoint);
7179 }
7180 case 'symbol':
7181 return fromCodePoint(codePoint);
7182 case 'unicodeEscape':
7183 return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
7184 case 'unicodeCodePointEscape':
7185 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
7186 default:
7187 throw Error('Unsupported node kind: ' + kind);
7188 }
7189 }
7190
7191 /*--------------------------------------------------------------------------*/
7192
7193 // Used to generate strings for each node type.
7194 var generators = {
7195 'alternative': generateAlternative,
7196 'anchor': generateAnchor,
7197 'characterClass': generateCharacterClass,
7198 'characterClassEscape': generateCharacterClassEscape,
7199 'characterClassRange': generateCharacterClassRange,
7200 'unicodePropertyEscape': generateUnicodePropertyEscape,
7201 'disjunction': generateDisjunction,
7202 'dot': generateDot,
7203 'group': generateGroup,
7204 'quantifier': generateQuantifier,
7205 'reference': generateReference,
7206 'value': generateValue
7207 };
7208
7209 /*--------------------------------------------------------------------------*/
7210
7211 // Export regjsgen.
7212 // Some AMD build optimizers, like r.js, check for condition patterns like the following:
7213 if (typeof undefined == 'function' && typeof undefined.amd == 'object' && undefined.amd) {
7214 // Define as an anonymous module so it can be aliased through path mapping.
7215 undefined(function() {
7216 return {
7217 'generate': generate
7218 };
7219 });
7220 }
7221 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
7222 else if (freeExports && freeModule) {
7223 // Export for CommonJS support.
7224 freeExports.generate = generate;
7225 }
7226 else {
7227 // Export to the global object.
7228 root.regjsgen = {
7229 'generate': generate
7230 };
7231 }
7232}.call(commonjsGlobal));
7233});
7234
7235var parser = createCommonjsModule(function (module) {
7236// regjsparser
7237//
7238// ==================================================================
7239//
7240// See ECMA-262 Standard: 15.10.1
7241//
7242// NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the
7243// term "Anchor" is used.
7244//
7245// Pattern ::
7246// Disjunction
7247//
7248// Disjunction ::
7249// Alternative
7250// Alternative | Disjunction
7251//
7252// Alternative ::
7253// [empty]
7254// Alternative Term
7255//
7256// Term ::
7257// Anchor
7258// Atom
7259// Atom Quantifier
7260//
7261// Anchor ::
7262// ^
7263// $
7264// \ b
7265// \ B
7266// ( ? = Disjunction )
7267// ( ? ! Disjunction )
7268//
7269// Quantifier ::
7270// QuantifierPrefix
7271// QuantifierPrefix ?
7272//
7273// QuantifierPrefix ::
7274// *
7275// +
7276// ?
7277// { DecimalDigits }
7278// { DecimalDigits , }
7279// { DecimalDigits , DecimalDigits }
7280//
7281// Atom ::
7282// PatternCharacter
7283// .
7284// \ AtomEscape
7285// CharacterClass
7286// ( Disjunction )
7287// ( ? : Disjunction )
7288//
7289// PatternCharacter ::
7290// SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |
7291//
7292// AtomEscape ::
7293// DecimalEscape
7294// CharacterEscape
7295// CharacterClassEscape
7296//
7297// CharacterEscape[U] ::
7298// ControlEscape
7299// c ControlLetter
7300// HexEscapeSequence
7301// RegExpUnicodeEscapeSequence[?U] (ES6)
7302// IdentityEscape[?U]
7303//
7304// ControlEscape ::
7305// one of f n r t v
7306// ControlLetter ::
7307// one of
7308// 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
7309// 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
7310//
7311// IdentityEscape ::
7312// SourceCharacter but not IdentifierPart
7313// <ZWJ>
7314// <ZWNJ>
7315//
7316// DecimalEscape ::
7317// DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
7318//
7319// CharacterClassEscape ::
7320// one of d D s S w W
7321//
7322// CharacterClass ::
7323// [ [lookahead ∉ {^}] ClassRanges ]
7324// [ ^ ClassRanges ]
7325//
7326// ClassRanges ::
7327// [empty]
7328// NonemptyClassRanges
7329//
7330// NonemptyClassRanges ::
7331// ClassAtom
7332// ClassAtom NonemptyClassRangesNoDash
7333// ClassAtom - ClassAtom ClassRanges
7334//
7335// NonemptyClassRangesNoDash ::
7336// ClassAtom
7337// ClassAtomNoDash NonemptyClassRangesNoDash
7338// ClassAtomNoDash - ClassAtom ClassRanges
7339//
7340// ClassAtom ::
7341// -
7342// ClassAtomNoDash
7343//
7344// ClassAtomNoDash ::
7345// SourceCharacter but not one of \ or ] or -
7346// \ ClassEscape
7347//
7348// ClassEscape ::
7349// DecimalEscape
7350// b
7351// CharacterEscape
7352// CharacterClassEscape
7353
7354(function() {
7355
7356 function parse(str, flags, features) {
7357 if (!features) {
7358 features = {};
7359 }
7360 function addRaw(node) {
7361 node.raw = str.substring(node.range[0], node.range[1]);
7362 return node;
7363 }
7364
7365 function updateRawStart(node, start) {
7366 node.range[0] = start;
7367 return addRaw(node);
7368 }
7369
7370 function createAnchor(kind, rawLength) {
7371 return addRaw({
7372 type: 'anchor',
7373 kind: kind,
7374 range: [
7375 pos - rawLength,
7376 pos
7377 ]
7378 });
7379 }
7380
7381 function createValue(kind, codePoint, from, to) {
7382 return addRaw({
7383 type: 'value',
7384 kind: kind,
7385 codePoint: codePoint,
7386 range: [from, to]
7387 });
7388 }
7389
7390 function createEscaped(kind, codePoint, value, fromOffset) {
7391 fromOffset = fromOffset || 0;
7392 return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);
7393 }
7394
7395 function createCharacter(matches) {
7396 var _char = matches[0];
7397 var first = _char.charCodeAt(0);
7398 if (hasUnicodeFlag) {
7399 var second;
7400 if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
7401 second = lookahead().charCodeAt(0);
7402 if (second >= 0xDC00 && second <= 0xDFFF) {
7403 // Unicode surrogate pair
7404 pos++;
7405 return createValue(
7406 'symbol',
7407 (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,
7408 pos - 2, pos);
7409 }
7410 }
7411 }
7412 return createValue('symbol', first, pos - 1, pos);
7413 }
7414
7415 function createDisjunction(alternatives, from, to) {
7416 return addRaw({
7417 type: 'disjunction',
7418 body: alternatives,
7419 range: [
7420 from,
7421 to
7422 ]
7423 });
7424 }
7425
7426 function createDot() {
7427 return addRaw({
7428 type: 'dot',
7429 range: [
7430 pos - 1,
7431 pos
7432 ]
7433 });
7434 }
7435
7436 function createCharacterClassEscape(value) {
7437 return addRaw({
7438 type: 'characterClassEscape',
7439 value: value,
7440 range: [
7441 pos - 2,
7442 pos
7443 ]
7444 });
7445 }
7446
7447 function createReference(matchIndex) {
7448 return addRaw({
7449 type: 'reference',
7450 matchIndex: parseInt(matchIndex, 10),
7451 range: [
7452 pos - 1 - matchIndex.length,
7453 pos
7454 ]
7455 });
7456 }
7457
7458 function createGroup(behavior, disjunction, from, to) {
7459 return addRaw({
7460 type: 'group',
7461 behavior: behavior,
7462 body: disjunction,
7463 range: [
7464 from,
7465 to
7466 ]
7467 });
7468 }
7469
7470 function createQuantifier(min, max, from, to) {
7471 if (to == null) {
7472 from = pos - 1;
7473 to = pos;
7474 }
7475
7476 return addRaw({
7477 type: 'quantifier',
7478 min: min,
7479 max: max,
7480 greedy: true,
7481 body: null, // set later on
7482 range: [
7483 from,
7484 to
7485 ]
7486 });
7487 }
7488
7489 function createAlternative(terms, from, to) {
7490 return addRaw({
7491 type: 'alternative',
7492 body: terms,
7493 range: [
7494 from,
7495 to
7496 ]
7497 });
7498 }
7499
7500 function createCharacterClass(classRanges, negative, from, to) {
7501 return addRaw({
7502 type: 'characterClass',
7503 body: classRanges,
7504 negative: negative,
7505 range: [
7506 from,
7507 to
7508 ]
7509 });
7510 }
7511
7512 function createClassRange(min, max, from, to) {
7513 // See 15.10.2.15:
7514 if (min.codePoint > max.codePoint) {
7515 bail('invalid range in character class', min.raw + '-' + max.raw, from, to);
7516 }
7517
7518 return addRaw({
7519 type: 'characterClassRange',
7520 min: min,
7521 max: max,
7522 range: [
7523 from,
7524 to
7525 ]
7526 });
7527 }
7528
7529 function flattenBody(body) {
7530 if (body.type === 'alternative') {
7531 return body.body;
7532 } else {
7533 return [body];
7534 }
7535 }
7536
7537 function incr(amount) {
7538 amount = (amount || 1);
7539 var res = str.substring(pos, pos + amount);
7540 pos += (amount || 1);
7541 return res;
7542 }
7543
7544 function skip(value) {
7545 if (!match(value)) {
7546 bail('character', value);
7547 }
7548 }
7549
7550 function match(value) {
7551 if (str.indexOf(value, pos) === pos) {
7552 return incr(value.length);
7553 }
7554 }
7555
7556 function lookahead() {
7557 return str[pos];
7558 }
7559
7560 function current(value) {
7561 return str.indexOf(value, pos) === pos;
7562 }
7563
7564 function next(value) {
7565 return str[pos + 1] === value;
7566 }
7567
7568 function matchReg(regExp) {
7569 var subStr = str.substring(pos);
7570 var res = subStr.match(regExp);
7571 if (res) {
7572 res.range = [];
7573 res.range[0] = pos;
7574 incr(res[0].length);
7575 res.range[1] = pos;
7576 }
7577 return res;
7578 }
7579
7580 function parseDisjunction() {
7581 // Disjunction ::
7582 // Alternative
7583 // Alternative | Disjunction
7584 var res = [], from = pos;
7585 res.push(parseAlternative());
7586
7587 while (match('|')) {
7588 res.push(parseAlternative());
7589 }
7590
7591 if (res.length === 1) {
7592 return res[0];
7593 }
7594
7595 return createDisjunction(res, from, pos);
7596 }
7597
7598 function parseAlternative() {
7599 var res = [], from = pos;
7600 var term;
7601
7602 // Alternative ::
7603 // [empty]
7604 // Alternative Term
7605 while (term = parseTerm()) {
7606 res.push(term);
7607 }
7608
7609 if (res.length === 1) {
7610 return res[0];
7611 }
7612
7613 return createAlternative(res, from, pos);
7614 }
7615
7616 function parseTerm() {
7617 // Term ::
7618 // Anchor
7619 // Atom
7620 // Atom Quantifier
7621
7622 if (pos >= str.length || current('|') || current(')')) {
7623 return null; /* Means: The term is empty */
7624 }
7625
7626 var anchor = parseAnchor();
7627
7628 if (anchor) {
7629 return anchor;
7630 }
7631
7632 var atom = parseAtom();
7633 if (!atom) {
7634 bail('Expected atom');
7635 }
7636 var quantifier = parseQuantifier() || false;
7637 if (quantifier) {
7638 quantifier.body = flattenBody(atom);
7639 // The quantifier contains the atom. Therefore, the beginning of the
7640 // quantifier range is given by the beginning of the atom.
7641 updateRawStart(quantifier, atom.range[0]);
7642 return quantifier;
7643 }
7644 return atom;
7645 }
7646
7647 function parseGroup(matchA, typeA, matchB, typeB) {
7648 var type = null, from = pos;
7649
7650 if (match(matchA)) {
7651 type = typeA;
7652 } else if (match(matchB)) {
7653 type = typeB;
7654 } else {
7655 return false;
7656 }
7657
7658 var body = parseDisjunction();
7659 if (!body) {
7660 bail('Expected disjunction');
7661 }
7662 skip(')');
7663 var group = createGroup(type, flattenBody(body), from, pos);
7664
7665 if (type == 'normal') {
7666 // Keep track of the number of closed groups. This is required for
7667 // parseDecimalEscape(). In case the string is parsed a second time the
7668 // value already holds the total count and no incrementation is required.
7669 if (firstIteration) {
7670 closedCaptureCounter++;
7671 }
7672 }
7673 return group;
7674 }
7675
7676 function parseAnchor() {
7677 // Anchor ::
7678 // ^
7679 // $
7680 // \ b
7681 // \ B
7682 // ( ? = Disjunction )
7683 // ( ? ! Disjunction )
7684 if (match('^')) {
7685 return createAnchor('start', 1 /* rawLength */);
7686 } else if (match('$')) {
7687 return createAnchor('end', 1 /* rawLength */);
7688 } else if (match('\\b')) {
7689 return createAnchor('boundary', 2 /* rawLength */);
7690 } else if (match('\\B')) {
7691 return createAnchor('not-boundary', 2 /* rawLength */);
7692 } else {
7693 return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');
7694 }
7695 }
7696
7697 function parseQuantifier() {
7698 // Quantifier ::
7699 // QuantifierPrefix
7700 // QuantifierPrefix ?
7701 //
7702 // QuantifierPrefix ::
7703 // *
7704 // +
7705 // ?
7706 // { DecimalDigits }
7707 // { DecimalDigits , }
7708 // { DecimalDigits , DecimalDigits }
7709
7710 var res, from = pos;
7711 var quantifier;
7712 var min, max;
7713
7714 if (match('*')) {
7715 quantifier = createQuantifier(0);
7716 }
7717 else if (match('+')) {
7718 quantifier = createQuantifier(1);
7719 }
7720 else if (match('?')) {
7721 quantifier = createQuantifier(0, 1);
7722 }
7723 else if (res = matchReg(/^\{([0-9]+)\}/)) {
7724 min = parseInt(res[1], 10);
7725 quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
7726 }
7727 else if (res = matchReg(/^\{([0-9]+),\}/)) {
7728 min = parseInt(res[1], 10);
7729 quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
7730 }
7731 else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
7732 min = parseInt(res[1], 10);
7733 max = parseInt(res[2], 10);
7734 if (min > max) {
7735 bail('numbers out of order in {} quantifier', '', from, pos);
7736 }
7737 quantifier = createQuantifier(min, max, res.range[0], res.range[1]);
7738 }
7739
7740 if (quantifier) {
7741 if (match('?')) {
7742 quantifier.greedy = false;
7743 quantifier.range[1] += 1;
7744 }
7745 }
7746
7747 return quantifier;
7748 }
7749
7750 function parseAtom() {
7751 // Atom ::
7752 // PatternCharacter
7753 // .
7754 // \ AtomEscape
7755 // CharacterClass
7756 // ( Disjunction )
7757 // ( ? : Disjunction )
7758
7759 var res;
7760
7761 // jviereck: allow ']', '}' here as well to be compatible with browser's
7762 // implementations: ']'.match(/]/);
7763 // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) {
7764 if (res = matchReg(/^[^^$\\.*+?(){[|]/)) {
7765 // PatternCharacter
7766 return createCharacter(res);
7767 }
7768 else if (match('.')) {
7769 // .
7770 return createDot();
7771 }
7772 else if (match('\\')) {
7773 // \ AtomEscape
7774 res = parseAtomEscape();
7775 if (!res) {
7776 bail('atomEscape');
7777 }
7778 return res;
7779 }
7780 else if (res = parseCharacterClass()) {
7781 return res;
7782 }
7783 else {
7784 // ( Disjunction )
7785 // ( ? : Disjunction )
7786 return parseGroup('(?:', 'ignore', '(', 'normal');
7787 }
7788 }
7789
7790 function parseUnicodeSurrogatePairEscape(firstEscape) {
7791 if (hasUnicodeFlag) {
7792 var first, second;
7793 if (firstEscape.kind == 'unicodeEscape' &&
7794 (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&
7795 current('\\') && next('u') ) {
7796 var prevPos = pos;
7797 pos++;
7798 var secondEscape = parseClassEscape();
7799 if (secondEscape.kind == 'unicodeEscape' &&
7800 (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {
7801 // Unicode surrogate pair
7802 firstEscape.range[1] = secondEscape.range[1];
7803 firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
7804 firstEscape.type = 'value';
7805 firstEscape.kind = 'unicodeCodePointEscape';
7806 addRaw(firstEscape);
7807 }
7808 else {
7809 pos = prevPos;
7810 }
7811 }
7812 }
7813 return firstEscape;
7814 }
7815
7816 function parseClassEscape() {
7817 return parseAtomEscape(true);
7818 }
7819
7820 function parseAtomEscape(insideCharacterClass) {
7821 // AtomEscape ::
7822 // DecimalEscape
7823 // CharacterEscape
7824 // CharacterClassEscape
7825
7826 var res, from = pos;
7827
7828 res = parseDecimalEscape();
7829 if (res) {
7830 return res;
7831 }
7832
7833 // For ClassEscape
7834 if (insideCharacterClass) {
7835 if (match('b')) {
7836 // 15.10.2.19
7837 // The production ClassEscape :: b evaluates by returning the
7838 // CharSet containing the one character <BS> (Unicode value 0008).
7839 return createEscaped('singleEscape', 0x0008, '\\b');
7840 } else if (match('B')) {
7841 bail('\\B not possible inside of CharacterClass', '', from);
7842 }
7843 }
7844
7845 res = parseCharacterEscape();
7846
7847 return res;
7848 }
7849
7850
7851 function parseDecimalEscape() {
7852 // DecimalEscape ::
7853 // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
7854 // CharacterClassEscape :: one of d D s S w W
7855
7856 var res, match;
7857
7858 if (res = matchReg(/^(?!0)\d+/)) {
7859 match = res[0];
7860 var refIdx = parseInt(res[0], 10);
7861 if (refIdx <= closedCaptureCounter) {
7862 // If the number is smaller than the normal-groups found so
7863 // far, then it is a reference...
7864 return createReference(res[0]);
7865 } else {
7866 // ... otherwise it needs to be interpreted as a octal (if the
7867 // number is in an octal format). If it is NOT octal format,
7868 // then the slash is ignored and the number is matched later
7869 // as normal characters.
7870
7871 // Recall the negative decision to decide if the input must be parsed
7872 // a second time with the total normal-groups.
7873 backrefDenied.push(refIdx);
7874
7875 // Reset the position again, as maybe only parts of the previous
7876 // matched numbers are actual octal numbers. E.g. in '019' only
7877 // the '01' should be matched.
7878 incr(-res[0].length);
7879 if (res = matchReg(/^[0-7]{1,3}/)) {
7880 return createEscaped('octal', parseInt(res[0], 8), res[0], 1);
7881 } else {
7882 // If we end up here, we have a case like /\91/. Then the
7883 // first slash is to be ignored and the 9 & 1 to be treated
7884 // like ordinary characters. Create a character for the
7885 // first number only here - other number-characters
7886 // (if available) will be matched later.
7887 res = createCharacter(matchReg(/^[89]/));
7888 return updateRawStart(res, res.range[0] - 1);
7889 }
7890 }
7891 }
7892 // Only allow octal numbers in the following. All matched numbers start
7893 // with a zero (if the do not, the previous if-branch is executed).
7894 // If the number is not octal format and starts with zero (e.g. `091`)
7895 // then only the zeros `0` is treated here and the `91` are ordinary
7896 // characters.
7897 // Example:
7898 // /\091/.exec('\091')[0].length === 3
7899 else if (res = matchReg(/^[0-7]{1,3}/)) {
7900 match = res[0];
7901 if (/^0{1,3}$/.test(match)) {
7902 // If they are all zeros, then only take the first one.
7903 return createEscaped('null', 0x0000, '0', match.length + 1);
7904 } else {
7905 return createEscaped('octal', parseInt(match, 8), match, 1);
7906 }
7907 } else if (res = matchReg(/^[dDsSwW]/)) {
7908 return createCharacterClassEscape(res[0]);
7909 }
7910 return false;
7911 }
7912
7913 function parseCharacterEscape() {
7914 // CharacterEscape ::
7915 // ControlEscape
7916 // c ControlLetter
7917 // HexEscapeSequence
7918 // UnicodeEscapeSequence
7919 // IdentityEscape
7920
7921 var res;
7922 if (res = matchReg(/^[fnrtv]/)) {
7923 // ControlEscape
7924 var codePoint = 0;
7925 switch (res[0]) {
7926 case 't': codePoint = 0x009; break;
7927 case 'n': codePoint = 0x00A; break;
7928 case 'v': codePoint = 0x00B; break;
7929 case 'f': codePoint = 0x00C; break;
7930 case 'r': codePoint = 0x00D; break;
7931 }
7932 return createEscaped('singleEscape', codePoint, '\\' + res[0]);
7933 } else if (res = matchReg(/^c([a-zA-Z])/)) {
7934 // c ControlLetter
7935 return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);
7936 } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) {
7937 // HexEscapeSequence
7938 return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2);
7939 } else if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {
7940 // UnicodeEscapeSequence
7941 return parseUnicodeSurrogatePairEscape(
7942 createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2)
7943 );
7944 } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {
7945 // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)
7946 return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);
7947 } else if (features.unicodePropertyEscape && hasUnicodeFlag && (res = matchReg(/^([pP])\{([^\}]+)\}/))) {
7948 // https://github.com/jviereck/regjsparser/issues/77
7949 return addRaw({
7950 type: 'unicodePropertyEscape',
7951 negative: res[1] === 'P',
7952 value: res[2],
7953 range: [res.range[0] - 1, res.range[1]],
7954 raw: res[0]
7955 });
7956 } else {
7957 // IdentityEscape
7958 return parseIdentityEscape();
7959 }
7960 }
7961
7962 // Taken from the Esprima parser.
7963 function isIdentifierPart(ch) {
7964 // Generated by `tools/generate-identifier-regex.js`.
7965 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]');
7966
7967 return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
7968 (ch >= 65 && ch <= 90) || // A..Z
7969 (ch >= 97 && ch <= 122) || // a..z
7970 (ch >= 48 && ch <= 57) || // 0..9
7971 (ch === 92) || // \ (backslash)
7972 ((ch >= 0x80) && NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
7973 }
7974
7975 function parseIdentityEscape() {
7976 // IdentityEscape ::
7977 // SourceCharacter but not IdentifierPart
7978 // <ZWJ>
7979 // <ZWNJ>
7980
7981 var ZWJ = '\u200C';
7982 var ZWNJ = '\u200D';
7983
7984 var tmp;
7985
7986 if (!isIdentifierPart(lookahead())) {
7987 tmp = incr();
7988 return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1);
7989 }
7990
7991 if (match(ZWJ)) {
7992 // <ZWJ>
7993 return createEscaped('identifier', 0x200C, ZWJ);
7994 } else if (match(ZWNJ)) {
7995 // <ZWNJ>
7996 return createEscaped('identifier', 0x200D, ZWNJ);
7997 }
7998
7999 return null;
8000 }
8001
8002 function parseCharacterClass() {
8003 // CharacterClass ::
8004 // [ [lookahead ∉ {^}] ClassRanges ]
8005 // [ ^ ClassRanges ]
8006
8007 var res, from = pos;
8008 if (res = matchReg(/^\[\^/)) {
8009 res = parseClassRanges();
8010 skip(']');
8011 return createCharacterClass(res, true, from, pos);
8012 } else if (match('[')) {
8013 res = parseClassRanges();
8014 skip(']');
8015 return createCharacterClass(res, false, from, pos);
8016 }
8017
8018 return null;
8019 }
8020
8021 function parseClassRanges() {
8022 // ClassRanges ::
8023 // [empty]
8024 // NonemptyClassRanges
8025
8026 var res;
8027 if (current(']')) {
8028 // Empty array means nothing insinde of the ClassRange.
8029 return [];
8030 } else {
8031 res = parseNonemptyClassRanges();
8032 if (!res) {
8033 bail('nonEmptyClassRanges');
8034 }
8035 return res;
8036 }
8037 }
8038
8039 function parseHelperClassRanges(atom) {
8040 var from, to, res;
8041 if (current('-') && !next(']')) {
8042 // ClassAtom - ClassAtom ClassRanges
8043 skip('-');
8044
8045 res = parseClassAtom();
8046 if (!res) {
8047 bail('classAtom');
8048 }
8049 to = pos;
8050 var classRanges = parseClassRanges();
8051 if (!classRanges) {
8052 bail('classRanges');
8053 }
8054 from = atom.range[0];
8055 if (classRanges.type === 'empty') {
8056 return [createClassRange(atom, res, from, to)];
8057 }
8058 return [createClassRange(atom, res, from, to)].concat(classRanges);
8059 }
8060
8061 res = parseNonemptyClassRangesNoDash();
8062 if (!res) {
8063 bail('nonEmptyClassRangesNoDash');
8064 }
8065
8066 return [atom].concat(res);
8067 }
8068
8069 function parseNonemptyClassRanges() {
8070 // NonemptyClassRanges ::
8071 // ClassAtom
8072 // ClassAtom NonemptyClassRangesNoDash
8073 // ClassAtom - ClassAtom ClassRanges
8074
8075 var atom = parseClassAtom();
8076 if (!atom) {
8077 bail('classAtom');
8078 }
8079
8080 if (current(']')) {
8081 // ClassAtom
8082 return [atom];
8083 }
8084
8085 // ClassAtom NonemptyClassRangesNoDash
8086 // ClassAtom - ClassAtom ClassRanges
8087 return parseHelperClassRanges(atom);
8088 }
8089
8090 function parseNonemptyClassRangesNoDash() {
8091 // NonemptyClassRangesNoDash ::
8092 // ClassAtom
8093 // ClassAtomNoDash NonemptyClassRangesNoDash
8094 // ClassAtomNoDash - ClassAtom ClassRanges
8095
8096 var res = parseClassAtom();
8097 if (!res) {
8098 bail('classAtom');
8099 }
8100 if (current(']')) {
8101 // ClassAtom
8102 return res;
8103 }
8104
8105 // ClassAtomNoDash NonemptyClassRangesNoDash
8106 // ClassAtomNoDash - ClassAtom ClassRanges
8107 return parseHelperClassRanges(res);
8108 }
8109
8110 function parseClassAtom() {
8111 // ClassAtom ::
8112 // -
8113 // ClassAtomNoDash
8114 if (match('-')) {
8115 return createCharacter('-');
8116 } else {
8117 return parseClassAtomNoDash();
8118 }
8119 }
8120
8121 function parseClassAtomNoDash() {
8122 // ClassAtomNoDash ::
8123 // SourceCharacter but not one of \ or ] or -
8124 // \ ClassEscape
8125
8126 var res;
8127 if (res = matchReg(/^[^\\\]-]/)) {
8128 return createCharacter(res[0]);
8129 } else if (match('\\')) {
8130 res = parseClassEscape();
8131 if (!res) {
8132 bail('classEscape');
8133 }
8134
8135 return parseUnicodeSurrogatePairEscape(res);
8136 }
8137 }
8138
8139 function bail(message, details, from, to) {
8140 from = from == null ? pos : from;
8141 to = to == null ? from : to;
8142
8143 var contextStart = Math.max(0, from - 10);
8144 var contextEnd = Math.min(to + 10, str.length);
8145
8146 // Output a bit of context and a line pointing to where our error is.
8147 //
8148 // We are assuming that there are no actual newlines in the content as this is a regular expression.
8149 var context = ' ' + str.substring(contextStart, contextEnd);
8150 var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^';
8151
8152 throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer);
8153 }
8154
8155 var backrefDenied = [];
8156 var closedCaptureCounter = 0;
8157 var firstIteration = true;
8158 var hasUnicodeFlag = (flags || "").indexOf("u") !== -1;
8159 var pos = 0;
8160
8161 // Convert the input to a string and treat the empty string special.
8162 str = String(str);
8163 if (str === '') {
8164 str = '(?:)';
8165 }
8166
8167 var result = parseDisjunction();
8168
8169 if (result.range[1] !== str.length) {
8170 bail('Could not parse entire input - got stuck', '', result.range[1]);
8171 }
8172
8173 // The spec requires to interpret the `\2` in `/\2()()/` as backreference.
8174 // As the parser collects the number of capture groups as the string is
8175 // parsed it is impossible to make these decisions at the point when the
8176 // `\2` is handled. In case the local decision turns out to be wrong after
8177 // the parsing has finished, the input string is parsed a second time with
8178 // the total number of capture groups set.
8179 //
8180 // SEE: https://github.com/jviereck/regjsparser/issues/70
8181 for (var i = 0; i < backrefDenied.length; i++) {
8182 if (backrefDenied[i] <= closedCaptureCounter) {
8183 // Parse the input a second time.
8184 pos = 0;
8185 firstIteration = false;
8186 return parseDisjunction();
8187 }
8188 }
8189
8190 return result;
8191 }
8192
8193 var regjsparser = {
8194 parse: parse
8195 };
8196
8197 if ('object' !== 'undefined' && module.exports) {
8198 module.exports = regjsparser;
8199 } else {
8200 window.regjsparser = regjsparser;
8201 }
8202
8203}());
8204});
8205
8206var regenerate = createCommonjsModule(function (module, exports) {
8207/*! https://mths.be/regenerate v1.3.3 by @mathias | MIT license */
8208(function(root) {
8209
8210 // Detect free variables `exports`.
8211 var freeExports = 'object' == 'object' && exports;
8212
8213 // Detect free variable `module`.
8214 var freeModule = 'object' == 'object' && module &&
8215 module.exports == freeExports && module;
8216
8217 // Detect free variable `global`, from Node.js/io.js or Browserified code,
8218 // and use it as `root`.
8219 var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
8220 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
8221 root = freeGlobal;
8222 }
8223
8224 /*--------------------------------------------------------------------------*/
8225
8226 var ERRORS = {
8227 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
8228 'to the `start` value.',
8229 'codePointRange': 'Invalid code point value. Code points range from ' +
8230 'U+000000 to U+10FFFF.'
8231 };
8232
8233 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
8234 var HIGH_SURROGATE_MIN = 0xD800;
8235 var HIGH_SURROGATE_MAX = 0xDBFF;
8236 var LOW_SURROGATE_MIN = 0xDC00;
8237 var LOW_SURROGATE_MAX = 0xDFFF;
8238
8239 // In Regenerate output, `\0` is never preceded by `\` because we sort by
8240 // code point value, so let’s keep this regular expression simple.
8241 var regexNull = /\\x00([^0123456789]|$)/g;
8242
8243 var object = {};
8244 var hasOwnProperty = object.hasOwnProperty;
8245 var extend = function(destination, source) {
8246 var key;
8247 for (key in source) {
8248 if (hasOwnProperty.call(source, key)) {
8249 destination[key] = source[key];
8250 }
8251 }
8252 return destination;
8253 };
8254
8255 var forEach = function(array, callback) {
8256 var index = -1;
8257 var length = array.length;
8258 while (++index < length) {
8259 callback(array[index], index);
8260 }
8261 };
8262
8263 var toString = object.toString;
8264 var isArray = function(value) {
8265 return toString.call(value) == '[object Array]';
8266 };
8267 var isNumber = function(value) {
8268 return typeof value == 'number' ||
8269 toString.call(value) == '[object Number]';
8270 };
8271
8272 // This assumes that `number` is a positive integer that `toString()`s nicely
8273 // (which is the case for all code point values).
8274 var zeroes = '0000';
8275 var pad = function(number, totalCharacters) {
8276 var string = String(number);
8277 return string.length < totalCharacters
8278 ? (zeroes + string).slice(-totalCharacters)
8279 : string;
8280 };
8281
8282 var hex = function(number) {
8283 return Number(number).toString(16).toUpperCase();
8284 };
8285
8286 var slice = [].slice;
8287
8288 /*--------------------------------------------------------------------------*/
8289
8290 var dataFromCodePoints = function(codePoints) {
8291 var index = -1;
8292 var length = codePoints.length;
8293 var max = length - 1;
8294 var result = [];
8295 var isStart = true;
8296 var tmp;
8297 var previous = 0;
8298 while (++index < length) {
8299 tmp = codePoints[index];
8300 if (isStart) {
8301 result.push(tmp);
8302 previous = tmp;
8303 isStart = false;
8304 } else {
8305 if (tmp == previous + 1) {
8306 if (index != max) {
8307 previous = tmp;
8308 continue;
8309 } else {
8310 isStart = true;
8311 result.push(tmp + 1);
8312 }
8313 } else {
8314 // End the previous range and start a new one.
8315 result.push(previous + 1, tmp);
8316 previous = tmp;
8317 }
8318 }
8319 }
8320 if (!isStart) {
8321 result.push(tmp + 1);
8322 }
8323 return result;
8324 };
8325
8326 var dataRemove = function(data, codePoint) {
8327 // Iterate over the data per `(start, end)` pair.
8328 var index = 0;
8329 var start;
8330 var end;
8331 var length = data.length;
8332 while (index < length) {
8333 start = data[index];
8334 end = data[index + 1];
8335 if (codePoint >= start && codePoint < end) {
8336 // Modify this pair.
8337 if (codePoint == start) {
8338 if (end == start + 1) {
8339 // Just remove `start` and `end`.
8340 data.splice(index, 2);
8341 return data;
8342 } else {
8343 // Just replace `start` with a new value.
8344 data[index] = codePoint + 1;
8345 return data;
8346 }
8347 } else if (codePoint == end - 1) {
8348 // Just replace `end` with a new value.
8349 data[index + 1] = codePoint;
8350 return data;
8351 } else {
8352 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
8353 data.splice(index, 2, start, codePoint, codePoint + 1, end);
8354 return data;
8355 }
8356 }
8357 index += 2;
8358 }
8359 return data;
8360 };
8361
8362 var dataRemoveRange = function(data, rangeStart, rangeEnd) {
8363 if (rangeEnd < rangeStart) {
8364 throw Error(ERRORS.rangeOrder);
8365 }
8366 // Iterate over the data per `(start, end)` pair.
8367 var index = 0;
8368 var start;
8369 var end;
8370 while (index < data.length) {
8371 start = data[index];
8372 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8373
8374 // Exit as soon as no more matching pairs can be found.
8375 if (start > rangeEnd) {
8376 return data;
8377 }
8378
8379 // Check if this range pair is equal to, or forms a subset of, the range
8380 // to be removed.
8381 // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
8382 // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
8383 if (rangeStart <= start && rangeEnd >= end) {
8384 // Remove this pair.
8385 data.splice(index, 2);
8386 continue;
8387 }
8388
8389 // Check if both `rangeStart` and `rangeEnd` are within the bounds of
8390 // this pair.
8391 // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
8392 if (rangeStart >= start && rangeEnd < end) {
8393 if (rangeStart == start) {
8394 // Replace `[start, end]` with `[startB, endB]`.
8395 data[index] = rangeEnd + 1;
8396 data[index + 1] = end + 1;
8397 return data;
8398 }
8399 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
8400 data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
8401 return data;
8402 }
8403
8404 // Check if only `rangeStart` is within the bounds of this pair.
8405 // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
8406 if (rangeStart >= start && rangeStart <= end) {
8407 // Replace `end` with `rangeStart`.
8408 data[index + 1] = rangeStart;
8409 // Note: we cannot `return` just yet, in case any following pairs still
8410 // contain matching code points.
8411 // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
8412 // → `[0, 4, 21, 31]`.
8413 }
8414
8415 // Check if only `rangeEnd` is within the bounds of this pair.
8416 // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
8417 else if (rangeEnd >= start && rangeEnd <= end) {
8418 // Just replace `start`.
8419 data[index] = rangeEnd + 1;
8420 return data;
8421 }
8422
8423 index += 2;
8424 }
8425 return data;
8426 };
8427
8428 var dataAdd = function(data, codePoint) {
8429 // Iterate over the data per `(start, end)` pair.
8430 var index = 0;
8431 var start;
8432 var end;
8433 var lastIndex = null;
8434 var length = data.length;
8435 if (codePoint < 0x0 || codePoint > 0x10FFFF) {
8436 throw RangeError(ERRORS.codePointRange);
8437 }
8438 while (index < length) {
8439 start = data[index];
8440 end = data[index + 1];
8441
8442 // Check if the code point is already in the set.
8443 if (codePoint >= start && codePoint < end) {
8444 return data;
8445 }
8446
8447 if (codePoint == start - 1) {
8448 // Just replace `start` with a new value.
8449 data[index] = codePoint;
8450 return data;
8451 }
8452
8453 // At this point, if `start` is `greater` than `codePoint`, insert a new
8454 // `[start, end]` pair before the current pair, or after the current pair
8455 // if there is a known `lastIndex`.
8456 if (start > codePoint) {
8457 data.splice(
8458 lastIndex != null ? lastIndex + 2 : 0,
8459 0,
8460 codePoint,
8461 codePoint + 1
8462 );
8463 return data;
8464 }
8465
8466 if (codePoint == end) {
8467 // Check if adding this code point causes two separate ranges to become
8468 // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
8469 if (codePoint + 1 == data[index + 2]) {
8470 data.splice(index, 4, start, data[index + 3]);
8471 return data;
8472 }
8473 // Else, just replace `end` with a new value.
8474 data[index + 1] = codePoint + 1;
8475 return data;
8476 }
8477 lastIndex = index;
8478 index += 2;
8479 }
8480 // The loop has finished; add the new pair to the end of the data set.
8481 data.push(codePoint, codePoint + 1);
8482 return data;
8483 };
8484
8485 var dataAddData = function(dataA, dataB) {
8486 // Iterate over the data per `(start, end)` pair.
8487 var index = 0;
8488 var start;
8489 var end;
8490 var data = dataA.slice();
8491 var length = dataB.length;
8492 while (index < length) {
8493 start = dataB[index];
8494 end = dataB[index + 1] - 1;
8495 if (start == end) {
8496 data = dataAdd(data, start);
8497 } else {
8498 data = dataAddRange(data, start, end);
8499 }
8500 index += 2;
8501 }
8502 return data;
8503 };
8504
8505 var dataRemoveData = function(dataA, dataB) {
8506 // Iterate over the data per `(start, end)` pair.
8507 var index = 0;
8508 var start;
8509 var end;
8510 var data = dataA.slice();
8511 var length = dataB.length;
8512 while (index < length) {
8513 start = dataB[index];
8514 end = dataB[index + 1] - 1;
8515 if (start == end) {
8516 data = dataRemove(data, start);
8517 } else {
8518 data = dataRemoveRange(data, start, end);
8519 }
8520 index += 2;
8521 }
8522 return data;
8523 };
8524
8525 var dataAddRange = function(data, rangeStart, rangeEnd) {
8526 if (rangeEnd < rangeStart) {
8527 throw Error(ERRORS.rangeOrder);
8528 }
8529 if (
8530 rangeStart < 0x0 || rangeStart > 0x10FFFF ||
8531 rangeEnd < 0x0 || rangeEnd > 0x10FFFF
8532 ) {
8533 throw RangeError(ERRORS.codePointRange);
8534 }
8535 // Iterate over the data per `(start, end)` pair.
8536 var index = 0;
8537 var start;
8538 var end;
8539 var added = false;
8540 var length = data.length;
8541 while (index < length) {
8542 start = data[index];
8543 end = data[index + 1];
8544
8545 if (added) {
8546 // The range has already been added to the set; at this point, we just
8547 // need to get rid of the following ranges in case they overlap.
8548
8549 // Check if this range can be combined with the previous range.
8550 if (start == rangeEnd + 1) {
8551 data.splice(index - 1, 2);
8552 return data;
8553 }
8554
8555 // Exit as soon as no more possibly overlapping pairs can be found.
8556 if (start > rangeEnd) {
8557 return data;
8558 }
8559
8560 // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
8561 // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
8562 // `0,16` range that was previously added.
8563 if (start >= rangeStart && start <= rangeEnd) {
8564 // `start` lies within the range that was previously added.
8565
8566 if (end > rangeStart && end - 1 <= rangeEnd) {
8567 // `end` lies within the range that was previously added as well,
8568 // so remove this pair.
8569 data.splice(index, 2);
8570 index -= 2;
8571 // Note: we cannot `return` just yet, as there may still be other
8572 // overlapping pairs.
8573 } else {
8574 // `start` lies within the range that was previously added, but
8575 // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
8576 // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
8577 // Remove the previously added `end` and the current `start`.
8578 data.splice(index - 1, 2);
8579 index -= 2;
8580 }
8581
8582 // Note: we cannot return yet.
8583 }
8584
8585 }
8586
8587 else if (start == rangeEnd + 1) {
8588 data[index] = rangeStart;
8589 return data;
8590 }
8591
8592 // Check if a new pair must be inserted *before* the current one.
8593 else if (start > rangeEnd) {
8594 data.splice(index, 0, rangeStart, rangeEnd + 1);
8595 return data;
8596 }
8597
8598 else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
8599 // The new range lies entirely within an existing range pair. No action
8600 // needed.
8601 return data;
8602 }
8603
8604 else if (
8605 // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
8606 (rangeStart >= start && rangeStart < end) ||
8607 // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
8608 end == rangeStart
8609 ) {
8610 // Replace `end` with the new value.
8611 data[index + 1] = rangeEnd + 1;
8612 // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
8613 // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
8614 added = true;
8615 // Note: we cannot `return` just yet.
8616 }
8617
8618 else if (rangeStart <= start && rangeEnd + 1 >= end) {
8619 // The new range is a superset of the old range.
8620 data[index] = rangeStart;
8621 data[index + 1] = rangeEnd + 1;
8622 added = true;
8623 }
8624
8625 index += 2;
8626 }
8627 // The loop has finished without doing anything; add the new pair to the end
8628 // of the data set.
8629 if (!added) {
8630 data.push(rangeStart, rangeEnd + 1);
8631 }
8632 return data;
8633 };
8634
8635 var dataContains = function(data, codePoint) {
8636 var index = 0;
8637 var length = data.length;
8638 // Exit early if `codePoint` is not within `data`’s overall range.
8639 var start = data[index];
8640 var end = data[length - 1];
8641 if (length >= 2) {
8642 if (codePoint < start || codePoint > end) {
8643 return false;
8644 }
8645 }
8646 // Iterate over the data per `(start, end)` pair.
8647 while (index < length) {
8648 start = data[index];
8649 end = data[index + 1];
8650 if (codePoint >= start && codePoint < end) {
8651 return true;
8652 }
8653 index += 2;
8654 }
8655 return false;
8656 };
8657
8658 var dataIntersection = function(data, codePoints) {
8659 var index = 0;
8660 var length = codePoints.length;
8661 var codePoint;
8662 var result = [];
8663 while (index < length) {
8664 codePoint = codePoints[index];
8665 if (dataContains(data, codePoint)) {
8666 result.push(codePoint);
8667 }
8668 ++index;
8669 }
8670 return dataFromCodePoints(result);
8671 };
8672
8673 var dataIsEmpty = function(data) {
8674 return !data.length;
8675 };
8676
8677 var dataIsSingleton = function(data) {
8678 // Check if the set only represents a single code point.
8679 return data.length == 2 && data[0] + 1 == data[1];
8680 };
8681
8682 var dataToArray = function(data) {
8683 // Iterate over the data per `(start, end)` pair.
8684 var index = 0;
8685 var start;
8686 var end;
8687 var result = [];
8688 var length = data.length;
8689 while (index < length) {
8690 start = data[index];
8691 end = data[index + 1];
8692 while (start < end) {
8693 result.push(start);
8694 ++start;
8695 }
8696 index += 2;
8697 }
8698 return result;
8699 };
8700
8701 /*--------------------------------------------------------------------------*/
8702
8703 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
8704 var floor = Math.floor;
8705 var highSurrogate = function(codePoint) {
8706 return parseInt(
8707 floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
8708 10
8709 );
8710 };
8711
8712 var lowSurrogate = function(codePoint) {
8713 return parseInt(
8714 (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
8715 10
8716 );
8717 };
8718
8719 var stringFromCharCode = String.fromCharCode;
8720 var codePointToString = function(codePoint) {
8721 var string;
8722 // https://mathiasbynens.be/notes/javascript-escapes#single
8723 // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
8724 // different meaning in regular expressions (word boundary), so it cannot
8725 // be used here.
8726 if (codePoint == 0x09) {
8727 string = '\\t';
8728 }
8729 // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
8730 // else if (codePoint == 0x0B) {
8731 // string = '\\v';
8732 // }
8733 else if (codePoint == 0x0A) {
8734 string = '\\n';
8735 }
8736 else if (codePoint == 0x0C) {
8737 string = '\\f';
8738 }
8739 else if (codePoint == 0x0D) {
8740 string = '\\r';
8741 }
8742 else if (codePoint == 0x5C) {
8743 string = '\\\\';
8744 }
8745 else if (
8746 codePoint == 0x24 ||
8747 (codePoint >= 0x28 && codePoint <= 0x2B) ||
8748 (codePoint >= 0x2D && codePoint <= 0x2F) ||
8749 codePoint == 0x3F ||
8750 (codePoint >= 0x5B && codePoint <= 0x5E) ||
8751 (codePoint >= 0x7B && codePoint <= 0x7D)
8752 ) {
8753 // The code point maps to an unsafe printable ASCII character;
8754 // backslash-escape it. Here’s the list of those symbols:
8755 //
8756 // $()*+-./?[\]^{|}
8757 //
8758 // See #7 for more info.
8759 string = '\\' + stringFromCharCode(codePoint);
8760 }
8761 else if (codePoint >= 0x20 && codePoint <= 0x7E) {
8762 // The code point maps to one of these printable ASCII symbols
8763 // (including the space character):
8764 //
8765 // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
8766 // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
8767 //
8768 // These can safely be used directly.
8769 string = stringFromCharCode(codePoint);
8770 }
8771 else if (codePoint <= 0xFF) {
8772 // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
8773 string = '\\x' + pad(hex(codePoint), 2);
8774 }
8775 else { // `codePoint <= 0xFFFF` holds true.
8776 // https://mathiasbynens.be/notes/javascript-escapes#unicode
8777 string = '\\u' + pad(hex(codePoint), 4);
8778 }
8779
8780 // There’s no need to account for astral symbols / surrogate pairs here,
8781 // since `codePointToString` is private and only used for BMP code points.
8782 // But if that’s what you need, just add an `else` block with this code:
8783 //
8784 // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
8785 // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
8786
8787 return string;
8788 };
8789
8790 var codePointToStringUnicode = function(codePoint) {
8791 if (codePoint <= 0xFFFF) {
8792 return codePointToString(codePoint);
8793 }
8794 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
8795 };
8796
8797 var symbolToCodePoint = function(symbol) {
8798 var length = symbol.length;
8799 var first = symbol.charCodeAt(0);
8800 var second;
8801 if (
8802 first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
8803 length > 1 // There is a next code unit.
8804 ) {
8805 // `first` is a high surrogate, and there is a next character. Assume
8806 // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
8807 second = symbol.charCodeAt(1);
8808 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
8809 return (first - HIGH_SURROGATE_MIN) * 0x400 +
8810 second - LOW_SURROGATE_MIN + 0x10000;
8811 }
8812 return first;
8813 };
8814
8815 var createBMPCharacterClasses = function(data) {
8816 // Iterate over the data per `(start, end)` pair.
8817 var result = '';
8818 var index = 0;
8819 var start;
8820 var end;
8821 var length = data.length;
8822 if (dataIsSingleton(data)) {
8823 return codePointToString(data[0]);
8824 }
8825 while (index < length) {
8826 start = data[index];
8827 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8828 if (start == end) {
8829 result += codePointToString(start);
8830 } else if (start + 1 == end) {
8831 result += codePointToString(start) + codePointToString(end);
8832 } else {
8833 result += codePointToString(start) + '-' + codePointToString(end);
8834 }
8835 index += 2;
8836 }
8837 return '[' + result + ']';
8838 };
8839
8840 var createUnicodeCharacterClasses = function(data) {
8841 // Iterate over the data per `(start, end)` pair.
8842 var result = '';
8843 var index = 0;
8844 var start;
8845 var end;
8846 var length = data.length;
8847 if (dataIsSingleton(data)) {
8848 return codePointToStringUnicode(data[0]);
8849 }
8850 while (index < length) {
8851 start = data[index];
8852 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8853 if (start == end) {
8854 result += codePointToStringUnicode(start);
8855 } else if (start + 1 == end) {
8856 result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
8857 } else {
8858 result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
8859 }
8860 index += 2;
8861 }
8862 return '[' + result + ']';
8863 };
8864
8865 var splitAtBMP = function(data) {
8866 // Iterate over the data per `(start, end)` pair.
8867 var loneHighSurrogates = [];
8868 var loneLowSurrogates = [];
8869 var bmp = [];
8870 var astral = [];
8871 var index = 0;
8872 var start;
8873 var end;
8874 var length = data.length;
8875 while (index < length) {
8876 start = data[index];
8877 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8878
8879 if (start < HIGH_SURROGATE_MIN) {
8880
8881 // The range starts and ends before the high surrogate range.
8882 // E.g. (0, 0x10).
8883 if (end < HIGH_SURROGATE_MIN) {
8884 bmp.push(start, end + 1);
8885 }
8886
8887 // The range starts before the high surrogate range and ends within it.
8888 // E.g. (0, 0xD855).
8889 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
8890 bmp.push(start, HIGH_SURROGATE_MIN);
8891 loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
8892 }
8893
8894 // The range starts before the high surrogate range and ends in the low
8895 // surrogate range. E.g. (0, 0xDCFF).
8896 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8897 bmp.push(start, HIGH_SURROGATE_MIN);
8898 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
8899 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
8900 }
8901
8902 // The range starts before the high surrogate range and ends after the
8903 // low surrogate range. E.g. (0, 0x10FFFF).
8904 if (end > LOW_SURROGATE_MAX) {
8905 bmp.push(start, HIGH_SURROGATE_MIN);
8906 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
8907 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
8908 if (end <= 0xFFFF) {
8909 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8910 } else {
8911 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8912 astral.push(0xFFFF + 1, end + 1);
8913 }
8914 }
8915
8916 } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
8917
8918 // The range starts and ends in the high surrogate range.
8919 // E.g. (0xD855, 0xD866).
8920 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
8921 loneHighSurrogates.push(start, end + 1);
8922 }
8923
8924 // The range starts in the high surrogate range and ends in the low
8925 // surrogate range. E.g. (0xD855, 0xDCFF).
8926 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8927 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
8928 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
8929 }
8930
8931 // The range starts in the high surrogate range and ends after the low
8932 // surrogate range. E.g. (0xD855, 0x10FFFF).
8933 if (end > LOW_SURROGATE_MAX) {
8934 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
8935 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
8936 if (end <= 0xFFFF) {
8937 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8938 } else {
8939 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8940 astral.push(0xFFFF + 1, end + 1);
8941 }
8942 }
8943
8944 } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
8945
8946 // The range starts and ends in the low surrogate range.
8947 // E.g. (0xDCFF, 0xDDFF).
8948 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8949 loneLowSurrogates.push(start, end + 1);
8950 }
8951
8952 // The range starts in the low surrogate range and ends after the low
8953 // surrogate range. E.g. (0xDCFF, 0x10FFFF).
8954 if (end > LOW_SURROGATE_MAX) {
8955 loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
8956 if (end <= 0xFFFF) {
8957 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8958 } else {
8959 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8960 astral.push(0xFFFF + 1, end + 1);
8961 }
8962 }
8963
8964 } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
8965
8966 // The range starts and ends after the low surrogate range.
8967 // E.g. (0xFFAA, 0x10FFFF).
8968 if (end <= 0xFFFF) {
8969 bmp.push(start, end + 1);
8970 } else {
8971 bmp.push(start, 0xFFFF + 1);
8972 astral.push(0xFFFF + 1, end + 1);
8973 }
8974
8975 } else {
8976
8977 // The range starts and ends in the astral range.
8978 astral.push(start, end + 1);
8979
8980 }
8981
8982 index += 2;
8983 }
8984 return {
8985 'loneHighSurrogates': loneHighSurrogates,
8986 'loneLowSurrogates': loneLowSurrogates,
8987 'bmp': bmp,
8988 'astral': astral
8989 };
8990 };
8991
8992 var optimizeSurrogateMappings = function(surrogateMappings) {
8993 var result = [];
8994 var tmpLow = [];
8995 var addLow = false;
8996 var mapping;
8997 var nextMapping;
8998 var highSurrogates;
8999 var lowSurrogates;
9000 var nextHighSurrogates;
9001 var nextLowSurrogates;
9002 var index = -1;
9003 var length = surrogateMappings.length;
9004 while (++index < length) {
9005 mapping = surrogateMappings[index];
9006 nextMapping = surrogateMappings[index + 1];
9007 if (!nextMapping) {
9008 result.push(mapping);
9009 continue;
9010 }
9011 highSurrogates = mapping[0];
9012 lowSurrogates = mapping[1];
9013 nextHighSurrogates = nextMapping[0];
9014 nextLowSurrogates = nextMapping[1];
9015
9016 // Check for identical high surrogate ranges.
9017 tmpLow = lowSurrogates;
9018 while (
9019 nextHighSurrogates &&
9020 highSurrogates[0] == nextHighSurrogates[0] &&
9021 highSurrogates[1] == nextHighSurrogates[1]
9022 ) {
9023 // Merge with the next item.
9024 if (dataIsSingleton(nextLowSurrogates)) {
9025 tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
9026 } else {
9027 tmpLow = dataAddRange(
9028 tmpLow,
9029 nextLowSurrogates[0],
9030 nextLowSurrogates[1] - 1
9031 );
9032 }
9033 ++index;
9034 mapping = surrogateMappings[index];
9035 highSurrogates = mapping[0];
9036 lowSurrogates = mapping[1];
9037 nextMapping = surrogateMappings[index + 1];
9038 nextHighSurrogates = nextMapping && nextMapping[0];
9039 nextLowSurrogates = nextMapping && nextMapping[1];
9040 addLow = true;
9041 }
9042 result.push([
9043 highSurrogates,
9044 addLow ? tmpLow : lowSurrogates
9045 ]);
9046 addLow = false;
9047 }
9048 return optimizeByLowSurrogates(result);
9049 };
9050
9051 var optimizeByLowSurrogates = function(surrogateMappings) {
9052 if (surrogateMappings.length == 1) {
9053 return surrogateMappings;
9054 }
9055 var index = -1;
9056 var innerIndex = -1;
9057 while (++index < surrogateMappings.length) {
9058 var mapping = surrogateMappings[index];
9059 var lowSurrogates = mapping[1];
9060 var lowSurrogateStart = lowSurrogates[0];
9061 var lowSurrogateEnd = lowSurrogates[1];
9062 innerIndex = index; // Note: the loop starts at the next index.
9063 while (++innerIndex < surrogateMappings.length) {
9064 var otherMapping = surrogateMappings[innerIndex];
9065 var otherLowSurrogates = otherMapping[1];
9066 var otherLowSurrogateStart = otherLowSurrogates[0];
9067 var otherLowSurrogateEnd = otherLowSurrogates[1];
9068 if (
9069 lowSurrogateStart == otherLowSurrogateStart &&
9070 lowSurrogateEnd == otherLowSurrogateEnd
9071 ) {
9072 // Add the code points in the other item to this one.
9073 if (dataIsSingleton(otherMapping[0])) {
9074 mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
9075 } else {
9076 mapping[0] = dataAddRange(
9077 mapping[0],
9078 otherMapping[0][0],
9079 otherMapping[0][1] - 1
9080 );
9081 }
9082 // Remove the other, now redundant, item.
9083 surrogateMappings.splice(innerIndex, 1);
9084 --innerIndex;
9085 }
9086 }
9087 }
9088 return surrogateMappings;
9089 };
9090
9091 var surrogateSet = function(data) {
9092 // Exit early if `data` is an empty set.
9093 if (!data.length) {
9094 return [];
9095 }
9096
9097 // Iterate over the data per `(start, end)` pair.
9098 var index = 0;
9099 var start;
9100 var end;
9101 var startHigh;
9102 var startLow;
9103 var endHigh;
9104 var endLow;
9105 var surrogateMappings = [];
9106 var length = data.length;
9107 while (index < length) {
9108 start = data[index];
9109 end = data[index + 1] - 1;
9110
9111 startHigh = highSurrogate(start);
9112 startLow = lowSurrogate(start);
9113 endHigh = highSurrogate(end);
9114 endLow = lowSurrogate(end);
9115
9116 var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
9117 var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
9118 var complete = false;
9119
9120 // Append the previous high-surrogate-to-low-surrogate mappings.
9121 // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
9122 if (
9123 startHigh == endHigh ||
9124 startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
9125 ) {
9126 surrogateMappings.push([
9127 [startHigh, endHigh + 1],
9128 [startLow, endLow + 1]
9129 ]);
9130 complete = true;
9131 } else {
9132 surrogateMappings.push([
9133 [startHigh, startHigh + 1],
9134 [startLow, LOW_SURROGATE_MAX + 1]
9135 ]);
9136 }
9137
9138 // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
9139 // `(endHigh - 1, LOW_SURROGATE_MAX)`.
9140 if (!complete && startHigh + 1 < endHigh) {
9141 if (endsWithHighestLowSurrogate) {
9142 // Combine step 2 and step 3.
9143 surrogateMappings.push([
9144 [startHigh + 1, endHigh + 1],
9145 [LOW_SURROGATE_MIN, endLow + 1]
9146 ]);
9147 complete = true;
9148 } else {
9149 surrogateMappings.push([
9150 [startHigh + 1, endHigh],
9151 [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
9152 ]);
9153 }
9154 }
9155
9156 // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
9157 if (!complete) {
9158 surrogateMappings.push([
9159 [endHigh, endHigh + 1],
9160 [LOW_SURROGATE_MIN, endLow + 1]
9161 ]);
9162 }
9163
9164 index += 2;
9165 }
9166
9167 // The format of `surrogateMappings` is as follows:
9168 //
9169 // [ surrogateMapping1, surrogateMapping2 ]
9170 //
9171 // i.e.:
9172 //
9173 // [
9174 // [ highSurrogates1, lowSurrogates1 ],
9175 // [ highSurrogates2, lowSurrogates2 ]
9176 // ]
9177 return optimizeSurrogateMappings(surrogateMappings);
9178 };
9179
9180 var createSurrogateCharacterClasses = function(surrogateMappings) {
9181 var result = [];
9182 forEach(surrogateMappings, function(surrogateMapping) {
9183 var highSurrogates = surrogateMapping[0];
9184 var lowSurrogates = surrogateMapping[1];
9185 result.push(
9186 createBMPCharacterClasses(highSurrogates) +
9187 createBMPCharacterClasses(lowSurrogates)
9188 );
9189 });
9190 return result.join('|');
9191 };
9192
9193 var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
9194 if (hasUnicodeFlag) {
9195 return createUnicodeCharacterClasses(data);
9196 }
9197 var result = [];
9198
9199 var parts = splitAtBMP(data);
9200 var loneHighSurrogates = parts.loneHighSurrogates;
9201 var loneLowSurrogates = parts.loneLowSurrogates;
9202 var bmp = parts.bmp;
9203 var astral = parts.astral;
9204 var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
9205 var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
9206
9207 var surrogateMappings = surrogateSet(astral);
9208
9209 if (bmpOnly) {
9210 bmp = dataAddData(bmp, loneHighSurrogates);
9211 hasLoneHighSurrogates = false;
9212 bmp = dataAddData(bmp, loneLowSurrogates);
9213 hasLoneLowSurrogates = false;
9214 }
9215
9216 if (!dataIsEmpty(bmp)) {
9217 // The data set contains BMP code points that are not high surrogates
9218 // needed for astral code points in the set.
9219 result.push(createBMPCharacterClasses(bmp));
9220 }
9221 if (surrogateMappings.length) {
9222 // The data set contains astral code points; append character classes
9223 // based on their surrogate pairs.
9224 result.push(createSurrogateCharacterClasses(surrogateMappings));
9225 }
9226 // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
9227 if (hasLoneHighSurrogates) {
9228 result.push(
9229 createBMPCharacterClasses(loneHighSurrogates) +
9230 // Make sure the high surrogates aren’t part of a surrogate pair.
9231 '(?![\\uDC00-\\uDFFF])'
9232 );
9233 }
9234 if (hasLoneLowSurrogates) {
9235 result.push(
9236 // It is not possible to accurately assert the low surrogates aren’t
9237 // part of a surrogate pair, since JavaScript regular expressions do
9238 // not support lookbehind.
9239 '(?:[^\\uD800-\\uDBFF]|^)' +
9240 createBMPCharacterClasses(loneLowSurrogates)
9241 );
9242 }
9243 return result.join('|');
9244 };
9245
9246 /*--------------------------------------------------------------------------*/
9247
9248 // `regenerate` can be used as a constructor (and new methods can be added to
9249 // its prototype) but also as a regular function, the latter of which is the
9250 // documented and most common usage. For that reason, it’s not capitalized.
9251 var regenerate = function(value) {
9252 if (arguments.length > 1) {
9253 value = slice.call(arguments);
9254 }
9255 if (this instanceof regenerate) {
9256 this.data = [];
9257 return value ? this.add(value) : this;
9258 }
9259 return (new regenerate).add(value);
9260 };
9261
9262 regenerate.version = '1.3.3';
9263
9264 var proto = regenerate.prototype;
9265 extend(proto, {
9266 'add': function(value) {
9267 var $this = this;
9268 if (value == null) {
9269 return $this;
9270 }
9271 if (value instanceof regenerate) {
9272 // Allow passing other Regenerate instances.
9273 $this.data = dataAddData($this.data, value.data);
9274 return $this;
9275 }
9276 if (arguments.length > 1) {
9277 value = slice.call(arguments);
9278 }
9279 if (isArray(value)) {
9280 forEach(value, function(item) {
9281 $this.add(item);
9282 });
9283 return $this;
9284 }
9285 $this.data = dataAdd(
9286 $this.data,
9287 isNumber(value) ? value : symbolToCodePoint(value)
9288 );
9289 return $this;
9290 },
9291 'remove': function(value) {
9292 var $this = this;
9293 if (value == null) {
9294 return $this;
9295 }
9296 if (value instanceof regenerate) {
9297 // Allow passing other Regenerate instances.
9298 $this.data = dataRemoveData($this.data, value.data);
9299 return $this;
9300 }
9301 if (arguments.length > 1) {
9302 value = slice.call(arguments);
9303 }
9304 if (isArray(value)) {
9305 forEach(value, function(item) {
9306 $this.remove(item);
9307 });
9308 return $this;
9309 }
9310 $this.data = dataRemove(
9311 $this.data,
9312 isNumber(value) ? value : symbolToCodePoint(value)
9313 );
9314 return $this;
9315 },
9316 'addRange': function(start, end) {
9317 var $this = this;
9318 $this.data = dataAddRange($this.data,
9319 isNumber(start) ? start : symbolToCodePoint(start),
9320 isNumber(end) ? end : symbolToCodePoint(end)
9321 );
9322 return $this;
9323 },
9324 'removeRange': function(start, end) {
9325 var $this = this;
9326 var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
9327 var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
9328 $this.data = dataRemoveRange(
9329 $this.data,
9330 startCodePoint,
9331 endCodePoint
9332 );
9333 return $this;
9334 },
9335 'intersection': function(argument) {
9336 var $this = this;
9337 // Allow passing other Regenerate instances.
9338 // TODO: Optimize this by writing and using `dataIntersectionData()`.
9339 var array = argument instanceof regenerate ?
9340 dataToArray(argument.data) :
9341 argument;
9342 $this.data = dataIntersection($this.data, array);
9343 return $this;
9344 },
9345 'contains': function(codePoint) {
9346 return dataContains(
9347 this.data,
9348 isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
9349 );
9350 },
9351 'clone': function() {
9352 var set = new regenerate;
9353 set.data = this.data.slice(0);
9354 return set;
9355 },
9356 'toString': function(options) {
9357 var result = createCharacterClassesFromData(
9358 this.data,
9359 options ? options.bmpOnly : false,
9360 options ? options.hasUnicodeFlag : false
9361 );
9362 if (!result) {
9363 // For an empty set, return something that can be inserted `/here/` to
9364 // form a valid regular expression. Avoid `(?:)` since that matches the
9365 // empty string.
9366 return '[]';
9367 }
9368 // Use `\0` instead of `\x00` where possible.
9369 return result.replace(regexNull, '\\0$1');
9370 },
9371 'toRegExp': function(flags) {
9372 var pattern = this.toString(
9373 flags && flags.indexOf('u') != -1 ?
9374 { 'hasUnicodeFlag': true } :
9375 null
9376 );
9377 return RegExp(pattern, flags || '');
9378 },
9379 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
9380 return dataToArray(this.data);
9381 }
9382 });
9383
9384 proto.toArray = proto.valueOf;
9385
9386 // Some AMD build optimizers, like r.js, check for specific condition patterns
9387 // like the following:
9388 if (
9389 typeof undefined == 'function' &&
9390 typeof undefined.amd == 'object' &&
9391 undefined.amd
9392 ) {
9393 undefined(function() {
9394 return regenerate;
9395 });
9396 } else if (freeExports && !freeExports.nodeType) {
9397 if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
9398 freeModule.exports = regenerate;
9399 } else { // in Narwhal or RingoJS v0.7.0-
9400 freeExports.regenerate = regenerate;
9401 }
9402 } else { // in Rhino or a web browser
9403 root.regenerate = regenerate;
9404 }
9405
9406}(commonjsGlobal));
9407});
9408
9409var unicodeCanonicalPropertyNamesEcmascript = new Set([
9410 // Non-binary properties:
9411 'General_Category',
9412 'Script',
9413 'Script_Extensions',
9414 // Binary properties:
9415 'Alphabetic',
9416 'Any',
9417 'ASCII',
9418 'ASCII_Hex_Digit',
9419 'Assigned',
9420 'Bidi_Control',
9421 'Bidi_Mirrored',
9422 'Case_Ignorable',
9423 'Cased',
9424 'Changes_When_Casefolded',
9425 'Changes_When_Casemapped',
9426 'Changes_When_Lowercased',
9427 'Changes_When_NFKC_Casefolded',
9428 'Changes_When_Titlecased',
9429 'Changes_When_Uppercased',
9430 'Dash',
9431 'Default_Ignorable_Code_Point',
9432 'Deprecated',
9433 'Diacritic',
9434 'Emoji',
9435 'Emoji_Component',
9436 'Emoji_Modifier',
9437 'Emoji_Modifier_Base',
9438 'Emoji_Presentation',
9439 'Extended_Pictographic',
9440 'Extender',
9441 'Grapheme_Base',
9442 'Grapheme_Extend',
9443 'Hex_Digit',
9444 'ID_Continue',
9445 'ID_Start',
9446 'Ideographic',
9447 'IDS_Binary_Operator',
9448 'IDS_Trinary_Operator',
9449 'Join_Control',
9450 'Logical_Order_Exception',
9451 'Lowercase',
9452 'Math',
9453 'Noncharacter_Code_Point',
9454 'Pattern_Syntax',
9455 'Pattern_White_Space',
9456 'Quotation_Mark',
9457 'Radical',
9458 'Regional_Indicator',
9459 'Sentence_Terminal',
9460 'Soft_Dotted',
9461 'Terminal_Punctuation',
9462 'Unified_Ideograph',
9463 'Uppercase',
9464 'Variation_Selector',
9465 'White_Space',
9466 'XID_Continue',
9467 'XID_Start'
9468]);
9469
9470// Generated using `npm run build`. Do not edit!
9471var unicodePropertyAliasesEcmascript = new Map([
9472 ['scx', 'Script_Extensions'],
9473 ['sc', 'Script'],
9474 ['gc', 'General_Category'],
9475 ['AHex', 'ASCII_Hex_Digit'],
9476 ['Alpha', 'Alphabetic'],
9477 ['Bidi_C', 'Bidi_Control'],
9478 ['Bidi_M', 'Bidi_Mirrored'],
9479 ['Cased', 'Cased'],
9480 ['CI', 'Case_Ignorable'],
9481 ['CWCF', 'Changes_When_Casefolded'],
9482 ['CWCM', 'Changes_When_Casemapped'],
9483 ['CWKCF', 'Changes_When_NFKC_Casefolded'],
9484 ['CWL', 'Changes_When_Lowercased'],
9485 ['CWT', 'Changes_When_Titlecased'],
9486 ['CWU', 'Changes_When_Uppercased'],
9487 ['Dash', 'Dash'],
9488 ['Dep', 'Deprecated'],
9489 ['DI', 'Default_Ignorable_Code_Point'],
9490 ['Dia', 'Diacritic'],
9491 ['Ext', 'Extender'],
9492 ['Gr_Base', 'Grapheme_Base'],
9493 ['Gr_Ext', 'Grapheme_Extend'],
9494 ['Hex', 'Hex_Digit'],
9495 ['IDC', 'ID_Continue'],
9496 ['Ideo', 'Ideographic'],
9497 ['IDS', 'ID_Start'],
9498 ['IDSB', 'IDS_Binary_Operator'],
9499 ['IDST', 'IDS_Trinary_Operator'],
9500 ['Join_C', 'Join_Control'],
9501 ['LOE', 'Logical_Order_Exception'],
9502 ['Lower', 'Lowercase'],
9503 ['Math', 'Math'],
9504 ['NChar', 'Noncharacter_Code_Point'],
9505 ['Pat_Syn', 'Pattern_Syntax'],
9506 ['Pat_WS', 'Pattern_White_Space'],
9507 ['QMark', 'Quotation_Mark'],
9508 ['Radical', 'Radical'],
9509 ['RI', 'Regional_Indicator'],
9510 ['SD', 'Soft_Dotted'],
9511 ['STerm', 'Sentence_Terminal'],
9512 ['Term', 'Terminal_Punctuation'],
9513 ['UIdeo', 'Unified_Ideograph'],
9514 ['Upper', 'Uppercase'],
9515 ['VS', 'Variation_Selector'],
9516 ['WSpace', 'White_Space'],
9517 ['space', 'White_Space'],
9518 ['XIDC', 'XID_Continue'],
9519 ['XIDS', 'XID_Start']
9520]);
9521
9522'use strict';
9523
9524
9525
9526
9527const matchProperty = function(property) {
9528 if (unicodeCanonicalPropertyNamesEcmascript.has(property)) {
9529 return property;
9530 }
9531 if (unicodePropertyAliasesEcmascript.has(property)) {
9532 return unicodePropertyAliasesEcmascript.get(property);
9533 }
9534 throw new Error(`Unknown property: ${ property }`);
9535};
9536
9537var unicodeMatchPropertyEcmascript = matchProperty;
9538
9539var mappings = new Map([
9540 ['General_Category', new Map([
9541 ['C', 'Other'],
9542 ['Cc', 'Control'],
9543 ['cntrl', 'Control'],
9544 ['Cf', 'Format'],
9545 ['Cn', 'Unassigned'],
9546 ['Co', 'Private_Use'],
9547 ['Cs', 'Surrogate'],
9548 ['L', 'Letter'],
9549 ['LC', 'Cased_Letter'],
9550 ['Ll', 'Lowercase_Letter'],
9551 ['Lm', 'Modifier_Letter'],
9552 ['Lo', 'Other_Letter'],
9553 ['Lt', 'Titlecase_Letter'],
9554 ['Lu', 'Uppercase_Letter'],
9555 ['M', 'Mark'],
9556 ['Combining_Mark', 'Mark'],
9557 ['Mc', 'Spacing_Mark'],
9558 ['Me', 'Enclosing_Mark'],
9559 ['Mn', 'Nonspacing_Mark'],
9560 ['N', 'Number'],
9561 ['Nd', 'Decimal_Number'],
9562 ['digit', 'Decimal_Number'],
9563 ['Nl', 'Letter_Number'],
9564 ['No', 'Other_Number'],
9565 ['P', 'Punctuation'],
9566 ['punct', 'Punctuation'],
9567 ['Pc', 'Connector_Punctuation'],
9568 ['Pd', 'Dash_Punctuation'],
9569 ['Pe', 'Close_Punctuation'],
9570 ['Pf', 'Final_Punctuation'],
9571 ['Pi', 'Initial_Punctuation'],
9572 ['Po', 'Other_Punctuation'],
9573 ['Ps', 'Open_Punctuation'],
9574 ['S', 'Symbol'],
9575 ['Sc', 'Currency_Symbol'],
9576 ['Sk', 'Modifier_Symbol'],
9577 ['Sm', 'Math_Symbol'],
9578 ['So', 'Other_Symbol'],
9579 ['Z', 'Separator'],
9580 ['Zl', 'Line_Separator'],
9581 ['Zp', 'Paragraph_Separator'],
9582 ['Zs', 'Space_Separator'],
9583 ['Other', 'Other'],
9584 ['Control', 'Control'],
9585 ['Format', 'Format'],
9586 ['Unassigned', 'Unassigned'],
9587 ['Private_Use', 'Private_Use'],
9588 ['Surrogate', 'Surrogate'],
9589 ['Letter', 'Letter'],
9590 ['Cased_Letter', 'Cased_Letter'],
9591 ['Lowercase_Letter', 'Lowercase_Letter'],
9592 ['Modifier_Letter', 'Modifier_Letter'],
9593 ['Other_Letter', 'Other_Letter'],
9594 ['Titlecase_Letter', 'Titlecase_Letter'],
9595 ['Uppercase_Letter', 'Uppercase_Letter'],
9596 ['Mark', 'Mark'],
9597 ['Spacing_Mark', 'Spacing_Mark'],
9598 ['Enclosing_Mark', 'Enclosing_Mark'],
9599 ['Nonspacing_Mark', 'Nonspacing_Mark'],
9600 ['Number', 'Number'],
9601 ['Decimal_Number', 'Decimal_Number'],
9602 ['Letter_Number', 'Letter_Number'],
9603 ['Other_Number', 'Other_Number'],
9604 ['Punctuation', 'Punctuation'],
9605 ['Connector_Punctuation', 'Connector_Punctuation'],
9606 ['Dash_Punctuation', 'Dash_Punctuation'],
9607 ['Close_Punctuation', 'Close_Punctuation'],
9608 ['Final_Punctuation', 'Final_Punctuation'],
9609 ['Initial_Punctuation', 'Initial_Punctuation'],
9610 ['Other_Punctuation', 'Other_Punctuation'],
9611 ['Open_Punctuation', 'Open_Punctuation'],
9612 ['Symbol', 'Symbol'],
9613 ['Currency_Symbol', 'Currency_Symbol'],
9614 ['Modifier_Symbol', 'Modifier_Symbol'],
9615 ['Math_Symbol', 'Math_Symbol'],
9616 ['Other_Symbol', 'Other_Symbol'],
9617 ['Separator', 'Separator'],
9618 ['Line_Separator', 'Line_Separator'],
9619 ['Paragraph_Separator', 'Paragraph_Separator'],
9620 ['Space_Separator', 'Space_Separator']
9621 ])],
9622 ['Script', new Map([
9623 ['Adlm', 'Adlam'],
9624 ['Aghb', 'Caucasian_Albanian'],
9625 ['Ahom', 'Ahom'],
9626 ['Arab', 'Arabic'],
9627 ['Armi', 'Imperial_Aramaic'],
9628 ['Armn', 'Armenian'],
9629 ['Avst', 'Avestan'],
9630 ['Bali', 'Balinese'],
9631 ['Bamu', 'Bamum'],
9632 ['Bass', 'Bassa_Vah'],
9633 ['Batk', 'Batak'],
9634 ['Beng', 'Bengali'],
9635 ['Bhks', 'Bhaiksuki'],
9636 ['Bopo', 'Bopomofo'],
9637 ['Brah', 'Brahmi'],
9638 ['Brai', 'Braille'],
9639 ['Bugi', 'Buginese'],
9640 ['Buhd', 'Buhid'],
9641 ['Cakm', 'Chakma'],
9642 ['Cans', 'Canadian_Aboriginal'],
9643 ['Cari', 'Carian'],
9644 ['Cham', 'Cham'],
9645 ['Cher', 'Cherokee'],
9646 ['Copt', 'Coptic'],
9647 ['Qaac', 'Coptic'],
9648 ['Cprt', 'Cypriot'],
9649 ['Cyrl', 'Cyrillic'],
9650 ['Deva', 'Devanagari'],
9651 ['Dsrt', 'Deseret'],
9652 ['Dupl', 'Duployan'],
9653 ['Egyp', 'Egyptian_Hieroglyphs'],
9654 ['Elba', 'Elbasan'],
9655 ['Ethi', 'Ethiopic'],
9656 ['Geor', 'Georgian'],
9657 ['Glag', 'Glagolitic'],
9658 ['Gonm', 'Masaram_Gondi'],
9659 ['Goth', 'Gothic'],
9660 ['Gran', 'Grantha'],
9661 ['Grek', 'Greek'],
9662 ['Gujr', 'Gujarati'],
9663 ['Guru', 'Gurmukhi'],
9664 ['Hang', 'Hangul'],
9665 ['Hani', 'Han'],
9666 ['Hano', 'Hanunoo'],
9667 ['Hatr', 'Hatran'],
9668 ['Hebr', 'Hebrew'],
9669 ['Hira', 'Hiragana'],
9670 ['Hluw', 'Anatolian_Hieroglyphs'],
9671 ['Hmng', 'Pahawh_Hmong'],
9672 ['Hrkt', 'Katakana_Or_Hiragana'],
9673 ['Hung', 'Old_Hungarian'],
9674 ['Ital', 'Old_Italic'],
9675 ['Java', 'Javanese'],
9676 ['Kali', 'Kayah_Li'],
9677 ['Kana', 'Katakana'],
9678 ['Khar', 'Kharoshthi'],
9679 ['Khmr', 'Khmer'],
9680 ['Khoj', 'Khojki'],
9681 ['Knda', 'Kannada'],
9682 ['Kthi', 'Kaithi'],
9683 ['Lana', 'Tai_Tham'],
9684 ['Laoo', 'Lao'],
9685 ['Latn', 'Latin'],
9686 ['Lepc', 'Lepcha'],
9687 ['Limb', 'Limbu'],
9688 ['Lina', 'Linear_A'],
9689 ['Linb', 'Linear_B'],
9690 ['Lisu', 'Lisu'],
9691 ['Lyci', 'Lycian'],
9692 ['Lydi', 'Lydian'],
9693 ['Mahj', 'Mahajani'],
9694 ['Mand', 'Mandaic'],
9695 ['Mani', 'Manichaean'],
9696 ['Marc', 'Marchen'],
9697 ['Mend', 'Mende_Kikakui'],
9698 ['Merc', 'Meroitic_Cursive'],
9699 ['Mero', 'Meroitic_Hieroglyphs'],
9700 ['Mlym', 'Malayalam'],
9701 ['Modi', 'Modi'],
9702 ['Mong', 'Mongolian'],
9703 ['Mroo', 'Mro'],
9704 ['Mtei', 'Meetei_Mayek'],
9705 ['Mult', 'Multani'],
9706 ['Mymr', 'Myanmar'],
9707 ['Narb', 'Old_North_Arabian'],
9708 ['Nbat', 'Nabataean'],
9709 ['Newa', 'Newa'],
9710 ['Nkoo', 'Nko'],
9711 ['Nshu', 'Nushu'],
9712 ['Ogam', 'Ogham'],
9713 ['Olck', 'Ol_Chiki'],
9714 ['Orkh', 'Old_Turkic'],
9715 ['Orya', 'Oriya'],
9716 ['Osge', 'Osage'],
9717 ['Osma', 'Osmanya'],
9718 ['Palm', 'Palmyrene'],
9719 ['Pauc', 'Pau_Cin_Hau'],
9720 ['Perm', 'Old_Permic'],
9721 ['Phag', 'Phags_Pa'],
9722 ['Phli', 'Inscriptional_Pahlavi'],
9723 ['Phlp', 'Psalter_Pahlavi'],
9724 ['Phnx', 'Phoenician'],
9725 ['Plrd', 'Miao'],
9726 ['Prti', 'Inscriptional_Parthian'],
9727 ['Rjng', 'Rejang'],
9728 ['Runr', 'Runic'],
9729 ['Samr', 'Samaritan'],
9730 ['Sarb', 'Old_South_Arabian'],
9731 ['Saur', 'Saurashtra'],
9732 ['Sgnw', 'SignWriting'],
9733 ['Shaw', 'Shavian'],
9734 ['Shrd', 'Sharada'],
9735 ['Sidd', 'Siddham'],
9736 ['Sind', 'Khudawadi'],
9737 ['Sinh', 'Sinhala'],
9738 ['Sora', 'Sora_Sompeng'],
9739 ['Soyo', 'Soyombo'],
9740 ['Sund', 'Sundanese'],
9741 ['Sylo', 'Syloti_Nagri'],
9742 ['Syrc', 'Syriac'],
9743 ['Tagb', 'Tagbanwa'],
9744 ['Takr', 'Takri'],
9745 ['Tale', 'Tai_Le'],
9746 ['Talu', 'New_Tai_Lue'],
9747 ['Taml', 'Tamil'],
9748 ['Tang', 'Tangut'],
9749 ['Tavt', 'Tai_Viet'],
9750 ['Telu', 'Telugu'],
9751 ['Tfng', 'Tifinagh'],
9752 ['Tglg', 'Tagalog'],
9753 ['Thaa', 'Thaana'],
9754 ['Thai', 'Thai'],
9755 ['Tibt', 'Tibetan'],
9756 ['Tirh', 'Tirhuta'],
9757 ['Ugar', 'Ugaritic'],
9758 ['Vaii', 'Vai'],
9759 ['Wara', 'Warang_Citi'],
9760 ['Xpeo', 'Old_Persian'],
9761 ['Xsux', 'Cuneiform'],
9762 ['Yiii', 'Yi'],
9763 ['Zanb', 'Zanabazar_Square'],
9764 ['Zinh', 'Inherited'],
9765 ['Qaai', 'Inherited'],
9766 ['Zyyy', 'Common'],
9767 ['Zzzz', 'Unknown'],
9768 ['Adlam', 'Adlam'],
9769 ['Caucasian_Albanian', 'Caucasian_Albanian'],
9770 ['Arabic', 'Arabic'],
9771 ['Imperial_Aramaic', 'Imperial_Aramaic'],
9772 ['Armenian', 'Armenian'],
9773 ['Avestan', 'Avestan'],
9774 ['Balinese', 'Balinese'],
9775 ['Bamum', 'Bamum'],
9776 ['Bassa_Vah', 'Bassa_Vah'],
9777 ['Batak', 'Batak'],
9778 ['Bengali', 'Bengali'],
9779 ['Bhaiksuki', 'Bhaiksuki'],
9780 ['Bopomofo', 'Bopomofo'],
9781 ['Brahmi', 'Brahmi'],
9782 ['Braille', 'Braille'],
9783 ['Buginese', 'Buginese'],
9784 ['Buhid', 'Buhid'],
9785 ['Chakma', 'Chakma'],
9786 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
9787 ['Carian', 'Carian'],
9788 ['Cherokee', 'Cherokee'],
9789 ['Coptic', 'Coptic'],
9790 ['Cypriot', 'Cypriot'],
9791 ['Cyrillic', 'Cyrillic'],
9792 ['Devanagari', 'Devanagari'],
9793 ['Deseret', 'Deseret'],
9794 ['Duployan', 'Duployan'],
9795 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
9796 ['Elbasan', 'Elbasan'],
9797 ['Ethiopic', 'Ethiopic'],
9798 ['Georgian', 'Georgian'],
9799 ['Glagolitic', 'Glagolitic'],
9800 ['Masaram_Gondi', 'Masaram_Gondi'],
9801 ['Gothic', 'Gothic'],
9802 ['Grantha', 'Grantha'],
9803 ['Greek', 'Greek'],
9804 ['Gujarati', 'Gujarati'],
9805 ['Gurmukhi', 'Gurmukhi'],
9806 ['Hangul', 'Hangul'],
9807 ['Han', 'Han'],
9808 ['Hanunoo', 'Hanunoo'],
9809 ['Hatran', 'Hatran'],
9810 ['Hebrew', 'Hebrew'],
9811 ['Hiragana', 'Hiragana'],
9812 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
9813 ['Pahawh_Hmong', 'Pahawh_Hmong'],
9814 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
9815 ['Old_Hungarian', 'Old_Hungarian'],
9816 ['Old_Italic', 'Old_Italic'],
9817 ['Javanese', 'Javanese'],
9818 ['Kayah_Li', 'Kayah_Li'],
9819 ['Katakana', 'Katakana'],
9820 ['Kharoshthi', 'Kharoshthi'],
9821 ['Khmer', 'Khmer'],
9822 ['Khojki', 'Khojki'],
9823 ['Kannada', 'Kannada'],
9824 ['Kaithi', 'Kaithi'],
9825 ['Tai_Tham', 'Tai_Tham'],
9826 ['Lao', 'Lao'],
9827 ['Latin', 'Latin'],
9828 ['Lepcha', 'Lepcha'],
9829 ['Limbu', 'Limbu'],
9830 ['Linear_A', 'Linear_A'],
9831 ['Linear_B', 'Linear_B'],
9832 ['Lycian', 'Lycian'],
9833 ['Lydian', 'Lydian'],
9834 ['Mahajani', 'Mahajani'],
9835 ['Mandaic', 'Mandaic'],
9836 ['Manichaean', 'Manichaean'],
9837 ['Marchen', 'Marchen'],
9838 ['Mende_Kikakui', 'Mende_Kikakui'],
9839 ['Meroitic_Cursive', 'Meroitic_Cursive'],
9840 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
9841 ['Malayalam', 'Malayalam'],
9842 ['Mongolian', 'Mongolian'],
9843 ['Mro', 'Mro'],
9844 ['Meetei_Mayek', 'Meetei_Mayek'],
9845 ['Multani', 'Multani'],
9846 ['Myanmar', 'Myanmar'],
9847 ['Old_North_Arabian', 'Old_North_Arabian'],
9848 ['Nabataean', 'Nabataean'],
9849 ['Nko', 'Nko'],
9850 ['Nushu', 'Nushu'],
9851 ['Ogham', 'Ogham'],
9852 ['Ol_Chiki', 'Ol_Chiki'],
9853 ['Old_Turkic', 'Old_Turkic'],
9854 ['Oriya', 'Oriya'],
9855 ['Osage', 'Osage'],
9856 ['Osmanya', 'Osmanya'],
9857 ['Palmyrene', 'Palmyrene'],
9858 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
9859 ['Old_Permic', 'Old_Permic'],
9860 ['Phags_Pa', 'Phags_Pa'],
9861 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
9862 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
9863 ['Phoenician', 'Phoenician'],
9864 ['Miao', 'Miao'],
9865 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
9866 ['Rejang', 'Rejang'],
9867 ['Runic', 'Runic'],
9868 ['Samaritan', 'Samaritan'],
9869 ['Old_South_Arabian', 'Old_South_Arabian'],
9870 ['Saurashtra', 'Saurashtra'],
9871 ['SignWriting', 'SignWriting'],
9872 ['Shavian', 'Shavian'],
9873 ['Sharada', 'Sharada'],
9874 ['Siddham', 'Siddham'],
9875 ['Khudawadi', 'Khudawadi'],
9876 ['Sinhala', 'Sinhala'],
9877 ['Sora_Sompeng', 'Sora_Sompeng'],
9878 ['Soyombo', 'Soyombo'],
9879 ['Sundanese', 'Sundanese'],
9880 ['Syloti_Nagri', 'Syloti_Nagri'],
9881 ['Syriac', 'Syriac'],
9882 ['Tagbanwa', 'Tagbanwa'],
9883 ['Takri', 'Takri'],
9884 ['Tai_Le', 'Tai_Le'],
9885 ['New_Tai_Lue', 'New_Tai_Lue'],
9886 ['Tamil', 'Tamil'],
9887 ['Tangut', 'Tangut'],
9888 ['Tai_Viet', 'Tai_Viet'],
9889 ['Telugu', 'Telugu'],
9890 ['Tifinagh', 'Tifinagh'],
9891 ['Tagalog', 'Tagalog'],
9892 ['Thaana', 'Thaana'],
9893 ['Tibetan', 'Tibetan'],
9894 ['Tirhuta', 'Tirhuta'],
9895 ['Ugaritic', 'Ugaritic'],
9896 ['Vai', 'Vai'],
9897 ['Warang_Citi', 'Warang_Citi'],
9898 ['Old_Persian', 'Old_Persian'],
9899 ['Cuneiform', 'Cuneiform'],
9900 ['Yi', 'Yi'],
9901 ['Zanabazar_Square', 'Zanabazar_Square'],
9902 ['Inherited', 'Inherited'],
9903 ['Common', 'Common'],
9904 ['Unknown', 'Unknown']
9905 ])],
9906 ['Script_Extensions', new Map([
9907 ['Adlm', 'Adlam'],
9908 ['Aghb', 'Caucasian_Albanian'],
9909 ['Ahom', 'Ahom'],
9910 ['Arab', 'Arabic'],
9911 ['Armi', 'Imperial_Aramaic'],
9912 ['Armn', 'Armenian'],
9913 ['Avst', 'Avestan'],
9914 ['Bali', 'Balinese'],
9915 ['Bamu', 'Bamum'],
9916 ['Bass', 'Bassa_Vah'],
9917 ['Batk', 'Batak'],
9918 ['Beng', 'Bengali'],
9919 ['Bhks', 'Bhaiksuki'],
9920 ['Bopo', 'Bopomofo'],
9921 ['Brah', 'Brahmi'],
9922 ['Brai', 'Braille'],
9923 ['Bugi', 'Buginese'],
9924 ['Buhd', 'Buhid'],
9925 ['Cakm', 'Chakma'],
9926 ['Cans', 'Canadian_Aboriginal'],
9927 ['Cari', 'Carian'],
9928 ['Cham', 'Cham'],
9929 ['Cher', 'Cherokee'],
9930 ['Copt', 'Coptic'],
9931 ['Qaac', 'Coptic'],
9932 ['Cprt', 'Cypriot'],
9933 ['Cyrl', 'Cyrillic'],
9934 ['Deva', 'Devanagari'],
9935 ['Dsrt', 'Deseret'],
9936 ['Dupl', 'Duployan'],
9937 ['Egyp', 'Egyptian_Hieroglyphs'],
9938 ['Elba', 'Elbasan'],
9939 ['Ethi', 'Ethiopic'],
9940 ['Geor', 'Georgian'],
9941 ['Glag', 'Glagolitic'],
9942 ['Gonm', 'Masaram_Gondi'],
9943 ['Goth', 'Gothic'],
9944 ['Gran', 'Grantha'],
9945 ['Grek', 'Greek'],
9946 ['Gujr', 'Gujarati'],
9947 ['Guru', 'Gurmukhi'],
9948 ['Hang', 'Hangul'],
9949 ['Hani', 'Han'],
9950 ['Hano', 'Hanunoo'],
9951 ['Hatr', 'Hatran'],
9952 ['Hebr', 'Hebrew'],
9953 ['Hira', 'Hiragana'],
9954 ['Hluw', 'Anatolian_Hieroglyphs'],
9955 ['Hmng', 'Pahawh_Hmong'],
9956 ['Hrkt', 'Katakana_Or_Hiragana'],
9957 ['Hung', 'Old_Hungarian'],
9958 ['Ital', 'Old_Italic'],
9959 ['Java', 'Javanese'],
9960 ['Kali', 'Kayah_Li'],
9961 ['Kana', 'Katakana'],
9962 ['Khar', 'Kharoshthi'],
9963 ['Khmr', 'Khmer'],
9964 ['Khoj', 'Khojki'],
9965 ['Knda', 'Kannada'],
9966 ['Kthi', 'Kaithi'],
9967 ['Lana', 'Tai_Tham'],
9968 ['Laoo', 'Lao'],
9969 ['Latn', 'Latin'],
9970 ['Lepc', 'Lepcha'],
9971 ['Limb', 'Limbu'],
9972 ['Lina', 'Linear_A'],
9973 ['Linb', 'Linear_B'],
9974 ['Lisu', 'Lisu'],
9975 ['Lyci', 'Lycian'],
9976 ['Lydi', 'Lydian'],
9977 ['Mahj', 'Mahajani'],
9978 ['Mand', 'Mandaic'],
9979 ['Mani', 'Manichaean'],
9980 ['Marc', 'Marchen'],
9981 ['Mend', 'Mende_Kikakui'],
9982 ['Merc', 'Meroitic_Cursive'],
9983 ['Mero', 'Meroitic_Hieroglyphs'],
9984 ['Mlym', 'Malayalam'],
9985 ['Modi', 'Modi'],
9986 ['Mong', 'Mongolian'],
9987 ['Mroo', 'Mro'],
9988 ['Mtei', 'Meetei_Mayek'],
9989 ['Mult', 'Multani'],
9990 ['Mymr', 'Myanmar'],
9991 ['Narb', 'Old_North_Arabian'],
9992 ['Nbat', 'Nabataean'],
9993 ['Newa', 'Newa'],
9994 ['Nkoo', 'Nko'],
9995 ['Nshu', 'Nushu'],
9996 ['Ogam', 'Ogham'],
9997 ['Olck', 'Ol_Chiki'],
9998 ['Orkh', 'Old_Turkic'],
9999 ['Orya', 'Oriya'],
10000 ['Osge', 'Osage'],
10001 ['Osma', 'Osmanya'],
10002 ['Palm', 'Palmyrene'],
10003 ['Pauc', 'Pau_Cin_Hau'],
10004 ['Perm', 'Old_Permic'],
10005 ['Phag', 'Phags_Pa'],
10006 ['Phli', 'Inscriptional_Pahlavi'],
10007 ['Phlp', 'Psalter_Pahlavi'],
10008 ['Phnx', 'Phoenician'],
10009 ['Plrd', 'Miao'],
10010 ['Prti', 'Inscriptional_Parthian'],
10011 ['Rjng', 'Rejang'],
10012 ['Runr', 'Runic'],
10013 ['Samr', 'Samaritan'],
10014 ['Sarb', 'Old_South_Arabian'],
10015 ['Saur', 'Saurashtra'],
10016 ['Sgnw', 'SignWriting'],
10017 ['Shaw', 'Shavian'],
10018 ['Shrd', 'Sharada'],
10019 ['Sidd', 'Siddham'],
10020 ['Sind', 'Khudawadi'],
10021 ['Sinh', 'Sinhala'],
10022 ['Sora', 'Sora_Sompeng'],
10023 ['Soyo', 'Soyombo'],
10024 ['Sund', 'Sundanese'],
10025 ['Sylo', 'Syloti_Nagri'],
10026 ['Syrc', 'Syriac'],
10027 ['Tagb', 'Tagbanwa'],
10028 ['Takr', 'Takri'],
10029 ['Tale', 'Tai_Le'],
10030 ['Talu', 'New_Tai_Lue'],
10031 ['Taml', 'Tamil'],
10032 ['Tang', 'Tangut'],
10033 ['Tavt', 'Tai_Viet'],
10034 ['Telu', 'Telugu'],
10035 ['Tfng', 'Tifinagh'],
10036 ['Tglg', 'Tagalog'],
10037 ['Thaa', 'Thaana'],
10038 ['Thai', 'Thai'],
10039 ['Tibt', 'Tibetan'],
10040 ['Tirh', 'Tirhuta'],
10041 ['Ugar', 'Ugaritic'],
10042 ['Vaii', 'Vai'],
10043 ['Wara', 'Warang_Citi'],
10044 ['Xpeo', 'Old_Persian'],
10045 ['Xsux', 'Cuneiform'],
10046 ['Yiii', 'Yi'],
10047 ['Zanb', 'Zanabazar_Square'],
10048 ['Zinh', 'Inherited'],
10049 ['Qaai', 'Inherited'],
10050 ['Zyyy', 'Common'],
10051 ['Zzzz', 'Unknown'],
10052 ['Adlam', 'Adlam'],
10053 ['Caucasian_Albanian', 'Caucasian_Albanian'],
10054 ['Arabic', 'Arabic'],
10055 ['Imperial_Aramaic', 'Imperial_Aramaic'],
10056 ['Armenian', 'Armenian'],
10057 ['Avestan', 'Avestan'],
10058 ['Balinese', 'Balinese'],
10059 ['Bamum', 'Bamum'],
10060 ['Bassa_Vah', 'Bassa_Vah'],
10061 ['Batak', 'Batak'],
10062 ['Bengali', 'Bengali'],
10063 ['Bhaiksuki', 'Bhaiksuki'],
10064 ['Bopomofo', 'Bopomofo'],
10065 ['Brahmi', 'Brahmi'],
10066 ['Braille', 'Braille'],
10067 ['Buginese', 'Buginese'],
10068 ['Buhid', 'Buhid'],
10069 ['Chakma', 'Chakma'],
10070 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
10071 ['Carian', 'Carian'],
10072 ['Cherokee', 'Cherokee'],
10073 ['Coptic', 'Coptic'],
10074 ['Cypriot', 'Cypriot'],
10075 ['Cyrillic', 'Cyrillic'],
10076 ['Devanagari', 'Devanagari'],
10077 ['Deseret', 'Deseret'],
10078 ['Duployan', 'Duployan'],
10079 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
10080 ['Elbasan', 'Elbasan'],
10081 ['Ethiopic', 'Ethiopic'],
10082 ['Georgian', 'Georgian'],
10083 ['Glagolitic', 'Glagolitic'],
10084 ['Masaram_Gondi', 'Masaram_Gondi'],
10085 ['Gothic', 'Gothic'],
10086 ['Grantha', 'Grantha'],
10087 ['Greek', 'Greek'],
10088 ['Gujarati', 'Gujarati'],
10089 ['Gurmukhi', 'Gurmukhi'],
10090 ['Hangul', 'Hangul'],
10091 ['Han', 'Han'],
10092 ['Hanunoo', 'Hanunoo'],
10093 ['Hatran', 'Hatran'],
10094 ['Hebrew', 'Hebrew'],
10095 ['Hiragana', 'Hiragana'],
10096 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
10097 ['Pahawh_Hmong', 'Pahawh_Hmong'],
10098 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
10099 ['Old_Hungarian', 'Old_Hungarian'],
10100 ['Old_Italic', 'Old_Italic'],
10101 ['Javanese', 'Javanese'],
10102 ['Kayah_Li', 'Kayah_Li'],
10103 ['Katakana', 'Katakana'],
10104 ['Kharoshthi', 'Kharoshthi'],
10105 ['Khmer', 'Khmer'],
10106 ['Khojki', 'Khojki'],
10107 ['Kannada', 'Kannada'],
10108 ['Kaithi', 'Kaithi'],
10109 ['Tai_Tham', 'Tai_Tham'],
10110 ['Lao', 'Lao'],
10111 ['Latin', 'Latin'],
10112 ['Lepcha', 'Lepcha'],
10113 ['Limbu', 'Limbu'],
10114 ['Linear_A', 'Linear_A'],
10115 ['Linear_B', 'Linear_B'],
10116 ['Lycian', 'Lycian'],
10117 ['Lydian', 'Lydian'],
10118 ['Mahajani', 'Mahajani'],
10119 ['Mandaic', 'Mandaic'],
10120 ['Manichaean', 'Manichaean'],
10121 ['Marchen', 'Marchen'],
10122 ['Mende_Kikakui', 'Mende_Kikakui'],
10123 ['Meroitic_Cursive', 'Meroitic_Cursive'],
10124 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
10125 ['Malayalam', 'Malayalam'],
10126 ['Mongolian', 'Mongolian'],
10127 ['Mro', 'Mro'],
10128 ['Meetei_Mayek', 'Meetei_Mayek'],
10129 ['Multani', 'Multani'],
10130 ['Myanmar', 'Myanmar'],
10131 ['Old_North_Arabian', 'Old_North_Arabian'],
10132 ['Nabataean', 'Nabataean'],
10133 ['Nko', 'Nko'],
10134 ['Nushu', 'Nushu'],
10135 ['Ogham', 'Ogham'],
10136 ['Ol_Chiki', 'Ol_Chiki'],
10137 ['Old_Turkic', 'Old_Turkic'],
10138 ['Oriya', 'Oriya'],
10139 ['Osage', 'Osage'],
10140 ['Osmanya', 'Osmanya'],
10141 ['Palmyrene', 'Palmyrene'],
10142 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
10143 ['Old_Permic', 'Old_Permic'],
10144 ['Phags_Pa', 'Phags_Pa'],
10145 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
10146 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
10147 ['Phoenician', 'Phoenician'],
10148 ['Miao', 'Miao'],
10149 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
10150 ['Rejang', 'Rejang'],
10151 ['Runic', 'Runic'],
10152 ['Samaritan', 'Samaritan'],
10153 ['Old_South_Arabian', 'Old_South_Arabian'],
10154 ['Saurashtra', 'Saurashtra'],
10155 ['SignWriting', 'SignWriting'],
10156 ['Shavian', 'Shavian'],
10157 ['Sharada', 'Sharada'],
10158 ['Siddham', 'Siddham'],
10159 ['Khudawadi', 'Khudawadi'],
10160 ['Sinhala', 'Sinhala'],
10161 ['Sora_Sompeng', 'Sora_Sompeng'],
10162 ['Soyombo', 'Soyombo'],
10163 ['Sundanese', 'Sundanese'],
10164 ['Syloti_Nagri', 'Syloti_Nagri'],
10165 ['Syriac', 'Syriac'],
10166 ['Tagbanwa', 'Tagbanwa'],
10167 ['Takri', 'Takri'],
10168 ['Tai_Le', 'Tai_Le'],
10169 ['New_Tai_Lue', 'New_Tai_Lue'],
10170 ['Tamil', 'Tamil'],
10171 ['Tangut', 'Tangut'],
10172 ['Tai_Viet', 'Tai_Viet'],
10173 ['Telugu', 'Telugu'],
10174 ['Tifinagh', 'Tifinagh'],
10175 ['Tagalog', 'Tagalog'],
10176 ['Thaana', 'Thaana'],
10177 ['Tibetan', 'Tibetan'],
10178 ['Tirhuta', 'Tirhuta'],
10179 ['Ugaritic', 'Ugaritic'],
10180 ['Vai', 'Vai'],
10181 ['Warang_Citi', 'Warang_Citi'],
10182 ['Old_Persian', 'Old_Persian'],
10183 ['Cuneiform', 'Cuneiform'],
10184 ['Yi', 'Yi'],
10185 ['Zanabazar_Square', 'Zanabazar_Square'],
10186 ['Inherited', 'Inherited'],
10187 ['Common', 'Common'],
10188 ['Unknown', 'Unknown']
10189 ])]
10190]);
10191
10192'use strict';
10193
10194
10195
10196const matchPropertyValue = function(property, value) {
10197 const aliasToValue = mappings.get(property);
10198 if (!aliasToValue) {
10199 throw new Error(`Unknown property \`${ property }\`.`);
10200 }
10201 const canonicalValue = aliasToValue.get(value);
10202 if (canonicalValue) {
10203 return canonicalValue;
10204 }
10205 throw new Error(
10206 `Unknown value \`${ value }\` for property \`${ property }\`.`
10207 );
10208};
10209
10210var unicodeMatchPropertyValueEcmascript = matchPropertyValue;
10211
10212var iuMappings = new Map([
10213 [0x4B, 0x212A],
10214 [0x53, 0x17F],
10215 [0x6B, 0x212A],
10216 [0x73, 0x17F],
10217 [0xB5, 0x39C],
10218 [0xC5, 0x212B],
10219 [0xDF, 0x1E9E],
10220 [0xE5, 0x212B],
10221 [0x17F, 0x53],
10222 [0x1C4, 0x1C5],
10223 [0x1C5, 0x1C4],
10224 [0x1C7, 0x1C8],
10225 [0x1C8, 0x1C7],
10226 [0x1CA, 0x1CB],
10227 [0x1CB, 0x1CA],
10228 [0x1F1, 0x1F2],
10229 [0x1F2, 0x1F1],
10230 [0x26A, 0xA7AE],
10231 [0x29D, 0xA7B2],
10232 [0x345, 0x1FBE],
10233 [0x392, 0x3D0],
10234 [0x395, 0x3F5],
10235 [0x398, 0x3F4],
10236 [0x399, 0x1FBE],
10237 [0x39A, 0x3F0],
10238 [0x39C, 0xB5],
10239 [0x3A0, 0x3D6],
10240 [0x3A1, 0x3F1],
10241 [0x3A3, 0x3C2],
10242 [0x3A6, 0x3D5],
10243 [0x3A9, 0x2126],
10244 [0x3B8, 0x3F4],
10245 [0x3C2, 0x3A3],
10246 [0x3C9, 0x2126],
10247 [0x3D0, 0x392],
10248 [0x3D1, 0x3F4],
10249 [0x3D5, 0x3A6],
10250 [0x3D6, 0x3A0],
10251 [0x3F0, 0x39A],
10252 [0x3F1, 0x3A1],
10253 [0x3F4, [
10254 0x398,
10255 0x3D1,
10256 0x3B8
10257 ]],
10258 [0x3F5, 0x395],
10259 [0x412, 0x1C80],
10260 [0x414, 0x1C81],
10261 [0x41E, 0x1C82],
10262 [0x421, 0x1C83],
10263 [0x422, 0x1C85],
10264 [0x42A, 0x1C86],
10265 [0x432, 0x1C80],
10266 [0x434, 0x1C81],
10267 [0x43E, 0x1C82],
10268 [0x441, 0x1C83],
10269 [0x442, [
10270 0x1C84,
10271 0x1C85
10272 ]],
10273 [0x44A, 0x1C86],
10274 [0x462, 0x1C87],
10275 [0x463, 0x1C87],
10276 [0x13A0, 0xAB70],
10277 [0x13A1, 0xAB71],
10278 [0x13A2, 0xAB72],
10279 [0x13A3, 0xAB73],
10280 [0x13A4, 0xAB74],
10281 [0x13A5, 0xAB75],
10282 [0x13A6, 0xAB76],
10283 [0x13A7, 0xAB77],
10284 [0x13A8, 0xAB78],
10285 [0x13A9, 0xAB79],
10286 [0x13AA, 0xAB7A],
10287 [0x13AB, 0xAB7B],
10288 [0x13AC, 0xAB7C],
10289 [0x13AD, 0xAB7D],
10290 [0x13AE, 0xAB7E],
10291 [0x13AF, 0xAB7F],
10292 [0x13B0, 0xAB80],
10293 [0x13B1, 0xAB81],
10294 [0x13B2, 0xAB82],
10295 [0x13B3, 0xAB83],
10296 [0x13B4, 0xAB84],
10297 [0x13B5, 0xAB85],
10298 [0x13B6, 0xAB86],
10299 [0x13B7, 0xAB87],
10300 [0x13B8, 0xAB88],
10301 [0x13B9, 0xAB89],
10302 [0x13BA, 0xAB8A],
10303 [0x13BB, 0xAB8B],
10304 [0x13BC, 0xAB8C],
10305 [0x13BD, 0xAB8D],
10306 [0x13BE, 0xAB8E],
10307 [0x13BF, 0xAB8F],
10308 [0x13C0, 0xAB90],
10309 [0x13C1, 0xAB91],
10310 [0x13C2, 0xAB92],
10311 [0x13C3, 0xAB93],
10312 [0x13C4, 0xAB94],
10313 [0x13C5, 0xAB95],
10314 [0x13C6, 0xAB96],
10315 [0x13C7, 0xAB97],
10316 [0x13C8, 0xAB98],
10317 [0x13C9, 0xAB99],
10318 [0x13CA, 0xAB9A],
10319 [0x13CB, 0xAB9B],
10320 [0x13CC, 0xAB9C],
10321 [0x13CD, 0xAB9D],
10322 [0x13CE, 0xAB9E],
10323 [0x13CF, 0xAB9F],
10324 [0x13D0, 0xABA0],
10325 [0x13D1, 0xABA1],
10326 [0x13D2, 0xABA2],
10327 [0x13D3, 0xABA3],
10328 [0x13D4, 0xABA4],
10329 [0x13D5, 0xABA5],
10330 [0x13D6, 0xABA6],
10331 [0x13D7, 0xABA7],
10332 [0x13D8, 0xABA8],
10333 [0x13D9, 0xABA9],
10334 [0x13DA, 0xABAA],
10335 [0x13DB, 0xABAB],
10336 [0x13DC, 0xABAC],
10337 [0x13DD, 0xABAD],
10338 [0x13DE, 0xABAE],
10339 [0x13DF, 0xABAF],
10340 [0x13E0, 0xABB0],
10341 [0x13E1, 0xABB1],
10342 [0x13E2, 0xABB2],
10343 [0x13E3, 0xABB3],
10344 [0x13E4, 0xABB4],
10345 [0x13E5, 0xABB5],
10346 [0x13E6, 0xABB6],
10347 [0x13E7, 0xABB7],
10348 [0x13E8, 0xABB8],
10349 [0x13E9, 0xABB9],
10350 [0x13EA, 0xABBA],
10351 [0x13EB, 0xABBB],
10352 [0x13EC, 0xABBC],
10353 [0x13ED, 0xABBD],
10354 [0x13EE, 0xABBE],
10355 [0x13EF, 0xABBF],
10356 [0x13F0, 0x13F8],
10357 [0x13F1, 0x13F9],
10358 [0x13F2, 0x13FA],
10359 [0x13F3, 0x13FB],
10360 [0x13F4, 0x13FC],
10361 [0x13F5, 0x13FD],
10362 [0x13F8, 0x13F0],
10363 [0x13F9, 0x13F1],
10364 [0x13FA, 0x13F2],
10365 [0x13FB, 0x13F3],
10366 [0x13FC, 0x13F4],
10367 [0x13FD, 0x13F5],
10368 [0x1C80, [
10369 0x412,
10370 0x432
10371 ]],
10372 [0x1C81, [
10373 0x414,
10374 0x434
10375 ]],
10376 [0x1C82, [
10377 0x41E,
10378 0x43E
10379 ]],
10380 [0x1C83, [
10381 0x421,
10382 0x441
10383 ]],
10384 [0x1C84, [
10385 0x1C85,
10386 0x442
10387 ]],
10388 [0x1C85, [
10389 0x422,
10390 0x1C84,
10391 0x442
10392 ]],
10393 [0x1C86, [
10394 0x42A,
10395 0x44A
10396 ]],
10397 [0x1C87, [
10398 0x462,
10399 0x463
10400 ]],
10401 [0x1C88, [
10402 0xA64A,
10403 0xA64B
10404 ]],
10405 [0x1E60, 0x1E9B],
10406 [0x1E9B, 0x1E60],
10407 [0x1E9E, 0xDF],
10408 [0x1F80, 0x1F88],
10409 [0x1F81, 0x1F89],
10410 [0x1F82, 0x1F8A],
10411 [0x1F83, 0x1F8B],
10412 [0x1F84, 0x1F8C],
10413 [0x1F85, 0x1F8D],
10414 [0x1F86, 0x1F8E],
10415 [0x1F87, 0x1F8F],
10416 [0x1F88, 0x1F80],
10417 [0x1F89, 0x1F81],
10418 [0x1F8A, 0x1F82],
10419 [0x1F8B, 0x1F83],
10420 [0x1F8C, 0x1F84],
10421 [0x1F8D, 0x1F85],
10422 [0x1F8E, 0x1F86],
10423 [0x1F8F, 0x1F87],
10424 [0x1F90, 0x1F98],
10425 [0x1F91, 0x1F99],
10426 [0x1F92, 0x1F9A],
10427 [0x1F93, 0x1F9B],
10428 [0x1F94, 0x1F9C],
10429 [0x1F95, 0x1F9D],
10430 [0x1F96, 0x1F9E],
10431 [0x1F97, 0x1F9F],
10432 [0x1F98, 0x1F90],
10433 [0x1F99, 0x1F91],
10434 [0x1F9A, 0x1F92],
10435 [0x1F9B, 0x1F93],
10436 [0x1F9C, 0x1F94],
10437 [0x1F9D, 0x1F95],
10438 [0x1F9E, 0x1F96],
10439 [0x1F9F, 0x1F97],
10440 [0x1FA0, 0x1FA8],
10441 [0x1FA1, 0x1FA9],
10442 [0x1FA2, 0x1FAA],
10443 [0x1FA3, 0x1FAB],
10444 [0x1FA4, 0x1FAC],
10445 [0x1FA5, 0x1FAD],
10446 [0x1FA6, 0x1FAE],
10447 [0x1FA7, 0x1FAF],
10448 [0x1FA8, 0x1FA0],
10449 [0x1FA9, 0x1FA1],
10450 [0x1FAA, 0x1FA2],
10451 [0x1FAB, 0x1FA3],
10452 [0x1FAC, 0x1FA4],
10453 [0x1FAD, 0x1FA5],
10454 [0x1FAE, 0x1FA6],
10455 [0x1FAF, 0x1FA7],
10456 [0x1FB3, 0x1FBC],
10457 [0x1FBC, 0x1FB3],
10458 [0x1FBE, [
10459 0x345,
10460 0x399
10461 ]],
10462 [0x1FC3, 0x1FCC],
10463 [0x1FCC, 0x1FC3],
10464 [0x1FF3, 0x1FFC],
10465 [0x1FFC, 0x1FF3],
10466 [0x2126, [
10467 0x3A9,
10468 0x3C9
10469 ]],
10470 [0x212A, 0x4B],
10471 [0x212B, [
10472 0xC5,
10473 0xE5
10474 ]],
10475 [0xA64A, 0x1C88],
10476 [0xA64B, 0x1C88],
10477 [0xA7AE, 0x26A],
10478 [0xA7B2, 0x29D],
10479 [0xA7B3, 0xAB53],
10480 [0xA7B4, 0xA7B5],
10481 [0xA7B5, 0xA7B4],
10482 [0xA7B6, 0xA7B7],
10483 [0xA7B7, 0xA7B6],
10484 [0xAB53, 0xA7B3],
10485 [0xAB70, 0x13A0],
10486 [0xAB71, 0x13A1],
10487 [0xAB72, 0x13A2],
10488 [0xAB73, 0x13A3],
10489 [0xAB74, 0x13A4],
10490 [0xAB75, 0x13A5],
10491 [0xAB76, 0x13A6],
10492 [0xAB77, 0x13A7],
10493 [0xAB78, 0x13A8],
10494 [0xAB79, 0x13A9],
10495 [0xAB7A, 0x13AA],
10496 [0xAB7B, 0x13AB],
10497 [0xAB7C, 0x13AC],
10498 [0xAB7D, 0x13AD],
10499 [0xAB7E, 0x13AE],
10500 [0xAB7F, 0x13AF],
10501 [0xAB80, 0x13B0],
10502 [0xAB81, 0x13B1],
10503 [0xAB82, 0x13B2],
10504 [0xAB83, 0x13B3],
10505 [0xAB84, 0x13B4],
10506 [0xAB85, 0x13B5],
10507 [0xAB86, 0x13B6],
10508 [0xAB87, 0x13B7],
10509 [0xAB88, 0x13B8],
10510 [0xAB89, 0x13B9],
10511 [0xAB8A, 0x13BA],
10512 [0xAB8B, 0x13BB],
10513 [0xAB8C, 0x13BC],
10514 [0xAB8D, 0x13BD],
10515 [0xAB8E, 0x13BE],
10516 [0xAB8F, 0x13BF],
10517 [0xAB90, 0x13C0],
10518 [0xAB91, 0x13C1],
10519 [0xAB92, 0x13C2],
10520 [0xAB93, 0x13C3],
10521 [0xAB94, 0x13C4],
10522 [0xAB95, 0x13C5],
10523 [0xAB96, 0x13C6],
10524 [0xAB97, 0x13C7],
10525 [0xAB98, 0x13C8],
10526 [0xAB99, 0x13C9],
10527 [0xAB9A, 0x13CA],
10528 [0xAB9B, 0x13CB],
10529 [0xAB9C, 0x13CC],
10530 [0xAB9D, 0x13CD],
10531 [0xAB9E, 0x13CE],
10532 [0xAB9F, 0x13CF],
10533 [0xABA0, 0x13D0],
10534 [0xABA1, 0x13D1],
10535 [0xABA2, 0x13D2],
10536 [0xABA3, 0x13D3],
10537 [0xABA4, 0x13D4],
10538 [0xABA5, 0x13D5],
10539 [0xABA6, 0x13D6],
10540 [0xABA7, 0x13D7],
10541 [0xABA8, 0x13D8],
10542 [0xABA9, 0x13D9],
10543 [0xABAA, 0x13DA],
10544 [0xABAB, 0x13DB],
10545 [0xABAC, 0x13DC],
10546 [0xABAD, 0x13DD],
10547 [0xABAE, 0x13DE],
10548 [0xABAF, 0x13DF],
10549 [0xABB0, 0x13E0],
10550 [0xABB1, 0x13E1],
10551 [0xABB2, 0x13E2],
10552 [0xABB3, 0x13E3],
10553 [0xABB4, 0x13E4],
10554 [0xABB5, 0x13E5],
10555 [0xABB6, 0x13E6],
10556 [0xABB7, 0x13E7],
10557 [0xABB8, 0x13E8],
10558 [0xABB9, 0x13E9],
10559 [0xABBA, 0x13EA],
10560 [0xABBB, 0x13EB],
10561 [0xABBC, 0x13EC],
10562 [0xABBD, 0x13ED],
10563 [0xABBE, 0x13EE],
10564 [0xABBF, 0x13EF],
10565 [0x10400, 0x10428],
10566 [0x10401, 0x10429],
10567 [0x10402, 0x1042A],
10568 [0x10403, 0x1042B],
10569 [0x10404, 0x1042C],
10570 [0x10405, 0x1042D],
10571 [0x10406, 0x1042E],
10572 [0x10407, 0x1042F],
10573 [0x10408, 0x10430],
10574 [0x10409, 0x10431],
10575 [0x1040A, 0x10432],
10576 [0x1040B, 0x10433],
10577 [0x1040C, 0x10434],
10578 [0x1040D, 0x10435],
10579 [0x1040E, 0x10436],
10580 [0x1040F, 0x10437],
10581 [0x10410, 0x10438],
10582 [0x10411, 0x10439],
10583 [0x10412, 0x1043A],
10584 [0x10413, 0x1043B],
10585 [0x10414, 0x1043C],
10586 [0x10415, 0x1043D],
10587 [0x10416, 0x1043E],
10588 [0x10417, 0x1043F],
10589 [0x10418, 0x10440],
10590 [0x10419, 0x10441],
10591 [0x1041A, 0x10442],
10592 [0x1041B, 0x10443],
10593 [0x1041C, 0x10444],
10594 [0x1041D, 0x10445],
10595 [0x1041E, 0x10446],
10596 [0x1041F, 0x10447],
10597 [0x10420, 0x10448],
10598 [0x10421, 0x10449],
10599 [0x10422, 0x1044A],
10600 [0x10423, 0x1044B],
10601 [0x10424, 0x1044C],
10602 [0x10425, 0x1044D],
10603 [0x10426, 0x1044E],
10604 [0x10427, 0x1044F],
10605 [0x10428, 0x10400],
10606 [0x10429, 0x10401],
10607 [0x1042A, 0x10402],
10608 [0x1042B, 0x10403],
10609 [0x1042C, 0x10404],
10610 [0x1042D, 0x10405],
10611 [0x1042E, 0x10406],
10612 [0x1042F, 0x10407],
10613 [0x10430, 0x10408],
10614 [0x10431, 0x10409],
10615 [0x10432, 0x1040A],
10616 [0x10433, 0x1040B],
10617 [0x10434, 0x1040C],
10618 [0x10435, 0x1040D],
10619 [0x10436, 0x1040E],
10620 [0x10437, 0x1040F],
10621 [0x10438, 0x10410],
10622 [0x10439, 0x10411],
10623 [0x1043A, 0x10412],
10624 [0x1043B, 0x10413],
10625 [0x1043C, 0x10414],
10626 [0x1043D, 0x10415],
10627 [0x1043E, 0x10416],
10628 [0x1043F, 0x10417],
10629 [0x10440, 0x10418],
10630 [0x10441, 0x10419],
10631 [0x10442, 0x1041A],
10632 [0x10443, 0x1041B],
10633 [0x10444, 0x1041C],
10634 [0x10445, 0x1041D],
10635 [0x10446, 0x1041E],
10636 [0x10447, 0x1041F],
10637 [0x10448, 0x10420],
10638 [0x10449, 0x10421],
10639 [0x1044A, 0x10422],
10640 [0x1044B, 0x10423],
10641 [0x1044C, 0x10424],
10642 [0x1044D, 0x10425],
10643 [0x1044E, 0x10426],
10644 [0x1044F, 0x10427],
10645 [0x104B0, 0x104D8],
10646 [0x104B1, 0x104D9],
10647 [0x104B2, 0x104DA],
10648 [0x104B3, 0x104DB],
10649 [0x104B4, 0x104DC],
10650 [0x104B5, 0x104DD],
10651 [0x104B6, 0x104DE],
10652 [0x104B7, 0x104DF],
10653 [0x104B8, 0x104E0],
10654 [0x104B9, 0x104E1],
10655 [0x104BA, 0x104E2],
10656 [0x104BB, 0x104E3],
10657 [0x104BC, 0x104E4],
10658 [0x104BD, 0x104E5],
10659 [0x104BE, 0x104E6],
10660 [0x104BF, 0x104E7],
10661 [0x104C0, 0x104E8],
10662 [0x104C1, 0x104E9],
10663 [0x104C2, 0x104EA],
10664 [0x104C3, 0x104EB],
10665 [0x104C4, 0x104EC],
10666 [0x104C5, 0x104ED],
10667 [0x104C6, 0x104EE],
10668 [0x104C7, 0x104EF],
10669 [0x104C8, 0x104F0],
10670 [0x104C9, 0x104F1],
10671 [0x104CA, 0x104F2],
10672 [0x104CB, 0x104F3],
10673 [0x104CC, 0x104F4],
10674 [0x104CD, 0x104F5],
10675 [0x104CE, 0x104F6],
10676 [0x104CF, 0x104F7],
10677 [0x104D0, 0x104F8],
10678 [0x104D1, 0x104F9],
10679 [0x104D2, 0x104FA],
10680 [0x104D3, 0x104FB],
10681 [0x104D8, 0x104B0],
10682 [0x104D9, 0x104B1],
10683 [0x104DA, 0x104B2],
10684 [0x104DB, 0x104B3],
10685 [0x104DC, 0x104B4],
10686 [0x104DD, 0x104B5],
10687 [0x104DE, 0x104B6],
10688 [0x104DF, 0x104B7],
10689 [0x104E0, 0x104B8],
10690 [0x104E1, 0x104B9],
10691 [0x104E2, 0x104BA],
10692 [0x104E3, 0x104BB],
10693 [0x104E4, 0x104BC],
10694 [0x104E5, 0x104BD],
10695 [0x104E6, 0x104BE],
10696 [0x104E7, 0x104BF],
10697 [0x104E8, 0x104C0],
10698 [0x104E9, 0x104C1],
10699 [0x104EA, 0x104C2],
10700 [0x104EB, 0x104C3],
10701 [0x104EC, 0x104C4],
10702 [0x104ED, 0x104C5],
10703 [0x104EE, 0x104C6],
10704 [0x104EF, 0x104C7],
10705 [0x104F0, 0x104C8],
10706 [0x104F1, 0x104C9],
10707 [0x104F2, 0x104CA],
10708 [0x104F3, 0x104CB],
10709 [0x104F4, 0x104CC],
10710 [0x104F5, 0x104CD],
10711 [0x104F6, 0x104CE],
10712 [0x104F7, 0x104CF],
10713 [0x104F8, 0x104D0],
10714 [0x104F9, 0x104D1],
10715 [0x104FA, 0x104D2],
10716 [0x104FB, 0x104D3],
10717 [0x10C80, 0x10CC0],
10718 [0x10C81, 0x10CC1],
10719 [0x10C82, 0x10CC2],
10720 [0x10C83, 0x10CC3],
10721 [0x10C84, 0x10CC4],
10722 [0x10C85, 0x10CC5],
10723 [0x10C86, 0x10CC6],
10724 [0x10C87, 0x10CC7],
10725 [0x10C88, 0x10CC8],
10726 [0x10C89, 0x10CC9],
10727 [0x10C8A, 0x10CCA],
10728 [0x10C8B, 0x10CCB],
10729 [0x10C8C, 0x10CCC],
10730 [0x10C8D, 0x10CCD],
10731 [0x10C8E, 0x10CCE],
10732 [0x10C8F, 0x10CCF],
10733 [0x10C90, 0x10CD0],
10734 [0x10C91, 0x10CD1],
10735 [0x10C92, 0x10CD2],
10736 [0x10C93, 0x10CD3],
10737 [0x10C94, 0x10CD4],
10738 [0x10C95, 0x10CD5],
10739 [0x10C96, 0x10CD6],
10740 [0x10C97, 0x10CD7],
10741 [0x10C98, 0x10CD8],
10742 [0x10C99, 0x10CD9],
10743 [0x10C9A, 0x10CDA],
10744 [0x10C9B, 0x10CDB],
10745 [0x10C9C, 0x10CDC],
10746 [0x10C9D, 0x10CDD],
10747 [0x10C9E, 0x10CDE],
10748 [0x10C9F, 0x10CDF],
10749 [0x10CA0, 0x10CE0],
10750 [0x10CA1, 0x10CE1],
10751 [0x10CA2, 0x10CE2],
10752 [0x10CA3, 0x10CE3],
10753 [0x10CA4, 0x10CE4],
10754 [0x10CA5, 0x10CE5],
10755 [0x10CA6, 0x10CE6],
10756 [0x10CA7, 0x10CE7],
10757 [0x10CA8, 0x10CE8],
10758 [0x10CA9, 0x10CE9],
10759 [0x10CAA, 0x10CEA],
10760 [0x10CAB, 0x10CEB],
10761 [0x10CAC, 0x10CEC],
10762 [0x10CAD, 0x10CED],
10763 [0x10CAE, 0x10CEE],
10764 [0x10CAF, 0x10CEF],
10765 [0x10CB0, 0x10CF0],
10766 [0x10CB1, 0x10CF1],
10767 [0x10CB2, 0x10CF2],
10768 [0x10CC0, 0x10C80],
10769 [0x10CC1, 0x10C81],
10770 [0x10CC2, 0x10C82],
10771 [0x10CC3, 0x10C83],
10772 [0x10CC4, 0x10C84],
10773 [0x10CC5, 0x10C85],
10774 [0x10CC6, 0x10C86],
10775 [0x10CC7, 0x10C87],
10776 [0x10CC8, 0x10C88],
10777 [0x10CC9, 0x10C89],
10778 [0x10CCA, 0x10C8A],
10779 [0x10CCB, 0x10C8B],
10780 [0x10CCC, 0x10C8C],
10781 [0x10CCD, 0x10C8D],
10782 [0x10CCE, 0x10C8E],
10783 [0x10CCF, 0x10C8F],
10784 [0x10CD0, 0x10C90],
10785 [0x10CD1, 0x10C91],
10786 [0x10CD2, 0x10C92],
10787 [0x10CD3, 0x10C93],
10788 [0x10CD4, 0x10C94],
10789 [0x10CD5, 0x10C95],
10790 [0x10CD6, 0x10C96],
10791 [0x10CD7, 0x10C97],
10792 [0x10CD8, 0x10C98],
10793 [0x10CD9, 0x10C99],
10794 [0x10CDA, 0x10C9A],
10795 [0x10CDB, 0x10C9B],
10796 [0x10CDC, 0x10C9C],
10797 [0x10CDD, 0x10C9D],
10798 [0x10CDE, 0x10C9E],
10799 [0x10CDF, 0x10C9F],
10800 [0x10CE0, 0x10CA0],
10801 [0x10CE1, 0x10CA1],
10802 [0x10CE2, 0x10CA2],
10803 [0x10CE3, 0x10CA3],
10804 [0x10CE4, 0x10CA4],
10805 [0x10CE5, 0x10CA5],
10806 [0x10CE6, 0x10CA6],
10807 [0x10CE7, 0x10CA7],
10808 [0x10CE8, 0x10CA8],
10809 [0x10CE9, 0x10CA9],
10810 [0x10CEA, 0x10CAA],
10811 [0x10CEB, 0x10CAB],
10812 [0x10CEC, 0x10CAC],
10813 [0x10CED, 0x10CAD],
10814 [0x10CEE, 0x10CAE],
10815 [0x10CEF, 0x10CAF],
10816 [0x10CF0, 0x10CB0],
10817 [0x10CF1, 0x10CB1],
10818 [0x10CF2, 0x10CB2],
10819 [0x118A0, 0x118C0],
10820 [0x118A1, 0x118C1],
10821 [0x118A2, 0x118C2],
10822 [0x118A3, 0x118C3],
10823 [0x118A4, 0x118C4],
10824 [0x118A5, 0x118C5],
10825 [0x118A6, 0x118C6],
10826 [0x118A7, 0x118C7],
10827 [0x118A8, 0x118C8],
10828 [0x118A9, 0x118C9],
10829 [0x118AA, 0x118CA],
10830 [0x118AB, 0x118CB],
10831 [0x118AC, 0x118CC],
10832 [0x118AD, 0x118CD],
10833 [0x118AE, 0x118CE],
10834 [0x118AF, 0x118CF],
10835 [0x118B0, 0x118D0],
10836 [0x118B1, 0x118D1],
10837 [0x118B2, 0x118D2],
10838 [0x118B3, 0x118D3],
10839 [0x118B4, 0x118D4],
10840 [0x118B5, 0x118D5],
10841 [0x118B6, 0x118D6],
10842 [0x118B7, 0x118D7],
10843 [0x118B8, 0x118D8],
10844 [0x118B9, 0x118D9],
10845 [0x118BA, 0x118DA],
10846 [0x118BB, 0x118DB],
10847 [0x118BC, 0x118DC],
10848 [0x118BD, 0x118DD],
10849 [0x118BE, 0x118DE],
10850 [0x118BF, 0x118DF],
10851 [0x118C0, 0x118A0],
10852 [0x118C1, 0x118A1],
10853 [0x118C2, 0x118A2],
10854 [0x118C3, 0x118A3],
10855 [0x118C4, 0x118A4],
10856 [0x118C5, 0x118A5],
10857 [0x118C6, 0x118A6],
10858 [0x118C7, 0x118A7],
10859 [0x118C8, 0x118A8],
10860 [0x118C9, 0x118A9],
10861 [0x118CA, 0x118AA],
10862 [0x118CB, 0x118AB],
10863 [0x118CC, 0x118AC],
10864 [0x118CD, 0x118AD],
10865 [0x118CE, 0x118AE],
10866 [0x118CF, 0x118AF],
10867 [0x118D0, 0x118B0],
10868 [0x118D1, 0x118B1],
10869 [0x118D2, 0x118B2],
10870 [0x118D3, 0x118B3],
10871 [0x118D4, 0x118B4],
10872 [0x118D5, 0x118B5],
10873 [0x118D6, 0x118B6],
10874 [0x118D7, 0x118B7],
10875 [0x118D8, 0x118B8],
10876 [0x118D9, 0x118B9],
10877 [0x118DA, 0x118BA],
10878 [0x118DB, 0x118BB],
10879 [0x118DC, 0x118BC],
10880 [0x118DD, 0x118BD],
10881 [0x118DE, 0x118BE],
10882 [0x118DF, 0x118BF],
10883 [0x1E900, 0x1E922],
10884 [0x1E901, 0x1E923],
10885 [0x1E902, 0x1E924],
10886 [0x1E903, 0x1E925],
10887 [0x1E904, 0x1E926],
10888 [0x1E905, 0x1E927],
10889 [0x1E906, 0x1E928],
10890 [0x1E907, 0x1E929],
10891 [0x1E908, 0x1E92A],
10892 [0x1E909, 0x1E92B],
10893 [0x1E90A, 0x1E92C],
10894 [0x1E90B, 0x1E92D],
10895 [0x1E90C, 0x1E92E],
10896 [0x1E90D, 0x1E92F],
10897 [0x1E90E, 0x1E930],
10898 [0x1E90F, 0x1E931],
10899 [0x1E910, 0x1E932],
10900 [0x1E911, 0x1E933],
10901 [0x1E912, 0x1E934],
10902 [0x1E913, 0x1E935],
10903 [0x1E914, 0x1E936],
10904 [0x1E915, 0x1E937],
10905 [0x1E916, 0x1E938],
10906 [0x1E917, 0x1E939],
10907 [0x1E918, 0x1E93A],
10908 [0x1E919, 0x1E93B],
10909 [0x1E91A, 0x1E93C],
10910 [0x1E91B, 0x1E93D],
10911 [0x1E91C, 0x1E93E],
10912 [0x1E91D, 0x1E93F],
10913 [0x1E91E, 0x1E940],
10914 [0x1E91F, 0x1E941],
10915 [0x1E920, 0x1E942],
10916 [0x1E921, 0x1E943],
10917 [0x1E922, 0x1E900],
10918 [0x1E923, 0x1E901],
10919 [0x1E924, 0x1E902],
10920 [0x1E925, 0x1E903],
10921 [0x1E926, 0x1E904],
10922 [0x1E927, 0x1E905],
10923 [0x1E928, 0x1E906],
10924 [0x1E929, 0x1E907],
10925 [0x1E92A, 0x1E908],
10926 [0x1E92B, 0x1E909],
10927 [0x1E92C, 0x1E90A],
10928 [0x1E92D, 0x1E90B],
10929 [0x1E92E, 0x1E90C],
10930 [0x1E92F, 0x1E90D],
10931 [0x1E930, 0x1E90E],
10932 [0x1E931, 0x1E90F],
10933 [0x1E932, 0x1E910],
10934 [0x1E933, 0x1E911],
10935 [0x1E934, 0x1E912],
10936 [0x1E935, 0x1E913],
10937 [0x1E936, 0x1E914],
10938 [0x1E937, 0x1E915],
10939 [0x1E938, 0x1E916],
10940 [0x1E939, 0x1E917],
10941 [0x1E93A, 0x1E918],
10942 [0x1E93B, 0x1E919],
10943 [0x1E93C, 0x1E91A],
10944 [0x1E93D, 0x1E91B],
10945 [0x1E93E, 0x1E91C],
10946 [0x1E93F, 0x1E91D],
10947 [0x1E940, 0x1E91E],
10948 [0x1E941, 0x1E91F],
10949 [0x1E942, 0x1E920],
10950 [0x1E943, 0x1E921]
10951]);
10952
10953// Generated using `npm run build`. Do not edit.
10954'use strict';
10955
10956
10957
10958var REGULAR = new Map([
10959 ['d', regenerate()
10960 .addRange(0x30, 0x39)],
10961 ['D', regenerate()
10962 .addRange(0x0, 0x2F)
10963 .addRange(0x3A, 0xFFFF)],
10964 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
10965 .addRange(0x9, 0xD)
10966 .addRange(0x2000, 0x200A)
10967 .addRange(0x2028, 0x2029)],
10968 ['S', regenerate()
10969 .addRange(0x0, 0x8)
10970 .addRange(0xE, 0x1F)
10971 .addRange(0x21, 0x9F)
10972 .addRange(0xA1, 0x167F)
10973 .addRange(0x1681, 0x1FFF)
10974 .addRange(0x200B, 0x2027)
10975 .addRange(0x202A, 0x202E)
10976 .addRange(0x2030, 0x205E)
10977 .addRange(0x2060, 0x2FFF)
10978 .addRange(0x3001, 0xFEFE)
10979 .addRange(0xFF00, 0xFFFF)],
10980 ['w', regenerate(0x5F)
10981 .addRange(0x30, 0x39)
10982 .addRange(0x41, 0x5A)
10983 .addRange(0x61, 0x7A)],
10984 ['W', regenerate(0x60)
10985 .addRange(0x0, 0x2F)
10986 .addRange(0x3A, 0x40)
10987 .addRange(0x5B, 0x5E)
10988 .addRange(0x7B, 0xFFFF)]
10989]);
10990
10991var UNICODE = new Map([
10992 ['d', regenerate()
10993 .addRange(0x30, 0x39)],
10994 ['D', regenerate()
10995 .addRange(0x0, 0x2F)
10996 .addRange(0x3A, 0x10FFFF)],
10997 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
10998 .addRange(0x9, 0xD)
10999 .addRange(0x2000, 0x200A)
11000 .addRange(0x2028, 0x2029)],
11001 ['S', regenerate()
11002 .addRange(0x0, 0x8)
11003 .addRange(0xE, 0x1F)
11004 .addRange(0x21, 0x9F)
11005 .addRange(0xA1, 0x167F)
11006 .addRange(0x1681, 0x1FFF)
11007 .addRange(0x200B, 0x2027)
11008 .addRange(0x202A, 0x202E)
11009 .addRange(0x2030, 0x205E)
11010 .addRange(0x2060, 0x2FFF)
11011 .addRange(0x3001, 0xFEFE)
11012 .addRange(0xFF00, 0x10FFFF)],
11013 ['w', regenerate(0x5F)
11014 .addRange(0x30, 0x39)
11015 .addRange(0x41, 0x5A)
11016 .addRange(0x61, 0x7A)],
11017 ['W', regenerate(0x60)
11018 .addRange(0x0, 0x2F)
11019 .addRange(0x3A, 0x40)
11020 .addRange(0x5B, 0x5E)
11021 .addRange(0x7B, 0x10FFFF)]
11022]);
11023
11024var UNICODE_IGNORE_CASE = new Map([
11025 ['d', regenerate()
11026 .addRange(0x30, 0x39)],
11027 ['D', regenerate()
11028 .addRange(0x0, 0x2F)
11029 .addRange(0x3A, 0x10FFFF)],
11030 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
11031 .addRange(0x9, 0xD)
11032 .addRange(0x2000, 0x200A)
11033 .addRange(0x2028, 0x2029)],
11034 ['S', regenerate()
11035 .addRange(0x0, 0x8)
11036 .addRange(0xE, 0x1F)
11037 .addRange(0x21, 0x9F)
11038 .addRange(0xA1, 0x167F)
11039 .addRange(0x1681, 0x1FFF)
11040 .addRange(0x200B, 0x2027)
11041 .addRange(0x202A, 0x202E)
11042 .addRange(0x2030, 0x205E)
11043 .addRange(0x2060, 0x2FFF)
11044 .addRange(0x3001, 0xFEFE)
11045 .addRange(0xFF00, 0x10FFFF)],
11046 ['w', regenerate(0x5F, 0x17F, 0x212A)
11047 .addRange(0x30, 0x39)
11048 .addRange(0x41, 0x5A)
11049 .addRange(0x61, 0x7A)],
11050 ['W', regenerate(0x60)
11051 .addRange(0x0, 0x2F)
11052 .addRange(0x3A, 0x40)
11053 .addRange(0x5B, 0x5E)
11054 .addRange(0x7B, 0x17E)
11055 .addRange(0x180, 0x2129)
11056 .addRange(0x212B, 0x10FFFF)]
11057]);
11058
11059var characterClassEscapeSets = {
11060 REGULAR: REGULAR,
11061 UNICODE: UNICODE,
11062 UNICODE_IGNORE_CASE: UNICODE_IGNORE_CASE
11063};
11064
11065var rewritePattern_1 = createCommonjsModule(function (module) {
11066'use strict';
11067
11068var generate = regjsgen.generate;
11069var parse = parser.parse;
11070
11071
11072
11073
11074
11075
11076// Prepare a Regenerate set containing all code points, used for negative
11077// character classes (if any).
11078var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
11079// Without the `u` flag, the range stops at 0xFFFF.
11080// https://mths.be/es6#sec-pattern-semantics
11081var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
11082
11083// Prepare a Regenerate set containing all code points that are supposed to be
11084// matched by `/./u`. https://mths.be/es6#sec-atom
11085var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
11086 .remove(
11087 // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
11088 0x000A, // Line Feed <LF>
11089 0x000D, // Carriage Return <CR>
11090 0x2028, // Line Separator <LS>
11091 0x2029 // Paragraph Separator <PS>
11092 );
11093// Prepare a Regenerate set containing all code points that are supposed to be
11094// matched by `/./` (only BMP code points).
11095var DOT_SET = DOT_SET_UNICODE.clone()
11096 .intersection(BMP_SET);
11097
11098var getCharacterClassEscapeSet = function (character, unicode, ignoreCase) {
11099 if (unicode) {
11100 if (ignoreCase) {
11101 return characterClassEscapeSets.UNICODE_IGNORE_CASE.get(character);
11102 }
11103 return characterClassEscapeSets.UNICODE.get(character);
11104 }
11105 return characterClassEscapeSets.REGULAR.get(character);
11106};
11107
11108var getDotSet = function (unicode, dotAll) {
11109 if (dotAll) {
11110 return unicode ? UNICODE_SET : BMP_SET;
11111 }
11112 return unicode ? DOT_SET_UNICODE : DOT_SET;
11113};
11114
11115var getUnicodePropertyValueSet = function (property, value) {
11116 var path = value ?
11117 (property + "/" + value) :
11118 ("Binary_Property/" + property);
11119 try {
11120 return commonjsRequire(("regenerate-unicode-properties/" + path + ".js"));
11121 } catch (exception) {
11122 throw new Error(
11123 "Failed to recognize value `" + value + "` for property " +
11124 "`" + property + "`."
11125 );
11126 }
11127};
11128
11129var handleLoneUnicodePropertyNameOrValue = function (value) {
11130 // It could be a `General_Category` value or a binary property.
11131 // Note: `unicodeMatchPropertyValue` throws on invalid values.
11132 try {
11133 var property$1 = 'General_Category';
11134 var category = unicodeMatchPropertyValueEcmascript(property$1, value);
11135 return getUnicodePropertyValueSet(property$1, category);
11136 } catch (exception) {}
11137 // It’s not a `General_Category` value, so check if it’s a binary
11138 // property. Note: `unicodeMatchProperty` throws on invalid properties.
11139 var property = unicodeMatchPropertyEcmascript(value);
11140 return getUnicodePropertyValueSet(property);
11141};
11142
11143var getUnicodePropertyEscapeSet = function (value, isNegative) {
11144 var parts = value.split('=');
11145 var firstPart = parts[0];
11146 var set;
11147 if (parts.length == 1) {
11148 set = handleLoneUnicodePropertyNameOrValue(firstPart);
11149 } else {
11150 // The pattern consists of two parts, i.e. `Property=Value`.
11151 var property = unicodeMatchPropertyEcmascript(firstPart);
11152 var value$1 = unicodeMatchPropertyValueEcmascript(property, parts[1]);
11153 set = getUnicodePropertyValueSet(property, value$1);
11154 }
11155 if (isNegative) {
11156 return UNICODE_SET.clone().remove(set);
11157 }
11158 return set.clone();
11159};
11160
11161// Given a range of code points, add any case-folded code points in that range
11162// to a set.
11163regenerate.prototype.iuAddRange = function(min, max) {
11164 var $this = this;
11165 do {
11166 var folded = caseFold(min);
11167 if (folded) {
11168 $this.add(folded);
11169 }
11170 } while (++min <= max);
11171 return $this;
11172};
11173
11174var update = function (item, pattern) {
11175 var tree = parse(pattern, config.useUnicodeFlag ? 'u' : '');
11176 switch (tree.type) {
11177 case 'characterClass':
11178 case 'group':
11179 case 'value':
11180 // No wrapping needed.
11181 break;
11182 default:
11183 // Wrap the pattern in a non-capturing group.
11184 tree = wrap(tree, pattern);
11185 }
11186 Object.assign(item, tree);
11187};
11188
11189var wrap = function (tree, pattern) {
11190 // Wrap the pattern in a non-capturing group.
11191 return {
11192 'type': 'group',
11193 'behavior': 'ignore',
11194 'body': [tree],
11195 'raw': ("(?:" + pattern + ")")
11196 };
11197};
11198
11199var caseFold = function (codePoint) {
11200 return iuMappings.get(codePoint) || false;
11201};
11202
11203var processCharacterClass = function (characterClassItem, regenerateOptions) {
11204 var set = regenerate();
11205 for (var i = 0, list = characterClassItem.body; i < list.length; i += 1) {
11206 var item = list[i];
11207
11208 switch (item.type) {
11209 case 'value':
11210 set.add(item.codePoint);
11211 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11212 var folded = caseFold(item.codePoint);
11213 if (folded) {
11214 set.add(folded);
11215 }
11216 }
11217 break;
11218 case 'characterClassRange':
11219 var min = item.min.codePoint;
11220 var max = item.max.codePoint;
11221 set.addRange(min, max);
11222 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11223 set.iuAddRange(min, max);
11224 }
11225 break;
11226 case 'characterClassEscape':
11227 set.add(getCharacterClassEscapeSet(
11228 item.value,
11229 config.unicode,
11230 config.ignoreCase
11231 ));
11232 break;
11233 case 'unicodePropertyEscape':
11234 set.add(getUnicodePropertyEscapeSet(item.value, item.negative));
11235 break;
11236 // The `default` clause is only here as a safeguard; it should never be
11237 // reached. Code coverage tools should ignore it.
11238 /* istanbul ignore next */
11239 default:
11240 throw new Error(("Unknown term type: " + (item.type)));
11241 }
11242 }
11243 if (characterClassItem.negative) {
11244 set = (config.unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
11245 }
11246 update(characterClassItem, set.toString(regenerateOptions));
11247 return characterClassItem;
11248};
11249
11250var processTerm = function (item, regenerateOptions) {
11251 switch (item.type) {
11252 case 'dot':
11253 update(
11254 item,
11255 getDotSet(config.unicode, config.dotAll).toString(regenerateOptions)
11256 );
11257 break;
11258 case 'characterClass':
11259 item = processCharacterClass(item, regenerateOptions);
11260 break;
11261 case 'unicodePropertyEscape':
11262 update(
11263 item,
11264 getUnicodePropertyEscapeSet(item.value, item.negative)
11265 .toString(regenerateOptions)
11266 );
11267 break;
11268 case 'characterClassEscape':
11269 update(
11270 item,
11271 getCharacterClassEscapeSet(
11272 item.value,
11273 config.unicode,
11274 config.ignoreCase
11275 ).toString(regenerateOptions)
11276 );
11277 break;
11278 case 'alternative':
11279 case 'disjunction':
11280 case 'group':
11281 case 'quantifier':
11282 item.body = item.body.map(function ( term ) {
11283 return processTerm(term, regenerateOptions);
11284 });
11285 break;
11286 case 'value':
11287 var codePoint = item.codePoint;
11288 var set = regenerate(codePoint);
11289 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11290 var folded = caseFold(codePoint);
11291 if (folded) {
11292 set.add(folded);
11293 }
11294 }
11295 update(item, set.toString(regenerateOptions));
11296 break;
11297 case 'anchor':
11298 case 'empty':
11299 case 'group':
11300 case 'reference':
11301 // Nothing to do here.
11302 break;
11303 // The `default` clause is only here as a safeguard; it should never be
11304 // reached. Code coverage tools should ignore it.
11305 /* istanbul ignore next */
11306 default:
11307 throw new Error(("Unknown term type: " + (item.type)));
11308 }
11309 return item;
11310};
11311
11312var config = {
11313 'ignoreCase': false,
11314 'unicode': false,
11315 'dotAll': false,
11316 'useUnicodeFlag': false
11317};
11318var rewritePattern = function (pattern, flags, options) {
11319 var regjsparserFeatures = {
11320 'unicodePropertyEscape': options && options.unicodePropertyEscape
11321 };
11322 config.ignoreCase = flags && flags.includes('i');
11323 config.unicode = flags && flags.includes('u');
11324 var supportDotAllFlag = options && options.dotAllFlag;
11325 config.dotAll = supportDotAllFlag && flags && flags.includes('s');
11326 config.useUnicodeFlag = options && options.useUnicodeFlag;
11327 var regenerateOptions = {
11328 'hasUnicodeFlag': config.useUnicodeFlag,
11329 'bmpOnly': !config.unicode
11330 };
11331 var tree = parse(pattern, flags, regjsparserFeatures);
11332 // Note: `processTerm` mutates `tree`.
11333 processTerm(tree, regenerateOptions);
11334 return generate(tree);
11335};
11336
11337module.exports = rewritePattern;
11338});
11339
11340var Literal = (function (Node) {
11341 function Literal () {
11342 Node.apply(this, arguments);
11343 }
11344
11345 if ( Node ) Literal.__proto__ = Node;
11346 Literal.prototype = Object.create( Node && Node.prototype );
11347 Literal.prototype.constructor = Literal;
11348
11349 Literal.prototype.initialise = function initialise () {
11350 if ( typeof this.value === 'string' ) {
11351 this.program.indentExclusionElements.push( this );
11352 }
11353 };
11354
11355 Literal.prototype.transpile = function transpile ( code, transforms ) {
11356 if ( transforms.numericLiteral ) {
11357 var leading = this.raw.slice( 0, 2 );
11358 if ( leading === '0b' || leading === '0o' ) {
11359 code.overwrite( this.start, this.end, String( this.value ), {
11360 storeName: true,
11361 contentOnly: true
11362 });
11363 }
11364 }
11365
11366 if ( this.regex ) {
11367 var ref = this.regex;
11368 var pattern = ref.pattern;
11369 var flags = ref.flags;
11370
11371 if ( transforms.stickyRegExp && /y/.test( flags ) ) throw new CompileError$1( 'Regular expression sticky flag is not supported', this );
11372 if ( transforms.unicodeRegExp && /u/.test( flags ) ) {
11373 code.overwrite( this.start, this.end, ("/" + (rewritePattern_1( pattern, flags )) + "/" + (flags.replace( 'u', '' ))), {
11374 contentOnly: true
11375 });
11376 }
11377 }
11378 };
11379
11380 return Literal;
11381}(Node$1));
11382
11383var MemberExpression = (function (Node) {
11384 function MemberExpression () {
11385 Node.apply(this, arguments);
11386 }
11387
11388 if ( Node ) MemberExpression.__proto__ = Node;
11389 MemberExpression.prototype = Object.create( Node && Node.prototype );
11390 MemberExpression.prototype.constructor = MemberExpression;
11391
11392 MemberExpression.prototype.transpile = function transpile ( code, transforms ) {
11393 if ( transforms.reservedProperties && reserved[ this.property.name ] ) {
11394 code.overwrite( this.object.end, this.property.start, "['" );
11395 code.appendLeft( this.property.end, "']" );
11396 }
11397
11398 Node.prototype.transpile.call( this, code, transforms );
11399 };
11400
11401 return MemberExpression;
11402}(Node$1));
11403
11404var NewExpression = (function (Node) {
11405 function NewExpression () {
11406 Node.apply(this, arguments);
11407 }
11408
11409 if ( Node ) NewExpression.__proto__ = Node;
11410 NewExpression.prototype = Object.create( Node && Node.prototype );
11411 NewExpression.prototype.constructor = NewExpression;
11412
11413 NewExpression.prototype.initialise = function initialise ( transforms ) {
11414 var this$1 = this;
11415
11416 if ( transforms.spreadRest && this.arguments.length ) {
11417 var lexicalBoundary = this.findLexicalBoundary();
11418
11419 var i = this.arguments.length;
11420 while ( i-- ) {
11421 var arg = this$1.arguments[i];
11422 if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
11423 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
11424 break;
11425 }
11426 }
11427 }
11428
11429 Node.prototype.initialise.call( this, transforms );
11430 };
11431
11432 NewExpression.prototype.transpile = function transpile ( code, transforms ) {
11433 if ( transforms.spreadRest && this.arguments.length ) {
11434 var firstArgument = this.arguments[0];
11435 var isNew = true;
11436 var hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias, isNew );
11437
11438 if ( hasSpreadElements ) {
11439 code.prependRight( this.start + 'new'.length, ' (Function.prototype.bind.apply(' );
11440 code.overwrite( this.callee.end, firstArgument.start, ', [ null ].concat( ' );
11441 code.appendLeft( this.end, ' ))' );
11442 }
11443 }
11444
11445 Node.prototype.transpile.call( this, code, transforms );
11446 };
11447
11448 return NewExpression;
11449}(Node$1));
11450
11451var ObjectExpression = (function (Node) {
11452 function ObjectExpression () {
11453 Node.apply(this, arguments);
11454 }
11455
11456 if ( Node ) ObjectExpression.__proto__ = Node;
11457 ObjectExpression.prototype = Object.create( Node && Node.prototype );
11458 ObjectExpression.prototype.constructor = ObjectExpression;
11459
11460 ObjectExpression.prototype.transpile = function transpile ( code, transforms ) {
11461 var this$1 = this;
11462
11463 Node.prototype.transpile.call( this, code, transforms );
11464
11465 var firstPropertyStart = this.start + 1;
11466 var regularPropertyCount = 0;
11467 var spreadPropertyCount = 0;
11468 var computedPropertyCount = 0;
11469
11470 for ( var i$2 = 0, list = this.properties; i$2 < list.length; i$2 += 1 ) {
11471 var prop = list[i$2];
11472
11473 if ( prop.type === 'SpreadElement' ) {
11474 spreadPropertyCount += 1;
11475 } else if ( prop.computed ) {
11476 computedPropertyCount += 1;
11477 } else if ( prop.type === 'Property' ) {
11478 regularPropertyCount += 1;
11479 }
11480 }
11481
11482 if ( spreadPropertyCount ) {
11483 if ( !this.program.options.objectAssign ) {
11484 throw new CompileError$1( 'Object spread operator requires specified objectAssign option with \'Object.assign\' or polyfill helper.', this );
11485 }
11486 // enclose run of non-spread properties in curlies
11487 var i = this.properties.length;
11488 if ( regularPropertyCount ) {
11489 while ( i-- ) {
11490 var prop$1 = this$1.properties[i];
11491
11492 if ( prop$1.type === 'Property' && !prop$1.computed ) {
11493 var lastProp = this$1.properties[ i - 1 ];
11494 var nextProp = this$1.properties[ i + 1 ];
11495
11496 if ( !lastProp || lastProp.type !== 'Property' || lastProp.computed ) {
11497 code.prependRight( prop$1.start, '{' );
11498 }
11499
11500 if ( !nextProp || nextProp.type !== 'Property' || nextProp.computed ) {
11501 code.appendLeft( prop$1.end, '}' );
11502 }
11503 }
11504 }
11505 }
11506
11507 // wrap the whole thing in Object.assign
11508 firstPropertyStart = this.properties[0].start;
11509 code.overwrite( this.start, firstPropertyStart, ((this.program.options.objectAssign) + "({}, "));
11510 code.overwrite( this.properties[ this.properties.length - 1 ].end, this.end, ')' );
11511 }
11512
11513 if ( computedPropertyCount && transforms.computedProperty ) {
11514 var i0 = this.getIndentation();
11515
11516 var isSimpleAssignment;
11517 var name;
11518
11519 if ( this.parent.type === 'VariableDeclarator' && this.parent.parent.declarations.length === 1 ) {
11520 isSimpleAssignment = true;
11521 name = this.parent.id.alias || this.parent.id.name; // TODO is this right?
11522 } else if ( this.parent.type === 'AssignmentExpression' && this.parent.parent.type === 'ExpressionStatement' && this.parent.left.type === 'Identifier' ) {
11523 isSimpleAssignment = true;
11524 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
11525 } else if ( this.parent.type === 'AssignmentPattern' && this.parent.left.type === 'Identifier' ) {
11526 isSimpleAssignment = true;
11527 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
11528 }
11529
11530 // handle block scoping
11531 var declaration = this.findScope( false ).findDeclaration( name );
11532 if ( declaration ) name = declaration.name;
11533
11534 var start = firstPropertyStart;
11535 var end = this.end;
11536
11537 if ( isSimpleAssignment ) {
11538 // ???
11539 } else {
11540 name = this.findScope( true ).createIdentifier( 'obj' );
11541
11542 var statement = this.findNearest( /(?:Statement|Declaration)$/ );
11543 code.appendLeft( statement.end, ("\n" + i0 + "var " + name + ";") );
11544
11545 code.prependRight( this.start, ("( " + name + " = ") );
11546 }
11547
11548 var len = this.properties.length;
11549 var lastComputedProp;
11550 var sawNonComputedProperty = false;
11551
11552 for ( var i$1 = 0; i$1 < len; i$1 += 1 ) {
11553 var prop$2 = this$1.properties[i$1];
11554
11555 if ( prop$2.computed ) {
11556 lastComputedProp = prop$2;
11557 var moveStart = i$1 > 0 ? this$1.properties[ i$1 - 1 ].end : start;
11558
11559 var propId = isSimpleAssignment ? (";\n" + i0 + name) : (", " + name);
11560
11561 if (moveStart < prop$2.start) {
11562 code.overwrite( moveStart, prop$2.start, propId );
11563 } else {
11564 code.prependRight( prop$2.start, propId );
11565 }
11566
11567 var c = prop$2.key.end;
11568 while ( code.original[c] !== ']' ) c += 1;
11569 c += 1;
11570
11571 if ( prop$2.value.start > c ) code.remove( c, prop$2.value.start );
11572 code.appendLeft( c, ' = ' );
11573 code.move( moveStart, prop$2.end, end );
11574
11575 if ( i$1 < len - 1 && ! sawNonComputedProperty ) {
11576 // remove trailing comma
11577 c = prop$2.end;
11578 while ( code.original[c] !== ',' ) c += 1;
11579
11580 code.remove( prop$2.end, c + 1 );
11581 }
11582
11583 if ( prop$2.method && transforms.conciseMethodProperty ) {
11584 code.prependRight( prop$2.value.start, 'function ' );
11585 }
11586 } else {
11587 sawNonComputedProperty = true;
11588 }
11589 }
11590
11591 // special case
11592 if ( computedPropertyCount === len ) {
11593 code.remove( this.properties[ len - 1 ].end, this.end - 1 );
11594 }
11595
11596 if ( !isSimpleAssignment ) {
11597 code.appendLeft( lastComputedProp.end, (", " + name + " )") );
11598 }
11599 }
11600 };
11601
11602 return ObjectExpression;
11603}(Node$1));
11604
11605var Property = (function (Node) {
11606 function Property () {
11607 Node.apply(this, arguments);
11608 }
11609
11610 if ( Node ) Property.__proto__ = Node;
11611 Property.prototype = Object.create( Node && Node.prototype );
11612 Property.prototype.constructor = Property;
11613
11614 Property.prototype.transpile = function transpile ( code, transforms ) {
11615 Node.prototype.transpile.call( this, code, transforms );
11616
11617 if ( transforms.conciseMethodProperty && !this.computed && this.parent.type !== 'ObjectPattern' ) {
11618 if ( this.shorthand ) {
11619 code.prependRight( this.start, ((this.key.name) + ": ") );
11620 } else if ( this.method ) {
11621 var name = '';
11622 if ( this.program.options.namedFunctionExpressions !== false ) {
11623 if ( this.key.type === 'Literal' && typeof this.key.value === 'number' ) {
11624 name = "";
11625 } else if ( this.key.type === 'Identifier' ) {
11626 if ( reserved[ this.key.name ] ||
11627 ! /^[a-z_$][a-z0-9_$]*$/i.test( this.key.name ) ||
11628 this.value.body.scope.references[this.key.name] ) {
11629 name = this.findScope( true ).createIdentifier( this.key.name );
11630 } else {
11631 name = this.key.name;
11632 }
11633 } else {
11634 name = this.findScope( true ).createIdentifier( this.key.value );
11635 }
11636 name = ' ' + name;
11637 }
11638
11639 if ( this.value.generator ) code.remove( this.start, this.key.start );
11640 code.appendLeft( this.key.end, (": function" + (this.value.generator ? '*' : '') + name) );
11641 }
11642 }
11643
11644 if ( transforms.reservedProperties && reserved[ this.key.name ] ) {
11645 code.prependRight( this.key.start, "'" );
11646 code.appendLeft( this.key.end, "'" );
11647 }
11648 };
11649
11650 return Property;
11651}(Node$1));
11652
11653var ReturnStatement = (function (Node) {
11654 function ReturnStatement () {
11655 Node.apply(this, arguments);
11656 }
11657
11658 if ( Node ) ReturnStatement.__proto__ = Node;
11659 ReturnStatement.prototype = Object.create( Node && Node.prototype );
11660 ReturnStatement.prototype.constructor = ReturnStatement;
11661
11662 ReturnStatement.prototype.initialise = function initialise ( transforms ) {
11663 this.loop = this.findNearest( loopStatement );
11664 this.nearestFunction = this.findNearest( /Function/ );
11665
11666 if ( this.loop && ( !this.nearestFunction || this.loop.depth > this.nearestFunction.depth ) ) {
11667 this.loop.canReturn = true;
11668 this.shouldWrap = true;
11669 }
11670
11671 if ( this.argument ) this.argument.initialise( transforms );
11672 };
11673
11674 ReturnStatement.prototype.transpile = function transpile ( code, transforms ) {
11675 var shouldWrap = this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;
11676
11677 if ( this.argument ) {
11678 if ( shouldWrap ) code.prependRight( this.argument.start, "{ v: " );
11679 this.argument.transpile( code, transforms );
11680 if ( shouldWrap ) code.appendLeft( this.argument.end, " }" );
11681 } else if ( shouldWrap ) {
11682 code.appendLeft( this.start + 6, ' {}' );
11683 }
11684 };
11685
11686 return ReturnStatement;
11687}(Node$1));
11688
11689var SpreadElement = (function (Node) {
11690 function SpreadElement () {
11691 Node.apply(this, arguments);
11692 }
11693
11694 if ( Node ) SpreadElement.__proto__ = Node;
11695 SpreadElement.prototype = Object.create( Node && Node.prototype );
11696 SpreadElement.prototype.constructor = SpreadElement;
11697
11698 SpreadElement.prototype.transpile = function transpile ( code, transforms ) {
11699 if (this.parent.type == "ObjectExpression") {
11700 code.remove( this.start, this.argument.start );
11701 code.remove( this.argument.end, this.end );
11702 }
11703
11704 Node.prototype.transpile.call( this, code, transforms );
11705 };
11706
11707 return SpreadElement;
11708}(Node$1));
11709
11710var Super = (function (Node) {
11711 function Super () {
11712 Node.apply(this, arguments);
11713 }
11714
11715 if ( Node ) Super.__proto__ = Node;
11716 Super.prototype = Object.create( Node && Node.prototype );
11717 Super.prototype.constructor = Super;
11718
11719 Super.prototype.initialise = function initialise ( transforms ) {
11720 if ( transforms.classes ) {
11721 this.method = this.findNearest( 'MethodDefinition' );
11722 if ( !this.method ) throw new CompileError$1( this, 'use of super outside class method' );
11723
11724 var parentClass = this.findNearest( 'ClassBody' ).parent;
11725 this.superClassName = parentClass.superClass && (parentClass.superClass.name || 'superclass');
11726
11727 if ( !this.superClassName ) throw new CompileError$1( 'super used in base class', this );
11728
11729 this.isCalled = this.parent.type === 'CallExpression' && this === this.parent.callee;
11730
11731 if ( this.method.kind !== 'constructor' && this.isCalled ) {
11732 throw new CompileError$1( 'super() not allowed outside class constructor', this );
11733 }
11734
11735 this.isMember = this.parent.type === 'MemberExpression';
11736
11737 if ( !this.isCalled && !this.isMember ) {
11738 throw new CompileError$1( 'Unexpected use of `super` (expected `super(...)` or `super.*`)', this );
11739 }
11740 }
11741
11742 if ( transforms.arrow ) {
11743 var lexicalBoundary = this.findLexicalBoundary();
11744 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
11745 var loop = this.findNearest( loopStatement );
11746
11747 if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
11748 this.thisAlias = lexicalBoundary.getThisAlias();
11749 }
11750
11751 if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
11752 this.thisAlias = lexicalBoundary.getThisAlias();
11753 }
11754 }
11755 };
11756
11757 Super.prototype.transpile = function transpile ( code, transforms ) {
11758 if ( transforms.classes ) {
11759 var expression = ( this.isCalled || this.method.static ) ?
11760 this.superClassName :
11761 ((this.superClassName) + ".prototype");
11762
11763 code.overwrite( this.start, this.end, expression, { storeName: true, contentOnly: true });
11764
11765 var callExpression = this.isCalled ? this.parent : this.parent.parent;
11766
11767 if ( callExpression && callExpression.type === 'CallExpression' ) {
11768 if ( !this.noCall ) { // special case – `super( ...args )`
11769 code.appendLeft( callExpression.callee.end, '.call' );
11770 }
11771
11772 var thisAlias = this.thisAlias || 'this';
11773
11774 if ( callExpression.arguments.length ) {
11775 code.appendLeft( callExpression.arguments[0].start, (thisAlias + ", ") );
11776 } else {
11777 code.appendLeft( callExpression.end - 1, ("" + thisAlias) );
11778 }
11779 }
11780 }
11781 };
11782
11783 return Super;
11784}(Node$1));
11785
11786var TaggedTemplateExpression = (function (Node) {
11787 function TaggedTemplateExpression () {
11788 Node.apply(this, arguments);
11789 }
11790
11791 if ( Node ) TaggedTemplateExpression.__proto__ = Node;
11792 TaggedTemplateExpression.prototype = Object.create( Node && Node.prototype );
11793 TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
11794
11795 TaggedTemplateExpression.prototype.initialise = function initialise ( transforms ) {
11796 if ( transforms.templateString && !transforms.dangerousTaggedTemplateString ) {
11797 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 );
11798 }
11799
11800 Node.prototype.initialise.call( this, transforms );
11801 };
11802
11803 TaggedTemplateExpression.prototype.transpile = function transpile ( code, transforms ) {
11804 if ( transforms.templateString && transforms.dangerousTaggedTemplateString ) {
11805 var ordered = this.quasi.expressions.concat( this.quasi.quasis ).sort( function ( a, b ) { return a.start - b.start; } );
11806
11807 // insert strings at start
11808 var templateStrings = this.quasi.quasis.map( function ( quasi ) { return JSON.stringify( quasi.value.cooked ); } );
11809 code.overwrite( this.tag.end, ordered[0].start, ("([" + (templateStrings.join(', ')) + "]") );
11810
11811 var lastIndex = ordered[0].start;
11812 ordered.forEach( function ( node ) {
11813 if ( node.type === 'TemplateElement' ) {
11814 code.remove( lastIndex, node.end );
11815 } else {
11816 code.overwrite( lastIndex, node.start, ', ' );
11817 }
11818
11819 lastIndex = node.end;
11820 });
11821
11822 code.overwrite( lastIndex, this.end, ')' );
11823 }
11824
11825 Node.prototype.transpile.call( this, code, transforms );
11826 };
11827
11828 return TaggedTemplateExpression;
11829}(Node$1));
11830
11831var TemplateElement = (function (Node) {
11832 function TemplateElement () {
11833 Node.apply(this, arguments);
11834 }
11835
11836 if ( Node ) TemplateElement.__proto__ = Node;
11837 TemplateElement.prototype = Object.create( Node && Node.prototype );
11838 TemplateElement.prototype.constructor = TemplateElement;
11839
11840 TemplateElement.prototype.initialise = function initialise () {
11841 this.program.indentExclusionElements.push( this );
11842 };
11843
11844 return TemplateElement;
11845}(Node$1));
11846
11847var TemplateLiteral = (function (Node) {
11848 function TemplateLiteral () {
11849 Node.apply(this, arguments);
11850 }
11851
11852 if ( Node ) TemplateLiteral.__proto__ = Node;
11853 TemplateLiteral.prototype = Object.create( Node && Node.prototype );
11854 TemplateLiteral.prototype.constructor = TemplateLiteral;
11855
11856 TemplateLiteral.prototype.transpile = function transpile ( code, transforms ) {
11857 if ( transforms.templateString && this.parent.type !== 'TaggedTemplateExpression' ) {
11858 var ordered = this.expressions.concat( this.quasis )
11859 .sort( function ( a, b ) { return a.start - b.start || a.end - b.end; } )
11860 .filter( function ( node, i ) {
11861 // include all expressions
11862 if ( node.type !== 'TemplateElement' ) return true;
11863
11864 // include all non-empty strings
11865 if ( node.value.raw ) return true;
11866
11867 // exclude all empty strings not at the head
11868 return !i;
11869 });
11870
11871 // special case – we may be able to skip the first element,
11872 // if it's the empty string, but only if the second and
11873 // third elements aren't both expressions (since they maybe
11874 // be numeric, and `1 + 2 + '3' === '33'`)
11875 if ( ordered.length >= 3 ) {
11876 var first = ordered[0];
11877 var third = ordered[2];
11878 if ( first.type === 'TemplateElement' && first.value.raw === '' && third.type === 'TemplateElement' ) {
11879 ordered.shift();
11880 }
11881 }
11882
11883 var parenthesise = ( this.quasis.length !== 1 || this.expressions.length !== 0 ) &&
11884 this.parent.type !== 'AssignmentExpression' &&
11885 this.parent.type !== 'AssignmentPattern' &&
11886 this.parent.type !== 'VariableDeclarator' &&
11887 ( this.parent.type !== 'BinaryExpression' || this.parent.operator !== '+' );
11888
11889 if ( parenthesise ) code.appendRight( this.start, '(' );
11890
11891 var lastIndex = this.start;
11892
11893 ordered.forEach( function ( node, i ) {
11894 var prefix = i === 0 ?
11895 parenthesise ? '(' : '' :
11896 ' + ';
11897
11898 if ( node.type === 'TemplateElement' ) {
11899 code.overwrite( lastIndex, node.end, prefix + JSON.stringify( node.value.cooked ) );
11900 } else {
11901 var parenthesise$1 = node.type !== 'Identifier'; // TODO other cases where it's safe
11902
11903 if ( parenthesise$1 ) prefix += '(';
11904
11905 code.remove( lastIndex, node.start );
11906
11907 if ( prefix ) code.prependRight( node.start, prefix );
11908 if ( parenthesise$1 ) code.appendLeft( node.end, ')' );
11909 }
11910
11911 lastIndex = node.end;
11912 });
11913
11914 if ( parenthesise ) code.appendLeft( lastIndex, ')' );
11915 code.remove( lastIndex, this.end );
11916 }
11917
11918 Node.prototype.transpile.call( this, code, transforms );
11919 };
11920
11921 return TemplateLiteral;
11922}(Node$1));
11923
11924var ThisExpression = (function (Node) {
11925 function ThisExpression () {
11926 Node.apply(this, arguments);
11927 }
11928
11929 if ( Node ) ThisExpression.__proto__ = Node;
11930 ThisExpression.prototype = Object.create( Node && Node.prototype );
11931 ThisExpression.prototype.constructor = ThisExpression;
11932
11933 ThisExpression.prototype.initialise = function initialise ( transforms ) {
11934 if ( transforms.arrow ) {
11935 var lexicalBoundary = this.findLexicalBoundary();
11936 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
11937 var loop = this.findNearest( loopStatement );
11938
11939 if ( ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth )
11940 || ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth )
11941 || ( loop && loop.right && loop.right.contains( this ) ) ) {
11942 this.alias = lexicalBoundary.getThisAlias();
11943 }
11944 }
11945 };
11946
11947 ThisExpression.prototype.transpile = function transpile ( code ) {
11948 if ( this.alias ) {
11949 code.overwrite( this.start, this.end, this.alias, {
11950 storeName: true,
11951 contentOnly: true
11952 });
11953 }
11954 };
11955
11956 return ThisExpression;
11957}(Node$1));
11958
11959var UpdateExpression = (function (Node) {
11960 function UpdateExpression () {
11961 Node.apply(this, arguments);
11962 }
11963
11964 if ( Node ) UpdateExpression.__proto__ = Node;
11965 UpdateExpression.prototype = Object.create( Node && Node.prototype );
11966 UpdateExpression.prototype.constructor = UpdateExpression;
11967
11968 UpdateExpression.prototype.initialise = function initialise ( transforms ) {
11969 if ( this.argument.type === 'Identifier' ) {
11970 var declaration = this.findScope( false ).findDeclaration( this.argument.name );
11971 if ( declaration && declaration.kind === 'const' ) {
11972 throw new CompileError$1( ((this.argument.name) + " is read-only"), this );
11973 }
11974
11975 // special case – https://gitlab.com/Rich-Harris/buble/issues/150
11976 var statement = declaration && declaration.node.ancestor( 3 );
11977 if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
11978 statement.reassigned[ this.argument.name ] = true;
11979 }
11980 }
11981
11982 Node.prototype.initialise.call( this, transforms );
11983 };
11984
11985 return UpdateExpression;
11986}(Node$1));
11987
11988var VariableDeclaration = (function (Node) {
11989 function VariableDeclaration () {
11990 Node.apply(this, arguments);
11991 }
11992
11993 if ( Node ) VariableDeclaration.__proto__ = Node;
11994 VariableDeclaration.prototype = Object.create( Node && Node.prototype );
11995 VariableDeclaration.prototype.constructor = VariableDeclaration;
11996
11997 VariableDeclaration.prototype.initialise = function initialise ( transforms ) {
11998 this.scope = this.findScope( this.kind === 'var' );
11999 this.declarations.forEach( function ( declarator ) { return declarator.initialise( transforms ); } );
12000 };
12001
12002 VariableDeclaration.prototype.transpile = function transpile ( code, transforms ) {
12003 var this$1 = this;
12004
12005 var i0 = this.getIndentation();
12006 var kind = this.kind;
12007
12008 if ( transforms.letConst && kind !== 'var' ) {
12009 kind = 'var';
12010 code.overwrite( this.start, this.start + this.kind.length, kind, { storeName: true });
12011 }
12012
12013 if ( transforms.destructuring && this.parent.type !== 'ForOfStatement' ) {
12014 var c = this.start;
12015 var lastDeclaratorIsPattern;
12016
12017 this.declarations.forEach( function ( declarator, i ) {
12018 declarator.transpile( code, transforms );
12019
12020 if ( declarator.id.type === 'Identifier' ) {
12021 if ( i > 0 && this$1.declarations[ i - 1 ].id.type !== 'Identifier' ) {
12022 code.overwrite( c, declarator.id.start, "var " );
12023 }
12024 } else {
12025 var inline = loopStatement.test( this$1.parent.type );
12026
12027 if ( i === 0 ) {
12028 code.remove( c, declarator.id.start );
12029 } else {
12030 code.overwrite( c, declarator.id.start, (";\n" + i0) );
12031 }
12032
12033 var simple = declarator.init.type === 'Identifier' && !declarator.init.rewritten;
12034
12035 var name = simple ? declarator.init.name : declarator.findScope( true ).createIdentifier( 'ref' );
12036
12037 var statementGenerators = [];
12038
12039 if ( simple ) {
12040 code.remove( declarator.id.end, declarator.end );
12041 } else {
12042 statementGenerators.push( function ( start, prefix, suffix ) {
12043 code.prependRight( declarator.id.end, ("var " + name) );
12044 code.appendLeft( declarator.init.end, ("" + suffix) );
12045 code.move( declarator.id.end, declarator.end, start );
12046 });
12047 }
12048
12049 destructure( code, declarator.findScope( false ), declarator.id, name, inline, statementGenerators );
12050
12051 var prefix = inline ? 'var ' : '';
12052 var suffix = inline ? ", " : (";\n" + i0);
12053 statementGenerators.forEach( function ( fn, j ) {
12054 if ( i === this$1.declarations.length - 1 && j === statementGenerators.length - 1 ) {
12055 suffix = inline ? '' : ';';
12056 }
12057
12058 fn( declarator.start, j === 0 ? prefix : '', suffix );
12059 });
12060 }
12061
12062 c = declarator.end;
12063 lastDeclaratorIsPattern = declarator.id.type !== 'Identifier';
12064 });
12065
12066 if ( lastDeclaratorIsPattern && this.end > c ) {
12067 code.overwrite( c, this.end, '', { contentOnly: true });
12068 }
12069 }
12070
12071 else {
12072 this.declarations.forEach( function ( declarator ) {
12073 declarator.transpile( code, transforms );
12074 });
12075 }
12076 };
12077
12078 return VariableDeclaration;
12079}(Node$1));
12080
12081var VariableDeclarator = (function (Node) {
12082 function VariableDeclarator () {
12083 Node.apply(this, arguments);
12084 }
12085
12086 if ( Node ) VariableDeclarator.__proto__ = Node;
12087 VariableDeclarator.prototype = Object.create( Node && Node.prototype );
12088 VariableDeclarator.prototype.constructor = VariableDeclarator;
12089
12090 VariableDeclarator.prototype.initialise = function initialise ( transforms ) {
12091 var kind = this.parent.kind;
12092 if ( kind === 'let' && this.parent.parent.type === 'ForStatement' ) {
12093 kind = 'for.let'; // special case...
12094 }
12095
12096 this.parent.scope.addDeclaration( this.id, kind );
12097 Node.prototype.initialise.call( this, transforms );
12098 };
12099
12100 VariableDeclarator.prototype.transpile = function transpile ( code, transforms ) {
12101 if ( !this.init && transforms.letConst && this.parent.kind !== 'var' ) {
12102 var inLoop = this.findNearest( /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/ );
12103 if ( inLoop && ! /Function/.test( inLoop.type ) && ! this.isLeftDeclaratorOfLoop() ) {
12104 code.appendLeft( this.id.end, ' = (void 0)' );
12105 }
12106 }
12107
12108 if ( this.id ) this.id.transpile( code, transforms );
12109 if ( this.init ) this.init.transpile( code, transforms );
12110 };
12111
12112 VariableDeclarator.prototype.isLeftDeclaratorOfLoop = function isLeftDeclaratorOfLoop () {
12113 return this.parent
12114 && this.parent.type === 'VariableDeclaration'
12115 && this.parent.parent
12116 && (this.parent.parent.type === 'ForInStatement'
12117 || this.parent.parent.type === 'ForOfStatement')
12118 && this.parent.parent.left
12119 && this.parent.parent.left.declarations[0] === this;
12120 };
12121
12122 return VariableDeclarator;
12123}(Node$1));
12124
12125var types$1$1 = {
12126 ArrayExpression: ArrayExpression,
12127 ArrowFunctionExpression: ArrowFunctionExpression,
12128 AssignmentExpression: AssignmentExpression,
12129 BinaryExpression: BinaryExpression,
12130 BreakStatement: BreakStatement,
12131 CallExpression: CallExpression,
12132 ClassBody: ClassBody,
12133 ClassDeclaration: ClassDeclaration,
12134 ClassExpression: ClassExpression,
12135 ContinueStatement: ContinueStatement,
12136 DoWhileStatement: LoopStatement,
12137 ExportNamedDeclaration: ExportNamedDeclaration,
12138 ExportDefaultDeclaration: ExportDefaultDeclaration,
12139 ForStatement: ForStatement,
12140 ForInStatement: ForInStatement,
12141 ForOfStatement: ForOfStatement,
12142 FunctionDeclaration: FunctionDeclaration,
12143 FunctionExpression: FunctionExpression,
12144 Identifier: Identifier,
12145 IfStatement: IfStatement,
12146 ImportDeclaration: ImportDeclaration,
12147 ImportDefaultSpecifier: ImportDefaultSpecifier,
12148 ImportSpecifier: ImportSpecifier,
12149 JSXAttribute: JSXAttribute,
12150 JSXClosingElement: JSXClosingElement,
12151 JSXElement: JSXElement,
12152 JSXExpressionContainer: JSXExpressionContainer,
12153 JSXOpeningElement: JSXOpeningElement,
12154 JSXSpreadAttribute: JSXSpreadAttribute,
12155 Literal: Literal,
12156 MemberExpression: MemberExpression,
12157 NewExpression: NewExpression,
12158 ObjectExpression: ObjectExpression,
12159 Property: Property,
12160 ReturnStatement: ReturnStatement,
12161 SpreadElement: SpreadElement,
12162 Super: Super,
12163 TaggedTemplateExpression: TaggedTemplateExpression,
12164 TemplateElement: TemplateElement,
12165 TemplateLiteral: TemplateLiteral,
12166 ThisExpression: ThisExpression,
12167 UpdateExpression: UpdateExpression,
12168 VariableDeclaration: VariableDeclaration,
12169 VariableDeclarator: VariableDeclarator,
12170 WhileStatement: LoopStatement
12171};
12172
12173var statementsWithBlocks = {
12174 IfStatement: 'consequent',
12175 ForStatement: 'body',
12176 ForInStatement: 'body',
12177 ForOfStatement: 'body',
12178 WhileStatement: 'body',
12179 DoWhileStatement: 'body',
12180 ArrowFunctionExpression: 'body'
12181};
12182
12183function wrap ( raw, parent ) {
12184 if ( !raw ) return;
12185
12186 if ( 'length' in raw ) {
12187 var i = raw.length;
12188 while ( i-- ) wrap( raw[i], parent );
12189 return;
12190 }
12191
12192 // with e.g. shorthand properties, key and value are
12193 // the same node. We don't want to wrap an object twice
12194 if ( raw.__wrapped ) return;
12195 raw.__wrapped = true;
12196
12197 if ( !keys[ raw.type ] ) {
12198 keys[ raw.type ] = Object.keys( raw ).filter( function ( key ) { return typeof raw[ key ] === 'object'; } );
12199 }
12200
12201 // special case – body-less if/for/while statements. TODO others?
12202 var bodyType = statementsWithBlocks[ raw.type ];
12203 if ( bodyType && raw[ bodyType ].type !== 'BlockStatement' ) {
12204 var expression = raw[ bodyType ];
12205
12206 // create a synthetic block statement, otherwise all hell
12207 // breaks loose when it comes to block scoping
12208 raw[ bodyType ] = {
12209 start: expression.start,
12210 end: expression.end,
12211 type: 'BlockStatement',
12212 body: [ expression ],
12213 synthetic: true
12214 };
12215 }
12216
12217 new Node$1( raw, parent );
12218
12219 var type = ( raw.type === 'BlockStatement' ? BlockStatement : types$1$1[ raw.type ] ) || Node$1;
12220 raw.__proto__ = type.prototype;
12221}
12222
12223function Scope ( options ) {
12224 options = options || {};
12225
12226 this.parent = options.parent;
12227 this.isBlockScope = !!options.block;
12228
12229 var scope = this;
12230 while ( scope.isBlockScope ) scope = scope.parent;
12231 this.functionScope = scope;
12232
12233 this.identifiers = [];
12234 this.declarations = Object.create( null );
12235 this.references = Object.create( null );
12236 this.blockScopedDeclarations = this.isBlockScope ? null : Object.create( null );
12237 this.aliases = this.isBlockScope ? null : Object.create( null );
12238}
12239
12240Scope.prototype = {
12241 addDeclaration: function addDeclaration ( node, kind ) {
12242 for ( var i = 0, list = extractNames( node ); i < list.length; i += 1 ) {
12243 var identifier = list[i];
12244
12245 var name = identifier.name;
12246
12247 var declaration = { name: name, node: identifier, kind: kind, instances: [] };
12248 this.declarations[ name ] = declaration;
12249
12250 if ( this.isBlockScope ) {
12251 if ( !this.functionScope.blockScopedDeclarations[ name ] ) this.functionScope.blockScopedDeclarations[ name ] = [];
12252 this.functionScope.blockScopedDeclarations[ name ].push( declaration );
12253 }
12254 }
12255 },
12256
12257 addReference: function addReference ( identifier ) {
12258 if ( this.consolidated ) {
12259 this.consolidateReference( identifier );
12260 } else {
12261 this.identifiers.push( identifier );
12262 }
12263 },
12264
12265 consolidate: function consolidate () {
12266 var this$1 = this;
12267
12268 for ( var i = 0; i < this$1.identifiers.length; i += 1 ) { // we might push to the array during consolidation, so don't cache length
12269 var identifier = this$1.identifiers[i];
12270 this$1.consolidateReference( identifier );
12271 }
12272
12273 this.consolidated = true; // TODO understand why this is necessary... seems bad
12274 },
12275
12276 consolidateReference: function consolidateReference ( identifier ) {
12277 var declaration = this.declarations[ identifier.name ];
12278 if ( declaration ) {
12279 declaration.instances.push( identifier );
12280 } else {
12281 this.references[ identifier.name ] = true;
12282 if ( this.parent ) this.parent.addReference( identifier );
12283 }
12284 },
12285
12286 contains: function contains ( name ) {
12287 return this.declarations[ name ] ||
12288 ( this.parent ? this.parent.contains( name ) : false );
12289 },
12290
12291 createIdentifier: function createIdentifier ( base ) {
12292 var this$1 = this;
12293
12294 if ( typeof base === 'number' ) base = base.toString();
12295
12296 base = base
12297 .replace( /\s/g, '' )
12298 .replace( /\[([^\]]+)\]/g, '_$1' )
12299 .replace( /[^a-zA-Z0-9_$]/g, '_' )
12300 .replace( /_{2,}/, '_' );
12301
12302 var name = base;
12303 var counter = 1;
12304
12305 while ( this$1.declarations[ name ] || this$1.references[ name ] || this$1.aliases[ name ] || name in reserved ) {
12306 name = base + "$" + (counter++);
12307 }
12308
12309 this.aliases[ name ] = true;
12310 return name;
12311 },
12312
12313 findDeclaration: function findDeclaration ( name ) {
12314 return this.declarations[ name ] ||
12315 ( this.parent && this.parent.findDeclaration( name ) );
12316 }
12317};
12318
12319function isUseStrict ( node ) {
12320 if ( !node ) return false;
12321 if ( node.type !== 'ExpressionStatement' ) return false;
12322 if ( node.expression.type !== 'Literal' ) return false;
12323 return node.expression.value === 'use strict';
12324}
12325
12326var BlockStatement = (function (Node) {
12327 function BlockStatement () {
12328 Node.apply(this, arguments);
12329 }
12330
12331 if ( Node ) BlockStatement.__proto__ = Node;
12332 BlockStatement.prototype = Object.create( Node && Node.prototype );
12333 BlockStatement.prototype.constructor = BlockStatement;
12334
12335 BlockStatement.prototype.createScope = function createScope () {
12336 var this$1 = this;
12337
12338 this.parentIsFunction = /Function/.test( this.parent.type );
12339 this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root';
12340 this.scope = new Scope({
12341 block: !this.isFunctionBlock,
12342 parent: this.parent.findScope( false )
12343 });
12344
12345 if ( this.parentIsFunction ) {
12346 this.parent.params.forEach( function ( node ) {
12347 this$1.scope.addDeclaration( node, 'param' );
12348 });
12349 }
12350 };
12351
12352 BlockStatement.prototype.initialise = function initialise ( transforms ) {
12353 this.thisAlias = null;
12354 this.argumentsAlias = null;
12355 this.defaultParameters = [];
12356
12357 // normally the scope gets created here, during initialisation,
12358 // but in some cases (e.g. `for` statements), we need to create
12359 // the scope early, as it pertains to both the init block and
12360 // the body of the statement
12361 if ( !this.scope ) this.createScope();
12362
12363 this.body.forEach( function ( node ) { return node.initialise( transforms ); } );
12364
12365 this.scope.consolidate();
12366 };
12367
12368 BlockStatement.prototype.findLexicalBoundary = function findLexicalBoundary () {
12369 if ( this.type === 'Program' ) return this;
12370 if ( /^Function/.test( this.parent.type ) ) return this;
12371
12372 return this.parent.findLexicalBoundary();
12373 };
12374
12375 BlockStatement.prototype.findScope = function findScope ( functionScope ) {
12376 if ( functionScope && !this.isFunctionBlock ) return this.parent.findScope( functionScope );
12377 return this.scope;
12378 };
12379
12380 BlockStatement.prototype.getArgumentsAlias = function getArgumentsAlias () {
12381 if ( !this.argumentsAlias ) {
12382 this.argumentsAlias = this.scope.createIdentifier( 'arguments' );
12383 }
12384
12385 return this.argumentsAlias;
12386 };
12387
12388 BlockStatement.prototype.getArgumentsArrayAlias = function getArgumentsArrayAlias () {
12389 if ( !this.argumentsArrayAlias ) {
12390 this.argumentsArrayAlias = this.scope.createIdentifier( 'argsArray' );
12391 }
12392
12393 return this.argumentsArrayAlias;
12394 };
12395
12396 BlockStatement.prototype.getThisAlias = function getThisAlias () {
12397 if ( !this.thisAlias ) {
12398 this.thisAlias = this.scope.createIdentifier( 'this' );
12399 }
12400
12401 return this.thisAlias;
12402 };
12403
12404 BlockStatement.prototype.getIndentation = function getIndentation () {
12405 var this$1 = this;
12406
12407 if ( this.indentation === undefined ) {
12408 var source = this.program.magicString.original;
12409
12410 var useOuter = this.synthetic || !this.body.length;
12411 var c = useOuter ? this.start : this.body[0].start;
12412
12413 while ( c && source[c] !== '\n' ) c -= 1;
12414
12415 this.indentation = '';
12416
12417 while ( true ) { // eslint-disable-line no-constant-condition
12418 c += 1;
12419 var char = source[c];
12420
12421 if ( char !== ' ' && char !== '\t' ) break;
12422
12423 this$1.indentation += char;
12424 }
12425
12426 var indentString = this.program.magicString.getIndentString();
12427
12428 // account for dedented class constructors
12429 var parent = this.parent;
12430 while ( parent ) {
12431 if ( parent.kind === 'constructor' && !parent.parent.parent.superClass ) {
12432 this$1.indentation = this$1.indentation.replace( indentString, '' );
12433 }
12434
12435 parent = parent.parent;
12436 }
12437
12438 if ( useOuter ) this.indentation += indentString;
12439 }
12440
12441 return this.indentation;
12442 };
12443
12444 BlockStatement.prototype.transpile = function transpile ( code, transforms ) {
12445 var this$1 = this;
12446
12447 var indentation = this.getIndentation();
12448
12449 var introStatementGenerators = [];
12450
12451 if ( this.argumentsAlias ) {
12452 introStatementGenerators.push( function ( start, prefix, suffix ) {
12453 var assignment = prefix + "var " + (this$1.argumentsAlias) + " = arguments" + suffix;
12454 code.appendLeft( start, assignment );
12455 });
12456 }
12457
12458 if ( this.thisAlias ) {
12459 introStatementGenerators.push( function ( start, prefix, suffix ) {
12460 var assignment = prefix + "var " + (this$1.thisAlias) + " = this" + suffix;
12461 code.appendLeft( start, assignment );
12462 });
12463 }
12464
12465 if ( this.argumentsArrayAlias ) {
12466 introStatementGenerators.push( function ( start, prefix, suffix ) {
12467 var i = this$1.scope.createIdentifier( 'i' );
12468 var assignment = prefix + "var " + i + " = arguments.length, " + (this$1.argumentsArrayAlias) + " = Array(" + i + ");\n" + indentation + "while ( " + i + "-- ) " + (this$1.argumentsArrayAlias) + "[" + i + "] = arguments[" + i + "]" + suffix;
12469 code.appendLeft( start, assignment );
12470 });
12471 }
12472
12473 if ( /Function/.test( this.parent.type ) ) {
12474 this.transpileParameters( code, transforms, indentation, introStatementGenerators );
12475 }
12476
12477 if ( transforms.letConst && this.isFunctionBlock ) {
12478 this.transpileBlockScopedIdentifiers( code );
12479 }
12480
12481 Node.prototype.transpile.call( this, code, transforms );
12482
12483 if ( this.synthetic ) {
12484 if ( this.parent.type === 'ArrowFunctionExpression' ) {
12485 var expr = this.body[0];
12486
12487 if ( introStatementGenerators.length ) {
12488 code.appendLeft( this.start, "{" ).prependRight( this.end, ((this.parent.getIndentation()) + "}") );
12489
12490 code.prependRight( expr.start, ("\n" + indentation + "return ") );
12491 code.appendLeft( expr.end, ";\n" );
12492 } else if ( transforms.arrow ) {
12493 code.prependRight( expr.start, "{ return " );
12494 code.appendLeft( expr.end, "; }" );
12495 }
12496 }
12497
12498 else if ( introStatementGenerators.length ) {
12499 code.prependRight( this.start, "{" ).appendLeft( this.end, "}" );
12500 }
12501 }
12502
12503 var start;
12504 if ( isUseStrict( this.body[0] ) ) {
12505 start = this.body[0].end;
12506 } else if ( this.synthetic || this.parent.type === 'Root' ) {
12507 start = this.start;
12508 } else {
12509 start = this.start + 1;
12510 }
12511
12512 var prefix = "\n" + indentation;
12513 var suffix = ';';
12514 introStatementGenerators.forEach( function ( fn, i ) {
12515 if ( i === introStatementGenerators.length - 1 ) suffix = ";\n";
12516 fn( start, prefix, suffix );
12517 });
12518 };
12519
12520 BlockStatement.prototype.transpileParameters = function transpileParameters ( code, transforms, indentation, introStatementGenerators ) {
12521 var this$1 = this;
12522
12523 var params = this.parent.params;
12524
12525 params.forEach( function ( param ) {
12526 if ( param.type === 'AssignmentPattern' && param.left.type === 'Identifier' ) {
12527 if ( transforms.defaultParameter ) {
12528 introStatementGenerators.push( function ( start, prefix, suffix ) {
12529 var lhs = prefix + "if ( " + (param.left.name) + " === void 0 ) " + (param.left.name);
12530
12531 code
12532 .prependRight( param.left.end, lhs )
12533 .move( param.left.end, param.right.end, start )
12534 .appendLeft( param.right.end, suffix );
12535 });
12536 }
12537 }
12538
12539 else if ( param.type === 'RestElement' ) {
12540 if ( transforms.spreadRest ) {
12541 introStatementGenerators.push( function ( start, prefix, suffix ) {
12542 var penultimateParam = params[ params.length - 2 ];
12543
12544 if ( penultimateParam ) {
12545 code.remove( penultimateParam ? penultimateParam.end : param.start, param.end );
12546 } else {
12547 var start$1 = param.start, end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8
12548
12549 while ( /\s/.test( code.original[ start$1 - 1 ] ) ) start$1 -= 1;
12550 while ( /\s/.test( code.original[ end ] ) ) end += 1;
12551
12552 code.remove( start$1, end );
12553 }
12554
12555 var name = param.argument.name;
12556 var len = this$1.scope.createIdentifier( 'len' );
12557 var count = params.length - 1;
12558
12559 if ( count ) {
12560 code.prependRight( start, (prefix + "var " + name + " = [], " + len + " = arguments.length - " + count + ";\n" + indentation + "while ( " + len + "-- > 0 ) " + name + "[ " + len + " ] = arguments[ " + len + " + " + count + " ]" + suffix) );
12561 } else {
12562 code.prependRight( start, (prefix + "var " + name + " = [], " + len + " = arguments.length;\n" + indentation + "while ( " + len + "-- ) " + name + "[ " + len + " ] = arguments[ " + len + " ]" + suffix) );
12563 }
12564 });
12565 }
12566 }
12567
12568 else if ( param.type !== 'Identifier' ) {
12569 if ( transforms.parameterDestructuring ) {
12570 var ref = this$1.scope.createIdentifier( 'ref' );
12571 destructure( code, this$1.scope, param, ref, false, introStatementGenerators );
12572 code.prependRight( param.start, ref );
12573 }
12574 }
12575 });
12576 };
12577
12578 BlockStatement.prototype.transpileBlockScopedIdentifiers = function transpileBlockScopedIdentifiers ( code ) {
12579 var this$1 = this;
12580
12581 Object.keys( this.scope.blockScopedDeclarations ).forEach( function ( name ) {
12582 var declarations = this$1.scope.blockScopedDeclarations[ name ];
12583
12584 for ( var i = 0, list = declarations; i < list.length; i += 1 ) {
12585 var declaration = list[i];
12586
12587 var cont = false; // TODO implement proper continue...
12588
12589 if ( declaration.kind === 'for.let' ) {
12590 // special case
12591 var forStatement = declaration.node.findNearest( 'ForStatement' );
12592
12593 if ( forStatement.shouldRewriteAsFunction ) {
12594 var outerAlias = this$1.scope.createIdentifier( name );
12595 var innerAlias = forStatement.reassigned[ name ] ?
12596 this$1.scope.createIdentifier( name ) :
12597 name;
12598
12599 declaration.name = outerAlias;
12600 code.overwrite( declaration.node.start, declaration.node.end, outerAlias, { storeName: true });
12601
12602 forStatement.aliases[ name ] = {
12603 outer: outerAlias,
12604 inner: innerAlias
12605 };
12606
12607 for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
12608 var identifier = list$1[i$1];
12609
12610 var alias = forStatement.body.contains( identifier ) ?
12611 innerAlias :
12612 outerAlias;
12613
12614 if ( name !== alias ) {
12615 code.overwrite( identifier.start, identifier.end, alias, { storeName: true });
12616 }
12617 }
12618
12619 cont = true;
12620 }
12621 }
12622
12623 if ( !cont ) {
12624 var alias$1 = this$1.scope.createIdentifier( name );
12625
12626 if ( name !== alias$1 ) {
12627 declaration.name = alias$1;
12628 code.overwrite( declaration.node.start, declaration.node.end, alias$1, { storeName: true });
12629
12630 for ( var i$2 = 0, list$2 = declaration.instances; i$2 < list$2.length; i$2 += 1 ) {
12631 var identifier$1 = list$2[i$2];
12632
12633 identifier$1.rewritten = true;
12634 code.overwrite( identifier$1.start, identifier$1.end, alias$1, { storeName: true });
12635 }
12636 }
12637 }
12638 }
12639 });
12640 };
12641
12642 return BlockStatement;
12643}(Node$1));
12644
12645function Program ( source, ast, transforms, options ) {
12646 var this$1 = this;
12647
12648 this.type = 'Root';
12649
12650 // options
12651 this.jsx = options.jsx || 'React.createElement';
12652 this.options = options;
12653
12654 this.source = source;
12655 this.magicString = new MagicString( source );
12656
12657 this.ast = ast;
12658 this.depth = 0;
12659
12660 wrap( this.body = ast, this );
12661 this.body.__proto__ = BlockStatement.prototype;
12662
12663 this.indentExclusionElements = [];
12664 this.body.initialise( transforms );
12665
12666 this.indentExclusions = Object.create( null );
12667 for ( var i$1 = 0, list = this.indentExclusionElements; i$1 < list.length; i$1 += 1 ) {
12668 var node = list[i$1];
12669
12670 for ( var i = node.start; i < node.end; i += 1 ) {
12671 this$1.indentExclusions[ i ] = true;
12672 }
12673 }
12674
12675 this.body.transpile( this.magicString, transforms );
12676}
12677
12678Program.prototype = {
12679 export: function export$1 ( options ) {
12680 if ( options === void 0 ) options = {};
12681
12682 return {
12683 code: this.magicString.toString(),
12684 map: this.magicString.generateMap({
12685 file: options.file,
12686 source: options.source,
12687 includeContent: options.includeContent !== false
12688 })
12689 };
12690 },
12691
12692 findNearest: function findNearest () {
12693 return null;
12694 },
12695
12696 findScope: function findScope () {
12697 return null;
12698 }
12699};
12700
12701var matrix = {
12702 chrome: {
12703 48: 1333689725,
12704 49: 1342078975,
12705 50: 1610514431,
12706 51: 1610514431,
12707 52: 2147385343
12708 },
12709 firefox: {
12710 43: 1207307741,
12711 44: 1207307741,
12712 45: 1207307741,
12713 46: 1476267485,
12714 47: 1476296671,
12715 48: 1476296671
12716 },
12717 safari: {
12718 8: 1073741824,
12719 9: 1328940894
12720 },
12721 ie: {
12722 8: 0,
12723 9: 1073741824,
12724 10: 1073741824,
12725 11: 1073770592
12726 },
12727 edge: {
12728 12: 1591620701,
12729 13: 1608400479
12730 },
12731 node: {
12732 '0.10': 1075052608,
12733 '0.12': 1091830852,
12734 4: 1327398527,
12735 5: 1327398527,
12736 6: 1610514431
12737 }
12738};
12739
12740var features = [
12741 'arrow',
12742 'classes',
12743 'collections',
12744 'computedProperty',
12745 'conciseMethodProperty',
12746 'constLoop',
12747 'constRedef',
12748 'defaultParameter',
12749 'destructuring',
12750 'extendNatives',
12751 'forOf',
12752 'generator',
12753 'letConst',
12754 'letLoop',
12755 'letLoopScope',
12756 'moduleExport',
12757 'moduleImport',
12758 'numericLiteral',
12759 'objectProto',
12760 'objectSuper',
12761 'oldOctalLiteral',
12762 'parameterDestructuring',
12763 'spreadRest',
12764 'stickyRegExp',
12765 'symbol',
12766 'templateString',
12767 'unicodeEscape',
12768 'unicodeIdentifier',
12769 'unicodeRegExp',
12770
12771 // ES2016
12772 'exponentiation',
12773
12774 // additional transforms, not from
12775 // https://featuretests.io
12776 'reservedProperties'
12777];
12778
12779var version$1 = "0.17.0";
12780
12781var ref = [
12782 inject$1,
12783 inject
12784].reduce( function ( final, plugin ) { return plugin( final ); }, acorn );
12785var parse = ref.parse;
12786
12787var dangerousTransforms = [
12788 'dangerousTaggedTemplateString',
12789 'dangerousForOf'
12790];
12791
12792function target ( target ) {
12793 var targets = Object.keys( target );
12794 var bitmask = targets.length ?
12795 2147483647 :
12796 1073741824;
12797
12798 Object.keys( target ).forEach( function ( environment ) {
12799 var versions = matrix[ environment ];
12800 if ( !versions ) throw new Error( ("Unknown environment '" + environment + "'. Please raise an issue at https://gitlab.com/Rich-Harris/buble/issues") );
12801
12802 var targetVersion = target[ environment ];
12803 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") );
12804 var support = versions[ targetVersion ];
12805
12806 bitmask &= support;
12807 });
12808
12809 var transforms = Object.create( null );
12810 features.forEach( function ( name, i ) {
12811 transforms[ name ] = !( bitmask & 1 << i );
12812 });
12813
12814 dangerousTransforms.forEach( function ( name ) {
12815 transforms[ name ] = false;
12816 });
12817
12818 return transforms;
12819}
12820
12821function transform ( source, options ) {
12822 if ( options === void 0 ) options = {};
12823
12824 var ast;
12825 var jsx = null;
12826
12827 try {
12828 ast = parse( source, {
12829 ecmaVersion: 8,
12830 preserveParens: true,
12831 sourceType: 'module',
12832 onComment: function (block, text) {
12833 if ( !jsx ) {
12834 var match = /@jsx\s+([^\s]+)/.exec( text );
12835 if ( match ) jsx = match[1];
12836 }
12837 },
12838 plugins: {
12839 jsx: true,
12840 objectSpread: true
12841 }
12842 });
12843 options.jsx = jsx || options.jsx;
12844 } catch ( err ) {
12845 err.snippet = getSnippet( source, err.loc );
12846 err.toString = function () { return ((err.name) + ": " + (err.message) + "\n" + (err.snippet)); };
12847 throw err;
12848 }
12849
12850 var transforms = target( options.target || {} );
12851 Object.keys( options.transforms || {} ).forEach( function ( name ) {
12852 if ( name === 'modules' ) {
12853 if ( !( 'moduleImport' in options.transforms ) ) transforms.moduleImport = options.transforms.modules;
12854 if ( !( 'moduleExport' in options.transforms ) ) transforms.moduleExport = options.transforms.modules;
12855 return;
12856 }
12857
12858 if ( !( name in transforms ) ) throw new Error( ("Unknown transform '" + name + "'") );
12859 transforms[ name ] = options.transforms[ name ];
12860 });
12861
12862 return new Program( source, ast, transforms, options ).export( options );
12863}
12864
12865export { target, transform, version$1 as VERSION };
12866//# sourceMappingURL=buble.es.js.map