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

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

Fix frontend appearance

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