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