UNPKG

201 kBJavaScriptView Raw
1// Reserved word lists for various dialects of the language
2
3var reservedWords = {
4 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",
5 5: "class enum extends super const export import",
6 6: "enum",
7 strict: "implements interface let package private protected public static yield",
8 strictBind: "eval arguments"
9};
10
11// And the keywords
12
13var 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";
14
15var keywords = {
16 5: ecma5AndLessKeywords,
17 "5module": ecma5AndLessKeywords + " export import",
18 6: ecma5AndLessKeywords + " const class extends export import super"
19};
20
21var keywordRelationalOperator = /^in(stanceof)?$/;
22
23// ## Character categories
24
25// Big ugly regular expressions that match characters in the
26// whitespace, identifier, and identifier-start categories. These
27// are only applied when a character is found to actually have a
28// code point above 128.
29// Generated by `bin/generate-identifier-regex.js`.
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\u0560-\u0588\u05d0-\u05ea\u05ef-\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\u0860-\u086a\u08a0-\u08b4\u08b6-\u08c7\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\u09fc\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\u0d04-\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\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\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-\u1878\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\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\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-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\u9ffc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7ca\ua7f5-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\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-\uab69\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\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\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\u09fe\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\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\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\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\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\u1abf\u1ac0\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\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\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\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\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,14,29,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,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,349,41,7,1,79,28,11,0,9,21,107,20,28,22,13,52,76,44,33,24,27,35,30,0,3,0,9,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,21,2,31,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,230,43,117,63,32,7,3,0,3,7,2,1,2,23,16,0,2,0,95,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,190,0,80,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,1237,43,8,8952,286,50,2,18,3,9,395,2309,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,2357,44,11,6,17,0,370,43,1301,196,60,67,8,0,1205,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,42717,35,4148,12,221,3,5761,15,7472,3104,541,1507,4938];
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,574,3,9,9,370,1,154,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,2,11,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,71,5,2,1,3,3,2,0,2,1,13,9,120,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1014,0,2,54,8,3,82,0,12,1,19628,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,262,6,10,9,419,13,1495,6,110,6,6,9,4759,9,787719,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}, startsExpr = {startsExpr: true};
131
132// Map keyword names to token types.
133
134var keywords$1 = {};
135
136// Succinct definitions of keyword token types
137function kw(name, options) {
138 if ( options === void 0 ) options = {};
139
140 options.keyword = name;
141 return keywords$1[name] = new TokenType(name, options)
142}
143
144var types = {
145 num: new TokenType("num", startsExpr),
146 regexp: new TokenType("regexp", startsExpr),
147 string: new TokenType("string", startsExpr),
148 name: new TokenType("name", startsExpr),
149 privateId: new TokenType("privateId", 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 questionDot: new TokenType("?."),
165 arrow: new TokenType("=>", beforeExpr),
166 template: new TokenType("template"),
167 invalidTemplate: new TokenType("invalidTemplate"),
168 ellipsis: new TokenType("...", beforeExpr),
169 backQuote: new TokenType("`", startsExpr),
170 dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
171
172 // Operators. These carry several kinds of properties to help the
173 // parser use them properly (the presence of these properties is
174 // what categorizes them as operators).
175 //
176 // `binop`, when present, specifies that this operator is a binary
177 // operator, and will refer to its precedence.
178 //
179 // `prefix` and `postfix` mark the operator as a prefix or postfix
180 // unary operator.
181 //
182 // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
183 // binary operators with a very low precedence, that should result
184 // in AssignmentExpression nodes.
185
186 eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
187 assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
188 incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
189 prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
190 logicalOR: binop("||", 1),
191 logicalAND: binop("&&", 2),
192 bitwiseOR: binop("|", 3),
193 bitwiseXOR: binop("^", 4),
194 bitwiseAND: binop("&", 5),
195 equality: binop("==/!=/===/!==", 6),
196 relational: binop("</>/<=/>=", 7),
197 bitShift: binop("<</>>/>>>", 8),
198 plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
199 modulo: binop("%", 10),
200 star: binop("*", 10),
201 slash: binop("/", 10),
202 starstar: new TokenType("**", {beforeExpr: true}),
203 coalesce: binop("??", 1),
204
205 // Keyword token types.
206 _break: kw("break"),
207 _case: kw("case", beforeExpr),
208 _catch: kw("catch"),
209 _continue: kw("continue"),
210 _debugger: kw("debugger"),
211 _default: kw("default", beforeExpr),
212 _do: kw("do", {isLoop: true, beforeExpr: true}),
213 _else: kw("else", beforeExpr),
214 _finally: kw("finally"),
215 _for: kw("for", {isLoop: true}),
216 _function: kw("function", startsExpr),
217 _if: kw("if"),
218 _return: kw("return", beforeExpr),
219 _switch: kw("switch"),
220 _throw: kw("throw", beforeExpr),
221 _try: kw("try"),
222 _var: kw("var"),
223 _const: kw("const"),
224 _while: kw("while", {isLoop: true}),
225 _with: kw("with"),
226 _new: kw("new", {beforeExpr: true, startsExpr: true}),
227 _this: kw("this", startsExpr),
228 _super: kw("super", startsExpr),
229 _class: kw("class", startsExpr),
230 _extends: kw("extends", beforeExpr),
231 _export: kw("export"),
232 _import: kw("import", startsExpr),
233 _null: kw("null", startsExpr),
234 _true: kw("true", startsExpr),
235 _false: kw("false", startsExpr),
236 _in: kw("in", {beforeExpr: true, binop: 7}),
237 _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
238 _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
239 _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
240 _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
241};
242
243// Matches a whole line break (where CRLF is considered a single
244// line break). Used to count lines.
245
246var lineBreak = /\r\n?|\n|\u2028|\u2029/;
247var lineBreakG = new RegExp(lineBreak.source, "g");
248
249function isNewLine(code, ecma2019String) {
250 return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029))
251}
252
253var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
254
255var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
256
257var ref = Object.prototype;
258var hasOwnProperty = ref.hasOwnProperty;
259var toString = ref.toString;
260
261// Checks if an object has a property.
262
263function has(obj, propName) {
264 return hasOwnProperty.call(obj, propName)
265}
266
267var isArray = Array.isArray || (function (obj) { return (
268 toString.call(obj) === "[object Array]"
269); });
270
271function wordsRegexp(words) {
272 return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
273}
274
275// These are used when `options.locations` is on, for the
276// `startLoc` and `endLoc` properties.
277
278var Position = function Position(line, col) {
279 this.line = line;
280 this.column = col;
281};
282
283Position.prototype.offset = function offset (n) {
284 return new Position(this.line, this.column + n)
285};
286
287var SourceLocation = function SourceLocation(p, start, end) {
288 this.start = start;
289 this.end = end;
290 if (p.sourceFile !== null) { this.source = p.sourceFile; }
291};
292
293// The `getLineInfo` function is mostly useful when the
294// `locations` option is off (for performance reasons) and you
295// want to find the line/column position for a given character
296// offset. `input` should be the code string that the offset refers
297// into.
298
299function getLineInfo(input, offset) {
300 for (var line = 1, cur = 0;;) {
301 lineBreakG.lastIndex = cur;
302 var match = lineBreakG.exec(input);
303 if (match && match.index < offset) {
304 ++line;
305 cur = match.index + match[0].length;
306 } else {
307 return new Position(line, offset - cur)
308 }
309 }
310}
311
312// A second argument must be given to configure the parser process.
313// These options are recognized (only `ecmaVersion` is required):
314
315var defaultOptions = {
316 // `ecmaVersion` indicates the ECMAScript version to parse. Must be
317 // either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10
318 // (2019), 11 (2020), 12 (2021), or `"latest"` (the latest version
319 // the library supports). This influences support for strict mode,
320 // the set of reserved words, and support for new syntax features.
321 ecmaVersion: null,
322 // `sourceType` indicates the mode the code should be parsed in.
323 // Can be either `"script"` or `"module"`. This influences global
324 // strict mode and parsing of `import` and `export` declarations.
325 sourceType: "script",
326 // `onInsertedSemicolon` can be a callback that will be called
327 // when a semicolon is automatically inserted. It will be passed
328 // the position of the comma as an offset, and if `locations` is
329 // enabled, it is given the location as a `{line, column}` object
330 // as second argument.
331 onInsertedSemicolon: null,
332 // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
333 // trailing commas.
334 onTrailingComma: null,
335 // By default, reserved words are only enforced if ecmaVersion >= 5.
336 // Set `allowReserved` to a boolean value to explicitly turn this on
337 // an off. When this option has the value "never", reserved words
338 // and keywords can also not be used as property names.
339 allowReserved: null,
340 // When enabled, a return at the top level is not considered an
341 // error.
342 allowReturnOutsideFunction: false,
343 // When enabled, import/export statements are not constrained to
344 // appearing at the top of the program, and an import.meta expression
345 // in a script isn't considered an error.
346 allowImportExportEverywhere: false,
347 // When enabled, await identifiers are allowed to appear at the top-level scope,
348 // but they are still not allowed in non-async functions.
349 allowAwaitOutsideFunction: false,
350 // When enabled, hashbang directive in the beginning of file
351 // is allowed and treated as a line comment.
352 allowHashBang: false,
353 // When `locations` is on, `loc` properties holding objects with
354 // `start` and `end` properties in `{line, column}` form (with
355 // line being 1-based and column 0-based) will be attached to the
356 // nodes.
357 locations: false,
358 // A function can be passed as `onToken` option, which will
359 // cause Acorn to call that function with object in the same
360 // format as tokens returned from `tokenizer().getToken()`. Note
361 // that you are not allowed to call the parser from the
362 // callback—that will corrupt its internal state.
363 onToken: null,
364 // A function can be passed as `onComment` option, which will
365 // cause Acorn to call that function with `(block, text, start,
366 // end)` parameters whenever a comment is skipped. `block` is a
367 // boolean indicating whether this is a block (`/* */`) comment,
368 // `text` is the content of the comment, and `start` and `end` are
369 // character offsets that denote the start and end of the comment.
370 // When the `locations` option is on, two more parameters are
371 // passed, the full `{line, column}` locations of the start and
372 // end of the comments. Note that you are not allowed to call the
373 // parser from the callback—that will corrupt its internal state.
374 onComment: null,
375 // Nodes have their start and end characters offsets recorded in
376 // `start` and `end` properties (directly on the node, rather than
377 // the `loc` object, which holds line/column data. To also add a
378 // [semi-standardized][range] `range` property holding a `[start,
379 // end]` array with the same numbers, set the `ranges` option to
380 // `true`.
381 //
382 // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
383 ranges: false,
384 // It is possible to parse multiple files into a single AST by
385 // passing the tree produced by parsing the first file as
386 // `program` option in subsequent parses. This will add the
387 // toplevel forms of the parsed file to the `Program` (top) node
388 // of an existing parse tree.
389 program: null,
390 // When `locations` is on, you can pass this to record the source
391 // file in every node's `loc` object.
392 sourceFile: null,
393 // This value, if given, is stored in every node, whether
394 // `locations` is on or off.
395 directSourceFile: null,
396 // When enabled, parenthesized expressions are represented by
397 // (non-standard) ParenthesizedExpression nodes
398 preserveParens: false
399};
400
401// Interpret and default an options object
402
403var warnedAboutEcmaVersion = false;
404
405function getOptions(opts) {
406 var options = {};
407
408 for (var opt in defaultOptions)
409 { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
410
411 if (options.ecmaVersion === "latest") {
412 options.ecmaVersion = 1e8;
413 } else if (options.ecmaVersion == null) {
414 if (!warnedAboutEcmaVersion && typeof console === "object" && console.warn) {
415 warnedAboutEcmaVersion = true;
416 console.warn("Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future.");
417 }
418 options.ecmaVersion = 11;
419 } else if (options.ecmaVersion >= 2015) {
420 options.ecmaVersion -= 2009;
421 }
422
423 if (options.allowReserved == null)
424 { options.allowReserved = options.ecmaVersion < 5; }
425
426 if (isArray(options.onToken)) {
427 var tokens = options.onToken;
428 options.onToken = function (token) { return tokens.push(token); };
429 }
430 if (isArray(options.onComment))
431 { options.onComment = pushComment(options, options.onComment); }
432
433 return options
434}
435
436function pushComment(options, array) {
437 return function(block, text, start, end, startLoc, endLoc) {
438 var comment = {
439 type: block ? "Block" : "Line",
440 value: text,
441 start: start,
442 end: end
443 };
444 if (options.locations)
445 { comment.loc = new SourceLocation(this, startLoc, endLoc); }
446 if (options.ranges)
447 { comment.range = [start, end]; }
448 array.push(comment);
449 }
450}
451
452// Each scope gets a bitset that may contain these flags
453var
454 SCOPE_TOP = 1,
455 SCOPE_FUNCTION = 2,
456 SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION,
457 SCOPE_ASYNC = 4,
458 SCOPE_GENERATOR = 8,
459 SCOPE_ARROW = 16,
460 SCOPE_SIMPLE_CATCH = 32,
461 SCOPE_SUPER = 64,
462 SCOPE_DIRECT_SUPER = 128;
463
464function functionFlags(async, generator) {
465 return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
466}
467
468// Used in checkLVal* and declareName to determine the type of a binding
469var
470 BIND_NONE = 0, // Not a binding
471 BIND_VAR = 1, // Var-style binding
472 BIND_LEXICAL = 2, // Let- or const-style binding
473 BIND_FUNCTION = 3, // Function declaration
474 BIND_SIMPLE_CATCH = 4, // Simple (identifier pattern) catch binding
475 BIND_OUTSIDE = 5; // Special case for function names as bound inside the function
476
477var Parser = function Parser(options, input, startPos) {
478 this.options = options = getOptions(options);
479 this.sourceFile = options.sourceFile;
480 this.keywords = wordsRegexp(keywords[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]);
481 var reserved = "";
482 if (options.allowReserved !== true) {
483 reserved = reservedWords[options.ecmaVersion >= 6 ? 6 : options.ecmaVersion === 5 ? 5 : 3];
484 if (options.sourceType === "module") { reserved += " await"; }
485 }
486 this.reservedWords = wordsRegexp(reserved);
487 var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
488 this.reservedWordsStrict = wordsRegexp(reservedStrict);
489 this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
490 this.input = String(input);
491
492 // Used to signal to callers of `readWord1` whether the word
493 // contained any escape sequences. This is needed because words with
494 // escape sequences must not be interpreted as keywords.
495 this.containsEsc = false;
496
497 // Set up token state
498
499 // The current position of the tokenizer in the input.
500 if (startPos) {
501 this.pos = startPos;
502 this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
503 this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
504 } else {
505 this.pos = this.lineStart = 0;
506 this.curLine = 1;
507 }
508
509 // Properties of the current token:
510 // Its type
511 this.type = types.eof;
512 // For tokens that include more information than their type, the value
513 this.value = null;
514 // Its start and end offset
515 this.start = this.end = this.pos;
516 // And, if locations are used, the {line, column} object
517 // corresponding to those offsets
518 this.startLoc = this.endLoc = this.curPosition();
519
520 // Position information for the previous token
521 this.lastTokEndLoc = this.lastTokStartLoc = null;
522 this.lastTokStart = this.lastTokEnd = this.pos;
523
524 // The context stack is used to superficially track syntactic
525 // context to predict whether a regular expression is allowed in a
526 // given position.
527 this.context = this.initialContext();
528 this.exprAllowed = true;
529
530 // Figure out if it's a module code.
531 this.inModule = options.sourceType === "module";
532 this.strict = this.inModule || this.strictDirective(this.pos);
533
534 // Used to signify the start of a potential arrow function
535 this.potentialArrowAt = -1;
536
537 // Positions to delayed-check that yield/await does not exist in default parameters.
538 this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
539 // Labels in scope.
540 this.labels = [];
541 // Thus-far undefined exports.
542 this.undefinedExports = Object.create(null);
543
544 // If enabled, skip leading hashbang line.
545 if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
546 { this.skipLineComment(2); }
547
548 // Scope tracking for duplicate variable names (see scope.js)
549 this.scopeStack = [];
550 this.enterScope(SCOPE_TOP);
551
552 // For RegExp validation
553 this.regexpState = null;
554
555 // The stack of private names.
556 // Each element has two properties: 'declared' and 'used'.
557 // When it exited from the outermost class definition, all used private names must be declared.
558 this.privateNameStack = [];
559};
560
561var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true },inNonArrowFunction: { configurable: true } };
562
563Parser.prototype.parse = function parse () {
564 var node = this.options.program || this.startNode();
565 this.nextToken();
566 return this.parseTopLevel(node)
567};
568
569prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
570prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 && !this.currentThisScope().inClassFieldInit };
571prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 && !this.currentThisScope().inClassFieldInit };
572prototypeAccessors.allowSuper.get = function () {
573 var ref = this.currentThisScope();
574 var flags = ref.flags;
575 var inClassFieldInit = ref.inClassFieldInit;
576 return (flags & SCOPE_SUPER) > 0 || inClassFieldInit
577};
578prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
579prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
580prototypeAccessors.inNonArrowFunction.get = function () {
581 var ref = this.currentThisScope();
582 var flags = ref.flags;
583 var inClassFieldInit = ref.inClassFieldInit;
584 return (flags & SCOPE_FUNCTION) > 0 || inClassFieldInit
585};
586
587Parser.extend = function extend () {
588 var plugins = [], len = arguments.length;
589 while ( len-- ) plugins[ len ] = arguments[ len ];
590
591 var cls = this;
592 for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
593 return cls
594};
595
596Parser.parse = function parse (input, options) {
597 return new this(options, input).parse()
598};
599
600Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
601 var parser = new this(options, input, pos);
602 parser.nextToken();
603 return parser.parseExpression()
604};
605
606Parser.tokenizer = function tokenizer (input, options) {
607 return new this(options, input)
608};
609
610Object.defineProperties( Parser.prototype, prototypeAccessors );
611
612var pp = Parser.prototype;
613
614// ## Parser utilities
615
616var literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/;
617pp.strictDirective = function(start) {
618 for (;;) {
619 // Try to find string literal.
620 skipWhiteSpace.lastIndex = start;
621 start += skipWhiteSpace.exec(this.input)[0].length;
622 var match = literal.exec(this.input.slice(start));
623 if (!match) { return false }
624 if ((match[1] || match[2]) === "use strict") {
625 skipWhiteSpace.lastIndex = start + match[0].length;
626 var spaceAfter = skipWhiteSpace.exec(this.input), end = spaceAfter.index + spaceAfter[0].length;
627 var next = this.input.charAt(end);
628 return next === ";" || next === "}" ||
629 (lineBreak.test(spaceAfter[0]) &&
630 !(/[(`.[+\-/*%<>=,?^&]/.test(next) || next === "!" && this.input.charAt(end + 1) === "="))
631 }
632 start += match[0].length;
633
634 // Skip semicolon, if any.
635 skipWhiteSpace.lastIndex = start;
636 start += skipWhiteSpace.exec(this.input)[0].length;
637 if (this.input[start] === ";")
638 { start++; }
639 }
640};
641
642// Predicate that tests whether the next token is of the given
643// type, and if yes, consumes it as a side effect.
644
645pp.eat = function(type) {
646 if (this.type === type) {
647 this.next();
648 return true
649 } else {
650 return false
651 }
652};
653
654// Tests whether parsed token is a contextual keyword.
655
656pp.isContextual = function(name) {
657 return this.type === types.name && this.value === name && !this.containsEsc
658};
659
660// Consumes contextual keyword if possible.
661
662pp.eatContextual = function(name) {
663 if (!this.isContextual(name)) { return false }
664 this.next();
665 return true
666};
667
668// Asserts that following token is given contextual keyword.
669
670pp.expectContextual = function(name) {
671 if (!this.eatContextual(name)) { this.unexpected(); }
672};
673
674// Test whether a semicolon can be inserted at the current position.
675
676pp.canInsertSemicolon = function() {
677 return this.type === types.eof ||
678 this.type === types.braceR ||
679 lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
680};
681
682pp.insertSemicolon = function() {
683 if (this.canInsertSemicolon()) {
684 if (this.options.onInsertedSemicolon)
685 { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
686 return true
687 }
688};
689
690// Consume a semicolon, or, failing that, see if we are allowed to
691// pretend that there is a semicolon at this position.
692
693pp.semicolon = function() {
694 if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
695};
696
697pp.afterTrailingComma = function(tokType, notNext) {
698 if (this.type === tokType) {
699 if (this.options.onTrailingComma)
700 { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
701 if (!notNext)
702 { this.next(); }
703 return true
704 }
705};
706
707// Expect a token of a given type. If found, consume it, otherwise,
708// raise an unexpected token error.
709
710pp.expect = function(type) {
711 this.eat(type) || this.unexpected();
712};
713
714// Raise an unexpected token error.
715
716pp.unexpected = function(pos) {
717 this.raise(pos != null ? pos : this.start, "Unexpected token");
718};
719
720function DestructuringErrors() {
721 this.shorthandAssign =
722 this.trailingComma =
723 this.parenthesizedAssign =
724 this.parenthesizedBind =
725 this.doubleProto =
726 -1;
727}
728
729pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
730 if (!refDestructuringErrors) { return }
731 if (refDestructuringErrors.trailingComma > -1)
732 { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
733 var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
734 if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
735};
736
737pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
738 if (!refDestructuringErrors) { return false }
739 var shorthandAssign = refDestructuringErrors.shorthandAssign;
740 var doubleProto = refDestructuringErrors.doubleProto;
741 if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
742 if (shorthandAssign >= 0)
743 { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
744 if (doubleProto >= 0)
745 { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
746};
747
748pp.checkYieldAwaitInDefaultParams = function() {
749 if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
750 { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
751 if (this.awaitPos)
752 { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
753};
754
755pp.isSimpleAssignTarget = function(expr) {
756 if (expr.type === "ParenthesizedExpression")
757 { return this.isSimpleAssignTarget(expr.expression) }
758 return expr.type === "Identifier" || expr.type === "MemberExpression"
759};
760
761var pp$1 = Parser.prototype;
762
763// ### Statement parsing
764
765// Parse a program. Initializes the parser, reads any number of
766// statements, and wraps them in a Program node. Optionally takes a
767// `program` argument. If present, the statements will be appended
768// to its body instead of creating a new node.
769
770pp$1.parseTopLevel = function(node) {
771 var exports = Object.create(null);
772 if (!node.body) { node.body = []; }
773 while (this.type !== types.eof) {
774 var stmt = this.parseStatement(null, true, exports);
775 node.body.push(stmt);
776 }
777 if (this.inModule)
778 { for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1)
779 {
780 var name = list[i];
781
782 this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
783 } }
784 this.adaptDirectivePrologue(node.body);
785 this.next();
786 node.sourceType = this.options.sourceType;
787 return this.finishNode(node, "Program")
788};
789
790var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
791
792pp$1.isLet = function(context) {
793 if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
794 skipWhiteSpace.lastIndex = this.pos;
795 var skip = skipWhiteSpace.exec(this.input);
796 var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
797 // For ambiguous cases, determine if a LexicalDeclaration (or only a
798 // Statement) is allowed here. If context is not empty then only a Statement
799 // is allowed. However, `let [` is an explicit negative lookahead for
800 // ExpressionStatement, so special-case it first.
801 if (nextCh === 91) { return true } // '['
802 if (context) { return false }
803
804 if (nextCh === 123) { return true } // '{'
805 if (isIdentifierStart(nextCh, true)) {
806 var pos = next + 1;
807 while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
808 var ident = this.input.slice(next, pos);
809 if (!keywordRelationalOperator.test(ident)) { return true }
810 }
811 return false
812};
813
814// check 'async [no LineTerminator here] function'
815// - 'async /*foo*/ function' is OK.
816// - 'async /*\n*/ function' is invalid.
817pp$1.isAsyncFunction = function() {
818 if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
819 { return false }
820
821 skipWhiteSpace.lastIndex = this.pos;
822 var skip = skipWhiteSpace.exec(this.input);
823 var next = this.pos + skip[0].length;
824 return !lineBreak.test(this.input.slice(this.pos, next)) &&
825 this.input.slice(next, next + 8) === "function" &&
826 (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
827};
828
829// Parse a single statement.
830//
831// If expecting a statement and finding a slash operator, parse a
832// regular expression literal. This is to handle cases like
833// `if (foo) /blah/.exec(foo)`, where looking at the previous token
834// does not help.
835
836pp$1.parseStatement = function(context, topLevel, exports) {
837 var starttype = this.type, node = this.startNode(), kind;
838
839 if (this.isLet(context)) {
840 starttype = types._var;
841 kind = "let";
842 }
843
844 // Most types of statements are recognized by the keyword they
845 // start with. Many are trivial to parse, some require a bit of
846 // complexity.
847
848 switch (starttype) {
849 case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
850 case types._debugger: return this.parseDebuggerStatement(node)
851 case types._do: return this.parseDoStatement(node)
852 case types._for: return this.parseForStatement(node)
853 case types._function:
854 // Function as sole body of either an if statement or a labeled statement
855 // works, but not when it is part of a labeled statement that is the sole
856 // body of an if statement.
857 if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
858 return this.parseFunctionStatement(node, false, !context)
859 case types._class:
860 if (context) { this.unexpected(); }
861 return this.parseClass(node, true)
862 case types._if: return this.parseIfStatement(node)
863 case types._return: return this.parseReturnStatement(node)
864 case types._switch: return this.parseSwitchStatement(node)
865 case types._throw: return this.parseThrowStatement(node)
866 case types._try: return this.parseTryStatement(node)
867 case types._const: case types._var:
868 kind = kind || this.value;
869 if (context && kind !== "var") { this.unexpected(); }
870 return this.parseVarStatement(node, kind)
871 case types._while: return this.parseWhileStatement(node)
872 case types._with: return this.parseWithStatement(node)
873 case types.braceL: return this.parseBlock(true, node)
874 case types.semi: return this.parseEmptyStatement(node)
875 case types._export:
876 case types._import:
877 if (this.options.ecmaVersion > 10 && starttype === types._import) {
878 skipWhiteSpace.lastIndex = this.pos;
879 var skip = skipWhiteSpace.exec(this.input);
880 var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
881 if (nextCh === 40 || nextCh === 46) // '(' or '.'
882 { return this.parseExpressionStatement(node, this.parseExpression()) }
883 }
884
885 if (!this.options.allowImportExportEverywhere) {
886 if (!topLevel)
887 { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
888 if (!this.inModule)
889 { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
890 }
891 return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
892
893 // If the statement does not start with a statement keyword or a
894 // brace, it's an ExpressionStatement or LabeledStatement. We
895 // simply start parsing an expression, and afterwards, if the
896 // next token is a colon and the expression was a simple
897 // Identifier node, we switch to interpreting it as a label.
898 default:
899 if (this.isAsyncFunction()) {
900 if (context) { this.unexpected(); }
901 this.next();
902 return this.parseFunctionStatement(node, true, !context)
903 }
904
905 var maybeName = this.value, expr = this.parseExpression();
906 if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
907 { return this.parseLabeledStatement(node, maybeName, expr, context) }
908 else { return this.parseExpressionStatement(node, expr) }
909 }
910};
911
912pp$1.parseBreakContinueStatement = function(node, keyword) {
913 var isBreak = keyword === "break";
914 this.next();
915 if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
916 else if (this.type !== types.name) { this.unexpected(); }
917 else {
918 node.label = this.parseIdent();
919 this.semicolon();
920 }
921
922 // Verify that there is an actual destination to break or
923 // continue to.
924 var i = 0;
925 for (; i < this.labels.length; ++i) {
926 var lab = this.labels[i];
927 if (node.label == null || lab.name === node.label.name) {
928 if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
929 if (node.label && isBreak) { break }
930 }
931 }
932 if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
933 return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
934};
935
936pp$1.parseDebuggerStatement = function(node) {
937 this.next();
938 this.semicolon();
939 return this.finishNode(node, "DebuggerStatement")
940};
941
942pp$1.parseDoStatement = function(node) {
943 this.next();
944 this.labels.push(loopLabel);
945 node.body = this.parseStatement("do");
946 this.labels.pop();
947 this.expect(types._while);
948 node.test = this.parseParenExpression();
949 if (this.options.ecmaVersion >= 6)
950 { this.eat(types.semi); }
951 else
952 { this.semicolon(); }
953 return this.finishNode(node, "DoWhileStatement")
954};
955
956// Disambiguating between a `for` and a `for`/`in` or `for`/`of`
957// loop is non-trivial. Basically, we have to parse the init `var`
958// statement or expression, disallowing the `in` operator (see
959// the second parameter to `parseExpression`), and then check
960// whether the next token is `in` or `of`. When there is no init
961// part (semicolon immediately after the opening parenthesis), it
962// is a regular `for` loop.
963
964pp$1.parseForStatement = function(node) {
965 this.next();
966 var awaitAt = (this.options.ecmaVersion >= 9 && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction)) && this.eatContextual("await")) ? this.lastTokStart : -1;
967 this.labels.push(loopLabel);
968 this.enterScope(0);
969 this.expect(types.parenL);
970 if (this.type === types.semi) {
971 if (awaitAt > -1) { this.unexpected(awaitAt); }
972 return this.parseFor(node, null)
973 }
974 var isLet = this.isLet();
975 if (this.type === types._var || this.type === types._const || isLet) {
976 var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
977 this.next();
978 this.parseVar(init$1, true, kind);
979 this.finishNode(init$1, "VariableDeclaration");
980 if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1) {
981 if (this.options.ecmaVersion >= 9) {
982 if (this.type === types._in) {
983 if (awaitAt > -1) { this.unexpected(awaitAt); }
984 } else { node.await = awaitAt > -1; }
985 }
986 return this.parseForIn(node, init$1)
987 }
988 if (awaitAt > -1) { this.unexpected(awaitAt); }
989 return this.parseFor(node, init$1)
990 }
991 var refDestructuringErrors = new DestructuringErrors;
992 var init = this.parseExpression(true, refDestructuringErrors);
993 if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
994 if (this.options.ecmaVersion >= 9) {
995 if (this.type === types._in) {
996 if (awaitAt > -1) { this.unexpected(awaitAt); }
997 } else { node.await = awaitAt > -1; }
998 }
999 this.toAssignable(init, false, refDestructuringErrors);
1000 this.checkLValPattern(init);
1001 return this.parseForIn(node, init)
1002 } else {
1003 this.checkExpressionErrors(refDestructuringErrors, true);
1004 }
1005 if (awaitAt > -1) { this.unexpected(awaitAt); }
1006 return this.parseFor(node, init)
1007};
1008
1009pp$1.parseFunctionStatement = function(node, isAsync, declarationPosition) {
1010 this.next();
1011 return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
1012};
1013
1014pp$1.parseIfStatement = function(node) {
1015 this.next();
1016 node.test = this.parseParenExpression();
1017 // allow function declarations in branches, but only in non-strict mode
1018 node.consequent = this.parseStatement("if");
1019 node.alternate = this.eat(types._else) ? this.parseStatement("if") : null;
1020 return this.finishNode(node, "IfStatement")
1021};
1022
1023pp$1.parseReturnStatement = function(node) {
1024 if (!this.inFunction && !this.options.allowReturnOutsideFunction)
1025 { this.raise(this.start, "'return' outside of function"); }
1026 this.next();
1027
1028 // In `return` (and `break`/`continue`), the keywords with
1029 // optional arguments, we eagerly look for a semicolon or the
1030 // possibility to insert one.
1031
1032 if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
1033 else { node.argument = this.parseExpression(); this.semicolon(); }
1034 return this.finishNode(node, "ReturnStatement")
1035};
1036
1037pp$1.parseSwitchStatement = function(node) {
1038 this.next();
1039 node.discriminant = this.parseParenExpression();
1040 node.cases = [];
1041 this.expect(types.braceL);
1042 this.labels.push(switchLabel);
1043 this.enterScope(0);
1044
1045 // Statements under must be grouped (by label) in SwitchCase
1046 // nodes. `cur` is used to keep the node that we are currently
1047 // adding statements to.
1048
1049 var cur;
1050 for (var sawDefault = false; this.type !== types.braceR;) {
1051 if (this.type === types._case || this.type === types._default) {
1052 var isCase = this.type === types._case;
1053 if (cur) { this.finishNode(cur, "SwitchCase"); }
1054 node.cases.push(cur = this.startNode());
1055 cur.consequent = [];
1056 this.next();
1057 if (isCase) {
1058 cur.test = this.parseExpression();
1059 } else {
1060 if (sawDefault) { this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); }
1061 sawDefault = true;
1062 cur.test = null;
1063 }
1064 this.expect(types.colon);
1065 } else {
1066 if (!cur) { this.unexpected(); }
1067 cur.consequent.push(this.parseStatement(null));
1068 }
1069 }
1070 this.exitScope();
1071 if (cur) { this.finishNode(cur, "SwitchCase"); }
1072 this.next(); // Closing brace
1073 this.labels.pop();
1074 return this.finishNode(node, "SwitchStatement")
1075};
1076
1077pp$1.parseThrowStatement = function(node) {
1078 this.next();
1079 if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
1080 { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
1081 node.argument = this.parseExpression();
1082 this.semicolon();
1083 return this.finishNode(node, "ThrowStatement")
1084};
1085
1086// Reused empty array added for node fields that are always empty.
1087
1088var empty = [];
1089
1090pp$1.parseTryStatement = function(node) {
1091 this.next();
1092 node.block = this.parseBlock();
1093 node.handler = null;
1094 if (this.type === types._catch) {
1095 var clause = this.startNode();
1096 this.next();
1097 if (this.eat(types.parenL)) {
1098 clause.param = this.parseBindingAtom();
1099 var simple = clause.param.type === "Identifier";
1100 this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0);
1101 this.checkLValPattern(clause.param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL);
1102 this.expect(types.parenR);
1103 } else {
1104 if (this.options.ecmaVersion < 10) { this.unexpected(); }
1105 clause.param = null;
1106 this.enterScope(0);
1107 }
1108 clause.body = this.parseBlock(false);
1109 this.exitScope();
1110 node.handler = this.finishNode(clause, "CatchClause");
1111 }
1112 node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
1113 if (!node.handler && !node.finalizer)
1114 { this.raise(node.start, "Missing catch or finally clause"); }
1115 return this.finishNode(node, "TryStatement")
1116};
1117
1118pp$1.parseVarStatement = function(node, kind) {
1119 this.next();
1120 this.parseVar(node, false, kind);
1121 this.semicolon();
1122 return this.finishNode(node, "VariableDeclaration")
1123};
1124
1125pp$1.parseWhileStatement = function(node) {
1126 this.next();
1127 node.test = this.parseParenExpression();
1128 this.labels.push(loopLabel);
1129 node.body = this.parseStatement("while");
1130 this.labels.pop();
1131 return this.finishNode(node, "WhileStatement")
1132};
1133
1134pp$1.parseWithStatement = function(node) {
1135 if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
1136 this.next();
1137 node.object = this.parseParenExpression();
1138 node.body = this.parseStatement("with");
1139 return this.finishNode(node, "WithStatement")
1140};
1141
1142pp$1.parseEmptyStatement = function(node) {
1143 this.next();
1144 return this.finishNode(node, "EmptyStatement")
1145};
1146
1147pp$1.parseLabeledStatement = function(node, maybeName, expr, context) {
1148 for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
1149 {
1150 var label = list[i$1];
1151
1152 if (label.name === maybeName)
1153 { this.raise(expr.start, "Label '" + maybeName + "' is already declared");
1154 } }
1155 var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
1156 for (var i = this.labels.length - 1; i >= 0; i--) {
1157 var label$1 = this.labels[i];
1158 if (label$1.statementStart === node.start) {
1159 // Update information about previous labels on this node
1160 label$1.statementStart = this.start;
1161 label$1.kind = kind;
1162 } else { break }
1163 }
1164 this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
1165 node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
1166 this.labels.pop();
1167 node.label = expr;
1168 return this.finishNode(node, "LabeledStatement")
1169};
1170
1171pp$1.parseExpressionStatement = function(node, expr) {
1172 node.expression = expr;
1173 this.semicolon();
1174 return this.finishNode(node, "ExpressionStatement")
1175};
1176
1177// Parse a semicolon-enclosed block of statements, handling `"use
1178// strict"` declarations when `allowStrict` is true (used for
1179// function bodies).
1180
1181pp$1.parseBlock = function(createNewLexicalScope, node, exitStrict) {
1182 if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
1183 if ( node === void 0 ) node = this.startNode();
1184
1185 node.body = [];
1186 this.expect(types.braceL);
1187 if (createNewLexicalScope) { this.enterScope(0); }
1188 while (this.type !== types.braceR) {
1189 var stmt = this.parseStatement(null);
1190 node.body.push(stmt);
1191 }
1192 if (exitStrict) { this.strict = false; }
1193 this.next();
1194 if (createNewLexicalScope) { this.exitScope(); }
1195 return this.finishNode(node, "BlockStatement")
1196};
1197
1198// Parse a regular `for` loop. The disambiguation code in
1199// `parseStatement` will already have parsed the init statement or
1200// expression.
1201
1202pp$1.parseFor = function(node, init) {
1203 node.init = init;
1204 this.expect(types.semi);
1205 node.test = this.type === types.semi ? null : this.parseExpression();
1206 this.expect(types.semi);
1207 node.update = this.type === types.parenR ? null : this.parseExpression();
1208 this.expect(types.parenR);
1209 node.body = this.parseStatement("for");
1210 this.exitScope();
1211 this.labels.pop();
1212 return this.finishNode(node, "ForStatement")
1213};
1214
1215// Parse a `for`/`in` and `for`/`of` loop, which are almost
1216// same from parser's perspective.
1217
1218pp$1.parseForIn = function(node, init) {
1219 var isForIn = this.type === types._in;
1220 this.next();
1221
1222 if (
1223 init.type === "VariableDeclaration" &&
1224 init.declarations[0].init != null &&
1225 (
1226 !isForIn ||
1227 this.options.ecmaVersion < 8 ||
1228 this.strict ||
1229 init.kind !== "var" ||
1230 init.declarations[0].id.type !== "Identifier"
1231 )
1232 ) {
1233 this.raise(
1234 init.start,
1235 ((isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer")
1236 );
1237 }
1238 node.left = init;
1239 node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
1240 this.expect(types.parenR);
1241 node.body = this.parseStatement("for");
1242 this.exitScope();
1243 this.labels.pop();
1244 return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement")
1245};
1246
1247// Parse a list of variable declarations.
1248
1249pp$1.parseVar = function(node, isFor, kind) {
1250 node.declarations = [];
1251 node.kind = kind;
1252 for (;;) {
1253 var decl = this.startNode();
1254 this.parseVarId(decl, kind);
1255 if (this.eat(types.eq)) {
1256 decl.init = this.parseMaybeAssign(isFor);
1257 } else if (kind === "const" && !(this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
1258 this.unexpected();
1259 } else if (decl.id.type !== "Identifier" && !(isFor && (this.type === types._in || this.isContextual("of")))) {
1260 this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
1261 } else {
1262 decl.init = null;
1263 }
1264 node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
1265 if (!this.eat(types.comma)) { break }
1266 }
1267 return node
1268};
1269
1270pp$1.parseVarId = function(decl, kind) {
1271 decl.id = this.parseBindingAtom();
1272 this.checkLValPattern(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
1273};
1274
1275var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
1276
1277// Parse a function declaration or literal (depending on the
1278// `statement & FUNC_STATEMENT`).
1279
1280// Remove `allowExpressionBody` for 7.0.0, as it is only called with false
1281pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync) {
1282 this.initFunction(node);
1283 if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
1284 if (this.type === types.star && (statement & FUNC_HANGING_STATEMENT))
1285 { this.unexpected(); }
1286 node.generator = this.eat(types.star);
1287 }
1288 if (this.options.ecmaVersion >= 8)
1289 { node.async = !!isAsync; }
1290
1291 if (statement & FUNC_STATEMENT) {
1292 node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types.name ? null : this.parseIdent();
1293 if (node.id && !(statement & FUNC_HANGING_STATEMENT))
1294 // If it is a regular function declaration in sloppy mode, then it is
1295 // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
1296 // mode depends on properties of the current scope (see
1297 // treatFunctionsAsVar).
1298 { this.checkLValSimple(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
1299 }
1300
1301 var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
1302 this.yieldPos = 0;
1303 this.awaitPos = 0;
1304 this.awaitIdentPos = 0;
1305 this.enterScope(functionFlags(node.async, node.generator));
1306
1307 if (!(statement & FUNC_STATEMENT))
1308 { node.id = this.type === types.name ? this.parseIdent() : null; }
1309
1310 this.parseFunctionParams(node);
1311 this.parseFunctionBody(node, allowExpressionBody, false);
1312
1313 this.yieldPos = oldYieldPos;
1314 this.awaitPos = oldAwaitPos;
1315 this.awaitIdentPos = oldAwaitIdentPos;
1316 return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
1317};
1318
1319pp$1.parseFunctionParams = function(node) {
1320 this.expect(types.parenL);
1321 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
1322 this.checkYieldAwaitInDefaultParams();
1323};
1324
1325// Parse a class declaration or literal (depending on the
1326// `isStatement` parameter).
1327
1328pp$1.parseClass = function(node, isStatement) {
1329 this.next();
1330
1331 // ecma-262 14.6 Class Definitions
1332 // A class definition is always strict mode code.
1333 var oldStrict = this.strict;
1334 this.strict = true;
1335
1336 this.parseClassId(node, isStatement);
1337 this.parseClassSuper(node);
1338 var privateNameMap = this.enterClassBody();
1339 var classBody = this.startNode();
1340 var hadConstructor = false;
1341 classBody.body = [];
1342 this.expect(types.braceL);
1343 while (this.type !== types.braceR) {
1344 var element = this.parseClassElement(node.superClass !== null);
1345 if (element) {
1346 classBody.body.push(element);
1347 if (element.type === "MethodDefinition" && element.kind === "constructor") {
1348 if (hadConstructor) { this.raise(element.start, "Duplicate constructor in the same class"); }
1349 hadConstructor = true;
1350 } else if (element.key.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) {
1351 this.raiseRecoverable(element.key.start, ("Identifier '#" + (element.key.name) + "' has already been declared"));
1352 }
1353 }
1354 }
1355 this.strict = oldStrict;
1356 this.next();
1357 node.body = this.finishNode(classBody, "ClassBody");
1358 this.exitClassBody();
1359 return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
1360};
1361
1362pp$1.parseClassElement = function(constructorAllowsSuper) {
1363 if (this.eat(types.semi)) { return null }
1364
1365 var ecmaVersion = this.options.ecmaVersion;
1366 var node = this.startNode();
1367 var keyName = "";
1368 var isGenerator = false;
1369 var isAsync = false;
1370 var kind = "method";
1371
1372 // Parse modifiers
1373 node.static = false;
1374 if (this.eatContextual("static")) {
1375 if (this.isClassElementNameStart() || this.type === types.star) {
1376 node.static = true;
1377 } else {
1378 keyName = "static";
1379 }
1380 }
1381 if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) {
1382 if ((this.isClassElementNameStart() || this.type === types.star) && !this.canInsertSemicolon()) {
1383 isAsync = true;
1384 } else {
1385 keyName = "async";
1386 }
1387 }
1388 if (!keyName && (ecmaVersion >= 9 || !isAsync) && this.eat(types.star)) {
1389 isGenerator = true;
1390 }
1391 if (!keyName && !isAsync && !isGenerator) {
1392 var lastValue = this.value;
1393 if (this.eatContextual("get") || this.eatContextual("set")) {
1394 if (this.isClassElementNameStart()) {
1395 kind = lastValue;
1396 } else {
1397 keyName = lastValue;
1398 }
1399 }
1400 }
1401
1402 // Parse element name
1403 if (keyName) {
1404 // 'async', 'get', 'set', or 'static' were not a keyword contextually.
1405 // The last token is any of those. Make it the element name.
1406 node.computed = false;
1407 node.key = this.startNodeAt(this.lastTokStart, this.lastTokStartLoc);
1408 node.key.name = keyName;
1409 this.finishNode(node.key, "Identifier");
1410 } else {
1411 this.parseClassElementName(node);
1412 }
1413
1414 // Parse element value
1415 if (ecmaVersion < 13 || this.type === types.parenL || kind !== "method" || isGenerator || isAsync) {
1416 var isConstructor = !node.static && checkKeyName(node, "constructor");
1417 var allowsDirectSuper = isConstructor && constructorAllowsSuper;
1418 // Couldn't move this check into the 'parseClassMethod' method for backward compatibility.
1419 if (isConstructor && kind !== "method") { this.raise(node.key.start, "Constructor can't have get/set modifier"); }
1420 node.kind = isConstructor ? "constructor" : kind;
1421 this.parseClassMethod(node, isGenerator, isAsync, allowsDirectSuper);
1422 } else {
1423 this.parseClassField(node);
1424 }
1425
1426 return node
1427};
1428
1429pp$1.isClassElementNameStart = function() {
1430 return (
1431 this.type === types.name ||
1432 this.type === types.privateId ||
1433 this.type === types.num ||
1434 this.type === types.string ||
1435 this.type === types.bracketL
1436 )
1437};
1438
1439pp$1.parseClassElementName = function(element) {
1440 if (this.type === types.privateId) {
1441 if (this.value === "constructor") {
1442 this.raise(this.start, "Classes can't have an element named '#constructor'");
1443 }
1444 element.computed = false;
1445 element.key = this.parsePrivateIdent();
1446 } else {
1447 this.parsePropertyName(element);
1448 }
1449};
1450
1451pp$1.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
1452 // Check key and flags
1453 var key = method.key;
1454 if (method.kind === "constructor") {
1455 if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
1456 if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
1457 } else if (method.static && checkKeyName(method, "prototype")) {
1458 this.raise(key.start, "Classes may not have a static property named prototype");
1459 }
1460
1461 // Parse value
1462 var value = method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
1463
1464 // Check value
1465 if (method.kind === "get" && value.params.length !== 0)
1466 { this.raiseRecoverable(value.start, "getter should have no params"); }
1467 if (method.kind === "set" && value.params.length !== 1)
1468 { this.raiseRecoverable(value.start, "setter should have exactly one param"); }
1469 if (method.kind === "set" && value.params[0].type === "RestElement")
1470 { this.raiseRecoverable(value.params[0].start, "Setter cannot use rest params"); }
1471
1472 return this.finishNode(method, "MethodDefinition")
1473};
1474
1475pp$1.parseClassField = function(field) {
1476 if (checkKeyName(field, "constructor")) {
1477 this.raise(field.key.start, "Classes can't have a field named 'constructor'");
1478 } else if (field.static && checkKeyName(field, "prototype")) {
1479 this.raise(field.key.start, "Classes can't have a static field named 'prototype'");
1480 }
1481
1482 if (this.eat(types.eq)) {
1483 // To raise SyntaxError if 'arguments' exists in the initializer.
1484 var scope = this.currentThisScope();
1485 var inClassFieldInit = scope.inClassFieldInit;
1486 scope.inClassFieldInit = true;
1487 field.value = this.parseMaybeAssign();
1488 scope.inClassFieldInit = inClassFieldInit;
1489 } else {
1490 field.value = null;
1491 }
1492 this.semicolon();
1493
1494 return this.finishNode(field, "PropertyDefinition")
1495};
1496
1497pp$1.parseClassId = function(node, isStatement) {
1498 if (this.type === types.name) {
1499 node.id = this.parseIdent();
1500 if (isStatement)
1501 { this.checkLValSimple(node.id, BIND_LEXICAL, false); }
1502 } else {
1503 if (isStatement === true)
1504 { this.unexpected(); }
1505 node.id = null;
1506 }
1507};
1508
1509pp$1.parseClassSuper = function(node) {
1510 node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
1511};
1512
1513pp$1.enterClassBody = function() {
1514 var element = {declared: Object.create(null), used: []};
1515 this.privateNameStack.push(element);
1516 return element.declared
1517};
1518
1519pp$1.exitClassBody = function() {
1520 var ref = this.privateNameStack.pop();
1521 var declared = ref.declared;
1522 var used = ref.used;
1523 var len = this.privateNameStack.length;
1524 var parent = len === 0 ? null : this.privateNameStack[len - 1];
1525 for (var i = 0; i < used.length; ++i) {
1526 var id = used[i];
1527 if (!has(declared, id.name)) {
1528 if (parent) {
1529 parent.used.push(id);
1530 } else {
1531 this.raiseRecoverable(id.start, ("Private field '#" + (id.name) + "' must be declared in an enclosing class"));
1532 }
1533 }
1534 }
1535};
1536
1537function isPrivateNameConflicted(privateNameMap, element) {
1538 var name = element.key.name;
1539 var curr = privateNameMap[name];
1540
1541 var next = "true";
1542 if (element.type === "MethodDefinition" && (element.kind === "get" || element.kind === "set")) {
1543 next = (element.static ? "s" : "i") + element.kind;
1544 }
1545
1546 // `class { get #a(){}; static set #a(_){} }` is also conflict.
1547 if (
1548 curr === "iget" && next === "iset" ||
1549 curr === "iset" && next === "iget" ||
1550 curr === "sget" && next === "sset" ||
1551 curr === "sset" && next === "sget"
1552 ) {
1553 privateNameMap[name] = "true";
1554 return false
1555 } else if (!curr) {
1556 privateNameMap[name] = next;
1557 return false
1558 } else {
1559 return true
1560 }
1561}
1562
1563function checkKeyName(node, name) {
1564 var computed = node.computed;
1565 var key = node.key;
1566 return !computed && (
1567 key.type === "Identifier" && key.name === name ||
1568 key.type === "Literal" && key.value === name
1569 )
1570}
1571
1572// Parses module export declaration.
1573
1574pp$1.parseExport = function(node, exports) {
1575 this.next();
1576 // export * from '...'
1577 if (this.eat(types.star)) {
1578 if (this.options.ecmaVersion >= 11) {
1579 if (this.eatContextual("as")) {
1580 node.exported = this.parseIdent(true);
1581 this.checkExport(exports, node.exported.name, this.lastTokStart);
1582 } else {
1583 node.exported = null;
1584 }
1585 }
1586 this.expectContextual("from");
1587 if (this.type !== types.string) { this.unexpected(); }
1588 node.source = this.parseExprAtom();
1589 this.semicolon();
1590 return this.finishNode(node, "ExportAllDeclaration")
1591 }
1592 if (this.eat(types._default)) { // export default ...
1593 this.checkExport(exports, "default", this.lastTokStart);
1594 var isAsync;
1595 if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
1596 var fNode = this.startNode();
1597 this.next();
1598 if (isAsync) { this.next(); }
1599 node.declaration = this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync);
1600 } else if (this.type === types._class) {
1601 var cNode = this.startNode();
1602 node.declaration = this.parseClass(cNode, "nullableID");
1603 } else {
1604 node.declaration = this.parseMaybeAssign();
1605 this.semicolon();
1606 }
1607 return this.finishNode(node, "ExportDefaultDeclaration")
1608 }
1609 // export var|const|let|function|class ...
1610 if (this.shouldParseExportStatement()) {
1611 node.declaration = this.parseStatement(null);
1612 if (node.declaration.type === "VariableDeclaration")
1613 { this.checkVariableExport(exports, node.declaration.declarations); }
1614 else
1615 { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
1616 node.specifiers = [];
1617 node.source = null;
1618 } else { // export { x, y as z } [from '...']
1619 node.declaration = null;
1620 node.specifiers = this.parseExportSpecifiers(exports);
1621 if (this.eatContextual("from")) {
1622 if (this.type !== types.string) { this.unexpected(); }
1623 node.source = this.parseExprAtom();
1624 } else {
1625 for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
1626 // check for keywords used as local names
1627 var spec = list[i];
1628
1629 this.checkUnreserved(spec.local);
1630 // check if export is defined
1631 this.checkLocalExport(spec.local);
1632 }
1633
1634 node.source = null;
1635 }
1636 this.semicolon();
1637 }
1638 return this.finishNode(node, "ExportNamedDeclaration")
1639};
1640
1641pp$1.checkExport = function(exports, name, pos) {
1642 if (!exports) { return }
1643 if (has(exports, name))
1644 { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
1645 exports[name] = true;
1646};
1647
1648pp$1.checkPatternExport = function(exports, pat) {
1649 var type = pat.type;
1650 if (type === "Identifier")
1651 { this.checkExport(exports, pat.name, pat.start); }
1652 else if (type === "ObjectPattern")
1653 { for (var i = 0, list = pat.properties; i < list.length; i += 1)
1654 {
1655 var prop = list[i];
1656
1657 this.checkPatternExport(exports, prop);
1658 } }
1659 else if (type === "ArrayPattern")
1660 { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
1661 var elt = list$1[i$1];
1662
1663 if (elt) { this.checkPatternExport(exports, elt); }
1664 } }
1665 else if (type === "Property")
1666 { this.checkPatternExport(exports, pat.value); }
1667 else if (type === "AssignmentPattern")
1668 { this.checkPatternExport(exports, pat.left); }
1669 else if (type === "RestElement")
1670 { this.checkPatternExport(exports, pat.argument); }
1671 else if (type === "ParenthesizedExpression")
1672 { this.checkPatternExport(exports, pat.expression); }
1673};
1674
1675pp$1.checkVariableExport = function(exports, decls) {
1676 if (!exports) { return }
1677 for (var i = 0, list = decls; i < list.length; i += 1)
1678 {
1679 var decl = list[i];
1680
1681 this.checkPatternExport(exports, decl.id);
1682 }
1683};
1684
1685pp$1.shouldParseExportStatement = function() {
1686 return this.type.keyword === "var" ||
1687 this.type.keyword === "const" ||
1688 this.type.keyword === "class" ||
1689 this.type.keyword === "function" ||
1690 this.isLet() ||
1691 this.isAsyncFunction()
1692};
1693
1694// Parses a comma-separated list of module exports.
1695
1696pp$1.parseExportSpecifiers = function(exports) {
1697 var nodes = [], first = true;
1698 // export { x, y as z } [from '...']
1699 this.expect(types.braceL);
1700 while (!this.eat(types.braceR)) {
1701 if (!first) {
1702 this.expect(types.comma);
1703 if (this.afterTrailingComma(types.braceR)) { break }
1704 } else { first = false; }
1705
1706 var node = this.startNode();
1707 node.local = this.parseIdent(true);
1708 node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
1709 this.checkExport(exports, node.exported.name, node.exported.start);
1710 nodes.push(this.finishNode(node, "ExportSpecifier"));
1711 }
1712 return nodes
1713};
1714
1715// Parses import declaration.
1716
1717pp$1.parseImport = function(node) {
1718 this.next();
1719 // import '...'
1720 if (this.type === types.string) {
1721 node.specifiers = empty;
1722 node.source = this.parseExprAtom();
1723 } else {
1724 node.specifiers = this.parseImportSpecifiers();
1725 this.expectContextual("from");
1726 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1727 }
1728 this.semicolon();
1729 return this.finishNode(node, "ImportDeclaration")
1730};
1731
1732// Parses a comma-separated list of module imports.
1733
1734pp$1.parseImportSpecifiers = function() {
1735 var nodes = [], first = true;
1736 if (this.type === types.name) {
1737 // import defaultObj, { x, y as z } from '...'
1738 var node = this.startNode();
1739 node.local = this.parseIdent();
1740 this.checkLValSimple(node.local, BIND_LEXICAL);
1741 nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
1742 if (!this.eat(types.comma)) { return nodes }
1743 }
1744 if (this.type === types.star) {
1745 var node$1 = this.startNode();
1746 this.next();
1747 this.expectContextual("as");
1748 node$1.local = this.parseIdent();
1749 this.checkLValSimple(node$1.local, BIND_LEXICAL);
1750 nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
1751 return nodes
1752 }
1753 this.expect(types.braceL);
1754 while (!this.eat(types.braceR)) {
1755 if (!first) {
1756 this.expect(types.comma);
1757 if (this.afterTrailingComma(types.braceR)) { break }
1758 } else { first = false; }
1759
1760 var node$2 = this.startNode();
1761 node$2.imported = this.parseIdent(true);
1762 if (this.eatContextual("as")) {
1763 node$2.local = this.parseIdent();
1764 } else {
1765 this.checkUnreserved(node$2.imported);
1766 node$2.local = node$2.imported;
1767 }
1768 this.checkLValSimple(node$2.local, BIND_LEXICAL);
1769 nodes.push(this.finishNode(node$2, "ImportSpecifier"));
1770 }
1771 return nodes
1772};
1773
1774// Set `ExpressionStatement#directive` property for directive prologues.
1775pp$1.adaptDirectivePrologue = function(statements) {
1776 for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
1777 statements[i].directive = statements[i].expression.raw.slice(1, -1);
1778 }
1779};
1780pp$1.isDirectiveCandidate = function(statement) {
1781 return (
1782 statement.type === "ExpressionStatement" &&
1783 statement.expression.type === "Literal" &&
1784 typeof statement.expression.value === "string" &&
1785 // Reject parenthesized strings.
1786 (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
1787 )
1788};
1789
1790var pp$2 = Parser.prototype;
1791
1792// Convert existing expression atom to assignable pattern
1793// if possible.
1794
1795pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
1796 if (this.options.ecmaVersion >= 6 && node) {
1797 switch (node.type) {
1798 case "Identifier":
1799 if (this.inAsync && node.name === "await")
1800 { this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
1801 break
1802
1803 case "ObjectPattern":
1804 case "ArrayPattern":
1805 case "AssignmentPattern":
1806 case "RestElement":
1807 break
1808
1809 case "ObjectExpression":
1810 node.type = "ObjectPattern";
1811 if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1812 for (var i = 0, list = node.properties; i < list.length; i += 1) {
1813 var prop = list[i];
1814
1815 this.toAssignable(prop, isBinding);
1816 // Early error:
1817 // AssignmentRestProperty[Yield, Await] :
1818 // `...` DestructuringAssignmentTarget[Yield, Await]
1819 //
1820 // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
1821 if (
1822 prop.type === "RestElement" &&
1823 (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
1824 ) {
1825 this.raise(prop.argument.start, "Unexpected token");
1826 }
1827 }
1828 break
1829
1830 case "Property":
1831 // AssignmentProperty has type === "Property"
1832 if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
1833 this.toAssignable(node.value, isBinding);
1834 break
1835
1836 case "ArrayExpression":
1837 node.type = "ArrayPattern";
1838 if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1839 this.toAssignableList(node.elements, isBinding);
1840 break
1841
1842 case "SpreadElement":
1843 node.type = "RestElement";
1844 this.toAssignable(node.argument, isBinding);
1845 if (node.argument.type === "AssignmentPattern")
1846 { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
1847 break
1848
1849 case "AssignmentExpression":
1850 if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
1851 node.type = "AssignmentPattern";
1852 delete node.operator;
1853 this.toAssignable(node.left, isBinding);
1854 break
1855
1856 case "ParenthesizedExpression":
1857 this.toAssignable(node.expression, isBinding, refDestructuringErrors);
1858 break
1859
1860 case "ChainExpression":
1861 this.raiseRecoverable(node.start, "Optional chaining cannot appear in left-hand side");
1862 break
1863
1864 case "MemberExpression":
1865 if (!isBinding) { break }
1866
1867 default:
1868 this.raise(node.start, "Assigning to rvalue");
1869 }
1870 } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1871 return node
1872};
1873
1874// Convert list of expression atoms to binding list.
1875
1876pp$2.toAssignableList = function(exprList, isBinding) {
1877 var end = exprList.length;
1878 for (var i = 0; i < end; i++) {
1879 var elt = exprList[i];
1880 if (elt) { this.toAssignable(elt, isBinding); }
1881 }
1882 if (end) {
1883 var last = exprList[end - 1];
1884 if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
1885 { this.unexpected(last.argument.start); }
1886 }
1887 return exprList
1888};
1889
1890// Parses spread element.
1891
1892pp$2.parseSpread = function(refDestructuringErrors) {
1893 var node = this.startNode();
1894 this.next();
1895 node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
1896 return this.finishNode(node, "SpreadElement")
1897};
1898
1899pp$2.parseRestBinding = function() {
1900 var node = this.startNode();
1901 this.next();
1902
1903 // RestElement inside of a function parameter must be an identifier
1904 if (this.options.ecmaVersion === 6 && this.type !== types.name)
1905 { this.unexpected(); }
1906
1907 node.argument = this.parseBindingAtom();
1908
1909 return this.finishNode(node, "RestElement")
1910};
1911
1912// Parses lvalue (assignable) atom.
1913
1914pp$2.parseBindingAtom = function() {
1915 if (this.options.ecmaVersion >= 6) {
1916 switch (this.type) {
1917 case types.bracketL:
1918 var node = this.startNode();
1919 this.next();
1920 node.elements = this.parseBindingList(types.bracketR, true, true);
1921 return this.finishNode(node, "ArrayPattern")
1922
1923 case types.braceL:
1924 return this.parseObj(true)
1925 }
1926 }
1927 return this.parseIdent()
1928};
1929
1930pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
1931 var elts = [], first = true;
1932 while (!this.eat(close)) {
1933 if (first) { first = false; }
1934 else { this.expect(types.comma); }
1935 if (allowEmpty && this.type === types.comma) {
1936 elts.push(null);
1937 } else if (allowTrailingComma && this.afterTrailingComma(close)) {
1938 break
1939 } else if (this.type === types.ellipsis) {
1940 var rest = this.parseRestBinding();
1941 this.parseBindingListItem(rest);
1942 elts.push(rest);
1943 if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
1944 this.expect(close);
1945 break
1946 } else {
1947 var elem = this.parseMaybeDefault(this.start, this.startLoc);
1948 this.parseBindingListItem(elem);
1949 elts.push(elem);
1950 }
1951 }
1952 return elts
1953};
1954
1955pp$2.parseBindingListItem = function(param) {
1956 return param
1957};
1958
1959// Parses assignment pattern around given atom if possible.
1960
1961pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
1962 left = left || this.parseBindingAtom();
1963 if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
1964 var node = this.startNodeAt(startPos, startLoc);
1965 node.left = left;
1966 node.right = this.parseMaybeAssign();
1967 return this.finishNode(node, "AssignmentPattern")
1968};
1969
1970// The following three functions all verify that a node is an lvalue —
1971// something that can be bound, or assigned to. In order to do so, they perform
1972// a variety of checks:
1973//
1974// - Check that none of the bound/assigned-to identifiers are reserved words.
1975// - Record name declarations for bindings in the appropriate scope.
1976// - Check duplicate argument names, if checkClashes is set.
1977//
1978// If a complex binding pattern is encountered (e.g., object and array
1979// destructuring), the entire pattern is recursively checked.
1980//
1981// There are three versions of checkLVal*() appropriate for different
1982// circumstances:
1983//
1984// - checkLValSimple() shall be used if the syntactic construct supports
1985// nothing other than identifiers and member expressions. Parenthesized
1986// expressions are also correctly handled. This is generally appropriate for
1987// constructs for which the spec says
1988//
1989// > It is a Syntax Error if AssignmentTargetType of [the production] is not
1990// > simple.
1991//
1992// It is also appropriate for checking if an identifier is valid and not
1993// defined elsewhere, like import declarations or function/class identifiers.
1994//
1995// Examples where this is used include:
1996// a += …;
1997// import a from '…';
1998// where a is the node to be checked.
1999//
2000// - checkLValPattern() shall be used if the syntactic construct supports
2001// anything checkLValSimple() supports, as well as object and array
2002// destructuring patterns. This is generally appropriate for constructs for
2003// which the spec says
2004//
2005// > It is a Syntax Error if [the production] is neither an ObjectLiteral nor
2006// > an ArrayLiteral and AssignmentTargetType of [the production] is not
2007// > simple.
2008//
2009// Examples where this is used include:
2010// (a = …);
2011// const a = …;
2012// try { … } catch (a) { … }
2013// where a is the node to be checked.
2014//
2015// - checkLValInnerPattern() shall be used if the syntactic construct supports
2016// anything checkLValPattern() supports, as well as default assignment
2017// patterns, rest elements, and other constructs that may appear within an
2018// object or array destructuring pattern.
2019//
2020// As a special case, function parameters also use checkLValInnerPattern(),
2021// as they also support defaults and rest constructs.
2022//
2023// These functions deliberately support both assignment and binding constructs,
2024// as the logic for both is exceedingly similar. If the node is the target of
2025// an assignment, then bindingType should be set to BIND_NONE. Otherwise, it
2026// should be set to the appropriate BIND_* constant, like BIND_VAR or
2027// BIND_LEXICAL.
2028//
2029// If the function is called with a non-BIND_NONE bindingType, then
2030// additionally a checkClashes object may be specified to allow checking for
2031// duplicate argument names. checkClashes is ignored if the provided construct
2032// is an assignment (i.e., bindingType is BIND_NONE).
2033
2034pp$2.checkLValSimple = function(expr, bindingType, checkClashes) {
2035 if ( bindingType === void 0 ) bindingType = BIND_NONE;
2036
2037 var isBind = bindingType !== BIND_NONE;
2038
2039 switch (expr.type) {
2040 case "Identifier":
2041 if (this.strict && this.reservedWordsStrictBind.test(expr.name))
2042 { this.raiseRecoverable(expr.start, (isBind ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
2043 if (isBind) {
2044 if (bindingType === BIND_LEXICAL && expr.name === "let")
2045 { this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); }
2046 if (checkClashes) {
2047 if (has(checkClashes, expr.name))
2048 { this.raiseRecoverable(expr.start, "Argument name clash"); }
2049 checkClashes[expr.name] = true;
2050 }
2051 if (bindingType !== BIND_OUTSIDE) { this.declareName(expr.name, bindingType, expr.start); }
2052 }
2053 break
2054
2055 case "ChainExpression":
2056 this.raiseRecoverable(expr.start, "Optional chaining cannot appear in left-hand side");
2057 break
2058
2059 case "MemberExpression":
2060 if (isBind) { this.raiseRecoverable(expr.start, "Binding member expression"); }
2061 break
2062
2063 case "ParenthesizedExpression":
2064 if (isBind) { this.raiseRecoverable(expr.start, "Binding parenthesized expression"); }
2065 return this.checkLValSimple(expr.expression, bindingType, checkClashes)
2066
2067 default:
2068 this.raise(expr.start, (isBind ? "Binding" : "Assigning to") + " rvalue");
2069 }
2070};
2071
2072pp$2.checkLValPattern = function(expr, bindingType, checkClashes) {
2073 if ( bindingType === void 0 ) bindingType = BIND_NONE;
2074
2075 switch (expr.type) {
2076 case "ObjectPattern":
2077 for (var i = 0, list = expr.properties; i < list.length; i += 1) {
2078 var prop = list[i];
2079
2080 this.checkLValInnerPattern(prop, bindingType, checkClashes);
2081 }
2082 break
2083
2084 case "ArrayPattern":
2085 for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
2086 var elem = list$1[i$1];
2087
2088 if (elem) { this.checkLValInnerPattern(elem, bindingType, checkClashes); }
2089 }
2090 break
2091
2092 default:
2093 this.checkLValSimple(expr, bindingType, checkClashes);
2094 }
2095};
2096
2097pp$2.checkLValInnerPattern = function(expr, bindingType, checkClashes) {
2098 if ( bindingType === void 0 ) bindingType = BIND_NONE;
2099
2100 switch (expr.type) {
2101 case "Property":
2102 // AssignmentProperty has type === "Property"
2103 this.checkLValInnerPattern(expr.value, bindingType, checkClashes);
2104 break
2105
2106 case "AssignmentPattern":
2107 this.checkLValPattern(expr.left, bindingType, checkClashes);
2108 break
2109
2110 case "RestElement":
2111 this.checkLValPattern(expr.argument, bindingType, checkClashes);
2112 break
2113
2114 default:
2115 this.checkLValPattern(expr, bindingType, checkClashes);
2116 }
2117};
2118
2119// A recursive descent parser operates by defining functions for all
2120
2121var pp$3 = Parser.prototype;
2122
2123// Check if property name clashes with already added.
2124// Object/class getters and setters are not allowed to clash —
2125// either with each other or with an init property — and in
2126// strict mode, init properties are also not allowed to be repeated.
2127
2128pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
2129 if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
2130 { return }
2131 if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
2132 { return }
2133 var key = prop.key;
2134 var name;
2135 switch (key.type) {
2136 case "Identifier": name = key.name; break
2137 case "Literal": name = String(key.value); break
2138 default: return
2139 }
2140 var kind = prop.kind;
2141 if (this.options.ecmaVersion >= 6) {
2142 if (name === "__proto__" && kind === "init") {
2143 if (propHash.proto) {
2144 if (refDestructuringErrors) {
2145 if (refDestructuringErrors.doubleProto < 0)
2146 { refDestructuringErrors.doubleProto = key.start; }
2147 // Backwards-compat kludge. Can be removed in version 6.0
2148 } else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
2149 }
2150 propHash.proto = true;
2151 }
2152 return
2153 }
2154 name = "$" + name;
2155 var other = propHash[name];
2156 if (other) {
2157 var redefinition;
2158 if (kind === "init") {
2159 redefinition = this.strict && other.init || other.get || other.set;
2160 } else {
2161 redefinition = other.init || other[kind];
2162 }
2163 if (redefinition)
2164 { this.raiseRecoverable(key.start, "Redefinition of property"); }
2165 } else {
2166 other = propHash[name] = {
2167 init: false,
2168 get: false,
2169 set: false
2170 };
2171 }
2172 other[kind] = true;
2173};
2174
2175// ### Expression parsing
2176
2177// These nest, from the most general expression type at the top to
2178// 'atomic', nondivisible expression types at the bottom. Most of
2179// the functions will simply let the function(s) below them parse,
2180// and, *if* the syntactic construct they handle is present, wrap
2181// the AST node that the inner parser gave them in another node.
2182
2183// Parse a full expression. The optional arguments are used to
2184// forbid the `in` operator (in for loops initalization expressions)
2185// and provide reference for storing '=' operator inside shorthand
2186// property assignment in contexts where both object expression
2187// and object pattern might appear (so it's possible to raise
2188// delayed syntax error at correct position).
2189
2190pp$3.parseExpression = function(noIn, refDestructuringErrors) {
2191 var startPos = this.start, startLoc = this.startLoc;
2192 var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
2193 if (this.type === types.comma) {
2194 var node = this.startNodeAt(startPos, startLoc);
2195 node.expressions = [expr];
2196 while (this.eat(types.comma)) { node.expressions.push(this.parseMaybeAssign(noIn, refDestructuringErrors)); }
2197 return this.finishNode(node, "SequenceExpression")
2198 }
2199 return expr
2200};
2201
2202// Parse an assignment expression. This includes applications of
2203// operators like `+=`.
2204
2205pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
2206 if (this.isContextual("yield")) {
2207 if (this.inGenerator) { return this.parseYield(noIn) }
2208 // The tokenizer will assume an expression is allowed after
2209 // `yield`, but this isn't that kind of yield
2210 else { this.exprAllowed = false; }
2211 }
2212
2213 var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
2214 if (refDestructuringErrors) {
2215 oldParenAssign = refDestructuringErrors.parenthesizedAssign;
2216 oldTrailingComma = refDestructuringErrors.trailingComma;
2217 refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
2218 } else {
2219 refDestructuringErrors = new DestructuringErrors;
2220 ownDestructuringErrors = true;
2221 }
2222
2223 var startPos = this.start, startLoc = this.startLoc;
2224 if (this.type === types.parenL || this.type === types.name)
2225 { this.potentialArrowAt = this.start; }
2226 var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
2227 if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
2228 if (this.type.isAssign) {
2229 var node = this.startNodeAt(startPos, startLoc);
2230 node.operator = this.value;
2231 if (this.type === types.eq)
2232 { left = this.toAssignable(left, false, refDestructuringErrors); }
2233 if (!ownDestructuringErrors) {
2234 refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1;
2235 }
2236 if (refDestructuringErrors.shorthandAssign >= left.start)
2237 { refDestructuringErrors.shorthandAssign = -1; } // reset because shorthand default was used correctly
2238 if (this.type === types.eq)
2239 { this.checkLValPattern(left); }
2240 else
2241 { this.checkLValSimple(left); }
2242 node.left = left;
2243 this.next();
2244 node.right = this.parseMaybeAssign(noIn);
2245 return this.finishNode(node, "AssignmentExpression")
2246 } else {
2247 if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
2248 }
2249 if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
2250 if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
2251 return left
2252};
2253
2254// Parse a ternary conditional (`?:`) operator.
2255
2256pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
2257 var startPos = this.start, startLoc = this.startLoc;
2258 var expr = this.parseExprOps(noIn, refDestructuringErrors);
2259 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
2260 if (this.eat(types.question)) {
2261 var node = this.startNodeAt(startPos, startLoc);
2262 node.test = expr;
2263 node.consequent = this.parseMaybeAssign();
2264 this.expect(types.colon);
2265 node.alternate = this.parseMaybeAssign(noIn);
2266 return this.finishNode(node, "ConditionalExpression")
2267 }
2268 return expr
2269};
2270
2271// Start the precedence parser.
2272
2273pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
2274 var startPos = this.start, startLoc = this.startLoc;
2275 var expr = this.parseMaybeUnary(refDestructuringErrors, false);
2276 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
2277 return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
2278};
2279
2280// Parse binary operators with the operator precedence parsing
2281// algorithm. `left` is the left-hand side of the operator.
2282// `minPrec` provides context that allows the function to stop and
2283// defer further parser to one of its callers when it encounters an
2284// operator that has a lower precedence than the set it is parsing.
2285
2286pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
2287 var prec = this.type.binop;
2288 if (prec != null && (!noIn || this.type !== types._in)) {
2289 if (prec > minPrec) {
2290 var logical = this.type === types.logicalOR || this.type === types.logicalAND;
2291 var coalesce = this.type === types.coalesce;
2292 if (coalesce) {
2293 // Handle the precedence of `tt.coalesce` as equal to the range of logical expressions.
2294 // In other words, `node.right` shouldn't contain logical expressions in order to check the mixed error.
2295 prec = types.logicalAND.binop;
2296 }
2297 var op = this.value;
2298 this.next();
2299 var startPos = this.start, startLoc = this.startLoc;
2300 var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
2301 var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce);
2302 if ((logical && this.type === types.coalesce) || (coalesce && (this.type === types.logicalOR || this.type === types.logicalAND))) {
2303 this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses");
2304 }
2305 return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
2306 }
2307 }
2308 return left
2309};
2310
2311pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
2312 var node = this.startNodeAt(startPos, startLoc);
2313 node.left = left;
2314 node.operator = op;
2315 node.right = right;
2316 return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
2317};
2318
2319// Parse unary operators, both prefix and postfix.
2320
2321pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
2322 var startPos = this.start, startLoc = this.startLoc, expr;
2323 if (this.isContextual("await") && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction))) {
2324 expr = this.parseAwait();
2325 sawUnary = true;
2326 } else if (this.type.prefix) {
2327 var node = this.startNode(), update = this.type === types.incDec;
2328 node.operator = this.value;
2329 node.prefix = true;
2330 this.next();
2331 node.argument = this.parseMaybeUnary(null, true);
2332 this.checkExpressionErrors(refDestructuringErrors, true);
2333 if (update) { this.checkLValSimple(node.argument); }
2334 else if (this.strict && node.operator === "delete" &&
2335 node.argument.type === "Identifier")
2336 { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
2337 else if (node.operator === "delete" && isPrivateFieldAccess(node.argument))
2338 { this.raiseRecoverable(node.start, "Private fields can not be deleted"); }
2339 else { sawUnary = true; }
2340 expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
2341 } else {
2342 expr = this.parseExprSubscripts(refDestructuringErrors);
2343 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
2344 while (this.type.postfix && !this.canInsertSemicolon()) {
2345 var node$1 = this.startNodeAt(startPos, startLoc);
2346 node$1.operator = this.value;
2347 node$1.prefix = false;
2348 node$1.argument = expr;
2349 this.checkLValSimple(expr);
2350 this.next();
2351 expr = this.finishNode(node$1, "UpdateExpression");
2352 }
2353 }
2354
2355 if (!sawUnary && this.eat(types.starstar))
2356 { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
2357 else
2358 { return expr }
2359};
2360
2361function isPrivateFieldAccess(node) {
2362 return (
2363 node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" ||
2364 node.type === "ChainExpression" && isPrivateFieldAccess(node.expression)
2365 )
2366}
2367
2368// Parse call, dot, and `[]`-subscript expressions.
2369
2370pp$3.parseExprSubscripts = function(refDestructuringErrors) {
2371 var startPos = this.start, startLoc = this.startLoc;
2372 var expr = this.parseExprAtom(refDestructuringErrors);
2373 if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")")
2374 { return expr }
2375 var result = this.parseSubscripts(expr, startPos, startLoc);
2376 if (refDestructuringErrors && result.type === "MemberExpression") {
2377 if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
2378 if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
2379 if (refDestructuringErrors.trailingComma >= result.start) { refDestructuringErrors.trailingComma = -1; }
2380 }
2381 return result
2382};
2383
2384pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
2385 var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
2386 this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 &&
2387 this.potentialArrowAt === base.start;
2388 var optionalChained = false;
2389
2390 while (true) {
2391 var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained);
2392
2393 if (element.optional) { optionalChained = true; }
2394 if (element === base || element.type === "ArrowFunctionExpression") {
2395 if (optionalChained) {
2396 var chainNode = this.startNodeAt(startPos, startLoc);
2397 chainNode.expression = element;
2398 element = this.finishNode(chainNode, "ChainExpression");
2399 }
2400 return element
2401 }
2402
2403 base = element;
2404 }
2405};
2406
2407pp$3.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained) {
2408 var optionalSupported = this.options.ecmaVersion >= 11;
2409 var optional = optionalSupported && this.eat(types.questionDot);
2410 if (noCalls && optional) { this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); }
2411
2412 var computed = this.eat(types.bracketL);
2413 if (computed || (optional && this.type !== types.parenL && this.type !== types.backQuote) || this.eat(types.dot)) {
2414 var node = this.startNodeAt(startPos, startLoc);
2415 node.object = base;
2416 if (computed) {
2417 node.property = this.parseExpression();
2418 this.expect(types.bracketR);
2419 } else if (this.type === types.privateId && base.type !== "Super") {
2420 node.property = this.parsePrivateIdent();
2421 } else {
2422 node.property = this.parseIdent(this.options.allowReserved !== "never");
2423 }
2424 node.computed = !!computed;
2425 if (optionalSupported) {
2426 node.optional = optional;
2427 }
2428 base = this.finishNode(node, "MemberExpression");
2429 } else if (!noCalls && this.eat(types.parenL)) {
2430 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
2431 this.yieldPos = 0;
2432 this.awaitPos = 0;
2433 this.awaitIdentPos = 0;
2434 var exprList = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors);
2435 if (maybeAsyncArrow && !optional && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2436 this.checkPatternErrors(refDestructuringErrors, false);
2437 this.checkYieldAwaitInDefaultParams();
2438 if (this.awaitIdentPos > 0)
2439 { this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); }
2440 this.yieldPos = oldYieldPos;
2441 this.awaitPos = oldAwaitPos;
2442 this.awaitIdentPos = oldAwaitIdentPos;
2443 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true)
2444 }
2445 this.checkExpressionErrors(refDestructuringErrors, true);
2446 this.yieldPos = oldYieldPos || this.yieldPos;
2447 this.awaitPos = oldAwaitPos || this.awaitPos;
2448 this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos;
2449 var node$1 = this.startNodeAt(startPos, startLoc);
2450 node$1.callee = base;
2451 node$1.arguments = exprList;
2452 if (optionalSupported) {
2453 node$1.optional = optional;
2454 }
2455 base = this.finishNode(node$1, "CallExpression");
2456 } else if (this.type === types.backQuote) {
2457 if (optional || optionalChained) {
2458 this.raise(this.start, "Optional chaining cannot appear in the tag of tagged template expressions");
2459 }
2460 var node$2 = this.startNodeAt(startPos, startLoc);
2461 node$2.tag = base;
2462 node$2.quasi = this.parseTemplate({isTagged: true});
2463 base = this.finishNode(node$2, "TaggedTemplateExpression");
2464 }
2465 return base
2466};
2467
2468// Parse an atomic expression — either a single token that is an
2469// expression, an expression started by a keyword like `function` or
2470// `new`, or an expression wrapped in punctuation like `()`, `[]`,
2471// or `{}`.
2472
2473pp$3.parseExprAtom = function(refDestructuringErrors) {
2474 // If a division operator appears in an expression position, the
2475 // tokenizer got confused, and we force it to read a regexp instead.
2476 if (this.type === types.slash) { this.readRegexp(); }
2477
2478 var node, canBeArrow = this.potentialArrowAt === this.start;
2479 switch (this.type) {
2480 case types._super:
2481 if (!this.allowSuper)
2482 { this.raise(this.start, "'super' keyword outside a method"); }
2483 node = this.startNode();
2484 this.next();
2485 if (this.type === types.parenL && !this.allowDirectSuper)
2486 { this.raise(node.start, "super() call outside constructor of a subclass"); }
2487 // The `super` keyword can appear at below:
2488 // SuperProperty:
2489 // super [ Expression ]
2490 // super . IdentifierName
2491 // SuperCall:
2492 // super ( Arguments )
2493 if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
2494 { this.unexpected(); }
2495 return this.finishNode(node, "Super")
2496
2497 case types._this:
2498 node = this.startNode();
2499 this.next();
2500 return this.finishNode(node, "ThisExpression")
2501
2502 case types.name:
2503 var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
2504 var id = this.parseIdent(false);
2505 if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
2506 { return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true) }
2507 if (canBeArrow && !this.canInsertSemicolon()) {
2508 if (this.eat(types.arrow))
2509 { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
2510 if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
2511 id = this.parseIdent(false);
2512 if (this.canInsertSemicolon() || !this.eat(types.arrow))
2513 { this.unexpected(); }
2514 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
2515 }
2516 }
2517 return id
2518
2519 case types.regexp:
2520 var value = this.value;
2521 node = this.parseLiteral(value.value);
2522 node.regex = {pattern: value.pattern, flags: value.flags};
2523 return node
2524
2525 case types.num: case types.string:
2526 return this.parseLiteral(this.value)
2527
2528 case types._null: case types._true: case types._false:
2529 node = this.startNode();
2530 node.value = this.type === types._null ? null : this.type === types._true;
2531 node.raw = this.type.keyword;
2532 this.next();
2533 return this.finishNode(node, "Literal")
2534
2535 case types.parenL:
2536 var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
2537 if (refDestructuringErrors) {
2538 if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
2539 { refDestructuringErrors.parenthesizedAssign = start; }
2540 if (refDestructuringErrors.parenthesizedBind < 0)
2541 { refDestructuringErrors.parenthesizedBind = start; }
2542 }
2543 return expr
2544
2545 case types.bracketL:
2546 node = this.startNode();
2547 this.next();
2548 node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
2549 return this.finishNode(node, "ArrayExpression")
2550
2551 case types.braceL:
2552 return this.parseObj(false, refDestructuringErrors)
2553
2554 case types._function:
2555 node = this.startNode();
2556 this.next();
2557 return this.parseFunction(node, 0)
2558
2559 case types._class:
2560 return this.parseClass(this.startNode(), false)
2561
2562 case types._new:
2563 return this.parseNew()
2564
2565 case types.backQuote:
2566 return this.parseTemplate()
2567
2568 case types._import:
2569 if (this.options.ecmaVersion >= 11) {
2570 return this.parseExprImport()
2571 } else {
2572 return this.unexpected()
2573 }
2574
2575 default:
2576 this.unexpected();
2577 }
2578};
2579
2580pp$3.parseExprImport = function() {
2581 var node = this.startNode();
2582
2583 // Consume `import` as an identifier for `import.meta`.
2584 // Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`.
2585 if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword import"); }
2586 var meta = this.parseIdent(true);
2587
2588 switch (this.type) {
2589 case types.parenL:
2590 return this.parseDynamicImport(node)
2591 case types.dot:
2592 node.meta = meta;
2593 return this.parseImportMeta(node)
2594 default:
2595 this.unexpected();
2596 }
2597};
2598
2599pp$3.parseDynamicImport = function(node) {
2600 this.next(); // skip `(`
2601
2602 // Parse node.source.
2603 node.source = this.parseMaybeAssign();
2604
2605 // Verify ending.
2606 if (!this.eat(types.parenR)) {
2607 var errorPos = this.start;
2608 if (this.eat(types.comma) && this.eat(types.parenR)) {
2609 this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()");
2610 } else {
2611 this.unexpected(errorPos);
2612 }
2613 }
2614
2615 return this.finishNode(node, "ImportExpression")
2616};
2617
2618pp$3.parseImportMeta = function(node) {
2619 this.next(); // skip `.`
2620
2621 var containsEsc = this.containsEsc;
2622 node.property = this.parseIdent(true);
2623
2624 if (node.property.name !== "meta")
2625 { this.raiseRecoverable(node.property.start, "The only valid meta property for import is 'import.meta'"); }
2626 if (containsEsc)
2627 { this.raiseRecoverable(node.start, "'import.meta' must not contain escaped characters"); }
2628 if (this.options.sourceType !== "module" && !this.options.allowImportExportEverywhere)
2629 { this.raiseRecoverable(node.start, "Cannot use 'import.meta' outside a module"); }
2630
2631 return this.finishNode(node, "MetaProperty")
2632};
2633
2634pp$3.parseLiteral = function(value) {
2635 var node = this.startNode();
2636 node.value = value;
2637 node.raw = this.input.slice(this.start, this.end);
2638 if (node.raw.charCodeAt(node.raw.length - 1) === 110) { node.bigint = node.raw.slice(0, -1).replace(/_/g, ""); }
2639 this.next();
2640 return this.finishNode(node, "Literal")
2641};
2642
2643pp$3.parseParenExpression = function() {
2644 this.expect(types.parenL);
2645 var val = this.parseExpression();
2646 this.expect(types.parenR);
2647 return val
2648};
2649
2650pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
2651 var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
2652 if (this.options.ecmaVersion >= 6) {
2653 this.next();
2654
2655 var innerStartPos = this.start, innerStartLoc = this.startLoc;
2656 var exprList = [], first = true, lastIsComma = false;
2657 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
2658 this.yieldPos = 0;
2659 this.awaitPos = 0;
2660 // Do not save awaitIdentPos to allow checking awaits nested in parameters
2661 while (this.type !== types.parenR) {
2662 first ? first = false : this.expect(types.comma);
2663 if (allowTrailingComma && this.afterTrailingComma(types.parenR, true)) {
2664 lastIsComma = true;
2665 break
2666 } else if (this.type === types.ellipsis) {
2667 spreadStart = this.start;
2668 exprList.push(this.parseParenItem(this.parseRestBinding()));
2669 if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
2670 break
2671 } else {
2672 exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
2673 }
2674 }
2675 var innerEndPos = this.start, innerEndLoc = this.startLoc;
2676 this.expect(types.parenR);
2677
2678 if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2679 this.checkPatternErrors(refDestructuringErrors, false);
2680 this.checkYieldAwaitInDefaultParams();
2681 this.yieldPos = oldYieldPos;
2682 this.awaitPos = oldAwaitPos;
2683 return this.parseParenArrowList(startPos, startLoc, exprList)
2684 }
2685
2686 if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
2687 if (spreadStart) { this.unexpected(spreadStart); }
2688 this.checkExpressionErrors(refDestructuringErrors, true);
2689 this.yieldPos = oldYieldPos || this.yieldPos;
2690 this.awaitPos = oldAwaitPos || this.awaitPos;
2691
2692 if (exprList.length > 1) {
2693 val = this.startNodeAt(innerStartPos, innerStartLoc);
2694 val.expressions = exprList;
2695 this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
2696 } else {
2697 val = exprList[0];
2698 }
2699 } else {
2700 val = this.parseParenExpression();
2701 }
2702
2703 if (this.options.preserveParens) {
2704 var par = this.startNodeAt(startPos, startLoc);
2705 par.expression = val;
2706 return this.finishNode(par, "ParenthesizedExpression")
2707 } else {
2708 return val
2709 }
2710};
2711
2712pp$3.parseParenItem = function(item) {
2713 return item
2714};
2715
2716pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
2717 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
2718};
2719
2720// New's precedence is slightly tricky. It must allow its argument to
2721// be a `[]` or dot subscript expression, but not a call — at least,
2722// not without wrapping it in parentheses. Thus, it uses the noCalls
2723// argument to parseSubscripts to prevent it from consuming the
2724// argument list.
2725
2726var empty$1 = [];
2727
2728pp$3.parseNew = function() {
2729 if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword new"); }
2730 var node = this.startNode();
2731 var meta = this.parseIdent(true);
2732 if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
2733 node.meta = meta;
2734 var containsEsc = this.containsEsc;
2735 node.property = this.parseIdent(true);
2736 if (node.property.name !== "target")
2737 { this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'"); }
2738 if (containsEsc)
2739 { this.raiseRecoverable(node.start, "'new.target' must not contain escaped characters"); }
2740 if (!this.inNonArrowFunction)
2741 { this.raiseRecoverable(node.start, "'new.target' can only be used in functions"); }
2742 return this.finishNode(node, "MetaProperty")
2743 }
2744 var startPos = this.start, startLoc = this.startLoc, isImport = this.type === types._import;
2745 node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
2746 if (isImport && node.callee.type === "ImportExpression") {
2747 this.raise(startPos, "Cannot use new with import()");
2748 }
2749 if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
2750 else { node.arguments = empty$1; }
2751 return this.finishNode(node, "NewExpression")
2752};
2753
2754// Parse template expression.
2755
2756pp$3.parseTemplateElement = function(ref) {
2757 var isTagged = ref.isTagged;
2758
2759 var elem = this.startNode();
2760 if (this.type === types.invalidTemplate) {
2761 if (!isTagged) {
2762 this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
2763 }
2764 elem.value = {
2765 raw: this.value,
2766 cooked: null
2767 };
2768 } else {
2769 elem.value = {
2770 raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
2771 cooked: this.value
2772 };
2773 }
2774 this.next();
2775 elem.tail = this.type === types.backQuote;
2776 return this.finishNode(elem, "TemplateElement")
2777};
2778
2779pp$3.parseTemplate = function(ref) {
2780 if ( ref === void 0 ) ref = {};
2781 var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
2782
2783 var node = this.startNode();
2784 this.next();
2785 node.expressions = [];
2786 var curElt = this.parseTemplateElement({isTagged: isTagged});
2787 node.quasis = [curElt];
2788 while (!curElt.tail) {
2789 if (this.type === types.eof) { this.raise(this.pos, "Unterminated template literal"); }
2790 this.expect(types.dollarBraceL);
2791 node.expressions.push(this.parseExpression());
2792 this.expect(types.braceR);
2793 node.quasis.push(curElt = this.parseTemplateElement({isTagged: isTagged}));
2794 }
2795 this.next();
2796 return this.finishNode(node, "TemplateLiteral")
2797};
2798
2799pp$3.isAsyncProp = function(prop) {
2800 return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
2801 (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types.star)) &&
2802 !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
2803};
2804
2805// Parse an object literal or binding pattern.
2806
2807pp$3.parseObj = function(isPattern, refDestructuringErrors) {
2808 var node = this.startNode(), first = true, propHash = {};
2809 node.properties = [];
2810 this.next();
2811 while (!this.eat(types.braceR)) {
2812 if (!first) {
2813 this.expect(types.comma);
2814 if (this.options.ecmaVersion >= 5 && this.afterTrailingComma(types.braceR)) { break }
2815 } else { first = false; }
2816
2817 var prop = this.parseProperty(isPattern, refDestructuringErrors);
2818 if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
2819 node.properties.push(prop);
2820 }
2821 return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
2822};
2823
2824pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
2825 var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
2826 if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
2827 if (isPattern) {
2828 prop.argument = this.parseIdent(false);
2829 if (this.type === types.comma) {
2830 this.raise(this.start, "Comma is not permitted after the rest element");
2831 }
2832 return this.finishNode(prop, "RestElement")
2833 }
2834 // To disallow parenthesized identifier via `this.toAssignable()`.
2835 if (this.type === types.parenL && refDestructuringErrors) {
2836 if (refDestructuringErrors.parenthesizedAssign < 0) {
2837 refDestructuringErrors.parenthesizedAssign = this.start;
2838 }
2839 if (refDestructuringErrors.parenthesizedBind < 0) {
2840 refDestructuringErrors.parenthesizedBind = this.start;
2841 }
2842 }
2843 // Parse argument.
2844 prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
2845 // To disallow trailing comma via `this.toAssignable()`.
2846 if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
2847 refDestructuringErrors.trailingComma = this.start;
2848 }
2849 // Finish
2850 return this.finishNode(prop, "SpreadElement")
2851 }
2852 if (this.options.ecmaVersion >= 6) {
2853 prop.method = false;
2854 prop.shorthand = false;
2855 if (isPattern || refDestructuringErrors) {
2856 startPos = this.start;
2857 startLoc = this.startLoc;
2858 }
2859 if (!isPattern)
2860 { isGenerator = this.eat(types.star); }
2861 }
2862 var containsEsc = this.containsEsc;
2863 this.parsePropertyName(prop);
2864 if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
2865 isAsync = true;
2866 isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
2867 this.parsePropertyName(prop, refDestructuringErrors);
2868 } else {
2869 isAsync = false;
2870 }
2871 this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
2872 return this.finishNode(prop, "Property")
2873};
2874
2875pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
2876 if ((isGenerator || isAsync) && this.type === types.colon)
2877 { this.unexpected(); }
2878
2879 if (this.eat(types.colon)) {
2880 prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
2881 prop.kind = "init";
2882 } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
2883 if (isPattern) { this.unexpected(); }
2884 prop.kind = "init";
2885 prop.method = true;
2886 prop.value = this.parseMethod(isGenerator, isAsync);
2887 } else if (!isPattern && !containsEsc &&
2888 this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
2889 (prop.key.name === "get" || prop.key.name === "set") &&
2890 (this.type !== types.comma && this.type !== types.braceR && this.type !== types.eq)) {
2891 if (isGenerator || isAsync) { this.unexpected(); }
2892 prop.kind = prop.key.name;
2893 this.parsePropertyName(prop);
2894 prop.value = this.parseMethod(false);
2895 var paramCount = prop.kind === "get" ? 0 : 1;
2896 if (prop.value.params.length !== paramCount) {
2897 var start = prop.value.start;
2898 if (prop.kind === "get")
2899 { this.raiseRecoverable(start, "getter should have no params"); }
2900 else
2901 { this.raiseRecoverable(start, "setter should have exactly one param"); }
2902 } else {
2903 if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
2904 { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
2905 }
2906 } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
2907 if (isGenerator || isAsync) { this.unexpected(); }
2908 this.checkUnreserved(prop.key);
2909 if (prop.key.name === "await" && !this.awaitIdentPos)
2910 { this.awaitIdentPos = startPos; }
2911 prop.kind = "init";
2912 if (isPattern) {
2913 prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
2914 } else if (this.type === types.eq && refDestructuringErrors) {
2915 if (refDestructuringErrors.shorthandAssign < 0)
2916 { refDestructuringErrors.shorthandAssign = this.start; }
2917 prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
2918 } else {
2919 prop.value = this.copyNode(prop.key);
2920 }
2921 prop.shorthand = true;
2922 } else { this.unexpected(); }
2923};
2924
2925pp$3.parsePropertyName = function(prop) {
2926 if (this.options.ecmaVersion >= 6) {
2927 if (this.eat(types.bracketL)) {
2928 prop.computed = true;
2929 prop.key = this.parseMaybeAssign();
2930 this.expect(types.bracketR);
2931 return prop.key
2932 } else {
2933 prop.computed = false;
2934 }
2935 }
2936 return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
2937};
2938
2939// Initialize empty function node.
2940
2941pp$3.initFunction = function(node) {
2942 node.id = null;
2943 if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
2944 if (this.options.ecmaVersion >= 8) { node.async = false; }
2945};
2946
2947// Parse object or class method.
2948
2949pp$3.parseMethod = function(isGenerator, isAsync, allowDirectSuper) {
2950 var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
2951
2952 this.initFunction(node);
2953 if (this.options.ecmaVersion >= 6)
2954 { node.generator = isGenerator; }
2955 if (this.options.ecmaVersion >= 8)
2956 { node.async = !!isAsync; }
2957
2958 this.yieldPos = 0;
2959 this.awaitPos = 0;
2960 this.awaitIdentPos = 0;
2961 this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
2962
2963 this.expect(types.parenL);
2964 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
2965 this.checkYieldAwaitInDefaultParams();
2966 this.parseFunctionBody(node, false, true);
2967
2968 this.yieldPos = oldYieldPos;
2969 this.awaitPos = oldAwaitPos;
2970 this.awaitIdentPos = oldAwaitIdentPos;
2971 return this.finishNode(node, "FunctionExpression")
2972};
2973
2974// Parse arrow function expression with given parameters.
2975
2976pp$3.parseArrowExpression = function(node, params, isAsync) {
2977 var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
2978
2979 this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
2980 this.initFunction(node);
2981 if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
2982
2983 this.yieldPos = 0;
2984 this.awaitPos = 0;
2985 this.awaitIdentPos = 0;
2986
2987 node.params = this.toAssignableList(params, true);
2988 this.parseFunctionBody(node, true, false);
2989
2990 this.yieldPos = oldYieldPos;
2991 this.awaitPos = oldAwaitPos;
2992 this.awaitIdentPos = oldAwaitIdentPos;
2993 return this.finishNode(node, "ArrowFunctionExpression")
2994};
2995
2996// Parse function body and check parameters.
2997
2998pp$3.parseFunctionBody = function(node, isArrowFunction, isMethod) {
2999 var isExpression = isArrowFunction && this.type !== types.braceL;
3000 var oldStrict = this.strict, useStrict = false;
3001
3002 if (isExpression) {
3003 node.body = this.parseMaybeAssign();
3004 node.expression = true;
3005 this.checkParams(node, false);
3006 } else {
3007 var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
3008 if (!oldStrict || nonSimple) {
3009 useStrict = this.strictDirective(this.end);
3010 // If this is a strict mode function, verify that argument names
3011 // are not repeated, and it does not try to bind the words `eval`
3012 // or `arguments`.
3013 if (useStrict && nonSimple)
3014 { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
3015 }
3016 // Start a new scope with regard to labels and the `inFunction`
3017 // flag (restore them to their old value afterwards).
3018 var oldLabels = this.labels;
3019 this.labels = [];
3020 if (useStrict) { this.strict = true; }
3021
3022 // Add the params to varDeclaredNames to ensure that an error is thrown
3023 // if a let/const declaration in the function clashes with one of the params.
3024 this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params));
3025 // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
3026 if (this.strict && node.id) { this.checkLValSimple(node.id, BIND_OUTSIDE); }
3027 node.body = this.parseBlock(false, undefined, useStrict && !oldStrict);
3028 node.expression = false;
3029 this.adaptDirectivePrologue(node.body.body);
3030 this.labels = oldLabels;
3031 }
3032 this.exitScope();
3033};
3034
3035pp$3.isSimpleParamList = function(params) {
3036 for (var i = 0, list = params; i < list.length; i += 1)
3037 {
3038 var param = list[i];
3039
3040 if (param.type !== "Identifier") { return false
3041 } }
3042 return true
3043};
3044
3045// Checks function params for various disallowed patterns such as using "eval"
3046// or "arguments" and duplicate parameters.
3047
3048pp$3.checkParams = function(node, allowDuplicates) {
3049 var nameHash = Object.create(null);
3050 for (var i = 0, list = node.params; i < list.length; i += 1)
3051 {
3052 var param = list[i];
3053
3054 this.checkLValInnerPattern(param, BIND_VAR, allowDuplicates ? null : nameHash);
3055 }
3056};
3057
3058// Parses a comma-separated list of expressions, and returns them as
3059// an array. `close` is the token type that ends the list, and
3060// `allowEmpty` can be turned on to allow subsequent commas with
3061// nothing in between them to be parsed as `null` (which is needed
3062// for array literals).
3063
3064pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
3065 var elts = [], first = true;
3066 while (!this.eat(close)) {
3067 if (!first) {
3068 this.expect(types.comma);
3069 if (allowTrailingComma && this.afterTrailingComma(close)) { break }
3070 } else { first = false; }
3071
3072 var elt = (void 0);
3073 if (allowEmpty && this.type === types.comma)
3074 { elt = null; }
3075 else if (this.type === types.ellipsis) {
3076 elt = this.parseSpread(refDestructuringErrors);
3077 if (refDestructuringErrors && this.type === types.comma && refDestructuringErrors.trailingComma < 0)
3078 { refDestructuringErrors.trailingComma = this.start; }
3079 } else {
3080 elt = this.parseMaybeAssign(false, refDestructuringErrors);
3081 }
3082 elts.push(elt);
3083 }
3084 return elts
3085};
3086
3087pp$3.checkUnreserved = function(ref) {
3088 var start = ref.start;
3089 var end = ref.end;
3090 var name = ref.name;
3091
3092 if (this.inGenerator && name === "yield")
3093 { this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); }
3094 if (this.inAsync && name === "await")
3095 { this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); }
3096 if (this.currentThisScope().inClassFieldInit && name === "arguments")
3097 { this.raiseRecoverable(start, "Cannot use 'arguments' in class field initializer"); }
3098 if (this.keywords.test(name))
3099 { this.raise(start, ("Unexpected keyword '" + name + "'")); }
3100 if (this.options.ecmaVersion < 6 &&
3101 this.input.slice(start, end).indexOf("\\") !== -1) { return }
3102 var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
3103 if (re.test(name)) {
3104 if (!this.inAsync && name === "await")
3105 { this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); }
3106 this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
3107 }
3108};
3109
3110// Parse the next token as an identifier. If `liberal` is true (used
3111// when parsing properties), it will also convert keywords into
3112// identifiers.
3113
3114pp$3.parseIdent = function(liberal, isBinding) {
3115 var node = this.startNode();
3116 if (this.type === types.name) {
3117 node.name = this.value;
3118 } else if (this.type.keyword) {
3119 node.name = this.type.keyword;
3120
3121 // To fix https://github.com/acornjs/acorn/issues/575
3122 // `class` and `function` keywords push new context into this.context.
3123 // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
3124 // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
3125 if ((node.name === "class" || node.name === "function") &&
3126 (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
3127 this.context.pop();
3128 }
3129 } else {
3130 this.unexpected();
3131 }
3132 this.next(!!liberal);
3133 this.finishNode(node, "Identifier");
3134 if (!liberal) {
3135 this.checkUnreserved(node);
3136 if (node.name === "await" && !this.awaitIdentPos)
3137 { this.awaitIdentPos = node.start; }
3138 }
3139 return node
3140};
3141
3142pp$3.parsePrivateIdent = function() {
3143 var node = this.startNode();
3144 if (this.type === types.privateId) {
3145 node.name = this.value;
3146 } else {
3147 this.unexpected();
3148 }
3149 this.next();
3150 this.finishNode(node, "PrivateIdentifier");
3151
3152 // For validating existence
3153 if (this.privateNameStack.length === 0) {
3154 this.raise(node.start, ("Private field '#" + (node.name) + "' must be declared in an enclosing class"));
3155 } else {
3156 this.privateNameStack[this.privateNameStack.length - 1].used.push(node);
3157 }
3158
3159 return node
3160};
3161
3162// Parses yield expression inside generator.
3163
3164pp$3.parseYield = function(noIn) {
3165 if (!this.yieldPos) { this.yieldPos = this.start; }
3166
3167 var node = this.startNode();
3168 this.next();
3169 if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) {
3170 node.delegate = false;
3171 node.argument = null;
3172 } else {
3173 node.delegate = this.eat(types.star);
3174 node.argument = this.parseMaybeAssign(noIn);
3175 }
3176 return this.finishNode(node, "YieldExpression")
3177};
3178
3179pp$3.parseAwait = function() {
3180 if (!this.awaitPos) { this.awaitPos = this.start; }
3181
3182 var node = this.startNode();
3183 this.next();
3184 node.argument = this.parseMaybeUnary(null, true);
3185 return this.finishNode(node, "AwaitExpression")
3186};
3187
3188var pp$4 = Parser.prototype;
3189
3190// This function is used to raise exceptions on parse errors. It
3191// takes an offset integer (into the current `input`) to indicate
3192// the location of the error, attaches the position to the end
3193// of the error message, and then raises a `SyntaxError` with that
3194// message.
3195
3196pp$4.raise = function(pos, message) {
3197 var loc = getLineInfo(this.input, pos);
3198 message += " (" + loc.line + ":" + loc.column + ")";
3199 var err = new SyntaxError(message);
3200 err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
3201 throw err
3202};
3203
3204pp$4.raiseRecoverable = pp$4.raise;
3205
3206pp$4.curPosition = function() {
3207 if (this.options.locations) {
3208 return new Position(this.curLine, this.pos - this.lineStart)
3209 }
3210};
3211
3212var pp$5 = Parser.prototype;
3213
3214var Scope = function Scope(flags) {
3215 this.flags = flags;
3216 // A list of var-declared names in the current lexical scope
3217 this.var = [];
3218 // A list of lexically-declared names in the current lexical scope
3219 this.lexical = [];
3220 // A list of lexically-declared FunctionDeclaration names in the current lexical scope
3221 this.functions = [];
3222 // A switch to disallow the identifier reference 'arguments'
3223 this.inClassFieldInit = false;
3224};
3225
3226// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
3227
3228pp$5.enterScope = function(flags) {
3229 this.scopeStack.push(new Scope(flags));
3230};
3231
3232pp$5.exitScope = function() {
3233 this.scopeStack.pop();
3234};
3235
3236// The spec says:
3237// > At the top level of a function, or script, function declarations are
3238// > treated like var declarations rather than like lexical declarations.
3239pp$5.treatFunctionsAsVarInScope = function(scope) {
3240 return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
3241};
3242
3243pp$5.declareName = function(name, bindingType, pos) {
3244 var redeclared = false;
3245 if (bindingType === BIND_LEXICAL) {
3246 var scope = this.currentScope();
3247 redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
3248 scope.lexical.push(name);
3249 if (this.inModule && (scope.flags & SCOPE_TOP))
3250 { delete this.undefinedExports[name]; }
3251 } else if (bindingType === BIND_SIMPLE_CATCH) {
3252 var scope$1 = this.currentScope();
3253 scope$1.lexical.push(name);
3254 } else if (bindingType === BIND_FUNCTION) {
3255 var scope$2 = this.currentScope();
3256 if (this.treatFunctionsAsVar)
3257 { redeclared = scope$2.lexical.indexOf(name) > -1; }
3258 else
3259 { redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
3260 scope$2.functions.push(name);
3261 } else {
3262 for (var i = this.scopeStack.length - 1; i >= 0; --i) {
3263 var scope$3 = this.scopeStack[i];
3264 if (scope$3.lexical.indexOf(name) > -1 && !((scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) ||
3265 !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
3266 redeclared = true;
3267 break
3268 }
3269 scope$3.var.push(name);
3270 if (this.inModule && (scope$3.flags & SCOPE_TOP))
3271 { delete this.undefinedExports[name]; }
3272 if (scope$3.flags & SCOPE_VAR) { break }
3273 }
3274 }
3275 if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); }
3276};
3277
3278pp$5.checkLocalExport = function(id) {
3279 // scope.functions must be empty as Module code is always strict.
3280 if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
3281 this.scopeStack[0].var.indexOf(id.name) === -1) {
3282 this.undefinedExports[id.name] = id;
3283 }
3284};
3285
3286pp$5.currentScope = function() {
3287 return this.scopeStack[this.scopeStack.length - 1]
3288};
3289
3290pp$5.currentVarScope = function() {
3291 for (var i = this.scopeStack.length - 1;; i--) {
3292 var scope = this.scopeStack[i];
3293 if (scope.flags & SCOPE_VAR) { return scope }
3294 }
3295};
3296
3297// Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
3298pp$5.currentThisScope = function() {
3299 for (var i = this.scopeStack.length - 1;; i--) {
3300 var scope = this.scopeStack[i];
3301 if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope }
3302 }
3303};
3304
3305var Node = function Node(parser, pos, loc) {
3306 this.type = "";
3307 this.start = pos;
3308 this.end = 0;
3309 if (parser.options.locations)
3310 { this.loc = new SourceLocation(parser, loc); }
3311 if (parser.options.directSourceFile)
3312 { this.sourceFile = parser.options.directSourceFile; }
3313 if (parser.options.ranges)
3314 { this.range = [pos, 0]; }
3315};
3316
3317// Start an AST node, attaching a start offset.
3318
3319var pp$6 = Parser.prototype;
3320
3321pp$6.startNode = function() {
3322 return new Node(this, this.start, this.startLoc)
3323};
3324
3325pp$6.startNodeAt = function(pos, loc) {
3326 return new Node(this, pos, loc)
3327};
3328
3329// Finish an AST node, adding `type` and `end` properties.
3330
3331function finishNodeAt(node, type, pos, loc) {
3332 node.type = type;
3333 node.end = pos;
3334 if (this.options.locations)
3335 { node.loc.end = loc; }
3336 if (this.options.ranges)
3337 { node.range[1] = pos; }
3338 return node
3339}
3340
3341pp$6.finishNode = function(node, type) {
3342 return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
3343};
3344
3345// Finish node at given position
3346
3347pp$6.finishNodeAt = function(node, type, pos, loc) {
3348 return finishNodeAt.call(this, node, type, pos, loc)
3349};
3350
3351pp$6.copyNode = function(node) {
3352 var newNode = new Node(this, node.start, this.startLoc);
3353 for (var prop in node) { newNode[prop] = node[prop]; }
3354 return newNode
3355};
3356
3357// The algorithm used to determine whether a regexp can appear at a
3358
3359var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
3360 this.token = token;
3361 this.isExpr = !!isExpr;
3362 this.preserveSpace = !!preserveSpace;
3363 this.override = override;
3364 this.generator = !!generator;
3365};
3366
3367var types$1 = {
3368 b_stat: new TokContext("{", false),
3369 b_expr: new TokContext("{", true),
3370 b_tmpl: new TokContext("${", false),
3371 p_stat: new TokContext("(", false),
3372 p_expr: new TokContext("(", true),
3373 q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
3374 f_stat: new TokContext("function", false),
3375 f_expr: new TokContext("function", true),
3376 f_expr_gen: new TokContext("function", true, false, null, true),
3377 f_gen: new TokContext("function", false, false, null, true)
3378};
3379
3380var pp$7 = Parser.prototype;
3381
3382pp$7.initialContext = function() {
3383 return [types$1.b_stat]
3384};
3385
3386pp$7.braceIsBlock = function(prevType) {
3387 var parent = this.curContext();
3388 if (parent === types$1.f_expr || parent === types$1.f_stat)
3389 { return true }
3390 if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
3391 { return !parent.isExpr }
3392
3393 // The check for `tt.name && exprAllowed` detects whether we are
3394 // after a `yield` or `of` construct. See the `updateContext` for
3395 // `tt.name`.
3396 if (prevType === types._return || prevType === types.name && this.exprAllowed)
3397 { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
3398 if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow)
3399 { return true }
3400 if (prevType === types.braceL)
3401 { return parent === types$1.b_stat }
3402 if (prevType === types._var || prevType === types._const || prevType === types.name)
3403 { return false }
3404 return !this.exprAllowed
3405};
3406
3407pp$7.inGeneratorContext = function() {
3408 for (var i = this.context.length - 1; i >= 1; i--) {
3409 var context = this.context[i];
3410 if (context.token === "function")
3411 { return context.generator }
3412 }
3413 return false
3414};
3415
3416pp$7.updateContext = function(prevType) {
3417 var update, type = this.type;
3418 if (type.keyword && prevType === types.dot)
3419 { this.exprAllowed = false; }
3420 else if (update = type.updateContext)
3421 { update.call(this, prevType); }
3422 else
3423 { this.exprAllowed = type.beforeExpr; }
3424};
3425
3426// Token-specific context update code
3427
3428types.parenR.updateContext = types.braceR.updateContext = function() {
3429 if (this.context.length === 1) {
3430 this.exprAllowed = true;
3431 return
3432 }
3433 var out = this.context.pop();
3434 if (out === types$1.b_stat && this.curContext().token === "function") {
3435 out = this.context.pop();
3436 }
3437 this.exprAllowed = !out.isExpr;
3438};
3439
3440types.braceL.updateContext = function(prevType) {
3441 this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
3442 this.exprAllowed = true;
3443};
3444
3445types.dollarBraceL.updateContext = function() {
3446 this.context.push(types$1.b_tmpl);
3447 this.exprAllowed = true;
3448};
3449
3450types.parenL.updateContext = function(prevType) {
3451 var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
3452 this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
3453 this.exprAllowed = true;
3454};
3455
3456types.incDec.updateContext = function() {
3457 // tokExprAllowed stays unchanged
3458};
3459
3460types._function.updateContext = types._class.updateContext = function(prevType) {
3461 if (prevType.beforeExpr && prevType !== types._else &&
3462 !(prevType === types.semi && this.curContext() !== types$1.p_stat) &&
3463 !(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
3464 !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
3465 { this.context.push(types$1.f_expr); }
3466 else
3467 { this.context.push(types$1.f_stat); }
3468 this.exprAllowed = false;
3469};
3470
3471types.backQuote.updateContext = function() {
3472 if (this.curContext() === types$1.q_tmpl)
3473 { this.context.pop(); }
3474 else
3475 { this.context.push(types$1.q_tmpl); }
3476 this.exprAllowed = false;
3477};
3478
3479types.star.updateContext = function(prevType) {
3480 if (prevType === types._function) {
3481 var index = this.context.length - 1;
3482 if (this.context[index] === types$1.f_expr)
3483 { this.context[index] = types$1.f_expr_gen; }
3484 else
3485 { this.context[index] = types$1.f_gen; }
3486 }
3487 this.exprAllowed = true;
3488};
3489
3490types.name.updateContext = function(prevType) {
3491 var allowed = false;
3492 if (this.options.ecmaVersion >= 6 && prevType !== types.dot) {
3493 if (this.value === "of" && !this.exprAllowed ||
3494 this.value === "yield" && this.inGeneratorContext())
3495 { allowed = true; }
3496 }
3497 this.exprAllowed = allowed;
3498};
3499
3500// This file contains Unicode properties extracted from the ECMAScript
3501// specification. The lists are extracted like so:
3502// $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText)
3503
3504// #table-binary-unicode-properties
3505var ecma9BinaryProperties = "ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS";
3506var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
3507var ecma11BinaryProperties = ecma10BinaryProperties;
3508var ecma12BinaryProperties = ecma11BinaryProperties + " EBase EComp EMod EPres ExtPict";
3509var unicodeBinaryProperties = {
3510 9: ecma9BinaryProperties,
3511 10: ecma10BinaryProperties,
3512 11: ecma11BinaryProperties,
3513 12: ecma12BinaryProperties
3514};
3515
3516// #table-unicode-general-category-values
3517var unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu";
3518
3519// #table-unicode-script-values
3520var ecma9ScriptValues = "Adlam Adlm Ahom Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb";
3521var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd";
3522var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
3523var ecma12ScriptValues = ecma11ScriptValues + " Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi";
3524var unicodeScriptValues = {
3525 9: ecma9ScriptValues,
3526 10: ecma10ScriptValues,
3527 11: ecma11ScriptValues,
3528 12: ecma12ScriptValues
3529};
3530
3531var data = {};
3532function buildUnicodeData(ecmaVersion) {
3533 var d = data[ecmaVersion] = {
3534 binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues),
3535 nonBinary: {
3536 General_Category: wordsRegexp(unicodeGeneralCategoryValues),
3537 Script: wordsRegexp(unicodeScriptValues[ecmaVersion])
3538 }
3539 };
3540 d.nonBinary.Script_Extensions = d.nonBinary.Script;
3541
3542 d.nonBinary.gc = d.nonBinary.General_Category;
3543 d.nonBinary.sc = d.nonBinary.Script;
3544 d.nonBinary.scx = d.nonBinary.Script_Extensions;
3545}
3546buildUnicodeData(9);
3547buildUnicodeData(10);
3548buildUnicodeData(11);
3549buildUnicodeData(12);
3550
3551var pp$8 = Parser.prototype;
3552
3553var RegExpValidationState = function RegExpValidationState(parser) {
3554 this.parser = parser;
3555 this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
3556 this.unicodeProperties = data[parser.options.ecmaVersion >= 12 ? 12 : parser.options.ecmaVersion];
3557 this.source = "";
3558 this.flags = "";
3559 this.start = 0;
3560 this.switchU = false;
3561 this.switchN = false;
3562 this.pos = 0;
3563 this.lastIntValue = 0;
3564 this.lastStringValue = "";
3565 this.lastAssertionIsQuantifiable = false;
3566 this.numCapturingParens = 0;
3567 this.maxBackReference = 0;
3568 this.groupNames = [];
3569 this.backReferenceNames = [];
3570};
3571
3572RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
3573 var unicode = flags.indexOf("u") !== -1;
3574 this.start = start | 0;
3575 this.source = pattern + "";
3576 this.flags = flags;
3577 this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
3578 this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
3579};
3580
3581RegExpValidationState.prototype.raise = function raise (message) {
3582 this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
3583};
3584
3585// If u flag is given, this returns the code point at the index (it combines a surrogate pair).
3586// Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
3587RegExpValidationState.prototype.at = function at (i, forceU) {
3588 if ( forceU === void 0 ) forceU = false;
3589
3590 var s = this.source;
3591 var l = s.length;
3592 if (i >= l) {
3593 return -1
3594 }
3595 var c = s.charCodeAt(i);
3596 if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
3597 return c
3598 }
3599 var next = s.charCodeAt(i + 1);
3600 return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c
3601};
3602
3603RegExpValidationState.prototype.nextIndex = function nextIndex (i, forceU) {
3604 if ( forceU === void 0 ) forceU = false;
3605
3606 var s = this.source;
3607 var l = s.length;
3608 if (i >= l) {
3609 return l
3610 }
3611 var c = s.charCodeAt(i), next;
3612 if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
3613 (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
3614 return i + 1
3615 }
3616 return i + 2
3617};
3618
3619RegExpValidationState.prototype.current = function current (forceU) {
3620 if ( forceU === void 0 ) forceU = false;
3621
3622 return this.at(this.pos, forceU)
3623};
3624
3625RegExpValidationState.prototype.lookahead = function lookahead (forceU) {
3626 if ( forceU === void 0 ) forceU = false;
3627
3628 return this.at(this.nextIndex(this.pos, forceU), forceU)
3629};
3630
3631RegExpValidationState.prototype.advance = function advance (forceU) {
3632 if ( forceU === void 0 ) forceU = false;
3633
3634 this.pos = this.nextIndex(this.pos, forceU);
3635};
3636
3637RegExpValidationState.prototype.eat = function eat (ch, forceU) {
3638 if ( forceU === void 0 ) forceU = false;
3639
3640 if (this.current(forceU) === ch) {
3641 this.advance(forceU);
3642 return true
3643 }
3644 return false
3645};
3646
3647function codePointToString(ch) {
3648 if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
3649 ch -= 0x10000;
3650 return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
3651}
3652
3653/**
3654 * Validate the flags part of a given RegExpLiteral.
3655 *
3656 * @param {RegExpValidationState} state The state to validate RegExp.
3657 * @returns {void}
3658 */
3659pp$8.validateRegExpFlags = function(state) {
3660 var validFlags = state.validFlags;
3661 var flags = state.flags;
3662
3663 for (var i = 0; i < flags.length; i++) {
3664 var flag = flags.charAt(i);
3665 if (validFlags.indexOf(flag) === -1) {
3666 this.raise(state.start, "Invalid regular expression flag");
3667 }
3668 if (flags.indexOf(flag, i + 1) > -1) {
3669 this.raise(state.start, "Duplicate regular expression flag");
3670 }
3671 }
3672};
3673
3674/**
3675 * Validate the pattern part of a given RegExpLiteral.
3676 *
3677 * @param {RegExpValidationState} state The state to validate RegExp.
3678 * @returns {void}
3679 */
3680pp$8.validateRegExpPattern = function(state) {
3681 this.regexp_pattern(state);
3682
3683 // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
3684 // parsing contains a |GroupName|, reparse with the goal symbol
3685 // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
3686 // exception if _P_ did not conform to the grammar, if any elements of _P_
3687 // were not matched by the parse, or if any Early Error conditions exist.
3688 if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
3689 state.switchN = true;
3690 this.regexp_pattern(state);
3691 }
3692};
3693
3694// https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
3695pp$8.regexp_pattern = function(state) {
3696 state.pos = 0;
3697 state.lastIntValue = 0;
3698 state.lastStringValue = "";
3699 state.lastAssertionIsQuantifiable = false;
3700 state.numCapturingParens = 0;
3701 state.maxBackReference = 0;
3702 state.groupNames.length = 0;
3703 state.backReferenceNames.length = 0;
3704
3705 this.regexp_disjunction(state);
3706
3707 if (state.pos !== state.source.length) {
3708 // Make the same messages as V8.
3709 if (state.eat(0x29 /* ) */)) {
3710 state.raise("Unmatched ')'");
3711 }
3712 if (state.eat(0x5D /* ] */) || state.eat(0x7D /* } */)) {
3713 state.raise("Lone quantifier brackets");
3714 }
3715 }
3716 if (state.maxBackReference > state.numCapturingParens) {
3717 state.raise("Invalid escape");
3718 }
3719 for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
3720 var name = list[i];
3721
3722 if (state.groupNames.indexOf(name) === -1) {
3723 state.raise("Invalid named capture referenced");
3724 }
3725 }
3726};
3727
3728// https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
3729pp$8.regexp_disjunction = function(state) {
3730 this.regexp_alternative(state);
3731 while (state.eat(0x7C /* | */)) {
3732 this.regexp_alternative(state);
3733 }
3734
3735 // Make the same message as V8.
3736 if (this.regexp_eatQuantifier(state, true)) {
3737 state.raise("Nothing to repeat");
3738 }
3739 if (state.eat(0x7B /* { */)) {
3740 state.raise("Lone quantifier brackets");
3741 }
3742};
3743
3744// https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
3745pp$8.regexp_alternative = function(state) {
3746 while (state.pos < state.source.length && this.regexp_eatTerm(state))
3747 { }
3748};
3749
3750// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
3751pp$8.regexp_eatTerm = function(state) {
3752 if (this.regexp_eatAssertion(state)) {
3753 // Handle `QuantifiableAssertion Quantifier` alternative.
3754 // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
3755 // is a QuantifiableAssertion.
3756 if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
3757 // Make the same message as V8.
3758 if (state.switchU) {
3759 state.raise("Invalid quantifier");
3760 }
3761 }
3762 return true
3763 }
3764
3765 if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
3766 this.regexp_eatQuantifier(state);
3767 return true
3768 }
3769
3770 return false
3771};
3772
3773// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
3774pp$8.regexp_eatAssertion = function(state) {
3775 var start = state.pos;
3776 state.lastAssertionIsQuantifiable = false;
3777
3778 // ^, $
3779 if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
3780 return true
3781 }
3782
3783 // \b \B
3784 if (state.eat(0x5C /* \ */)) {
3785 if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
3786 return true
3787 }
3788 state.pos = start;
3789 }
3790
3791 // Lookahead / Lookbehind
3792 if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
3793 var lookbehind = false;
3794 if (this.options.ecmaVersion >= 9) {
3795 lookbehind = state.eat(0x3C /* < */);
3796 }
3797 if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
3798 this.regexp_disjunction(state);
3799 if (!state.eat(0x29 /* ) */)) {
3800 state.raise("Unterminated group");
3801 }
3802 state.lastAssertionIsQuantifiable = !lookbehind;
3803 return true
3804 }
3805 }
3806
3807 state.pos = start;
3808 return false
3809};
3810
3811// https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
3812pp$8.regexp_eatQuantifier = function(state, noError) {
3813 if ( noError === void 0 ) noError = false;
3814
3815 if (this.regexp_eatQuantifierPrefix(state, noError)) {
3816 state.eat(0x3F /* ? */);
3817 return true
3818 }
3819 return false
3820};
3821
3822// https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
3823pp$8.regexp_eatQuantifierPrefix = function(state, noError) {
3824 return (
3825 state.eat(0x2A /* * */) ||
3826 state.eat(0x2B /* + */) ||
3827 state.eat(0x3F /* ? */) ||
3828 this.regexp_eatBracedQuantifier(state, noError)
3829 )
3830};
3831pp$8.regexp_eatBracedQuantifier = function(state, noError) {
3832 var start = state.pos;
3833 if (state.eat(0x7B /* { */)) {
3834 var min = 0, max = -1;
3835 if (this.regexp_eatDecimalDigits(state)) {
3836 min = state.lastIntValue;
3837 if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
3838 max = state.lastIntValue;
3839 }
3840 if (state.eat(0x7D /* } */)) {
3841 // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
3842 if (max !== -1 && max < min && !noError) {
3843 state.raise("numbers out of order in {} quantifier");
3844 }
3845 return true
3846 }
3847 }
3848 if (state.switchU && !noError) {
3849 state.raise("Incomplete quantifier");
3850 }
3851 state.pos = start;
3852 }
3853 return false
3854};
3855
3856// https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
3857pp$8.regexp_eatAtom = function(state) {
3858 return (
3859 this.regexp_eatPatternCharacters(state) ||
3860 state.eat(0x2E /* . */) ||
3861 this.regexp_eatReverseSolidusAtomEscape(state) ||
3862 this.regexp_eatCharacterClass(state) ||
3863 this.regexp_eatUncapturingGroup(state) ||
3864 this.regexp_eatCapturingGroup(state)
3865 )
3866};
3867pp$8.regexp_eatReverseSolidusAtomEscape = function(state) {
3868 var start = state.pos;
3869 if (state.eat(0x5C /* \ */)) {
3870 if (this.regexp_eatAtomEscape(state)) {
3871 return true
3872 }
3873 state.pos = start;
3874 }
3875 return false
3876};
3877pp$8.regexp_eatUncapturingGroup = function(state) {
3878 var start = state.pos;
3879 if (state.eat(0x28 /* ( */)) {
3880 if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
3881 this.regexp_disjunction(state);
3882 if (state.eat(0x29 /* ) */)) {
3883 return true
3884 }
3885 state.raise("Unterminated group");
3886 }
3887 state.pos = start;
3888 }
3889 return false
3890};
3891pp$8.regexp_eatCapturingGroup = function(state) {
3892 if (state.eat(0x28 /* ( */)) {
3893 if (this.options.ecmaVersion >= 9) {
3894 this.regexp_groupSpecifier(state);
3895 } else if (state.current() === 0x3F /* ? */) {
3896 state.raise("Invalid group");
3897 }
3898 this.regexp_disjunction(state);
3899 if (state.eat(0x29 /* ) */)) {
3900 state.numCapturingParens += 1;
3901 return true
3902 }
3903 state.raise("Unterminated group");
3904 }
3905 return false
3906};
3907
3908// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
3909pp$8.regexp_eatExtendedAtom = function(state) {
3910 return (
3911 state.eat(0x2E /* . */) ||
3912 this.regexp_eatReverseSolidusAtomEscape(state) ||
3913 this.regexp_eatCharacterClass(state) ||
3914 this.regexp_eatUncapturingGroup(state) ||
3915 this.regexp_eatCapturingGroup(state) ||
3916 this.regexp_eatInvalidBracedQuantifier(state) ||
3917 this.regexp_eatExtendedPatternCharacter(state)
3918 )
3919};
3920
3921// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
3922pp$8.regexp_eatInvalidBracedQuantifier = function(state) {
3923 if (this.regexp_eatBracedQuantifier(state, true)) {
3924 state.raise("Nothing to repeat");
3925 }
3926 return false
3927};
3928
3929// https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
3930pp$8.regexp_eatSyntaxCharacter = function(state) {
3931 var ch = state.current();
3932 if (isSyntaxCharacter(ch)) {
3933 state.lastIntValue = ch;
3934 state.advance();
3935 return true
3936 }
3937 return false
3938};
3939function isSyntaxCharacter(ch) {
3940 return (
3941 ch === 0x24 /* $ */ ||
3942 ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
3943 ch === 0x2E /* . */ ||
3944 ch === 0x3F /* ? */ ||
3945 ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
3946 ch >= 0x7B /* { */ && ch <= 0x7D /* } */
3947 )
3948}
3949
3950// https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
3951// But eat eager.
3952pp$8.regexp_eatPatternCharacters = function(state) {
3953 var start = state.pos;
3954 var ch = 0;
3955 while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
3956 state.advance();
3957 }
3958 return state.pos !== start
3959};
3960
3961// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
3962pp$8.regexp_eatExtendedPatternCharacter = function(state) {
3963 var ch = state.current();
3964 if (
3965 ch !== -1 &&
3966 ch !== 0x24 /* $ */ &&
3967 !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
3968 ch !== 0x2E /* . */ &&
3969 ch !== 0x3F /* ? */ &&
3970 ch !== 0x5B /* [ */ &&
3971 ch !== 0x5E /* ^ */ &&
3972 ch !== 0x7C /* | */
3973 ) {
3974 state.advance();
3975 return true
3976 }
3977 return false
3978};
3979
3980// GroupSpecifier ::
3981// [empty]
3982// `?` GroupName
3983pp$8.regexp_groupSpecifier = function(state) {
3984 if (state.eat(0x3F /* ? */)) {
3985 if (this.regexp_eatGroupName(state)) {
3986 if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
3987 state.raise("Duplicate capture group name");
3988 }
3989 state.groupNames.push(state.lastStringValue);
3990 return
3991 }
3992 state.raise("Invalid group");
3993 }
3994};
3995
3996// GroupName ::
3997// `<` RegExpIdentifierName `>`
3998// Note: this updates `state.lastStringValue` property with the eaten name.
3999pp$8.regexp_eatGroupName = function(state) {
4000 state.lastStringValue = "";
4001 if (state.eat(0x3C /* < */)) {
4002 if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
4003 return true
4004 }
4005 state.raise("Invalid capture group name");
4006 }
4007 return false
4008};
4009
4010// RegExpIdentifierName ::
4011// RegExpIdentifierStart
4012// RegExpIdentifierName RegExpIdentifierPart
4013// Note: this updates `state.lastStringValue` property with the eaten name.
4014pp$8.regexp_eatRegExpIdentifierName = function(state) {
4015 state.lastStringValue = "";
4016 if (this.regexp_eatRegExpIdentifierStart(state)) {
4017 state.lastStringValue += codePointToString(state.lastIntValue);
4018 while (this.regexp_eatRegExpIdentifierPart(state)) {
4019 state.lastStringValue += codePointToString(state.lastIntValue);
4020 }
4021 return true
4022 }
4023 return false
4024};
4025
4026// RegExpIdentifierStart ::
4027// UnicodeIDStart
4028// `$`
4029// `_`
4030// `\` RegExpUnicodeEscapeSequence[+U]
4031pp$8.regexp_eatRegExpIdentifierStart = function(state) {
4032 var start = state.pos;
4033 var forceU = this.options.ecmaVersion >= 11;
4034 var ch = state.current(forceU);
4035 state.advance(forceU);
4036
4037 if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
4038 ch = state.lastIntValue;
4039 }
4040 if (isRegExpIdentifierStart(ch)) {
4041 state.lastIntValue = ch;
4042 return true
4043 }
4044
4045 state.pos = start;
4046 return false
4047};
4048function isRegExpIdentifierStart(ch) {
4049 return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
4050}
4051
4052// RegExpIdentifierPart ::
4053// UnicodeIDContinue
4054// `$`
4055// `_`
4056// `\` RegExpUnicodeEscapeSequence[+U]
4057// <ZWNJ>
4058// <ZWJ>
4059pp$8.regexp_eatRegExpIdentifierPart = function(state) {
4060 var start = state.pos;
4061 var forceU = this.options.ecmaVersion >= 11;
4062 var ch = state.current(forceU);
4063 state.advance(forceU);
4064
4065 if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
4066 ch = state.lastIntValue;
4067 }
4068 if (isRegExpIdentifierPart(ch)) {
4069 state.lastIntValue = ch;
4070 return true
4071 }
4072
4073 state.pos = start;
4074 return false
4075};
4076function isRegExpIdentifierPart(ch) {
4077 return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
4078}
4079
4080// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
4081pp$8.regexp_eatAtomEscape = function(state) {
4082 if (
4083 this.regexp_eatBackReference(state) ||
4084 this.regexp_eatCharacterClassEscape(state) ||
4085 this.regexp_eatCharacterEscape(state) ||
4086 (state.switchN && this.regexp_eatKGroupName(state))
4087 ) {
4088 return true
4089 }
4090 if (state.switchU) {
4091 // Make the same message as V8.
4092 if (state.current() === 0x63 /* c */) {
4093 state.raise("Invalid unicode escape");
4094 }
4095 state.raise("Invalid escape");
4096 }
4097 return false
4098};
4099pp$8.regexp_eatBackReference = function(state) {
4100 var start = state.pos;
4101 if (this.regexp_eatDecimalEscape(state)) {
4102 var n = state.lastIntValue;
4103 if (state.switchU) {
4104 // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
4105 if (n > state.maxBackReference) {
4106 state.maxBackReference = n;
4107 }
4108 return true
4109 }
4110 if (n <= state.numCapturingParens) {
4111 return true
4112 }
4113 state.pos = start;
4114 }
4115 return false
4116};
4117pp$8.regexp_eatKGroupName = function(state) {
4118 if (state.eat(0x6B /* k */)) {
4119 if (this.regexp_eatGroupName(state)) {
4120 state.backReferenceNames.push(state.lastStringValue);
4121 return true
4122 }
4123 state.raise("Invalid named reference");
4124 }
4125 return false
4126};
4127
4128// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
4129pp$8.regexp_eatCharacterEscape = function(state) {
4130 return (
4131 this.regexp_eatControlEscape(state) ||
4132 this.regexp_eatCControlLetter(state) ||
4133 this.regexp_eatZero(state) ||
4134 this.regexp_eatHexEscapeSequence(state) ||
4135 this.regexp_eatRegExpUnicodeEscapeSequence(state, false) ||
4136 (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
4137 this.regexp_eatIdentityEscape(state)
4138 )
4139};
4140pp$8.regexp_eatCControlLetter = function(state) {
4141 var start = state.pos;
4142 if (state.eat(0x63 /* c */)) {
4143 if (this.regexp_eatControlLetter(state)) {
4144 return true
4145 }
4146 state.pos = start;
4147 }
4148 return false
4149};
4150pp$8.regexp_eatZero = function(state) {
4151 if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
4152 state.lastIntValue = 0;
4153 state.advance();
4154 return true
4155 }
4156 return false
4157};
4158
4159// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
4160pp$8.regexp_eatControlEscape = function(state) {
4161 var ch = state.current();
4162 if (ch === 0x74 /* t */) {
4163 state.lastIntValue = 0x09; /* \t */
4164 state.advance();
4165 return true
4166 }
4167 if (ch === 0x6E /* n */) {
4168 state.lastIntValue = 0x0A; /* \n */
4169 state.advance();
4170 return true
4171 }
4172 if (ch === 0x76 /* v */) {
4173 state.lastIntValue = 0x0B; /* \v */
4174 state.advance();
4175 return true
4176 }
4177 if (ch === 0x66 /* f */) {
4178 state.lastIntValue = 0x0C; /* \f */
4179 state.advance();
4180 return true
4181 }
4182 if (ch === 0x72 /* r */) {
4183 state.lastIntValue = 0x0D; /* \r */
4184 state.advance();
4185 return true
4186 }
4187 return false
4188};
4189
4190// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
4191pp$8.regexp_eatControlLetter = function(state) {
4192 var ch = state.current();
4193 if (isControlLetter(ch)) {
4194 state.lastIntValue = ch % 0x20;
4195 state.advance();
4196 return true
4197 }
4198 return false
4199};
4200function isControlLetter(ch) {
4201 return (
4202 (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
4203 (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
4204 )
4205}
4206
4207// https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
4208pp$8.regexp_eatRegExpUnicodeEscapeSequence = function(state, forceU) {
4209 if ( forceU === void 0 ) forceU = false;
4210
4211 var start = state.pos;
4212 var switchU = forceU || state.switchU;
4213
4214 if (state.eat(0x75 /* u */)) {
4215 if (this.regexp_eatFixedHexDigits(state, 4)) {
4216 var lead = state.lastIntValue;
4217 if (switchU && lead >= 0xD800 && lead <= 0xDBFF) {
4218 var leadSurrogateEnd = state.pos;
4219 if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
4220 var trail = state.lastIntValue;
4221 if (trail >= 0xDC00 && trail <= 0xDFFF) {
4222 state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
4223 return true
4224 }
4225 }
4226 state.pos = leadSurrogateEnd;
4227 state.lastIntValue = lead;
4228 }
4229 return true
4230 }
4231 if (
4232 switchU &&
4233 state.eat(0x7B /* { */) &&
4234 this.regexp_eatHexDigits(state) &&
4235 state.eat(0x7D /* } */) &&
4236 isValidUnicode(state.lastIntValue)
4237 ) {
4238 return true
4239 }
4240 if (switchU) {
4241 state.raise("Invalid unicode escape");
4242 }
4243 state.pos = start;
4244 }
4245
4246 return false
4247};
4248function isValidUnicode(ch) {
4249 return ch >= 0 && ch <= 0x10FFFF
4250}
4251
4252// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
4253pp$8.regexp_eatIdentityEscape = function(state) {
4254 if (state.switchU) {
4255 if (this.regexp_eatSyntaxCharacter(state)) {
4256 return true
4257 }
4258 if (state.eat(0x2F /* / */)) {
4259 state.lastIntValue = 0x2F; /* / */
4260 return true
4261 }
4262 return false
4263 }
4264
4265 var ch = state.current();
4266 if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
4267 state.lastIntValue = ch;
4268 state.advance();
4269 return true
4270 }
4271
4272 return false
4273};
4274
4275// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
4276pp$8.regexp_eatDecimalEscape = function(state) {
4277 state.lastIntValue = 0;
4278 var ch = state.current();
4279 if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
4280 do {
4281 state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
4282 state.advance();
4283 } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
4284 return true
4285 }
4286 return false
4287};
4288
4289// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
4290pp$8.regexp_eatCharacterClassEscape = function(state) {
4291 var ch = state.current();
4292
4293 if (isCharacterClassEscape(ch)) {
4294 state.lastIntValue = -1;
4295 state.advance();
4296 return true
4297 }
4298
4299 if (
4300 state.switchU &&
4301 this.options.ecmaVersion >= 9 &&
4302 (ch === 0x50 /* P */ || ch === 0x70 /* p */)
4303 ) {
4304 state.lastIntValue = -1;
4305 state.advance();
4306 if (
4307 state.eat(0x7B /* { */) &&
4308 this.regexp_eatUnicodePropertyValueExpression(state) &&
4309 state.eat(0x7D /* } */)
4310 ) {
4311 return true
4312 }
4313 state.raise("Invalid property name");
4314 }
4315
4316 return false
4317};
4318function isCharacterClassEscape(ch) {
4319 return (
4320 ch === 0x64 /* d */ ||
4321 ch === 0x44 /* D */ ||
4322 ch === 0x73 /* s */ ||
4323 ch === 0x53 /* S */ ||
4324 ch === 0x77 /* w */ ||
4325 ch === 0x57 /* W */
4326 )
4327}
4328
4329// UnicodePropertyValueExpression ::
4330// UnicodePropertyName `=` UnicodePropertyValue
4331// LoneUnicodePropertyNameOrValue
4332pp$8.regexp_eatUnicodePropertyValueExpression = function(state) {
4333 var start = state.pos;
4334
4335 // UnicodePropertyName `=` UnicodePropertyValue
4336 if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
4337 var name = state.lastStringValue;
4338 if (this.regexp_eatUnicodePropertyValue(state)) {
4339 var value = state.lastStringValue;
4340 this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
4341 return true
4342 }
4343 }
4344 state.pos = start;
4345
4346 // LoneUnicodePropertyNameOrValue
4347 if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
4348 var nameOrValue = state.lastStringValue;
4349 this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
4350 return true
4351 }
4352 return false
4353};
4354pp$8.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
4355 if (!has(state.unicodeProperties.nonBinary, name))
4356 { state.raise("Invalid property name"); }
4357 if (!state.unicodeProperties.nonBinary[name].test(value))
4358 { state.raise("Invalid property value"); }
4359};
4360pp$8.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
4361 if (!state.unicodeProperties.binary.test(nameOrValue))
4362 { state.raise("Invalid property name"); }
4363};
4364
4365// UnicodePropertyName ::
4366// UnicodePropertyNameCharacters
4367pp$8.regexp_eatUnicodePropertyName = function(state) {
4368 var ch = 0;
4369 state.lastStringValue = "";
4370 while (isUnicodePropertyNameCharacter(ch = state.current())) {
4371 state.lastStringValue += codePointToString(ch);
4372 state.advance();
4373 }
4374 return state.lastStringValue !== ""
4375};
4376function isUnicodePropertyNameCharacter(ch) {
4377 return isControlLetter(ch) || ch === 0x5F /* _ */
4378}
4379
4380// UnicodePropertyValue ::
4381// UnicodePropertyValueCharacters
4382pp$8.regexp_eatUnicodePropertyValue = function(state) {
4383 var ch = 0;
4384 state.lastStringValue = "";
4385 while (isUnicodePropertyValueCharacter(ch = state.current())) {
4386 state.lastStringValue += codePointToString(ch);
4387 state.advance();
4388 }
4389 return state.lastStringValue !== ""
4390};
4391function isUnicodePropertyValueCharacter(ch) {
4392 return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
4393}
4394
4395// LoneUnicodePropertyNameOrValue ::
4396// UnicodePropertyValueCharacters
4397pp$8.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
4398 return this.regexp_eatUnicodePropertyValue(state)
4399};
4400
4401// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
4402pp$8.regexp_eatCharacterClass = function(state) {
4403 if (state.eat(0x5B /* [ */)) {
4404 state.eat(0x5E /* ^ */);
4405 this.regexp_classRanges(state);
4406 if (state.eat(0x5D /* ] */)) {
4407 return true
4408 }
4409 // Unreachable since it threw "unterminated regular expression" error before.
4410 state.raise("Unterminated character class");
4411 }
4412 return false
4413};
4414
4415// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
4416// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
4417// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
4418pp$8.regexp_classRanges = function(state) {
4419 while (this.regexp_eatClassAtom(state)) {
4420 var left = state.lastIntValue;
4421 if (state.eat(0x2D /* - */) && this.regexp_eatClassAtom(state)) {
4422 var right = state.lastIntValue;
4423 if (state.switchU && (left === -1 || right === -1)) {
4424 state.raise("Invalid character class");
4425 }
4426 if (left !== -1 && right !== -1 && left > right) {
4427 state.raise("Range out of order in character class");
4428 }
4429 }
4430 }
4431};
4432
4433// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
4434// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
4435pp$8.regexp_eatClassAtom = function(state) {
4436 var start = state.pos;
4437
4438 if (state.eat(0x5C /* \ */)) {
4439 if (this.regexp_eatClassEscape(state)) {
4440 return true
4441 }
4442 if (state.switchU) {
4443 // Make the same message as V8.
4444 var ch$1 = state.current();
4445 if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
4446 state.raise("Invalid class escape");
4447 }
4448 state.raise("Invalid escape");
4449 }
4450 state.pos = start;
4451 }
4452
4453 var ch = state.current();
4454 if (ch !== 0x5D /* ] */) {
4455 state.lastIntValue = ch;
4456 state.advance();
4457 return true
4458 }
4459
4460 return false
4461};
4462
4463// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
4464pp$8.regexp_eatClassEscape = function(state) {
4465 var start = state.pos;
4466
4467 if (state.eat(0x62 /* b */)) {
4468 state.lastIntValue = 0x08; /* <BS> */
4469 return true
4470 }
4471
4472 if (state.switchU && state.eat(0x2D /* - */)) {
4473 state.lastIntValue = 0x2D; /* - */
4474 return true
4475 }
4476
4477 if (!state.switchU && state.eat(0x63 /* c */)) {
4478 if (this.regexp_eatClassControlLetter(state)) {
4479 return true
4480 }
4481 state.pos = start;
4482 }
4483
4484 return (
4485 this.regexp_eatCharacterClassEscape(state) ||
4486 this.regexp_eatCharacterEscape(state)
4487 )
4488};
4489
4490// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
4491pp$8.regexp_eatClassControlLetter = function(state) {
4492 var ch = state.current();
4493 if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
4494 state.lastIntValue = ch % 0x20;
4495 state.advance();
4496 return true
4497 }
4498 return false
4499};
4500
4501// https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
4502pp$8.regexp_eatHexEscapeSequence = function(state) {
4503 var start = state.pos;
4504 if (state.eat(0x78 /* x */)) {
4505 if (this.regexp_eatFixedHexDigits(state, 2)) {
4506 return true
4507 }
4508 if (state.switchU) {
4509 state.raise("Invalid escape");
4510 }
4511 state.pos = start;
4512 }
4513 return false
4514};
4515
4516// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
4517pp$8.regexp_eatDecimalDigits = function(state) {
4518 var start = state.pos;
4519 var ch = 0;
4520 state.lastIntValue = 0;
4521 while (isDecimalDigit(ch = state.current())) {
4522 state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
4523 state.advance();
4524 }
4525 return state.pos !== start
4526};
4527function isDecimalDigit(ch) {
4528 return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
4529}
4530
4531// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
4532pp$8.regexp_eatHexDigits = function(state) {
4533 var start = state.pos;
4534 var ch = 0;
4535 state.lastIntValue = 0;
4536 while (isHexDigit(ch = state.current())) {
4537 state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
4538 state.advance();
4539 }
4540 return state.pos !== start
4541};
4542function isHexDigit(ch) {
4543 return (
4544 (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
4545 (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
4546 (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
4547 )
4548}
4549function hexToInt(ch) {
4550 if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
4551 return 10 + (ch - 0x41 /* A */)
4552 }
4553 if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
4554 return 10 + (ch - 0x61 /* a */)
4555 }
4556 return ch - 0x30 /* 0 */
4557}
4558
4559// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
4560// Allows only 0-377(octal) i.e. 0-255(decimal).
4561pp$8.regexp_eatLegacyOctalEscapeSequence = function(state) {
4562 if (this.regexp_eatOctalDigit(state)) {
4563 var n1 = state.lastIntValue;
4564 if (this.regexp_eatOctalDigit(state)) {
4565 var n2 = state.lastIntValue;
4566 if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
4567 state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
4568 } else {
4569 state.lastIntValue = n1 * 8 + n2;
4570 }
4571 } else {
4572 state.lastIntValue = n1;
4573 }
4574 return true
4575 }
4576 return false
4577};
4578
4579// https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
4580pp$8.regexp_eatOctalDigit = function(state) {
4581 var ch = state.current();
4582 if (isOctalDigit(ch)) {
4583 state.lastIntValue = ch - 0x30; /* 0 */
4584 state.advance();
4585 return true
4586 }
4587 state.lastIntValue = 0;
4588 return false
4589};
4590function isOctalDigit(ch) {
4591 return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
4592}
4593
4594// https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
4595// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
4596// And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
4597pp$8.regexp_eatFixedHexDigits = function(state, length) {
4598 var start = state.pos;
4599 state.lastIntValue = 0;
4600 for (var i = 0; i < length; ++i) {
4601 var ch = state.current();
4602 if (!isHexDigit(ch)) {
4603 state.pos = start;
4604 return false
4605 }
4606 state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
4607 state.advance();
4608 }
4609 return true
4610};
4611
4612// Object type used to represent tokens. Note that normally, tokens
4613// simply exist as properties on the parser object. This is only
4614// used for the onToken callback and the external tokenizer.
4615
4616var Token = function Token(p) {
4617 this.type = p.type;
4618 this.value = p.value;
4619 this.start = p.start;
4620 this.end = p.end;
4621 if (p.options.locations)
4622 { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
4623 if (p.options.ranges)
4624 { this.range = [p.start, p.end]; }
4625};
4626
4627// ## Tokenizer
4628
4629var pp$9 = Parser.prototype;
4630
4631// Move to the next token
4632
4633pp$9.next = function(ignoreEscapeSequenceInKeyword) {
4634 if (!ignoreEscapeSequenceInKeyword && this.type.keyword && this.containsEsc)
4635 { this.raiseRecoverable(this.start, "Escape sequence in keyword " + this.type.keyword); }
4636 if (this.options.onToken)
4637 { this.options.onToken(new Token(this)); }
4638
4639 this.lastTokEnd = this.end;
4640 this.lastTokStart = this.start;
4641 this.lastTokEndLoc = this.endLoc;
4642 this.lastTokStartLoc = this.startLoc;
4643 this.nextToken();
4644};
4645
4646pp$9.getToken = function() {
4647 this.next();
4648 return new Token(this)
4649};
4650
4651// If we're in an ES6 environment, make parsers iterable
4652if (typeof Symbol !== "undefined")
4653 { pp$9[Symbol.iterator] = function() {
4654 var this$1 = this;
4655
4656 return {
4657 next: function () {
4658 var token = this$1.getToken();
4659 return {
4660 done: token.type === types.eof,
4661 value: token
4662 }
4663 }
4664 }
4665 }; }
4666
4667// Toggle strict mode. Re-reads the next number or string to please
4668// pedantic tests (`"use strict"; 010;` should fail).
4669
4670pp$9.curContext = function() {
4671 return this.context[this.context.length - 1]
4672};
4673
4674// Read a single token, updating the parser object's token-related
4675// properties.
4676
4677pp$9.nextToken = function() {
4678 var curContext = this.curContext();
4679 if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
4680
4681 this.start = this.pos;
4682 if (this.options.locations) { this.startLoc = this.curPosition(); }
4683 if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
4684
4685 if (curContext.override) { return curContext.override(this) }
4686 else { this.readToken(this.fullCharCodeAtPos()); }
4687};
4688
4689pp$9.readToken = function(code) {
4690 // Identifier or keyword. '\uXXXX' sequences are allowed in
4691 // identifiers, so '\' also dispatches to that.
4692 if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
4693 { return this.readWord() }
4694
4695 return this.getTokenFromCode(code)
4696};
4697
4698pp$9.fullCharCodeAtPos = function() {
4699 var code = this.input.charCodeAt(this.pos);
4700 if (code <= 0xd7ff || code >= 0xe000) { return code }
4701 var next = this.input.charCodeAt(this.pos + 1);
4702 return (code << 10) + next - 0x35fdc00
4703};
4704
4705pp$9.skipBlockComment = function() {
4706 var startLoc = this.options.onComment && this.curPosition();
4707 var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
4708 if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
4709 this.pos = end + 2;
4710 if (this.options.locations) {
4711 lineBreakG.lastIndex = start;
4712 var match;
4713 while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
4714 ++this.curLine;
4715 this.lineStart = match.index + match[0].length;
4716 }
4717 }
4718 if (this.options.onComment)
4719 { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
4720 startLoc, this.curPosition()); }
4721};
4722
4723pp$9.skipLineComment = function(startSkip) {
4724 var start = this.pos;
4725 var startLoc = this.options.onComment && this.curPosition();
4726 var ch = this.input.charCodeAt(this.pos += startSkip);
4727 while (this.pos < this.input.length && !isNewLine(ch)) {
4728 ch = this.input.charCodeAt(++this.pos);
4729 }
4730 if (this.options.onComment)
4731 { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
4732 startLoc, this.curPosition()); }
4733};
4734
4735// Called at the start of the parse and after every token. Skips
4736// whitespace and comments, and.
4737
4738pp$9.skipSpace = function() {
4739 loop: while (this.pos < this.input.length) {
4740 var ch = this.input.charCodeAt(this.pos);
4741 switch (ch) {
4742 case 32: case 160: // ' '
4743 ++this.pos;
4744 break
4745 case 13:
4746 if (this.input.charCodeAt(this.pos + 1) === 10) {
4747 ++this.pos;
4748 }
4749 case 10: case 8232: case 8233:
4750 ++this.pos;
4751 if (this.options.locations) {
4752 ++this.curLine;
4753 this.lineStart = this.pos;
4754 }
4755 break
4756 case 47: // '/'
4757 switch (this.input.charCodeAt(this.pos + 1)) {
4758 case 42: // '*'
4759 this.skipBlockComment();
4760 break
4761 case 47:
4762 this.skipLineComment(2);
4763 break
4764 default:
4765 break loop
4766 }
4767 break
4768 default:
4769 if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
4770 ++this.pos;
4771 } else {
4772 break loop
4773 }
4774 }
4775 }
4776};
4777
4778// Called at the end of every token. Sets `end`, `val`, and
4779// maintains `context` and `exprAllowed`, and skips the space after
4780// the token, so that the next one's `start` will point at the
4781// right position.
4782
4783pp$9.finishToken = function(type, val) {
4784 this.end = this.pos;
4785 if (this.options.locations) { this.endLoc = this.curPosition(); }
4786 var prevType = this.type;
4787 this.type = type;
4788 this.value = val;
4789
4790 this.updateContext(prevType);
4791};
4792
4793// ### Token reading
4794
4795// This is the function that is called to fetch the next token. It
4796// is somewhat obscure, because it works in character codes rather
4797// than characters, and because operator parsing has been inlined
4798// into it.
4799//
4800// All in the name of speed.
4801//
4802pp$9.readToken_dot = function() {
4803 var next = this.input.charCodeAt(this.pos + 1);
4804 if (next >= 48 && next <= 57) { return this.readNumber(true) }
4805 var next2 = this.input.charCodeAt(this.pos + 2);
4806 if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
4807 this.pos += 3;
4808 return this.finishToken(types.ellipsis)
4809 } else {
4810 ++this.pos;
4811 return this.finishToken(types.dot)
4812 }
4813};
4814
4815pp$9.readToken_slash = function() { // '/'
4816 var next = this.input.charCodeAt(this.pos + 1);
4817 if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
4818 if (next === 61) { return this.finishOp(types.assign, 2) }
4819 return this.finishOp(types.slash, 1)
4820};
4821
4822pp$9.readToken_mult_modulo_exp = function(code) { // '%*'
4823 var next = this.input.charCodeAt(this.pos + 1);
4824 var size = 1;
4825 var tokentype = code === 42 ? types.star : types.modulo;
4826
4827 // exponentiation operator ** and **=
4828 if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
4829 ++size;
4830 tokentype = types.starstar;
4831 next = this.input.charCodeAt(this.pos + 2);
4832 }
4833
4834 if (next === 61) { return this.finishOp(types.assign, size + 1) }
4835 return this.finishOp(tokentype, size)
4836};
4837
4838pp$9.readToken_pipe_amp = function(code) { // '|&'
4839 var next = this.input.charCodeAt(this.pos + 1);
4840 if (next === code) {
4841 if (this.options.ecmaVersion >= 12) {
4842 var next2 = this.input.charCodeAt(this.pos + 2);
4843 if (next2 === 61) { return this.finishOp(types.assign, 3) }
4844 }
4845 return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2)
4846 }
4847 if (next === 61) { return this.finishOp(types.assign, 2) }
4848 return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
4849};
4850
4851pp$9.readToken_caret = function() { // '^'
4852 var next = this.input.charCodeAt(this.pos + 1);
4853 if (next === 61) { return this.finishOp(types.assign, 2) }
4854 return this.finishOp(types.bitwiseXOR, 1)
4855};
4856
4857pp$9.readToken_plus_min = function(code) { // '+-'
4858 var next = this.input.charCodeAt(this.pos + 1);
4859 if (next === code) {
4860 if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
4861 (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
4862 // A `-->` line comment
4863 this.skipLineComment(3);
4864 this.skipSpace();
4865 return this.nextToken()
4866 }
4867 return this.finishOp(types.incDec, 2)
4868 }
4869 if (next === 61) { return this.finishOp(types.assign, 2) }
4870 return this.finishOp(types.plusMin, 1)
4871};
4872
4873pp$9.readToken_lt_gt = function(code) { // '<>'
4874 var next = this.input.charCodeAt(this.pos + 1);
4875 var size = 1;
4876 if (next === code) {
4877 size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
4878 if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
4879 return this.finishOp(types.bitShift, size)
4880 }
4881 if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
4882 this.input.charCodeAt(this.pos + 3) === 45) {
4883 // `<!--`, an XML-style comment that should be interpreted as a line comment
4884 this.skipLineComment(4);
4885 this.skipSpace();
4886 return this.nextToken()
4887 }
4888 if (next === 61) { size = 2; }
4889 return this.finishOp(types.relational, size)
4890};
4891
4892pp$9.readToken_eq_excl = function(code) { // '=!'
4893 var next = this.input.charCodeAt(this.pos + 1);
4894 if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
4895 if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
4896 this.pos += 2;
4897 return this.finishToken(types.arrow)
4898 }
4899 return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
4900};
4901
4902pp$9.readToken_question = function() { // '?'
4903 var ecmaVersion = this.options.ecmaVersion;
4904 if (ecmaVersion >= 11) {
4905 var next = this.input.charCodeAt(this.pos + 1);
4906 if (next === 46) {
4907 var next2 = this.input.charCodeAt(this.pos + 2);
4908 if (next2 < 48 || next2 > 57) { return this.finishOp(types.questionDot, 2) }
4909 }
4910 if (next === 63) {
4911 if (ecmaVersion >= 12) {
4912 var next2$1 = this.input.charCodeAt(this.pos + 2);
4913 if (next2$1 === 61) { return this.finishOp(types.assign, 3) }
4914 }
4915 return this.finishOp(types.coalesce, 2)
4916 }
4917 }
4918 return this.finishOp(types.question, 1)
4919};
4920
4921pp$9.readToken_numberSign = function() { // '#'
4922 var ecmaVersion = this.options.ecmaVersion;
4923 var code = 35; // '#'
4924 if (ecmaVersion >= 13) {
4925 ++this.pos;
4926 code = this.fullCharCodeAtPos();
4927 if (isIdentifierStart(code, true) || code === 92 /* '\' */) {
4928 return this.finishToken(types.privateId, this.readWord1())
4929 }
4930 }
4931
4932 this.raise(this.pos, "Unexpected character '" + codePointToString$1(code) + "'");
4933};
4934
4935pp$9.getTokenFromCode = function(code) {
4936 switch (code) {
4937 // The interpretation of a dot depends on whether it is followed
4938 // by a digit or another two dots.
4939 case 46: // '.'
4940 return this.readToken_dot()
4941
4942 // Punctuation tokens.
4943 case 40: ++this.pos; return this.finishToken(types.parenL)
4944 case 41: ++this.pos; return this.finishToken(types.parenR)
4945 case 59: ++this.pos; return this.finishToken(types.semi)
4946 case 44: ++this.pos; return this.finishToken(types.comma)
4947 case 91: ++this.pos; return this.finishToken(types.bracketL)
4948 case 93: ++this.pos; return this.finishToken(types.bracketR)
4949 case 123: ++this.pos; return this.finishToken(types.braceL)
4950 case 125: ++this.pos; return this.finishToken(types.braceR)
4951 case 58: ++this.pos; return this.finishToken(types.colon)
4952
4953 case 96: // '`'
4954 if (this.options.ecmaVersion < 6) { break }
4955 ++this.pos;
4956 return this.finishToken(types.backQuote)
4957
4958 case 48: // '0'
4959 var next = this.input.charCodeAt(this.pos + 1);
4960 if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
4961 if (this.options.ecmaVersion >= 6) {
4962 if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
4963 if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
4964 }
4965
4966 // Anything else beginning with a digit is an integer, octal
4967 // number, or float.
4968 case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
4969 return this.readNumber(false)
4970
4971 // Quotes produce strings.
4972 case 34: case 39: // '"', "'"
4973 return this.readString(code)
4974
4975 // Operators are parsed inline in tiny state machines. '=' (61) is
4976 // often referred to. `finishOp` simply skips the amount of
4977 // characters it is given as second argument, and returns a token
4978 // of the type given by its first argument.
4979
4980 case 47: // '/'
4981 return this.readToken_slash()
4982
4983 case 37: case 42: // '%*'
4984 return this.readToken_mult_modulo_exp(code)
4985
4986 case 124: case 38: // '|&'
4987 return this.readToken_pipe_amp(code)
4988
4989 case 94: // '^'
4990 return this.readToken_caret()
4991
4992 case 43: case 45: // '+-'
4993 return this.readToken_plus_min(code)
4994
4995 case 60: case 62: // '<>'
4996 return this.readToken_lt_gt(code)
4997
4998 case 61: case 33: // '=!'
4999 return this.readToken_eq_excl(code)
5000
5001 case 63: // '?'
5002 return this.readToken_question()
5003
5004 case 126: // '~'
5005 return this.finishOp(types.prefix, 1)
5006
5007 case 35: // '#'
5008 return this.readToken_numberSign()
5009 }
5010
5011 this.raise(this.pos, "Unexpected character '" + codePointToString$1(code) + "'");
5012};
5013
5014pp$9.finishOp = function(type, size) {
5015 var str = this.input.slice(this.pos, this.pos + size);
5016 this.pos += size;
5017 return this.finishToken(type, str)
5018};
5019
5020pp$9.readRegexp = function() {
5021 var escaped, inClass, start = this.pos;
5022 for (;;) {
5023 if (this.pos >= this.input.length) { this.raise(start, "Unterminated regular expression"); }
5024 var ch = this.input.charAt(this.pos);
5025 if (lineBreak.test(ch)) { this.raise(start, "Unterminated regular expression"); }
5026 if (!escaped) {
5027 if (ch === "[") { inClass = true; }
5028 else if (ch === "]" && inClass) { inClass = false; }
5029 else if (ch === "/" && !inClass) { break }
5030 escaped = ch === "\\";
5031 } else { escaped = false; }
5032 ++this.pos;
5033 }
5034 var pattern = this.input.slice(start, this.pos);
5035 ++this.pos;
5036 var flagsStart = this.pos;
5037 var flags = this.readWord1();
5038 if (this.containsEsc) { this.unexpected(flagsStart); }
5039
5040 // Validate pattern
5041 var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
5042 state.reset(start, pattern, flags);
5043 this.validateRegExpFlags(state);
5044 this.validateRegExpPattern(state);
5045
5046 // Create Literal#value property value.
5047 var value = null;
5048 try {
5049 value = new RegExp(pattern, flags);
5050 } catch (e) {
5051 // ESTree requires null if it failed to instantiate RegExp object.
5052 // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
5053 }
5054
5055 return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
5056};
5057
5058// Read an integer in the given radix. Return null if zero digits
5059// were read, the integer value otherwise. When `len` is given, this
5060// will return `null` unless the integer has exactly `len` digits.
5061
5062pp$9.readInt = function(radix, len, maybeLegacyOctalNumericLiteral) {
5063 // `len` is used for character escape sequences. In that case, disallow separators.
5064 var allowSeparators = this.options.ecmaVersion >= 12 && len === undefined;
5065
5066 // `maybeLegacyOctalNumericLiteral` is true if it doesn't have prefix (0x,0o,0b)
5067 // and isn't fraction part nor exponent part. In that case, if the first digit
5068 // is zero then disallow separators.
5069 var isLegacyOctalNumericLiteral = maybeLegacyOctalNumericLiteral && this.input.charCodeAt(this.pos) === 48;
5070
5071 var start = this.pos, total = 0, lastCode = 0;
5072 for (var i = 0, e = len == null ? Infinity : len; i < e; ++i, ++this.pos) {
5073 var code = this.input.charCodeAt(this.pos), val = (void 0);
5074
5075 if (allowSeparators && code === 95) {
5076 if (isLegacyOctalNumericLiteral) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed in legacy octal numeric literals"); }
5077 if (lastCode === 95) { this.raiseRecoverable(this.pos, "Numeric separator must be exactly one underscore"); }
5078 if (i === 0) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed at the first of digits"); }
5079 lastCode = code;
5080 continue
5081 }
5082
5083 if (code >= 97) { val = code - 97 + 10; } // a
5084 else if (code >= 65) { val = code - 65 + 10; } // A
5085 else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
5086 else { val = Infinity; }
5087 if (val >= radix) { break }
5088 lastCode = code;
5089 total = total * radix + val;
5090 }
5091
5092 if (allowSeparators && lastCode === 95) { this.raiseRecoverable(this.pos - 1, "Numeric separator is not allowed at the last of digits"); }
5093 if (this.pos === start || len != null && this.pos - start !== len) { return null }
5094
5095 return total
5096};
5097
5098function stringToNumber(str, isLegacyOctalNumericLiteral) {
5099 if (isLegacyOctalNumericLiteral) {
5100 return parseInt(str, 8)
5101 }
5102
5103 // `parseFloat(value)` stops parsing at the first numeric separator then returns a wrong value.
5104 return parseFloat(str.replace(/_/g, ""))
5105}
5106
5107function stringToBigInt(str) {
5108 if (typeof BigInt !== "function") {
5109 return null
5110 }
5111
5112 // `BigInt(value)` throws syntax error if the string contains numeric separators.
5113 return BigInt(str.replace(/_/g, ""))
5114}
5115
5116pp$9.readRadixNumber = function(radix) {
5117 var start = this.pos;
5118 this.pos += 2; // 0x
5119 var val = this.readInt(radix);
5120 if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
5121 if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
5122 val = stringToBigInt(this.input.slice(start, this.pos));
5123 ++this.pos;
5124 } else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
5125 return this.finishToken(types.num, val)
5126};
5127
5128// Read an integer, octal integer, or floating-point number.
5129
5130pp$9.readNumber = function(startsWithDot) {
5131 var start = this.pos;
5132 if (!startsWithDot && this.readInt(10, undefined, true) === null) { this.raise(start, "Invalid number"); }
5133 var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
5134 if (octal && this.strict) { this.raise(start, "Invalid number"); }
5135 var next = this.input.charCodeAt(this.pos);
5136 if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
5137 var val$1 = stringToBigInt(this.input.slice(start, this.pos));
5138 ++this.pos;
5139 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
5140 return this.finishToken(types.num, val$1)
5141 }
5142 if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
5143 if (next === 46 && !octal) { // '.'
5144 ++this.pos;
5145 this.readInt(10);
5146 next = this.input.charCodeAt(this.pos);
5147 }
5148 if ((next === 69 || next === 101) && !octal) { // 'eE'
5149 next = this.input.charCodeAt(++this.pos);
5150 if (next === 43 || next === 45) { ++this.pos; } // '+-'
5151 if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
5152 }
5153 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
5154
5155 var val = stringToNumber(this.input.slice(start, this.pos), octal);
5156 return this.finishToken(types.num, val)
5157};
5158
5159// Read a string value, interpreting backslash-escapes.
5160
5161pp$9.readCodePoint = function() {
5162 var ch = this.input.charCodeAt(this.pos), code;
5163
5164 if (ch === 123) { // '{'
5165 if (this.options.ecmaVersion < 6) { this.unexpected(); }
5166 var codePos = ++this.pos;
5167 code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
5168 ++this.pos;
5169 if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
5170 } else {
5171 code = this.readHexChar(4);
5172 }
5173 return code
5174};
5175
5176function codePointToString$1(code) {
5177 // UTF-16 Decoding
5178 if (code <= 0xFFFF) { return String.fromCharCode(code) }
5179 code -= 0x10000;
5180 return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
5181}
5182
5183pp$9.readString = function(quote) {
5184 var out = "", chunkStart = ++this.pos;
5185 for (;;) {
5186 if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated string constant"); }
5187 var ch = this.input.charCodeAt(this.pos);
5188 if (ch === quote) { break }
5189 if (ch === 92) { // '\'
5190 out += this.input.slice(chunkStart, this.pos);
5191 out += this.readEscapedChar(false);
5192 chunkStart = this.pos;
5193 } else {
5194 if (isNewLine(ch, this.options.ecmaVersion >= 10)) { this.raise(this.start, "Unterminated string constant"); }
5195 ++this.pos;
5196 }
5197 }
5198 out += this.input.slice(chunkStart, this.pos++);
5199 return this.finishToken(types.string, out)
5200};
5201
5202// Reads template string tokens.
5203
5204var INVALID_TEMPLATE_ESCAPE_ERROR = {};
5205
5206pp$9.tryReadTemplateToken = function() {
5207 this.inTemplateElement = true;
5208 try {
5209 this.readTmplToken();
5210 } catch (err) {
5211 if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
5212 this.readInvalidTemplateToken();
5213 } else {
5214 throw err
5215 }
5216 }
5217
5218 this.inTemplateElement = false;
5219};
5220
5221pp$9.invalidStringToken = function(position, message) {
5222 if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
5223 throw INVALID_TEMPLATE_ESCAPE_ERROR
5224 } else {
5225 this.raise(position, message);
5226 }
5227};
5228
5229pp$9.readTmplToken = function() {
5230 var out = "", chunkStart = this.pos;
5231 for (;;) {
5232 if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated template"); }
5233 var ch = this.input.charCodeAt(this.pos);
5234 if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) { // '`', '${'
5235 if (this.pos === this.start && (this.type === types.template || this.type === types.invalidTemplate)) {
5236 if (ch === 36) {
5237 this.pos += 2;
5238 return this.finishToken(types.dollarBraceL)
5239 } else {
5240 ++this.pos;
5241 return this.finishToken(types.backQuote)
5242 }
5243 }
5244 out += this.input.slice(chunkStart, this.pos);
5245 return this.finishToken(types.template, out)
5246 }
5247 if (ch === 92) { // '\'
5248 out += this.input.slice(chunkStart, this.pos);
5249 out += this.readEscapedChar(true);
5250 chunkStart = this.pos;
5251 } else if (isNewLine(ch)) {
5252 out += this.input.slice(chunkStart, this.pos);
5253 ++this.pos;
5254 switch (ch) {
5255 case 13:
5256 if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
5257 case 10:
5258 out += "\n";
5259 break
5260 default:
5261 out += String.fromCharCode(ch);
5262 break
5263 }
5264 if (this.options.locations) {
5265 ++this.curLine;
5266 this.lineStart = this.pos;
5267 }
5268 chunkStart = this.pos;
5269 } else {
5270 ++this.pos;
5271 }
5272 }
5273};
5274
5275// Reads a template token to search for the end, without validating any escape sequences
5276pp$9.readInvalidTemplateToken = function() {
5277 for (; this.pos < this.input.length; this.pos++) {
5278 switch (this.input[this.pos]) {
5279 case "\\":
5280 ++this.pos;
5281 break
5282
5283 case "$":
5284 if (this.input[this.pos + 1] !== "{") {
5285 break
5286 }
5287 // falls through
5288
5289 case "`":
5290 return this.finishToken(types.invalidTemplate, this.input.slice(this.start, this.pos))
5291
5292 // no default
5293 }
5294 }
5295 this.raise(this.start, "Unterminated template");
5296};
5297
5298// Used to read escaped characters
5299
5300pp$9.readEscapedChar = function(inTemplate) {
5301 var ch = this.input.charCodeAt(++this.pos);
5302 ++this.pos;
5303 switch (ch) {
5304 case 110: return "\n" // 'n' -> '\n'
5305 case 114: return "\r" // 'r' -> '\r'
5306 case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
5307 case 117: return codePointToString$1(this.readCodePoint()) // 'u'
5308 case 116: return "\t" // 't' -> '\t'
5309 case 98: return "\b" // 'b' -> '\b'
5310 case 118: return "\u000b" // 'v' -> '\u000b'
5311 case 102: return "\f" // 'f' -> '\f'
5312 case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
5313 case 10: // ' \n'
5314 if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
5315 return ""
5316 case 56:
5317 case 57:
5318 if (this.strict) {
5319 this.invalidStringToken(
5320 this.pos - 1,
5321 "Invalid escape sequence"
5322 );
5323 }
5324 if (inTemplate) {
5325 var codePos = this.pos - 1;
5326
5327 this.invalidStringToken(
5328 codePos,
5329 "Invalid escape sequence in template string"
5330 );
5331
5332 return null
5333 }
5334 default:
5335 if (ch >= 48 && ch <= 55) {
5336 var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
5337 var octal = parseInt(octalStr, 8);
5338 if (octal > 255) {
5339 octalStr = octalStr.slice(0, -1);
5340 octal = parseInt(octalStr, 8);
5341 }
5342 this.pos += octalStr.length - 1;
5343 ch = this.input.charCodeAt(this.pos);
5344 if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
5345 this.invalidStringToken(
5346 this.pos - 1 - octalStr.length,
5347 inTemplate
5348 ? "Octal literal in template string"
5349 : "Octal literal in strict mode"
5350 );
5351 }
5352 return String.fromCharCode(octal)
5353 }
5354 if (isNewLine(ch)) {
5355 // Unicode new line characters after \ get removed from output in both
5356 // template literals and strings
5357 return ""
5358 }
5359 return String.fromCharCode(ch)
5360 }
5361};
5362
5363// Used to read character escape sequences ('\x', '\u', '\U').
5364
5365pp$9.readHexChar = function(len) {
5366 var codePos = this.pos;
5367 var n = this.readInt(16, len);
5368 if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
5369 return n
5370};
5371
5372// Read an identifier, and return it as a string. Sets `this.containsEsc`
5373// to whether the word contained a '\u' escape.
5374//
5375// Incrementally adds only escaped chars, adding other chunks as-is
5376// as a micro-optimization.
5377
5378pp$9.readWord1 = function() {
5379 this.containsEsc = false;
5380 var word = "", first = true, chunkStart = this.pos;
5381 var astral = this.options.ecmaVersion >= 6;
5382 while (this.pos < this.input.length) {
5383 var ch = this.fullCharCodeAtPos();
5384 if (isIdentifierChar(ch, astral)) {
5385 this.pos += ch <= 0xffff ? 1 : 2;
5386 } else if (ch === 92) { // "\"
5387 this.containsEsc = true;
5388 word += this.input.slice(chunkStart, this.pos);
5389 var escStart = this.pos;
5390 if (this.input.charCodeAt(++this.pos) !== 117) // "u"
5391 { this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); }
5392 ++this.pos;
5393 var esc = this.readCodePoint();
5394 if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
5395 { this.invalidStringToken(escStart, "Invalid Unicode escape"); }
5396 word += codePointToString$1(esc);
5397 chunkStart = this.pos;
5398 } else {
5399 break
5400 }
5401 first = false;
5402 }
5403 return word + this.input.slice(chunkStart, this.pos)
5404};
5405
5406// Read an identifier or keyword token. Will check for reserved
5407// words when necessary.
5408
5409pp$9.readWord = function() {
5410 var word = this.readWord1();
5411 var type = types.name;
5412 if (this.keywords.test(word)) {
5413 type = keywords$1[word];
5414 }
5415 return this.finishToken(type, word)
5416};
5417
5418// Acorn is a tiny, fast JavaScript parser written in JavaScript.
5419
5420var version = "8.2.0";
5421
5422Parser.acorn = {
5423 Parser: Parser,
5424 version: version,
5425 defaultOptions: defaultOptions,
5426 Position: Position,
5427 SourceLocation: SourceLocation,
5428 getLineInfo: getLineInfo,
5429 Node: Node,
5430 TokenType: TokenType,
5431 tokTypes: types,
5432 keywordTypes: keywords$1,
5433 TokContext: TokContext,
5434 tokContexts: types$1,
5435 isIdentifierChar: isIdentifierChar,
5436 isIdentifierStart: isIdentifierStart,
5437 Token: Token,
5438 isNewLine: isNewLine,
5439 lineBreak: lineBreak,
5440 lineBreakG: lineBreakG,
5441 nonASCIIwhitespace: nonASCIIwhitespace
5442};
5443
5444// The main exported interface (under `self.acorn` when in the
5445// browser) is a `parse` function that takes a code string and
5446// returns an abstract syntax tree as specified by [Mozilla parser
5447// API][api].
5448//
5449// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
5450
5451function parse(input, options) {
5452 return Parser.parse(input, options)
5453}
5454
5455// This function tries to parse a single expression at a given
5456// offset in a string. Useful for parsing mixed-language formats
5457// that embed JavaScript expressions.
5458
5459function parseExpressionAt(input, pos, options) {
5460 return Parser.parseExpressionAt(input, pos, options)
5461}
5462
5463// Acorn is organized as a tokenizer and a recursive-descent parser.
5464// The `tokenizer` export provides an interface to the tokenizer.
5465
5466function tokenizer(input, options) {
5467 return Parser.tokenizer(input, options)
5468}
5469
5470export { Node, Parser, Position, SourceLocation, TokContext, Token, TokenType, defaultOptions, getLineInfo, isIdentifierChar, isIdentifierStart, isNewLine, keywords$1 as keywordTypes, lineBreak, lineBreakG, nonASCIIwhitespace, parse, parseExpressionAt, types$1 as tokContexts, types as tokTypes, tokenizer, version };