UNPKG

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