UNPKG

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