source: frontend/node_modules/acorn/dist/acorn.mjs

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

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