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

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

primeNG components

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