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