UNPKG

301 kBJavaScriptView Raw
1import { promises } from 'fs';
2import * as path from 'path';
3import { resolve } from 'path';
4import glob from 'fast-glob';
5import require$$0 from 'util';
6import { cwd } from 'process';
7import typescript from 'typescript';
8
9// Reserved word lists for various dialects of the language
10
11var reservedWords = {
12 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",
13 5: "class enum extends super const export import",
14 6: "enum",
15 strict: "implements interface let package private protected public static yield",
16 strictBind: "eval arguments"
17};
18
19// And the keywords
20
21var 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";
22
23var keywords = {
24 5: ecma5AndLessKeywords,
25 "5module": ecma5AndLessKeywords + " export import",
26 6: ecma5AndLessKeywords + " const class extends export import super"
27};
28
29var keywordRelationalOperator = /^in(stanceof)?$/;
30
31// ## Character categories
32
33// Big ugly regular expressions that match characters in the
34// whitespace, identifier, and identifier-start categories. These
35// are only applied when a character is found to actually have a
36// code point above 128.
37// Generated by `bin/generate-identifier-regex.js`.
38var 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";
39var 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";
40
41var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
42var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
43
44nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
45
46// These are a run-length and offset encoded representation of the
47// >0xffff code points that are a valid part of identifiers. The
48// offset starts at 0x10000, and each pair of numbers represents an
49// offset to the next range, and then a size of the range. They were
50// generated by bin/generate-identifier-regex.js
51
52// eslint-disable-next-line comma-spacing
53var 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];
54
55// eslint-disable-next-line comma-spacing
56var 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];
57
58// This has a complexity linear to the value of the code. The
59// assumption is that looking up astral identifier characters is
60// rare.
61function isInAstralSet(code, set) {
62 var pos = 0x10000;
63 for (var i = 0; i < set.length; i += 2) {
64 pos += set[i];
65 if (pos > code) { return false }
66 pos += set[i + 1];
67 if (pos >= code) { return true }
68 }
69}
70
71// Test whether a given character code starts an identifier.
72
73function isIdentifierStart(code, astral) {
74 if (code < 65) { return code === 36 }
75 if (code < 91) { return true }
76 if (code < 97) { return code === 95 }
77 if (code < 123) { return true }
78 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
79 if (astral === false) { return false }
80 return isInAstralSet(code, astralIdentifierStartCodes)
81}
82
83// Test whether a given character is part of an identifier.
84
85function isIdentifierChar(code, astral) {
86 if (code < 48) { return code === 36 }
87 if (code < 58) { return true }
88 if (code < 65) { return false }
89 if (code < 91) { return true }
90 if (code < 97) { return code === 95 }
91 if (code < 123) { return true }
92 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
93 if (astral === false) { return false }
94 return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
95}
96
97// ## Token types
98
99// The assignment of fine-grained, information-carrying type objects
100// allows the tokenizer to store the information it has about a
101// token in a way that is very cheap for the parser to look up.
102
103// All token type variables start with an underscore, to make them
104// easy to recognize.
105
106// The `beforeExpr` property is used to disambiguate between regular
107// expressions and divisions. It is set on all token types that can
108// be followed by an expression (thus, a slash after them would be a
109// regular expression).
110//
111// The `startsExpr` property is used to check if the token ends a
112// `yield` expression. It is set on all token types that either can
113// directly start an expression (like a quotation mark) or can
114// continue an expression (like the body of a string).
115//
116// `isLoop` marks a keyword as starting a loop, which is important
117// to know when parsing a label, in order to allow or disallow
118// continue jumps to that label.
119
120var TokenType = function TokenType(label, conf) {
121 if ( conf === void 0 ) conf = {};
122
123 this.label = label;
124 this.keyword = conf.keyword;
125 this.beforeExpr = !!conf.beforeExpr;
126 this.startsExpr = !!conf.startsExpr;
127 this.isLoop = !!conf.isLoop;
128 this.isAssign = !!conf.isAssign;
129 this.prefix = !!conf.prefix;
130 this.postfix = !!conf.postfix;
131 this.binop = conf.binop || null;
132 this.updateContext = null;
133};
134
135function binop(name, prec) {
136 return new TokenType(name, {beforeExpr: true, binop: prec})
137}
138var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};
139
140// Map keyword names to token types.
141
142var keywords$1 = {};
143
144// Succinct definitions of keyword token types
145function kw(name, options) {
146 if ( options === void 0 ) options = {};
147
148 options.keyword = name;
149 return keywords$1[name] = new TokenType(name, options)
150}
151
152var types = {
153 num: new TokenType("num", startsExpr),
154 regexp: new TokenType("regexp", startsExpr),
155 string: new TokenType("string", startsExpr),
156 name: new TokenType("name", startsExpr),
157 eof: new TokenType("eof"),
158
159 // Punctuation token types.
160 bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
161 bracketR: new TokenType("]"),
162 braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
163 braceR: new TokenType("}"),
164 parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
165 parenR: new TokenType(")"),
166 comma: new TokenType(",", beforeExpr),
167 semi: new TokenType(";", beforeExpr),
168 colon: new TokenType(":", beforeExpr),
169 dot: new TokenType("."),
170 question: new TokenType("?", beforeExpr),
171 questionDot: new TokenType("?."),
172 arrow: new TokenType("=>", beforeExpr),
173 template: new TokenType("template"),
174 invalidTemplate: new TokenType("invalidTemplate"),
175 ellipsis: new TokenType("...", beforeExpr),
176 backQuote: new TokenType("`", startsExpr),
177 dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
178
179 // Operators. These carry several kinds of properties to help the
180 // parser use them properly (the presence of these properties is
181 // what categorizes them as operators).
182 //
183 // `binop`, when present, specifies that this operator is a binary
184 // operator, and will refer to its precedence.
185 //
186 // `prefix` and `postfix` mark the operator as a prefix or postfix
187 // unary operator.
188 //
189 // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
190 // binary operators with a very low precedence, that should result
191 // in AssignmentExpression nodes.
192
193 eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
194 assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
195 incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
196 prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
197 logicalOR: binop("||", 1),
198 logicalAND: binop("&&", 2),
199 bitwiseOR: binop("|", 3),
200 bitwiseXOR: binop("^", 4),
201 bitwiseAND: binop("&", 5),
202 equality: binop("==/!=/===/!==", 6),
203 relational: binop("</>/<=/>=", 7),
204 bitShift: binop("<</>>/>>>", 8),
205 plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
206 modulo: binop("%", 10),
207 star: binop("*", 10),
208 slash: binop("/", 10),
209 starstar: new TokenType("**", {beforeExpr: true}),
210 coalesce: binop("??", 1),
211
212 // Keyword token types.
213 _break: kw("break"),
214 _case: kw("case", beforeExpr),
215 _catch: kw("catch"),
216 _continue: kw("continue"),
217 _debugger: kw("debugger"),
218 _default: kw("default", beforeExpr),
219 _do: kw("do", {isLoop: true, beforeExpr: true}),
220 _else: kw("else", beforeExpr),
221 _finally: kw("finally"),
222 _for: kw("for", {isLoop: true}),
223 _function: kw("function", startsExpr),
224 _if: kw("if"),
225 _return: kw("return", beforeExpr),
226 _switch: kw("switch"),
227 _throw: kw("throw", beforeExpr),
228 _try: kw("try"),
229 _var: kw("var"),
230 _const: kw("const"),
231 _while: kw("while", {isLoop: true}),
232 _with: kw("with"),
233 _new: kw("new", {beforeExpr: true, startsExpr: true}),
234 _this: kw("this", startsExpr),
235 _super: kw("super", startsExpr),
236 _class: kw("class", startsExpr),
237 _extends: kw("extends", beforeExpr),
238 _export: kw("export"),
239 _import: kw("import", startsExpr),
240 _null: kw("null", startsExpr),
241 _true: kw("true", startsExpr),
242 _false: kw("false", startsExpr),
243 _in: kw("in", {beforeExpr: true, binop: 7}),
244 _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
245 _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
246 _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
247 _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
248};
249
250// Matches a whole line break (where CRLF is considered a single
251// line break). Used to count lines.
252
253var lineBreak = /\r\n?|\n|\u2028|\u2029/;
254var lineBreakG = new RegExp(lineBreak.source, "g");
255
256function isNewLine(code, ecma2019String) {
257 return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029))
258}
259
260var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
261
262var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
263
264var ref = Object.prototype;
265var hasOwnProperty = ref.hasOwnProperty;
266var toString$1 = ref.toString;
267
268// Checks if an object has a property.
269
270function has$3(obj, propName) {
271 return hasOwnProperty.call(obj, propName)
272}
273
274var isArray$1 = Array.isArray || (function (obj) { return (
275 toString$1.call(obj) === "[object Array]"
276); });
277
278function wordsRegexp(words) {
279 return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
280}
281
282// These are used when `options.locations` is on, for the
283// `startLoc` and `endLoc` properties.
284
285var Position = function Position(line, col) {
286 this.line = line;
287 this.column = col;
288};
289
290Position.prototype.offset = function offset (n) {
291 return new Position(this.line, this.column + n)
292};
293
294var SourceLocation = function SourceLocation(p, start, end) {
295 this.start = start;
296 this.end = end;
297 if (p.sourceFile !== null) { this.source = p.sourceFile; }
298};
299
300// The `getLineInfo` function is mostly useful when the
301// `locations` option is off (for performance reasons) and you
302// want to find the line/column position for a given character
303// offset. `input` should be the code string that the offset refers
304// into.
305
306function getLineInfo(input, offset) {
307 for (var line = 1, cur = 0;;) {
308 lineBreakG.lastIndex = cur;
309 var match = lineBreakG.exec(input);
310 if (match && match.index < offset) {
311 ++line;
312 cur = match.index + match[0].length;
313 } else {
314 return new Position(line, offset - cur)
315 }
316 }
317}
318
319// A second argument must be given to configure the parser process.
320// These options are recognized (only `ecmaVersion` is required):
321
322var defaultOptions = {
323 // `ecmaVersion` indicates the ECMAScript version to parse. Must be
324 // either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10
325 // (2019), 11 (2020), 12 (2021), or `"latest"` (the latest version
326 // the library supports). This influences support for strict mode,
327 // the set of reserved words, and support for new syntax features.
328 ecmaVersion: null,
329 // `sourceType` indicates the mode the code should be parsed in.
330 // Can be either `"script"` or `"module"`. This influences global
331 // strict mode and parsing of `import` and `export` declarations.
332 sourceType: "script",
333 // `onInsertedSemicolon` can be a callback that will be called
334 // when a semicolon is automatically inserted. It will be passed
335 // the position of the comma as an offset, and if `locations` is
336 // enabled, it is given the location as a `{line, column}` object
337 // as second argument.
338 onInsertedSemicolon: null,
339 // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
340 // trailing commas.
341 onTrailingComma: null,
342 // By default, reserved words are only enforced if ecmaVersion >= 5.
343 // Set `allowReserved` to a boolean value to explicitly turn this on
344 // an off. When this option has the value "never", reserved words
345 // and keywords can also not be used as property names.
346 allowReserved: null,
347 // When enabled, a return at the top level is not considered an
348 // error.
349 allowReturnOutsideFunction: false,
350 // When enabled, import/export statements are not constrained to
351 // appearing at the top of the program, and an import.meta expression
352 // in a script isn't considered an error.
353 allowImportExportEverywhere: false,
354 // When enabled, await identifiers are allowed to appear at the top-level scope,
355 // but they are still not allowed in non-async functions.
356 allowAwaitOutsideFunction: false,
357 // When enabled, hashbang directive in the beginning of file
358 // is allowed and treated as a line comment.
359 allowHashBang: false,
360 // When `locations` is on, `loc` properties holding objects with
361 // `start` and `end` properties in `{line, column}` form (with
362 // line being 1-based and column 0-based) will be attached to the
363 // nodes.
364 locations: false,
365 // A function can be passed as `onToken` option, which will
366 // cause Acorn to call that function with object in the same
367 // format as tokens returned from `tokenizer().getToken()`. Note
368 // that you are not allowed to call the parser from the
369 // callback—that will corrupt its internal state.
370 onToken: null,
371 // A function can be passed as `onComment` option, which will
372 // cause Acorn to call that function with `(block, text, start,
373 // end)` parameters whenever a comment is skipped. `block` is a
374 // boolean indicating whether this is a block (`/* */`) comment,
375 // `text` is the content of the comment, and `start` and `end` are
376 // character offsets that denote the start and end of the comment.
377 // When the `locations` option is on, two more parameters are
378 // passed, the full `{line, column}` locations of the start and
379 // end of the comments. Note that you are not allowed to call the
380 // parser from the callback—that will corrupt its internal state.
381 onComment: null,
382 // Nodes have their start and end characters offsets recorded in
383 // `start` and `end` properties (directly on the node, rather than
384 // the `loc` object, which holds line/column data. To also add a
385 // [semi-standardized][range] `range` property holding a `[start,
386 // end]` array with the same numbers, set the `ranges` option to
387 // `true`.
388 //
389 // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
390 ranges: false,
391 // It is possible to parse multiple files into a single AST by
392 // passing the tree produced by parsing the first file as
393 // `program` option in subsequent parses. This will add the
394 // toplevel forms of the parsed file to the `Program` (top) node
395 // of an existing parse tree.
396 program: null,
397 // When `locations` is on, you can pass this to record the source
398 // file in every node's `loc` object.
399 sourceFile: null,
400 // This value, if given, is stored in every node, whether
401 // `locations` is on or off.
402 directSourceFile: null,
403 // When enabled, parenthesized expressions are represented by
404 // (non-standard) ParenthesizedExpression nodes
405 preserveParens: false
406};
407
408// Interpret and default an options object
409
410var warnedAboutEcmaVersion = false;
411
412function getOptions(opts) {
413 var options = {};
414
415 for (var opt in defaultOptions)
416 { options[opt] = opts && has$3(opts, opt) ? opts[opt] : defaultOptions[opt]; }
417
418 if (options.ecmaVersion === "latest") {
419 options.ecmaVersion = 1e8;
420 } else if (options.ecmaVersion == null) {
421 if (!warnedAboutEcmaVersion && typeof console === "object" && console.warn) {
422 warnedAboutEcmaVersion = true;
423 console.warn("Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future.");
424 }
425 options.ecmaVersion = 11;
426 } else if (options.ecmaVersion >= 2015) {
427 options.ecmaVersion -= 2009;
428 }
429
430 if (options.allowReserved == null)
431 { options.allowReserved = options.ecmaVersion < 5; }
432
433 if (isArray$1(options.onToken)) {
434 var tokens = options.onToken;
435 options.onToken = function (token) { return tokens.push(token); };
436 }
437 if (isArray$1(options.onComment))
438 { options.onComment = pushComment(options, options.onComment); }
439
440 return options
441}
442
443function pushComment(options, array) {
444 return function(block, text, start, end, startLoc, endLoc) {
445 var comment = {
446 type: block ? "Block" : "Line",
447 value: text,
448 start: start,
449 end: end
450 };
451 if (options.locations)
452 { comment.loc = new SourceLocation(this, startLoc, endLoc); }
453 if (options.ranges)
454 { comment.range = [start, end]; }
455 array.push(comment);
456 }
457}
458
459// Each scope gets a bitset that may contain these flags
460var
461 SCOPE_TOP = 1,
462 SCOPE_FUNCTION = 2,
463 SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION,
464 SCOPE_ASYNC = 4,
465 SCOPE_GENERATOR = 8,
466 SCOPE_ARROW = 16,
467 SCOPE_SIMPLE_CATCH = 32,
468 SCOPE_SUPER = 64,
469 SCOPE_DIRECT_SUPER = 128;
470
471function functionFlags(async, generator) {
472 return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
473}
474
475// Used in checkLVal* and declareName to determine the type of a binding
476var
477 BIND_NONE = 0, // Not a binding
478 BIND_VAR = 1, // Var-style binding
479 BIND_LEXICAL = 2, // Let- or const-style binding
480 BIND_FUNCTION = 3, // Function declaration
481 BIND_SIMPLE_CATCH = 4, // Simple (identifier pattern) catch binding
482 BIND_OUTSIDE = 5; // Special case for function names as bound inside the function
483
484var Parser = function Parser(options, input, startPos) {
485 this.options = options = getOptions(options);
486 this.sourceFile = options.sourceFile;
487 this.keywords = wordsRegexp(keywords[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]);
488 var reserved = "";
489 if (options.allowReserved !== true) {
490 reserved = reservedWords[options.ecmaVersion >= 6 ? 6 : options.ecmaVersion === 5 ? 5 : 3];
491 if (options.sourceType === "module") { reserved += " await"; }
492 }
493 this.reservedWords = wordsRegexp(reserved);
494 var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
495 this.reservedWordsStrict = wordsRegexp(reservedStrict);
496 this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
497 this.input = String(input);
498
499 // Used to signal to callers of `readWord1` whether the word
500 // contained any escape sequences. This is needed because words with
501 // escape sequences must not be interpreted as keywords.
502 this.containsEsc = false;
503
504 // Set up token state
505
506 // The current position of the tokenizer in the input.
507 if (startPos) {
508 this.pos = startPos;
509 this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
510 this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
511 } else {
512 this.pos = this.lineStart = 0;
513 this.curLine = 1;
514 }
515
516 // Properties of the current token:
517 // Its type
518 this.type = types.eof;
519 // For tokens that include more information than their type, the value
520 this.value = null;
521 // Its start and end offset
522 this.start = this.end = this.pos;
523 // And, if locations are used, the {line, column} object
524 // corresponding to those offsets
525 this.startLoc = this.endLoc = this.curPosition();
526
527 // Position information for the previous token
528 this.lastTokEndLoc = this.lastTokStartLoc = null;
529 this.lastTokStart = this.lastTokEnd = this.pos;
530
531 // The context stack is used to superficially track syntactic
532 // context to predict whether a regular expression is allowed in a
533 // given position.
534 this.context = this.initialContext();
535 this.exprAllowed = true;
536
537 // Figure out if it's a module code.
538 this.inModule = options.sourceType === "module";
539 this.strict = this.inModule || this.strictDirective(this.pos);
540
541 // Used to signify the start of a potential arrow function
542 this.potentialArrowAt = -1;
543
544 // Positions to delayed-check that yield/await does not exist in default parameters.
545 this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
546 // Labels in scope.
547 this.labels = [];
548 // Thus-far undefined exports.
549 this.undefinedExports = Object.create(null);
550
551 // If enabled, skip leading hashbang line.
552 if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
553 { this.skipLineComment(2); }
554
555 // Scope tracking for duplicate variable names (see scope.js)
556 this.scopeStack = [];
557 this.enterScope(SCOPE_TOP);
558
559 // For RegExp validation
560 this.regexpState = null;
561};
562
563var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true },inNonArrowFunction: { configurable: true } };
564
565Parser.prototype.parse = function parse () {
566 var node = this.options.program || this.startNode();
567 this.nextToken();
568 return this.parseTopLevel(node)
569};
570
571prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
572prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 };
573prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 };
574prototypeAccessors.allowSuper.get = function () { return (this.currentThisScope().flags & SCOPE_SUPER) > 0 };
575prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
576prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
577prototypeAccessors.inNonArrowFunction.get = function () { return (this.currentThisScope().flags & SCOPE_FUNCTION) > 0 };
578
579Parser.extend = function extend () {
580 var plugins = [], len = arguments.length;
581 while ( len-- ) plugins[ len ] = arguments[ len ];
582
583 var cls = this;
584 for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
585 return cls
586};
587
588Parser.parse = function parse (input, options) {
589 return new this(options, input).parse()
590};
591
592Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
593 var parser = new this(options, input, pos);
594 parser.nextToken();
595 return parser.parseExpression()
596};
597
598Parser.tokenizer = function tokenizer (input, options) {
599 return new this(options, input)
600};
601
602Object.defineProperties( Parser.prototype, prototypeAccessors );
603
604var pp = Parser.prototype;
605
606// ## Parser utilities
607
608var literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/;
609pp.strictDirective = function(start) {
610 for (;;) {
611 // Try to find string literal.
612 skipWhiteSpace.lastIndex = start;
613 start += skipWhiteSpace.exec(this.input)[0].length;
614 var match = literal.exec(this.input.slice(start));
615 if (!match) { return false }
616 if ((match[1] || match[2]) === "use strict") {
617 skipWhiteSpace.lastIndex = start + match[0].length;
618 var spaceAfter = skipWhiteSpace.exec(this.input), end = spaceAfter.index + spaceAfter[0].length;
619 var next = this.input.charAt(end);
620 return next === ";" || next === "}" ||
621 (lineBreak.test(spaceAfter[0]) &&
622 !(/[(`.[+\-/*%<>=,?^&]/.test(next) || next === "!" && this.input.charAt(end + 1) === "="))
623 }
624 start += match[0].length;
625
626 // Skip semicolon, if any.
627 skipWhiteSpace.lastIndex = start;
628 start += skipWhiteSpace.exec(this.input)[0].length;
629 if (this.input[start] === ";")
630 { start++; }
631 }
632};
633
634// Predicate that tests whether the next token is of the given
635// type, and if yes, consumes it as a side effect.
636
637pp.eat = function(type) {
638 if (this.type === type) {
639 this.next();
640 return true
641 } else {
642 return false
643 }
644};
645
646// Tests whether parsed token is a contextual keyword.
647
648pp.isContextual = function(name) {
649 return this.type === types.name && this.value === name && !this.containsEsc
650};
651
652// Consumes contextual keyword if possible.
653
654pp.eatContextual = function(name) {
655 if (!this.isContextual(name)) { return false }
656 this.next();
657 return true
658};
659
660// Asserts that following token is given contextual keyword.
661
662pp.expectContextual = function(name) {
663 if (!this.eatContextual(name)) { this.unexpected(); }
664};
665
666// Test whether a semicolon can be inserted at the current position.
667
668pp.canInsertSemicolon = function() {
669 return this.type === types.eof ||
670 this.type === types.braceR ||
671 lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
672};
673
674pp.insertSemicolon = function() {
675 if (this.canInsertSemicolon()) {
676 if (this.options.onInsertedSemicolon)
677 { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
678 return true
679 }
680};
681
682// Consume a semicolon, or, failing that, see if we are allowed to
683// pretend that there is a semicolon at this position.
684
685pp.semicolon = function() {
686 if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
687};
688
689pp.afterTrailingComma = function(tokType, notNext) {
690 if (this.type === tokType) {
691 if (this.options.onTrailingComma)
692 { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
693 if (!notNext)
694 { this.next(); }
695 return true
696 }
697};
698
699// Expect a token of a given type. If found, consume it, otherwise,
700// raise an unexpected token error.
701
702pp.expect = function(type) {
703 this.eat(type) || this.unexpected();
704};
705
706// Raise an unexpected token error.
707
708pp.unexpected = function(pos) {
709 this.raise(pos != null ? pos : this.start, "Unexpected token");
710};
711
712function DestructuringErrors() {
713 this.shorthandAssign =
714 this.trailingComma =
715 this.parenthesizedAssign =
716 this.parenthesizedBind =
717 this.doubleProto =
718 -1;
719}
720
721pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
722 if (!refDestructuringErrors) { return }
723 if (refDestructuringErrors.trailingComma > -1)
724 { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
725 var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
726 if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
727};
728
729pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
730 if (!refDestructuringErrors) { return false }
731 var shorthandAssign = refDestructuringErrors.shorthandAssign;
732 var doubleProto = refDestructuringErrors.doubleProto;
733 if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
734 if (shorthandAssign >= 0)
735 { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
736 if (doubleProto >= 0)
737 { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
738};
739
740pp.checkYieldAwaitInDefaultParams = function() {
741 if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
742 { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
743 if (this.awaitPos)
744 { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
745};
746
747pp.isSimpleAssignTarget = function(expr) {
748 if (expr.type === "ParenthesizedExpression")
749 { return this.isSimpleAssignTarget(expr.expression) }
750 return expr.type === "Identifier" || expr.type === "MemberExpression"
751};
752
753var pp$1 = Parser.prototype;
754
755// ### Statement parsing
756
757// Parse a program. Initializes the parser, reads any number of
758// statements, and wraps them in a Program node. Optionally takes a
759// `program` argument. If present, the statements will be appended
760// to its body instead of creating a new node.
761
762pp$1.parseTopLevel = function(node) {
763 var exports = Object.create(null);
764 if (!node.body) { node.body = []; }
765 while (this.type !== types.eof) {
766 var stmt = this.parseStatement(null, true, exports);
767 node.body.push(stmt);
768 }
769 if (this.inModule)
770 { for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1)
771 {
772 var name = list[i];
773
774 this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
775 } }
776 this.adaptDirectivePrologue(node.body);
777 this.next();
778 node.sourceType = this.options.sourceType;
779 return this.finishNode(node, "Program")
780};
781
782var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
783
784pp$1.isLet = function(context) {
785 if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
786 skipWhiteSpace.lastIndex = this.pos;
787 var skip = skipWhiteSpace.exec(this.input);
788 var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
789 // For ambiguous cases, determine if a LexicalDeclaration (or only a
790 // Statement) is allowed here. If context is not empty then only a Statement
791 // is allowed. However, `let [` is an explicit negative lookahead for
792 // ExpressionStatement, so special-case it first.
793 if (nextCh === 91) { return true } // '['
794 if (context) { return false }
795
796 if (nextCh === 123) { return true } // '{'
797 if (isIdentifierStart(nextCh, true)) {
798 var pos = next + 1;
799 while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
800 var ident = this.input.slice(next, pos);
801 if (!keywordRelationalOperator.test(ident)) { return true }
802 }
803 return false
804};
805
806// check 'async [no LineTerminator here] function'
807// - 'async /*foo*/ function' is OK.
808// - 'async /*\n*/ function' is invalid.
809pp$1.isAsyncFunction = function() {
810 if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
811 { return false }
812
813 skipWhiteSpace.lastIndex = this.pos;
814 var skip = skipWhiteSpace.exec(this.input);
815 var next = this.pos + skip[0].length;
816 return !lineBreak.test(this.input.slice(this.pos, next)) &&
817 this.input.slice(next, next + 8) === "function" &&
818 (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
819};
820
821// Parse a single statement.
822//
823// If expecting a statement and finding a slash operator, parse a
824// regular expression literal. This is to handle cases like
825// `if (foo) /blah/.exec(foo)`, where looking at the previous token
826// does not help.
827
828pp$1.parseStatement = function(context, topLevel, exports) {
829 var starttype = this.type, node = this.startNode(), kind;
830
831 if (this.isLet(context)) {
832 starttype = types._var;
833 kind = "let";
834 }
835
836 // Most types of statements are recognized by the keyword they
837 // start with. Many are trivial to parse, some require a bit of
838 // complexity.
839
840 switch (starttype) {
841 case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
842 case types._debugger: return this.parseDebuggerStatement(node)
843 case types._do: return this.parseDoStatement(node)
844 case types._for: return this.parseForStatement(node)
845 case types._function:
846 // Function as sole body of either an if statement or a labeled statement
847 // works, but not when it is part of a labeled statement that is the sole
848 // body of an if statement.
849 if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
850 return this.parseFunctionStatement(node, false, !context)
851 case types._class:
852 if (context) { this.unexpected(); }
853 return this.parseClass(node, true)
854 case types._if: return this.parseIfStatement(node)
855 case types._return: return this.parseReturnStatement(node)
856 case types._switch: return this.parseSwitchStatement(node)
857 case types._throw: return this.parseThrowStatement(node)
858 case types._try: return this.parseTryStatement(node)
859 case types._const: case types._var:
860 kind = kind || this.value;
861 if (context && kind !== "var") { this.unexpected(); }
862 return this.parseVarStatement(node, kind)
863 case types._while: return this.parseWhileStatement(node)
864 case types._with: return this.parseWithStatement(node)
865 case types.braceL: return this.parseBlock(true, node)
866 case types.semi: return this.parseEmptyStatement(node)
867 case types._export:
868 case types._import:
869 if (this.options.ecmaVersion > 10 && starttype === types._import) {
870 skipWhiteSpace.lastIndex = this.pos;
871 var skip = skipWhiteSpace.exec(this.input);
872 var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
873 if (nextCh === 40 || nextCh === 46) // '(' or '.'
874 { return this.parseExpressionStatement(node, this.parseExpression()) }
875 }
876
877 if (!this.options.allowImportExportEverywhere) {
878 if (!topLevel)
879 { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
880 if (!this.inModule)
881 { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
882 }
883 return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
884
885 // If the statement does not start with a statement keyword or a
886 // brace, it's an ExpressionStatement or LabeledStatement. We
887 // simply start parsing an expression, and afterwards, if the
888 // next token is a colon and the expression was a simple
889 // Identifier node, we switch to interpreting it as a label.
890 default:
891 if (this.isAsyncFunction()) {
892 if (context) { this.unexpected(); }
893 this.next();
894 return this.parseFunctionStatement(node, true, !context)
895 }
896
897 var maybeName = this.value, expr = this.parseExpression();
898 if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
899 { return this.parseLabeledStatement(node, maybeName, expr, context) }
900 else { return this.parseExpressionStatement(node, expr) }
901 }
902};
903
904pp$1.parseBreakContinueStatement = function(node, keyword) {
905 var isBreak = keyword === "break";
906 this.next();
907 if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
908 else if (this.type !== types.name) { this.unexpected(); }
909 else {
910 node.label = this.parseIdent();
911 this.semicolon();
912 }
913
914 // Verify that there is an actual destination to break or
915 // continue to.
916 var i = 0;
917 for (; i < this.labels.length; ++i) {
918 var lab = this.labels[i];
919 if (node.label == null || lab.name === node.label.name) {
920 if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
921 if (node.label && isBreak) { break }
922 }
923 }
924 if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
925 return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
926};
927
928pp$1.parseDebuggerStatement = function(node) {
929 this.next();
930 this.semicolon();
931 return this.finishNode(node, "DebuggerStatement")
932};
933
934pp$1.parseDoStatement = function(node) {
935 this.next();
936 this.labels.push(loopLabel);
937 node.body = this.parseStatement("do");
938 this.labels.pop();
939 this.expect(types._while);
940 node.test = this.parseParenExpression();
941 if (this.options.ecmaVersion >= 6)
942 { this.eat(types.semi); }
943 else
944 { this.semicolon(); }
945 return this.finishNode(node, "DoWhileStatement")
946};
947
948// Disambiguating between a `for` and a `for`/`in` or `for`/`of`
949// loop is non-trivial. Basically, we have to parse the init `var`
950// statement or expression, disallowing the `in` operator (see
951// the second parameter to `parseExpression`), and then check
952// whether the next token is `in` or `of`. When there is no init
953// part (semicolon immediately after the opening parenthesis), it
954// is a regular `for` loop.
955
956pp$1.parseForStatement = function(node) {
957 this.next();
958 var awaitAt = (this.options.ecmaVersion >= 9 && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction)) && this.eatContextual("await")) ? this.lastTokStart : -1;
959 this.labels.push(loopLabel);
960 this.enterScope(0);
961 this.expect(types.parenL);
962 if (this.type === types.semi) {
963 if (awaitAt > -1) { this.unexpected(awaitAt); }
964 return this.parseFor(node, null)
965 }
966 var isLet = this.isLet();
967 if (this.type === types._var || this.type === types._const || isLet) {
968 var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
969 this.next();
970 this.parseVar(init$1, true, kind);
971 this.finishNode(init$1, "VariableDeclaration");
972 if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1) {
973 if (this.options.ecmaVersion >= 9) {
974 if (this.type === types._in) {
975 if (awaitAt > -1) { this.unexpected(awaitAt); }
976 } else { node.await = awaitAt > -1; }
977 }
978 return this.parseForIn(node, init$1)
979 }
980 if (awaitAt > -1) { this.unexpected(awaitAt); }
981 return this.parseFor(node, init$1)
982 }
983 var refDestructuringErrors = new DestructuringErrors;
984 var init = this.parseExpression(true, refDestructuringErrors);
985 if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
986 if (this.options.ecmaVersion >= 9) {
987 if (this.type === types._in) {
988 if (awaitAt > -1) { this.unexpected(awaitAt); }
989 } else { node.await = awaitAt > -1; }
990 }
991 this.toAssignable(init, false, refDestructuringErrors);
992 this.checkLValPattern(init);
993 return this.parseForIn(node, init)
994 } else {
995 this.checkExpressionErrors(refDestructuringErrors, true);
996 }
997 if (awaitAt > -1) { this.unexpected(awaitAt); }
998 return this.parseFor(node, init)
999};
1000
1001pp$1.parseFunctionStatement = function(node, isAsync, declarationPosition) {
1002 this.next();
1003 return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
1004};
1005
1006pp$1.parseIfStatement = function(node) {
1007 this.next();
1008 node.test = this.parseParenExpression();
1009 // allow function declarations in branches, but only in non-strict mode
1010 node.consequent = this.parseStatement("if");
1011 node.alternate = this.eat(types._else) ? this.parseStatement("if") : null;
1012 return this.finishNode(node, "IfStatement")
1013};
1014
1015pp$1.parseReturnStatement = function(node) {
1016 if (!this.inFunction && !this.options.allowReturnOutsideFunction)
1017 { this.raise(this.start, "'return' outside of function"); }
1018 this.next();
1019
1020 // In `return` (and `break`/`continue`), the keywords with
1021 // optional arguments, we eagerly look for a semicolon or the
1022 // possibility to insert one.
1023
1024 if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
1025 else { node.argument = this.parseExpression(); this.semicolon(); }
1026 return this.finishNode(node, "ReturnStatement")
1027};
1028
1029pp$1.parseSwitchStatement = function(node) {
1030 this.next();
1031 node.discriminant = this.parseParenExpression();
1032 node.cases = [];
1033 this.expect(types.braceL);
1034 this.labels.push(switchLabel);
1035 this.enterScope(0);
1036
1037 // Statements under must be grouped (by label) in SwitchCase
1038 // nodes. `cur` is used to keep the node that we are currently
1039 // adding statements to.
1040
1041 var cur;
1042 for (var sawDefault = false; this.type !== types.braceR;) {
1043 if (this.type === types._case || this.type === types._default) {
1044 var isCase = this.type === types._case;
1045 if (cur) { this.finishNode(cur, "SwitchCase"); }
1046 node.cases.push(cur = this.startNode());
1047 cur.consequent = [];
1048 this.next();
1049 if (isCase) {
1050 cur.test = this.parseExpression();
1051 } else {
1052 if (sawDefault) { this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); }
1053 sawDefault = true;
1054 cur.test = null;
1055 }
1056 this.expect(types.colon);
1057 } else {
1058 if (!cur) { this.unexpected(); }
1059 cur.consequent.push(this.parseStatement(null));
1060 }
1061 }
1062 this.exitScope();
1063 if (cur) { this.finishNode(cur, "SwitchCase"); }
1064 this.next(); // Closing brace
1065 this.labels.pop();
1066 return this.finishNode(node, "SwitchStatement")
1067};
1068
1069pp$1.parseThrowStatement = function(node) {
1070 this.next();
1071 if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
1072 { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
1073 node.argument = this.parseExpression();
1074 this.semicolon();
1075 return this.finishNode(node, "ThrowStatement")
1076};
1077
1078// Reused empty array added for node fields that are always empty.
1079
1080var empty = [];
1081
1082pp$1.parseTryStatement = function(node) {
1083 this.next();
1084 node.block = this.parseBlock();
1085 node.handler = null;
1086 if (this.type === types._catch) {
1087 var clause = this.startNode();
1088 this.next();
1089 if (this.eat(types.parenL)) {
1090 clause.param = this.parseBindingAtom();
1091 var simple = clause.param.type === "Identifier";
1092 this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0);
1093 this.checkLValPattern(clause.param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL);
1094 this.expect(types.parenR);
1095 } else {
1096 if (this.options.ecmaVersion < 10) { this.unexpected(); }
1097 clause.param = null;
1098 this.enterScope(0);
1099 }
1100 clause.body = this.parseBlock(false);
1101 this.exitScope();
1102 node.handler = this.finishNode(clause, "CatchClause");
1103 }
1104 node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
1105 if (!node.handler && !node.finalizer)
1106 { this.raise(node.start, "Missing catch or finally clause"); }
1107 return this.finishNode(node, "TryStatement")
1108};
1109
1110pp$1.parseVarStatement = function(node, kind) {
1111 this.next();
1112 this.parseVar(node, false, kind);
1113 this.semicolon();
1114 return this.finishNode(node, "VariableDeclaration")
1115};
1116
1117pp$1.parseWhileStatement = function(node) {
1118 this.next();
1119 node.test = this.parseParenExpression();
1120 this.labels.push(loopLabel);
1121 node.body = this.parseStatement("while");
1122 this.labels.pop();
1123 return this.finishNode(node, "WhileStatement")
1124};
1125
1126pp$1.parseWithStatement = function(node) {
1127 if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
1128 this.next();
1129 node.object = this.parseParenExpression();
1130 node.body = this.parseStatement("with");
1131 return this.finishNode(node, "WithStatement")
1132};
1133
1134pp$1.parseEmptyStatement = function(node) {
1135 this.next();
1136 return this.finishNode(node, "EmptyStatement")
1137};
1138
1139pp$1.parseLabeledStatement = function(node, maybeName, expr, context) {
1140 for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
1141 {
1142 var label = list[i$1];
1143
1144 if (label.name === maybeName)
1145 { this.raise(expr.start, "Label '" + maybeName + "' is already declared");
1146 } }
1147 var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
1148 for (var i = this.labels.length - 1; i >= 0; i--) {
1149 var label$1 = this.labels[i];
1150 if (label$1.statementStart === node.start) {
1151 // Update information about previous labels on this node
1152 label$1.statementStart = this.start;
1153 label$1.kind = kind;
1154 } else { break }
1155 }
1156 this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
1157 node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
1158 this.labels.pop();
1159 node.label = expr;
1160 return this.finishNode(node, "LabeledStatement")
1161};
1162
1163pp$1.parseExpressionStatement = function(node, expr) {
1164 node.expression = expr;
1165 this.semicolon();
1166 return this.finishNode(node, "ExpressionStatement")
1167};
1168
1169// Parse a semicolon-enclosed block of statements, handling `"use
1170// strict"` declarations when `allowStrict` is true (used for
1171// function bodies).
1172
1173pp$1.parseBlock = function(createNewLexicalScope, node, exitStrict) {
1174 if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
1175 if ( node === void 0 ) node = this.startNode();
1176
1177 node.body = [];
1178 this.expect(types.braceL);
1179 if (createNewLexicalScope) { this.enterScope(0); }
1180 while (this.type !== types.braceR) {
1181 var stmt = this.parseStatement(null);
1182 node.body.push(stmt);
1183 }
1184 if (exitStrict) { this.strict = false; }
1185 this.next();
1186 if (createNewLexicalScope) { this.exitScope(); }
1187 return this.finishNode(node, "BlockStatement")
1188};
1189
1190// Parse a regular `for` loop. The disambiguation code in
1191// `parseStatement` will already have parsed the init statement or
1192// expression.
1193
1194pp$1.parseFor = function(node, init) {
1195 node.init = init;
1196 this.expect(types.semi);
1197 node.test = this.type === types.semi ? null : this.parseExpression();
1198 this.expect(types.semi);
1199 node.update = this.type === types.parenR ? null : this.parseExpression();
1200 this.expect(types.parenR);
1201 node.body = this.parseStatement("for");
1202 this.exitScope();
1203 this.labels.pop();
1204 return this.finishNode(node, "ForStatement")
1205};
1206
1207// Parse a `for`/`in` and `for`/`of` loop, which are almost
1208// same from parser's perspective.
1209
1210pp$1.parseForIn = function(node, init) {
1211 var isForIn = this.type === types._in;
1212 this.next();
1213
1214 if (
1215 init.type === "VariableDeclaration" &&
1216 init.declarations[0].init != null &&
1217 (
1218 !isForIn ||
1219 this.options.ecmaVersion < 8 ||
1220 this.strict ||
1221 init.kind !== "var" ||
1222 init.declarations[0].id.type !== "Identifier"
1223 )
1224 ) {
1225 this.raise(
1226 init.start,
1227 ((isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer")
1228 );
1229 }
1230 node.left = init;
1231 node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
1232 this.expect(types.parenR);
1233 node.body = this.parseStatement("for");
1234 this.exitScope();
1235 this.labels.pop();
1236 return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement")
1237};
1238
1239// Parse a list of variable declarations.
1240
1241pp$1.parseVar = function(node, isFor, kind) {
1242 node.declarations = [];
1243 node.kind = kind;
1244 for (;;) {
1245 var decl = this.startNode();
1246 this.parseVarId(decl, kind);
1247 if (this.eat(types.eq)) {
1248 decl.init = this.parseMaybeAssign(isFor);
1249 } else if (kind === "const" && !(this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
1250 this.unexpected();
1251 } else if (decl.id.type !== "Identifier" && !(isFor && (this.type === types._in || this.isContextual("of")))) {
1252 this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
1253 } else {
1254 decl.init = null;
1255 }
1256 node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
1257 if (!this.eat(types.comma)) { break }
1258 }
1259 return node
1260};
1261
1262pp$1.parseVarId = function(decl, kind) {
1263 decl.id = this.parseBindingAtom();
1264 this.checkLValPattern(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
1265};
1266
1267var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
1268
1269// Parse a function declaration or literal (depending on the
1270// `statement & FUNC_STATEMENT`).
1271
1272// Remove `allowExpressionBody` for 7.0.0, as it is only called with false
1273pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync) {
1274 this.initFunction(node);
1275 if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
1276 if (this.type === types.star && (statement & FUNC_HANGING_STATEMENT))
1277 { this.unexpected(); }
1278 node.generator = this.eat(types.star);
1279 }
1280 if (this.options.ecmaVersion >= 8)
1281 { node.async = !!isAsync; }
1282
1283 if (statement & FUNC_STATEMENT) {
1284 node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types.name ? null : this.parseIdent();
1285 if (node.id && !(statement & FUNC_HANGING_STATEMENT))
1286 // If it is a regular function declaration in sloppy mode, then it is
1287 // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
1288 // mode depends on properties of the current scope (see
1289 // treatFunctionsAsVar).
1290 { this.checkLValSimple(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
1291 }
1292
1293 var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
1294 this.yieldPos = 0;
1295 this.awaitPos = 0;
1296 this.awaitIdentPos = 0;
1297 this.enterScope(functionFlags(node.async, node.generator));
1298
1299 if (!(statement & FUNC_STATEMENT))
1300 { node.id = this.type === types.name ? this.parseIdent() : null; }
1301
1302 this.parseFunctionParams(node);
1303 this.parseFunctionBody(node, allowExpressionBody, false);
1304
1305 this.yieldPos = oldYieldPos;
1306 this.awaitPos = oldAwaitPos;
1307 this.awaitIdentPos = oldAwaitIdentPos;
1308 return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
1309};
1310
1311pp$1.parseFunctionParams = function(node) {
1312 this.expect(types.parenL);
1313 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
1314 this.checkYieldAwaitInDefaultParams();
1315};
1316
1317// Parse a class declaration or literal (depending on the
1318// `isStatement` parameter).
1319
1320pp$1.parseClass = function(node, isStatement) {
1321 this.next();
1322
1323 // ecma-262 14.6 Class Definitions
1324 // A class definition is always strict mode code.
1325 var oldStrict = this.strict;
1326 this.strict = true;
1327
1328 this.parseClassId(node, isStatement);
1329 this.parseClassSuper(node);
1330 var classBody = this.startNode();
1331 var hadConstructor = false;
1332 classBody.body = [];
1333 this.expect(types.braceL);
1334 while (this.type !== types.braceR) {
1335 var element = this.parseClassElement(node.superClass !== null);
1336 if (element) {
1337 classBody.body.push(element);
1338 if (element.type === "MethodDefinition" && element.kind === "constructor") {
1339 if (hadConstructor) { this.raise(element.start, "Duplicate constructor in the same class"); }
1340 hadConstructor = true;
1341 }
1342 }
1343 }
1344 this.strict = oldStrict;
1345 this.next();
1346 node.body = this.finishNode(classBody, "ClassBody");
1347 return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
1348};
1349
1350pp$1.parseClassElement = function(constructorAllowsSuper) {
1351 var this$1 = this;
1352
1353 if (this.eat(types.semi)) { return null }
1354
1355 var method = this.startNode();
1356 var tryContextual = function (k, noLineBreak) {
1357 if ( noLineBreak === void 0 ) noLineBreak = false;
1358
1359 var start = this$1.start, startLoc = this$1.startLoc;
1360 if (!this$1.eatContextual(k)) { return false }
1361 if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
1362 if (method.key) { this$1.unexpected(); }
1363 method.computed = false;
1364 method.key = this$1.startNodeAt(start, startLoc);
1365 method.key.name = k;
1366 this$1.finishNode(method.key, "Identifier");
1367 return false
1368 };
1369
1370 method.kind = "method";
1371 method.static = tryContextual("static");
1372 var isGenerator = this.eat(types.star);
1373 var isAsync = false;
1374 if (!isGenerator) {
1375 if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
1376 isAsync = true;
1377 isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
1378 } else if (tryContextual("get")) {
1379 method.kind = "get";
1380 } else if (tryContextual("set")) {
1381 method.kind = "set";
1382 }
1383 }
1384 if (!method.key) { this.parsePropertyName(method); }
1385 var key = method.key;
1386 var allowsDirectSuper = false;
1387 if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
1388 key.type === "Literal" && key.value === "constructor")) {
1389 if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
1390 if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
1391 if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
1392 method.kind = "constructor";
1393 allowsDirectSuper = constructorAllowsSuper;
1394 } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
1395 this.raise(key.start, "Classes may not have a static property named prototype");
1396 }
1397 this.parseClassMethod(method, isGenerator, isAsync, allowsDirectSuper);
1398 if (method.kind === "get" && method.value.params.length !== 0)
1399 { this.raiseRecoverable(method.value.start, "getter should have no params"); }
1400 if (method.kind === "set" && method.value.params.length !== 1)
1401 { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
1402 if (method.kind === "set" && method.value.params[0].type === "RestElement")
1403 { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
1404 return method
1405};
1406
1407pp$1.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
1408 method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
1409 return this.finishNode(method, "MethodDefinition")
1410};
1411
1412pp$1.parseClassId = function(node, isStatement) {
1413 if (this.type === types.name) {
1414 node.id = this.parseIdent();
1415 if (isStatement)
1416 { this.checkLValSimple(node.id, BIND_LEXICAL, false); }
1417 } else {
1418 if (isStatement === true)
1419 { this.unexpected(); }
1420 node.id = null;
1421 }
1422};
1423
1424pp$1.parseClassSuper = function(node) {
1425 node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
1426};
1427
1428// Parses module export declaration.
1429
1430pp$1.parseExport = function(node, exports) {
1431 this.next();
1432 // export * from '...'
1433 if (this.eat(types.star)) {
1434 if (this.options.ecmaVersion >= 11) {
1435 if (this.eatContextual("as")) {
1436 node.exported = this.parseIdent(true);
1437 this.checkExport(exports, node.exported.name, this.lastTokStart);
1438 } else {
1439 node.exported = null;
1440 }
1441 }
1442 this.expectContextual("from");
1443 if (this.type !== types.string) { this.unexpected(); }
1444 node.source = this.parseExprAtom();
1445 this.semicolon();
1446 return this.finishNode(node, "ExportAllDeclaration")
1447 }
1448 if (this.eat(types._default)) { // export default ...
1449 this.checkExport(exports, "default", this.lastTokStart);
1450 var isAsync;
1451 if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
1452 var fNode = this.startNode();
1453 this.next();
1454 if (isAsync) { this.next(); }
1455 node.declaration = this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync);
1456 } else if (this.type === types._class) {
1457 var cNode = this.startNode();
1458 node.declaration = this.parseClass(cNode, "nullableID");
1459 } else {
1460 node.declaration = this.parseMaybeAssign();
1461 this.semicolon();
1462 }
1463 return this.finishNode(node, "ExportDefaultDeclaration")
1464 }
1465 // export var|const|let|function|class ...
1466 if (this.shouldParseExportStatement()) {
1467 node.declaration = this.parseStatement(null);
1468 if (node.declaration.type === "VariableDeclaration")
1469 { this.checkVariableExport(exports, node.declaration.declarations); }
1470 else
1471 { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
1472 node.specifiers = [];
1473 node.source = null;
1474 } else { // export { x, y as z } [from '...']
1475 node.declaration = null;
1476 node.specifiers = this.parseExportSpecifiers(exports);
1477 if (this.eatContextual("from")) {
1478 if (this.type !== types.string) { this.unexpected(); }
1479 node.source = this.parseExprAtom();
1480 } else {
1481 for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
1482 // check for keywords used as local names
1483 var spec = list[i];
1484
1485 this.checkUnreserved(spec.local);
1486 // check if export is defined
1487 this.checkLocalExport(spec.local);
1488 }
1489
1490 node.source = null;
1491 }
1492 this.semicolon();
1493 }
1494 return this.finishNode(node, "ExportNamedDeclaration")
1495};
1496
1497pp$1.checkExport = function(exports, name, pos) {
1498 if (!exports) { return }
1499 if (has$3(exports, name))
1500 { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
1501 exports[name] = true;
1502};
1503
1504pp$1.checkPatternExport = function(exports, pat) {
1505 var type = pat.type;
1506 if (type === "Identifier")
1507 { this.checkExport(exports, pat.name, pat.start); }
1508 else if (type === "ObjectPattern")
1509 { for (var i = 0, list = pat.properties; i < list.length; i += 1)
1510 {
1511 var prop = list[i];
1512
1513 this.checkPatternExport(exports, prop);
1514 } }
1515 else if (type === "ArrayPattern")
1516 { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
1517 var elt = list$1[i$1];
1518
1519 if (elt) { this.checkPatternExport(exports, elt); }
1520 } }
1521 else if (type === "Property")
1522 { this.checkPatternExport(exports, pat.value); }
1523 else if (type === "AssignmentPattern")
1524 { this.checkPatternExport(exports, pat.left); }
1525 else if (type === "RestElement")
1526 { this.checkPatternExport(exports, pat.argument); }
1527 else if (type === "ParenthesizedExpression")
1528 { this.checkPatternExport(exports, pat.expression); }
1529};
1530
1531pp$1.checkVariableExport = function(exports, decls) {
1532 if (!exports) { return }
1533 for (var i = 0, list = decls; i < list.length; i += 1)
1534 {
1535 var decl = list[i];
1536
1537 this.checkPatternExport(exports, decl.id);
1538 }
1539};
1540
1541pp$1.shouldParseExportStatement = function() {
1542 return this.type.keyword === "var" ||
1543 this.type.keyword === "const" ||
1544 this.type.keyword === "class" ||
1545 this.type.keyword === "function" ||
1546 this.isLet() ||
1547 this.isAsyncFunction()
1548};
1549
1550// Parses a comma-separated list of module exports.
1551
1552pp$1.parseExportSpecifiers = function(exports) {
1553 var nodes = [], first = true;
1554 // export { x, y as z } [from '...']
1555 this.expect(types.braceL);
1556 while (!this.eat(types.braceR)) {
1557 if (!first) {
1558 this.expect(types.comma);
1559 if (this.afterTrailingComma(types.braceR)) { break }
1560 } else { first = false; }
1561
1562 var node = this.startNode();
1563 node.local = this.parseIdent(true);
1564 node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
1565 this.checkExport(exports, node.exported.name, node.exported.start);
1566 nodes.push(this.finishNode(node, "ExportSpecifier"));
1567 }
1568 return nodes
1569};
1570
1571// Parses import declaration.
1572
1573pp$1.parseImport = function(node) {
1574 this.next();
1575 // import '...'
1576 if (this.type === types.string) {
1577 node.specifiers = empty;
1578 node.source = this.parseExprAtom();
1579 } else {
1580 node.specifiers = this.parseImportSpecifiers();
1581 this.expectContextual("from");
1582 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1583 }
1584 this.semicolon();
1585 return this.finishNode(node, "ImportDeclaration")
1586};
1587
1588// Parses a comma-separated list of module imports.
1589
1590pp$1.parseImportSpecifiers = function() {
1591 var nodes = [], first = true;
1592 if (this.type === types.name) {
1593 // import defaultObj, { x, y as z } from '...'
1594 var node = this.startNode();
1595 node.local = this.parseIdent();
1596 this.checkLValSimple(node.local, BIND_LEXICAL);
1597 nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
1598 if (!this.eat(types.comma)) { return nodes }
1599 }
1600 if (this.type === types.star) {
1601 var node$1 = this.startNode();
1602 this.next();
1603 this.expectContextual("as");
1604 node$1.local = this.parseIdent();
1605 this.checkLValSimple(node$1.local, BIND_LEXICAL);
1606 nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
1607 return nodes
1608 }
1609 this.expect(types.braceL);
1610 while (!this.eat(types.braceR)) {
1611 if (!first) {
1612 this.expect(types.comma);
1613 if (this.afterTrailingComma(types.braceR)) { break }
1614 } else { first = false; }
1615
1616 var node$2 = this.startNode();
1617 node$2.imported = this.parseIdent(true);
1618 if (this.eatContextual("as")) {
1619 node$2.local = this.parseIdent();
1620 } else {
1621 this.checkUnreserved(node$2.imported);
1622 node$2.local = node$2.imported;
1623 }
1624 this.checkLValSimple(node$2.local, BIND_LEXICAL);
1625 nodes.push(this.finishNode(node$2, "ImportSpecifier"));
1626 }
1627 return nodes
1628};
1629
1630// Set `ExpressionStatement#directive` property for directive prologues.
1631pp$1.adaptDirectivePrologue = function(statements) {
1632 for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
1633 statements[i].directive = statements[i].expression.raw.slice(1, -1);
1634 }
1635};
1636pp$1.isDirectiveCandidate = function(statement) {
1637 return (
1638 statement.type === "ExpressionStatement" &&
1639 statement.expression.type === "Literal" &&
1640 typeof statement.expression.value === "string" &&
1641 // Reject parenthesized strings.
1642 (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
1643 )
1644};
1645
1646var pp$2 = Parser.prototype;
1647
1648// Convert existing expression atom to assignable pattern
1649// if possible.
1650
1651pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
1652 if (this.options.ecmaVersion >= 6 && node) {
1653 switch (node.type) {
1654 case "Identifier":
1655 if (this.inAsync && node.name === "await")
1656 { this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
1657 break
1658
1659 case "ObjectPattern":
1660 case "ArrayPattern":
1661 case "AssignmentPattern":
1662 case "RestElement":
1663 break
1664
1665 case "ObjectExpression":
1666 node.type = "ObjectPattern";
1667 if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1668 for (var i = 0, list = node.properties; i < list.length; i += 1) {
1669 var prop = list[i];
1670
1671 this.toAssignable(prop, isBinding);
1672 // Early error:
1673 // AssignmentRestProperty[Yield, Await] :
1674 // `...` DestructuringAssignmentTarget[Yield, Await]
1675 //
1676 // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
1677 if (
1678 prop.type === "RestElement" &&
1679 (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
1680 ) {
1681 this.raise(prop.argument.start, "Unexpected token");
1682 }
1683 }
1684 break
1685
1686 case "Property":
1687 // AssignmentProperty has type === "Property"
1688 if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
1689 this.toAssignable(node.value, isBinding);
1690 break
1691
1692 case "ArrayExpression":
1693 node.type = "ArrayPattern";
1694 if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1695 this.toAssignableList(node.elements, isBinding);
1696 break
1697
1698 case "SpreadElement":
1699 node.type = "RestElement";
1700 this.toAssignable(node.argument, isBinding);
1701 if (node.argument.type === "AssignmentPattern")
1702 { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
1703 break
1704
1705 case "AssignmentExpression":
1706 if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
1707 node.type = "AssignmentPattern";
1708 delete node.operator;
1709 this.toAssignable(node.left, isBinding);
1710 break
1711
1712 case "ParenthesizedExpression":
1713 this.toAssignable(node.expression, isBinding, refDestructuringErrors);
1714 break
1715
1716 case "ChainExpression":
1717 this.raiseRecoverable(node.start, "Optional chaining cannot appear in left-hand side");
1718 break
1719
1720 case "MemberExpression":
1721 if (!isBinding) { break }
1722
1723 default:
1724 this.raise(node.start, "Assigning to rvalue");
1725 }
1726 } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1727 return node
1728};
1729
1730// Convert list of expression atoms to binding list.
1731
1732pp$2.toAssignableList = function(exprList, isBinding) {
1733 var end = exprList.length;
1734 for (var i = 0; i < end; i++) {
1735 var elt = exprList[i];
1736 if (elt) { this.toAssignable(elt, isBinding); }
1737 }
1738 if (end) {
1739 var last = exprList[end - 1];
1740 if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
1741 { this.unexpected(last.argument.start); }
1742 }
1743 return exprList
1744};
1745
1746// Parses spread element.
1747
1748pp$2.parseSpread = function(refDestructuringErrors) {
1749 var node = this.startNode();
1750 this.next();
1751 node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
1752 return this.finishNode(node, "SpreadElement")
1753};
1754
1755pp$2.parseRestBinding = function() {
1756 var node = this.startNode();
1757 this.next();
1758
1759 // RestElement inside of a function parameter must be an identifier
1760 if (this.options.ecmaVersion === 6 && this.type !== types.name)
1761 { this.unexpected(); }
1762
1763 node.argument = this.parseBindingAtom();
1764
1765 return this.finishNode(node, "RestElement")
1766};
1767
1768// Parses lvalue (assignable) atom.
1769
1770pp$2.parseBindingAtom = function() {
1771 if (this.options.ecmaVersion >= 6) {
1772 switch (this.type) {
1773 case types.bracketL:
1774 var node = this.startNode();
1775 this.next();
1776 node.elements = this.parseBindingList(types.bracketR, true, true);
1777 return this.finishNode(node, "ArrayPattern")
1778
1779 case types.braceL:
1780 return this.parseObj(true)
1781 }
1782 }
1783 return this.parseIdent()
1784};
1785
1786pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
1787 var elts = [], first = true;
1788 while (!this.eat(close)) {
1789 if (first) { first = false; }
1790 else { this.expect(types.comma); }
1791 if (allowEmpty && this.type === types.comma) {
1792 elts.push(null);
1793 } else if (allowTrailingComma && this.afterTrailingComma(close)) {
1794 break
1795 } else if (this.type === types.ellipsis) {
1796 var rest = this.parseRestBinding();
1797 this.parseBindingListItem(rest);
1798 elts.push(rest);
1799 if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
1800 this.expect(close);
1801 break
1802 } else {
1803 var elem = this.parseMaybeDefault(this.start, this.startLoc);
1804 this.parseBindingListItem(elem);
1805 elts.push(elem);
1806 }
1807 }
1808 return elts
1809};
1810
1811pp$2.parseBindingListItem = function(param) {
1812 return param
1813};
1814
1815// Parses assignment pattern around given atom if possible.
1816
1817pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
1818 left = left || this.parseBindingAtom();
1819 if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
1820 var node = this.startNodeAt(startPos, startLoc);
1821 node.left = left;
1822 node.right = this.parseMaybeAssign();
1823 return this.finishNode(node, "AssignmentPattern")
1824};
1825
1826// The following three functions all verify that a node is an lvalue —
1827// something that can be bound, or assigned to. In order to do so, they perform
1828// a variety of checks:
1829//
1830// - Check that none of the bound/assigned-to identifiers are reserved words.
1831// - Record name declarations for bindings in the appropriate scope.
1832// - Check duplicate argument names, if checkClashes is set.
1833//
1834// If a complex binding pattern is encountered (e.g., object and array
1835// destructuring), the entire pattern is recursively checked.
1836//
1837// There are three versions of checkLVal*() appropriate for different
1838// circumstances:
1839//
1840// - checkLValSimple() shall be used if the syntactic construct supports
1841// nothing other than identifiers and member expressions. Parenthesized
1842// expressions are also correctly handled. This is generally appropriate for
1843// constructs for which the spec says
1844//
1845// > It is a Syntax Error if AssignmentTargetType of [the production] is not
1846// > simple.
1847//
1848// It is also appropriate for checking if an identifier is valid and not
1849// defined elsewhere, like import declarations or function/class identifiers.
1850//
1851// Examples where this is used include:
1852// a += …;
1853// import a from '…';
1854// where a is the node to be checked.
1855//
1856// - checkLValPattern() shall be used if the syntactic construct supports
1857// anything checkLValSimple() supports, as well as object and array
1858// destructuring patterns. This is generally appropriate for constructs for
1859// which the spec says
1860//
1861// > It is a Syntax Error if [the production] is neither an ObjectLiteral nor
1862// > an ArrayLiteral and AssignmentTargetType of [the production] is not
1863// > simple.
1864//
1865// Examples where this is used include:
1866// (a = …);
1867// const a = …;
1868// try { … } catch (a) { … }
1869// where a is the node to be checked.
1870//
1871// - checkLValInnerPattern() shall be used if the syntactic construct supports
1872// anything checkLValPattern() supports, as well as default assignment
1873// patterns, rest elements, and other constructs that may appear within an
1874// object or array destructuring pattern.
1875//
1876// As a special case, function parameters also use checkLValInnerPattern(),
1877// as they also support defaults and rest constructs.
1878//
1879// These functions deliberately support both assignment and binding constructs,
1880// as the logic for both is exceedingly similar. If the node is the target of
1881// an assignment, then bindingType should be set to BIND_NONE. Otherwise, it
1882// should be set to the appropriate BIND_* constant, like BIND_VAR or
1883// BIND_LEXICAL.
1884//
1885// If the function is called with a non-BIND_NONE bindingType, then
1886// additionally a checkClashes object may be specified to allow checking for
1887// duplicate argument names. checkClashes is ignored if the provided construct
1888// is an assignment (i.e., bindingType is BIND_NONE).
1889
1890pp$2.checkLValSimple = function(expr, bindingType, checkClashes) {
1891 if ( bindingType === void 0 ) bindingType = BIND_NONE;
1892
1893 var isBind = bindingType !== BIND_NONE;
1894
1895 switch (expr.type) {
1896 case "Identifier":
1897 if (this.strict && this.reservedWordsStrictBind.test(expr.name))
1898 { this.raiseRecoverable(expr.start, (isBind ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
1899 if (isBind) {
1900 if (bindingType === BIND_LEXICAL && expr.name === "let")
1901 { this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); }
1902 if (checkClashes) {
1903 if (has$3(checkClashes, expr.name))
1904 { this.raiseRecoverable(expr.start, "Argument name clash"); }
1905 checkClashes[expr.name] = true;
1906 }
1907 if (bindingType !== BIND_OUTSIDE) { this.declareName(expr.name, bindingType, expr.start); }
1908 }
1909 break
1910
1911 case "ChainExpression":
1912 this.raiseRecoverable(expr.start, "Optional chaining cannot appear in left-hand side");
1913 break
1914
1915 case "MemberExpression":
1916 if (isBind) { this.raiseRecoverable(expr.start, "Binding member expression"); }
1917 break
1918
1919 case "ParenthesizedExpression":
1920 if (isBind) { this.raiseRecoverable(expr.start, "Binding parenthesized expression"); }
1921 return this.checkLValSimple(expr.expression, bindingType, checkClashes)
1922
1923 default:
1924 this.raise(expr.start, (isBind ? "Binding" : "Assigning to") + " rvalue");
1925 }
1926};
1927
1928pp$2.checkLValPattern = function(expr, bindingType, checkClashes) {
1929 if ( bindingType === void 0 ) bindingType = BIND_NONE;
1930
1931 switch (expr.type) {
1932 case "ObjectPattern":
1933 for (var i = 0, list = expr.properties; i < list.length; i += 1) {
1934 var prop = list[i];
1935
1936 this.checkLValInnerPattern(prop, bindingType, checkClashes);
1937 }
1938 break
1939
1940 case "ArrayPattern":
1941 for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
1942 var elem = list$1[i$1];
1943
1944 if (elem) { this.checkLValInnerPattern(elem, bindingType, checkClashes); }
1945 }
1946 break
1947
1948 default:
1949 this.checkLValSimple(expr, bindingType, checkClashes);
1950 }
1951};
1952
1953pp$2.checkLValInnerPattern = function(expr, bindingType, checkClashes) {
1954 if ( bindingType === void 0 ) bindingType = BIND_NONE;
1955
1956 switch (expr.type) {
1957 case "Property":
1958 // AssignmentProperty has type === "Property"
1959 this.checkLValInnerPattern(expr.value, bindingType, checkClashes);
1960 break
1961
1962 case "AssignmentPattern":
1963 this.checkLValPattern(expr.left, bindingType, checkClashes);
1964 break
1965
1966 case "RestElement":
1967 this.checkLValPattern(expr.argument, bindingType, checkClashes);
1968 break
1969
1970 default:
1971 this.checkLValPattern(expr, bindingType, checkClashes);
1972 }
1973};
1974
1975// A recursive descent parser operates by defining functions for all
1976
1977var pp$3 = Parser.prototype;
1978
1979// Check if property name clashes with already added.
1980// Object/class getters and setters are not allowed to clash —
1981// either with each other or with an init property — and in
1982// strict mode, init properties are also not allowed to be repeated.
1983
1984pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
1985 if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
1986 { return }
1987 if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
1988 { return }
1989 var key = prop.key;
1990 var name;
1991 switch (key.type) {
1992 case "Identifier": name = key.name; break
1993 case "Literal": name = String(key.value); break
1994 default: return
1995 }
1996 var kind = prop.kind;
1997 if (this.options.ecmaVersion >= 6) {
1998 if (name === "__proto__" && kind === "init") {
1999 if (propHash.proto) {
2000 if (refDestructuringErrors) {
2001 if (refDestructuringErrors.doubleProto < 0)
2002 { refDestructuringErrors.doubleProto = key.start; }
2003 // Backwards-compat kludge. Can be removed in version 6.0
2004 } else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
2005 }
2006 propHash.proto = true;
2007 }
2008 return
2009 }
2010 name = "$" + name;
2011 var other = propHash[name];
2012 if (other) {
2013 var redefinition;
2014 if (kind === "init") {
2015 redefinition = this.strict && other.init || other.get || other.set;
2016 } else {
2017 redefinition = other.init || other[kind];
2018 }
2019 if (redefinition)
2020 { this.raiseRecoverable(key.start, "Redefinition of property"); }
2021 } else {
2022 other = propHash[name] = {
2023 init: false,
2024 get: false,
2025 set: false
2026 };
2027 }
2028 other[kind] = true;
2029};
2030
2031// ### Expression parsing
2032
2033// These nest, from the most general expression type at the top to
2034// 'atomic', nondivisible expression types at the bottom. Most of
2035// the functions will simply let the function(s) below them parse,
2036// and, *if* the syntactic construct they handle is present, wrap
2037// the AST node that the inner parser gave them in another node.
2038
2039// Parse a full expression. The optional arguments are used to
2040// forbid the `in` operator (in for loops initalization expressions)
2041// and provide reference for storing '=' operator inside shorthand
2042// property assignment in contexts where both object expression
2043// and object pattern might appear (so it's possible to raise
2044// delayed syntax error at correct position).
2045
2046pp$3.parseExpression = function(noIn, refDestructuringErrors) {
2047 var startPos = this.start, startLoc = this.startLoc;
2048 var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
2049 if (this.type === types.comma) {
2050 var node = this.startNodeAt(startPos, startLoc);
2051 node.expressions = [expr];
2052 while (this.eat(types.comma)) { node.expressions.push(this.parseMaybeAssign(noIn, refDestructuringErrors)); }
2053 return this.finishNode(node, "SequenceExpression")
2054 }
2055 return expr
2056};
2057
2058// Parse an assignment expression. This includes applications of
2059// operators like `+=`.
2060
2061pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
2062 if (this.isContextual("yield")) {
2063 if (this.inGenerator) { return this.parseYield(noIn) }
2064 // The tokenizer will assume an expression is allowed after
2065 // `yield`, but this isn't that kind of yield
2066 else { this.exprAllowed = false; }
2067 }
2068
2069 var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
2070 if (refDestructuringErrors) {
2071 oldParenAssign = refDestructuringErrors.parenthesizedAssign;
2072 oldTrailingComma = refDestructuringErrors.trailingComma;
2073 refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
2074 } else {
2075 refDestructuringErrors = new DestructuringErrors;
2076 ownDestructuringErrors = true;
2077 }
2078
2079 var startPos = this.start, startLoc = this.startLoc;
2080 if (this.type === types.parenL || this.type === types.name)
2081 { this.potentialArrowAt = this.start; }
2082 var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
2083 if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
2084 if (this.type.isAssign) {
2085 var node = this.startNodeAt(startPos, startLoc);
2086 node.operator = this.value;
2087 if (this.type === types.eq)
2088 { left = this.toAssignable(left, false, refDestructuringErrors); }
2089 if (!ownDestructuringErrors) {
2090 refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1;
2091 }
2092 if (refDestructuringErrors.shorthandAssign >= left.start)
2093 { refDestructuringErrors.shorthandAssign = -1; } // reset because shorthand default was used correctly
2094 if (this.type === types.eq)
2095 { this.checkLValPattern(left); }
2096 else
2097 { this.checkLValSimple(left); }
2098 node.left = left;
2099 this.next();
2100 node.right = this.parseMaybeAssign(noIn);
2101 return this.finishNode(node, "AssignmentExpression")
2102 } else {
2103 if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
2104 }
2105 if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
2106 if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
2107 return left
2108};
2109
2110// Parse a ternary conditional (`?:`) operator.
2111
2112pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
2113 var startPos = this.start, startLoc = this.startLoc;
2114 var expr = this.parseExprOps(noIn, refDestructuringErrors);
2115 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
2116 if (this.eat(types.question)) {
2117 var node = this.startNodeAt(startPos, startLoc);
2118 node.test = expr;
2119 node.consequent = this.parseMaybeAssign();
2120 this.expect(types.colon);
2121 node.alternate = this.parseMaybeAssign(noIn);
2122 return this.finishNode(node, "ConditionalExpression")
2123 }
2124 return expr
2125};
2126
2127// Start the precedence parser.
2128
2129pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
2130 var startPos = this.start, startLoc = this.startLoc;
2131 var expr = this.parseMaybeUnary(refDestructuringErrors, false);
2132 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
2133 return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
2134};
2135
2136// Parse binary operators with the operator precedence parsing
2137// algorithm. `left` is the left-hand side of the operator.
2138// `minPrec` provides context that allows the function to stop and
2139// defer further parser to one of its callers when it encounters an
2140// operator that has a lower precedence than the set it is parsing.
2141
2142pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
2143 var prec = this.type.binop;
2144 if (prec != null && (!noIn || this.type !== types._in)) {
2145 if (prec > minPrec) {
2146 var logical = this.type === types.logicalOR || this.type === types.logicalAND;
2147 var coalesce = this.type === types.coalesce;
2148 if (coalesce) {
2149 // Handle the precedence of `tt.coalesce` as equal to the range of logical expressions.
2150 // In other words, `node.right` shouldn't contain logical expressions in order to check the mixed error.
2151 prec = types.logicalAND.binop;
2152 }
2153 var op = this.value;
2154 this.next();
2155 var startPos = this.start, startLoc = this.startLoc;
2156 var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
2157 var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce);
2158 if ((logical && this.type === types.coalesce) || (coalesce && (this.type === types.logicalOR || this.type === types.logicalAND))) {
2159 this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses");
2160 }
2161 return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
2162 }
2163 }
2164 return left
2165};
2166
2167pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
2168 var node = this.startNodeAt(startPos, startLoc);
2169 node.left = left;
2170 node.operator = op;
2171 node.right = right;
2172 return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
2173};
2174
2175// Parse unary operators, both prefix and postfix.
2176
2177pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
2178 var startPos = this.start, startLoc = this.startLoc, expr;
2179 if (this.isContextual("await") && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction))) {
2180 expr = this.parseAwait();
2181 sawUnary = true;
2182 } else if (this.type.prefix) {
2183 var node = this.startNode(), update = this.type === types.incDec;
2184 node.operator = this.value;
2185 node.prefix = true;
2186 this.next();
2187 node.argument = this.parseMaybeUnary(null, true);
2188 this.checkExpressionErrors(refDestructuringErrors, true);
2189 if (update) { this.checkLValSimple(node.argument); }
2190 else if (this.strict && node.operator === "delete" &&
2191 node.argument.type === "Identifier")
2192 { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
2193 else { sawUnary = true; }
2194 expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
2195 } else {
2196 expr = this.parseExprSubscripts(refDestructuringErrors);
2197 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
2198 while (this.type.postfix && !this.canInsertSemicolon()) {
2199 var node$1 = this.startNodeAt(startPos, startLoc);
2200 node$1.operator = this.value;
2201 node$1.prefix = false;
2202 node$1.argument = expr;
2203 this.checkLValSimple(expr);
2204 this.next();
2205 expr = this.finishNode(node$1, "UpdateExpression");
2206 }
2207 }
2208
2209 if (!sawUnary && this.eat(types.starstar))
2210 { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
2211 else
2212 { return expr }
2213};
2214
2215// Parse call, dot, and `[]`-subscript expressions.
2216
2217pp$3.parseExprSubscripts = function(refDestructuringErrors) {
2218 var startPos = this.start, startLoc = this.startLoc;
2219 var expr = this.parseExprAtom(refDestructuringErrors);
2220 if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")")
2221 { return expr }
2222 var result = this.parseSubscripts(expr, startPos, startLoc);
2223 if (refDestructuringErrors && result.type === "MemberExpression") {
2224 if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
2225 if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
2226 if (refDestructuringErrors.trailingComma >= result.start) { refDestructuringErrors.trailingComma = -1; }
2227 }
2228 return result
2229};
2230
2231pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
2232 var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
2233 this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 &&
2234 this.potentialArrowAt === base.start;
2235 var optionalChained = false;
2236
2237 while (true) {
2238 var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained);
2239
2240 if (element.optional) { optionalChained = true; }
2241 if (element === base || element.type === "ArrowFunctionExpression") {
2242 if (optionalChained) {
2243 var chainNode = this.startNodeAt(startPos, startLoc);
2244 chainNode.expression = element;
2245 element = this.finishNode(chainNode, "ChainExpression");
2246 }
2247 return element
2248 }
2249
2250 base = element;
2251 }
2252};
2253
2254pp$3.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained) {
2255 var optionalSupported = this.options.ecmaVersion >= 11;
2256 var optional = optionalSupported && this.eat(types.questionDot);
2257 if (noCalls && optional) { this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); }
2258
2259 var computed = this.eat(types.bracketL);
2260 if (computed || (optional && this.type !== types.parenL && this.type !== types.backQuote) || this.eat(types.dot)) {
2261 var node = this.startNodeAt(startPos, startLoc);
2262 node.object = base;
2263 node.property = computed ? this.parseExpression() : this.parseIdent(this.options.allowReserved !== "never");
2264 node.computed = !!computed;
2265 if (computed) { this.expect(types.bracketR); }
2266 if (optionalSupported) {
2267 node.optional = optional;
2268 }
2269 base = this.finishNode(node, "MemberExpression");
2270 } else if (!noCalls && this.eat(types.parenL)) {
2271 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
2272 this.yieldPos = 0;
2273 this.awaitPos = 0;
2274 this.awaitIdentPos = 0;
2275 var exprList = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors);
2276 if (maybeAsyncArrow && !optional && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2277 this.checkPatternErrors(refDestructuringErrors, false);
2278 this.checkYieldAwaitInDefaultParams();
2279 if (this.awaitIdentPos > 0)
2280 { this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); }
2281 this.yieldPos = oldYieldPos;
2282 this.awaitPos = oldAwaitPos;
2283 this.awaitIdentPos = oldAwaitIdentPos;
2284 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true)
2285 }
2286 this.checkExpressionErrors(refDestructuringErrors, true);
2287 this.yieldPos = oldYieldPos || this.yieldPos;
2288 this.awaitPos = oldAwaitPos || this.awaitPos;
2289 this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos;
2290 var node$1 = this.startNodeAt(startPos, startLoc);
2291 node$1.callee = base;
2292 node$1.arguments = exprList;
2293 if (optionalSupported) {
2294 node$1.optional = optional;
2295 }
2296 base = this.finishNode(node$1, "CallExpression");
2297 } else if (this.type === types.backQuote) {
2298 if (optional || optionalChained) {
2299 this.raise(this.start, "Optional chaining cannot appear in the tag of tagged template expressions");
2300 }
2301 var node$2 = this.startNodeAt(startPos, startLoc);
2302 node$2.tag = base;
2303 node$2.quasi = this.parseTemplate({isTagged: true});
2304 base = this.finishNode(node$2, "TaggedTemplateExpression");
2305 }
2306 return base
2307};
2308
2309// Parse an atomic expression — either a single token that is an
2310// expression, an expression started by a keyword like `function` or
2311// `new`, or an expression wrapped in punctuation like `()`, `[]`,
2312// or `{}`.
2313
2314pp$3.parseExprAtom = function(refDestructuringErrors) {
2315 // If a division operator appears in an expression position, the
2316 // tokenizer got confused, and we force it to read a regexp instead.
2317 if (this.type === types.slash) { this.readRegexp(); }
2318
2319 var node, canBeArrow = this.potentialArrowAt === this.start;
2320 switch (this.type) {
2321 case types._super:
2322 if (!this.allowSuper)
2323 { this.raise(this.start, "'super' keyword outside a method"); }
2324 node = this.startNode();
2325 this.next();
2326 if (this.type === types.parenL && !this.allowDirectSuper)
2327 { this.raise(node.start, "super() call outside constructor of a subclass"); }
2328 // The `super` keyword can appear at below:
2329 // SuperProperty:
2330 // super [ Expression ]
2331 // super . IdentifierName
2332 // SuperCall:
2333 // super ( Arguments )
2334 if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
2335 { this.unexpected(); }
2336 return this.finishNode(node, "Super")
2337
2338 case types._this:
2339 node = this.startNode();
2340 this.next();
2341 return this.finishNode(node, "ThisExpression")
2342
2343 case types.name:
2344 var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
2345 var id = this.parseIdent(false);
2346 if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
2347 { return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true) }
2348 if (canBeArrow && !this.canInsertSemicolon()) {
2349 if (this.eat(types.arrow))
2350 { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
2351 if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
2352 id = this.parseIdent(false);
2353 if (this.canInsertSemicolon() || !this.eat(types.arrow))
2354 { this.unexpected(); }
2355 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
2356 }
2357 }
2358 return id
2359
2360 case types.regexp:
2361 var value = this.value;
2362 node = this.parseLiteral(value.value);
2363 node.regex = {pattern: value.pattern, flags: value.flags};
2364 return node
2365
2366 case types.num: case types.string:
2367 return this.parseLiteral(this.value)
2368
2369 case types._null: case types._true: case types._false:
2370 node = this.startNode();
2371 node.value = this.type === types._null ? null : this.type === types._true;
2372 node.raw = this.type.keyword;
2373 this.next();
2374 return this.finishNode(node, "Literal")
2375
2376 case types.parenL:
2377 var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
2378 if (refDestructuringErrors) {
2379 if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
2380 { refDestructuringErrors.parenthesizedAssign = start; }
2381 if (refDestructuringErrors.parenthesizedBind < 0)
2382 { refDestructuringErrors.parenthesizedBind = start; }
2383 }
2384 return expr
2385
2386 case types.bracketL:
2387 node = this.startNode();
2388 this.next();
2389 node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
2390 return this.finishNode(node, "ArrayExpression")
2391
2392 case types.braceL:
2393 return this.parseObj(false, refDestructuringErrors)
2394
2395 case types._function:
2396 node = this.startNode();
2397 this.next();
2398 return this.parseFunction(node, 0)
2399
2400 case types._class:
2401 return this.parseClass(this.startNode(), false)
2402
2403 case types._new:
2404 return this.parseNew()
2405
2406 case types.backQuote:
2407 return this.parseTemplate()
2408
2409 case types._import:
2410 if (this.options.ecmaVersion >= 11) {
2411 return this.parseExprImport()
2412 } else {
2413 return this.unexpected()
2414 }
2415
2416 default:
2417 this.unexpected();
2418 }
2419};
2420
2421pp$3.parseExprImport = function() {
2422 var node = this.startNode();
2423
2424 // Consume `import` as an identifier for `import.meta`.
2425 // Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`.
2426 if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword import"); }
2427 var meta = this.parseIdent(true);
2428
2429 switch (this.type) {
2430 case types.parenL:
2431 return this.parseDynamicImport(node)
2432 case types.dot:
2433 node.meta = meta;
2434 return this.parseImportMeta(node)
2435 default:
2436 this.unexpected();
2437 }
2438};
2439
2440pp$3.parseDynamicImport = function(node) {
2441 this.next(); // skip `(`
2442
2443 // Parse node.source.
2444 node.source = this.parseMaybeAssign();
2445
2446 // Verify ending.
2447 if (!this.eat(types.parenR)) {
2448 var errorPos = this.start;
2449 if (this.eat(types.comma) && this.eat(types.parenR)) {
2450 this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()");
2451 } else {
2452 this.unexpected(errorPos);
2453 }
2454 }
2455
2456 return this.finishNode(node, "ImportExpression")
2457};
2458
2459pp$3.parseImportMeta = function(node) {
2460 this.next(); // skip `.`
2461
2462 var containsEsc = this.containsEsc;
2463 node.property = this.parseIdent(true);
2464
2465 if (node.property.name !== "meta")
2466 { this.raiseRecoverable(node.property.start, "The only valid meta property for import is 'import.meta'"); }
2467 if (containsEsc)
2468 { this.raiseRecoverable(node.start, "'import.meta' must not contain escaped characters"); }
2469 if (this.options.sourceType !== "module" && !this.options.allowImportExportEverywhere)
2470 { this.raiseRecoverable(node.start, "Cannot use 'import.meta' outside a module"); }
2471
2472 return this.finishNode(node, "MetaProperty")
2473};
2474
2475pp$3.parseLiteral = function(value) {
2476 var node = this.startNode();
2477 node.value = value;
2478 node.raw = this.input.slice(this.start, this.end);
2479 if (node.raw.charCodeAt(node.raw.length - 1) === 110) { node.bigint = node.raw.slice(0, -1).replace(/_/g, ""); }
2480 this.next();
2481 return this.finishNode(node, "Literal")
2482};
2483
2484pp$3.parseParenExpression = function() {
2485 this.expect(types.parenL);
2486 var val = this.parseExpression();
2487 this.expect(types.parenR);
2488 return val
2489};
2490
2491pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
2492 var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
2493 if (this.options.ecmaVersion >= 6) {
2494 this.next();
2495
2496 var innerStartPos = this.start, innerStartLoc = this.startLoc;
2497 var exprList = [], first = true, lastIsComma = false;
2498 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
2499 this.yieldPos = 0;
2500 this.awaitPos = 0;
2501 // Do not save awaitIdentPos to allow checking awaits nested in parameters
2502 while (this.type !== types.parenR) {
2503 first ? first = false : this.expect(types.comma);
2504 if (allowTrailingComma && this.afterTrailingComma(types.parenR, true)) {
2505 lastIsComma = true;
2506 break
2507 } else if (this.type === types.ellipsis) {
2508 spreadStart = this.start;
2509 exprList.push(this.parseParenItem(this.parseRestBinding()));
2510 if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
2511 break
2512 } else {
2513 exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
2514 }
2515 }
2516 var innerEndPos = this.start, innerEndLoc = this.startLoc;
2517 this.expect(types.parenR);
2518
2519 if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2520 this.checkPatternErrors(refDestructuringErrors, false);
2521 this.checkYieldAwaitInDefaultParams();
2522 this.yieldPos = oldYieldPos;
2523 this.awaitPos = oldAwaitPos;
2524 return this.parseParenArrowList(startPos, startLoc, exprList)
2525 }
2526
2527 if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
2528 if (spreadStart) { this.unexpected(spreadStart); }
2529 this.checkExpressionErrors(refDestructuringErrors, true);
2530 this.yieldPos = oldYieldPos || this.yieldPos;
2531 this.awaitPos = oldAwaitPos || this.awaitPos;
2532
2533 if (exprList.length > 1) {
2534 val = this.startNodeAt(innerStartPos, innerStartLoc);
2535 val.expressions = exprList;
2536 this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
2537 } else {
2538 val = exprList[0];
2539 }
2540 } else {
2541 val = this.parseParenExpression();
2542 }
2543
2544 if (this.options.preserveParens) {
2545 var par = this.startNodeAt(startPos, startLoc);
2546 par.expression = val;
2547 return this.finishNode(par, "ParenthesizedExpression")
2548 } else {
2549 return val
2550 }
2551};
2552
2553pp$3.parseParenItem = function(item) {
2554 return item
2555};
2556
2557pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
2558 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
2559};
2560
2561// New's precedence is slightly tricky. It must allow its argument to
2562// be a `[]` or dot subscript expression, but not a call — at least,
2563// not without wrapping it in parentheses. Thus, it uses the noCalls
2564// argument to parseSubscripts to prevent it from consuming the
2565// argument list.
2566
2567var empty$1 = [];
2568
2569pp$3.parseNew = function() {
2570 if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword new"); }
2571 var node = this.startNode();
2572 var meta = this.parseIdent(true);
2573 if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
2574 node.meta = meta;
2575 var containsEsc = this.containsEsc;
2576 node.property = this.parseIdent(true);
2577 if (node.property.name !== "target")
2578 { this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'"); }
2579 if (containsEsc)
2580 { this.raiseRecoverable(node.start, "'new.target' must not contain escaped characters"); }
2581 if (!this.inNonArrowFunction)
2582 { this.raiseRecoverable(node.start, "'new.target' can only be used in functions"); }
2583 return this.finishNode(node, "MetaProperty")
2584 }
2585 var startPos = this.start, startLoc = this.startLoc, isImport = this.type === types._import;
2586 node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
2587 if (isImport && node.callee.type === "ImportExpression") {
2588 this.raise(startPos, "Cannot use new with import()");
2589 }
2590 if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
2591 else { node.arguments = empty$1; }
2592 return this.finishNode(node, "NewExpression")
2593};
2594
2595// Parse template expression.
2596
2597pp$3.parseTemplateElement = function(ref) {
2598 var isTagged = ref.isTagged;
2599
2600 var elem = this.startNode();
2601 if (this.type === types.invalidTemplate) {
2602 if (!isTagged) {
2603 this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
2604 }
2605 elem.value = {
2606 raw: this.value,
2607 cooked: null
2608 };
2609 } else {
2610 elem.value = {
2611 raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
2612 cooked: this.value
2613 };
2614 }
2615 this.next();
2616 elem.tail = this.type === types.backQuote;
2617 return this.finishNode(elem, "TemplateElement")
2618};
2619
2620pp$3.parseTemplate = function(ref) {
2621 if ( ref === void 0 ) ref = {};
2622 var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
2623
2624 var node = this.startNode();
2625 this.next();
2626 node.expressions = [];
2627 var curElt = this.parseTemplateElement({isTagged: isTagged});
2628 node.quasis = [curElt];
2629 while (!curElt.tail) {
2630 if (this.type === types.eof) { this.raise(this.pos, "Unterminated template literal"); }
2631 this.expect(types.dollarBraceL);
2632 node.expressions.push(this.parseExpression());
2633 this.expect(types.braceR);
2634 node.quasis.push(curElt = this.parseTemplateElement({isTagged: isTagged}));
2635 }
2636 this.next();
2637 return this.finishNode(node, "TemplateLiteral")
2638};
2639
2640pp$3.isAsyncProp = function(prop) {
2641 return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
2642 (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)) &&
2643 !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
2644};
2645
2646// Parse an object literal or binding pattern.
2647
2648pp$3.parseObj = function(isPattern, refDestructuringErrors) {
2649 var node = this.startNode(), first = true, propHash = {};
2650 node.properties = [];
2651 this.next();
2652 while (!this.eat(types.braceR)) {
2653 if (!first) {
2654 this.expect(types.comma);
2655 if (this.options.ecmaVersion >= 5 && this.afterTrailingComma(types.braceR)) { break }
2656 } else { first = false; }
2657
2658 var prop = this.parseProperty(isPattern, refDestructuringErrors);
2659 if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
2660 node.properties.push(prop);
2661 }
2662 return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
2663};
2664
2665pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
2666 var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
2667 if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
2668 if (isPattern) {
2669 prop.argument = this.parseIdent(false);
2670 if (this.type === types.comma) {
2671 this.raise(this.start, "Comma is not permitted after the rest element");
2672 }
2673 return this.finishNode(prop, "RestElement")
2674 }
2675 // To disallow parenthesized identifier via `this.toAssignable()`.
2676 if (this.type === types.parenL && refDestructuringErrors) {
2677 if (refDestructuringErrors.parenthesizedAssign < 0) {
2678 refDestructuringErrors.parenthesizedAssign = this.start;
2679 }
2680 if (refDestructuringErrors.parenthesizedBind < 0) {
2681 refDestructuringErrors.parenthesizedBind = this.start;
2682 }
2683 }
2684 // Parse argument.
2685 prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
2686 // To disallow trailing comma via `this.toAssignable()`.
2687 if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
2688 refDestructuringErrors.trailingComma = this.start;
2689 }
2690 // Finish
2691 return this.finishNode(prop, "SpreadElement")
2692 }
2693 if (this.options.ecmaVersion >= 6) {
2694 prop.method = false;
2695 prop.shorthand = false;
2696 if (isPattern || refDestructuringErrors) {
2697 startPos = this.start;
2698 startLoc = this.startLoc;
2699 }
2700 if (!isPattern)
2701 { isGenerator = this.eat(types.star); }
2702 }
2703 var containsEsc = this.containsEsc;
2704 this.parsePropertyName(prop);
2705 if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
2706 isAsync = true;
2707 isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
2708 this.parsePropertyName(prop, refDestructuringErrors);
2709 } else {
2710 isAsync = false;
2711 }
2712 this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
2713 return this.finishNode(prop, "Property")
2714};
2715
2716pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
2717 if ((isGenerator || isAsync) && this.type === types.colon)
2718 { this.unexpected(); }
2719
2720 if (this.eat(types.colon)) {
2721 prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
2722 prop.kind = "init";
2723 } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
2724 if (isPattern) { this.unexpected(); }
2725 prop.kind = "init";
2726 prop.method = true;
2727 prop.value = this.parseMethod(isGenerator, isAsync);
2728 } else if (!isPattern && !containsEsc &&
2729 this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
2730 (prop.key.name === "get" || prop.key.name === "set") &&
2731 (this.type !== types.comma && this.type !== types.braceR && this.type !== types.eq)) {
2732 if (isGenerator || isAsync) { this.unexpected(); }
2733 prop.kind = prop.key.name;
2734 this.parsePropertyName(prop);
2735 prop.value = this.parseMethod(false);
2736 var paramCount = prop.kind === "get" ? 0 : 1;
2737 if (prop.value.params.length !== paramCount) {
2738 var start = prop.value.start;
2739 if (prop.kind === "get")
2740 { this.raiseRecoverable(start, "getter should have no params"); }
2741 else
2742 { this.raiseRecoverable(start, "setter should have exactly one param"); }
2743 } else {
2744 if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
2745 { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
2746 }
2747 } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
2748 if (isGenerator || isAsync) { this.unexpected(); }
2749 this.checkUnreserved(prop.key);
2750 if (prop.key.name === "await" && !this.awaitIdentPos)
2751 { this.awaitIdentPos = startPos; }
2752 prop.kind = "init";
2753 if (isPattern) {
2754 prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
2755 } else if (this.type === types.eq && refDestructuringErrors) {
2756 if (refDestructuringErrors.shorthandAssign < 0)
2757 { refDestructuringErrors.shorthandAssign = this.start; }
2758 prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
2759 } else {
2760 prop.value = this.copyNode(prop.key);
2761 }
2762 prop.shorthand = true;
2763 } else { this.unexpected(); }
2764};
2765
2766pp$3.parsePropertyName = function(prop) {
2767 if (this.options.ecmaVersion >= 6) {
2768 if (this.eat(types.bracketL)) {
2769 prop.computed = true;
2770 prop.key = this.parseMaybeAssign();
2771 this.expect(types.bracketR);
2772 return prop.key
2773 } else {
2774 prop.computed = false;
2775 }
2776 }
2777 return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
2778};
2779
2780// Initialize empty function node.
2781
2782pp$3.initFunction = function(node) {
2783 node.id = null;
2784 if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
2785 if (this.options.ecmaVersion >= 8) { node.async = false; }
2786};
2787
2788// Parse object or class method.
2789
2790pp$3.parseMethod = function(isGenerator, isAsync, allowDirectSuper) {
2791 var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
2792
2793 this.initFunction(node);
2794 if (this.options.ecmaVersion >= 6)
2795 { node.generator = isGenerator; }
2796 if (this.options.ecmaVersion >= 8)
2797 { node.async = !!isAsync; }
2798
2799 this.yieldPos = 0;
2800 this.awaitPos = 0;
2801 this.awaitIdentPos = 0;
2802 this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
2803
2804 this.expect(types.parenL);
2805 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
2806 this.checkYieldAwaitInDefaultParams();
2807 this.parseFunctionBody(node, false, true);
2808
2809 this.yieldPos = oldYieldPos;
2810 this.awaitPos = oldAwaitPos;
2811 this.awaitIdentPos = oldAwaitIdentPos;
2812 return this.finishNode(node, "FunctionExpression")
2813};
2814
2815// Parse arrow function expression with given parameters.
2816
2817pp$3.parseArrowExpression = function(node, params, isAsync) {
2818 var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
2819
2820 this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
2821 this.initFunction(node);
2822 if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
2823
2824 this.yieldPos = 0;
2825 this.awaitPos = 0;
2826 this.awaitIdentPos = 0;
2827
2828 node.params = this.toAssignableList(params, true);
2829 this.parseFunctionBody(node, true, false);
2830
2831 this.yieldPos = oldYieldPos;
2832 this.awaitPos = oldAwaitPos;
2833 this.awaitIdentPos = oldAwaitIdentPos;
2834 return this.finishNode(node, "ArrowFunctionExpression")
2835};
2836
2837// Parse function body and check parameters.
2838
2839pp$3.parseFunctionBody = function(node, isArrowFunction, isMethod) {
2840 var isExpression = isArrowFunction && this.type !== types.braceL;
2841 var oldStrict = this.strict, useStrict = false;
2842
2843 if (isExpression) {
2844 node.body = this.parseMaybeAssign();
2845 node.expression = true;
2846 this.checkParams(node, false);
2847 } else {
2848 var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
2849 if (!oldStrict || nonSimple) {
2850 useStrict = this.strictDirective(this.end);
2851 // If this is a strict mode function, verify that argument names
2852 // are not repeated, and it does not try to bind the words `eval`
2853 // or `arguments`.
2854 if (useStrict && nonSimple)
2855 { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
2856 }
2857 // Start a new scope with regard to labels and the `inFunction`
2858 // flag (restore them to their old value afterwards).
2859 var oldLabels = this.labels;
2860 this.labels = [];
2861 if (useStrict) { this.strict = true; }
2862
2863 // Add the params to varDeclaredNames to ensure that an error is thrown
2864 // if a let/const declaration in the function clashes with one of the params.
2865 this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params));
2866 // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
2867 if (this.strict && node.id) { this.checkLValSimple(node.id, BIND_OUTSIDE); }
2868 node.body = this.parseBlock(false, undefined, useStrict && !oldStrict);
2869 node.expression = false;
2870 this.adaptDirectivePrologue(node.body.body);
2871 this.labels = oldLabels;
2872 }
2873 this.exitScope();
2874};
2875
2876pp$3.isSimpleParamList = function(params) {
2877 for (var i = 0, list = params; i < list.length; i += 1)
2878 {
2879 var param = list[i];
2880
2881 if (param.type !== "Identifier") { return false
2882 } }
2883 return true
2884};
2885
2886// Checks function params for various disallowed patterns such as using "eval"
2887// or "arguments" and duplicate parameters.
2888
2889pp$3.checkParams = function(node, allowDuplicates) {
2890 var nameHash = Object.create(null);
2891 for (var i = 0, list = node.params; i < list.length; i += 1)
2892 {
2893 var param = list[i];
2894
2895 this.checkLValInnerPattern(param, BIND_VAR, allowDuplicates ? null : nameHash);
2896 }
2897};
2898
2899// Parses a comma-separated list of expressions, and returns them as
2900// an array. `close` is the token type that ends the list, and
2901// `allowEmpty` can be turned on to allow subsequent commas with
2902// nothing in between them to be parsed as `null` (which is needed
2903// for array literals).
2904
2905pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
2906 var elts = [], first = true;
2907 while (!this.eat(close)) {
2908 if (!first) {
2909 this.expect(types.comma);
2910 if (allowTrailingComma && this.afterTrailingComma(close)) { break }
2911 } else { first = false; }
2912
2913 var elt = (void 0);
2914 if (allowEmpty && this.type === types.comma)
2915 { elt = null; }
2916 else if (this.type === types.ellipsis) {
2917 elt = this.parseSpread(refDestructuringErrors);
2918 if (refDestructuringErrors && this.type === types.comma && refDestructuringErrors.trailingComma < 0)
2919 { refDestructuringErrors.trailingComma = this.start; }
2920 } else {
2921 elt = this.parseMaybeAssign(false, refDestructuringErrors);
2922 }
2923 elts.push(elt);
2924 }
2925 return elts
2926};
2927
2928pp$3.checkUnreserved = function(ref) {
2929 var start = ref.start;
2930 var end = ref.end;
2931 var name = ref.name;
2932
2933 if (this.inGenerator && name === "yield")
2934 { this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); }
2935 if (this.inAsync && name === "await")
2936 { this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); }
2937 if (this.keywords.test(name))
2938 { this.raise(start, ("Unexpected keyword '" + name + "'")); }
2939 if (this.options.ecmaVersion < 6 &&
2940 this.input.slice(start, end).indexOf("\\") !== -1) { return }
2941 var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
2942 if (re.test(name)) {
2943 if (!this.inAsync && name === "await")
2944 { this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); }
2945 this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
2946 }
2947};
2948
2949// Parse the next token as an identifier. If `liberal` is true (used
2950// when parsing properties), it will also convert keywords into
2951// identifiers.
2952
2953pp$3.parseIdent = function(liberal, isBinding) {
2954 var node = this.startNode();
2955 if (this.type === types.name) {
2956 node.name = this.value;
2957 } else if (this.type.keyword) {
2958 node.name = this.type.keyword;
2959
2960 // To fix https://github.com/acornjs/acorn/issues/575
2961 // `class` and `function` keywords push new context into this.context.
2962 // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
2963 // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
2964 if ((node.name === "class" || node.name === "function") &&
2965 (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
2966 this.context.pop();
2967 }
2968 } else {
2969 this.unexpected();
2970 }
2971 this.next(!!liberal);
2972 this.finishNode(node, "Identifier");
2973 if (!liberal) {
2974 this.checkUnreserved(node);
2975 if (node.name === "await" && !this.awaitIdentPos)
2976 { this.awaitIdentPos = node.start; }
2977 }
2978 return node
2979};
2980
2981// Parses yield expression inside generator.
2982
2983pp$3.parseYield = function(noIn) {
2984 if (!this.yieldPos) { this.yieldPos = this.start; }
2985
2986 var node = this.startNode();
2987 this.next();
2988 if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) {
2989 node.delegate = false;
2990 node.argument = null;
2991 } else {
2992 node.delegate = this.eat(types.star);
2993 node.argument = this.parseMaybeAssign(noIn);
2994 }
2995 return this.finishNode(node, "YieldExpression")
2996};
2997
2998pp$3.parseAwait = function() {
2999 if (!this.awaitPos) { this.awaitPos = this.start; }
3000
3001 var node = this.startNode();
3002 this.next();
3003 node.argument = this.parseMaybeUnary(null, true);
3004 return this.finishNode(node, "AwaitExpression")
3005};
3006
3007var pp$4 = Parser.prototype;
3008
3009// This function is used to raise exceptions on parse errors. It
3010// takes an offset integer (into the current `input`) to indicate
3011// the location of the error, attaches the position to the end
3012// of the error message, and then raises a `SyntaxError` with that
3013// message.
3014
3015pp$4.raise = function(pos, message) {
3016 var loc = getLineInfo(this.input, pos);
3017 message += " (" + loc.line + ":" + loc.column + ")";
3018 var err = new SyntaxError(message);
3019 err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
3020 throw err
3021};
3022
3023pp$4.raiseRecoverable = pp$4.raise;
3024
3025pp$4.curPosition = function() {
3026 if (this.options.locations) {
3027 return new Position(this.curLine, this.pos - this.lineStart)
3028 }
3029};
3030
3031var pp$5 = Parser.prototype;
3032
3033var Scope = function Scope(flags) {
3034 this.flags = flags;
3035 // A list of var-declared names in the current lexical scope
3036 this.var = [];
3037 // A list of lexically-declared names in the current lexical scope
3038 this.lexical = [];
3039 // A list of lexically-declared FunctionDeclaration names in the current lexical scope
3040 this.functions = [];
3041};
3042
3043// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
3044
3045pp$5.enterScope = function(flags) {
3046 this.scopeStack.push(new Scope(flags));
3047};
3048
3049pp$5.exitScope = function() {
3050 this.scopeStack.pop();
3051};
3052
3053// The spec says:
3054// > At the top level of a function, or script, function declarations are
3055// > treated like var declarations rather than like lexical declarations.
3056pp$5.treatFunctionsAsVarInScope = function(scope) {
3057 return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
3058};
3059
3060pp$5.declareName = function(name, bindingType, pos) {
3061 var redeclared = false;
3062 if (bindingType === BIND_LEXICAL) {
3063 var scope = this.currentScope();
3064 redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
3065 scope.lexical.push(name);
3066 if (this.inModule && (scope.flags & SCOPE_TOP))
3067 { delete this.undefinedExports[name]; }
3068 } else if (bindingType === BIND_SIMPLE_CATCH) {
3069 var scope$1 = this.currentScope();
3070 scope$1.lexical.push(name);
3071 } else if (bindingType === BIND_FUNCTION) {
3072 var scope$2 = this.currentScope();
3073 if (this.treatFunctionsAsVar)
3074 { redeclared = scope$2.lexical.indexOf(name) > -1; }
3075 else
3076 { redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
3077 scope$2.functions.push(name);
3078 } else {
3079 for (var i = this.scopeStack.length - 1; i >= 0; --i) {
3080 var scope$3 = this.scopeStack[i];
3081 if (scope$3.lexical.indexOf(name) > -1 && !((scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) ||
3082 !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
3083 redeclared = true;
3084 break
3085 }
3086 scope$3.var.push(name);
3087 if (this.inModule && (scope$3.flags & SCOPE_TOP))
3088 { delete this.undefinedExports[name]; }
3089 if (scope$3.flags & SCOPE_VAR) { break }
3090 }
3091 }
3092 if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); }
3093};
3094
3095pp$5.checkLocalExport = function(id) {
3096 // scope.functions must be empty as Module code is always strict.
3097 if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
3098 this.scopeStack[0].var.indexOf(id.name) === -1) {
3099 this.undefinedExports[id.name] = id;
3100 }
3101};
3102
3103pp$5.currentScope = function() {
3104 return this.scopeStack[this.scopeStack.length - 1]
3105};
3106
3107pp$5.currentVarScope = function() {
3108 for (var i = this.scopeStack.length - 1;; i--) {
3109 var scope = this.scopeStack[i];
3110 if (scope.flags & SCOPE_VAR) { return scope }
3111 }
3112};
3113
3114// Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
3115pp$5.currentThisScope = function() {
3116 for (var i = this.scopeStack.length - 1;; i--) {
3117 var scope = this.scopeStack[i];
3118 if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope }
3119 }
3120};
3121
3122var Node = function Node(parser, pos, loc) {
3123 this.type = "";
3124 this.start = pos;
3125 this.end = 0;
3126 if (parser.options.locations)
3127 { this.loc = new SourceLocation(parser, loc); }
3128 if (parser.options.directSourceFile)
3129 { this.sourceFile = parser.options.directSourceFile; }
3130 if (parser.options.ranges)
3131 { this.range = [pos, 0]; }
3132};
3133
3134// Start an AST node, attaching a start offset.
3135
3136var pp$6 = Parser.prototype;
3137
3138pp$6.startNode = function() {
3139 return new Node(this, this.start, this.startLoc)
3140};
3141
3142pp$6.startNodeAt = function(pos, loc) {
3143 return new Node(this, pos, loc)
3144};
3145
3146// Finish an AST node, adding `type` and `end` properties.
3147
3148function finishNodeAt(node, type, pos, loc) {
3149 node.type = type;
3150 node.end = pos;
3151 if (this.options.locations)
3152 { node.loc.end = loc; }
3153 if (this.options.ranges)
3154 { node.range[1] = pos; }
3155 return node
3156}
3157
3158pp$6.finishNode = function(node, type) {
3159 return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
3160};
3161
3162// Finish node at given position
3163
3164pp$6.finishNodeAt = function(node, type, pos, loc) {
3165 return finishNodeAt.call(this, node, type, pos, loc)
3166};
3167
3168pp$6.copyNode = function(node) {
3169 var newNode = new Node(this, node.start, this.startLoc);
3170 for (var prop in node) { newNode[prop] = node[prop]; }
3171 return newNode
3172};
3173
3174// The algorithm used to determine whether a regexp can appear at a
3175
3176var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
3177 this.token = token;
3178 this.isExpr = !!isExpr;
3179 this.preserveSpace = !!preserveSpace;
3180 this.override = override;
3181 this.generator = !!generator;
3182};
3183
3184var types$1 = {
3185 b_stat: new TokContext("{", false),
3186 b_expr: new TokContext("{", true),
3187 b_tmpl: new TokContext("${", false),
3188 p_stat: new TokContext("(", false),
3189 p_expr: new TokContext("(", true),
3190 q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
3191 f_stat: new TokContext("function", false),
3192 f_expr: new TokContext("function", true),
3193 f_expr_gen: new TokContext("function", true, false, null, true),
3194 f_gen: new TokContext("function", false, false, null, true)
3195};
3196
3197var pp$7 = Parser.prototype;
3198
3199pp$7.initialContext = function() {
3200 return [types$1.b_stat]
3201};
3202
3203pp$7.braceIsBlock = function(prevType) {
3204 var parent = this.curContext();
3205 if (parent === types$1.f_expr || parent === types$1.f_stat)
3206 { return true }
3207 if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
3208 { return !parent.isExpr }
3209
3210 // The check for `tt.name && exprAllowed` detects whether we are
3211 // after a `yield` or `of` construct. See the `updateContext` for
3212 // `tt.name`.
3213 if (prevType === types._return || prevType === types.name && this.exprAllowed)
3214 { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
3215 if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow)
3216 { return true }
3217 if (prevType === types.braceL)
3218 { return parent === types$1.b_stat }
3219 if (prevType === types._var || prevType === types._const || prevType === types.name)
3220 { return false }
3221 return !this.exprAllowed
3222};
3223
3224pp$7.inGeneratorContext = function() {
3225 for (var i = this.context.length - 1; i >= 1; i--) {
3226 var context = this.context[i];
3227 if (context.token === "function")
3228 { return context.generator }
3229 }
3230 return false
3231};
3232
3233pp$7.updateContext = function(prevType) {
3234 var update, type = this.type;
3235 if (type.keyword && prevType === types.dot)
3236 { this.exprAllowed = false; }
3237 else if (update = type.updateContext)
3238 { update.call(this, prevType); }
3239 else
3240 { this.exprAllowed = type.beforeExpr; }
3241};
3242
3243// Token-specific context update code
3244
3245types.parenR.updateContext = types.braceR.updateContext = function() {
3246 if (this.context.length === 1) {
3247 this.exprAllowed = true;
3248 return
3249 }
3250 var out = this.context.pop();
3251 if (out === types$1.b_stat && this.curContext().token === "function") {
3252 out = this.context.pop();
3253 }
3254 this.exprAllowed = !out.isExpr;
3255};
3256
3257types.braceL.updateContext = function(prevType) {
3258 this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
3259 this.exprAllowed = true;
3260};
3261
3262types.dollarBraceL.updateContext = function() {
3263 this.context.push(types$1.b_tmpl);
3264 this.exprAllowed = true;
3265};
3266
3267types.parenL.updateContext = function(prevType) {
3268 var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
3269 this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
3270 this.exprAllowed = true;
3271};
3272
3273types.incDec.updateContext = function() {
3274 // tokExprAllowed stays unchanged
3275};
3276
3277types._function.updateContext = types._class.updateContext = function(prevType) {
3278 if (prevType.beforeExpr && prevType !== types._else &&
3279 !(prevType === types.semi && this.curContext() !== types$1.p_stat) &&
3280 !(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
3281 !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
3282 { this.context.push(types$1.f_expr); }
3283 else
3284 { this.context.push(types$1.f_stat); }
3285 this.exprAllowed = false;
3286};
3287
3288types.backQuote.updateContext = function() {
3289 if (this.curContext() === types$1.q_tmpl)
3290 { this.context.pop(); }
3291 else
3292 { this.context.push(types$1.q_tmpl); }
3293 this.exprAllowed = false;
3294};
3295
3296types.star.updateContext = function(prevType) {
3297 if (prevType === types._function) {
3298 var index = this.context.length - 1;
3299 if (this.context[index] === types$1.f_expr)
3300 { this.context[index] = types$1.f_expr_gen; }
3301 else
3302 { this.context[index] = types$1.f_gen; }
3303 }
3304 this.exprAllowed = true;
3305};
3306
3307types.name.updateContext = function(prevType) {
3308 var allowed = false;
3309 if (this.options.ecmaVersion >= 6 && prevType !== types.dot) {
3310 if (this.value === "of" && !this.exprAllowed ||
3311 this.value === "yield" && this.inGeneratorContext())
3312 { allowed = true; }
3313 }
3314 this.exprAllowed = allowed;
3315};
3316
3317// This file contains Unicode properties extracted from the ECMAScript
3318// specification. The lists are extracted like so:
3319// $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText)
3320
3321// #table-binary-unicode-properties
3322var 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";
3323var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
3324var ecma11BinaryProperties = ecma10BinaryProperties;
3325var ecma12BinaryProperties = ecma11BinaryProperties + " EBase EComp EMod EPres ExtPict";
3326var unicodeBinaryProperties = {
3327 9: ecma9BinaryProperties,
3328 10: ecma10BinaryProperties,
3329 11: ecma11BinaryProperties,
3330 12: ecma12BinaryProperties
3331};
3332
3333// #table-unicode-general-category-values
3334var 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";
3335
3336// #table-unicode-script-values
3337var 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";
3338var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd";
3339var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
3340var ecma12ScriptValues = ecma11ScriptValues + " Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi";
3341var unicodeScriptValues = {
3342 9: ecma9ScriptValues,
3343 10: ecma10ScriptValues,
3344 11: ecma11ScriptValues,
3345 12: ecma12ScriptValues
3346};
3347
3348var data = {};
3349function buildUnicodeData(ecmaVersion) {
3350 var d = data[ecmaVersion] = {
3351 binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues),
3352 nonBinary: {
3353 General_Category: wordsRegexp(unicodeGeneralCategoryValues),
3354 Script: wordsRegexp(unicodeScriptValues[ecmaVersion])
3355 }
3356 };
3357 d.nonBinary.Script_Extensions = d.nonBinary.Script;
3358
3359 d.nonBinary.gc = d.nonBinary.General_Category;
3360 d.nonBinary.sc = d.nonBinary.Script;
3361 d.nonBinary.scx = d.nonBinary.Script_Extensions;
3362}
3363buildUnicodeData(9);
3364buildUnicodeData(10);
3365buildUnicodeData(11);
3366buildUnicodeData(12);
3367
3368var pp$8 = Parser.prototype;
3369
3370var RegExpValidationState = function RegExpValidationState(parser) {
3371 this.parser = parser;
3372 this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
3373 this.unicodeProperties = data[parser.options.ecmaVersion >= 12 ? 12 : parser.options.ecmaVersion];
3374 this.source = "";
3375 this.flags = "";
3376 this.start = 0;
3377 this.switchU = false;
3378 this.switchN = false;
3379 this.pos = 0;
3380 this.lastIntValue = 0;
3381 this.lastStringValue = "";
3382 this.lastAssertionIsQuantifiable = false;
3383 this.numCapturingParens = 0;
3384 this.maxBackReference = 0;
3385 this.groupNames = [];
3386 this.backReferenceNames = [];
3387};
3388
3389RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
3390 var unicode = flags.indexOf("u") !== -1;
3391 this.start = start | 0;
3392 this.source = pattern + "";
3393 this.flags = flags;
3394 this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
3395 this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
3396};
3397
3398RegExpValidationState.prototype.raise = function raise (message) {
3399 this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
3400};
3401
3402// If u flag is given, this returns the code point at the index (it combines a surrogate pair).
3403// Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
3404RegExpValidationState.prototype.at = function at (i, forceU) {
3405 if ( forceU === void 0 ) forceU = false;
3406
3407 var s = this.source;
3408 var l = s.length;
3409 if (i >= l) {
3410 return -1
3411 }
3412 var c = s.charCodeAt(i);
3413 if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
3414 return c
3415 }
3416 var next = s.charCodeAt(i + 1);
3417 return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c
3418};
3419
3420RegExpValidationState.prototype.nextIndex = function nextIndex (i, forceU) {
3421 if ( forceU === void 0 ) forceU = false;
3422
3423 var s = this.source;
3424 var l = s.length;
3425 if (i >= l) {
3426 return l
3427 }
3428 var c = s.charCodeAt(i), next;
3429 if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
3430 (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
3431 return i + 1
3432 }
3433 return i + 2
3434};
3435
3436RegExpValidationState.prototype.current = function current (forceU) {
3437 if ( forceU === void 0 ) forceU = false;
3438
3439 return this.at(this.pos, forceU)
3440};
3441
3442RegExpValidationState.prototype.lookahead = function lookahead (forceU) {
3443 if ( forceU === void 0 ) forceU = false;
3444
3445 return this.at(this.nextIndex(this.pos, forceU), forceU)
3446};
3447
3448RegExpValidationState.prototype.advance = function advance (forceU) {
3449 if ( forceU === void 0 ) forceU = false;
3450
3451 this.pos = this.nextIndex(this.pos, forceU);
3452};
3453
3454RegExpValidationState.prototype.eat = function eat (ch, forceU) {
3455 if ( forceU === void 0 ) forceU = false;
3456
3457 if (this.current(forceU) === ch) {
3458 this.advance(forceU);
3459 return true
3460 }
3461 return false
3462};
3463
3464function codePointToString(ch) {
3465 if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
3466 ch -= 0x10000;
3467 return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
3468}
3469
3470/**
3471 * Validate the flags part of a given RegExpLiteral.
3472 *
3473 * @param {RegExpValidationState} state The state to validate RegExp.
3474 * @returns {void}
3475 */
3476pp$8.validateRegExpFlags = function(state) {
3477 var validFlags = state.validFlags;
3478 var flags = state.flags;
3479
3480 for (var i = 0; i < flags.length; i++) {
3481 var flag = flags.charAt(i);
3482 if (validFlags.indexOf(flag) === -1) {
3483 this.raise(state.start, "Invalid regular expression flag");
3484 }
3485 if (flags.indexOf(flag, i + 1) > -1) {
3486 this.raise(state.start, "Duplicate regular expression flag");
3487 }
3488 }
3489};
3490
3491/**
3492 * Validate the pattern part of a given RegExpLiteral.
3493 *
3494 * @param {RegExpValidationState} state The state to validate RegExp.
3495 * @returns {void}
3496 */
3497pp$8.validateRegExpPattern = function(state) {
3498 this.regexp_pattern(state);
3499
3500 // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
3501 // parsing contains a |GroupName|, reparse with the goal symbol
3502 // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
3503 // exception if _P_ did not conform to the grammar, if any elements of _P_
3504 // were not matched by the parse, or if any Early Error conditions exist.
3505 if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
3506 state.switchN = true;
3507 this.regexp_pattern(state);
3508 }
3509};
3510
3511// https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
3512pp$8.regexp_pattern = function(state) {
3513 state.pos = 0;
3514 state.lastIntValue = 0;
3515 state.lastStringValue = "";
3516 state.lastAssertionIsQuantifiable = false;
3517 state.numCapturingParens = 0;
3518 state.maxBackReference = 0;
3519 state.groupNames.length = 0;
3520 state.backReferenceNames.length = 0;
3521
3522 this.regexp_disjunction(state);
3523
3524 if (state.pos !== state.source.length) {
3525 // Make the same messages as V8.
3526 if (state.eat(0x29 /* ) */)) {
3527 state.raise("Unmatched ')'");
3528 }
3529 if (state.eat(0x5D /* ] */) || state.eat(0x7D /* } */)) {
3530 state.raise("Lone quantifier brackets");
3531 }
3532 }
3533 if (state.maxBackReference > state.numCapturingParens) {
3534 state.raise("Invalid escape");
3535 }
3536 for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
3537 var name = list[i];
3538
3539 if (state.groupNames.indexOf(name) === -1) {
3540 state.raise("Invalid named capture referenced");
3541 }
3542 }
3543};
3544
3545// https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
3546pp$8.regexp_disjunction = function(state) {
3547 this.regexp_alternative(state);
3548 while (state.eat(0x7C /* | */)) {
3549 this.regexp_alternative(state);
3550 }
3551
3552 // Make the same message as V8.
3553 if (this.regexp_eatQuantifier(state, true)) {
3554 state.raise("Nothing to repeat");
3555 }
3556 if (state.eat(0x7B /* { */)) {
3557 state.raise("Lone quantifier brackets");
3558 }
3559};
3560
3561// https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
3562pp$8.regexp_alternative = function(state) {
3563 while (state.pos < state.source.length && this.regexp_eatTerm(state))
3564 { }
3565};
3566
3567// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
3568pp$8.regexp_eatTerm = function(state) {
3569 if (this.regexp_eatAssertion(state)) {
3570 // Handle `QuantifiableAssertion Quantifier` alternative.
3571 // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
3572 // is a QuantifiableAssertion.
3573 if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
3574 // Make the same message as V8.
3575 if (state.switchU) {
3576 state.raise("Invalid quantifier");
3577 }
3578 }
3579 return true
3580 }
3581
3582 if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
3583 this.regexp_eatQuantifier(state);
3584 return true
3585 }
3586
3587 return false
3588};
3589
3590// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
3591pp$8.regexp_eatAssertion = function(state) {
3592 var start = state.pos;
3593 state.lastAssertionIsQuantifiable = false;
3594
3595 // ^, $
3596 if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
3597 return true
3598 }
3599
3600 // \b \B
3601 if (state.eat(0x5C /* \ */)) {
3602 if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
3603 return true
3604 }
3605 state.pos = start;
3606 }
3607
3608 // Lookahead / Lookbehind
3609 if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
3610 var lookbehind = false;
3611 if (this.options.ecmaVersion >= 9) {
3612 lookbehind = state.eat(0x3C /* < */);
3613 }
3614 if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
3615 this.regexp_disjunction(state);
3616 if (!state.eat(0x29 /* ) */)) {
3617 state.raise("Unterminated group");
3618 }
3619 state.lastAssertionIsQuantifiable = !lookbehind;
3620 return true
3621 }
3622 }
3623
3624 state.pos = start;
3625 return false
3626};
3627
3628// https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
3629pp$8.regexp_eatQuantifier = function(state, noError) {
3630 if ( noError === void 0 ) noError = false;
3631
3632 if (this.regexp_eatQuantifierPrefix(state, noError)) {
3633 state.eat(0x3F /* ? */);
3634 return true
3635 }
3636 return false
3637};
3638
3639// https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
3640pp$8.regexp_eatQuantifierPrefix = function(state, noError) {
3641 return (
3642 state.eat(0x2A /* * */) ||
3643 state.eat(0x2B /* + */) ||
3644 state.eat(0x3F /* ? */) ||
3645 this.regexp_eatBracedQuantifier(state, noError)
3646 )
3647};
3648pp$8.regexp_eatBracedQuantifier = function(state, noError) {
3649 var start = state.pos;
3650 if (state.eat(0x7B /* { */)) {
3651 var min = 0, max = -1;
3652 if (this.regexp_eatDecimalDigits(state)) {
3653 min = state.lastIntValue;
3654 if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
3655 max = state.lastIntValue;
3656 }
3657 if (state.eat(0x7D /* } */)) {
3658 // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
3659 if (max !== -1 && max < min && !noError) {
3660 state.raise("numbers out of order in {} quantifier");
3661 }
3662 return true
3663 }
3664 }
3665 if (state.switchU && !noError) {
3666 state.raise("Incomplete quantifier");
3667 }
3668 state.pos = start;
3669 }
3670 return false
3671};
3672
3673// https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
3674pp$8.regexp_eatAtom = function(state) {
3675 return (
3676 this.regexp_eatPatternCharacters(state) ||
3677 state.eat(0x2E /* . */) ||
3678 this.regexp_eatReverseSolidusAtomEscape(state) ||
3679 this.regexp_eatCharacterClass(state) ||
3680 this.regexp_eatUncapturingGroup(state) ||
3681 this.regexp_eatCapturingGroup(state)
3682 )
3683};
3684pp$8.regexp_eatReverseSolidusAtomEscape = function(state) {
3685 var start = state.pos;
3686 if (state.eat(0x5C /* \ */)) {
3687 if (this.regexp_eatAtomEscape(state)) {
3688 return true
3689 }
3690 state.pos = start;
3691 }
3692 return false
3693};
3694pp$8.regexp_eatUncapturingGroup = function(state) {
3695 var start = state.pos;
3696 if (state.eat(0x28 /* ( */)) {
3697 if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
3698 this.regexp_disjunction(state);
3699 if (state.eat(0x29 /* ) */)) {
3700 return true
3701 }
3702 state.raise("Unterminated group");
3703 }
3704 state.pos = start;
3705 }
3706 return false
3707};
3708pp$8.regexp_eatCapturingGroup = function(state) {
3709 if (state.eat(0x28 /* ( */)) {
3710 if (this.options.ecmaVersion >= 9) {
3711 this.regexp_groupSpecifier(state);
3712 } else if (state.current() === 0x3F /* ? */) {
3713 state.raise("Invalid group");
3714 }
3715 this.regexp_disjunction(state);
3716 if (state.eat(0x29 /* ) */)) {
3717 state.numCapturingParens += 1;
3718 return true
3719 }
3720 state.raise("Unterminated group");
3721 }
3722 return false
3723};
3724
3725// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
3726pp$8.regexp_eatExtendedAtom = function(state) {
3727 return (
3728 state.eat(0x2E /* . */) ||
3729 this.regexp_eatReverseSolidusAtomEscape(state) ||
3730 this.regexp_eatCharacterClass(state) ||
3731 this.regexp_eatUncapturingGroup(state) ||
3732 this.regexp_eatCapturingGroup(state) ||
3733 this.regexp_eatInvalidBracedQuantifier(state) ||
3734 this.regexp_eatExtendedPatternCharacter(state)
3735 )
3736};
3737
3738// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
3739pp$8.regexp_eatInvalidBracedQuantifier = function(state) {
3740 if (this.regexp_eatBracedQuantifier(state, true)) {
3741 state.raise("Nothing to repeat");
3742 }
3743 return false
3744};
3745
3746// https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
3747pp$8.regexp_eatSyntaxCharacter = function(state) {
3748 var ch = state.current();
3749 if (isSyntaxCharacter(ch)) {
3750 state.lastIntValue = ch;
3751 state.advance();
3752 return true
3753 }
3754 return false
3755};
3756function isSyntaxCharacter(ch) {
3757 return (
3758 ch === 0x24 /* $ */ ||
3759 ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
3760 ch === 0x2E /* . */ ||
3761 ch === 0x3F /* ? */ ||
3762 ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
3763 ch >= 0x7B /* { */ && ch <= 0x7D /* } */
3764 )
3765}
3766
3767// https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
3768// But eat eager.
3769pp$8.regexp_eatPatternCharacters = function(state) {
3770 var start = state.pos;
3771 var ch = 0;
3772 while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
3773 state.advance();
3774 }
3775 return state.pos !== start
3776};
3777
3778// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
3779pp$8.regexp_eatExtendedPatternCharacter = function(state) {
3780 var ch = state.current();
3781 if (
3782 ch !== -1 &&
3783 ch !== 0x24 /* $ */ &&
3784 !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
3785 ch !== 0x2E /* . */ &&
3786 ch !== 0x3F /* ? */ &&
3787 ch !== 0x5B /* [ */ &&
3788 ch !== 0x5E /* ^ */ &&
3789 ch !== 0x7C /* | */
3790 ) {
3791 state.advance();
3792 return true
3793 }
3794 return false
3795};
3796
3797// GroupSpecifier ::
3798// [empty]
3799// `?` GroupName
3800pp$8.regexp_groupSpecifier = function(state) {
3801 if (state.eat(0x3F /* ? */)) {
3802 if (this.regexp_eatGroupName(state)) {
3803 if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
3804 state.raise("Duplicate capture group name");
3805 }
3806 state.groupNames.push(state.lastStringValue);
3807 return
3808 }
3809 state.raise("Invalid group");
3810 }
3811};
3812
3813// GroupName ::
3814// `<` RegExpIdentifierName `>`
3815// Note: this updates `state.lastStringValue` property with the eaten name.
3816pp$8.regexp_eatGroupName = function(state) {
3817 state.lastStringValue = "";
3818 if (state.eat(0x3C /* < */)) {
3819 if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
3820 return true
3821 }
3822 state.raise("Invalid capture group name");
3823 }
3824 return false
3825};
3826
3827// RegExpIdentifierName ::
3828// RegExpIdentifierStart
3829// RegExpIdentifierName RegExpIdentifierPart
3830// Note: this updates `state.lastStringValue` property with the eaten name.
3831pp$8.regexp_eatRegExpIdentifierName = function(state) {
3832 state.lastStringValue = "";
3833 if (this.regexp_eatRegExpIdentifierStart(state)) {
3834 state.lastStringValue += codePointToString(state.lastIntValue);
3835 while (this.regexp_eatRegExpIdentifierPart(state)) {
3836 state.lastStringValue += codePointToString(state.lastIntValue);
3837 }
3838 return true
3839 }
3840 return false
3841};
3842
3843// RegExpIdentifierStart ::
3844// UnicodeIDStart
3845// `$`
3846// `_`
3847// `\` RegExpUnicodeEscapeSequence[+U]
3848pp$8.regexp_eatRegExpIdentifierStart = function(state) {
3849 var start = state.pos;
3850 var forceU = this.options.ecmaVersion >= 11;
3851 var ch = state.current(forceU);
3852 state.advance(forceU);
3853
3854 if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
3855 ch = state.lastIntValue;
3856 }
3857 if (isRegExpIdentifierStart(ch)) {
3858 state.lastIntValue = ch;
3859 return true
3860 }
3861
3862 state.pos = start;
3863 return false
3864};
3865function isRegExpIdentifierStart(ch) {
3866 return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
3867}
3868
3869// RegExpIdentifierPart ::
3870// UnicodeIDContinue
3871// `$`
3872// `_`
3873// `\` RegExpUnicodeEscapeSequence[+U]
3874// <ZWNJ>
3875// <ZWJ>
3876pp$8.regexp_eatRegExpIdentifierPart = function(state) {
3877 var start = state.pos;
3878 var forceU = this.options.ecmaVersion >= 11;
3879 var ch = state.current(forceU);
3880 state.advance(forceU);
3881
3882 if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
3883 ch = state.lastIntValue;
3884 }
3885 if (isRegExpIdentifierPart(ch)) {
3886 state.lastIntValue = ch;
3887 return true
3888 }
3889
3890 state.pos = start;
3891 return false
3892};
3893function isRegExpIdentifierPart(ch) {
3894 return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
3895}
3896
3897// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
3898pp$8.regexp_eatAtomEscape = function(state) {
3899 if (
3900 this.regexp_eatBackReference(state) ||
3901 this.regexp_eatCharacterClassEscape(state) ||
3902 this.regexp_eatCharacterEscape(state) ||
3903 (state.switchN && this.regexp_eatKGroupName(state))
3904 ) {
3905 return true
3906 }
3907 if (state.switchU) {
3908 // Make the same message as V8.
3909 if (state.current() === 0x63 /* c */) {
3910 state.raise("Invalid unicode escape");
3911 }
3912 state.raise("Invalid escape");
3913 }
3914 return false
3915};
3916pp$8.regexp_eatBackReference = function(state) {
3917 var start = state.pos;
3918 if (this.regexp_eatDecimalEscape(state)) {
3919 var n = state.lastIntValue;
3920 if (state.switchU) {
3921 // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
3922 if (n > state.maxBackReference) {
3923 state.maxBackReference = n;
3924 }
3925 return true
3926 }
3927 if (n <= state.numCapturingParens) {
3928 return true
3929 }
3930 state.pos = start;
3931 }
3932 return false
3933};
3934pp$8.regexp_eatKGroupName = function(state) {
3935 if (state.eat(0x6B /* k */)) {
3936 if (this.regexp_eatGroupName(state)) {
3937 state.backReferenceNames.push(state.lastStringValue);
3938 return true
3939 }
3940 state.raise("Invalid named reference");
3941 }
3942 return false
3943};
3944
3945// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
3946pp$8.regexp_eatCharacterEscape = function(state) {
3947 return (
3948 this.regexp_eatControlEscape(state) ||
3949 this.regexp_eatCControlLetter(state) ||
3950 this.regexp_eatZero(state) ||
3951 this.regexp_eatHexEscapeSequence(state) ||
3952 this.regexp_eatRegExpUnicodeEscapeSequence(state, false) ||
3953 (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
3954 this.regexp_eatIdentityEscape(state)
3955 )
3956};
3957pp$8.regexp_eatCControlLetter = function(state) {
3958 var start = state.pos;
3959 if (state.eat(0x63 /* c */)) {
3960 if (this.regexp_eatControlLetter(state)) {
3961 return true
3962 }
3963 state.pos = start;
3964 }
3965 return false
3966};
3967pp$8.regexp_eatZero = function(state) {
3968 if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
3969 state.lastIntValue = 0;
3970 state.advance();
3971 return true
3972 }
3973 return false
3974};
3975
3976// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
3977pp$8.regexp_eatControlEscape = function(state) {
3978 var ch = state.current();
3979 if (ch === 0x74 /* t */) {
3980 state.lastIntValue = 0x09; /* \t */
3981 state.advance();
3982 return true
3983 }
3984 if (ch === 0x6E /* n */) {
3985 state.lastIntValue = 0x0A; /* \n */
3986 state.advance();
3987 return true
3988 }
3989 if (ch === 0x76 /* v */) {
3990 state.lastIntValue = 0x0B; /* \v */
3991 state.advance();
3992 return true
3993 }
3994 if (ch === 0x66 /* f */) {
3995 state.lastIntValue = 0x0C; /* \f */
3996 state.advance();
3997 return true
3998 }
3999 if (ch === 0x72 /* r */) {
4000 state.lastIntValue = 0x0D; /* \r */
4001 state.advance();
4002 return true
4003 }
4004 return false
4005};
4006
4007// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
4008pp$8.regexp_eatControlLetter = function(state) {
4009 var ch = state.current();
4010 if (isControlLetter(ch)) {
4011 state.lastIntValue = ch % 0x20;
4012 state.advance();
4013 return true
4014 }
4015 return false
4016};
4017function isControlLetter(ch) {
4018 return (
4019 (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
4020 (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
4021 )
4022}
4023
4024// https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
4025pp$8.regexp_eatRegExpUnicodeEscapeSequence = function(state, forceU) {
4026 if ( forceU === void 0 ) forceU = false;
4027
4028 var start = state.pos;
4029 var switchU = forceU || state.switchU;
4030
4031 if (state.eat(0x75 /* u */)) {
4032 if (this.regexp_eatFixedHexDigits(state, 4)) {
4033 var lead = state.lastIntValue;
4034 if (switchU && lead >= 0xD800 && lead <= 0xDBFF) {
4035 var leadSurrogateEnd = state.pos;
4036 if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
4037 var trail = state.lastIntValue;
4038 if (trail >= 0xDC00 && trail <= 0xDFFF) {
4039 state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
4040 return true
4041 }
4042 }
4043 state.pos = leadSurrogateEnd;
4044 state.lastIntValue = lead;
4045 }
4046 return true
4047 }
4048 if (
4049 switchU &&
4050 state.eat(0x7B /* { */) &&
4051 this.regexp_eatHexDigits(state) &&
4052 state.eat(0x7D /* } */) &&
4053 isValidUnicode(state.lastIntValue)
4054 ) {
4055 return true
4056 }
4057 if (switchU) {
4058 state.raise("Invalid unicode escape");
4059 }
4060 state.pos = start;
4061 }
4062
4063 return false
4064};
4065function isValidUnicode(ch) {
4066 return ch >= 0 && ch <= 0x10FFFF
4067}
4068
4069// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
4070pp$8.regexp_eatIdentityEscape = function(state) {
4071 if (state.switchU) {
4072 if (this.regexp_eatSyntaxCharacter(state)) {
4073 return true
4074 }
4075 if (state.eat(0x2F /* / */)) {
4076 state.lastIntValue = 0x2F; /* / */
4077 return true
4078 }
4079 return false
4080 }
4081
4082 var ch = state.current();
4083 if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
4084 state.lastIntValue = ch;
4085 state.advance();
4086 return true
4087 }
4088
4089 return false
4090};
4091
4092// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
4093pp$8.regexp_eatDecimalEscape = function(state) {
4094 state.lastIntValue = 0;
4095 var ch = state.current();
4096 if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
4097 do {
4098 state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
4099 state.advance();
4100 } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
4101 return true
4102 }
4103 return false
4104};
4105
4106// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
4107pp$8.regexp_eatCharacterClassEscape = function(state) {
4108 var ch = state.current();
4109
4110 if (isCharacterClassEscape(ch)) {
4111 state.lastIntValue = -1;
4112 state.advance();
4113 return true
4114 }
4115
4116 if (
4117 state.switchU &&
4118 this.options.ecmaVersion >= 9 &&
4119 (ch === 0x50 /* P */ || ch === 0x70 /* p */)
4120 ) {
4121 state.lastIntValue = -1;
4122 state.advance();
4123 if (
4124 state.eat(0x7B /* { */) &&
4125 this.regexp_eatUnicodePropertyValueExpression(state) &&
4126 state.eat(0x7D /* } */)
4127 ) {
4128 return true
4129 }
4130 state.raise("Invalid property name");
4131 }
4132
4133 return false
4134};
4135function isCharacterClassEscape(ch) {
4136 return (
4137 ch === 0x64 /* d */ ||
4138 ch === 0x44 /* D */ ||
4139 ch === 0x73 /* s */ ||
4140 ch === 0x53 /* S */ ||
4141 ch === 0x77 /* w */ ||
4142 ch === 0x57 /* W */
4143 )
4144}
4145
4146// UnicodePropertyValueExpression ::
4147// UnicodePropertyName `=` UnicodePropertyValue
4148// LoneUnicodePropertyNameOrValue
4149pp$8.regexp_eatUnicodePropertyValueExpression = function(state) {
4150 var start = state.pos;
4151
4152 // UnicodePropertyName `=` UnicodePropertyValue
4153 if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
4154 var name = state.lastStringValue;
4155 if (this.regexp_eatUnicodePropertyValue(state)) {
4156 var value = state.lastStringValue;
4157 this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
4158 return true
4159 }
4160 }
4161 state.pos = start;
4162
4163 // LoneUnicodePropertyNameOrValue
4164 if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
4165 var nameOrValue = state.lastStringValue;
4166 this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
4167 return true
4168 }
4169 return false
4170};
4171pp$8.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
4172 if (!has$3(state.unicodeProperties.nonBinary, name))
4173 { state.raise("Invalid property name"); }
4174 if (!state.unicodeProperties.nonBinary[name].test(value))
4175 { state.raise("Invalid property value"); }
4176};
4177pp$8.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
4178 if (!state.unicodeProperties.binary.test(nameOrValue))
4179 { state.raise("Invalid property name"); }
4180};
4181
4182// UnicodePropertyName ::
4183// UnicodePropertyNameCharacters
4184pp$8.regexp_eatUnicodePropertyName = function(state) {
4185 var ch = 0;
4186 state.lastStringValue = "";
4187 while (isUnicodePropertyNameCharacter(ch = state.current())) {
4188 state.lastStringValue += codePointToString(ch);
4189 state.advance();
4190 }
4191 return state.lastStringValue !== ""
4192};
4193function isUnicodePropertyNameCharacter(ch) {
4194 return isControlLetter(ch) || ch === 0x5F /* _ */
4195}
4196
4197// UnicodePropertyValue ::
4198// UnicodePropertyValueCharacters
4199pp$8.regexp_eatUnicodePropertyValue = function(state) {
4200 var ch = 0;
4201 state.lastStringValue = "";
4202 while (isUnicodePropertyValueCharacter(ch = state.current())) {
4203 state.lastStringValue += codePointToString(ch);
4204 state.advance();
4205 }
4206 return state.lastStringValue !== ""
4207};
4208function isUnicodePropertyValueCharacter(ch) {
4209 return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
4210}
4211
4212// LoneUnicodePropertyNameOrValue ::
4213// UnicodePropertyValueCharacters
4214pp$8.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
4215 return this.regexp_eatUnicodePropertyValue(state)
4216};
4217
4218// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
4219pp$8.regexp_eatCharacterClass = function(state) {
4220 if (state.eat(0x5B /* [ */)) {
4221 state.eat(0x5E /* ^ */);
4222 this.regexp_classRanges(state);
4223 if (state.eat(0x5D /* ] */)) {
4224 return true
4225 }
4226 // Unreachable since it threw "unterminated regular expression" error before.
4227 state.raise("Unterminated character class");
4228 }
4229 return false
4230};
4231
4232// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
4233// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
4234// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
4235pp$8.regexp_classRanges = function(state) {
4236 while (this.regexp_eatClassAtom(state)) {
4237 var left = state.lastIntValue;
4238 if (state.eat(0x2D /* - */) && this.regexp_eatClassAtom(state)) {
4239 var right = state.lastIntValue;
4240 if (state.switchU && (left === -1 || right === -1)) {
4241 state.raise("Invalid character class");
4242 }
4243 if (left !== -1 && right !== -1 && left > right) {
4244 state.raise("Range out of order in character class");
4245 }
4246 }
4247 }
4248};
4249
4250// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
4251// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
4252pp$8.regexp_eatClassAtom = function(state) {
4253 var start = state.pos;
4254
4255 if (state.eat(0x5C /* \ */)) {
4256 if (this.regexp_eatClassEscape(state)) {
4257 return true
4258 }
4259 if (state.switchU) {
4260 // Make the same message as V8.
4261 var ch$1 = state.current();
4262 if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
4263 state.raise("Invalid class escape");
4264 }
4265 state.raise("Invalid escape");
4266 }
4267 state.pos = start;
4268 }
4269
4270 var ch = state.current();
4271 if (ch !== 0x5D /* ] */) {
4272 state.lastIntValue = ch;
4273 state.advance();
4274 return true
4275 }
4276
4277 return false
4278};
4279
4280// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
4281pp$8.regexp_eatClassEscape = function(state) {
4282 var start = state.pos;
4283
4284 if (state.eat(0x62 /* b */)) {
4285 state.lastIntValue = 0x08; /* <BS> */
4286 return true
4287 }
4288
4289 if (state.switchU && state.eat(0x2D /* - */)) {
4290 state.lastIntValue = 0x2D; /* - */
4291 return true
4292 }
4293
4294 if (!state.switchU && state.eat(0x63 /* c */)) {
4295 if (this.regexp_eatClassControlLetter(state)) {
4296 return true
4297 }
4298 state.pos = start;
4299 }
4300
4301 return (
4302 this.regexp_eatCharacterClassEscape(state) ||
4303 this.regexp_eatCharacterEscape(state)
4304 )
4305};
4306
4307// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
4308pp$8.regexp_eatClassControlLetter = function(state) {
4309 var ch = state.current();
4310 if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
4311 state.lastIntValue = ch % 0x20;
4312 state.advance();
4313 return true
4314 }
4315 return false
4316};
4317
4318// https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
4319pp$8.regexp_eatHexEscapeSequence = function(state) {
4320 var start = state.pos;
4321 if (state.eat(0x78 /* x */)) {
4322 if (this.regexp_eatFixedHexDigits(state, 2)) {
4323 return true
4324 }
4325 if (state.switchU) {
4326 state.raise("Invalid escape");
4327 }
4328 state.pos = start;
4329 }
4330 return false
4331};
4332
4333// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
4334pp$8.regexp_eatDecimalDigits = function(state) {
4335 var start = state.pos;
4336 var ch = 0;
4337 state.lastIntValue = 0;
4338 while (isDecimalDigit(ch = state.current())) {
4339 state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
4340 state.advance();
4341 }
4342 return state.pos !== start
4343};
4344function isDecimalDigit(ch) {
4345 return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
4346}
4347
4348// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
4349pp$8.regexp_eatHexDigits = function(state) {
4350 var start = state.pos;
4351 var ch = 0;
4352 state.lastIntValue = 0;
4353 while (isHexDigit(ch = state.current())) {
4354 state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
4355 state.advance();
4356 }
4357 return state.pos !== start
4358};
4359function isHexDigit(ch) {
4360 return (
4361 (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
4362 (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
4363 (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
4364 )
4365}
4366function hexToInt(ch) {
4367 if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
4368 return 10 + (ch - 0x41 /* A */)
4369 }
4370 if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
4371 return 10 + (ch - 0x61 /* a */)
4372 }
4373 return ch - 0x30 /* 0 */
4374}
4375
4376// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
4377// Allows only 0-377(octal) i.e. 0-255(decimal).
4378pp$8.regexp_eatLegacyOctalEscapeSequence = function(state) {
4379 if (this.regexp_eatOctalDigit(state)) {
4380 var n1 = state.lastIntValue;
4381 if (this.regexp_eatOctalDigit(state)) {
4382 var n2 = state.lastIntValue;
4383 if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
4384 state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
4385 } else {
4386 state.lastIntValue = n1 * 8 + n2;
4387 }
4388 } else {
4389 state.lastIntValue = n1;
4390 }
4391 return true
4392 }
4393 return false
4394};
4395
4396// https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
4397pp$8.regexp_eatOctalDigit = function(state) {
4398 var ch = state.current();
4399 if (isOctalDigit(ch)) {
4400 state.lastIntValue = ch - 0x30; /* 0 */
4401 state.advance();
4402 return true
4403 }
4404 state.lastIntValue = 0;
4405 return false
4406};
4407function isOctalDigit(ch) {
4408 return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
4409}
4410
4411// https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
4412// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
4413// And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
4414pp$8.regexp_eatFixedHexDigits = function(state, length) {
4415 var start = state.pos;
4416 state.lastIntValue = 0;
4417 for (var i = 0; i < length; ++i) {
4418 var ch = state.current();
4419 if (!isHexDigit(ch)) {
4420 state.pos = start;
4421 return false
4422 }
4423 state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
4424 state.advance();
4425 }
4426 return true
4427};
4428
4429// Object type used to represent tokens. Note that normally, tokens
4430// simply exist as properties on the parser object. This is only
4431// used for the onToken callback and the external tokenizer.
4432
4433var Token = function Token(p) {
4434 this.type = p.type;
4435 this.value = p.value;
4436 this.start = p.start;
4437 this.end = p.end;
4438 if (p.options.locations)
4439 { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
4440 if (p.options.ranges)
4441 { this.range = [p.start, p.end]; }
4442};
4443
4444// ## Tokenizer
4445
4446var pp$9 = Parser.prototype;
4447
4448// Move to the next token
4449
4450pp$9.next = function(ignoreEscapeSequenceInKeyword) {
4451 if (!ignoreEscapeSequenceInKeyword && this.type.keyword && this.containsEsc)
4452 { this.raiseRecoverable(this.start, "Escape sequence in keyword " + this.type.keyword); }
4453 if (this.options.onToken)
4454 { this.options.onToken(new Token(this)); }
4455
4456 this.lastTokEnd = this.end;
4457 this.lastTokStart = this.start;
4458 this.lastTokEndLoc = this.endLoc;
4459 this.lastTokStartLoc = this.startLoc;
4460 this.nextToken();
4461};
4462
4463pp$9.getToken = function() {
4464 this.next();
4465 return new Token(this)
4466};
4467
4468// If we're in an ES6 environment, make parsers iterable
4469if (typeof Symbol !== "undefined")
4470 { pp$9[Symbol.iterator] = function() {
4471 var this$1 = this;
4472
4473 return {
4474 next: function () {
4475 var token = this$1.getToken();
4476 return {
4477 done: token.type === types.eof,
4478 value: token
4479 }
4480 }
4481 }
4482 }; }
4483
4484// Toggle strict mode. Re-reads the next number or string to please
4485// pedantic tests (`"use strict"; 010;` should fail).
4486
4487pp$9.curContext = function() {
4488 return this.context[this.context.length - 1]
4489};
4490
4491// Read a single token, updating the parser object's token-related
4492// properties.
4493
4494pp$9.nextToken = function() {
4495 var curContext = this.curContext();
4496 if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
4497
4498 this.start = this.pos;
4499 if (this.options.locations) { this.startLoc = this.curPosition(); }
4500 if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
4501
4502 if (curContext.override) { return curContext.override(this) }
4503 else { this.readToken(this.fullCharCodeAtPos()); }
4504};
4505
4506pp$9.readToken = function(code) {
4507 // Identifier or keyword. '\uXXXX' sequences are allowed in
4508 // identifiers, so '\' also dispatches to that.
4509 if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
4510 { return this.readWord() }
4511
4512 return this.getTokenFromCode(code)
4513};
4514
4515pp$9.fullCharCodeAtPos = function() {
4516 var code = this.input.charCodeAt(this.pos);
4517 if (code <= 0xd7ff || code >= 0xe000) { return code }
4518 var next = this.input.charCodeAt(this.pos + 1);
4519 return (code << 10) + next - 0x35fdc00
4520};
4521
4522pp$9.skipBlockComment = function() {
4523 var startLoc = this.options.onComment && this.curPosition();
4524 var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
4525 if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
4526 this.pos = end + 2;
4527 if (this.options.locations) {
4528 lineBreakG.lastIndex = start;
4529 var match;
4530 while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
4531 ++this.curLine;
4532 this.lineStart = match.index + match[0].length;
4533 }
4534 }
4535 if (this.options.onComment)
4536 { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
4537 startLoc, this.curPosition()); }
4538};
4539
4540pp$9.skipLineComment = function(startSkip) {
4541 var start = this.pos;
4542 var startLoc = this.options.onComment && this.curPosition();
4543 var ch = this.input.charCodeAt(this.pos += startSkip);
4544 while (this.pos < this.input.length && !isNewLine(ch)) {
4545 ch = this.input.charCodeAt(++this.pos);
4546 }
4547 if (this.options.onComment)
4548 { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
4549 startLoc, this.curPosition()); }
4550};
4551
4552// Called at the start of the parse and after every token. Skips
4553// whitespace and comments, and.
4554
4555pp$9.skipSpace = function() {
4556 loop: while (this.pos < this.input.length) {
4557 var ch = this.input.charCodeAt(this.pos);
4558 switch (ch) {
4559 case 32: case 160: // ' '
4560 ++this.pos;
4561 break
4562 case 13:
4563 if (this.input.charCodeAt(this.pos + 1) === 10) {
4564 ++this.pos;
4565 }
4566 case 10: case 8232: case 8233:
4567 ++this.pos;
4568 if (this.options.locations) {
4569 ++this.curLine;
4570 this.lineStart = this.pos;
4571 }
4572 break
4573 case 47: // '/'
4574 switch (this.input.charCodeAt(this.pos + 1)) {
4575 case 42: // '*'
4576 this.skipBlockComment();
4577 break
4578 case 47:
4579 this.skipLineComment(2);
4580 break
4581 default:
4582 break loop
4583 }
4584 break
4585 default:
4586 if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
4587 ++this.pos;
4588 } else {
4589 break loop
4590 }
4591 }
4592 }
4593};
4594
4595// Called at the end of every token. Sets `end`, `val`, and
4596// maintains `context` and `exprAllowed`, and skips the space after
4597// the token, so that the next one's `start` will point at the
4598// right position.
4599
4600pp$9.finishToken = function(type, val) {
4601 this.end = this.pos;
4602 if (this.options.locations) { this.endLoc = this.curPosition(); }
4603 var prevType = this.type;
4604 this.type = type;
4605 this.value = val;
4606
4607 this.updateContext(prevType);
4608};
4609
4610// ### Token reading
4611
4612// This is the function that is called to fetch the next token. It
4613// is somewhat obscure, because it works in character codes rather
4614// than characters, and because operator parsing has been inlined
4615// into it.
4616//
4617// All in the name of speed.
4618//
4619pp$9.readToken_dot = function() {
4620 var next = this.input.charCodeAt(this.pos + 1);
4621 if (next >= 48 && next <= 57) { return this.readNumber(true) }
4622 var next2 = this.input.charCodeAt(this.pos + 2);
4623 if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
4624 this.pos += 3;
4625 return this.finishToken(types.ellipsis)
4626 } else {
4627 ++this.pos;
4628 return this.finishToken(types.dot)
4629 }
4630};
4631
4632pp$9.readToken_slash = function() { // '/'
4633 var next = this.input.charCodeAt(this.pos + 1);
4634 if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
4635 if (next === 61) { return this.finishOp(types.assign, 2) }
4636 return this.finishOp(types.slash, 1)
4637};
4638
4639pp$9.readToken_mult_modulo_exp = function(code) { // '%*'
4640 var next = this.input.charCodeAt(this.pos + 1);
4641 var size = 1;
4642 var tokentype = code === 42 ? types.star : types.modulo;
4643
4644 // exponentiation operator ** and **=
4645 if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
4646 ++size;
4647 tokentype = types.starstar;
4648 next = this.input.charCodeAt(this.pos + 2);
4649 }
4650
4651 if (next === 61) { return this.finishOp(types.assign, size + 1) }
4652 return this.finishOp(tokentype, size)
4653};
4654
4655pp$9.readToken_pipe_amp = function(code) { // '|&'
4656 var next = this.input.charCodeAt(this.pos + 1);
4657 if (next === code) {
4658 if (this.options.ecmaVersion >= 12) {
4659 var next2 = this.input.charCodeAt(this.pos + 2);
4660 if (next2 === 61) { return this.finishOp(types.assign, 3) }
4661 }
4662 return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2)
4663 }
4664 if (next === 61) { return this.finishOp(types.assign, 2) }
4665 return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
4666};
4667
4668pp$9.readToken_caret = function() { // '^'
4669 var next = this.input.charCodeAt(this.pos + 1);
4670 if (next === 61) { return this.finishOp(types.assign, 2) }
4671 return this.finishOp(types.bitwiseXOR, 1)
4672};
4673
4674pp$9.readToken_plus_min = function(code) { // '+-'
4675 var next = this.input.charCodeAt(this.pos + 1);
4676 if (next === code) {
4677 if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
4678 (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
4679 // A `-->` line comment
4680 this.skipLineComment(3);
4681 this.skipSpace();
4682 return this.nextToken()
4683 }
4684 return this.finishOp(types.incDec, 2)
4685 }
4686 if (next === 61) { return this.finishOp(types.assign, 2) }
4687 return this.finishOp(types.plusMin, 1)
4688};
4689
4690pp$9.readToken_lt_gt = function(code) { // '<>'
4691 var next = this.input.charCodeAt(this.pos + 1);
4692 var size = 1;
4693 if (next === code) {
4694 size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
4695 if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
4696 return this.finishOp(types.bitShift, size)
4697 }
4698 if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
4699 this.input.charCodeAt(this.pos + 3) === 45) {
4700 // `<!--`, an XML-style comment that should be interpreted as a line comment
4701 this.skipLineComment(4);
4702 this.skipSpace();
4703 return this.nextToken()
4704 }
4705 if (next === 61) { size = 2; }
4706 return this.finishOp(types.relational, size)
4707};
4708
4709pp$9.readToken_eq_excl = function(code) { // '=!'
4710 var next = this.input.charCodeAt(this.pos + 1);
4711 if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
4712 if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
4713 this.pos += 2;
4714 return this.finishToken(types.arrow)
4715 }
4716 return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
4717};
4718
4719pp$9.readToken_question = function() { // '?'
4720 var ecmaVersion = this.options.ecmaVersion;
4721 if (ecmaVersion >= 11) {
4722 var next = this.input.charCodeAt(this.pos + 1);
4723 if (next === 46) {
4724 var next2 = this.input.charCodeAt(this.pos + 2);
4725 if (next2 < 48 || next2 > 57) { return this.finishOp(types.questionDot, 2) }
4726 }
4727 if (next === 63) {
4728 if (ecmaVersion >= 12) {
4729 var next2$1 = this.input.charCodeAt(this.pos + 2);
4730 if (next2$1 === 61) { return this.finishOp(types.assign, 3) }
4731 }
4732 return this.finishOp(types.coalesce, 2)
4733 }
4734 }
4735 return this.finishOp(types.question, 1)
4736};
4737
4738pp$9.getTokenFromCode = function(code) {
4739 switch (code) {
4740 // The interpretation of a dot depends on whether it is followed
4741 // by a digit or another two dots.
4742 case 46: // '.'
4743 return this.readToken_dot()
4744
4745 // Punctuation tokens.
4746 case 40: ++this.pos; return this.finishToken(types.parenL)
4747 case 41: ++this.pos; return this.finishToken(types.parenR)
4748 case 59: ++this.pos; return this.finishToken(types.semi)
4749 case 44: ++this.pos; return this.finishToken(types.comma)
4750 case 91: ++this.pos; return this.finishToken(types.bracketL)
4751 case 93: ++this.pos; return this.finishToken(types.bracketR)
4752 case 123: ++this.pos; return this.finishToken(types.braceL)
4753 case 125: ++this.pos; return this.finishToken(types.braceR)
4754 case 58: ++this.pos; return this.finishToken(types.colon)
4755
4756 case 96: // '`'
4757 if (this.options.ecmaVersion < 6) { break }
4758 ++this.pos;
4759 return this.finishToken(types.backQuote)
4760
4761 case 48: // '0'
4762 var next = this.input.charCodeAt(this.pos + 1);
4763 if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
4764 if (this.options.ecmaVersion >= 6) {
4765 if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
4766 if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
4767 }
4768
4769 // Anything else beginning with a digit is an integer, octal
4770 // number, or float.
4771 case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
4772 return this.readNumber(false)
4773
4774 // Quotes produce strings.
4775 case 34: case 39: // '"', "'"
4776 return this.readString(code)
4777
4778 // Operators are parsed inline in tiny state machines. '=' (61) is
4779 // often referred to. `finishOp` simply skips the amount of
4780 // characters it is given as second argument, and returns a token
4781 // of the type given by its first argument.
4782
4783 case 47: // '/'
4784 return this.readToken_slash()
4785
4786 case 37: case 42: // '%*'
4787 return this.readToken_mult_modulo_exp(code)
4788
4789 case 124: case 38: // '|&'
4790 return this.readToken_pipe_amp(code)
4791
4792 case 94: // '^'
4793 return this.readToken_caret()
4794
4795 case 43: case 45: // '+-'
4796 return this.readToken_plus_min(code)
4797
4798 case 60: case 62: // '<>'
4799 return this.readToken_lt_gt(code)
4800
4801 case 61: case 33: // '=!'
4802 return this.readToken_eq_excl(code)
4803
4804 case 63: // '?'
4805 return this.readToken_question()
4806
4807 case 126: // '~'
4808 return this.finishOp(types.prefix, 1)
4809 }
4810
4811 this.raise(this.pos, "Unexpected character '" + codePointToString$1(code) + "'");
4812};
4813
4814pp$9.finishOp = function(type, size) {
4815 var str = this.input.slice(this.pos, this.pos + size);
4816 this.pos += size;
4817 return this.finishToken(type, str)
4818};
4819
4820pp$9.readRegexp = function() {
4821 var escaped, inClass, start = this.pos;
4822 for (;;) {
4823 if (this.pos >= this.input.length) { this.raise(start, "Unterminated regular expression"); }
4824 var ch = this.input.charAt(this.pos);
4825 if (lineBreak.test(ch)) { this.raise(start, "Unterminated regular expression"); }
4826 if (!escaped) {
4827 if (ch === "[") { inClass = true; }
4828 else if (ch === "]" && inClass) { inClass = false; }
4829 else if (ch === "/" && !inClass) { break }
4830 escaped = ch === "\\";
4831 } else { escaped = false; }
4832 ++this.pos;
4833 }
4834 var pattern = this.input.slice(start, this.pos);
4835 ++this.pos;
4836 var flagsStart = this.pos;
4837 var flags = this.readWord1();
4838 if (this.containsEsc) { this.unexpected(flagsStart); }
4839
4840 // Validate pattern
4841 var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
4842 state.reset(start, pattern, flags);
4843 this.validateRegExpFlags(state);
4844 this.validateRegExpPattern(state);
4845
4846 // Create Literal#value property value.
4847 var value = null;
4848 try {
4849 value = new RegExp(pattern, flags);
4850 } catch (e) {
4851 // ESTree requires null if it failed to instantiate RegExp object.
4852 // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
4853 }
4854
4855 return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
4856};
4857
4858// Read an integer in the given radix. Return null if zero digits
4859// were read, the integer value otherwise. When `len` is given, this
4860// will return `null` unless the integer has exactly `len` digits.
4861
4862pp$9.readInt = function(radix, len, maybeLegacyOctalNumericLiteral) {
4863 // `len` is used for character escape sequences. In that case, disallow separators.
4864 var allowSeparators = this.options.ecmaVersion >= 12 && len === undefined;
4865
4866 // `maybeLegacyOctalNumericLiteral` is true if it doesn't have prefix (0x,0o,0b)
4867 // and isn't fraction part nor exponent part. In that case, if the first digit
4868 // is zero then disallow separators.
4869 var isLegacyOctalNumericLiteral = maybeLegacyOctalNumericLiteral && this.input.charCodeAt(this.pos) === 48;
4870
4871 var start = this.pos, total = 0, lastCode = 0;
4872 for (var i = 0, e = len == null ? Infinity : len; i < e; ++i, ++this.pos) {
4873 var code = this.input.charCodeAt(this.pos), val = (void 0);
4874
4875 if (allowSeparators && code === 95) {
4876 if (isLegacyOctalNumericLiteral) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed in legacy octal numeric literals"); }
4877 if (lastCode === 95) { this.raiseRecoverable(this.pos, "Numeric separator must be exactly one underscore"); }
4878 if (i === 0) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed at the first of digits"); }
4879 lastCode = code;
4880 continue
4881 }
4882
4883 if (code >= 97) { val = code - 97 + 10; } // a
4884 else if (code >= 65) { val = code - 65 + 10; } // A
4885 else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
4886 else { val = Infinity; }
4887 if (val >= radix) { break }
4888 lastCode = code;
4889 total = total * radix + val;
4890 }
4891
4892 if (allowSeparators && lastCode === 95) { this.raiseRecoverable(this.pos - 1, "Numeric separator is not allowed at the last of digits"); }
4893 if (this.pos === start || len != null && this.pos - start !== len) { return null }
4894
4895 return total
4896};
4897
4898function stringToNumber(str, isLegacyOctalNumericLiteral) {
4899 if (isLegacyOctalNumericLiteral) {
4900 return parseInt(str, 8)
4901 }
4902
4903 // `parseFloat(value)` stops parsing at the first numeric separator then returns a wrong value.
4904 return parseFloat(str.replace(/_/g, ""))
4905}
4906
4907function stringToBigInt(str) {
4908 if (typeof BigInt !== "function") {
4909 return null
4910 }
4911
4912 // `BigInt(value)` throws syntax error if the string contains numeric separators.
4913 return BigInt(str.replace(/_/g, ""))
4914}
4915
4916pp$9.readRadixNumber = function(radix) {
4917 var start = this.pos;
4918 this.pos += 2; // 0x
4919 var val = this.readInt(radix);
4920 if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
4921 if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
4922 val = stringToBigInt(this.input.slice(start, this.pos));
4923 ++this.pos;
4924 } else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
4925 return this.finishToken(types.num, val)
4926};
4927
4928// Read an integer, octal integer, or floating-point number.
4929
4930pp$9.readNumber = function(startsWithDot) {
4931 var start = this.pos;
4932 if (!startsWithDot && this.readInt(10, undefined, true) === null) { this.raise(start, "Invalid number"); }
4933 var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
4934 if (octal && this.strict) { this.raise(start, "Invalid number"); }
4935 var next = this.input.charCodeAt(this.pos);
4936 if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
4937 var val$1 = stringToBigInt(this.input.slice(start, this.pos));
4938 ++this.pos;
4939 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
4940 return this.finishToken(types.num, val$1)
4941 }
4942 if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
4943 if (next === 46 && !octal) { // '.'
4944 ++this.pos;
4945 this.readInt(10);
4946 next = this.input.charCodeAt(this.pos);
4947 }
4948 if ((next === 69 || next === 101) && !octal) { // 'eE'
4949 next = this.input.charCodeAt(++this.pos);
4950 if (next === 43 || next === 45) { ++this.pos; } // '+-'
4951 if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
4952 }
4953 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
4954
4955 var val = stringToNumber(this.input.slice(start, this.pos), octal);
4956 return this.finishToken(types.num, val)
4957};
4958
4959// Read a string value, interpreting backslash-escapes.
4960
4961pp$9.readCodePoint = function() {
4962 var ch = this.input.charCodeAt(this.pos), code;
4963
4964 if (ch === 123) { // '{'
4965 if (this.options.ecmaVersion < 6) { this.unexpected(); }
4966 var codePos = ++this.pos;
4967 code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
4968 ++this.pos;
4969 if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
4970 } else {
4971 code = this.readHexChar(4);
4972 }
4973 return code
4974};
4975
4976function codePointToString$1(code) {
4977 // UTF-16 Decoding
4978 if (code <= 0xFFFF) { return String.fromCharCode(code) }
4979 code -= 0x10000;
4980 return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
4981}
4982
4983pp$9.readString = function(quote) {
4984 var out = "", chunkStart = ++this.pos;
4985 for (;;) {
4986 if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated string constant"); }
4987 var ch = this.input.charCodeAt(this.pos);
4988 if (ch === quote) { break }
4989 if (ch === 92) { // '\'
4990 out += this.input.slice(chunkStart, this.pos);
4991 out += this.readEscapedChar(false);
4992 chunkStart = this.pos;
4993 } else {
4994 if (isNewLine(ch, this.options.ecmaVersion >= 10)) { this.raise(this.start, "Unterminated string constant"); }
4995 ++this.pos;
4996 }
4997 }
4998 out += this.input.slice(chunkStart, this.pos++);
4999 return this.finishToken(types.string, out)
5000};
5001
5002// Reads template string tokens.
5003
5004var INVALID_TEMPLATE_ESCAPE_ERROR = {};
5005
5006pp$9.tryReadTemplateToken = function() {
5007 this.inTemplateElement = true;
5008 try {
5009 this.readTmplToken();
5010 } catch (err) {
5011 if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
5012 this.readInvalidTemplateToken();
5013 } else {
5014 throw err
5015 }
5016 }
5017
5018 this.inTemplateElement = false;
5019};
5020
5021pp$9.invalidStringToken = function(position, message) {
5022 if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
5023 throw INVALID_TEMPLATE_ESCAPE_ERROR
5024 } else {
5025 this.raise(position, message);
5026 }
5027};
5028
5029pp$9.readTmplToken = function() {
5030 var out = "", chunkStart = this.pos;
5031 for (;;) {
5032 if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated template"); }
5033 var ch = this.input.charCodeAt(this.pos);
5034 if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) { // '`', '${'
5035 if (this.pos === this.start && (this.type === types.template || this.type === types.invalidTemplate)) {
5036 if (ch === 36) {
5037 this.pos += 2;
5038 return this.finishToken(types.dollarBraceL)
5039 } else {
5040 ++this.pos;
5041 return this.finishToken(types.backQuote)
5042 }
5043 }
5044 out += this.input.slice(chunkStart, this.pos);
5045 return this.finishToken(types.template, out)
5046 }
5047 if (ch === 92) { // '\'
5048 out += this.input.slice(chunkStart, this.pos);
5049 out += this.readEscapedChar(true);
5050 chunkStart = this.pos;
5051 } else if (isNewLine(ch)) {
5052 out += this.input.slice(chunkStart, this.pos);
5053 ++this.pos;
5054 switch (ch) {
5055 case 13:
5056 if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
5057 case 10:
5058 out += "\n";
5059 break
5060 default:
5061 out += String.fromCharCode(ch);
5062 break
5063 }
5064 if (this.options.locations) {
5065 ++this.curLine;
5066 this.lineStart = this.pos;
5067 }
5068 chunkStart = this.pos;
5069 } else {
5070 ++this.pos;
5071 }
5072 }
5073};
5074
5075// Reads a template token to search for the end, without validating any escape sequences
5076pp$9.readInvalidTemplateToken = function() {
5077 for (; this.pos < this.input.length; this.pos++) {
5078 switch (this.input[this.pos]) {
5079 case "\\":
5080 ++this.pos;
5081 break
5082
5083 case "$":
5084 if (this.input[this.pos + 1] !== "{") {
5085 break
5086 }
5087 // falls through
5088
5089 case "`":
5090 return this.finishToken(types.invalidTemplate, this.input.slice(this.start, this.pos))
5091
5092 // no default
5093 }
5094 }
5095 this.raise(this.start, "Unterminated template");
5096};
5097
5098// Used to read escaped characters
5099
5100pp$9.readEscapedChar = function(inTemplate) {
5101 var ch = this.input.charCodeAt(++this.pos);
5102 ++this.pos;
5103 switch (ch) {
5104 case 110: return "\n" // 'n' -> '\n'
5105 case 114: return "\r" // 'r' -> '\r'
5106 case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
5107 case 117: return codePointToString$1(this.readCodePoint()) // 'u'
5108 case 116: return "\t" // 't' -> '\t'
5109 case 98: return "\b" // 'b' -> '\b'
5110 case 118: return "\u000b" // 'v' -> '\u000b'
5111 case 102: return "\f" // 'f' -> '\f'
5112 case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
5113 case 10: // ' \n'
5114 if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
5115 return ""
5116 case 56:
5117 case 57:
5118 if (this.strict) {
5119 this.invalidStringToken(
5120 this.pos - 1,
5121 "Invalid escape sequence"
5122 );
5123 }
5124 if (inTemplate) {
5125 var codePos = this.pos - 1;
5126
5127 this.invalidStringToken(
5128 codePos,
5129 "Invalid escape sequence in template string"
5130 );
5131
5132 return null
5133 }
5134 default:
5135 if (ch >= 48 && ch <= 55) {
5136 var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
5137 var octal = parseInt(octalStr, 8);
5138 if (octal > 255) {
5139 octalStr = octalStr.slice(0, -1);
5140 octal = parseInt(octalStr, 8);
5141 }
5142 this.pos += octalStr.length - 1;
5143 ch = this.input.charCodeAt(this.pos);
5144 if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
5145 this.invalidStringToken(
5146 this.pos - 1 - octalStr.length,
5147 inTemplate
5148 ? "Octal literal in template string"
5149 : "Octal literal in strict mode"
5150 );
5151 }
5152 return String.fromCharCode(octal)
5153 }
5154 if (isNewLine(ch)) {
5155 // Unicode new line characters after \ get removed from output in both
5156 // template literals and strings
5157 return ""
5158 }
5159 return String.fromCharCode(ch)
5160 }
5161};
5162
5163// Used to read character escape sequences ('\x', '\u', '\U').
5164
5165pp$9.readHexChar = function(len) {
5166 var codePos = this.pos;
5167 var n = this.readInt(16, len);
5168 if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
5169 return n
5170};
5171
5172// Read an identifier, and return it as a string. Sets `this.containsEsc`
5173// to whether the word contained a '\u' escape.
5174//
5175// Incrementally adds only escaped chars, adding other chunks as-is
5176// as a micro-optimization.
5177
5178pp$9.readWord1 = function() {
5179 this.containsEsc = false;
5180 var word = "", first = true, chunkStart = this.pos;
5181 var astral = this.options.ecmaVersion >= 6;
5182 while (this.pos < this.input.length) {
5183 var ch = this.fullCharCodeAtPos();
5184 if (isIdentifierChar(ch, astral)) {
5185 this.pos += ch <= 0xffff ? 1 : 2;
5186 } else if (ch === 92) { // "\"
5187 this.containsEsc = true;
5188 word += this.input.slice(chunkStart, this.pos);
5189 var escStart = this.pos;
5190 if (this.input.charCodeAt(++this.pos) !== 117) // "u"
5191 { this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); }
5192 ++this.pos;
5193 var esc = this.readCodePoint();
5194 if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
5195 { this.invalidStringToken(escStart, "Invalid Unicode escape"); }
5196 word += codePointToString$1(esc);
5197 chunkStart = this.pos;
5198 } else {
5199 break
5200 }
5201 first = false;
5202 }
5203 return word + this.input.slice(chunkStart, this.pos)
5204};
5205
5206// Read an identifier or keyword token. Will check for reserved
5207// words when necessary.
5208
5209pp$9.readWord = function() {
5210 var word = this.readWord1();
5211 var type = types.name;
5212 if (this.keywords.test(word)) {
5213 type = keywords$1[word];
5214 }
5215 return this.finishToken(type, word)
5216};
5217
5218// Acorn is a tiny, fast JavaScript parser written in JavaScript.
5219
5220var version = "8.1.0";
5221
5222Parser.acorn = {
5223 Parser: Parser,
5224 version: version,
5225 defaultOptions: defaultOptions,
5226 Position: Position,
5227 SourceLocation: SourceLocation,
5228 getLineInfo: getLineInfo,
5229 Node: Node,
5230 TokenType: TokenType,
5231 tokTypes: types,
5232 keywordTypes: keywords$1,
5233 TokContext: TokContext,
5234 tokContexts: types$1,
5235 isIdentifierChar: isIdentifierChar,
5236 isIdentifierStart: isIdentifierStart,
5237 Token: Token,
5238 isNewLine: isNewLine,
5239 lineBreak: lineBreak,
5240 lineBreakG: lineBreakG,
5241 nonASCIIwhitespace: nonASCIIwhitespace
5242};
5243
5244var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
5245function encode(decoded) {
5246 var sourceFileIndex = 0; // second field
5247 var sourceCodeLine = 0; // third field
5248 var sourceCodeColumn = 0; // fourth field
5249 var nameIndex = 0; // fifth field
5250 var mappings = '';
5251 for (var i = 0; i < decoded.length; i++) {
5252 var line = decoded[i];
5253 if (i > 0)
5254 mappings += ';';
5255 if (line.length === 0)
5256 continue;
5257 var generatedCodeColumn = 0; // first field
5258 var lineMappings = [];
5259 for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {
5260 var segment = line_1[_i];
5261 var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn);
5262 generatedCodeColumn = segment[0];
5263 if (segment.length > 1) {
5264 segmentMappings +=
5265 encodeInteger(segment[1] - sourceFileIndex) +
5266 encodeInteger(segment[2] - sourceCodeLine) +
5267 encodeInteger(segment[3] - sourceCodeColumn);
5268 sourceFileIndex = segment[1];
5269 sourceCodeLine = segment[2];
5270 sourceCodeColumn = segment[3];
5271 }
5272 if (segment.length === 5) {
5273 segmentMappings += encodeInteger(segment[4] - nameIndex);
5274 nameIndex = segment[4];
5275 }
5276 lineMappings.push(segmentMappings);
5277 }
5278 mappings += lineMappings.join(',');
5279 }
5280 return mappings;
5281}
5282function encodeInteger(num) {
5283 var result = '';
5284 num = num < 0 ? (-num << 1) | 1 : num << 1;
5285 do {
5286 var clamped = num & 31;
5287 num >>>= 5;
5288 if (num > 0) {
5289 clamped |= 32;
5290 }
5291 result += chars[clamped];
5292 } while (num > 0);
5293 return result;
5294}
5295
5296var BitSet = function BitSet(arg) {
5297 this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
5298};
5299
5300BitSet.prototype.add = function add (n) {
5301 this.bits[n >> 5] |= 1 << (n & 31);
5302};
5303
5304BitSet.prototype.has = function has (n) {
5305 return !!(this.bits[n >> 5] & (1 << (n & 31)));
5306};
5307
5308var Chunk = function Chunk(start, end, content) {
5309 this.start = start;
5310 this.end = end;
5311 this.original = content;
5312
5313 this.intro = '';
5314 this.outro = '';
5315
5316 this.content = content;
5317 this.storeName = false;
5318 this.edited = false;
5319
5320 // we make these non-enumerable, for sanity while debugging
5321 Object.defineProperties(this, {
5322 previous: { writable: true, value: null },
5323 next: { writable: true, value: null }
5324 });
5325};
5326
5327Chunk.prototype.appendLeft = function appendLeft (content) {
5328 this.outro += content;
5329};
5330
5331Chunk.prototype.appendRight = function appendRight (content) {
5332 this.intro = this.intro + content;
5333};
5334
5335Chunk.prototype.clone = function clone () {
5336 var chunk = new Chunk(this.start, this.end, this.original);
5337
5338 chunk.intro = this.intro;
5339 chunk.outro = this.outro;
5340 chunk.content = this.content;
5341 chunk.storeName = this.storeName;
5342 chunk.edited = this.edited;
5343
5344 return chunk;
5345};
5346
5347Chunk.prototype.contains = function contains (index) {
5348 return this.start < index && index < this.end;
5349};
5350
5351Chunk.prototype.eachNext = function eachNext (fn) {
5352 var chunk = this;
5353 while (chunk) {
5354 fn(chunk);
5355 chunk = chunk.next;
5356 }
5357};
5358
5359Chunk.prototype.eachPrevious = function eachPrevious (fn) {
5360 var chunk = this;
5361 while (chunk) {
5362 fn(chunk);
5363 chunk = chunk.previous;
5364 }
5365};
5366
5367Chunk.prototype.edit = function edit (content, storeName, contentOnly) {
5368 this.content = content;
5369 if (!contentOnly) {
5370 this.intro = '';
5371 this.outro = '';
5372 }
5373 this.storeName = storeName;
5374
5375 this.edited = true;
5376
5377 return this;
5378};
5379
5380Chunk.prototype.prependLeft = function prependLeft (content) {
5381 this.outro = content + this.outro;
5382};
5383
5384Chunk.prototype.prependRight = function prependRight (content) {
5385 this.intro = content + this.intro;
5386};
5387
5388Chunk.prototype.split = function split (index) {
5389 var sliceIndex = index - this.start;
5390
5391 var originalBefore = this.original.slice(0, sliceIndex);
5392 var originalAfter = this.original.slice(sliceIndex);
5393
5394 this.original = originalBefore;
5395
5396 var newChunk = new Chunk(index, this.end, originalAfter);
5397 newChunk.outro = this.outro;
5398 this.outro = '';
5399
5400 this.end = index;
5401
5402 if (this.edited) {
5403 // TODO is this block necessary?...
5404 newChunk.edit('', false);
5405 this.content = '';
5406 } else {
5407 this.content = originalBefore;
5408 }
5409
5410 newChunk.next = this.next;
5411 if (newChunk.next) { newChunk.next.previous = newChunk; }
5412 newChunk.previous = this;
5413 this.next = newChunk;
5414
5415 return newChunk;
5416};
5417
5418Chunk.prototype.toString = function toString () {
5419 return this.intro + this.content + this.outro;
5420};
5421
5422Chunk.prototype.trimEnd = function trimEnd (rx) {
5423 this.outro = this.outro.replace(rx, '');
5424 if (this.outro.length) { return true; }
5425
5426 var trimmed = this.content.replace(rx, '');
5427
5428 if (trimmed.length) {
5429 if (trimmed !== this.content) {
5430 this.split(this.start + trimmed.length).edit('', undefined, true);
5431 }
5432 return true;
5433
5434 } else {
5435 this.edit('', undefined, true);
5436
5437 this.intro = this.intro.replace(rx, '');
5438 if (this.intro.length) { return true; }
5439 }
5440};
5441
5442Chunk.prototype.trimStart = function trimStart (rx) {
5443 this.intro = this.intro.replace(rx, '');
5444 if (this.intro.length) { return true; }
5445
5446 var trimmed = this.content.replace(rx, '');
5447
5448 if (trimmed.length) {
5449 if (trimmed !== this.content) {
5450 this.split(this.end - trimmed.length);
5451 this.edit('', undefined, true);
5452 }
5453 return true;
5454
5455 } else {
5456 this.edit('', undefined, true);
5457
5458 this.outro = this.outro.replace(rx, '');
5459 if (this.outro.length) { return true; }
5460 }
5461};
5462
5463var btoa = function () {
5464 throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
5465};
5466if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
5467 btoa = function (str) { return window.btoa(unescape(encodeURIComponent(str))); };
5468} else if (typeof Buffer === 'function') {
5469 btoa = function (str) { return Buffer.from(str, 'utf-8').toString('base64'); };
5470}
5471
5472var SourceMap = function SourceMap(properties) {
5473 this.version = 3;
5474 this.file = properties.file;
5475 this.sources = properties.sources;
5476 this.sourcesContent = properties.sourcesContent;
5477 this.names = properties.names;
5478 this.mappings = encode(properties.mappings);
5479};
5480
5481SourceMap.prototype.toString = function toString () {
5482 return JSON.stringify(this);
5483};
5484
5485SourceMap.prototype.toUrl = function toUrl () {
5486 return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
5487};
5488
5489function guessIndent(code) {
5490 var lines = code.split('\n');
5491
5492 var tabbed = lines.filter(function (line) { return /^\t+/.test(line); });
5493 var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); });
5494
5495 if (tabbed.length === 0 && spaced.length === 0) {
5496 return null;
5497 }
5498
5499 // More lines tabbed than spaced? Assume tabs, and
5500 // default to tabs in the case of a tie (or nothing
5501 // to go on)
5502 if (tabbed.length >= spaced.length) {
5503 return '\t';
5504 }
5505
5506 // Otherwise, we need to guess the multiple
5507 var min = spaced.reduce(function (previous, current) {
5508 var numSpaces = /^ +/.exec(current)[0].length;
5509 return Math.min(numSpaces, previous);
5510 }, Infinity);
5511
5512 return new Array(min + 1).join(' ');
5513}
5514
5515function getRelativePath(from, to) {
5516 var fromParts = from.split(/[/\\]/);
5517 var toParts = to.split(/[/\\]/);
5518
5519 fromParts.pop(); // get dirname
5520
5521 while (fromParts[0] === toParts[0]) {
5522 fromParts.shift();
5523 toParts.shift();
5524 }
5525
5526 if (fromParts.length) {
5527 var i = fromParts.length;
5528 while (i--) { fromParts[i] = '..'; }
5529 }
5530
5531 return fromParts.concat(toParts).join('/');
5532}
5533
5534var toString = Object.prototype.toString;
5535
5536function isObject(thing) {
5537 return toString.call(thing) === '[object Object]';
5538}
5539
5540function getLocator(source) {
5541 var originalLines = source.split('\n');
5542 var lineOffsets = [];
5543
5544 for (var i = 0, pos = 0; i < originalLines.length; i++) {
5545 lineOffsets.push(pos);
5546 pos += originalLines[i].length + 1;
5547 }
5548
5549 return function locate(index) {
5550 var i = 0;
5551 var j = lineOffsets.length;
5552 while (i < j) {
5553 var m = (i + j) >> 1;
5554 if (index < lineOffsets[m]) {
5555 j = m;
5556 } else {
5557 i = m + 1;
5558 }
5559 }
5560 var line = i - 1;
5561 var column = index - lineOffsets[line];
5562 return { line: line, column: column };
5563 };
5564}
5565
5566var Mappings = function Mappings(hires) {
5567 this.hires = hires;
5568 this.generatedCodeLine = 0;
5569 this.generatedCodeColumn = 0;
5570 this.raw = [];
5571 this.rawSegments = this.raw[this.generatedCodeLine] = [];
5572 this.pending = null;
5573};
5574
5575Mappings.prototype.addEdit = function addEdit (sourceIndex, content, loc, nameIndex) {
5576 if (content.length) {
5577 var segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
5578 if (nameIndex >= 0) {
5579 segment.push(nameIndex);
5580 }
5581 this.rawSegments.push(segment);
5582 } else if (this.pending) {
5583 this.rawSegments.push(this.pending);
5584 }
5585
5586 this.advance(content);
5587 this.pending = null;
5588};
5589
5590Mappings.prototype.addUneditedChunk = function addUneditedChunk (sourceIndex, chunk, original, loc, sourcemapLocations) {
5591 var originalCharIndex = chunk.start;
5592 var first = true;
5593
5594 while (originalCharIndex < chunk.end) {
5595 if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
5596 this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
5597 }
5598
5599 if (original[originalCharIndex] === '\n') {
5600 loc.line += 1;
5601 loc.column = 0;
5602 this.generatedCodeLine += 1;
5603 this.raw[this.generatedCodeLine] = this.rawSegments = [];
5604 this.generatedCodeColumn = 0;
5605 first = true;
5606 } else {
5607 loc.column += 1;
5608 this.generatedCodeColumn += 1;
5609 first = false;
5610 }
5611
5612 originalCharIndex += 1;
5613 }
5614
5615 this.pending = null;
5616};
5617
5618Mappings.prototype.advance = function advance (str) {
5619 if (!str) { return; }
5620
5621 var lines = str.split('\n');
5622
5623 if (lines.length > 1) {
5624 for (var i = 0; i < lines.length - 1; i++) {
5625 this.generatedCodeLine++;
5626 this.raw[this.generatedCodeLine] = this.rawSegments = [];
5627 }
5628 this.generatedCodeColumn = 0;
5629 }
5630
5631 this.generatedCodeColumn += lines[lines.length - 1].length;
5632};
5633
5634var n = '\n';
5635
5636var warned = {
5637 insertLeft: false,
5638 insertRight: false,
5639 storeName: false
5640};
5641
5642var MagicString = function MagicString(string, options) {
5643 if ( options === void 0 ) options = {};
5644
5645 var chunk = new Chunk(0, string.length, string);
5646
5647 Object.defineProperties(this, {
5648 original: { writable: true, value: string },
5649 outro: { writable: true, value: '' },
5650 intro: { writable: true, value: '' },
5651 firstChunk: { writable: true, value: chunk },
5652 lastChunk: { writable: true, value: chunk },
5653 lastSearchedChunk: { writable: true, value: chunk },
5654 byStart: { writable: true, value: {} },
5655 byEnd: { writable: true, value: {} },
5656 filename: { writable: true, value: options.filename },
5657 indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
5658 sourcemapLocations: { writable: true, value: new BitSet() },
5659 storedNames: { writable: true, value: {} },
5660 indentStr: { writable: true, value: guessIndent(string) }
5661 });
5662
5663 this.byStart[0] = chunk;
5664 this.byEnd[string.length] = chunk;
5665};
5666
5667MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
5668 this.sourcemapLocations.add(char);
5669};
5670
5671MagicString.prototype.append = function append (content) {
5672 if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
5673
5674 this.outro += content;
5675 return this;
5676};
5677
5678MagicString.prototype.appendLeft = function appendLeft (index, content) {
5679 if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
5680
5681 this._split(index);
5682
5683 var chunk = this.byEnd[index];
5684
5685 if (chunk) {
5686 chunk.appendLeft(content);
5687 } else {
5688 this.intro += content;
5689 }
5690 return this;
5691};
5692
5693MagicString.prototype.appendRight = function appendRight (index, content) {
5694 if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
5695
5696 this._split(index);
5697
5698 var chunk = this.byStart[index];
5699
5700 if (chunk) {
5701 chunk.appendRight(content);
5702 } else {
5703 this.outro += content;
5704 }
5705 return this;
5706};
5707
5708MagicString.prototype.clone = function clone () {
5709 var cloned = new MagicString(this.original, { filename: this.filename });
5710
5711 var originalChunk = this.firstChunk;
5712 var clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
5713
5714 while (originalChunk) {
5715 cloned.byStart[clonedChunk.start] = clonedChunk;
5716 cloned.byEnd[clonedChunk.end] = clonedChunk;
5717
5718 var nextOriginalChunk = originalChunk.next;
5719 var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
5720
5721 if (nextClonedChunk) {
5722 clonedChunk.next = nextClonedChunk;
5723 nextClonedChunk.previous = clonedChunk;
5724
5725 clonedChunk = nextClonedChunk;
5726 }
5727
5728 originalChunk = nextOriginalChunk;
5729 }
5730
5731 cloned.lastChunk = clonedChunk;
5732
5733 if (this.indentExclusionRanges) {
5734 cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
5735 }
5736
5737 cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
5738
5739 cloned.intro = this.intro;
5740 cloned.outro = this.outro;
5741
5742 return cloned;
5743};
5744
5745MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
5746 var this$1 = this;
5747
5748 options = options || {};
5749
5750 var sourceIndex = 0;
5751 var names = Object.keys(this.storedNames);
5752 var mappings = new Mappings(options.hires);
5753
5754 var locate = getLocator(this.original);
5755
5756 if (this.intro) {
5757 mappings.advance(this.intro);
5758 }
5759
5760 this.firstChunk.eachNext(function (chunk) {
5761 var loc = locate(chunk.start);
5762
5763 if (chunk.intro.length) { mappings.advance(chunk.intro); }
5764
5765 if (chunk.edited) {
5766 mappings.addEdit(
5767 sourceIndex,
5768 chunk.content,
5769 loc,
5770 chunk.storeName ? names.indexOf(chunk.original) : -1
5771 );
5772 } else {
5773 mappings.addUneditedChunk(sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations);
5774 }
5775
5776 if (chunk.outro.length) { mappings.advance(chunk.outro); }
5777 });
5778
5779 return {
5780 file: options.file ? options.file.split(/[/\\]/).pop() : null,
5781 sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
5782 sourcesContent: options.includeContent ? [this.original] : [null],
5783 names: names,
5784 mappings: mappings.raw
5785 };
5786};
5787
5788MagicString.prototype.generateMap = function generateMap (options) {
5789 return new SourceMap(this.generateDecodedMap(options));
5790};
5791
5792MagicString.prototype.getIndentString = function getIndentString () {
5793 return this.indentStr === null ? '\t' : this.indentStr;
5794};
5795
5796MagicString.prototype.indent = function indent (indentStr, options) {
5797 var pattern = /^[^\r\n]/gm;
5798
5799 if (isObject(indentStr)) {
5800 options = indentStr;
5801 indentStr = undefined;
5802 }
5803
5804 indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
5805
5806 if (indentStr === '') { return this; } // noop
5807
5808 options = options || {};
5809
5810 // Process exclusion ranges
5811 var isExcluded = {};
5812
5813 if (options.exclude) {
5814 var exclusions =
5815 typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
5816 exclusions.forEach(function (exclusion) {
5817 for (var i = exclusion[0]; i < exclusion[1]; i += 1) {
5818 isExcluded[i] = true;
5819 }
5820 });
5821 }
5822
5823 var shouldIndentNextCharacter = options.indentStart !== false;
5824 var replacer = function (match) {
5825 if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
5826 shouldIndentNextCharacter = true;
5827 return match;
5828 };
5829
5830 this.intro = this.intro.replace(pattern, replacer);
5831
5832 var charIndex = 0;
5833 var chunk = this.firstChunk;
5834
5835 while (chunk) {
5836 var end = chunk.end;
5837
5838 if (chunk.edited) {
5839 if (!isExcluded[charIndex]) {
5840 chunk.content = chunk.content.replace(pattern, replacer);
5841
5842 if (chunk.content.length) {
5843 shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
5844 }
5845 }
5846 } else {
5847 charIndex = chunk.start;
5848
5849 while (charIndex < end) {
5850 if (!isExcluded[charIndex]) {
5851 var char = this.original[charIndex];
5852
5853 if (char === '\n') {
5854 shouldIndentNextCharacter = true;
5855 } else if (char !== '\r' && shouldIndentNextCharacter) {
5856 shouldIndentNextCharacter = false;
5857
5858 if (charIndex === chunk.start) {
5859 chunk.prependRight(indentStr);
5860 } else {
5861 this._splitChunk(chunk, charIndex);
5862 chunk = chunk.next;
5863 chunk.prependRight(indentStr);
5864 }
5865 }
5866 }
5867
5868 charIndex += 1;
5869 }
5870 }
5871
5872 charIndex = chunk.end;
5873 chunk = chunk.next;
5874 }
5875
5876 this.outro = this.outro.replace(pattern, replacer);
5877
5878 return this;
5879};
5880
5881MagicString.prototype.insert = function insert () {
5882 throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
5883};
5884
5885MagicString.prototype.insertLeft = function insertLeft (index, content) {
5886 if (!warned.insertLeft) {
5887 console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
5888 warned.insertLeft = true;
5889 }
5890
5891 return this.appendLeft(index, content);
5892};
5893
5894MagicString.prototype.insertRight = function insertRight (index, content) {
5895 if (!warned.insertRight) {
5896 console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
5897 warned.insertRight = true;
5898 }
5899
5900 return this.prependRight(index, content);
5901};
5902
5903MagicString.prototype.move = function move (start, end, index) {
5904 if (index >= start && index <= end) { throw new Error('Cannot move a selection inside itself'); }
5905
5906 this._split(start);
5907 this._split(end);
5908 this._split(index);
5909
5910 var first = this.byStart[start];
5911 var last = this.byEnd[end];
5912
5913 var oldLeft = first.previous;
5914 var oldRight = last.next;
5915
5916 var newRight = this.byStart[index];
5917 if (!newRight && last === this.lastChunk) { return this; }
5918 var newLeft = newRight ? newRight.previous : this.lastChunk;
5919
5920 if (oldLeft) { oldLeft.next = oldRight; }
5921 if (oldRight) { oldRight.previous = oldLeft; }
5922
5923 if (newLeft) { newLeft.next = first; }
5924 if (newRight) { newRight.previous = last; }
5925
5926 if (!first.previous) { this.firstChunk = last.next; }
5927 if (!last.next) {
5928 this.lastChunk = first.previous;
5929 this.lastChunk.next = null;
5930 }
5931
5932 first.previous = newLeft;
5933 last.next = newRight || null;
5934
5935 if (!newLeft) { this.firstChunk = first; }
5936 if (!newRight) { this.lastChunk = last; }
5937 return this;
5938};
5939
5940MagicString.prototype.overwrite = function overwrite (start, end, content, options) {
5941 if (typeof content !== 'string') { throw new TypeError('replacement content must be a string'); }
5942
5943 while (start < 0) { start += this.original.length; }
5944 while (end < 0) { end += this.original.length; }
5945
5946 if (end > this.original.length) { throw new Error('end is out of bounds'); }
5947 if (start === end)
5948 { throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
5949
5950 this._split(start);
5951 this._split(end);
5952
5953 if (options === true) {
5954 if (!warned.storeName) {
5955 console.warn('The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'); // eslint-disable-line no-console
5956 warned.storeName = true;
5957 }
5958
5959 options = { storeName: true };
5960 }
5961 var storeName = options !== undefined ? options.storeName : false;
5962 var contentOnly = options !== undefined ? options.contentOnly : false;
5963
5964 if (storeName) {
5965 var original = this.original.slice(start, end);
5966 this.storedNames[original] = true;
5967 }
5968
5969 var first = this.byStart[start];
5970 var last = this.byEnd[end];
5971
5972 if (first) {
5973 if (end > first.end && first.next !== this.byStart[first.end]) {
5974 throw new Error('Cannot overwrite across a split point');
5975 }
5976
5977 first.edit(content, storeName, contentOnly);
5978
5979 if (first !== last) {
5980 var chunk = first.next;
5981 while (chunk !== last) {
5982 chunk.edit('', false);
5983 chunk = chunk.next;
5984 }
5985
5986 chunk.edit('', false);
5987 }
5988 } else {
5989 // must be inserting at the end
5990 var newChunk = new Chunk(start, end, '').edit(content, storeName);
5991
5992 // TODO last chunk in the array may not be the last chunk, if it's moved...
5993 last.next = newChunk;
5994 newChunk.previous = last;
5995 }
5996 return this;
5997};
5998
5999MagicString.prototype.prepend = function prepend (content) {
6000 if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
6001
6002 this.intro = content + this.intro;
6003 return this;
6004};
6005
6006MagicString.prototype.prependLeft = function prependLeft (index, content) {
6007 if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
6008
6009 this._split(index);
6010
6011 var chunk = this.byEnd[index];
6012
6013 if (chunk) {
6014 chunk.prependLeft(content);
6015 } else {
6016 this.intro = content + this.intro;
6017 }
6018 return this;
6019};
6020
6021MagicString.prototype.prependRight = function prependRight (index, content) {
6022 if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
6023
6024 this._split(index);
6025
6026 var chunk = this.byStart[index];
6027
6028 if (chunk) {
6029 chunk.prependRight(content);
6030 } else {
6031 this.outro = content + this.outro;
6032 }
6033 return this;
6034};
6035
6036MagicString.prototype.remove = function remove (start, end) {
6037 while (start < 0) { start += this.original.length; }
6038 while (end < 0) { end += this.original.length; }
6039
6040 if (start === end) { return this; }
6041
6042 if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); }
6043 if (start > end) { throw new Error('end must be greater than start'); }
6044
6045 this._split(start);
6046 this._split(end);
6047
6048 var chunk = this.byStart[start];
6049
6050 while (chunk) {
6051 chunk.intro = '';
6052 chunk.outro = '';
6053 chunk.edit('');
6054
6055 chunk = end > chunk.end ? this.byStart[chunk.end] : null;
6056 }
6057 return this;
6058};
6059
6060MagicString.prototype.lastChar = function lastChar () {
6061 if (this.outro.length)
6062 { return this.outro[this.outro.length - 1]; }
6063 var chunk = this.lastChunk;
6064 do {
6065 if (chunk.outro.length)
6066 { return chunk.outro[chunk.outro.length - 1]; }
6067 if (chunk.content.length)
6068 { return chunk.content[chunk.content.length - 1]; }
6069 if (chunk.intro.length)
6070 { return chunk.intro[chunk.intro.length - 1]; }
6071 } while (chunk = chunk.previous);
6072 if (this.intro.length)
6073 { return this.intro[this.intro.length - 1]; }
6074 return '';
6075};
6076
6077MagicString.prototype.lastLine = function lastLine () {
6078 var lineIndex = this.outro.lastIndexOf(n);
6079 if (lineIndex !== -1)
6080 { return this.outro.substr(lineIndex + 1); }
6081 var lineStr = this.outro;
6082 var chunk = this.lastChunk;
6083 do {
6084 if (chunk.outro.length > 0) {
6085 lineIndex = chunk.outro.lastIndexOf(n);
6086 if (lineIndex !== -1)
6087 { return chunk.outro.substr(lineIndex + 1) + lineStr; }
6088 lineStr = chunk.outro + lineStr;
6089 }
6090
6091 if (chunk.content.length > 0) {
6092 lineIndex = chunk.content.lastIndexOf(n);
6093 if (lineIndex !== -1)
6094 { return chunk.content.substr(lineIndex + 1) + lineStr; }
6095 lineStr = chunk.content + lineStr;
6096 }
6097
6098 if (chunk.intro.length > 0) {
6099 lineIndex = chunk.intro.lastIndexOf(n);
6100 if (lineIndex !== -1)
6101 { return chunk.intro.substr(lineIndex + 1) + lineStr; }
6102 lineStr = chunk.intro + lineStr;
6103 }
6104 } while (chunk = chunk.previous);
6105 lineIndex = this.intro.lastIndexOf(n);
6106 if (lineIndex !== -1)
6107 { return this.intro.substr(lineIndex + 1) + lineStr; }
6108 return this.intro + lineStr;
6109};
6110
6111MagicString.prototype.slice = function slice (start, end) {
6112 if ( start === void 0 ) start = 0;
6113 if ( end === void 0 ) end = this.original.length;
6114
6115 while (start < 0) { start += this.original.length; }
6116 while (end < 0) { end += this.original.length; }
6117
6118 var result = '';
6119
6120 // find start chunk
6121 var chunk = this.firstChunk;
6122 while (chunk && (chunk.start > start || chunk.end <= start)) {
6123 // found end chunk before start
6124 if (chunk.start < end && chunk.end >= end) {
6125 return result;
6126 }
6127
6128 chunk = chunk.next;
6129 }
6130
6131 if (chunk && chunk.edited && chunk.start !== start)
6132 { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
6133
6134 var startChunk = chunk;
6135 while (chunk) {
6136 if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
6137 result += chunk.intro;
6138 }
6139
6140 var containsEnd = chunk.start < end && chunk.end >= end;
6141 if (containsEnd && chunk.edited && chunk.end !== end)
6142 { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
6143
6144 var sliceStart = startChunk === chunk ? start - chunk.start : 0;
6145 var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
6146
6147 result += chunk.content.slice(sliceStart, sliceEnd);
6148
6149 if (chunk.outro && (!containsEnd || chunk.end === end)) {
6150 result += chunk.outro;
6151 }
6152
6153 if (containsEnd) {
6154 break;
6155 }
6156
6157 chunk = chunk.next;
6158 }
6159
6160 return result;
6161};
6162
6163// TODO deprecate this? not really very useful
6164MagicString.prototype.snip = function snip (start, end) {
6165 var clone = this.clone();
6166 clone.remove(0, start);
6167 clone.remove(end, clone.original.length);
6168
6169 return clone;
6170};
6171
6172MagicString.prototype._split = function _split (index) {
6173 if (this.byStart[index] || this.byEnd[index]) { return; }
6174
6175 var chunk = this.lastSearchedChunk;
6176 var searchForward = index > chunk.end;
6177
6178 while (chunk) {
6179 if (chunk.contains(index)) { return this._splitChunk(chunk, index); }
6180
6181 chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
6182 }
6183};
6184
6185MagicString.prototype._splitChunk = function _splitChunk (chunk, index) {
6186 if (chunk.edited && chunk.content.length) {
6187 // zero-length edited chunks are a special case (overlapping replacements)
6188 var loc = getLocator(this.original)(index);
6189 throw new Error(
6190 ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")")
6191 );
6192 }
6193
6194 var newChunk = chunk.split(index);
6195
6196 this.byEnd[index] = chunk;
6197 this.byStart[index] = newChunk;
6198 this.byEnd[newChunk.end] = newChunk;
6199
6200 if (chunk === this.lastChunk) { this.lastChunk = newChunk; }
6201
6202 this.lastSearchedChunk = chunk;
6203 return true;
6204};
6205
6206MagicString.prototype.toString = function toString () {
6207 var str = this.intro;
6208
6209 var chunk = this.firstChunk;
6210 while (chunk) {
6211 str += chunk.toString();
6212 chunk = chunk.next;
6213 }
6214
6215 return str + this.outro;
6216};
6217
6218MagicString.prototype.isEmpty = function isEmpty () {
6219 var chunk = this.firstChunk;
6220 do {
6221 if (chunk.intro.length && chunk.intro.trim() ||
6222 chunk.content.length && chunk.content.trim() ||
6223 chunk.outro.length && chunk.outro.trim())
6224 { return false; }
6225 } while (chunk = chunk.next);
6226 return true;
6227};
6228
6229MagicString.prototype.length = function length () {
6230 var chunk = this.firstChunk;
6231 var length = 0;
6232 do {
6233 length += chunk.intro.length + chunk.content.length + chunk.outro.length;
6234 } while (chunk = chunk.next);
6235 return length;
6236};
6237
6238MagicString.prototype.trimLines = function trimLines () {
6239 return this.trim('[\\r\\n]');
6240};
6241
6242MagicString.prototype.trim = function trim (charType) {
6243 return this.trimStart(charType).trimEnd(charType);
6244};
6245
6246MagicString.prototype.trimEndAborted = function trimEndAborted (charType) {
6247 var rx = new RegExp((charType || '\\s') + '+$');
6248
6249 this.outro = this.outro.replace(rx, '');
6250 if (this.outro.length) { return true; }
6251
6252 var chunk = this.lastChunk;
6253
6254 do {
6255 var end = chunk.end;
6256 var aborted = chunk.trimEnd(rx);
6257
6258 // if chunk was trimmed, we have a new lastChunk
6259 if (chunk.end !== end) {
6260 if (this.lastChunk === chunk) {
6261 this.lastChunk = chunk.next;
6262 }
6263
6264 this.byEnd[chunk.end] = chunk;
6265 this.byStart[chunk.next.start] = chunk.next;
6266 this.byEnd[chunk.next.end] = chunk.next;
6267 }
6268
6269 if (aborted) { return true; }
6270 chunk = chunk.previous;
6271 } while (chunk);
6272
6273 return false;
6274};
6275
6276MagicString.prototype.trimEnd = function trimEnd (charType) {
6277 this.trimEndAborted(charType);
6278 return this;
6279};
6280MagicString.prototype.trimStartAborted = function trimStartAborted (charType) {
6281 var rx = new RegExp('^' + (charType || '\\s') + '+');
6282
6283 this.intro = this.intro.replace(rx, '');
6284 if (this.intro.length) { return true; }
6285
6286 var chunk = this.firstChunk;
6287
6288 do {
6289 var end = chunk.end;
6290 var aborted = chunk.trimStart(rx);
6291
6292 if (chunk.end !== end) {
6293 // special case...
6294 if (chunk === this.lastChunk) { this.lastChunk = chunk.next; }
6295
6296 this.byEnd[chunk.end] = chunk;
6297 this.byStart[chunk.next.start] = chunk.next;
6298 this.byEnd[chunk.next.end] = chunk.next;
6299 }
6300
6301 if (aborted) { return true; }
6302 chunk = chunk.next;
6303 } while (chunk);
6304
6305 return false;
6306};
6307
6308MagicString.prototype.trimStart = function trimStart (charType) {
6309 this.trimStartAborted(charType);
6310 return this;
6311};
6312
6313/**
6314 * Conditionally log a message
6315 * @param {string} message
6316 * @param {Array<any>} passed
6317 */
6318function log(message, ...passed) {
6319}
6320
6321const DEFAULT_ACORN_OPTIONS = {
6322 ecmaVersion: 2020,
6323 sourceType: 'module',
6324 preserveParens: false,
6325 ranges: true,
6326};
6327
6328/**
6329 * Parse filePath contents into a Program.
6330 * @param {string} filePath
6331 * @return {[Promise<acorn.Program>, MagicString]}
6332 */
6333async function parse(filePath) {
6334 try {
6335 const contents = await promises.readFile(filePath, 'utf8');
6336 const parse = Parser.parse(contents, DEFAULT_ACORN_OPTIONS);
6337 const magic = new MagicString(contents);
6338 return [parse, magic];
6339 } catch (e) {
6340 throw e;
6341 }
6342}
6343
6344class WalkerBase {constructor() { WalkerBase.prototype.__init.call(this);WalkerBase.prototype.__init2.call(this);WalkerBase.prototype.__init3.call(this);WalkerBase.prototype.__init4.call(this); }
6345 __init() {this.should_skip = false;}
6346 __init2() {this.should_remove = false;}
6347 __init3() {this.replacement = null;}
6348
6349 __init4() {this.context = {
6350 skip: () => (this.should_skip = true),
6351 remove: () => (this.should_remove = true),
6352 replace: (node) => (this.replacement = node)
6353 };}
6354
6355 replace(parent, prop, index, node) {
6356 if (parent) {
6357 if (index !== null) {
6358 parent[prop][index] = node;
6359 } else {
6360 parent[prop] = node;
6361 }
6362 }
6363 }
6364
6365 remove(parent, prop, index) {
6366 if (parent) {
6367 if (index !== null) {
6368 parent[prop].splice(index, 1);
6369 } else {
6370 delete parent[prop];
6371 }
6372 }
6373 }
6374}
6375
6376class AsyncWalkerClass extends WalkerBase {
6377
6378
6379
6380 constructor(walker) {
6381 super();
6382 this.enter = walker.enter;
6383 this.leave = walker.leave;
6384 }
6385
6386 async visit(
6387 node,
6388 parent,
6389 enter,
6390 leave,
6391 prop,
6392 index
6393 ) {
6394 if (node) {
6395 if (enter) {
6396 const _should_skip = this.should_skip;
6397 const _should_remove = this.should_remove;
6398 const _replacement = this.replacement;
6399 this.should_skip = false;
6400 this.should_remove = false;
6401 this.replacement = null;
6402
6403 await enter.call(this.context, node, parent, prop, index);
6404
6405 if (this.replacement) {
6406 node = this.replacement;
6407 this.replace(parent, prop, index, node);
6408 }
6409
6410 if (this.should_remove) {
6411 this.remove(parent, prop, index);
6412 }
6413
6414 const skipped = this.should_skip;
6415 const removed = this.should_remove;
6416
6417 this.should_skip = _should_skip;
6418 this.should_remove = _should_remove;
6419 this.replacement = _replacement;
6420
6421 if (skipped) return node;
6422 if (removed) return null;
6423 }
6424
6425 for (const key in node) {
6426 const value = (node )[key];
6427
6428 if (typeof value !== "object") {
6429 continue;
6430 } else if (Array.isArray(value)) {
6431 for (let i = 0; i < value.length; i += 1) {
6432 if (value[i] !== null && typeof value[i].type === 'string') {
6433 if (!(await this.visit(value[i], node, enter, leave, key, i))) {
6434 // removed
6435 i--;
6436 }
6437 }
6438 }
6439 } else if (value !== null && typeof value.type === "string") {
6440 await this.visit(value, node, enter, leave, key, null);
6441 }
6442 }
6443
6444 if (leave) {
6445 const _replacement = this.replacement;
6446 const _should_remove = this.should_remove;
6447 this.replacement = null;
6448 this.should_remove = false;
6449
6450 await leave.call(this.context, node, parent, prop, index);
6451
6452 if (this.replacement) {
6453 node = this.replacement;
6454 this.replace(parent, prop, index, node);
6455 }
6456
6457 if (this.should_remove) {
6458 this.remove(parent, prop, index);
6459 }
6460
6461 const removed = this.should_remove;
6462
6463 this.replacement = _replacement;
6464 this.should_remove = _should_remove;
6465
6466 if (removed) return null;
6467 }
6468 }
6469
6470 return node;
6471 }
6472}
6473
6474async function asyncWalk(
6475 ast,
6476 walker
6477) {
6478 const instance = new AsyncWalkerClass(walker);
6479 return await instance.visit(ast, null, walker.enter, walker.leave);
6480}
6481
6482var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6483
6484function createCommonjsModule(fn) {
6485 var module = { exports: {} };
6486 return fn(module, module.exports), module.exports;
6487}
6488
6489/* eslint no-invalid-this: 1 */
6490
6491var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
6492var slice$1 = Array.prototype.slice;
6493var toStr$9 = Object.prototype.toString;
6494var funcType = '[object Function]';
6495
6496var implementation$3 = function bind(that) {
6497 var target = this;
6498 if (typeof target !== 'function' || toStr$9.call(target) !== funcType) {
6499 throw new TypeError(ERROR_MESSAGE + target);
6500 }
6501 var args = slice$1.call(arguments, 1);
6502
6503 var bound;
6504 var binder = function () {
6505 if (this instanceof bound) {
6506 var result = target.apply(
6507 this,
6508 args.concat(slice$1.call(arguments))
6509 );
6510 if (Object(result) === result) {
6511 return result;
6512 }
6513 return this;
6514 } else {
6515 return target.apply(
6516 that,
6517 args.concat(slice$1.call(arguments))
6518 );
6519 }
6520 };
6521
6522 var boundLength = Math.max(0, target.length - args.length);
6523 var boundArgs = [];
6524 for (var i = 0; i < boundLength; i++) {
6525 boundArgs.push('$' + i);
6526 }
6527
6528 bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
6529
6530 if (target.prototype) {
6531 var Empty = function Empty() {};
6532 Empty.prototype = target.prototype;
6533 bound.prototype = new Empty();
6534 Empty.prototype = null;
6535 }
6536
6537 return bound;
6538};
6539
6540var functionBind = Function.prototype.bind || implementation$3;
6541
6542/* eslint complexity: [2, 18], max-statements: [2, 33] */
6543var shams = function hasSymbols() {
6544 if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
6545 if (typeof Symbol.iterator === 'symbol') { return true; }
6546
6547 var obj = {};
6548 var sym = Symbol('test');
6549 var symObj = Object(sym);
6550 if (typeof sym === 'string') { return false; }
6551
6552 if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }
6553 if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }
6554
6555 // temp disabled per https://github.com/ljharb/object.assign/issues/17
6556 // if (sym instanceof Symbol) { return false; }
6557 // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
6558 // if (!(symObj instanceof Symbol)) { return false; }
6559
6560 // if (typeof Symbol.prototype.toString !== 'function') { return false; }
6561 // if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; }
6562
6563 var symVal = 42;
6564 obj[sym] = symVal;
6565 for (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax
6566 if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }
6567
6568 if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }
6569
6570 var syms = Object.getOwnPropertySymbols(obj);
6571 if (syms.length !== 1 || syms[0] !== sym) { return false; }
6572
6573 if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }
6574
6575 if (typeof Object.getOwnPropertyDescriptor === 'function') {
6576 var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
6577 if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
6578 }
6579
6580 return true;
6581};
6582
6583var origSymbol = commonjsGlobal.Symbol;
6584
6585
6586var hasSymbols$4 = function hasNativeSymbols() {
6587 if (typeof origSymbol !== 'function') { return false; }
6588 if (typeof Symbol !== 'function') { return false; }
6589 if (typeof origSymbol('foo') !== 'symbol') { return false; }
6590 if (typeof Symbol('bar') !== 'symbol') { return false; }
6591
6592 return shams();
6593};
6594
6595var src = functionBind.call(Function.call, Object.prototype.hasOwnProperty);
6596
6597var undefined$1;
6598
6599var $SyntaxError$1 = SyntaxError;
6600var $Function = Function;
6601var $TypeError$g = TypeError;
6602
6603// eslint-disable-next-line consistent-return
6604var getEvalledConstructor = function (expressionSyntax) {
6605 try {
6606 return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')();
6607 } catch (e) {}
6608};
6609
6610var $gOPD$1 = Object.getOwnPropertyDescriptor;
6611if ($gOPD$1) {
6612 try {
6613 $gOPD$1({}, '');
6614 } catch (e) {
6615 $gOPD$1 = null; // this is IE 8, which has a broken gOPD
6616 }
6617}
6618
6619var throwTypeError = function () {
6620 throw new $TypeError$g();
6621};
6622var ThrowTypeError = $gOPD$1
6623 ? (function () {
6624 try {
6625 // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties
6626 arguments.callee; // IE 8 does not throw here
6627 return throwTypeError;
6628 } catch (calleeThrows) {
6629 try {
6630 // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '')
6631 return $gOPD$1(arguments, 'callee').get;
6632 } catch (gOPDthrows) {
6633 return throwTypeError;
6634 }
6635 }
6636 }())
6637 : throwTypeError;
6638
6639var hasSymbols$3 = hasSymbols$4();
6640
6641var getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto
6642
6643var needsEval = {};
6644
6645var TypedArray = typeof Uint8Array === 'undefined' ? undefined$1 : getProto(Uint8Array);
6646
6647var INTRINSICS = {
6648 '%AggregateError%': typeof AggregateError === 'undefined' ? undefined$1 : AggregateError,
6649 '%Array%': Array,
6650 '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer,
6651 '%ArrayIteratorPrototype%': hasSymbols$3 ? getProto([][Symbol.iterator]()) : undefined$1,
6652 '%AsyncFromSyncIteratorPrototype%': undefined$1,
6653 '%AsyncFunction%': needsEval,
6654 '%AsyncGenerator%': needsEval,
6655 '%AsyncGeneratorFunction%': needsEval,
6656 '%AsyncIteratorPrototype%': needsEval,
6657 '%Atomics%': typeof Atomics === 'undefined' ? undefined$1 : Atomics,
6658 '%BigInt%': typeof BigInt === 'undefined' ? undefined$1 : BigInt,
6659 '%Boolean%': Boolean,
6660 '%DataView%': typeof DataView === 'undefined' ? undefined$1 : DataView,
6661 '%Date%': Date,
6662 '%decodeURI%': decodeURI,
6663 '%decodeURIComponent%': decodeURIComponent,
6664 '%encodeURI%': encodeURI,
6665 '%encodeURIComponent%': encodeURIComponent,
6666 '%Error%': Error,
6667 '%eval%': eval, // eslint-disable-line no-eval
6668 '%EvalError%': EvalError,
6669 '%Float32Array%': typeof Float32Array === 'undefined' ? undefined$1 : Float32Array,
6670 '%Float64Array%': typeof Float64Array === 'undefined' ? undefined$1 : Float64Array,
6671 '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined$1 : FinalizationRegistry,
6672 '%Function%': $Function,
6673 '%GeneratorFunction%': needsEval,
6674 '%Int8Array%': typeof Int8Array === 'undefined' ? undefined$1 : Int8Array,
6675 '%Int16Array%': typeof Int16Array === 'undefined' ? undefined$1 : Int16Array,
6676 '%Int32Array%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array,
6677 '%isFinite%': isFinite,
6678 '%isNaN%': isNaN,
6679 '%IteratorPrototype%': hasSymbols$3 ? getProto(getProto([][Symbol.iterator]())) : undefined$1,
6680 '%JSON%': typeof JSON === 'object' ? JSON : undefined$1,
6681 '%Map%': typeof Map === 'undefined' ? undefined$1 : Map,
6682 '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols$3 ? undefined$1 : getProto(new Map()[Symbol.iterator]()),
6683 '%Math%': Math,
6684 '%Number%': Number,
6685 '%Object%': Object,
6686 '%parseFloat%': parseFloat,
6687 '%parseInt%': parseInt,
6688 '%Promise%': typeof Promise === 'undefined' ? undefined$1 : Promise,
6689 '%Proxy%': typeof Proxy === 'undefined' ? undefined$1 : Proxy,
6690 '%RangeError%': RangeError,
6691 '%ReferenceError%': ReferenceError,
6692 '%Reflect%': typeof Reflect === 'undefined' ? undefined$1 : Reflect,
6693 '%RegExp%': RegExp,
6694 '%Set%': typeof Set === 'undefined' ? undefined$1 : Set,
6695 '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols$3 ? undefined$1 : getProto(new Set()[Symbol.iterator]()),
6696 '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer,
6697 '%String%': String,
6698 '%StringIteratorPrototype%': hasSymbols$3 ? getProto(''[Symbol.iterator]()) : undefined$1,
6699 '%Symbol%': hasSymbols$3 ? Symbol : undefined$1,
6700 '%SyntaxError%': $SyntaxError$1,
6701 '%ThrowTypeError%': ThrowTypeError,
6702 '%TypedArray%': TypedArray,
6703 '%TypeError%': $TypeError$g,
6704 '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined$1 : Uint8Array,
6705 '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined$1 : Uint8ClampedArray,
6706 '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined$1 : Uint16Array,
6707 '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined$1 : Uint32Array,
6708 '%URIError%': URIError,
6709 '%WeakMap%': typeof WeakMap === 'undefined' ? undefined$1 : WeakMap,
6710 '%WeakRef%': typeof WeakRef === 'undefined' ? undefined$1 : WeakRef,
6711 '%WeakSet%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet
6712};
6713
6714var doEval = function doEval(name) {
6715 var value;
6716 if (name === '%AsyncFunction%') {
6717 value = getEvalledConstructor('async function () {}');
6718 } else if (name === '%GeneratorFunction%') {
6719 value = getEvalledConstructor('function* () {}');
6720 } else if (name === '%AsyncGeneratorFunction%') {
6721 value = getEvalledConstructor('async function* () {}');
6722 } else if (name === '%AsyncGenerator%') {
6723 var fn = doEval('%AsyncGeneratorFunction%');
6724 if (fn) {
6725 value = fn.prototype;
6726 }
6727 } else if (name === '%AsyncIteratorPrototype%') {
6728 var gen = doEval('%AsyncGenerator%');
6729 if (gen) {
6730 value = getProto(gen.prototype);
6731 }
6732 }
6733
6734 INTRINSICS[name] = value;
6735
6736 return value;
6737};
6738
6739var LEGACY_ALIASES = {
6740 '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'],
6741 '%ArrayPrototype%': ['Array', 'prototype'],
6742 '%ArrayProto_entries%': ['Array', 'prototype', 'entries'],
6743 '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'],
6744 '%ArrayProto_keys%': ['Array', 'prototype', 'keys'],
6745 '%ArrayProto_values%': ['Array', 'prototype', 'values'],
6746 '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'],
6747 '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'],
6748 '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'],
6749 '%BooleanPrototype%': ['Boolean', 'prototype'],
6750 '%DataViewPrototype%': ['DataView', 'prototype'],
6751 '%DatePrototype%': ['Date', 'prototype'],
6752 '%ErrorPrototype%': ['Error', 'prototype'],
6753 '%EvalErrorPrototype%': ['EvalError', 'prototype'],
6754 '%Float32ArrayPrototype%': ['Float32Array', 'prototype'],
6755 '%Float64ArrayPrototype%': ['Float64Array', 'prototype'],
6756 '%FunctionPrototype%': ['Function', 'prototype'],
6757 '%Generator%': ['GeneratorFunction', 'prototype'],
6758 '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'],
6759 '%Int8ArrayPrototype%': ['Int8Array', 'prototype'],
6760 '%Int16ArrayPrototype%': ['Int16Array', 'prototype'],
6761 '%Int32ArrayPrototype%': ['Int32Array', 'prototype'],
6762 '%JSONParse%': ['JSON', 'parse'],
6763 '%JSONStringify%': ['JSON', 'stringify'],
6764 '%MapPrototype%': ['Map', 'prototype'],
6765 '%NumberPrototype%': ['Number', 'prototype'],
6766 '%ObjectPrototype%': ['Object', 'prototype'],
6767 '%ObjProto_toString%': ['Object', 'prototype', 'toString'],
6768 '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'],
6769 '%PromisePrototype%': ['Promise', 'prototype'],
6770 '%PromiseProto_then%': ['Promise', 'prototype', 'then'],
6771 '%Promise_all%': ['Promise', 'all'],
6772 '%Promise_reject%': ['Promise', 'reject'],
6773 '%Promise_resolve%': ['Promise', 'resolve'],
6774 '%RangeErrorPrototype%': ['RangeError', 'prototype'],
6775 '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'],
6776 '%RegExpPrototype%': ['RegExp', 'prototype'],
6777 '%SetPrototype%': ['Set', 'prototype'],
6778 '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'],
6779 '%StringPrototype%': ['String', 'prototype'],
6780 '%SymbolPrototype%': ['Symbol', 'prototype'],
6781 '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'],
6782 '%TypedArrayPrototype%': ['TypedArray', 'prototype'],
6783 '%TypeErrorPrototype%': ['TypeError', 'prototype'],
6784 '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'],
6785 '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'],
6786 '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'],
6787 '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'],
6788 '%URIErrorPrototype%': ['URIError', 'prototype'],
6789 '%WeakMapPrototype%': ['WeakMap', 'prototype'],
6790 '%WeakSetPrototype%': ['WeakSet', 'prototype']
6791};
6792
6793
6794
6795var $concat = functionBind.call(Function.call, Array.prototype.concat);
6796var $spliceApply = functionBind.call(Function.apply, Array.prototype.splice);
6797var $replace$1 = functionBind.call(Function.call, String.prototype.replace);
6798var $strSlice$1 = functionBind.call(Function.call, String.prototype.slice);
6799
6800/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */
6801var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
6802var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */
6803var stringToPath = function stringToPath(string) {
6804 var first = $strSlice$1(string, 0, 1);
6805 var last = $strSlice$1(string, -1);
6806 if (first === '%' && last !== '%') {
6807 throw new $SyntaxError$1('invalid intrinsic syntax, expected closing `%`');
6808 } else if (last === '%' && first !== '%') {
6809 throw new $SyntaxError$1('invalid intrinsic syntax, expected opening `%`');
6810 }
6811 var result = [];
6812 $replace$1(string, rePropName, function (match, number, quote, subString) {
6813 result[result.length] = quote ? $replace$1(subString, reEscapeChar, '$1') : number || match;
6814 });
6815 return result;
6816};
6817/* end adaptation */
6818
6819var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
6820 var intrinsicName = name;
6821 var alias;
6822 if (src(LEGACY_ALIASES, intrinsicName)) {
6823 alias = LEGACY_ALIASES[intrinsicName];
6824 intrinsicName = '%' + alias[0] + '%';
6825 }
6826
6827 if (src(INTRINSICS, intrinsicName)) {
6828 var value = INTRINSICS[intrinsicName];
6829 if (value === needsEval) {
6830 value = doEval(intrinsicName);
6831 }
6832 if (typeof value === 'undefined' && !allowMissing) {
6833 throw new $TypeError$g('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
6834 }
6835
6836 return {
6837 alias: alias,
6838 name: intrinsicName,
6839 value: value
6840 };
6841 }
6842
6843 throw new $SyntaxError$1('intrinsic ' + name + ' does not exist!');
6844};
6845
6846var getIntrinsic = function GetIntrinsic(name, allowMissing) {
6847 if (typeof name !== 'string' || name.length === 0) {
6848 throw new $TypeError$g('intrinsic name must be a non-empty string');
6849 }
6850 if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
6851 throw new $TypeError$g('"allowMissing" argument must be a boolean');
6852 }
6853
6854 var parts = stringToPath(name);
6855 var intrinsicBaseName = parts.length > 0 ? parts[0] : '';
6856
6857 var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing);
6858 var intrinsicRealName = intrinsic.name;
6859 var value = intrinsic.value;
6860 var skipFurtherCaching = false;
6861
6862 var alias = intrinsic.alias;
6863 if (alias) {
6864 intrinsicBaseName = alias[0];
6865 $spliceApply(parts, $concat([0, 1], alias));
6866 }
6867
6868 for (var i = 1, isOwn = true; i < parts.length; i += 1) {
6869 var part = parts[i];
6870 var first = $strSlice$1(part, 0, 1);
6871 var last = $strSlice$1(part, -1);
6872 if (
6873 (
6874 (first === '"' || first === "'" || first === '`')
6875 || (last === '"' || last === "'" || last === '`')
6876 )
6877 && first !== last
6878 ) {
6879 throw new $SyntaxError$1('property names with quotes must have matching quotes');
6880 }
6881 if (part === 'constructor' || !isOwn) {
6882 skipFurtherCaching = true;
6883 }
6884
6885 intrinsicBaseName += '.' + part;
6886 intrinsicRealName = '%' + intrinsicBaseName + '%';
6887
6888 if (src(INTRINSICS, intrinsicRealName)) {
6889 value = INTRINSICS[intrinsicRealName];
6890 } else if (value != null) {
6891 if (!(part in value)) {
6892 if (!allowMissing) {
6893 throw new $TypeError$g('base intrinsic for ' + name + ' exists, but the property is not available.');
6894 }
6895 return void undefined$1;
6896 }
6897 if ($gOPD$1 && (i + 1) >= parts.length) {
6898 var desc = $gOPD$1(value, part);
6899 isOwn = !!desc;
6900
6901 // By convention, when a data property is converted to an accessor
6902 // property to emulate a data property that does not suffer from
6903 // the override mistake, that accessor's getter is marked with
6904 // an `originalValue` property. Here, when we detect this, we
6905 // uphold the illusion by pretending to see that original data
6906 // property, i.e., returning the value rather than the getter
6907 // itself.
6908 if (isOwn && 'get' in desc && !('originalValue' in desc.get)) {
6909 value = desc.get;
6910 } else {
6911 value = value[part];
6912 }
6913 } else {
6914 isOwn = src(value, part);
6915 value = value[part];
6916 }
6917
6918 if (isOwn && !skipFurtherCaching) {
6919 INTRINSICS[intrinsicRealName] = value;
6920 }
6921 }
6922 }
6923 return value;
6924};
6925
6926var callBind = createCommonjsModule(function (module) {
6927
6928
6929
6930
6931var $apply = getIntrinsic('%Function.prototype.apply%');
6932var $call = getIntrinsic('%Function.prototype.call%');
6933var $reflectApply = getIntrinsic('%Reflect.apply%', true) || functionBind.call($call, $apply);
6934
6935var $gOPD = getIntrinsic('%Object.getOwnPropertyDescriptor%', true);
6936var $defineProperty = getIntrinsic('%Object.defineProperty%', true);
6937var $max = getIntrinsic('%Math.max%');
6938
6939if ($defineProperty) {
6940 try {
6941 $defineProperty({}, 'a', { value: 1 });
6942 } catch (e) {
6943 // IE 8 has a broken defineProperty
6944 $defineProperty = null;
6945 }
6946}
6947
6948module.exports = function callBind(originalFunction) {
6949 var func = $reflectApply(functionBind, $call, arguments);
6950 if ($gOPD && $defineProperty) {
6951 var desc = $gOPD(func, 'length');
6952 if (desc.configurable) {
6953 // original length, plus the receiver, minus any additional arguments (after the receiver)
6954 $defineProperty(
6955 func,
6956 'length',
6957 { value: 1 + $max(0, originalFunction.length - (arguments.length - 1)) }
6958 );
6959 }
6960 }
6961 return func;
6962};
6963
6964var applyBind = function applyBind() {
6965 return $reflectApply(functionBind, $apply, arguments);
6966};
6967
6968if ($defineProperty) {
6969 $defineProperty(module.exports, 'apply', { value: applyBind });
6970} else {
6971 module.exports.apply = applyBind;
6972}
6973});
6974
6975var toStr$8 = Object.prototype.toString;
6976
6977var isArguments = function isArguments(value) {
6978 var str = toStr$8.call(value);
6979 var isArgs = str === '[object Arguments]';
6980 if (!isArgs) {
6981 isArgs = str !== '[object Array]' &&
6982 value !== null &&
6983 typeof value === 'object' &&
6984 typeof value.length === 'number' &&
6985 value.length >= 0 &&
6986 toStr$8.call(value.callee) === '[object Function]';
6987 }
6988 return isArgs;
6989};
6990
6991var keysShim$1;
6992if (!Object.keys) {
6993 // modified from https://github.com/es-shims/es5-shim
6994 var has$2 = Object.prototype.hasOwnProperty;
6995 var toStr$7 = Object.prototype.toString;
6996 var isArgs = isArguments; // eslint-disable-line global-require
6997 var isEnumerable$1 = Object.prototype.propertyIsEnumerable;
6998 var hasDontEnumBug = !isEnumerable$1.call({ toString: null }, 'toString');
6999 var hasProtoEnumBug = isEnumerable$1.call(function () {}, 'prototype');
7000 var dontEnums = [
7001 'toString',
7002 'toLocaleString',
7003 'valueOf',
7004 'hasOwnProperty',
7005 'isPrototypeOf',
7006 'propertyIsEnumerable',
7007 'constructor'
7008 ];
7009 var equalsConstructorPrototype = function (o) {
7010 var ctor = o.constructor;
7011 return ctor && ctor.prototype === o;
7012 };
7013 var excludedKeys = {
7014 $applicationCache: true,
7015 $console: true,
7016 $external: true,
7017 $frame: true,
7018 $frameElement: true,
7019 $frames: true,
7020 $innerHeight: true,
7021 $innerWidth: true,
7022 $onmozfullscreenchange: true,
7023 $onmozfullscreenerror: true,
7024 $outerHeight: true,
7025 $outerWidth: true,
7026 $pageXOffset: true,
7027 $pageYOffset: true,
7028 $parent: true,
7029 $scrollLeft: true,
7030 $scrollTop: true,
7031 $scrollX: true,
7032 $scrollY: true,
7033 $self: true,
7034 $webkitIndexedDB: true,
7035 $webkitStorageInfo: true,
7036 $window: true
7037 };
7038 var hasAutomationEqualityBug = (function () {
7039 /* global window */
7040 if (typeof window === 'undefined') { return false; }
7041 for (var k in window) {
7042 try {
7043 if (!excludedKeys['$' + k] && has$2.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
7044 try {
7045 equalsConstructorPrototype(window[k]);
7046 } catch (e) {
7047 return true;
7048 }
7049 }
7050 } catch (e) {
7051 return true;
7052 }
7053 }
7054 return false;
7055 }());
7056 var equalsConstructorPrototypeIfNotBuggy = function (o) {
7057 /* global window */
7058 if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
7059 return equalsConstructorPrototype(o);
7060 }
7061 try {
7062 return equalsConstructorPrototype(o);
7063 } catch (e) {
7064 return false;
7065 }
7066 };
7067
7068 keysShim$1 = function keys(object) {
7069 var isObject = object !== null && typeof object === 'object';
7070 var isFunction = toStr$7.call(object) === '[object Function]';
7071 var isArguments = isArgs(object);
7072 var isString = isObject && toStr$7.call(object) === '[object String]';
7073 var theKeys = [];
7074
7075 if (!isObject && !isFunction && !isArguments) {
7076 throw new TypeError('Object.keys called on a non-object');
7077 }
7078
7079 var skipProto = hasProtoEnumBug && isFunction;
7080 if (isString && object.length > 0 && !has$2.call(object, 0)) {
7081 for (var i = 0; i < object.length; ++i) {
7082 theKeys.push(String(i));
7083 }
7084 }
7085
7086 if (isArguments && object.length > 0) {
7087 for (var j = 0; j < object.length; ++j) {
7088 theKeys.push(String(j));
7089 }
7090 } else {
7091 for (var name in object) {
7092 if (!(skipProto && name === 'prototype') && has$2.call(object, name)) {
7093 theKeys.push(String(name));
7094 }
7095 }
7096 }
7097
7098 if (hasDontEnumBug) {
7099 var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
7100
7101 for (var k = 0; k < dontEnums.length; ++k) {
7102 if (!(skipConstructor && dontEnums[k] === 'constructor') && has$2.call(object, dontEnums[k])) {
7103 theKeys.push(dontEnums[k]);
7104 }
7105 }
7106 }
7107 return theKeys;
7108 };
7109}
7110var implementation$2 = keysShim$1;
7111
7112var slice = Array.prototype.slice;
7113
7114
7115var origKeys = Object.keys;
7116var keysShim = origKeys ? function keys(o) { return origKeys(o); } : implementation$2;
7117
7118var originalKeys = Object.keys;
7119
7120keysShim.shim = function shimObjectKeys() {
7121 if (Object.keys) {
7122 var keysWorksWithArguments = (function () {
7123 // Safari 5.0 bug
7124 var args = Object.keys(arguments);
7125 return args && args.length === arguments.length;
7126 }(1, 2));
7127 if (!keysWorksWithArguments) {
7128 Object.keys = function keys(object) { // eslint-disable-line func-name-matching
7129 if (isArguments(object)) {
7130 return originalKeys(slice.call(object));
7131 }
7132 return originalKeys(object);
7133 };
7134 }
7135 } else {
7136 Object.keys = keysShim;
7137 }
7138 return Object.keys || keysShim;
7139};
7140
7141var objectKeys = keysShim;
7142
7143var hasSymbols$2 = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
7144
7145var toStr$6 = Object.prototype.toString;
7146var concat = Array.prototype.concat;
7147var origDefineProperty = Object.defineProperty;
7148
7149var isFunction = function (fn) {
7150 return typeof fn === 'function' && toStr$6.call(fn) === '[object Function]';
7151};
7152
7153var arePropertyDescriptorsSupported = function () {
7154 var obj = {};
7155 try {
7156 origDefineProperty(obj, 'x', { enumerable: false, value: obj });
7157 // eslint-disable-next-line no-unused-vars, no-restricted-syntax
7158 for (var _ in obj) { // jscs:ignore disallowUnusedVariables
7159 return false;
7160 }
7161 return obj.x === obj;
7162 } catch (e) { /* this is IE 8. */
7163 return false;
7164 }
7165};
7166var supportsDescriptors = origDefineProperty && arePropertyDescriptorsSupported();
7167
7168var defineProperty = function (object, name, value, predicate) {
7169 if (name in object && (!isFunction(predicate) || !predicate())) {
7170 return;
7171 }
7172 if (supportsDescriptors) {
7173 origDefineProperty(object, name, {
7174 configurable: true,
7175 enumerable: false,
7176 value: value,
7177 writable: true
7178 });
7179 } else {
7180 object[name] = value;
7181 }
7182};
7183
7184var defineProperties = function (object, map) {
7185 var predicates = arguments.length > 2 ? arguments[2] : {};
7186 var props = objectKeys(map);
7187 if (hasSymbols$2) {
7188 props = concat.call(props, Object.getOwnPropertySymbols(map));
7189 }
7190 for (var i = 0; i < props.length; i += 1) {
7191 defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
7192 }
7193};
7194
7195defineProperties.supportsDescriptors = !!supportsDescriptors;
7196
7197var defineProperties_1 = defineProperties;
7198
7199var requirePromise = function requirePromise() {
7200 if (typeof Promise !== 'function') {
7201 throw new TypeError('`Promise.allSettled` requires a global `Promise` be available.');
7202 }
7203};
7204
7205var $resolve = getIntrinsic('%Promise.resolve%', true);
7206var $PromiseResolve = $resolve && callBind($resolve);
7207
7208// https://262.ecma-international.org/9.0/#sec-promise-resolve
7209
7210var PromiseResolve = function PromiseResolve(C, x) {
7211 if (!$PromiseResolve) {
7212 throw new SyntaxError('This environment does not support Promises.');
7213 }
7214 return $PromiseResolve(C, x);
7215};
7216
7217// https://262.ecma-international.org/5.1/#sec-8
7218
7219var Type$1 = function Type(x) {
7220 if (x === null) {
7221 return 'Null';
7222 }
7223 if (typeof x === 'undefined') {
7224 return 'Undefined';
7225 }
7226 if (typeof x === 'function' || typeof x === 'object') {
7227 return 'Object';
7228 }
7229 if (typeof x === 'number') {
7230 return 'Number';
7231 }
7232 if (typeof x === 'boolean') {
7233 return 'Boolean';
7234 }
7235 if (typeof x === 'string') {
7236 return 'String';
7237 }
7238};
7239
7240// https://262.ecma-international.org/11.0/#sec-ecmascript-data-types-and-values
7241
7242var Type = function Type(x) {
7243 if (typeof x === 'symbol') {
7244 return 'Symbol';
7245 }
7246 if (typeof x === 'bigint') {
7247 return 'BigInt';
7248 }
7249 return Type$1(x);
7250};
7251
7252// this should only run in node >= 13.2, so it
7253// does not need any of the intense fallbacks that old node/browsers do
7254
7255var $iterator = Symbol.iterator;
7256var node = function getIterator(iterable) {
7257 // alternatively, `iterable[$iterator]?.()`
7258 if (iterable != null && typeof iterable[$iterator] !== 'undefined') {
7259 return iterable[$iterator]();
7260 }
7261};
7262
7263var $TypeError$f = TypeError;
7264
7265// eslint-disable-next-line consistent-return
7266var iterateIterator = function iterateIterator(iterator) {
7267 if (!iterator || typeof iterator.next !== 'function') {
7268 throw new $TypeError$f('iterator must be an object with a `next` method');
7269 }
7270 if (arguments.length > 1) {
7271 var callback = arguments[1];
7272 if (typeof callback !== 'function') {
7273 throw new $TypeError$f('`callback`, if provided, must be a function');
7274 }
7275 }
7276 var values = callback || [];
7277 var result;
7278 while ((result = iterator.next()) && !result.done) {
7279 if (callback) {
7280 callback(result.value); // eslint-disable-line callback-return
7281 } else {
7282 values.push(result.value);
7283 }
7284 }
7285 if (!callback) {
7286 return values;
7287 }
7288};
7289
7290var $TypeError$e = TypeError;
7291
7292
7293var iterateValue = function iterateValue(iterable) {
7294 var iterator = node(iterable);
7295 if (!iterator) {
7296 throw new $TypeError$e('non-iterable value provided');
7297 }
7298 if (arguments.length > 1) {
7299 return iterateIterator(iterator, arguments[1]);
7300 }
7301 return iterateIterator(iterator);
7302};
7303
7304var $TypeError$d = getIntrinsic('%TypeError%');
7305
7306// http://262.ecma-international.org/5.1/#sec-9.10
7307
7308var CheckObjectCoercible = function CheckObjectCoercible(value, optMessage) {
7309 if (value == null) {
7310 throw new $TypeError$d(optMessage || ('Cannot call method on ' + value));
7311 }
7312 return value;
7313};
7314
7315var RequireObjectCoercible = CheckObjectCoercible;
7316
7317var $indexOf = callBind(getIntrinsic('String.prototype.indexOf'));
7318
7319var callBound = function callBoundIntrinsic(name, allowMissing) {
7320 var intrinsic = getIntrinsic(name, !!allowMissing);
7321 if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) {
7322 return callBind(intrinsic);
7323 }
7324 return intrinsic;
7325};
7326
7327var util_inspect = require$$0.inspect;
7328
7329var hasMap = typeof Map === 'function' && Map.prototype;
7330var mapSizeDescriptor = Object.getOwnPropertyDescriptor && hasMap ? Object.getOwnPropertyDescriptor(Map.prototype, 'size') : null;
7331var mapSize = hasMap && mapSizeDescriptor && typeof mapSizeDescriptor.get === 'function' ? mapSizeDescriptor.get : null;
7332var mapForEach = hasMap && Map.prototype.forEach;
7333var hasSet = typeof Set === 'function' && Set.prototype;
7334var setSizeDescriptor = Object.getOwnPropertyDescriptor && hasSet ? Object.getOwnPropertyDescriptor(Set.prototype, 'size') : null;
7335var setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor.get === 'function' ? setSizeDescriptor.get : null;
7336var setForEach = hasSet && Set.prototype.forEach;
7337var hasWeakMap = typeof WeakMap === 'function' && WeakMap.prototype;
7338var weakMapHas = hasWeakMap ? WeakMap.prototype.has : null;
7339var hasWeakSet = typeof WeakSet === 'function' && WeakSet.prototype;
7340var weakSetHas = hasWeakSet ? WeakSet.prototype.has : null;
7341var booleanValueOf = Boolean.prototype.valueOf;
7342var objectToString = Object.prototype.toString;
7343var functionToString = Function.prototype.toString;
7344var match = String.prototype.match;
7345var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null;
7346var gOPS = Object.getOwnPropertySymbols;
7347var symToString = typeof Symbol === 'function' ? Symbol.prototype.toString : null;
7348var isEnumerable = Object.prototype.propertyIsEnumerable;
7349
7350var inspectCustom = util_inspect.custom;
7351var inspectSymbol = inspectCustom && isSymbol$1(inspectCustom) ? inspectCustom : null;
7352
7353var objectInspect = function inspect_(obj, options, depth, seen) {
7354 var opts = options || {};
7355
7356 if (has$1(opts, 'quoteStyle') && (opts.quoteStyle !== 'single' && opts.quoteStyle !== 'double')) {
7357 throw new TypeError('option "quoteStyle" must be "single" or "double"');
7358 }
7359 if (
7360 has$1(opts, 'maxStringLength') && (typeof opts.maxStringLength === 'number'
7361 ? opts.maxStringLength < 0 && opts.maxStringLength !== Infinity
7362 : opts.maxStringLength !== null
7363 )
7364 ) {
7365 throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');
7366 }
7367 var customInspect = has$1(opts, 'customInspect') ? opts.customInspect : true;
7368 if (typeof customInspect !== 'boolean') {
7369 throw new TypeError('option "customInspect", if provided, must be `true` or `false`');
7370 }
7371
7372 if (
7373 has$1(opts, 'indent')
7374 && opts.indent !== null
7375 && opts.indent !== '\t'
7376 && !(parseInt(opts.indent, 10) === opts.indent && opts.indent > 0)
7377 ) {
7378 throw new TypeError('options "indent" must be "\\t", an integer > 0, or `null`');
7379 }
7380
7381 if (typeof obj === 'undefined') {
7382 return 'undefined';
7383 }
7384 if (obj === null) {
7385 return 'null';
7386 }
7387 if (typeof obj === 'boolean') {
7388 return obj ? 'true' : 'false';
7389 }
7390
7391 if (typeof obj === 'string') {
7392 return inspectString(obj, opts);
7393 }
7394 if (typeof obj === 'number') {
7395 if (obj === 0) {
7396 return Infinity / obj > 0 ? '0' : '-0';
7397 }
7398 return String(obj);
7399 }
7400 if (typeof obj === 'bigint') {
7401 return String(obj) + 'n';
7402 }
7403
7404 var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;
7405 if (typeof depth === 'undefined') { depth = 0; }
7406 if (depth >= maxDepth && maxDepth > 0 && typeof obj === 'object') {
7407 return isArray(obj) ? '[Array]' : '[Object]';
7408 }
7409
7410 var indent = getIndent(opts, depth);
7411
7412 if (typeof seen === 'undefined') {
7413 seen = [];
7414 } else if (indexOf(seen, obj) >= 0) {
7415 return '[Circular]';
7416 }
7417
7418 function inspect(value, from, noIndent) {
7419 if (from) {
7420 seen = seen.slice();
7421 seen.push(from);
7422 }
7423 if (noIndent) {
7424 var newOpts = {
7425 depth: opts.depth
7426 };
7427 if (has$1(opts, 'quoteStyle')) {
7428 newOpts.quoteStyle = opts.quoteStyle;
7429 }
7430 return inspect_(value, newOpts, depth + 1, seen);
7431 }
7432 return inspect_(value, opts, depth + 1, seen);
7433 }
7434
7435 if (typeof obj === 'function') {
7436 var name = nameOf(obj);
7437 var keys = arrObjKeys(obj, inspect);
7438 return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + keys.join(', ') + ' }' : '');
7439 }
7440 if (isSymbol$1(obj)) {
7441 var symString = symToString.call(obj);
7442 return typeof obj === 'object' ? markBoxed(symString) : symString;
7443 }
7444 if (isElement(obj)) {
7445 var s = '<' + String(obj.nodeName).toLowerCase();
7446 var attrs = obj.attributes || [];
7447 for (var i = 0; i < attrs.length; i++) {
7448 s += ' ' + attrs[i].name + '=' + wrapQuotes(quote(attrs[i].value), 'double', opts);
7449 }
7450 s += '>';
7451 if (obj.childNodes && obj.childNodes.length) { s += '...'; }
7452 s += '</' + String(obj.nodeName).toLowerCase() + '>';
7453 return s;
7454 }
7455 if (isArray(obj)) {
7456 if (obj.length === 0) { return '[]'; }
7457 var xs = arrObjKeys(obj, inspect);
7458 if (indent && !singleLineValues(xs)) {
7459 return '[' + indentedJoin(xs, indent) + ']';
7460 }
7461 return '[ ' + xs.join(', ') + ' ]';
7462 }
7463 if (isError(obj)) {
7464 var parts = arrObjKeys(obj, inspect);
7465 if (parts.length === 0) { return '[' + String(obj) + ']'; }
7466 return '{ [' + String(obj) + '] ' + parts.join(', ') + ' }';
7467 }
7468 if (typeof obj === 'object' && customInspect) {
7469 if (inspectSymbol && typeof obj[inspectSymbol] === 'function') {
7470 return obj[inspectSymbol]();
7471 } else if (typeof obj.inspect === 'function') {
7472 return obj.inspect();
7473 }
7474 }
7475 if (isMap(obj)) {
7476 var mapParts = [];
7477 mapForEach.call(obj, function (value, key) {
7478 mapParts.push(inspect(key, obj, true) + ' => ' + inspect(value, obj));
7479 });
7480 return collectionOf('Map', mapSize.call(obj), mapParts, indent);
7481 }
7482 if (isSet(obj)) {
7483 var setParts = [];
7484 setForEach.call(obj, function (value) {
7485 setParts.push(inspect(value, obj));
7486 });
7487 return collectionOf('Set', setSize.call(obj), setParts, indent);
7488 }
7489 if (isWeakMap(obj)) {
7490 return weakCollectionOf('WeakMap');
7491 }
7492 if (isWeakSet(obj)) {
7493 return weakCollectionOf('WeakSet');
7494 }
7495 if (isNumber(obj)) {
7496 return markBoxed(inspect(Number(obj)));
7497 }
7498 if (isBigInt(obj)) {
7499 return markBoxed(inspect(bigIntValueOf.call(obj)));
7500 }
7501 if (isBoolean(obj)) {
7502 return markBoxed(booleanValueOf.call(obj));
7503 }
7504 if (isString$1(obj)) {
7505 return markBoxed(inspect(String(obj)));
7506 }
7507 if (!isDate(obj) && !isRegExp(obj)) {
7508 var ys = arrObjKeys(obj, inspect);
7509 if (ys.length === 0) { return '{}'; }
7510 if (indent) {
7511 return '{' + indentedJoin(ys, indent) + '}';
7512 }
7513 return '{ ' + ys.join(', ') + ' }';
7514 }
7515 return String(obj);
7516};
7517
7518function wrapQuotes(s, defaultStyle, opts) {
7519 var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'";
7520 return quoteChar + s + quoteChar;
7521}
7522
7523function quote(s) {
7524 return String(s).replace(/"/g, '&quot;');
7525}
7526
7527function isArray(obj) { return toStr$5(obj) === '[object Array]'; }
7528function isDate(obj) { return toStr$5(obj) === '[object Date]'; }
7529function isRegExp(obj) { return toStr$5(obj) === '[object RegExp]'; }
7530function isError(obj) { return toStr$5(obj) === '[object Error]'; }
7531function isSymbol$1(obj) { return toStr$5(obj) === '[object Symbol]'; }
7532function isString$1(obj) { return toStr$5(obj) === '[object String]'; }
7533function isNumber(obj) { return toStr$5(obj) === '[object Number]'; }
7534function isBigInt(obj) { return toStr$5(obj) === '[object BigInt]'; }
7535function isBoolean(obj) { return toStr$5(obj) === '[object Boolean]'; }
7536
7537var hasOwn = Object.prototype.hasOwnProperty || function (key) { return key in this; };
7538function has$1(obj, key) {
7539 return hasOwn.call(obj, key);
7540}
7541
7542function toStr$5(obj) {
7543 return objectToString.call(obj);
7544}
7545
7546function nameOf(f) {
7547 if (f.name) { return f.name; }
7548 var m = match.call(functionToString.call(f), /^function\s*([\w$]+)/);
7549 if (m) { return m[1]; }
7550 return null;
7551}
7552
7553function indexOf(xs, x) {
7554 if (xs.indexOf) { return xs.indexOf(x); }
7555 for (var i = 0, l = xs.length; i < l; i++) {
7556 if (xs[i] === x) { return i; }
7557 }
7558 return -1;
7559}
7560
7561function isMap(x) {
7562 if (!mapSize || !x || typeof x !== 'object') {
7563 return false;
7564 }
7565 try {
7566 mapSize.call(x);
7567 try {
7568 setSize.call(x);
7569 } catch (s) {
7570 return true;
7571 }
7572 return x instanceof Map; // core-js workaround, pre-v2.5.0
7573 } catch (e) {}
7574 return false;
7575}
7576
7577function isWeakMap(x) {
7578 if (!weakMapHas || !x || typeof x !== 'object') {
7579 return false;
7580 }
7581 try {
7582 weakMapHas.call(x, weakMapHas);
7583 try {
7584 weakSetHas.call(x, weakSetHas);
7585 } catch (s) {
7586 return true;
7587 }
7588 return x instanceof WeakMap; // core-js workaround, pre-v2.5.0
7589 } catch (e) {}
7590 return false;
7591}
7592
7593function isSet(x) {
7594 if (!setSize || !x || typeof x !== 'object') {
7595 return false;
7596 }
7597 try {
7598 setSize.call(x);
7599 try {
7600 mapSize.call(x);
7601 } catch (m) {
7602 return true;
7603 }
7604 return x instanceof Set; // core-js workaround, pre-v2.5.0
7605 } catch (e) {}
7606 return false;
7607}
7608
7609function isWeakSet(x) {
7610 if (!weakSetHas || !x || typeof x !== 'object') {
7611 return false;
7612 }
7613 try {
7614 weakSetHas.call(x, weakSetHas);
7615 try {
7616 weakMapHas.call(x, weakMapHas);
7617 } catch (s) {
7618 return true;
7619 }
7620 return x instanceof WeakSet; // core-js workaround, pre-v2.5.0
7621 } catch (e) {}
7622 return false;
7623}
7624
7625function isElement(x) {
7626 if (!x || typeof x !== 'object') { return false; }
7627 if (typeof HTMLElement !== 'undefined' && x instanceof HTMLElement) {
7628 return true;
7629 }
7630 return typeof x.nodeName === 'string' && typeof x.getAttribute === 'function';
7631}
7632
7633function inspectString(str, opts) {
7634 if (str.length > opts.maxStringLength) {
7635 var remaining = str.length - opts.maxStringLength;
7636 var trailer = '... ' + remaining + ' more character' + (remaining > 1 ? 's' : '');
7637 return inspectString(str.slice(0, opts.maxStringLength), opts) + trailer;
7638 }
7639 // eslint-disable-next-line no-control-regex
7640 var s = str.replace(/(['\\])/g, '\\$1').replace(/[\x00-\x1f]/g, lowbyte);
7641 return wrapQuotes(s, 'single', opts);
7642}
7643
7644function lowbyte(c) {
7645 var n = c.charCodeAt(0);
7646 var x = {
7647 8: 'b',
7648 9: 't',
7649 10: 'n',
7650 12: 'f',
7651 13: 'r'
7652 }[n];
7653 if (x) { return '\\' + x; }
7654 return '\\x' + (n < 0x10 ? '0' : '') + n.toString(16).toUpperCase();
7655}
7656
7657function markBoxed(str) {
7658 return 'Object(' + str + ')';
7659}
7660
7661function weakCollectionOf(type) {
7662 return type + ' { ? }';
7663}
7664
7665function collectionOf(type, size, entries, indent) {
7666 var joinedEntries = indent ? indentedJoin(entries, indent) : entries.join(', ');
7667 return type + ' (' + size + ') {' + joinedEntries + '}';
7668}
7669
7670function singleLineValues(xs) {
7671 for (var i = 0; i < xs.length; i++) {
7672 if (indexOf(xs[i], '\n') >= 0) {
7673 return false;
7674 }
7675 }
7676 return true;
7677}
7678
7679function getIndent(opts, depth) {
7680 var baseIndent;
7681 if (opts.indent === '\t') {
7682 baseIndent = '\t';
7683 } else if (typeof opts.indent === 'number' && opts.indent > 0) {
7684 baseIndent = Array(opts.indent + 1).join(' ');
7685 } else {
7686 return null;
7687 }
7688 return {
7689 base: baseIndent,
7690 prev: Array(depth + 1).join(baseIndent)
7691 };
7692}
7693
7694function indentedJoin(xs, indent) {
7695 if (xs.length === 0) { return ''; }
7696 var lineJoiner = '\n' + indent.prev + indent.base;
7697 return lineJoiner + xs.join(',' + lineJoiner) + '\n' + indent.prev;
7698}
7699
7700function arrObjKeys(obj, inspect) {
7701 var isArr = isArray(obj);
7702 var xs = [];
7703 if (isArr) {
7704 xs.length = obj.length;
7705 for (var i = 0; i < obj.length; i++) {
7706 xs[i] = has$1(obj, i) ? inspect(obj[i], obj) : '';
7707 }
7708 }
7709 for (var key in obj) { // eslint-disable-line no-restricted-syntax
7710 if (!has$1(obj, key)) { continue; } // eslint-disable-line no-restricted-syntax, no-continue
7711 if (isArr && String(Number(key)) === key && key < obj.length) { continue; } // eslint-disable-line no-restricted-syntax, no-continue
7712 if ((/[^\w$]/).test(key)) {
7713 xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj));
7714 } else {
7715 xs.push(key + ': ' + inspect(obj[key], obj));
7716 }
7717 }
7718 if (typeof gOPS === 'function') {
7719 var syms = gOPS(obj);
7720 for (var j = 0; j < syms.length; j++) {
7721 if (isEnumerable.call(obj, syms[j])) {
7722 xs.push('[' + inspect(syms[j]) + ']: ' + inspect(obj[syms[j]], obj));
7723 }
7724 }
7725 }
7726 return xs;
7727}
7728
7729// https://ecma-international.org/ecma-262/6.0/#sec-ispropertykey
7730
7731var IsPropertyKey = function IsPropertyKey(argument) {
7732 return typeof argument === 'string' || typeof argument === 'symbol';
7733};
7734
7735var $TypeError$c = getIntrinsic('%TypeError%');
7736
7737
7738
7739
7740
7741
7742/**
7743 * 7.3.1 Get (O, P) - https://ecma-international.org/ecma-262/6.0/#sec-get-o-p
7744 * 1. Assert: Type(O) is Object.
7745 * 2. Assert: IsPropertyKey(P) is true.
7746 * 3. Return O.[[Get]](P, O).
7747 */
7748
7749var Get = function Get(O, P) {
7750 // 7.3.1.1
7751 if (Type(O) !== 'Object') {
7752 throw new $TypeError$c('Assertion failed: Type(O) is not Object');
7753 }
7754 // 7.3.1.2
7755 if (!IsPropertyKey(P)) {
7756 throw new $TypeError$c('Assertion failed: IsPropertyKey(P) is not true, got ' + objectInspect(P));
7757 }
7758 // 7.3.1.3
7759 return O[P];
7760};
7761
7762var $Array$1 = getIntrinsic('%Array%');
7763
7764// eslint-disable-next-line global-require
7765var toStr$4 = !$Array$1.isArray && callBound('Object.prototype.toString');
7766
7767// https://ecma-international.org/ecma-262/6.0/#sec-isarray
7768
7769var IsArray = $Array$1.isArray || function IsArray(argument) {
7770 return toStr$4(argument) === '[object Array]';
7771};
7772
7773// TODO: remove, semver-major
7774
7775var GetIntrinsic = getIntrinsic;
7776
7777var $TypeError$b = getIntrinsic('%TypeError%');
7778
7779var isPropertyDescriptor = function IsPropertyDescriptor(ES, Desc) {
7780 if (ES.Type(Desc) !== 'Object') {
7781 return false;
7782 }
7783 var allowed = {
7784 '[[Configurable]]': true,
7785 '[[Enumerable]]': true,
7786 '[[Get]]': true,
7787 '[[Set]]': true,
7788 '[[Value]]': true,
7789 '[[Writable]]': true
7790 };
7791
7792 for (var key in Desc) { // eslint-disable-line no-restricted-syntax
7793 if (src(Desc, key) && !allowed[key]) {
7794 return false;
7795 }
7796 }
7797
7798 if (ES.IsDataDescriptor(Desc) && ES.IsAccessorDescriptor(Desc)) {
7799 throw new $TypeError$b('Property Descriptors may not be both accessor and data descriptors');
7800 }
7801 return true;
7802};
7803
7804var $defineProperty = getIntrinsic('%Object.defineProperty%', true);
7805
7806if ($defineProperty) {
7807 try {
7808 $defineProperty({}, 'a', { value: 1 });
7809 } catch (e) {
7810 // IE 8 has a broken defineProperty
7811 $defineProperty = null;
7812 }
7813}
7814
7815
7816
7817var $isEnumerable$1 = callBound('Object.prototype.propertyIsEnumerable');
7818
7819// eslint-disable-next-line max-params
7820var DefineOwnProperty = function DefineOwnProperty(IsDataDescriptor, SameValue, FromPropertyDescriptor, O, P, desc) {
7821 if (!$defineProperty) {
7822 if (!IsDataDescriptor(desc)) {
7823 // ES3 does not support getters/setters
7824 return false;
7825 }
7826 if (!desc['[[Configurable]]'] || !desc['[[Writable]]']) {
7827 return false;
7828 }
7829
7830 // fallback for ES3
7831 if (P in O && $isEnumerable$1(O, P) !== !!desc['[[Enumerable]]']) {
7832 // a non-enumerable existing property
7833 return false;
7834 }
7835
7836 // property does not exist at all, or exists but is enumerable
7837 var V = desc['[[Value]]'];
7838 // eslint-disable-next-line no-param-reassign
7839 O[P] = V; // will use [[Define]]
7840 return SameValue(O[P], V);
7841 }
7842 $defineProperty(O, P, FromPropertyDescriptor(desc));
7843 return true;
7844};
7845
7846var $TypeError$a = getIntrinsic('%TypeError%');
7847var $SyntaxError = getIntrinsic('%SyntaxError%');
7848
7849
7850
7851var predicates = {
7852 // https://262.ecma-international.org/6.0/#sec-property-descriptor-specification-type
7853 'Property Descriptor': function isPropertyDescriptor(Type, Desc) {
7854 if (Type(Desc) !== 'Object') {
7855 return false;
7856 }
7857 var allowed = {
7858 '[[Configurable]]': true,
7859 '[[Enumerable]]': true,
7860 '[[Get]]': true,
7861 '[[Set]]': true,
7862 '[[Value]]': true,
7863 '[[Writable]]': true
7864 };
7865
7866 for (var key in Desc) { // eslint-disable-line
7867 if (src(Desc, key) && !allowed[key]) {
7868 return false;
7869 }
7870 }
7871
7872 var isData = src(Desc, '[[Value]]');
7873 var IsAccessor = src(Desc, '[[Get]]') || src(Desc, '[[Set]]');
7874 if (isData && IsAccessor) {
7875 throw new $TypeError$a('Property Descriptors may not be both accessor and data descriptors');
7876 }
7877 return true;
7878 }
7879};
7880
7881var assertRecord = function assertRecord(Type, recordType, argumentName, value) {
7882 var predicate = predicates[recordType];
7883 if (typeof predicate !== 'function') {
7884 throw new $SyntaxError('unknown record type: ' + recordType);
7885 }
7886 if (!predicate(Type, value)) {
7887 throw new $TypeError$a(argumentName + ' must be a ' + recordType);
7888 }
7889};
7890
7891// https://ecma-international.org/ecma-262/6.0/#sec-frompropertydescriptor
7892
7893var FromPropertyDescriptor = function FromPropertyDescriptor(Desc) {
7894 if (typeof Desc === 'undefined') {
7895 return Desc;
7896 }
7897
7898 assertRecord(Type, 'Property Descriptor', 'Desc', Desc);
7899
7900 var obj = {};
7901 if ('[[Value]]' in Desc) {
7902 obj.value = Desc['[[Value]]'];
7903 }
7904 if ('[[Writable]]' in Desc) {
7905 obj.writable = Desc['[[Writable]]'];
7906 }
7907 if ('[[Get]]' in Desc) {
7908 obj.get = Desc['[[Get]]'];
7909 }
7910 if ('[[Set]]' in Desc) {
7911 obj.set = Desc['[[Set]]'];
7912 }
7913 if ('[[Enumerable]]' in Desc) {
7914 obj.enumerable = Desc['[[Enumerable]]'];
7915 }
7916 if ('[[Configurable]]' in Desc) {
7917 obj.configurable = Desc['[[Configurable]]'];
7918 }
7919 return obj;
7920};
7921
7922// https://ecma-international.org/ecma-262/6.0/#sec-isaccessordescriptor
7923
7924var IsAccessorDescriptor = function IsAccessorDescriptor(Desc) {
7925 if (typeof Desc === 'undefined') {
7926 return false;
7927 }
7928
7929 assertRecord(Type, 'Property Descriptor', 'Desc', Desc);
7930
7931 if (!src(Desc, '[[Get]]') && !src(Desc, '[[Set]]')) {
7932 return false;
7933 }
7934
7935 return true;
7936};
7937
7938// https://ecma-international.org/ecma-262/6.0/#sec-isdatadescriptor
7939
7940var IsDataDescriptor = function IsDataDescriptor(Desc) {
7941 if (typeof Desc === 'undefined') {
7942 return false;
7943 }
7944
7945 assertRecord(Type, 'Property Descriptor', 'Desc', Desc);
7946
7947 if (!src(Desc, '[[Value]]') && !src(Desc, '[[Writable]]')) {
7948 return false;
7949 }
7950
7951 return true;
7952};
7953
7954var _isNaN = Number.isNaN || function isNaN(a) {
7955 return a !== a;
7956};
7957
7958// http://262.ecma-international.org/5.1/#sec-9.12
7959
7960var SameValue = function SameValue(x, y) {
7961 if (x === y) { // 0 === -0, but they are not identical.
7962 if (x === 0) { return 1 / x === 1 / y; }
7963 return true;
7964 }
7965 return _isNaN(x) && _isNaN(y);
7966};
7967
7968// http://262.ecma-international.org/5.1/#sec-9.2
7969
7970var ToBoolean = function ToBoolean(value) { return !!value; };
7971
7972var fnToStr$1 = Function.prototype.toString;
7973var reflectApply = typeof Reflect === 'object' && Reflect !== null && Reflect.apply;
7974var badArrayLike;
7975var isCallableMarker;
7976if (typeof reflectApply === 'function' && typeof Object.defineProperty === 'function') {
7977 try {
7978 badArrayLike = Object.defineProperty({}, 'length', {
7979 get: function () {
7980 throw isCallableMarker;
7981 }
7982 });
7983 isCallableMarker = {};
7984 // eslint-disable-next-line no-throw-literal
7985 reflectApply(function () { throw 42; }, null, badArrayLike);
7986 } catch (_) {
7987 if (_ !== isCallableMarker) {
7988 reflectApply = null;
7989 }
7990 }
7991} else {
7992 reflectApply = null;
7993}
7994
7995var constructorRegex$1 = /^\s*class\b/;
7996var isES6ClassFn$1 = function isES6ClassFunction(value) {
7997 try {
7998 var fnStr = fnToStr$1.call(value);
7999 return constructorRegex$1.test(fnStr);
8000 } catch (e) {
8001 return false; // not a function
8002 }
8003};
8004
8005var tryFunctionObject$1 = function tryFunctionToStr(value) {
8006 try {
8007 if (isES6ClassFn$1(value)) { return false; }
8008 fnToStr$1.call(value);
8009 return true;
8010 } catch (e) {
8011 return false;
8012 }
8013};
8014var toStr$3 = Object.prototype.toString;
8015var fnClass$1 = '[object Function]';
8016var genClass$1 = '[object GeneratorFunction]';
8017var hasToStringTag$4 = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
8018/* globals document: false */
8019var documentDotAll = typeof document === 'object' && typeof document.all === 'undefined' && document.all !== undefined ? document.all : {};
8020
8021var isCallable$1 = reflectApply
8022 ? function isCallable(value) {
8023 if (value === documentDotAll) { return true; }
8024 if (!value) { return false; }
8025 if (typeof value !== 'function' && typeof value !== 'object') { return false; }
8026 if (typeof value === 'function' && !value.prototype) { return true; }
8027 try {
8028 reflectApply(value, null, badArrayLike);
8029 } catch (e) {
8030 if (e !== isCallableMarker) { return false; }
8031 }
8032 return !isES6ClassFn$1(value);
8033 }
8034 : function isCallable(value) {
8035 if (value === documentDotAll) { return true; }
8036 if (!value) { return false; }
8037 if (typeof value !== 'function' && typeof value !== 'object') { return false; }
8038 if (typeof value === 'function' && !value.prototype) { return true; }
8039 if (hasToStringTag$4) { return tryFunctionObject$1(value); }
8040 if (isES6ClassFn$1(value)) { return false; }
8041 var strClass = toStr$3.call(value);
8042 return strClass === fnClass$1 || strClass === genClass$1;
8043 };
8044
8045// http://262.ecma-international.org/5.1/#sec-9.11
8046
8047var IsCallable = isCallable$1;
8048
8049var $TypeError$9 = getIntrinsic('%TypeError%');
8050
8051
8052
8053
8054
8055// https://262.ecma-international.org/5.1/#sec-8.10.5
8056
8057var ToPropertyDescriptor = function ToPropertyDescriptor(Obj) {
8058 if (Type(Obj) !== 'Object') {
8059 throw new $TypeError$9('ToPropertyDescriptor requires an object');
8060 }
8061
8062 var desc = {};
8063 if (src(Obj, 'enumerable')) {
8064 desc['[[Enumerable]]'] = ToBoolean(Obj.enumerable);
8065 }
8066 if (src(Obj, 'configurable')) {
8067 desc['[[Configurable]]'] = ToBoolean(Obj.configurable);
8068 }
8069 if (src(Obj, 'value')) {
8070 desc['[[Value]]'] = Obj.value;
8071 }
8072 if (src(Obj, 'writable')) {
8073 desc['[[Writable]]'] = ToBoolean(Obj.writable);
8074 }
8075 if (src(Obj, 'get')) {
8076 var getter = Obj.get;
8077 if (typeof getter !== 'undefined' && !IsCallable(getter)) {
8078 throw new $TypeError$9('getter must be a function');
8079 }
8080 desc['[[Get]]'] = getter;
8081 }
8082 if (src(Obj, 'set')) {
8083 var setter = Obj.set;
8084 if (typeof setter !== 'undefined' && !IsCallable(setter)) {
8085 throw new $TypeError$9('setter must be a function');
8086 }
8087 desc['[[Set]]'] = setter;
8088 }
8089
8090 if ((src(desc, '[[Get]]') || src(desc, '[[Set]]')) && (src(desc, '[[Value]]') || src(desc, '[[Writable]]'))) {
8091 throw new $TypeError$9('Invalid property descriptor. Cannot both specify accessors and a value or writable attribute');
8092 }
8093 return desc;
8094};
8095
8096var $TypeError$8 = getIntrinsic('%TypeError%');
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109// https://ecma-international.org/ecma-262/6.0/#sec-definepropertyorthrow
8110
8111var DefinePropertyOrThrow = function DefinePropertyOrThrow(O, P, desc) {
8112 if (Type(O) !== 'Object') {
8113 throw new $TypeError$8('Assertion failed: Type(O) is not Object');
8114 }
8115
8116 if (!IsPropertyKey(P)) {
8117 throw new $TypeError$8('Assertion failed: IsPropertyKey(P) is not true');
8118 }
8119
8120 var Desc = isPropertyDescriptor({
8121 Type: Type,
8122 IsDataDescriptor: IsDataDescriptor,
8123 IsAccessorDescriptor: IsAccessorDescriptor
8124 }, desc) ? desc : ToPropertyDescriptor(desc);
8125 if (!isPropertyDescriptor({
8126 Type: Type,
8127 IsDataDescriptor: IsDataDescriptor,
8128 IsAccessorDescriptor: IsAccessorDescriptor
8129 }, Desc)) {
8130 throw new $TypeError$8('Assertion failed: Desc is not a valid Property Descriptor');
8131 }
8132
8133 return DefineOwnProperty(
8134 IsDataDescriptor,
8135 SameValue,
8136 FromPropertyDescriptor,
8137 O,
8138 P,
8139 Desc
8140 );
8141};
8142
8143var IsConstructor = createCommonjsModule(function (module) {
8144
8145
8146
8147var $construct = GetIntrinsic('%Reflect.construct%', true);
8148
8149var DefinePropertyOrThrow$1 = DefinePropertyOrThrow;
8150try {
8151 DefinePropertyOrThrow$1({}, '', { '[[Get]]': function () {} });
8152} catch (e) {
8153 // Accessor properties aren't supported
8154 DefinePropertyOrThrow$1 = null;
8155}
8156
8157// https://ecma-international.org/ecma-262/6.0/#sec-isconstructor
8158
8159if (DefinePropertyOrThrow$1 && $construct) {
8160 var isConstructorMarker = {};
8161 var badArrayLike = {};
8162 DefinePropertyOrThrow$1(badArrayLike, 'length', {
8163 '[[Get]]': function () {
8164 throw isConstructorMarker;
8165 },
8166 '[[Enumerable]]': true
8167 });
8168
8169 module.exports = function IsConstructor(argument) {
8170 try {
8171 // `Reflect.construct` invokes `IsConstructor(target)` before `Get(args, 'length')`:
8172 $construct(argument, badArrayLike);
8173 } catch (err) {
8174 return err === isConstructorMarker;
8175 }
8176 };
8177} else {
8178 module.exports = function IsConstructor(argument) {
8179 // unfortunately there's no way to truly check this without try/catch `new argument` in old environments
8180 return typeof argument === 'function' && !!argument.prototype;
8181 };
8182}
8183});
8184
8185var $abs = getIntrinsic('%Math.abs%');
8186
8187// http://262.ecma-international.org/5.1/#sec-5.2
8188
8189var abs = function abs(x) {
8190 return $abs(x);
8191};
8192
8193// var modulo = require('./modulo');
8194var $floor = Math.floor;
8195
8196// http://262.ecma-international.org/5.1/#sec-5.2
8197
8198var floor = function floor(x) {
8199 // return x - modulo(x, 1);
8200 return $floor(x);
8201};
8202
8203var $isNaN = Number.isNaN || function (a) { return a !== a; };
8204
8205var _isFinite = Number.isFinite || function (x) { return typeof x === 'number' && !$isNaN(x) && x !== Infinity && x !== -Infinity; };
8206
8207// https://ecma-international.org/ecma-262/6.0/#sec-isinteger
8208
8209var IsInteger = function IsInteger(argument) {
8210 if (typeof argument !== 'number' || _isNaN(argument) || !_isFinite(argument)) {
8211 return false;
8212 }
8213 var absValue = abs(argument);
8214 return floor(absValue) === absValue;
8215};
8216
8217var $Array = getIntrinsic('%Array%');
8218var $species = getIntrinsic('%Symbol.species%', true);
8219var $TypeError$7 = getIntrinsic('%TypeError%');
8220
8221
8222
8223
8224
8225
8226
8227// https://ecma-international.org/ecma-262/6.0/#sec-arrayspeciescreate
8228
8229var ArraySpeciesCreate = function ArraySpeciesCreate(originalArray, length) {
8230 if (!IsInteger(length) || length < 0) {
8231 throw new $TypeError$7('Assertion failed: length must be an integer >= 0');
8232 }
8233 var len = length === 0 ? 0 : length;
8234 var C;
8235 var isArray = IsArray(originalArray);
8236 if (isArray) {
8237 C = Get(originalArray, 'constructor');
8238 // TODO: figure out how to make a cross-realm normal Array, a same-realm Array
8239 // if (IsConstructor(C)) {
8240 // if C is another realm's Array, C = undefined
8241 // Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(Array))) === null ?
8242 // }
8243 if ($species && Type(C) === 'Object') {
8244 C = Get(C, $species);
8245 if (C === null) {
8246 C = void 0;
8247 }
8248 }
8249 }
8250 if (typeof C === 'undefined') {
8251 return $Array(len);
8252 }
8253 if (!IsConstructor(C)) {
8254 throw new $TypeError$7('C must be a constructor');
8255 }
8256 return new C(len); // Construct(C, len);
8257};
8258
8259var $TypeError$6 = getIntrinsic('%TypeError%');
8260
8261
8262
8263var $apply = getIntrinsic('%Reflect.apply%', true) || callBound('%Function.prototype.apply%');
8264
8265// https://ecma-international.org/ecma-262/6.0/#sec-call
8266
8267var Call = function Call(F, V) {
8268 var argumentsList = arguments.length > 2 ? arguments[2] : [];
8269 if (!IsArray(argumentsList)) {
8270 throw new $TypeError$6('Assertion failed: optional `argumentsList`, if provided, must be a List');
8271 }
8272 return $apply(F, V, argumentsList);
8273};
8274
8275var $gOPD = getIntrinsic('%Object.getOwnPropertyDescriptor%');
8276if ($gOPD) {
8277 try {
8278 $gOPD([], 'length');
8279 } catch (e) {
8280 // IE 8 has a broken gOPD
8281 $gOPD = null;
8282 }
8283}
8284
8285var getOwnPropertyDescriptor = $gOPD;
8286
8287var hasSymbols$1 = hasSymbols$4();
8288var hasToStringTag$3 = hasSymbols$1 && typeof Symbol.toStringTag === 'symbol';
8289var has;
8290var $exec;
8291var isRegexMarker;
8292var badStringifier;
8293
8294if (hasToStringTag$3) {
8295 has = callBound('Object.prototype.hasOwnProperty');
8296 $exec = callBound('RegExp.prototype.exec');
8297 isRegexMarker = {};
8298
8299 var throwRegexMarker = function () {
8300 throw isRegexMarker;
8301 };
8302 badStringifier = {
8303 toString: throwRegexMarker,
8304 valueOf: throwRegexMarker
8305 };
8306
8307 if (typeof Symbol.toPrimitive === 'symbol') {
8308 badStringifier[Symbol.toPrimitive] = throwRegexMarker;
8309 }
8310}
8311
8312var $toString = callBound('Object.prototype.toString');
8313var gOPD = Object.getOwnPropertyDescriptor;
8314var regexClass = '[object RegExp]';
8315
8316var isRegex = hasToStringTag$3
8317 // eslint-disable-next-line consistent-return
8318 ? function isRegex(value) {
8319 if (!value || typeof value !== 'object') {
8320 return false;
8321 }
8322
8323 var descriptor = gOPD(value, 'lastIndex');
8324 var hasLastIndexDataProperty = descriptor && has(descriptor, 'value');
8325 if (!hasLastIndexDataProperty) {
8326 return false;
8327 }
8328
8329 try {
8330 $exec(value, badStringifier);
8331 } catch (e) {
8332 return e === isRegexMarker;
8333 }
8334 }
8335 : function isRegex(value) {
8336 // In older browsers, typeof regex incorrectly returns 'function'
8337 if (!value || (typeof value !== 'object' && typeof value !== 'function')) {
8338 return false;
8339 }
8340
8341 return $toString(value) === regexClass;
8342 };
8343
8344var $match = getIntrinsic('%Symbol.match%', true);
8345
8346
8347
8348
8349
8350// https://ecma-international.org/ecma-262/6.0/#sec-isregexp
8351
8352var IsRegExp = function IsRegExp(argument) {
8353 if (!argument || typeof argument !== 'object') {
8354 return false;
8355 }
8356 if ($match) {
8357 var isRegExp = argument[$match];
8358 if (typeof isRegExp !== 'undefined') {
8359 return ToBoolean(isRegExp);
8360 }
8361 }
8362 return isRegex(argument);
8363};
8364
8365var $TypeError$5 = getIntrinsic('%TypeError%');
8366
8367
8368
8369var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379// https://ecma-international.org/ecma-262/6.0/#sec-ordinarygetownproperty
8380
8381var OrdinaryGetOwnProperty = function OrdinaryGetOwnProperty(O, P) {
8382 if (Type(O) !== 'Object') {
8383 throw new $TypeError$5('Assertion failed: O must be an Object');
8384 }
8385 if (!IsPropertyKey(P)) {
8386 throw new $TypeError$5('Assertion failed: P must be a Property Key');
8387 }
8388 if (!src(O, P)) {
8389 return void 0;
8390 }
8391 if (!getOwnPropertyDescriptor) {
8392 // ES3 / IE 8 fallback
8393 var arrayLength = IsArray(O) && P === 'length';
8394 var regexLastIndex = IsRegExp(O) && P === 'lastIndex';
8395 return {
8396 '[[Configurable]]': !(arrayLength || regexLastIndex),
8397 '[[Enumerable]]': $isEnumerable(O, P),
8398 '[[Value]]': O[P],
8399 '[[Writable]]': true
8400 };
8401 }
8402 return ToPropertyDescriptor(getOwnPropertyDescriptor(O, P));
8403};
8404
8405var isPrimitive$1 = function isPrimitive(value) {
8406 return value === null || (typeof value !== 'function' && typeof value !== 'object');
8407};
8408
8409var $Object$1 = getIntrinsic('%Object%');
8410
8411
8412
8413var $preventExtensions = $Object$1.preventExtensions;
8414var $isExtensible = $Object$1.isExtensible;
8415
8416// https://ecma-international.org/ecma-262/6.0/#sec-isextensible-o
8417
8418var IsExtensible = $preventExtensions
8419 ? function IsExtensible(obj) {
8420 return !isPrimitive$1(obj) && $isExtensible(obj);
8421 }
8422 : function IsExtensible(obj) {
8423 return !isPrimitive$1(obj);
8424 };
8425
8426var $TypeError$4 = getIntrinsic('%TypeError%');
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438// https://ecma-international.org/ecma-262/6.0/#sec-createdataproperty
8439
8440var CreateDataProperty = function CreateDataProperty(O, P, V) {
8441 if (Type(O) !== 'Object') {
8442 throw new $TypeError$4('Assertion failed: Type(O) is not Object');
8443 }
8444 if (!IsPropertyKey(P)) {
8445 throw new $TypeError$4('Assertion failed: IsPropertyKey(P) is not true');
8446 }
8447 var oldDesc = OrdinaryGetOwnProperty(O, P);
8448 var extensible = !oldDesc || IsExtensible(O);
8449 var immutable = oldDesc && (!oldDesc['[[Writable]]'] || !oldDesc['[[Configurable]]']);
8450 if (immutable || !extensible) {
8451 return false;
8452 }
8453 return DefineOwnProperty(
8454 IsDataDescriptor,
8455 SameValue,
8456 FromPropertyDescriptor,
8457 O,
8458 P,
8459 {
8460 '[[Configurable]]': true,
8461 '[[Enumerable]]': true,
8462 '[[Value]]': V,
8463 '[[Writable]]': true
8464 }
8465 );
8466};
8467
8468var $TypeError$3 = getIntrinsic('%TypeError%');
8469
8470
8471
8472
8473
8474// // https://ecma-international.org/ecma-262/6.0/#sec-createdatapropertyorthrow
8475
8476var CreateDataPropertyOrThrow = function CreateDataPropertyOrThrow(O, P, V) {
8477 if (Type(O) !== 'Object') {
8478 throw new $TypeError$3('Assertion failed: Type(O) is not Object');
8479 }
8480 if (!IsPropertyKey(P)) {
8481 throw new $TypeError$3('Assertion failed: IsPropertyKey(P) is not true');
8482 }
8483 var success = CreateDataProperty(O, P, V);
8484 if (!success) {
8485 throw new $TypeError$3('unable to create data property');
8486 }
8487 return success;
8488};
8489
8490var $TypeError$2 = getIntrinsic('%TypeError%');
8491
8492
8493
8494
8495// https://ecma-international.org/ecma-262/6.0/#sec-hasproperty
8496
8497var HasProperty = function HasProperty(O, P) {
8498 if (Type(O) !== 'Object') {
8499 throw new $TypeError$2('Assertion failed: `O` must be an Object');
8500 }
8501 if (!IsPropertyKey(P)) {
8502 throw new $TypeError$2('Assertion failed: `P` must be a Property Key');
8503 }
8504 return P in O;
8505};
8506
8507var $test = getIntrinsic('RegExp.prototype.test');
8508
8509
8510
8511var regexTester = function regexTester(regex) {
8512 return callBind($test, regex);
8513};
8514
8515var isPrimitive = function isPrimitive(value) {
8516 return value === null || (typeof value !== 'function' && typeof value !== 'object');
8517};
8518
8519var fnToStr = Function.prototype.toString;
8520
8521var constructorRegex = /^\s*class\b/;
8522var isES6ClassFn = function isES6ClassFunction(value) {
8523 try {
8524 var fnStr = fnToStr.call(value);
8525 return constructorRegex.test(fnStr);
8526 } catch (e) {
8527 return false; // not a function
8528 }
8529};
8530
8531var tryFunctionObject = function tryFunctionToStr(value) {
8532 try {
8533 if (isES6ClassFn(value)) { return false; }
8534 fnToStr.call(value);
8535 return true;
8536 } catch (e) {
8537 return false;
8538 }
8539};
8540var toStr$2 = Object.prototype.toString;
8541var fnClass = '[object Function]';
8542var genClass = '[object GeneratorFunction]';
8543var hasToStringTag$2 = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
8544
8545var isCallable = function isCallable(value) {
8546 if (!value) { return false; }
8547 if (typeof value !== 'function' && typeof value !== 'object') { return false; }
8548 if (typeof value === 'function' && !value.prototype) { return true; }
8549 if (hasToStringTag$2) { return tryFunctionObject(value); }
8550 if (isES6ClassFn(value)) { return false; }
8551 var strClass = toStr$2.call(value);
8552 return strClass === fnClass || strClass === genClass;
8553};
8554
8555var getDay = Date.prototype.getDay;
8556var tryDateObject = function tryDateGetDayCall(value) {
8557 try {
8558 getDay.call(value);
8559 return true;
8560 } catch (e) {
8561 return false;
8562 }
8563};
8564
8565var toStr$1 = Object.prototype.toString;
8566var dateClass = '[object Date]';
8567var hasToStringTag$1 = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
8568
8569var isDateObject = function isDateObject(value) {
8570 if (typeof value !== 'object' || value === null) {
8571 return false;
8572 }
8573 return hasToStringTag$1 ? tryDateObject(value) : toStr$1.call(value) === dateClass;
8574};
8575
8576var isSymbol = createCommonjsModule(function (module) {
8577
8578var toStr = Object.prototype.toString;
8579var hasSymbols = hasSymbols$4();
8580
8581if (hasSymbols) {
8582 var symToStr = Symbol.prototype.toString;
8583 var symStringRegex = /^Symbol\(.*\)$/;
8584 var isSymbolObject = function isRealSymbolObject(value) {
8585 if (typeof value.valueOf() !== 'symbol') {
8586 return false;
8587 }
8588 return symStringRegex.test(symToStr.call(value));
8589 };
8590
8591 module.exports = function isSymbol(value) {
8592 if (typeof value === 'symbol') {
8593 return true;
8594 }
8595 if (toStr.call(value) !== '[object Symbol]') {
8596 return false;
8597 }
8598 try {
8599 return isSymbolObject(value);
8600 } catch (e) {
8601 return false;
8602 }
8603 };
8604} else {
8605
8606 module.exports = function isSymbol(value) {
8607 // this environment does not support Symbols.
8608 return false ;
8609 };
8610}
8611});
8612
8613var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol';
8614
8615
8616
8617
8618
8619
8620var ordinaryToPrimitive = function OrdinaryToPrimitive(O, hint) {
8621 if (typeof O === 'undefined' || O === null) {
8622 throw new TypeError('Cannot call method on ' + O);
8623 }
8624 if (typeof hint !== 'string' || (hint !== 'number' && hint !== 'string')) {
8625 throw new TypeError('hint must be "string" or "number"');
8626 }
8627 var methodNames = hint === 'string' ? ['toString', 'valueOf'] : ['valueOf', 'toString'];
8628 var method, result, i;
8629 for (i = 0; i < methodNames.length; ++i) {
8630 method = O[methodNames[i]];
8631 if (isCallable(method)) {
8632 result = method.call(O);
8633 if (isPrimitive(result)) {
8634 return result;
8635 }
8636 }
8637 }
8638 throw new TypeError('No default value');
8639};
8640
8641var GetMethod = function GetMethod(O, P) {
8642 var func = O[P];
8643 if (func !== null && typeof func !== 'undefined') {
8644 if (!isCallable(func)) {
8645 throw new TypeError(func + ' returned for property ' + P + ' of object ' + O + ' is not a function');
8646 }
8647 return func;
8648 }
8649 return void 0;
8650};
8651
8652// http://www.ecma-international.org/ecma-262/6.0/#sec-toprimitive
8653var es2015 = function ToPrimitive(input) {
8654 if (isPrimitive(input)) {
8655 return input;
8656 }
8657 var hint = 'default';
8658 if (arguments.length > 1) {
8659 if (arguments[1] === String) {
8660 hint = 'string';
8661 } else if (arguments[1] === Number) {
8662 hint = 'number';
8663 }
8664 }
8665
8666 var exoticToPrim;
8667 if (hasSymbols) {
8668 if (Symbol.toPrimitive) {
8669 exoticToPrim = GetMethod(input, Symbol.toPrimitive);
8670 } else if (isSymbol(input)) {
8671 exoticToPrim = Symbol.prototype.valueOf;
8672 }
8673 }
8674 if (typeof exoticToPrim !== 'undefined') {
8675 var result = exoticToPrim.call(input, hint);
8676 if (isPrimitive(result)) {
8677 return result;
8678 }
8679 throw new TypeError('unable to convert exotic object to primitive');
8680 }
8681 if (hint === 'default' && (isDateObject(input) || isSymbol(input))) {
8682 hint = 'string';
8683 }
8684 return ordinaryToPrimitive(input, hint === 'default' ? 'number' : hint);
8685};
8686
8687// https://ecma-international.org/ecma-262/6.0/#sec-toprimitive
8688
8689var ToPrimitive = function ToPrimitive(input) {
8690 if (arguments.length > 1) {
8691 return es2015(input, arguments[1]);
8692 }
8693 return es2015(input);
8694};
8695
8696var $TypeError$1 = getIntrinsic('%TypeError%');
8697var $Number = getIntrinsic('%Number%');
8698var $RegExp = getIntrinsic('%RegExp%');
8699var $parseInteger = getIntrinsic('%parseInt%');
8700
8701
8702
8703
8704
8705var $strSlice = callBound('String.prototype.slice');
8706var isBinary = regexTester(/^0b[01]+$/i);
8707var isOctal = regexTester(/^0o[0-7]+$/i);
8708var isInvalidHexLiteral = regexTester(/^[-+]0x[0-9a-f]+$/i);
8709var nonWS = ['\u0085', '\u200b', '\ufffe'].join('');
8710var nonWSregex = new $RegExp('[' + nonWS + ']', 'g');
8711var hasNonWS = regexTester(nonWSregex);
8712
8713// whitespace from: https://es5.github.io/#x15.5.4.20
8714// implementation from https://github.com/es-shims/es5-shim/blob/v3.4.0/es5-shim.js#L1304-L1324
8715var ws = [
8716 '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003',
8717 '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028',
8718 '\u2029\uFEFF'
8719].join('');
8720var trimRegex = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g');
8721var $replace = callBound('String.prototype.replace');
8722var $trim = function (value) {
8723 return $replace(value, trimRegex, '');
8724};
8725
8726
8727
8728// https://ecma-international.org/ecma-262/6.0/#sec-tonumber
8729
8730var ToNumber = function ToNumber(argument) {
8731 var value = isPrimitive$1(argument) ? argument : ToPrimitive(argument, $Number);
8732 if (typeof value === 'symbol') {
8733 throw new $TypeError$1('Cannot convert a Symbol value to a number');
8734 }
8735 if (typeof value === 'string') {
8736 if (isBinary(value)) {
8737 return ToNumber($parseInteger($strSlice(value, 2), 2));
8738 } else if (isOctal(value)) {
8739 return ToNumber($parseInteger($strSlice(value, 2), 8));
8740 } else if (hasNonWS(value) || isInvalidHexLiteral(value)) {
8741 return NaN;
8742 } else {
8743 var trimmed = $trim(value);
8744 if (trimmed !== value) {
8745 return ToNumber(trimmed);
8746 }
8747 }
8748 }
8749 return $Number(value);
8750};
8751
8752// http://262.ecma-international.org/5.1/#sec-9.6
8753
8754var ToUint32 = function ToUint32(x) {
8755 return ToNumber(x) >>> 0;
8756};
8757
8758var $Object = getIntrinsic('%Object%');
8759
8760
8761
8762// https://ecma-international.org/ecma-262/6.0/#sec-toobject
8763
8764var ToObject = function ToObject(value) {
8765 RequireObjectCoercible(value);
8766 return $Object(value);
8767};
8768
8769var $String = getIntrinsic('%String%');
8770var $TypeError = getIntrinsic('%TypeError%');
8771
8772// https://ecma-international.org/ecma-262/6.0/#sec-tostring
8773
8774var ToString = function ToString(argument) {
8775 if (typeof argument === 'symbol') {
8776 throw new $TypeError('Cannot convert a Symbol value to a string');
8777 }
8778 return $String(argument);
8779};
8780
8781var strValue = String.prototype.valueOf;
8782var tryStringObject = function tryStringObject(value) {
8783 try {
8784 strValue.call(value);
8785 return true;
8786 } catch (e) {
8787 return false;
8788 }
8789};
8790var toStr = Object.prototype.toString;
8791var strClass = '[object String]';
8792var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
8793
8794var isString = function isString(value) {
8795 if (typeof value === 'string') {
8796 return true;
8797 }
8798 if (typeof value !== 'object') {
8799 return false;
8800 }
8801 return hasToStringTag ? tryStringObject(value) : toStr.call(value) === strClass;
8802};
8803
8804// Check failure of by-index access of string characters (IE < 9) and failure of `0 in boxedString` (Rhino)
8805var boxedString = Object('a');
8806var splitString = boxedString[0] !== 'a' || !(0 in boxedString);
8807
8808var strSplit = callBound('String.prototype.split');
8809
8810var implementation$1 = function map(callbackfn) {
8811 var O = ToObject(this);
8812 var self = splitString && isString(O) ? strSplit(O, '') : O;
8813 var len = ToUint32(self.length);
8814
8815 // If no callback function or if callback is not a callable function
8816 if (!IsCallable(callbackfn)) {
8817 throw new TypeError('Array.prototype.map callback must be a function');
8818 }
8819
8820 var T;
8821 if (arguments.length > 1) {
8822 T = arguments[1];
8823 }
8824
8825 var A = ArraySpeciesCreate(O, len);
8826 var k = 0;
8827 while (k < len) {
8828 var Pk = ToString(k);
8829 var kPresent = HasProperty(O, Pk);
8830 if (kPresent) {
8831 var kValue = Get(O, Pk);
8832 var mappedValue = Call(callbackfn, T, [kValue, k, O]);
8833 CreateDataPropertyOrThrow(A, Pk, mappedValue);
8834 }
8835 k += 1;
8836 }
8837
8838 return A;
8839};
8840
8841var esArrayMethodBoxesProperly = function properlyBoxed(method) {
8842 // Check node 0.6.21 bug where third parameter is not boxed
8843 var properlyBoxesNonStrict = true;
8844 var properlyBoxesStrict = true;
8845 var threwException = false;
8846 if (typeof method === 'function') {
8847 try {
8848 // eslint-disable-next-line max-params
8849 method.call('f', function (_, __, O) {
8850 if (typeof O !== 'object') {
8851 properlyBoxesNonStrict = false;
8852 }
8853 });
8854
8855 method.call(
8856 [null],
8857 function () {
8858 'use strict';
8859
8860 properlyBoxesStrict = typeof this === 'string'; // eslint-disable-line no-invalid-this
8861 },
8862 'x'
8863 );
8864 } catch (e) {
8865 threwException = true;
8866 }
8867 return !threwException && properlyBoxesNonStrict && properlyBoxesStrict;
8868 }
8869 return false;
8870};
8871
8872var polyfill$2 = function getPolyfill() {
8873 var method = Array.prototype.map;
8874 return esArrayMethodBoxesProperly(method) ? method : implementation$1;
8875};
8876
8877var shim$1 = function shimArrayPrototypeMap() {
8878 var polyfill = polyfill$2();
8879 defineProperties_1(
8880 Array.prototype,
8881 { map: polyfill },
8882 { map: function () { return Array.prototype.map !== polyfill; } }
8883 );
8884 return polyfill;
8885};
8886
8887var polyfill$1 = polyfill$2();
8888
8889
8890var $slice = callBound('Array.prototype.slice');
8891
8892// eslint-disable-next-line no-unused-vars
8893var boundMapShim = function map(array, callbackfn) {
8894 RequireObjectCoercible(array);
8895 return polyfill$1.apply(array, $slice(arguments, 1));
8896};
8897defineProperties_1(boundMapShim, {
8898 getPolyfill: polyfill$2,
8899 implementation: implementation$1,
8900 shim: shim$1
8901});
8902
8903var array_prototype_map = boundMapShim;
8904
8905requirePromise();
8906
8907
8908
8909
8910
8911
8912
8913
8914var all = callBind(getIntrinsic('%Promise.all%'));
8915var reject = callBind(getIntrinsic('%Promise.reject%'));
8916
8917var implementation = function allSettled(iterable) {
8918 var C = this;
8919 if (Type(C) !== 'Object') {
8920 throw new TypeError('`this` value must be an object');
8921 }
8922 var values = iterateValue(iterable);
8923 return all(C, array_prototype_map(values, function (item) {
8924 var onFulfill = function (value) {
8925 return { status: 'fulfilled', value: value };
8926 };
8927 var onReject = function (reason) {
8928 return { status: 'rejected', reason: reason };
8929 };
8930 var itemPromise = PromiseResolve(C, item);
8931 try {
8932 return itemPromise.then(onFulfill, onReject);
8933 } catch (e) {
8934 return reject(C, e);
8935 }
8936 }));
8937};
8938
8939var polyfill = function getPolyfill() {
8940 requirePromise();
8941 return typeof Promise.allSettled === 'function' ? Promise.allSettled : implementation;
8942};
8943
8944var shim = function shimAllSettled() {
8945 requirePromise();
8946
8947 var polyfill$1 = polyfill();
8948 defineProperties_1(Promise, { allSettled: polyfill$1 }, {
8949 allSettled: function testAllSettled() {
8950 return Promise.allSettled !== polyfill$1;
8951 }
8952 });
8953 return polyfill$1;
8954};
8955
8956requirePromise();
8957var bound = callBind(polyfill());
8958
8959var rebindable = function allSettled(iterable) {
8960 // eslint-disable-next-line no-invalid-this
8961 return bound(typeof this === 'undefined' ? Promise : this, iterable);
8962};
8963
8964defineProperties_1(rebindable, {
8965 getPolyfill: polyfill,
8966 implementation: implementation,
8967 shim: shim
8968});
8969
8970var promise_allsettled = rebindable;
8971
8972/**
8973 * Return if any of these paths exist.
8974 * @param {Array<string>} paths
8975 * @return {Promise<boolean>}
8976 */
8977async function pathExists(paths) {
8978 try {
8979 await promise_allsettled(paths.map((path) => promises.access(path)));
8980 } catch (e) {
8981 }
8982
8983 return true;
8984}
8985
8986/**
8987 * Update a path with a new extension.
8988 * @param {string} originalPath
8989 * @param {string} newExtension
8990 * @return {string} updated path with new extension
8991 */
8992function repath(originalPath, newExtension) {
8993 return path.join(path.dirname(originalPath), path.basename(originalPath, path.extname(originalPath)) + newExtension);
8994}
8995
8996/**
8997 * convert `import from './foo'` or `export from './foo'` specifiers to include mjs extensions.
8998 * @param {string} dirname
8999 * @param {string} filePath
9000 * @return {Promise<string>}
9001 */
9002async function convertRelativeImportPaths(dirname, filePath) {
9003 const [program, magicString] = await parse(filePath);
9004
9005 await asyncWalk(program, {
9006 enter: async function (node) {
9007 if (node.type === 'ImportDeclaration' || node.type === 'ExportNamedDeclaration' || node.type === 'ExportAllDeclaration') {
9008 const { source } = node;
9009
9010 if (source === null || !source.value.startsWith('.')) {
9011 return;
9012 }
9013
9014 // The first character of the module source is a dot, indicating this could be a path.
9015 const basePath = path.join(dirname, source.value);
9016 if (await pathExists([basePath + '.js', basePath + '.mjs'])) {
9017 // There is a existing filesystem entry for either an '.mjs' or '.js' version of the import.
9018 // It is safe to use the '.mjs' extension for this import.
9019 const [start, end] = source.range;
9020 magicString.overwrite(start, end, `'./${repath(source.value, '.mjs')}'`);
9021 }
9022 }
9023 },
9024 });
9025
9026 return magicString.toString();
9027}
9028
9029/**
9030 * Format each js file output by TypeScript
9031 * 1. With an `.mjs` extension.
9032 * 2. With each relative import location including an `.mjs` extension
9033 * @param {string} configFileLocation
9034 * @param {Object} config
9035 * @return {Promise<Set<string>>}
9036 */
9037async function format(configFileLocation, config) {
9038 const basePath = path.resolve(path.dirname(configFileLocation), config.compilerOptions.outDir);
9039 const filePaths = await glob(basePath + '/**/*.js');
9040 const newFilePaths = new Set();
9041 for (const filePath of filePaths) {
9042 try {
9043 const newFilePath = repath(filePath, '.mjs');
9044 const fileDirName = path.dirname(filePath);
9045 const newFileContent = await convertRelativeImportPaths(fileDirName, filePath);
9046
9047 newFilePaths.add(newFilePath);
9048 await promises.writeFile(newFilePath, newFileContent);
9049 await promises.unlink(filePath);
9050 } catch (e) {
9051 }
9052 }
9053
9054 return newFilePaths;
9055}
9056
9057function config(project) {
9058 const configFilePath = project ? resolve(cwd(), project) : typescript.findConfigFile(cwd(), typescript.sys.fileExists);
9059 const configFile = typescript.readConfigFile(configFilePath, typescript.sys.readFile);
9060
9061 if (configFile.error) {
9062 throw configFile.error;
9063 }
9064 return configFile.config;
9065}
9066
9067export { config, format, log, parse };