source: trip-planner-front/node_modules/acorn/dist/acorn.mjs@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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