You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5155 lines
186 KiB

2 years ago
  1. // Reserved word lists for various dialects of the language
  2. var reservedWords = {
  3. 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",
  4. 5: "class enum extends super const export import",
  5. 6: "enum",
  6. strict: "implements interface let package private protected public static yield",
  7. strictBind: "eval arguments"
  8. };
  9. // And the keywords
  10. 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";
  11. var keywords = {
  12. 5: ecma5AndLessKeywords,
  13. "5module": ecma5AndLessKeywords + " export import",
  14. 6: ecma5AndLessKeywords + " const class extends export import super"
  15. };
  16. var keywordRelationalOperator = /^in(stanceof)?$/;
  17. // ## Character categories
  18. // Big ugly regular expressions that match characters in the
  19. // whitespace, identifier, and identifier-start categories. These
  20. // are only applied when a character is found to actually have a
  21. // code point above 128.
  22. // Generated by `bin/generate-identifier-regex.js`.
  23. 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\u08a0-\u08b4\u08b6-\u08c7\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\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\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-\u170c\u170e-\u1711\u1720-\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-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\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-\u9ffc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7ca\ua7f5-\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-
  24. 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\u08d3-\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\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf\u1ac0\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-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
  25. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  26. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  27. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  28. // These are a run-length and offset encoded representation of the
  29. // >0xffff code points that are a valid part of identifiers. The
  30. // offset starts at 0x10000, and each pair of numbers represents an
  31. // offset to the next range, and then a size of the range. They were
  32. // generated by bin/generate-identifier-regex.js
  33. // eslint-disable-next-line comma-spacing
  34. 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,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,349,41,7,1,79,28,11,0,9,21,107,20,28,22,13,52,76,44,33,24,27,35,30,0,3,0,9,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,21,2,31,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,230,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,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,190,0,80,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,1237,43,8,8952,286,50,2,18,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,2357,44,11,6,17,0,370,43,1301,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,42717,35,4148,12,221,3,5761,15,7472,3104,541,1507,4938];
  35. // eslint-disable-next-line comma-spacing
  36. var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,370,1,154,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,2,11,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,71,5,2,1,3,3,2,0,2,1,13,9,120,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1014,0,2,54,8,3,82,0,12,1,19628,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,262,6,10,9,419,13,1495,6,110,6,6,9,4759,9,787719,239];
  37. // This has a complexity linear to the value of the code. The
  38. // assumption is that looking up astral identifier characters is
  39. // rare.
  40. function isInAstralSet(code, set) {
  41. var pos = 0x10000;
  42. for (var i = 0; i < set.length; i += 2) {
  43. pos += set[i];
  44. if (pos > code) { return false }
  45. pos += set[i + 1];
  46. if (pos >= code) { return true }
  47. }
  48. }
  49. // Test whether a given character code starts an identifier.
  50. function isIdentifierStart(code, astral) {
  51. if (code < 65) { return code === 36 }
  52. if (code < 91) { return true }
  53. if (code < 97) { return code === 95 }
  54. if (code < 123) { return true }
  55. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  56. if (astral === false) { return false }
  57. return isInAstralSet(code, astralIdentifierStartCodes)
  58. }
  59. // Test whether a given character is part of an identifier.
  60. function isIdentifierChar(code, astral) {
  61. if (code < 48) { return code === 36 }
  62. if (code < 58) { return true }
  63. if (code < 65) { return false }
  64. if (code < 91) { return true }
  65. if (code < 97) { return code === 95 }
  66. if (code < 123) { return true }
  67. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  68. if (astral === false) { return false }
  69. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  70. }
  71. // ## Token types
  72. // The assignment of fine-grained, information-carrying type objects
  73. // allows the tokenizer to store the information it has about a
  74. // token in a way that is very cheap for the parser to look up.
  75. // All token type variables start with an underscore, to make them
  76. // easy to recognize.
  77. // The `beforeExpr` property is used to disambiguate between regular
  78. // expressions and divisions. It is set on all token types that can
  79. // be followed by an expression (thus, a slash after them would be a
  80. // regular expression).
  81. //
  82. // The `startsExpr` property is used to check if the token ends a
  83. // `yield` expression. It is set on all token types that either can
  84. // directly start an expression (like a quotation mark) or can
  85. // continue an expression (like the body of a string).
  86. //
  87. // `isLoop` marks a keyword as starting a loop, which is important
  88. // to know when parsing a label, in order to allow or disallow
  89. // continue jumps to that label.
  90. var TokenType = function TokenType(label, conf) {
  91. if ( conf === void 0 ) conf = {};
  92. this.label = label;
  93. this.keyword = conf.keyword;
  94. this.beforeExpr = !!conf.beforeExpr;
  95. this.startsExpr = !!conf.startsExpr;
  96. this.isLoop = !!conf.isLoop;
  97. this.isAssign = !!conf.isAssign;
  98. this.prefix = !!conf.prefix;
  99. this.postfix = !!conf.postfix;
  100. this.binop = conf.binop || null;
  101. this.updateContext = null;
  102. };
  103. function binop(name, prec) {
  104. return new TokenType(name, {beforeExpr: true, binop: prec})
  105. }
  106. var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};
  107. // Map keyword names to token types.
  108. var keywords$1 = {};
  109. // Succinct definitions of keyword token types
  110. function kw(name, options) {
  111. if ( options === void 0 ) options = {};
  112. options.keyword = name;
  113. return keywords$1[name] = new TokenType(name, options)
  114. }
  115. var types = {
  116. num: new TokenType("num", startsExpr),
  117. regexp: new TokenType("regexp", startsExpr),
  118. string: new TokenType("string", startsExpr),
  119. name: new TokenType("name", startsExpr),
  120. eof: new TokenType("eof"),
  121. // Punctuation token types.
  122. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  123. bracketR: new TokenType("]"),
  124. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  125. braceR: new TokenType("}"),
  126. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  127. parenR: new TokenType(")"),
  128. comma: new TokenType(",", beforeExpr),
  129. semi: new TokenType(";", beforeExpr),
  130. colon: new TokenType(":", beforeExpr),
  131. dot: new TokenType("."),
  132. question: new TokenType("?", beforeExpr),
  133. questionDot: new TokenType("?."),
  134. arrow: new TokenType("=>", beforeExpr),
  135. template: new TokenType("template"),
  136. invalidTemplate: new TokenType("invalidTemplate"),
  137. ellipsis: new TokenType("...", beforeExpr),
  138. backQuote: new TokenType("`", startsExpr),
  139. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  140. // Operators. These carry several kinds of properties to help the
  141. // parser use them properly (the presence of these properties is
  142. // what categorizes them as operators).
  143. //
  144. // `binop`, when present, specifies that this operator is a binary
  145. // operator, and will refer to its precedence.
  146. //
  147. // `prefix` and `postfix` mark the operator as a prefix or postfix
  148. // unary operator.
  149. //
  150. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  151. // binary operators with a very low precedence, that should result
  152. // in AssignmentExpression nodes.
  153. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  154. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  155. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  156. prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
  157. logicalOR: binop("||", 1),
  158. logicalAND: binop("&&", 2),
  159. bitwiseOR: binop("|", 3),
  160. bitwiseXOR: binop("^", 4),
  161. bitwiseAND: binop("&", 5),
  162. equality: binop("==/!=/===/!==", 6),
  163. relational: binop("</>/<=/>=", 7),
  164. bitShift: binop("<</>>/>>>", 8),
  165. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  166. modulo: binop("%", 10),
  167. star: binop("*", 10),
  168. slash: binop("/", 10),
  169. starstar: new TokenType("**", {beforeExpr: true}),
  170. coalesce: binop("??", 1),
  171. // Keyword token types.
  172. _break: kw("break"),
  173. _case: kw("case", beforeExpr),
  174. _catch: kw("catch"),
  175. _continue: kw("continue"),
  176. _debugger: kw("debugger"),
  177. _default: kw("default", beforeExpr),
  178. _do: kw("do", {isLoop: true, beforeExpr: true}),
  179. _else: kw("else", beforeExpr),
  180. _finally: kw("finally"),
  181. _for: kw("for", {isLoop: true}),
  182. _function: kw("function", startsExpr),
  183. _if: kw("if"),
  184. _return: kw("return", beforeExpr),
  185. _switch: kw("switch"),
  186. _throw: kw("throw", beforeExpr),
  187. _try: kw("try"),
  188. _var: kw("var"),
  189. _const: kw("const"),
  190. _while: kw("while", {isLoop: true}),
  191. _with: kw("with"),
  192. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  193. _this: kw("this", startsExpr),
  194. _super: kw("super", startsExpr),
  195. _class: kw("class", startsExpr),
  196. _extends: kw("extends", beforeExpr),
  197. _export: kw("export"),
  198. _import: kw("import", startsExpr),
  199. _null: kw("null", startsExpr),
  200. _true: kw("true", startsExpr),
  201. _false: kw("false", startsExpr),
  202. _in: kw("in", {beforeExpr: true, binop: 7}),
  203. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  204. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  205. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  206. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  207. };
  208. // Matches a whole line break (where CRLF is considered a single
  209. // line break). Used to count lines.
  210. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  211. var lineBreakG = new RegExp(lineBreak.source, "g");
  212. function isNewLine(code, ecma2019String) {
  213. return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029))
  214. }
  215. var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  216. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  217. var ref = Object.prototype;
  218. var hasOwnProperty = ref.hasOwnProperty;
  219. var toString = ref.toString;
  220. // Checks if an object has a property.
  221. function has(obj, propName) {
  222. return hasOwnProperty.call(obj, propName)
  223. }
  224. var isArray = Array.isArray || (function (obj) { return (
  225. toString.call(obj) === "[object Array]"
  226. ); });
  227. function wordsRegexp(words) {
  228. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  229. }
  230. // These are used when `options.locations` is on, for the
  231. // `startLoc` and `endLoc` properties.
  232. var Position = function Position(line, col) {
  233. this.line = line;
  234. this.column = col;
  235. };
  236. Position.prototype.offset = function offset (n) {
  237. return new Position(this.line, this.column + n)
  238. };
  239. var SourceLocation = function SourceLocation(p, start, end) {
  240. this.start = start;
  241. this.end = end;
  242. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  243. };
  244. // The `getLineInfo` function is mostly useful when the
  245. // `locations` option is off (for performance reasons) and you
  246. // want to find the line/column position for a given character
  247. // offset. `input` should be the code string that the offset refers
  248. // into.
  249. function getLineInfo(input, offset) {
  250. for (var line = 1, cur = 0;;) {
  251. lineBreakG.lastIndex = cur;
  252. var match = lineBreakG.exec(input);
  253. if (match && match.index < offset) {
  254. ++line;
  255. cur = match.index + match[0].length;
  256. } else {
  257. return new Position(line, offset - cur)
  258. }
  259. }
  260. }
  261. // A second optional argument can be given to further configure
  262. // the parser process. These options are recognized:
  263. var defaultOptions = {
  264. // `ecmaVersion` indicates the ECMAScript version to parse. Must be
  265. // either 3, 5, 6 (2015), 7 (2016), 8 (2017), 9 (2018), or 10
  266. // (2019). This influences support for strict mode, the set of
  267. // reserved words, and support for new syntax features. The default
  268. // is 10.
  269. ecmaVersion: 10,
  270. // `sourceType` indicates the mode the code should be parsed in.
  271. // Can be either `"script"` or `"module"`. This influences global
  272. // strict mode and parsing of `import` and `export` declarations.
  273. sourceType: "script",
  274. // `onInsertedSemicolon` can be a callback that will be called
  275. // when a semicolon is automatically inserted. It will be passed
  276. // the position of the comma as an offset, and if `locations` is
  277. // enabled, it is given the location as a `{line, column}` object
  278. // as second argument.
  279. onInsertedSemicolon: null,
  280. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  281. // trailing commas.
  282. onTrailingComma: null,
  283. // By default, reserved words are only enforced if ecmaVersion >= 5.
  284. // Set `allowReserved` to a boolean value to explicitly turn this on
  285. // an off. When this option has the value "never", reserved words
  286. // and keywords can also not be used as property names.
  287. allowReserved: null,
  288. // When enabled, a return at the top level is not considered an
  289. // error.
  290. allowReturnOutsideFunction: false,
  291. // When enabled, import/export statements are not constrained to
  292. // appearing at the top of the program.
  293. allowImportExportEverywhere: false,
  294. // When enabled, await identifiers are allowed to appear at the top-level scope,
  295. // but they are still not allowed in non-async functions.
  296. allowAwaitOutsideFunction: false,
  297. // When enabled, hashbang directive in the beginning of file
  298. // is allowed and treated as a line comment.
  299. allowHashBang: false,
  300. // When `locations` is on, `loc` properties holding objects with
  301. // `start` and `end` properties in `{line, column}` form (with
  302. // line being 1-based and column 0-based) will be attached to the
  303. // nodes.
  304. locations: false,
  305. // A function can be passed as `onToken` option, which will
  306. // cause Acorn to call that function with object in the same
  307. // format as tokens returned from `tokenizer().getToken()`. Note
  308. // that you are not allowed to call the parser from the
  309. // callback—that will corrupt its internal state.
  310. onToken: null,
  311. // A function can be passed as `onComment` option, which will
  312. // cause Acorn to call that function with `(block, text, start,
  313. // end)` parameters whenever a comment is skipped. `block` is a
  314. // boolean indicating whether this is a block (`/* */`) comment,
  315. // `text` is the content of the comment, and `start` and `end` are
  316. // character offsets that denote the start and end of the comment.
  317. // When the `locations` option is on, two more parameters are
  318. // passed, the full `{line, column}` locations of the start and
  319. // end of the comments. Note that you are not allowed to call the
  320. // parser from the callback—that will corrupt its internal state.
  321. onComment: null,
  322. // Nodes have their start and end characters offsets recorded in
  323. // `start` and `end` properties (directly on the node, rather than
  324. // the `loc` object, which holds line/column data. To also add a
  325. // [semi-standardized][range] `range` property holding a `[start,
  326. // end]` array with the same numbers, set the `ranges` option to
  327. // `true`.
  328. //
  329. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  330. ranges: false,
  331. // It is possible to parse multiple files into a single AST by
  332. // passing the tree produced by parsing the first file as
  333. // `program` option in subsequent parses. This will add the
  334. // toplevel forms of the parsed file to the `Program` (top) node
  335. // of an existing parse tree.
  336. program: null,
  337. // When `locations` is on, you can pass this to record the source
  338. // file in every node's `loc` object.
  339. sourceFile: null,
  340. // This value, if given, is stored in every node, whether
  341. // `locations` is on or off.
  342. directSourceFile: null,
  343. // When enabled, parenthesized expressions are represented by
  344. // (non-standard) ParenthesizedExpression nodes
  345. preserveParens: false
  346. };
  347. // Interpret and default an options object
  348. function getOptions(opts) {
  349. var options = {};
  350. for (var opt in defaultOptions)
  351. { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  352. if (options.ecmaVersion >= 2015)
  353. { options.ecmaVersion -= 2009; }
  354. if (options.allowReserved == null)
  355. { options.allowReserved = options.ecmaVersion < 5; }
  356. if (isArray(options.onToken)) {
  357. var tokens = options.onToken;
  358. options.onToken = function (token) { return tokens.push(token); };
  359. }
  360. if (isArray(options.onComment))
  361. { options.onComment = pushComment(options, options.onComment); }
  362. return options
  363. }
  364. function pushComment(options, array) {
  365. return function(block, text, start, end, startLoc, endLoc) {
  366. var comment = {
  367. type: block ? "Block" : "Line",
  368. value: text,
  369. start: start,
  370. end: end
  371. };
  372. if (options.locations)
  373. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  374. if (options.ranges)
  375. { comment.range = [start, end]; }
  376. array.push(comment);
  377. }
  378. }
  379. // Each scope gets a bitset that may contain these flags
  380. var
  381. SCOPE_TOP = 1,
  382. SCOPE_FUNCTION = 2,
  383. SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION,
  384. SCOPE_ASYNC = 4,
  385. SCOPE_GENERATOR = 8,
  386. SCOPE_ARROW = 16,
  387. SCOPE_SIMPLE_CATCH = 32,
  388. SCOPE_SUPER = 64,
  389. SCOPE_DIRECT_SUPER = 128;
  390. function functionFlags(async, generator) {
  391. return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
  392. }
  393. // Used in checkLVal and declareName to determine the type of a binding
  394. var
  395. BIND_NONE = 0, // Not a binding
  396. BIND_VAR = 1, // Var-style binding
  397. BIND_LEXICAL = 2, // Let- or const-style binding
  398. BIND_FUNCTION = 3, // Function declaration
  399. BIND_SIMPLE_CATCH = 4, // Simple (identifier pattern) catch binding
  400. BIND_OUTSIDE = 5; // Special case for function names as bound inside the function
  401. var Parser = function Parser(options, input, startPos) {
  402. this.options = options = getOptions(options);
  403. this.sourceFile = options.sourceFile;
  404. this.keywords = wordsRegexp(keywords[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]);
  405. var reserved = "";
  406. if (options.allowReserved !== true) {
  407. for (var v = options.ecmaVersion;; v--)
  408. { if (reserved = reservedWords[v]) { break } }
  409. if (options.sourceType === "module") { reserved += " await"; }
  410. }
  411. this.reservedWords = wordsRegexp(reserved);
  412. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  413. this.reservedWordsStrict = wordsRegexp(reservedStrict);
  414. this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
  415. this.input = String(input);
  416. // Used to signal to callers of `readWord1` whether the word
  417. // contained any escape sequences. This is needed because words with
  418. // escape sequences must not be interpreted as keywords.
  419. this.containsEsc = false;
  420. // Set up token state
  421. // The current position of the tokenizer in the input.
  422. if (startPos) {
  423. this.pos = startPos;
  424. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  425. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  426. } else {
  427. this.pos = this.lineStart = 0;
  428. this.curLine = 1;
  429. }
  430. // Properties of the current token:
  431. // Its type
  432. this.type = types.eof;
  433. // For tokens that include more information than their type, the value
  434. this.value = null;
  435. // Its start and end offset
  436. this.start = this.end = this.pos;
  437. // And, if locations are used, the {line, column} object
  438. // corresponding to those offsets
  439. this.startLoc = this.endLoc = this.curPosition();
  440. // Position information for the previous token
  441. this.lastTokEndLoc = this.lastTokStartLoc = null;
  442. this.lastTokStart = this.lastTokEnd = this.pos;
  443. // The context stack is used to superficially track syntactic
  444. // context to predict whether a regular expression is allowed in a
  445. // given position.
  446. this.context = this.initialContext();
  447. this.exprAllowed = true;
  448. // Figure out if it's a module code.
  449. this.inModule = options.sourceType === "module";
  450. this.strict = this.inModule || this.strictDirective(this.pos);
  451. // Used to signify the start of a potential arrow function
  452. this.potentialArrowAt = -1;
  453. // Positions to delayed-check that yield/await does not exist in default parameters.
  454. this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
  455. // Labels in scope.
  456. this.labels = [];
  457. // Thus-far undefined exports.
  458. this.undefinedExports = {};
  459. // If enabled, skip leading hashbang line.
  460. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  461. { this.skipLineComment(2); }
  462. // Scope tracking for duplicate variable names (see scope.js)
  463. this.scopeStack = [];
  464. this.enterScope(SCOPE_TOP);
  465. // For RegExp validation
  466. this.regexpState = null;
  467. };
  468. var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true } };
  469. Parser.prototype.parse = function parse () {
  470. var node = this.options.program || this.startNode();
  471. this.nextToken();
  472. return this.parseTopLevel(node)
  473. };
  474. prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
  475. prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 };
  476. prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 };
  477. prototypeAccessors.allowSuper.get = function () { return (this.currentThisScope().flags & SCOPE_SUPER) > 0 };
  478. prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
  479. prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
  480. // Switch to a getter for 7.0.0.
  481. Parser.prototype.inNonArrowFunction = function inNonArrowFunction () { return (this.currentThisScope().flags & SCOPE_FUNCTION) > 0 };
  482. Parser.extend = function extend () {
  483. var plugins = [], len = arguments.length;
  484. while ( len-- ) plugins[ len ] = arguments[ len ];
  485. var cls = this;
  486. for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
  487. return cls
  488. };
  489. Parser.parse = function parse (input, options) {
  490. return new this(options, input).parse()
  491. };
  492. Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
  493. var parser = new this(options, input, pos);
  494. parser.nextToken();
  495. return parser.parseExpression()
  496. };
  497. Parser.tokenizer = function tokenizer (input, options) {
  498. return new this(options, input)
  499. };
  500. Object.defineProperties( Parser.prototype, prototypeAccessors );
  501. var pp = Parser.prototype;
  502. // ## Parser utilities
  503. var literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/;
  504. pp.strictDirective = function(start) {
  505. for (;;) {
  506. // Try to find string literal.
  507. skipWhiteSpace.lastIndex = start;
  508. start += skipWhiteSpace.exec(this.input)[0].length;
  509. var match = literal.exec(this.input.slice(start));
  510. if (!match) { return false }
  511. if ((match[1] || match[2]) === "use strict") {
  512. skipWhiteSpace.lastIndex = start + match[0].length;
  513. var spaceAfter = skipWhiteSpace.exec(this.input), end = spaceAfter.index + spaceAfter[0].length;
  514. var next = this.input.charAt(end);
  515. return next === ";" || next === "}" ||
  516. (lineBreak.test(spaceAfter[0]) &&
  517. !(/[(`.[+\-/*%<>=,?^&]/.test(next) || next === "!" && this.input.charAt(end + 1) === "="))
  518. }
  519. start += match[0].length;
  520. // Skip semicolon, if any.
  521. skipWhiteSpace.lastIndex = start;
  522. start += skipWhiteSpace.exec(this.input)[0].length;
  523. if (this.input[start] === ";")
  524. { start++; }
  525. }
  526. };
  527. // Predicate that tests whether the next token is of the given
  528. // type, and if yes, consumes it as a side effect.
  529. pp.eat = function(type) {
  530. if (this.type === type) {
  531. this.next();
  532. return true
  533. } else {
  534. return false
  535. }
  536. };
  537. // Tests whether parsed token is a contextual keyword.
  538. pp.isContextual = function(name) {
  539. return this.type === types.name && this.value === name && !this.containsEsc
  540. };
  541. // Consumes contextual keyword if possible.
  542. pp.eatContextual = function(name) {
  543. if (!this.isContextual(name)) { return false }
  544. this.next();
  545. return true
  546. };
  547. // Asserts that following token is given contextual keyword.
  548. pp.expectContextual = function(name) {
  549. if (!this.eatContextual(name)) { this.unexpected(); }
  550. };
  551. // Test whether a semicolon can be inserted at the current position.
  552. pp.canInsertSemicolon = function() {
  553. return this.type === types.eof ||
  554. this.type === types.braceR ||
  555. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  556. };
  557. pp.insertSemicolon = function() {
  558. if (this.canInsertSemicolon()) {
  559. if (this.options.onInsertedSemicolon)
  560. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  561. return true
  562. }
  563. };
  564. // Consume a semicolon, or, failing that, see if we are allowed to
  565. // pretend that there is a semicolon at this position.
  566. pp.semicolon = function() {
  567. if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
  568. };
  569. pp.afterTrailingComma = function(tokType, notNext) {
  570. if (this.type === tokType) {
  571. if (this.options.onTrailingComma)
  572. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  573. if (!notNext)
  574. { this.next(); }
  575. return true
  576. }
  577. };
  578. // Expect a token of a given type. If found, consume it, otherwise,
  579. // raise an unexpected token error.
  580. pp.expect = function(type) {
  581. this.eat(type) || this.unexpected();
  582. };
  583. // Raise an unexpected token error.
  584. pp.unexpected = function(pos) {
  585. this.raise(pos != null ? pos : this.start, "Unexpected token");
  586. };
  587. function DestructuringErrors() {
  588. this.shorthandAssign =
  589. this.trailingComma =
  590. this.parenthesizedAssign =
  591. this.parenthesizedBind =
  592. this.doubleProto =
  593. -1;
  594. }
  595. pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  596. if (!refDestructuringErrors) { return }
  597. if (refDestructuringErrors.trailingComma > -1)
  598. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  599. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  600. if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
  601. };
  602. pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  603. if (!refDestructuringErrors) { return false }
  604. var shorthandAssign = refDestructuringErrors.shorthandAssign;
  605. var doubleProto = refDestructuringErrors.doubleProto;
  606. if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
  607. if (shorthandAssign >= 0)
  608. { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
  609. if (doubleProto >= 0)
  610. { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
  611. };
  612. pp.checkYieldAwaitInDefaultParams = function() {
  613. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  614. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  615. if (this.awaitPos)
  616. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  617. };
  618. pp.isSimpleAssignTarget = function(expr) {
  619. if (expr.type === "ParenthesizedExpression")
  620. { return this.isSimpleAssignTarget(expr.expression) }
  621. return expr.type === "Identifier" || expr.type === "MemberExpression"
  622. };
  623. var pp$1 = Parser.prototype;
  624. // ### Statement parsing
  625. // Parse a program. Initializes the parser, reads any number of
  626. // statements, and wraps them in a Program node. Optionally takes a
  627. // `program` argument. If present, the statements will be appended
  628. // to its body instead of creating a new node.
  629. pp$1.parseTopLevel = function(node) {
  630. var exports = {};
  631. if (!node.body) { node.body = []; }
  632. while (this.type !== types.eof) {
  633. var stmt = this.parseStatement(null, true, exports);
  634. node.body.push(stmt);
  635. }
  636. if (this.inModule)
  637. { for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1)
  638. {
  639. var name = list[i];
  640. this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
  641. } }
  642. this.adaptDirectivePrologue(node.body);
  643. this.next();
  644. node.sourceType = this.options.sourceType;
  645. return this.finishNode(node, "Program")
  646. };
  647. var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
  648. pp$1.isLet = function(context) {
  649. if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
  650. skipWhiteSpace.lastIndex = this.pos;
  651. var skip = skipWhiteSpace.exec(this.input);
  652. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  653. // For ambiguous cases, determine if a LexicalDeclaration (or only a
  654. // Statement) is allowed here. If context is not empty then only a Statement
  655. // is allowed. However, `let [` is an explicit negative lookahead for
  656. // ExpressionStatement, so special-case it first.
  657. if (nextCh === 91) { return true } // '['
  658. if (context) { return false }
  659. if (nextCh === 123) { return true } // '{'
  660. if (isIdentifierStart(nextCh, true)) {
  661. var pos = next + 1;
  662. while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
  663. var ident = this.input.slice(next, pos);
  664. if (!keywordRelationalOperator.test(ident)) { return true }
  665. }
  666. return false
  667. };
  668. // check 'async [no LineTerminator here] function'
  669. // - 'async /*foo*/ function' is OK.
  670. // - 'async /*\n*/ function' is invalid.
  671. pp$1.isAsyncFunction = function() {
  672. if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
  673. { return false }
  674. skipWhiteSpace.lastIndex = this.pos;
  675. var skip = skipWhiteSpace.exec(this.input);
  676. var next = this.pos + skip[0].length;
  677. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  678. this.input.slice(next, next + 8) === "function" &&
  679. (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
  680. };
  681. // Parse a single statement.
  682. //
  683. // If expecting a statement and finding a slash operator, parse a
  684. // regular expression literal. This is to handle cases like
  685. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  686. // does not help.
  687. pp$1.parseStatement = function(context, topLevel, exports) {
  688. var starttype = this.type, node = this.startNode(), kind;
  689. if (this.isLet(context)) {
  690. starttype = types._var;
  691. kind = "let";
  692. }
  693. // Most types of statements are recognized by the keyword they
  694. // start with. Many are trivial to parse, some require a bit of
  695. // complexity.
  696. switch (starttype) {
  697. case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  698. case types._debugger: return this.parseDebuggerStatement(node)
  699. case types._do: return this.parseDoStatement(node)
  700. case types._for: return this.parseForStatement(node)
  701. case types._function:
  702. // Function as sole body of either an if statement or a labeled statement
  703. // works, but not when it is part of a labeled statement that is the sole
  704. // body of an if statement.
  705. if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
  706. return this.parseFunctionStatement(node, false, !context)
  707. case types._class:
  708. if (context) { this.unexpected(); }
  709. return this.parseClass(node, true)
  710. case types._if: return this.parseIfStatement(node)
  711. case types._return: return this.parseReturnStatement(node)
  712. case types._switch: return this.parseSwitchStatement(node)
  713. case types._throw: return this.parseThrowStatement(node)
  714. case types._try: return this.parseTryStatement(node)
  715. case types._const: case types._var:
  716. kind = kind || this.value;
  717. if (context && kind !== "var") { this.unexpected(); }
  718. return this.parseVarStatement(node, kind)
  719. case types._while: return this.parseWhileStatement(node)
  720. case types._with: return this.parseWithStatement(node)
  721. case types.braceL: return this.parseBlock(true, node)
  722. case types.semi: return this.parseEmptyStatement(node)
  723. case types._export:
  724. case types._import:
  725. if (this.options.ecmaVersion > 10 && starttype === types._import) {
  726. skipWhiteSpace.lastIndex = this.pos;
  727. var skip = skipWhiteSpace.exec(this.input);
  728. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  729. if (nextCh === 40 || nextCh === 46) // '(' or '.'
  730. { return this.parseExpressionStatement(node, this.parseExpression()) }
  731. }
  732. if (!this.options.allowImportExportEverywhere) {
  733. if (!topLevel)
  734. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  735. if (!this.inModule)
  736. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  737. }
  738. return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
  739. // If the statement does not start with a statement keyword or a
  740. // brace, it's an ExpressionStatement or LabeledStatement. We
  741. // simply start parsing an expression, and afterwards, if the
  742. // next token is a colon and the expression was a simple
  743. // Identifier node, we switch to interpreting it as a label.
  744. default:
  745. if (this.isAsyncFunction()) {
  746. if (context) { this.unexpected(); }
  747. this.next();
  748. return this.parseFunctionStatement(node, true, !context)
  749. }
  750. var maybeName = this.value, expr = this.parseExpression();
  751. if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
  752. { return this.parseLabeledStatement(node, maybeName, expr, context) }
  753. else { return this.parseExpressionStatement(node, expr) }
  754. }
  755. };
  756. pp$1.parseBreakContinueStatement = function(node, keyword) {
  757. var isBreak = keyword === "break";
  758. this.next();
  759. if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
  760. else if (this.type !== types.name) { this.unexpected(); }
  761. else {
  762. node.label = this.parseIdent();
  763. this.semicolon();
  764. }
  765. // Verify that there is an actual destination to break or
  766. // continue to.
  767. var i = 0;
  768. for (; i < this.labels.length; ++i) {
  769. var lab = this.labels[i];
  770. if (node.label == null || lab.name === node.label.name) {
  771. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  772. if (node.label && isBreak) { break }
  773. }
  774. }
  775. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  776. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  777. };
  778. pp$1.parseDebuggerStatement = function(node) {
  779. this.next();
  780. this.semicolon();
  781. return this.finishNode(node, "DebuggerStatement")
  782. };
  783. pp$1.parseDoStatement = function(node) {
  784. this.next();
  785. this.labels.push(loopLabel);
  786. node.body = this.parseStatement("do");
  787. this.labels.pop();
  788. this.expect(types._while);
  789. node.test = this.parseParenExpression();
  790. if (this.options.ecmaVersion >= 6)
  791. { this.eat(types.semi); }
  792. else
  793. { this.semicolon(); }
  794. return this.finishNode(node, "DoWhileStatement")
  795. };
  796. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  797. // loop is non-trivial. Basically, we have to parse the init `var`
  798. // statement or expression, disallowing the `in` operator (see
  799. // the second parameter to `parseExpression`), and then check
  800. // whether the next token is `in` or `of`. When there is no init
  801. // part (semicolon immediately after the opening parenthesis), it
  802. // is a regular `for` loop.
  803. pp$1.parseForStatement = function(node) {
  804. this.next();
  805. var awaitAt = (this.options.ecmaVersion >= 9 && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction)) && this.eatContextual("await")) ? this.lastTokStart : -1;
  806. this.labels.push(loopLabel);
  807. this.enterScope(0);
  808. this.expect(types.parenL);
  809. if (this.type === types.semi) {
  810. if (awaitAt > -1) { this.unexpected(awaitAt); }
  811. return this.parseFor(node, null)
  812. }
  813. var isLet = this.isLet();
  814. if (this.type === types._var || this.type === types._const || isLet) {
  815. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  816. this.next();
  817. this.parseVar(init$1, true, kind);
  818. this.finishNode(init$1, "VariableDeclaration");
  819. if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1) {
  820. if (this.options.ecmaVersion >= 9) {
  821. if (this.type === types._in) {
  822. if (awaitAt > -1) { this.unexpected(awaitAt); }
  823. } else { node.await = awaitAt > -1; }
  824. }
  825. return this.parseForIn(node, init$1)
  826. }
  827. if (awaitAt > -1) { this.unexpected(awaitAt); }
  828. return this.parseFor(node, init$1)
  829. }
  830. var refDestructuringErrors = new DestructuringErrors;
  831. var init = this.parseExpression(true, refDestructuringErrors);
  832. if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  833. if (this.options.ecmaVersion >= 9) {
  834. if (this.type === types._in) {
  835. if (awaitAt > -1) { this.unexpected(awaitAt); }
  836. } else { node.await = awaitAt > -1; }
  837. }
  838. this.toAssignable(init, false, refDestructuringErrors);
  839. this.checkLVal(init);
  840. return this.parseForIn(node, init)
  841. } else {
  842. this.checkExpressionErrors(refDestructuringErrors, true);
  843. }
  844. if (awaitAt > -1) { this.unexpected(awaitAt); }
  845. return this.parseFor(node, init)
  846. };
  847. pp$1.parseFunctionStatement = function(node, isAsync, declarationPosition) {
  848. this.next();
  849. return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
  850. };
  851. pp$1.parseIfStatement = function(node) {
  852. this.next();
  853. node.test = this.parseParenExpression();
  854. // allow function declarations in branches, but only in non-strict mode
  855. node.consequent = this.parseStatement("if");
  856. node.alternate = this.eat(types._else) ? this.parseStatement("if") : null;
  857. return this.finishNode(node, "IfStatement")
  858. };
  859. pp$1.parseReturnStatement = function(node) {
  860. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  861. { this.raise(this.start, "'return' outside of function"); }
  862. this.next();
  863. // In `return` (and `break`/`continue`), the keywords with
  864. // optional arguments, we eagerly look for a semicolon or the
  865. // possibility to insert one.
  866. if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
  867. else { node.argument = this.parseExpression(); this.semicolon(); }
  868. return this.finishNode(node, "ReturnStatement")
  869. };
  870. pp$1.parseSwitchStatement = function(node) {
  871. this.next();
  872. node.discriminant = this.parseParenExpression();
  873. node.cases = [];
  874. this.expect(types.braceL);
  875. this.labels.push(switchLabel);
  876. this.enterScope(0);
  877. // Statements under must be grouped (by label) in SwitchCase
  878. // nodes. `cur` is used to keep the node that we are currently
  879. // adding statements to.
  880. var cur;
  881. for (var sawDefault = false; this.type !== types.braceR;) {
  882. if (this.type === types._case || this.type === types._default) {
  883. var isCase = this.type === types._case;
  884. if (cur) { this.finishNode(cur, "SwitchCase"); }
  885. node.cases.push(cur = this.startNode());
  886. cur.consequent = [];
  887. this.next();
  888. if (isCase) {
  889. cur.test = this.parseExpression();
  890. } else {
  891. if (sawDefault) { this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); }
  892. sawDefault = true;
  893. cur.test = null;
  894. }
  895. this.expect(types.colon);
  896. } else {
  897. if (!cur) { this.unexpected(); }
  898. cur.consequent.push(this.parseStatement(null));
  899. }
  900. }
  901. this.exitScope();
  902. if (cur) { this.finishNode(cur, "SwitchCase"); }
  903. this.next(); // Closing brace
  904. this.labels.pop();
  905. return this.finishNode(node, "SwitchStatement")
  906. };
  907. pp$1.parseThrowStatement = function(node) {
  908. this.next();
  909. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  910. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  911. node.argument = this.parseExpression();
  912. this.semicolon();
  913. return this.finishNode(node, "ThrowStatement")
  914. };
  915. // Reused empty array added for node fields that are always empty.
  916. var empty = [];
  917. pp$1.parseTryStatement = function(node) {
  918. this.next();
  919. node.block = this.parseBlock();
  920. node.handler = null;
  921. if (this.type === types._catch) {
  922. var clause = this.startNode();
  923. this.next();
  924. if (this.eat(types.parenL)) {
  925. clause.param = this.parseBindingAtom();
  926. var simple = clause.param.type === "Identifier";
  927. this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0);
  928. this.checkLVal(clause.param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL);
  929. this.expect(types.parenR);
  930. } else {
  931. if (this.options.ecmaVersion < 10) { this.unexpected(); }
  932. clause.param = null;
  933. this.enterScope(0);
  934. }
  935. clause.body = this.parseBlock(false);
  936. this.exitScope();
  937. node.handler = this.finishNode(clause, "CatchClause");
  938. }
  939. node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
  940. if (!node.handler && !node.finalizer)
  941. { this.raise(node.start, "Missing catch or finally clause"); }
  942. return this.finishNode(node, "TryStatement")
  943. };
  944. pp$1.parseVarStatement = function(node, kind) {
  945. this.next();
  946. this.parseVar(node, false, kind);
  947. this.semicolon();
  948. return this.finishNode(node, "VariableDeclaration")
  949. };
  950. pp$1.parseWhileStatement = function(node) {
  951. this.next();
  952. node.test = this.parseParenExpression();
  953. this.labels.push(loopLabel);
  954. node.body = this.parseStatement("while");
  955. this.labels.pop();
  956. return this.finishNode(node, "WhileStatement")
  957. };
  958. pp$1.parseWithStatement = function(node) {
  959. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  960. this.next();
  961. node.object = this.parseParenExpression();
  962. node.body = this.parseStatement("with");
  963. return this.finishNode(node, "WithStatement")
  964. };
  965. pp$1.parseEmptyStatement = function(node) {
  966. this.next();
  967. return this.finishNode(node, "EmptyStatement")
  968. };
  969. pp$1.parseLabeledStatement = function(node, maybeName, expr, context) {
  970. for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
  971. {
  972. var label = list[i$1];
  973. if (label.name === maybeName)
  974. { this.raise(expr.start, "Label '" + maybeName + "' is already declared");
  975. } }
  976. var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
  977. for (var i = this.labels.length - 1; i >= 0; i--) {
  978. var label$1 = this.labels[i];
  979. if (label$1.statementStart === node.start) {
  980. // Update information about previous labels on this node
  981. label$1.statementStart = this.start;
  982. label$1.kind = kind;
  983. } else { break }
  984. }
  985. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  986. node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
  987. this.labels.pop();
  988. node.label = expr;
  989. return this.finishNode(node, "LabeledStatement")
  990. };
  991. pp$1.parseExpressionStatement = function(node, expr) {
  992. node.expression = expr;
  993. this.semicolon();
  994. return this.finishNode(node, "ExpressionStatement")
  995. };
  996. // Parse a semicolon-enclosed block of statements, handling `"use
  997. // strict"` declarations when `allowStrict` is true (used for
  998. // function bodies).
  999. pp$1.parseBlock = function(createNewLexicalScope, node, exitStrict) {
  1000. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  1001. if ( node === void 0 ) node = this.startNode();
  1002. node.body = [];
  1003. this.expect(types.braceL);
  1004. if (createNewLexicalScope) { this.enterScope(0); }
  1005. while (this.type !== types.braceR) {
  1006. var stmt = this.parseStatement(null);
  1007. node.body.push(stmt);
  1008. }
  1009. if (exitStrict) { this.strict = false; }
  1010. this.next();
  1011. if (createNewLexicalScope) { this.exitScope(); }
  1012. return this.finishNode(node, "BlockStatement")
  1013. };
  1014. // Parse a regular `for` loop. The disambiguation code in
  1015. // `parseStatement` will already have parsed the init statement or
  1016. // expression.
  1017. pp$1.parseFor = function(node, init) {
  1018. node.init = init;
  1019. this.expect(types.semi);
  1020. node.test = this.type === types.semi ? null : this.parseExpression();
  1021. this.expect(types.semi);
  1022. node.update = this.type === types.parenR ? null : this.parseExpression();
  1023. this.expect(types.parenR);
  1024. node.body = this.parseStatement("for");
  1025. this.exitScope();
  1026. this.labels.pop();
  1027. return this.finishNode(node, "ForStatement")
  1028. };
  1029. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  1030. // same from parser's perspective.
  1031. pp$1.parseForIn = function(node, init) {
  1032. var isForIn = this.type === types._in;
  1033. this.next();
  1034. if (
  1035. init.type === "VariableDeclaration" &&
  1036. init.declarations[0].init != null &&
  1037. (
  1038. !isForIn ||
  1039. this.options.ecmaVersion < 8 ||
  1040. this.strict ||
  1041. init.kind !== "var" ||
  1042. init.declarations[0].id.type !== "Identifier"
  1043. )
  1044. ) {
  1045. this.raise(
  1046. init.start,
  1047. ((isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer")
  1048. );
  1049. } else if (init.type === "AssignmentPattern") {
  1050. this.raise(init.start, "Invalid left-hand side in for-loop");
  1051. }
  1052. node.left = init;
  1053. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
  1054. this.expect(types.parenR);
  1055. node.body = this.parseStatement("for");
  1056. this.exitScope();
  1057. this.labels.pop();
  1058. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement")
  1059. };
  1060. // Parse a list of variable declarations.
  1061. pp$1.parseVar = function(node, isFor, kind) {
  1062. node.declarations = [];
  1063. node.kind = kind;
  1064. for (;;) {
  1065. var decl = this.startNode();
  1066. this.parseVarId(decl, kind);
  1067. if (this.eat(types.eq)) {
  1068. decl.init = this.parseMaybeAssign(isFor);
  1069. } else if (kind === "const" && !(this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
  1070. this.unexpected();
  1071. } else if (decl.id.type !== "Identifier" && !(isFor && (this.type === types._in || this.isContextual("of")))) {
  1072. this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
  1073. } else {
  1074. decl.init = null;
  1075. }
  1076. node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
  1077. if (!this.eat(types.comma)) { break }
  1078. }
  1079. return node
  1080. };
  1081. pp$1.parseVarId = function(decl, kind) {
  1082. decl.id = this.parseBindingAtom();
  1083. this.checkLVal(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
  1084. };
  1085. var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
  1086. // Parse a function declaration or literal (depending on the
  1087. // `statement & FUNC_STATEMENT`).
  1088. // Remove `allowExpressionBody` for 7.0.0, as it is only called with false
  1089. pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync) {
  1090. this.initFunction(node);
  1091. if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
  1092. if (this.type === types.star && (statement & FUNC_HANGING_STATEMENT))
  1093. { this.unexpected(); }
  1094. node.generator = this.eat(types.star);
  1095. }
  1096. if (this.options.ecmaVersion >= 8)
  1097. { node.async = !!isAsync; }
  1098. if (statement & FUNC_STATEMENT) {
  1099. node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types.name ? null : this.parseIdent();
  1100. if (node.id && !(statement & FUNC_HANGING_STATEMENT))
  1101. // If it is a regular function declaration in sloppy mode, then it is
  1102. // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
  1103. // mode depends on properties of the current scope (see
  1104. // treatFunctionsAsVar).
  1105. { this.checkLVal(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
  1106. }
  1107. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  1108. this.yieldPos = 0;
  1109. this.awaitPos = 0;
  1110. this.awaitIdentPos = 0;
  1111. this.enterScope(functionFlags(node.async, node.generator));
  1112. if (!(statement & FUNC_STATEMENT))
  1113. { node.id = this.type === types.name ? this.parseIdent() : null; }
  1114. this.parseFunctionParams(node);
  1115. this.parseFunctionBody(node, allowExpressionBody, false);
  1116. this.yieldPos = oldYieldPos;
  1117. this.awaitPos = oldAwaitPos;
  1118. this.awaitIdentPos = oldAwaitIdentPos;
  1119. return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
  1120. };
  1121. pp$1.parseFunctionParams = function(node) {
  1122. this.expect(types.parenL);
  1123. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  1124. this.checkYieldAwaitInDefaultParams();
  1125. };
  1126. // Parse a class declaration or literal (depending on the
  1127. // `isStatement` parameter).
  1128. pp$1.parseClass = function(node, isStatement) {
  1129. this.next();
  1130. // ecma-262 14.6 Class Definitions
  1131. // A class definition is always strict mode code.
  1132. var oldStrict = this.strict;
  1133. this.strict = true;
  1134. this.parseClassId(node, isStatement);
  1135. this.parseClassSuper(node);
  1136. var classBody = this.startNode();
  1137. var hadConstructor = false;
  1138. classBody.body = [];
  1139. this.expect(types.braceL);
  1140. while (this.type !== types.braceR) {
  1141. var element = this.parseClassElement(node.superClass !== null);
  1142. if (element) {
  1143. classBody.body.push(element);
  1144. if (element.type === "MethodDefinition" && element.kind === "constructor") {
  1145. if (hadConstructor) { this.raise(element.start, "Duplicate constructor in the same class"); }
  1146. hadConstructor = true;
  1147. }
  1148. }
  1149. }
  1150. this.strict = oldStrict;
  1151. this.next();
  1152. node.body = this.finishNode(classBody, "ClassBody");
  1153. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1154. };
  1155. pp$1.parseClassElement = function(constructorAllowsSuper) {
  1156. var this$1 = this;
  1157. if (this.eat(types.semi)) { return null }
  1158. var method = this.startNode();
  1159. var tryContextual = function (k, noLineBreak) {
  1160. if ( noLineBreak === void 0 ) noLineBreak = false;
  1161. var start = this$1.start, startLoc = this$1.startLoc;
  1162. if (!this$1.eatContextual(k)) { return false }
  1163. if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
  1164. if (method.key) { this$1.unexpected(); }
  1165. method.computed = false;
  1166. method.key = this$1.startNodeAt(start, startLoc);
  1167. method.key.name = k;
  1168. this$1.finishNode(method.key, "Identifier");
  1169. return false
  1170. };
  1171. method.kind = "method";
  1172. method.static = tryContextual("static");
  1173. var isGenerator = this.eat(types.star);
  1174. var isAsync = false;
  1175. if (!isGenerator) {
  1176. if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
  1177. isAsync = true;
  1178. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  1179. } else if (tryContextual("get")) {
  1180. method.kind = "get";
  1181. } else if (tryContextual("set")) {
  1182. method.kind = "set";
  1183. }
  1184. }
  1185. if (!method.key) { this.parsePropertyName(method); }
  1186. var key = method.key;
  1187. var allowsDirectSuper = false;
  1188. if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
  1189. key.type === "Literal" && key.value === "constructor")) {
  1190. if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
  1191. if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
  1192. if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
  1193. method.kind = "constructor";
  1194. allowsDirectSuper = constructorAllowsSuper;
  1195. } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
  1196. this.raise(key.start, "Classes may not have a static property named prototype");
  1197. }
  1198. this.parseClassMethod(method, isGenerator, isAsync, allowsDirectSuper);
  1199. if (method.kind === "get" && method.value.params.length !== 0)
  1200. { this.raiseRecoverable(method.value.start, "getter should have no params"); }
  1201. if (method.kind === "set" && method.value.params.length !== 1)
  1202. { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
  1203. if (method.kind === "set" && method.value.params[0].type === "RestElement")
  1204. { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
  1205. return method
  1206. };
  1207. pp$1.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
  1208. method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
  1209. return this.finishNode(method, "MethodDefinition")
  1210. };
  1211. pp$1.parseClassId = function(node, isStatement) {
  1212. if (this.type === types.name) {
  1213. node.id = this.parseIdent();
  1214. if (isStatement)
  1215. { this.checkLVal(node.id, BIND_LEXICAL, false); }
  1216. } else {
  1217. if (isStatement === true)
  1218. { this.unexpected(); }
  1219. node.id = null;
  1220. }
  1221. };
  1222. pp$1.parseClassSuper = function(node) {
  1223. node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
  1224. };
  1225. // Parses module export declaration.
  1226. pp$1.parseExport = function(node, exports) {
  1227. this.next();
  1228. // export * from '...'
  1229. if (this.eat(types.star)) {
  1230. if (this.options.ecmaVersion >= 11) {
  1231. if (this.eatContextual("as")) {
  1232. node.exported = this.parseIdent(true);
  1233. this.checkExport(exports, node.exported.name, this.lastTokStart);
  1234. } else {
  1235. node.exported = null;
  1236. }
  1237. }
  1238. this.expectContextual("from");
  1239. if (this.type !== types.string) { this.unexpected(); }
  1240. node.source = this.parseExprAtom();
  1241. this.semicolon();
  1242. return this.finishNode(node, "ExportAllDeclaration")
  1243. }
  1244. if (this.eat(types._default)) { // export default ...
  1245. this.checkExport(exports, "default", this.lastTokStart);
  1246. var isAsync;
  1247. if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
  1248. var fNode = this.startNode();
  1249. this.next();
  1250. if (isAsync) { this.next(); }
  1251. node.declaration = this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync);
  1252. } else if (this.type === types._class) {
  1253. var cNode = this.startNode();
  1254. node.declaration = this.parseClass(cNode, "nullableID");
  1255. } else {
  1256. node.declaration = this.parseMaybeAssign();
  1257. this.semicolon();
  1258. }
  1259. return this.finishNode(node, "ExportDefaultDeclaration")
  1260. }
  1261. // export var|const|let|function|class ...
  1262. if (this.shouldParseExportStatement()) {
  1263. node.declaration = this.parseStatement(null);
  1264. if (node.declaration.type === "VariableDeclaration")
  1265. { this.checkVariableExport(exports, node.declaration.declarations); }
  1266. else
  1267. { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
  1268. node.specifiers = [];
  1269. node.source = null;
  1270. } else { // export { x, y as z } [from '...']
  1271. node.declaration = null;
  1272. node.specifiers = this.parseExportSpecifiers(exports);
  1273. if (this.eatContextual("from")) {
  1274. if (this.type !== types.string) { this.unexpected(); }
  1275. node.source = this.parseExprAtom();
  1276. } else {
  1277. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1278. // check for keywords used as local names
  1279. var spec = list[i];
  1280. this.checkUnreserved(spec.local);
  1281. // check if export is defined
  1282. this.checkLocalExport(spec.local);
  1283. }
  1284. node.source = null;
  1285. }
  1286. this.semicolon();
  1287. }
  1288. return this.finishNode(node, "ExportNamedDeclaration")
  1289. };
  1290. pp$1.checkExport = function(exports, name, pos) {
  1291. if (!exports) { return }
  1292. if (has(exports, name))
  1293. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1294. exports[name] = true;
  1295. };
  1296. pp$1.checkPatternExport = function(exports, pat) {
  1297. var type = pat.type;
  1298. if (type === "Identifier")
  1299. { this.checkExport(exports, pat.name, pat.start); }
  1300. else if (type === "ObjectPattern")
  1301. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1302. {
  1303. var prop = list[i];
  1304. this.checkPatternExport(exports, prop);
  1305. } }
  1306. else if (type === "ArrayPattern")
  1307. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1308. var elt = list$1[i$1];
  1309. if (elt) { this.checkPatternExport(exports, elt); }
  1310. } }
  1311. else if (type === "Property")
  1312. { this.checkPatternExport(exports, pat.value); }
  1313. else if (type === "AssignmentPattern")
  1314. { this.checkPatternExport(exports, pat.left); }
  1315. else if (type === "RestElement")
  1316. { this.checkPatternExport(exports, pat.argument); }
  1317. else if (type === "ParenthesizedExpression")
  1318. { this.checkPatternExport(exports, pat.expression); }
  1319. };
  1320. pp$1.checkVariableExport = function(exports, decls) {
  1321. if (!exports) { return }
  1322. for (var i = 0, list = decls; i < list.length; i += 1)
  1323. {
  1324. var decl = list[i];
  1325. this.checkPatternExport(exports, decl.id);
  1326. }
  1327. };
  1328. pp$1.shouldParseExportStatement = function() {
  1329. return this.type.keyword === "var" ||
  1330. this.type.keyword === "const" ||
  1331. this.type.keyword === "class" ||
  1332. this.type.keyword === "function" ||
  1333. this.isLet() ||
  1334. this.isAsyncFunction()
  1335. };
  1336. // Parses a comma-separated list of module exports.
  1337. pp$1.parseExportSpecifiers = function(exports) {
  1338. var nodes = [], first = true;
  1339. // export { x, y as z } [from '...']
  1340. this.expect(types.braceL);
  1341. while (!this.eat(types.braceR)) {
  1342. if (!first) {
  1343. this.expect(types.comma);
  1344. if (this.afterTrailingComma(types.braceR)) { break }
  1345. } else { first = false; }
  1346. var node = this.startNode();
  1347. node.local = this.parseIdent(true);
  1348. node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
  1349. this.checkExport(exports, node.exported.name, node.exported.start);
  1350. nodes.push(this.finishNode(node, "ExportSpecifier"));
  1351. }
  1352. return nodes
  1353. };
  1354. // Parses import declaration.
  1355. pp$1.parseImport = function(node) {
  1356. this.next();
  1357. // import '...'
  1358. if (this.type === types.string) {
  1359. node.specifiers = empty;
  1360. node.source = this.parseExprAtom();
  1361. } else {
  1362. node.specifiers = this.parseImportSpecifiers();
  1363. this.expectContextual("from");
  1364. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1365. }
  1366. this.semicolon();
  1367. return this.finishNode(node, "ImportDeclaration")
  1368. };
  1369. // Parses a comma-separated list of module imports.
  1370. pp$1.parseImportSpecifiers = function() {
  1371. var nodes = [], first = true;
  1372. if (this.type === types.name) {
  1373. // import defaultObj, { x, y as z } from '...'
  1374. var node = this.startNode();
  1375. node.local = this.parseIdent();
  1376. this.checkLVal(node.local, BIND_LEXICAL);
  1377. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1378. if (!this.eat(types.comma)) { return nodes }
  1379. }
  1380. if (this.type === types.star) {
  1381. var node$1 = this.startNode();
  1382. this.next();
  1383. this.expectContextual("as");
  1384. node$1.local = this.parseIdent();
  1385. this.checkLVal(node$1.local, BIND_LEXICAL);
  1386. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1387. return nodes
  1388. }
  1389. this.expect(types.braceL);
  1390. while (!this.eat(types.braceR)) {
  1391. if (!first) {
  1392. this.expect(types.comma);
  1393. if (this.afterTrailingComma(types.braceR)) { break }
  1394. } else { first = false; }
  1395. var node$2 = this.startNode();
  1396. node$2.imported = this.parseIdent(true);
  1397. if (this.eatContextual("as")) {
  1398. node$2.local = this.parseIdent();
  1399. } else {
  1400. this.checkUnreserved(node$2.imported);
  1401. node$2.local = node$2.imported;
  1402. }
  1403. this.checkLVal(node$2.local, BIND_LEXICAL);
  1404. nodes.push(this.finishNode(node$2, "ImportSpecifier"));
  1405. }
  1406. return nodes
  1407. };
  1408. // Set `ExpressionStatement#directive` property for directive prologues.
  1409. pp$1.adaptDirectivePrologue = function(statements) {
  1410. for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
  1411. statements[i].directive = statements[i].expression.raw.slice(1, -1);
  1412. }
  1413. };
  1414. pp$1.isDirectiveCandidate = function(statement) {
  1415. return (
  1416. statement.type === "ExpressionStatement" &&
  1417. statement.expression.type === "Literal" &&
  1418. typeof statement.expression.value === "string" &&
  1419. // Reject parenthesized strings.
  1420. (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
  1421. )
  1422. };
  1423. var pp$2 = Parser.prototype;
  1424. // Convert existing expression atom to assignable pattern
  1425. // if possible.
  1426. pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
  1427. if (this.options.ecmaVersion >= 6 && node) {
  1428. switch (node.type) {
  1429. case "Identifier":
  1430. if (this.inAsync && node.name === "await")
  1431. { this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
  1432. break
  1433. case "ObjectPattern":
  1434. case "ArrayPattern":
  1435. case "RestElement":
  1436. break
  1437. case "ObjectExpression":
  1438. node.type = "ObjectPattern";
  1439. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1440. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1441. var prop = list[i];
  1442. this.toAssignable(prop, isBinding);
  1443. // Early error:
  1444. // AssignmentRestProperty[Yield, Await] :
  1445. // `...` DestructuringAssignmentTarget[Yield, Await]
  1446. //
  1447. // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
  1448. if (
  1449. prop.type === "RestElement" &&
  1450. (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
  1451. ) {
  1452. this.raise(prop.argument.start, "Unexpected token");
  1453. }
  1454. }
  1455. break
  1456. case "Property":
  1457. // AssignmentProperty has type === "Property"
  1458. if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
  1459. this.toAssignable(node.value, isBinding);
  1460. break
  1461. case "ArrayExpression":
  1462. node.type = "ArrayPattern";
  1463. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1464. this.toAssignableList(node.elements, isBinding);
  1465. break
  1466. case "SpreadElement":
  1467. node.type = "RestElement";
  1468. this.toAssignable(node.argument, isBinding);
  1469. if (node.argument.type === "AssignmentPattern")
  1470. { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
  1471. break
  1472. case "AssignmentExpression":
  1473. if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
  1474. node.type = "AssignmentPattern";
  1475. delete node.operator;
  1476. this.toAssignable(node.left, isBinding);
  1477. // falls through to AssignmentPattern
  1478. case "AssignmentPattern":
  1479. break
  1480. case "ParenthesizedExpression":
  1481. this.toAssignable(node.expression, isBinding, refDestructuringErrors);
  1482. break
  1483. case "ChainExpression":
  1484. this.raiseRecoverable(node.start, "Optional chaining cannot appear in left-hand side");
  1485. break
  1486. case "MemberExpression":
  1487. if (!isBinding) { break }
  1488. default:
  1489. this.raise(node.start, "Assigning to rvalue");
  1490. }
  1491. } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1492. return node
  1493. };
  1494. // Convert list of expression atoms to binding list.
  1495. pp$2.toAssignableList = function(exprList, isBinding) {
  1496. var end = exprList.length;
  1497. for (var i = 0; i < end; i++) {
  1498. var elt = exprList[i];
  1499. if (elt) { this.toAssignable(elt, isBinding); }
  1500. }
  1501. if (end) {
  1502. var last = exprList[end - 1];
  1503. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1504. { this.unexpected(last.argument.start); }
  1505. }
  1506. return exprList
  1507. };
  1508. // Parses spread element.
  1509. pp$2.parseSpread = function(refDestructuringErrors) {
  1510. var node = this.startNode();
  1511. this.next();
  1512. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1513. return this.finishNode(node, "SpreadElement")
  1514. };
  1515. pp$2.parseRestBinding = function() {
  1516. var node = this.startNode();
  1517. this.next();
  1518. // RestElement inside of a function parameter must be an identifier
  1519. if (this.options.ecmaVersion === 6 && this.type !== types.name)
  1520. { this.unexpected(); }
  1521. node.argument = this.parseBindingAtom();
  1522. return this.finishNode(node, "RestElement")
  1523. };
  1524. // Parses lvalue (assignable) atom.
  1525. pp$2.parseBindingAtom = function() {
  1526. if (this.options.ecmaVersion >= 6) {
  1527. switch (this.type) {
  1528. case types.bracketL:
  1529. var node = this.startNode();
  1530. this.next();
  1531. node.elements = this.parseBindingList(types.bracketR, true, true);
  1532. return this.finishNode(node, "ArrayPattern")
  1533. case types.braceL:
  1534. return this.parseObj(true)
  1535. }
  1536. }
  1537. return this.parseIdent()
  1538. };
  1539. pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  1540. var elts = [], first = true;
  1541. while (!this.eat(close)) {
  1542. if (first) { first = false; }
  1543. else { this.expect(types.comma); }
  1544. if (allowEmpty && this.type === types.comma) {
  1545. elts.push(null);
  1546. } else if (allowTrailingComma && this.afterTrailingComma(close)) {
  1547. break
  1548. } else if (this.type === types.ellipsis) {
  1549. var rest = this.parseRestBinding();
  1550. this.parseBindingListItem(rest);
  1551. elts.push(rest);
  1552. if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
  1553. this.expect(close);
  1554. break
  1555. } else {
  1556. var elem = this.parseMaybeDefault(this.start, this.startLoc);
  1557. this.parseBindingListItem(elem);
  1558. elts.push(elem);
  1559. }
  1560. }
  1561. return elts
  1562. };
  1563. pp$2.parseBindingListItem = function(param) {
  1564. return param
  1565. };
  1566. // Parses assignment pattern around given atom if possible.
  1567. pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
  1568. left = left || this.parseBindingAtom();
  1569. if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
  1570. var node = this.startNodeAt(startPos, startLoc);
  1571. node.left = left;
  1572. node.right = this.parseMaybeAssign();
  1573. return this.finishNode(node, "AssignmentPattern")
  1574. };
  1575. // Verify that a node is an lval — something that can be assigned
  1576. // to.
  1577. // bindingType can be either:
  1578. // 'var' indicating that the lval creates a 'var' binding
  1579. // 'let' indicating that the lval creates a lexical ('let' or 'const') binding
  1580. // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
  1581. pp$2.checkLVal = function(expr, bindingType, checkClashes) {
  1582. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  1583. switch (expr.type) {
  1584. case "Identifier":
  1585. if (bindingType === BIND_LEXICAL && expr.name === "let")
  1586. { this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); }
  1587. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1588. { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1589. if (checkClashes) {
  1590. if (has(checkClashes, expr.name))
  1591. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1592. checkClashes[expr.name] = true;
  1593. }
  1594. if (bindingType !== BIND_NONE && bindingType !== BIND_OUTSIDE) { this.declareName(expr.name, bindingType, expr.start); }
  1595. break
  1596. case "ChainExpression":
  1597. this.raiseRecoverable(expr.start, "Optional chaining cannot appear in left-hand side");
  1598. break
  1599. case "MemberExpression":
  1600. if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
  1601. break
  1602. case "ObjectPattern":
  1603. for (var i = 0, list = expr.properties; i < list.length; i += 1)
  1604. {
  1605. var prop = list[i];
  1606. this.checkLVal(prop, bindingType, checkClashes);
  1607. }
  1608. break
  1609. case "Property":
  1610. // AssignmentProperty has type === "Property"
  1611. this.checkLVal(expr.value, bindingType, checkClashes);
  1612. break
  1613. case "ArrayPattern":
  1614. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1615. var elem = list$1[i$1];
  1616. if (elem) { this.checkLVal(elem, bindingType, checkClashes); }
  1617. }
  1618. break
  1619. case "AssignmentPattern":
  1620. this.checkLVal(expr.left, bindingType, checkClashes);
  1621. break
  1622. case "RestElement":
  1623. this.checkLVal(expr.argument, bindingType, checkClashes);
  1624. break
  1625. case "ParenthesizedExpression":
  1626. this.checkLVal(expr.expression, bindingType, checkClashes);
  1627. break
  1628. default:
  1629. this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
  1630. }
  1631. };
  1632. // A recursive descent parser operates by defining functions for all
  1633. var pp$3 = Parser.prototype;
  1634. // Check if property name clashes with already added.
  1635. // Object/class getters and setters are not allowed to clash —
  1636. // either with each other or with an init property — and in
  1637. // strict mode, init properties are also not allowed to be repeated.
  1638. pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
  1639. if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
  1640. { return }
  1641. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  1642. { return }
  1643. var key = prop.key;
  1644. var name;
  1645. switch (key.type) {
  1646. case "Identifier": name = key.name; break
  1647. case "Literal": name = String(key.value); break
  1648. default: return
  1649. }
  1650. var kind = prop.kind;
  1651. if (this.options.ecmaVersion >= 6) {
  1652. if (name === "__proto__" && kind === "init") {
  1653. if (propHash.proto) {
  1654. if (refDestructuringErrors) {
  1655. if (refDestructuringErrors.doubleProto < 0)
  1656. { refDestructuringErrors.doubleProto = key.start; }
  1657. // Backwards-compat kludge. Can be removed in version 6.0
  1658. } else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
  1659. }
  1660. propHash.proto = true;
  1661. }
  1662. return
  1663. }
  1664. name = "$" + name;
  1665. var other = propHash[name];
  1666. if (other) {
  1667. var redefinition;
  1668. if (kind === "init") {
  1669. redefinition = this.strict && other.init || other.get || other.set;
  1670. } else {
  1671. redefinition = other.init || other[kind];
  1672. }
  1673. if (redefinition)
  1674. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  1675. } else {
  1676. other = propHash[name] = {
  1677. init: false,
  1678. get: false,
  1679. set: false
  1680. };
  1681. }
  1682. other[kind] = true;
  1683. };
  1684. // ### Expression parsing
  1685. // These nest, from the most general expression type at the top to
  1686. // 'atomic', nondivisible expression types at the bottom. Most of
  1687. // the functions will simply let the function(s) below them parse,
  1688. // and, *if* the syntactic construct they handle is present, wrap
  1689. // the AST node that the inner parser gave them in another node.
  1690. // Parse a full expression. The optional arguments are used to
  1691. // forbid the `in` operator (in for loops initalization expressions)
  1692. // and provide reference for storing '=' operator inside shorthand
  1693. // property assignment in contexts where both object expression
  1694. // and object pattern might appear (so it's possible to raise
  1695. // delayed syntax error at correct position).
  1696. pp$3.parseExpression = function(noIn, refDestructuringErrors) {
  1697. var startPos = this.start, startLoc = this.startLoc;
  1698. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  1699. if (this.type === types.comma) {
  1700. var node = this.startNodeAt(startPos, startLoc);
  1701. node.expressions = [expr];
  1702. while (this.eat(types.comma)) { node.expressions.push(this.parseMaybeAssign(noIn, refDestructuringErrors)); }
  1703. return this.finishNode(node, "SequenceExpression")
  1704. }
  1705. return expr
  1706. };
  1707. // Parse an assignment expression. This includes applications of
  1708. // operators like `+=`.
  1709. pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
  1710. if (this.isContextual("yield")) {
  1711. if (this.inGenerator) { return this.parseYield(noIn) }
  1712. // The tokenizer will assume an expression is allowed after
  1713. // `yield`, but this isn't that kind of yield
  1714. else { this.exprAllowed = false; }
  1715. }
  1716. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
  1717. if (refDestructuringErrors) {
  1718. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  1719. oldTrailingComma = refDestructuringErrors.trailingComma;
  1720. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  1721. } else {
  1722. refDestructuringErrors = new DestructuringErrors;
  1723. ownDestructuringErrors = true;
  1724. }
  1725. var startPos = this.start, startLoc = this.startLoc;
  1726. if (this.type === types.parenL || this.type === types.name)
  1727. { this.potentialArrowAt = this.start; }
  1728. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  1729. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  1730. if (this.type.isAssign) {
  1731. var node = this.startNodeAt(startPos, startLoc);
  1732. node.operator = this.value;
  1733. node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left;
  1734. if (!ownDestructuringErrors) {
  1735. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1;
  1736. }
  1737. if (refDestructuringErrors.shorthandAssign >= node.left.start)
  1738. { refDestructuringErrors.shorthandAssign = -1; } // reset because shorthand default was used correctly
  1739. this.checkLVal(left);
  1740. this.next();
  1741. node.right = this.parseMaybeAssign(noIn);
  1742. return this.finishNode(node, "AssignmentExpression")
  1743. } else {
  1744. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  1745. }
  1746. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  1747. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  1748. return left
  1749. };
  1750. // Parse a ternary conditional (`?:`) operator.
  1751. pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
  1752. var startPos = this.start, startLoc = this.startLoc;
  1753. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  1754. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1755. if (this.eat(types.question)) {
  1756. var node = this.startNodeAt(startPos, startLoc);
  1757. node.test = expr;
  1758. node.consequent = this.parseMaybeAssign();
  1759. this.expect(types.colon);
  1760. node.alternate = this.parseMaybeAssign(noIn);
  1761. return this.finishNode(node, "ConditionalExpression")
  1762. }
  1763. return expr
  1764. };
  1765. // Start the precedence parser.
  1766. pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
  1767. var startPos = this.start, startLoc = this.startLoc;
  1768. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  1769. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1770. return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
  1771. };
  1772. // Parse binary operators with the operator precedence parsing
  1773. // algorithm. `left` is the left-hand side of the operator.
  1774. // `minPrec` provides context that allows the function to stop and
  1775. // defer further parser to one of its callers when it encounters an
  1776. // operator that has a lower precedence than the set it is parsing.
  1777. pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
  1778. var prec = this.type.binop;
  1779. if (prec != null && (!noIn || this.type !== types._in)) {
  1780. if (prec > minPrec) {
  1781. var logical = this.type === types.logicalOR || this.type === types.logicalAND;
  1782. var coalesce = this.type === types.coalesce;
  1783. if (coalesce) {
  1784. // Handle the precedence of `tt.coalesce` as equal to the range of logical expressions.
  1785. // In other words, `node.right` shouldn't contain logical expressions in order to check the mixed error.
  1786. prec = types.logicalAND.binop;
  1787. }
  1788. var op = this.value;
  1789. this.next();
  1790. var startPos = this.start, startLoc = this.startLoc;
  1791. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  1792. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce);
  1793. if ((logical && this.type === types.coalesce) || (coalesce && (this.type === types.logicalOR || this.type === types.logicalAND))) {
  1794. this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses");
  1795. }
  1796. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
  1797. }
  1798. }
  1799. return left
  1800. };
  1801. pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  1802. var node = this.startNodeAt(startPos, startLoc);
  1803. node.left = left;
  1804. node.operator = op;
  1805. node.right = right;
  1806. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  1807. };
  1808. // Parse unary operators, both prefix and postfix.
  1809. pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
  1810. var startPos = this.start, startLoc = this.startLoc, expr;
  1811. if (this.isContextual("await") && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction))) {
  1812. expr = this.parseAwait();
  1813. sawUnary = true;
  1814. } else if (this.type.prefix) {
  1815. var node = this.startNode(), update = this.type === types.incDec;
  1816. node.operator = this.value;
  1817. node.prefix = true;
  1818. this.next();
  1819. node.argument = this.parseMaybeUnary(null, true);
  1820. this.checkExpressionErrors(refDestructuringErrors, true);
  1821. if (update) { this.checkLVal(node.argument); }
  1822. else if (this.strict && node.operator === "delete" &&
  1823. node.argument.type === "Identifier")
  1824. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  1825. else { sawUnary = true; }
  1826. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  1827. } else {
  1828. expr = this.parseExprSubscripts(refDestructuringErrors);
  1829. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1830. while (this.type.postfix && !this.canInsertSemicolon()) {
  1831. var node$1 = this.startNodeAt(startPos, startLoc);
  1832. node$1.operator = this.value;
  1833. node$1.prefix = false;
  1834. node$1.argument = expr;
  1835. this.checkLVal(expr);
  1836. this.next();
  1837. expr = this.finishNode(node$1, "UpdateExpression");
  1838. }
  1839. }
  1840. if (!sawUnary && this.eat(types.starstar))
  1841. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
  1842. else
  1843. { return expr }
  1844. };
  1845. // Parse call, dot, and `[]`-subscript expressions.
  1846. pp$3.parseExprSubscripts = function(refDestructuringErrors) {
  1847. var startPos = this.start, startLoc = this.startLoc;
  1848. var expr = this.parseExprAtom(refDestructuringErrors);
  1849. if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")")
  1850. { return expr }
  1851. var result = this.parseSubscripts(expr, startPos, startLoc);
  1852. if (refDestructuringErrors && result.type === "MemberExpression") {
  1853. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  1854. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  1855. }
  1856. return result
  1857. };
  1858. pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
  1859. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  1860. this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 &&
  1861. this.potentialArrowAt === base.start;
  1862. var optionalChained = false;
  1863. while (true) {
  1864. var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained);
  1865. if (element.optional) { optionalChained = true; }
  1866. if (element === base || element.type === "ArrowFunctionExpression") {
  1867. if (optionalChained) {
  1868. var chainNode = this.startNodeAt(startPos, startLoc);
  1869. chainNode.expression = element;
  1870. element = this.finishNode(chainNode, "ChainExpression");
  1871. }
  1872. return element
  1873. }
  1874. base = element;
  1875. }
  1876. };
  1877. pp$3.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained) {
  1878. var optionalSupported = this.options.ecmaVersion >= 11;
  1879. var optional = optionalSupported && this.eat(types.questionDot);
  1880. if (noCalls && optional) { this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); }
  1881. var computed = this.eat(types.bracketL);
  1882. if (computed || (optional && this.type !== types.parenL && this.type !== types.backQuote) || this.eat(types.dot)) {
  1883. var node = this.startNodeAt(startPos, startLoc);
  1884. node.object = base;
  1885. node.property = computed ? this.parseExpression() : this.parseIdent(this.options.allowReserved !== "never");
  1886. node.computed = !!computed;
  1887. if (computed) { this.expect(types.bracketR); }
  1888. if (optionalSupported) {
  1889. node.optional = optional;
  1890. }
  1891. base = this.finishNode(node, "MemberExpression");
  1892. } else if (!noCalls && this.eat(types.parenL)) {
  1893. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  1894. this.yieldPos = 0;
  1895. this.awaitPos = 0;
  1896. this.awaitIdentPos = 0;
  1897. var exprList = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors);
  1898. if (maybeAsyncArrow && !optional && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  1899. this.checkPatternErrors(refDestructuringErrors, false);
  1900. this.checkYieldAwaitInDefaultParams();
  1901. if (this.awaitIdentPos > 0)
  1902. { this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); }
  1903. this.yieldPos = oldYieldPos;
  1904. this.awaitPos = oldAwaitPos;
  1905. this.awaitIdentPos = oldAwaitIdentPos;
  1906. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true)
  1907. }
  1908. this.checkExpressionErrors(refDestructuringErrors, true);
  1909. this.yieldPos = oldYieldPos || this.yieldPos;
  1910. this.awaitPos = oldAwaitPos || this.awaitPos;
  1911. this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos;
  1912. var node$1 = this.startNodeAt(startPos, startLoc);
  1913. node$1.callee = base;
  1914. node$1.arguments = exprList;
  1915. if (optionalSupported) {
  1916. node$1.optional = optional;
  1917. }
  1918. base = this.finishNode(node$1, "CallExpression");
  1919. } else if (this.type === types.backQuote) {
  1920. if (optional || optionalChained) {
  1921. this.raise(this.start, "Optional chaining cannot appear in the tag of tagged template expressions");
  1922. }
  1923. var node$2 = this.startNodeAt(startPos, startLoc);
  1924. node$2.tag = base;
  1925. node$2.quasi = this.parseTemplate({isTagged: true});
  1926. base = this.finishNode(node$2, "TaggedTemplateExpression");
  1927. }
  1928. return base
  1929. };
  1930. // Parse an atomic expression — either a single token that is an
  1931. // expression, an expression started by a keyword like `function` or
  1932. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  1933. // or `{}`.
  1934. pp$3.parseExprAtom = function(refDestructuringErrors) {
  1935. // If a division operator appears in an expression position, the
  1936. // tokenizer got confused, and we force it to read a regexp instead.
  1937. if (this.type === types.slash) { this.readRegexp(); }
  1938. var node, canBeArrow = this.potentialArrowAt === this.start;
  1939. switch (this.type) {
  1940. case types._super:
  1941. if (!this.allowSuper)
  1942. { this.raise(this.start, "'super' keyword outside a method"); }
  1943. node = this.startNode();
  1944. this.next();
  1945. if (this.type === types.parenL && !this.allowDirectSuper)
  1946. { this.raise(node.start, "super() call outside constructor of a subclass"); }
  1947. // The `super` keyword can appear at below:
  1948. // SuperProperty:
  1949. // super [ Expression ]
  1950. // super . IdentifierName
  1951. // SuperCall:
  1952. // super ( Arguments )
  1953. if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
  1954. { this.unexpected(); }
  1955. return this.finishNode(node, "Super")
  1956. case types._this:
  1957. node = this.startNode();
  1958. this.next();
  1959. return this.finishNode(node, "ThisExpression")
  1960. case types.name:
  1961. var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
  1962. var id = this.parseIdent(false);
  1963. if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
  1964. { return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true) }
  1965. if (canBeArrow && !this.canInsertSemicolon()) {
  1966. if (this.eat(types.arrow))
  1967. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
  1968. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
  1969. id = this.parseIdent(false);
  1970. if (this.canInsertSemicolon() || !this.eat(types.arrow))
  1971. { this.unexpected(); }
  1972. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
  1973. }
  1974. }
  1975. return id
  1976. case types.regexp:
  1977. var value = this.value;
  1978. node = this.parseLiteral(value.value);
  1979. node.regex = {pattern: value.pattern, flags: value.flags};
  1980. return node
  1981. case types.num: case types.string:
  1982. return this.parseLiteral(this.value)
  1983. case types._null: case types._true: case types._false:
  1984. node = this.startNode();
  1985. node.value = this.type === types._null ? null : this.type === types._true;
  1986. node.raw = this.type.keyword;
  1987. this.next();
  1988. return this.finishNode(node, "Literal")
  1989. case types.parenL:
  1990. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
  1991. if (refDestructuringErrors) {
  1992. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  1993. { refDestructuringErrors.parenthesizedAssign = start; }
  1994. if (refDestructuringErrors.parenthesizedBind < 0)
  1995. { refDestructuringErrors.parenthesizedBind = start; }
  1996. }
  1997. return expr
  1998. case types.bracketL:
  1999. node = this.startNode();
  2000. this.next();
  2001. node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
  2002. return this.finishNode(node, "ArrayExpression")
  2003. case types.braceL:
  2004. return this.parseObj(false, refDestructuringErrors)
  2005. case types._function:
  2006. node = this.startNode();
  2007. this.next();
  2008. return this.parseFunction(node, 0)
  2009. case types._class:
  2010. return this.parseClass(this.startNode(), false)
  2011. case types._new:
  2012. return this.parseNew()
  2013. case types.backQuote:
  2014. return this.parseTemplate()
  2015. case types._import:
  2016. if (this.options.ecmaVersion >= 11) {
  2017. return this.parseExprImport()
  2018. } else {
  2019. return this.unexpected()
  2020. }
  2021. default:
  2022. this.unexpected();
  2023. }
  2024. };
  2025. pp$3.parseExprImport = function() {
  2026. var node = this.startNode();
  2027. // Consume `import` as an identifier for `import.meta`.
  2028. // Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`.
  2029. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword import"); }
  2030. var meta = this.parseIdent(true);
  2031. switch (this.type) {
  2032. case types.parenL:
  2033. return this.parseDynamicImport(node)
  2034. case types.dot:
  2035. node.meta = meta;
  2036. return this.parseImportMeta(node)
  2037. default:
  2038. this.unexpected();
  2039. }
  2040. };
  2041. pp$3.parseDynamicImport = function(node) {
  2042. this.next(); // skip `(`
  2043. // Parse node.source.
  2044. node.source = this.parseMaybeAssign();
  2045. // Verify ending.
  2046. if (!this.eat(types.parenR)) {
  2047. var errorPos = this.start;
  2048. if (this.eat(types.comma) && this.eat(types.parenR)) {
  2049. this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()");
  2050. } else {
  2051. this.unexpected(errorPos);
  2052. }
  2053. }
  2054. return this.finishNode(node, "ImportExpression")
  2055. };
  2056. pp$3.parseImportMeta = function(node) {
  2057. this.next(); // skip `.`
  2058. var containsEsc = this.containsEsc;
  2059. node.property = this.parseIdent(true);
  2060. if (node.property.name !== "meta")
  2061. { this.raiseRecoverable(node.property.start, "The only valid meta property for import is 'import.meta'"); }
  2062. if (containsEsc)
  2063. { this.raiseRecoverable(node.start, "'import.meta' must not contain escaped characters"); }
  2064. if (this.options.sourceType !== "module")
  2065. { this.raiseRecoverable(node.start, "Cannot use 'import.meta' outside a module"); }
  2066. return this.finishNode(node, "MetaProperty")
  2067. };
  2068. pp$3.parseLiteral = function(value) {
  2069. var node = this.startNode();
  2070. node.value = value;
  2071. node.raw = this.input.slice(this.start, this.end);
  2072. if (node.raw.charCodeAt(node.raw.length - 1) === 110) { node.bigint = node.raw.slice(0, -1).replace(/_/g, ""); }
  2073. this.next();
  2074. return this.finishNode(node, "Literal")
  2075. };
  2076. pp$3.parseParenExpression = function() {
  2077. this.expect(types.parenL);
  2078. var val = this.parseExpression();
  2079. this.expect(types.parenR);
  2080. return val
  2081. };
  2082. pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
  2083. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  2084. if (this.options.ecmaVersion >= 6) {
  2085. this.next();
  2086. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  2087. var exprList = [], first = true, lastIsComma = false;
  2088. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
  2089. this.yieldPos = 0;
  2090. this.awaitPos = 0;
  2091. // Do not save awaitIdentPos to allow checking awaits nested in parameters
  2092. while (this.type !== types.parenR) {
  2093. first ? first = false : this.expect(types.comma);
  2094. if (allowTrailingComma && this.afterTrailingComma(types.parenR, true)) {
  2095. lastIsComma = true;
  2096. break
  2097. } else if (this.type === types.ellipsis) {
  2098. spreadStart = this.start;
  2099. exprList.push(this.parseParenItem(this.parseRestBinding()));
  2100. if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
  2101. break
  2102. } else {
  2103. exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
  2104. }
  2105. }
  2106. var innerEndPos = this.start, innerEndLoc = this.startLoc;
  2107. this.expect(types.parenR);
  2108. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  2109. this.checkPatternErrors(refDestructuringErrors, false);
  2110. this.checkYieldAwaitInDefaultParams();
  2111. this.yieldPos = oldYieldPos;
  2112. this.awaitPos = oldAwaitPos;
  2113. return this.parseParenArrowList(startPos, startLoc, exprList)
  2114. }
  2115. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  2116. if (spreadStart) { this.unexpected(spreadStart); }
  2117. this.checkExpressionErrors(refDestructuringErrors, true);
  2118. this.yieldPos = oldYieldPos || this.yieldPos;
  2119. this.awaitPos = oldAwaitPos || this.awaitPos;
  2120. if (exprList.length > 1) {
  2121. val = this.startNodeAt(innerStartPos, innerStartLoc);
  2122. val.expressions = exprList;
  2123. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  2124. } else {
  2125. val = exprList[0];
  2126. }
  2127. } else {
  2128. val = this.parseParenExpression();
  2129. }
  2130. if (this.options.preserveParens) {
  2131. var par = this.startNodeAt(startPos, startLoc);
  2132. par.expression = val;
  2133. return this.finishNode(par, "ParenthesizedExpression")
  2134. } else {
  2135. return val
  2136. }
  2137. };
  2138. pp$3.parseParenItem = function(item) {
  2139. return item
  2140. };
  2141. pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
  2142. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
  2143. };
  2144. // New's precedence is slightly tricky. It must allow its argument to
  2145. // be a `[]` or dot subscript expression, but not a call — at least,
  2146. // not without wrapping it in parentheses. Thus, it uses the noCalls
  2147. // argument to parseSubscripts to prevent it from consuming the
  2148. // argument list.
  2149. var empty$1 = [];
  2150. pp$3.parseNew = function() {
  2151. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword new"); }
  2152. var node = this.startNode();
  2153. var meta = this.parseIdent(true);
  2154. if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
  2155. node.meta = meta;
  2156. var containsEsc = this.containsEsc;
  2157. node.property = this.parseIdent(true);
  2158. if (node.property.name !== "target")
  2159. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'"); }
  2160. if (containsEsc)
  2161. { this.raiseRecoverable(node.start, "'new.target' must not contain escaped characters"); }
  2162. if (!this.inNonArrowFunction())
  2163. { this.raiseRecoverable(node.start, "'new.target' can only be used in functions"); }
  2164. return this.finishNode(node, "MetaProperty")
  2165. }
  2166. var startPos = this.start, startLoc = this.startLoc, isImport = this.type === types._import;
  2167. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  2168. if (isImport && node.callee.type === "ImportExpression") {
  2169. this.raise(startPos, "Cannot use new with import()");
  2170. }
  2171. if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
  2172. else { node.arguments = empty$1; }
  2173. return this.finishNode(node, "NewExpression")
  2174. };
  2175. // Parse template expression.
  2176. pp$3.parseTemplateElement = function(ref) {
  2177. var isTagged = ref.isTagged;
  2178. var elem = this.startNode();
  2179. if (this.type === types.invalidTemplate) {
  2180. if (!isTagged) {
  2181. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  2182. }
  2183. elem.value = {
  2184. raw: this.value,
  2185. cooked: null
  2186. };
  2187. } else {
  2188. elem.value = {
  2189. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  2190. cooked: this.value
  2191. };
  2192. }
  2193. this.next();
  2194. elem.tail = this.type === types.backQuote;
  2195. return this.finishNode(elem, "TemplateElement")
  2196. };
  2197. pp$3.parseTemplate = function(ref) {
  2198. if ( ref === void 0 ) ref = {};
  2199. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  2200. var node = this.startNode();
  2201. this.next();
  2202. node.expressions = [];
  2203. var curElt = this.parseTemplateElement({isTagged: isTagged});
  2204. node.quasis = [curElt];
  2205. while (!curElt.tail) {
  2206. if (this.type === types.eof) { this.raise(this.pos, "Unterminated template literal"); }
  2207. this.expect(types.dollarBraceL);
  2208. node.expressions.push(this.parseExpression());
  2209. this.expect(types.braceR);
  2210. node.quasis.push(curElt = this.parseTemplateElement({isTagged: isTagged}));
  2211. }
  2212. this.next();
  2213. return this.finishNode(node, "TemplateLiteral")
  2214. };
  2215. pp$3.isAsyncProp = function(prop) {
  2216. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  2217. (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types.star)) &&
  2218. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  2219. };
  2220. // Parse an object literal or binding pattern.
  2221. pp$3.parseObj = function(isPattern, refDestructuringErrors) {
  2222. var node = this.startNode(), first = true, propHash = {};
  2223. node.properties = [];
  2224. this.next();
  2225. while (!this.eat(types.braceR)) {
  2226. if (!first) {
  2227. this.expect(types.comma);
  2228. if (this.options.ecmaVersion >= 5 && this.afterTrailingComma(types.braceR)) { break }
  2229. } else { first = false; }
  2230. var prop = this.parseProperty(isPattern, refDestructuringErrors);
  2231. if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
  2232. node.properties.push(prop);
  2233. }
  2234. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  2235. };
  2236. pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
  2237. var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
  2238. if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
  2239. if (isPattern) {
  2240. prop.argument = this.parseIdent(false);
  2241. if (this.type === types.comma) {
  2242. this.raise(this.start, "Comma is not permitted after the rest element");
  2243. }
  2244. return this.finishNode(prop, "RestElement")
  2245. }
  2246. // To disallow parenthesized identifier via `this.toAssignable()`.
  2247. if (this.type === types.parenL && refDestructuringErrors) {
  2248. if (refDestructuringErrors.parenthesizedAssign < 0) {
  2249. refDestructuringErrors.parenthesizedAssign = this.start;
  2250. }
  2251. if (refDestructuringErrors.parenthesizedBind < 0) {
  2252. refDestructuringErrors.parenthesizedBind = this.start;
  2253. }
  2254. }
  2255. // Parse argument.
  2256. prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  2257. // To disallow trailing comma via `this.toAssignable()`.
  2258. if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
  2259. refDestructuringErrors.trailingComma = this.start;
  2260. }
  2261. // Finish
  2262. return this.finishNode(prop, "SpreadElement")
  2263. }
  2264. if (this.options.ecmaVersion >= 6) {
  2265. prop.method = false;
  2266. prop.shorthand = false;
  2267. if (isPattern || refDestructuringErrors) {
  2268. startPos = this.start;
  2269. startLoc = this.startLoc;
  2270. }
  2271. if (!isPattern)
  2272. { isGenerator = this.eat(types.star); }
  2273. }
  2274. var containsEsc = this.containsEsc;
  2275. this.parsePropertyName(prop);
  2276. if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
  2277. isAsync = true;
  2278. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  2279. this.parsePropertyName(prop, refDestructuringErrors);
  2280. } else {
  2281. isAsync = false;
  2282. }
  2283. this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
  2284. return this.finishNode(prop, "Property")
  2285. };
  2286. pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
  2287. if ((isGenerator || isAsync) && this.type === types.colon)
  2288. { this.unexpected(); }
  2289. if (this.eat(types.colon)) {
  2290. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  2291. prop.kind = "init";
  2292. } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
  2293. if (isPattern) { this.unexpected(); }
  2294. prop.kind = "init";
  2295. prop.method = true;
  2296. prop.value = this.parseMethod(isGenerator, isAsync);
  2297. } else if (!isPattern && !containsEsc &&
  2298. this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  2299. (prop.key.name === "get" || prop.key.name === "set") &&
  2300. (this.type !== types.comma && this.type !== types.braceR && this.type !== types.eq)) {
  2301. if (isGenerator || isAsync) { this.unexpected(); }
  2302. prop.kind = prop.key.name;
  2303. this.parsePropertyName(prop);
  2304. prop.value = this.parseMethod(false);
  2305. var paramCount = prop.kind === "get" ? 0 : 1;
  2306. if (prop.value.params.length !== paramCount) {
  2307. var start = prop.value.start;
  2308. if (prop.kind === "get")
  2309. { this.raiseRecoverable(start, "getter should have no params"); }
  2310. else
  2311. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2312. } else {
  2313. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2314. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2315. }
  2316. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2317. if (isGenerator || isAsync) { this.unexpected(); }
  2318. this.checkUnreserved(prop.key);
  2319. if (prop.key.name === "await" && !this.awaitIdentPos)
  2320. { this.awaitIdentPos = startPos; }
  2321. prop.kind = "init";
  2322. if (isPattern) {
  2323. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2324. } else if (this.type === types.eq && refDestructuringErrors) {
  2325. if (refDestructuringErrors.shorthandAssign < 0)
  2326. { refDestructuringErrors.shorthandAssign = this.start; }
  2327. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2328. } else {
  2329. prop.value = prop.key;
  2330. }
  2331. prop.shorthand = true;
  2332. } else { this.unexpected(); }
  2333. };
  2334. pp$3.parsePropertyName = function(prop) {
  2335. if (this.options.ecmaVersion >= 6) {
  2336. if (this.eat(types.bracketL)) {
  2337. prop.computed = true;
  2338. prop.key = this.parseMaybeAssign();
  2339. this.expect(types.bracketR);
  2340. return prop.key
  2341. } else {
  2342. prop.computed = false;
  2343. }
  2344. }
  2345. return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
  2346. };
  2347. // Initialize empty function node.
  2348. pp$3.initFunction = function(node) {
  2349. node.id = null;
  2350. if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
  2351. if (this.options.ecmaVersion >= 8) { node.async = false; }
  2352. };
  2353. // Parse object or class method.
  2354. pp$3.parseMethod = function(isGenerator, isAsync, allowDirectSuper) {
  2355. var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2356. this.initFunction(node);
  2357. if (this.options.ecmaVersion >= 6)
  2358. { node.generator = isGenerator; }
  2359. if (this.options.ecmaVersion >= 8)
  2360. { node.async = !!isAsync; }
  2361. this.yieldPos = 0;
  2362. this.awaitPos = 0;
  2363. this.awaitIdentPos = 0;
  2364. this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  2365. this.expect(types.parenL);
  2366. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  2367. this.checkYieldAwaitInDefaultParams();
  2368. this.parseFunctionBody(node, false, true);
  2369. this.yieldPos = oldYieldPos;
  2370. this.awaitPos = oldAwaitPos;
  2371. this.awaitIdentPos = oldAwaitIdentPos;
  2372. return this.finishNode(node, "FunctionExpression")
  2373. };
  2374. // Parse arrow function expression with given parameters.
  2375. pp$3.parseArrowExpression = function(node, params, isAsync) {
  2376. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2377. this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
  2378. this.initFunction(node);
  2379. if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
  2380. this.yieldPos = 0;
  2381. this.awaitPos = 0;
  2382. this.awaitIdentPos = 0;
  2383. node.params = this.toAssignableList(params, true);
  2384. this.parseFunctionBody(node, true, false);
  2385. this.yieldPos = oldYieldPos;
  2386. this.awaitPos = oldAwaitPos;
  2387. this.awaitIdentPos = oldAwaitIdentPos;
  2388. return this.finishNode(node, "ArrowFunctionExpression")
  2389. };
  2390. // Parse function body and check parameters.
  2391. pp$3.parseFunctionBody = function(node, isArrowFunction, isMethod) {
  2392. var isExpression = isArrowFunction && this.type !== types.braceL;
  2393. var oldStrict = this.strict, useStrict = false;
  2394. if (isExpression) {
  2395. node.body = this.parseMaybeAssign();
  2396. node.expression = true;
  2397. this.checkParams(node, false);
  2398. } else {
  2399. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2400. if (!oldStrict || nonSimple) {
  2401. useStrict = this.strictDirective(this.end);
  2402. // If this is a strict mode function, verify that argument names
  2403. // are not repeated, and it does not try to bind the words `eval`
  2404. // or `arguments`.
  2405. if (useStrict && nonSimple)
  2406. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2407. }
  2408. // Start a new scope with regard to labels and the `inFunction`
  2409. // flag (restore them to their old value afterwards).
  2410. var oldLabels = this.labels;
  2411. this.labels = [];
  2412. if (useStrict) { this.strict = true; }
  2413. // Add the params to varDeclaredNames to ensure that an error is thrown
  2414. // if a let/const declaration in the function clashes with one of the params.
  2415. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params));
  2416. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2417. if (this.strict && node.id) { this.checkLVal(node.id, BIND_OUTSIDE); }
  2418. node.body = this.parseBlock(false, undefined, useStrict && !oldStrict);
  2419. node.expression = false;
  2420. this.adaptDirectivePrologue(node.body.body);
  2421. this.labels = oldLabels;
  2422. }
  2423. this.exitScope();
  2424. };
  2425. pp$3.isSimpleParamList = function(params) {
  2426. for (var i = 0, list = params; i < list.length; i += 1)
  2427. {
  2428. var param = list[i];
  2429. if (param.type !== "Identifier") { return false
  2430. } }
  2431. return true
  2432. };
  2433. // Checks function params for various disallowed patterns such as using "eval"
  2434. // or "arguments" and duplicate parameters.
  2435. pp$3.checkParams = function(node, allowDuplicates) {
  2436. var nameHash = {};
  2437. for (var i = 0, list = node.params; i < list.length; i += 1)
  2438. {
  2439. var param = list[i];
  2440. this.checkLVal(param, BIND_VAR, allowDuplicates ? null : nameHash);
  2441. }
  2442. };
  2443. // Parses a comma-separated list of expressions, and returns them as
  2444. // an array. `close` is the token type that ends the list, and
  2445. // `allowEmpty` can be turned on to allow subsequent commas with
  2446. // nothing in between them to be parsed as `null` (which is needed
  2447. // for array literals).
  2448. pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2449. var elts = [], first = true;
  2450. while (!this.eat(close)) {
  2451. if (!first) {
  2452. this.expect(types.comma);
  2453. if (allowTrailingComma && this.afterTrailingComma(close)) { break }
  2454. } else { first = false; }
  2455. var elt = (void 0);
  2456. if (allowEmpty && this.type === types.comma)
  2457. { elt = null; }
  2458. else if (this.type === types.ellipsis) {
  2459. elt = this.parseSpread(refDestructuringErrors);
  2460. if (refDestructuringErrors && this.type === types.comma && refDestructuringErrors.trailingComma < 0)
  2461. { refDestructuringErrors.trailingComma = this.start; }
  2462. } else {
  2463. elt = this.parseMaybeAssign(false, refDestructuringErrors);
  2464. }
  2465. elts.push(elt);
  2466. }
  2467. return elts
  2468. };
  2469. pp$3.checkUnreserved = function(ref) {
  2470. var start = ref.start;
  2471. var end = ref.end;
  2472. var name = ref.name;
  2473. if (this.inGenerator && name === "yield")
  2474. { this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); }
  2475. if (this.inAsync && name === "await")
  2476. { this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); }
  2477. if (this.keywords.test(name))
  2478. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  2479. if (this.options.ecmaVersion < 6 &&
  2480. this.input.slice(start, end).indexOf("\\") !== -1) { return }
  2481. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  2482. if (re.test(name)) {
  2483. if (!this.inAsync && name === "await")
  2484. { this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); }
  2485. this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
  2486. }
  2487. };
  2488. // Parse the next token as an identifier. If `liberal` is true (used
  2489. // when parsing properties), it will also convert keywords into
  2490. // identifiers.
  2491. pp$3.parseIdent = function(liberal, isBinding) {
  2492. var node = this.startNode();
  2493. if (this.type === types.name) {
  2494. node.name = this.value;
  2495. } else if (this.type.keyword) {
  2496. node.name = this.type.keyword;
  2497. // To fix https://github.com/acornjs/acorn/issues/575
  2498. // `class` and `function` keywords push new context into this.context.
  2499. // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
  2500. // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
  2501. if ((node.name === "class" || node.name === "function") &&
  2502. (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
  2503. this.context.pop();
  2504. }
  2505. } else {
  2506. this.unexpected();
  2507. }
  2508. this.next(!!liberal);
  2509. this.finishNode(node, "Identifier");
  2510. if (!liberal) {
  2511. this.checkUnreserved(node);
  2512. if (node.name === "await" && !this.awaitIdentPos)
  2513. { this.awaitIdentPos = node.start; }
  2514. }
  2515. return node
  2516. };
  2517. // Parses yield expression inside generator.
  2518. pp$3.parseYield = function(noIn) {
  2519. if (!this.yieldPos) { this.yieldPos = this.start; }
  2520. var node = this.startNode();
  2521. this.next();
  2522. if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) {
  2523. node.delegate = false;
  2524. node.argument = null;
  2525. } else {
  2526. node.delegate = this.eat(types.star);
  2527. node.argument = this.parseMaybeAssign(noIn);
  2528. }
  2529. return this.finishNode(node, "YieldExpression")
  2530. };
  2531. pp$3.parseAwait = function() {
  2532. if (!this.awaitPos) { this.awaitPos = this.start; }
  2533. var node = this.startNode();
  2534. this.next();
  2535. node.argument = this.parseMaybeUnary(null, false);
  2536. return this.finishNode(node, "AwaitExpression")
  2537. };
  2538. var pp$4 = Parser.prototype;
  2539. // This function is used to raise exceptions on parse errors. It
  2540. // takes an offset integer (into the current `input`) to indicate
  2541. // the location of the error, attaches the position to the end
  2542. // of the error message, and then raises a `SyntaxError` with that
  2543. // message.
  2544. pp$4.raise = function(pos, message) {
  2545. var loc = getLineInfo(this.input, pos);
  2546. message += " (" + loc.line + ":" + loc.column + ")";
  2547. var err = new SyntaxError(message);
  2548. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  2549. throw err
  2550. };
  2551. pp$4.raiseRecoverable = pp$4.raise;
  2552. pp$4.curPosition = function() {
  2553. if (this.options.locations) {
  2554. return new Position(this.curLine, this.pos - this.lineStart)
  2555. }
  2556. };
  2557. var pp$5 = Parser.prototype;
  2558. var Scope = function Scope(flags) {
  2559. this.flags = flags;
  2560. // A list of var-declared names in the current lexical scope
  2561. this.var = [];
  2562. // A list of lexically-declared names in the current lexical scope
  2563. this.lexical = [];
  2564. // A list of lexically-declared FunctionDeclaration names in the current lexical scope
  2565. this.functions = [];
  2566. };
  2567. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  2568. pp$5.enterScope = function(flags) {
  2569. this.scopeStack.push(new Scope(flags));
  2570. };
  2571. pp$5.exitScope = function() {
  2572. this.scopeStack.pop();
  2573. };
  2574. // The spec says:
  2575. // > At the top level of a function, or script, function declarations are
  2576. // > treated like var declarations rather than like lexical declarations.
  2577. pp$5.treatFunctionsAsVarInScope = function(scope) {
  2578. return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
  2579. };
  2580. pp$5.declareName = function(name, bindingType, pos) {
  2581. var redeclared = false;
  2582. if (bindingType === BIND_LEXICAL) {
  2583. var scope = this.currentScope();
  2584. redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
  2585. scope.lexical.push(name);
  2586. if (this.inModule && (scope.flags & SCOPE_TOP))
  2587. { delete this.undefinedExports[name]; }
  2588. } else if (bindingType === BIND_SIMPLE_CATCH) {
  2589. var scope$1 = this.currentScope();
  2590. scope$1.lexical.push(name);
  2591. } else if (bindingType === BIND_FUNCTION) {
  2592. var scope$2 = this.currentScope();
  2593. if (this.treatFunctionsAsVar)
  2594. { redeclared = scope$2.lexical.indexOf(name) > -1; }
  2595. else
  2596. { redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
  2597. scope$2.functions.push(name);
  2598. } else {
  2599. for (var i = this.scopeStack.length - 1; i >= 0; --i) {
  2600. var scope$3 = this.scopeStack[i];
  2601. if (scope$3.lexical.indexOf(name) > -1 && !((scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) ||
  2602. !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
  2603. redeclared = true;
  2604. break
  2605. }
  2606. scope$3.var.push(name);
  2607. if (this.inModule && (scope$3.flags & SCOPE_TOP))
  2608. { delete this.undefinedExports[name]; }
  2609. if (scope$3.flags & SCOPE_VAR) { break }
  2610. }
  2611. }
  2612. if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); }
  2613. };
  2614. pp$5.checkLocalExport = function(id) {
  2615. // scope.functions must be empty as Module code is always strict.
  2616. if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
  2617. this.scopeStack[0].var.indexOf(id.name) === -1) {
  2618. this.undefinedExports[id.name] = id;
  2619. }
  2620. };
  2621. pp$5.currentScope = function() {
  2622. return this.scopeStack[this.scopeStack.length - 1]
  2623. };
  2624. pp$5.currentVarScope = function() {
  2625. for (var i = this.scopeStack.length - 1;; i--) {
  2626. var scope = this.scopeStack[i];
  2627. if (scope.flags & SCOPE_VAR) { return scope }
  2628. }
  2629. };
  2630. // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
  2631. pp$5.currentThisScope = function() {
  2632. for (var i = this.scopeStack.length - 1;; i--) {
  2633. var scope = this.scopeStack[i];
  2634. if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope }
  2635. }
  2636. };
  2637. var Node = function Node(parser, pos, loc) {
  2638. this.type = "";
  2639. this.start = pos;
  2640. this.end = 0;
  2641. if (parser.options.locations)
  2642. { this.loc = new SourceLocation(parser, loc); }
  2643. if (parser.options.directSourceFile)
  2644. { this.sourceFile = parser.options.directSourceFile; }
  2645. if (parser.options.ranges)
  2646. { this.range = [pos, 0]; }
  2647. };
  2648. // Start an AST node, attaching a start offset.
  2649. var pp$6 = Parser.prototype;
  2650. pp$6.startNode = function() {
  2651. return new Node(this, this.start, this.startLoc)
  2652. };
  2653. pp$6.startNodeAt = function(pos, loc) {
  2654. return new Node(this, pos, loc)
  2655. };
  2656. // Finish an AST node, adding `type` and `end` properties.
  2657. function finishNodeAt(node, type, pos, loc) {
  2658. node.type = type;
  2659. node.end = pos;
  2660. if (this.options.locations)
  2661. { node.loc.end = loc; }
  2662. if (this.options.ranges)
  2663. { node.range[1] = pos; }
  2664. return node
  2665. }
  2666. pp$6.finishNode = function(node, type) {
  2667. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  2668. };
  2669. // Finish node at given position
  2670. pp$6.finishNodeAt = function(node, type, pos, loc) {
  2671. return finishNodeAt.call(this, node, type, pos, loc)
  2672. };
  2673. // The algorithm used to determine whether a regexp can appear at a
  2674. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  2675. this.token = token;
  2676. this.isExpr = !!isExpr;
  2677. this.preserveSpace = !!preserveSpace;
  2678. this.override = override;
  2679. this.generator = !!generator;
  2680. };
  2681. var types$1 = {
  2682. b_stat: new TokContext("{", false),
  2683. b_expr: new TokContext("{", true),
  2684. b_tmpl: new TokContext("${", false),
  2685. p_stat: new TokContext("(", false),
  2686. p_expr: new TokContext("(", true),
  2687. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  2688. f_stat: new TokContext("function", false),
  2689. f_expr: new TokContext("function", true),
  2690. f_expr_gen: new TokContext("function", true, false, null, true),
  2691. f_gen: new TokContext("function", false, false, null, true)
  2692. };
  2693. var pp$7 = Parser.prototype;
  2694. pp$7.initialContext = function() {
  2695. return [types$1.b_stat]
  2696. };
  2697. pp$7.braceIsBlock = function(prevType) {
  2698. var parent = this.curContext();
  2699. if (parent === types$1.f_expr || parent === types$1.f_stat)
  2700. { return true }
  2701. if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
  2702. { return !parent.isExpr }
  2703. // The check for `tt.name && exprAllowed` detects whether we are
  2704. // after a `yield` or `of` construct. See the `updateContext` for
  2705. // `tt.name`.
  2706. if (prevType === types._return || prevType === types.name && this.exprAllowed)
  2707. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  2708. if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow)
  2709. { return true }
  2710. if (prevType === types.braceL)
  2711. { return parent === types$1.b_stat }
  2712. if (prevType === types._var || prevType === types._const || prevType === types.name)
  2713. { return false }
  2714. return !this.exprAllowed
  2715. };
  2716. pp$7.inGeneratorContext = function() {
  2717. for (var i = this.context.length - 1; i >= 1; i--) {
  2718. var context = this.context[i];
  2719. if (context.token === "function")
  2720. { return context.generator }
  2721. }
  2722. return false
  2723. };
  2724. pp$7.updateContext = function(prevType) {
  2725. var update, type = this.type;
  2726. if (type.keyword && prevType === types.dot)
  2727. { this.exprAllowed = false; }
  2728. else if (update = type.updateContext)
  2729. { update.call(this, prevType); }
  2730. else
  2731. { this.exprAllowed = type.beforeExpr; }
  2732. };
  2733. // Token-specific context update code
  2734. types.parenR.updateContext = types.braceR.updateContext = function() {
  2735. if (this.context.length === 1) {
  2736. this.exprAllowed = true;
  2737. return
  2738. }
  2739. var out = this.context.pop();
  2740. if (out === types$1.b_stat && this.curContext().token === "function") {
  2741. out = this.context.pop();
  2742. }
  2743. this.exprAllowed = !out.isExpr;
  2744. };
  2745. types.braceL.updateContext = function(prevType) {
  2746. this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
  2747. this.exprAllowed = true;
  2748. };
  2749. types.dollarBraceL.updateContext = function() {
  2750. this.context.push(types$1.b_tmpl);
  2751. this.exprAllowed = true;
  2752. };
  2753. types.parenL.updateContext = function(prevType) {
  2754. var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
  2755. this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
  2756. this.exprAllowed = true;
  2757. };
  2758. types.incDec.updateContext = function() {
  2759. // tokExprAllowed stays unchanged
  2760. };
  2761. types._function.updateContext = types._class.updateContext = function(prevType) {
  2762. if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
  2763. !(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
  2764. !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
  2765. { this.context.push(types$1.f_expr); }
  2766. else
  2767. { this.context.push(types$1.f_stat); }
  2768. this.exprAllowed = false;
  2769. };
  2770. types.backQuote.updateContext = function() {
  2771. if (this.curContext() === types$1.q_tmpl)
  2772. { this.context.pop(); }
  2773. else
  2774. { this.context.push(types$1.q_tmpl); }
  2775. this.exprAllowed = false;
  2776. };
  2777. types.star.updateContext = function(prevType) {
  2778. if (prevType === types._function) {
  2779. var index = this.context.length - 1;
  2780. if (this.context[index] === types$1.f_expr)
  2781. { this.context[index] = types$1.f_expr_gen; }
  2782. else
  2783. { this.context[index] = types$1.f_gen; }
  2784. }
  2785. this.exprAllowed = true;
  2786. };
  2787. types.name.updateContext = function(prevType) {
  2788. var allowed = false;
  2789. if (this.options.ecmaVersion >= 6 && prevType !== types.dot) {
  2790. if (this.value === "of" && !this.exprAllowed ||
  2791. this.value === "yield" && this.inGeneratorContext())
  2792. { allowed = true; }
  2793. }
  2794. this.exprAllowed = allowed;
  2795. };
  2796. // This file contains Unicode properties extracted from the ECMAScript
  2797. // specification. The lists are extracted like so:
  2798. // $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText)
  2799. // #table-binary-unicode-properties
  2800. 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";
  2801. var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
  2802. var ecma11BinaryProperties = ecma10BinaryProperties;
  2803. var unicodeBinaryProperties = {
  2804. 9: ecma9BinaryProperties,
  2805. 10: ecma10BinaryProperties,
  2806. 11: ecma11BinaryProperties
  2807. };
  2808. // #table-unicode-general-category-values
  2809. 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";
  2810. // #table-unicode-script-values
  2811. var ecma9ScriptValues = "Adlam Adlm Ahom 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 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";
  2812. var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd";
  2813. var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
  2814. var unicodeScriptValues = {
  2815. 9: ecma9ScriptValues,
  2816. 10: ecma10ScriptValues,
  2817. 11: ecma11ScriptValues
  2818. };
  2819. var data = {};
  2820. function buildUnicodeData(ecmaVersion) {
  2821. var d = data[ecmaVersion] = {
  2822. binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues),
  2823. nonBinary: {
  2824. General_Category: wordsRegexp(unicodeGeneralCategoryValues),
  2825. Script: wordsRegexp(unicodeScriptValues[ecmaVersion])
  2826. }
  2827. };
  2828. d.nonBinary.Script_Extensions = d.nonBinary.Script;
  2829. d.nonBinary.gc = d.nonBinary.General_Category;
  2830. d.nonBinary.sc = d.nonBinary.Script;
  2831. d.nonBinary.scx = d.nonBinary.Script_Extensions;
  2832. }
  2833. buildUnicodeData(9);
  2834. buildUnicodeData(10);
  2835. buildUnicodeData(11);
  2836. var pp$8 = Parser.prototype;
  2837. var RegExpValidationState = function RegExpValidationState(parser) {
  2838. this.parser = parser;
  2839. this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
  2840. this.unicodeProperties = data[parser.options.ecmaVersion >= 11 ? 11 : parser.options.ecmaVersion];
  2841. this.source = "";
  2842. this.flags = "";
  2843. this.start = 0;
  2844. this.switchU = false;
  2845. this.switchN = false;
  2846. this.pos = 0;
  2847. this.lastIntValue = 0;
  2848. this.lastStringValue = "";
  2849. this.lastAssertionIsQuantifiable = false;
  2850. this.numCapturingParens = 0;
  2851. this.maxBackReference = 0;
  2852. this.groupNames = [];
  2853. this.backReferenceNames = [];
  2854. };
  2855. RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
  2856. var unicode = flags.indexOf("u") !== -1;
  2857. this.start = start | 0;
  2858. this.source = pattern + "";
  2859. this.flags = flags;
  2860. this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
  2861. this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
  2862. };
  2863. RegExpValidationState.prototype.raise = function raise (message) {
  2864. this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
  2865. };
  2866. // If u flag is given, this returns the code point at the index (it combines a surrogate pair).
  2867. // Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
  2868. RegExpValidationState.prototype.at = function at (i, forceU) {
  2869. if ( forceU === void 0 ) forceU = false;
  2870. var s = this.source;
  2871. var l = s.length;
  2872. if (i >= l) {
  2873. return -1
  2874. }
  2875. var c = s.charCodeAt(i);
  2876. if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  2877. return c
  2878. }
  2879. var next = s.charCodeAt(i + 1);
  2880. return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c
  2881. };
  2882. RegExpValidationState.prototype.nextIndex = function nextIndex (i, forceU) {
  2883. if ( forceU === void 0 ) forceU = false;
  2884. var s = this.source;
  2885. var l = s.length;
  2886. if (i >= l) {
  2887. return l
  2888. }
  2889. var c = s.charCodeAt(i), next;
  2890. if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
  2891. (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
  2892. return i + 1
  2893. }
  2894. return i + 2
  2895. };
  2896. RegExpValidationState.prototype.current = function current (forceU) {
  2897. if ( forceU === void 0 ) forceU = false;
  2898. return this.at(this.pos, forceU)
  2899. };
  2900. RegExpValidationState.prototype.lookahead = function lookahead (forceU) {
  2901. if ( forceU === void 0 ) forceU = false;
  2902. return this.at(this.nextIndex(this.pos, forceU), forceU)
  2903. };
  2904. RegExpValidationState.prototype.advance = function advance (forceU) {
  2905. if ( forceU === void 0 ) forceU = false;
  2906. this.pos = this.nextIndex(this.pos, forceU);
  2907. };
  2908. RegExpValidationState.prototype.eat = function eat (ch, forceU) {
  2909. if ( forceU === void 0 ) forceU = false;
  2910. if (this.current(forceU) === ch) {
  2911. this.advance(forceU);
  2912. return true
  2913. }
  2914. return false
  2915. };
  2916. function codePointToString(ch) {
  2917. if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
  2918. ch -= 0x10000;
  2919. return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
  2920. }
  2921. /**
  2922. * Validate the flags part of a given RegExpLiteral.
  2923. *
  2924. * @param {RegExpValidationState} state The state to validate RegExp.
  2925. * @returns {void}
  2926. */
  2927. pp$8.validateRegExpFlags = function(state) {
  2928. var validFlags = state.validFlags;
  2929. var flags = state.flags;
  2930. for (var i = 0; i < flags.length; i++) {
  2931. var flag = flags.charAt(i);
  2932. if (validFlags.indexOf(flag) === -1) {
  2933. this.raise(state.start, "Invalid regular expression flag");
  2934. }
  2935. if (flags.indexOf(flag, i + 1) > -1) {
  2936. this.raise(state.start, "Duplicate regular expression flag");
  2937. }
  2938. }
  2939. };
  2940. /**
  2941. * Validate the pattern part of a given RegExpLiteral.
  2942. *
  2943. * @param {RegExpValidationState} state The state to validate RegExp.
  2944. * @returns {void}
  2945. */
  2946. pp$8.validateRegExpPattern = function(state) {
  2947. this.regexp_pattern(state);
  2948. // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
  2949. // parsing contains a |GroupName|, reparse with the goal symbol
  2950. // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
  2951. // exception if _P_ did not conform to the grammar, if any elements of _P_
  2952. // were not matched by the parse, or if any Early Error conditions exist.
  2953. if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
  2954. state.switchN = true;
  2955. this.regexp_pattern(state);
  2956. }
  2957. };
  2958. // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
  2959. pp$8.regexp_pattern = function(state) {
  2960. state.pos = 0;
  2961. state.lastIntValue = 0;
  2962. state.lastStringValue = "";
  2963. state.lastAssertionIsQuantifiable = false;
  2964. state.numCapturingParens = 0;
  2965. state.maxBackReference = 0;
  2966. state.groupNames.length = 0;
  2967. state.backReferenceNames.length = 0;
  2968. this.regexp_disjunction(state);
  2969. if (state.pos !== state.source.length) {
  2970. // Make the same messages as V8.
  2971. if (state.eat(0x29 /* ) */)) {
  2972. state.raise("Unmatched ')'");
  2973. }
  2974. if (state.eat(0x5D /* ] */) || state.eat(0x7D /* } */)) {
  2975. state.raise("Lone quantifier brackets");
  2976. }
  2977. }
  2978. if (state.maxBackReference > state.numCapturingParens) {
  2979. state.raise("Invalid escape");
  2980. }
  2981. for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
  2982. var name = list[i];
  2983. if (state.groupNames.indexOf(name) === -1) {
  2984. state.raise("Invalid named capture referenced");
  2985. }
  2986. }
  2987. };
  2988. // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
  2989. pp$8.regexp_disjunction = function(state) {
  2990. this.regexp_alternative(state);
  2991. while (state.eat(0x7C /* | */)) {
  2992. this.regexp_alternative(state);
  2993. }
  2994. // Make the same message as V8.
  2995. if (this.regexp_eatQuantifier(state, true)) {
  2996. state.raise("Nothing to repeat");
  2997. }
  2998. if (state.eat(0x7B /* { */)) {
  2999. state.raise("Lone quantifier brackets");
  3000. }
  3001. };
  3002. // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
  3003. pp$8.regexp_alternative = function(state) {
  3004. while (state.pos < state.source.length && this.regexp_eatTerm(state))
  3005. { }
  3006. };
  3007. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
  3008. pp$8.regexp_eatTerm = function(state) {
  3009. if (this.regexp_eatAssertion(state)) {
  3010. // Handle `QuantifiableAssertion Quantifier` alternative.
  3011. // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
  3012. // is a QuantifiableAssertion.
  3013. if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
  3014. // Make the same message as V8.
  3015. if (state.switchU) {
  3016. state.raise("Invalid quantifier");
  3017. }
  3018. }
  3019. return true
  3020. }
  3021. if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
  3022. this.regexp_eatQuantifier(state);
  3023. return true
  3024. }
  3025. return false
  3026. };
  3027. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
  3028. pp$8.regexp_eatAssertion = function(state) {
  3029. var start = state.pos;
  3030. state.lastAssertionIsQuantifiable = false;
  3031. // ^, $
  3032. if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
  3033. return true
  3034. }
  3035. // \b \B
  3036. if (state.eat(0x5C /* \ */)) {
  3037. if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
  3038. return true
  3039. }
  3040. state.pos = start;
  3041. }
  3042. // Lookahead / Lookbehind
  3043. if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
  3044. var lookbehind = false;
  3045. if (this.options.ecmaVersion >= 9) {
  3046. lookbehind = state.eat(0x3C /* < */);
  3047. }
  3048. if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
  3049. this.regexp_disjunction(state);
  3050. if (!state.eat(0x29 /* ) */)) {
  3051. state.raise("Unterminated group");
  3052. }
  3053. state.lastAssertionIsQuantifiable = !lookbehind;
  3054. return true
  3055. }
  3056. }
  3057. state.pos = start;
  3058. return false
  3059. };
  3060. // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
  3061. pp$8.regexp_eatQuantifier = function(state, noError) {
  3062. if ( noError === void 0 ) noError = false;
  3063. if (this.regexp_eatQuantifierPrefix(state, noError)) {
  3064. state.eat(0x3F /* ? */);
  3065. return true
  3066. }
  3067. return false
  3068. };
  3069. // https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
  3070. pp$8.regexp_eatQuantifierPrefix = function(state, noError) {
  3071. return (
  3072. state.eat(0x2A /* * */) ||
  3073. state.eat(0x2B /* + */) ||
  3074. state.eat(0x3F /* ? */) ||
  3075. this.regexp_eatBracedQuantifier(state, noError)
  3076. )
  3077. };
  3078. pp$8.regexp_eatBracedQuantifier = function(state, noError) {
  3079. var start = state.pos;
  3080. if (state.eat(0x7B /* { */)) {
  3081. var min = 0, max = -1;
  3082. if (this.regexp_eatDecimalDigits(state)) {
  3083. min = state.lastIntValue;
  3084. if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
  3085. max = state.lastIntValue;
  3086. }
  3087. if (state.eat(0x7D /* } */)) {
  3088. // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
  3089. if (max !== -1 && max < min && !noError) {
  3090. state.raise("numbers out of order in {} quantifier");
  3091. }
  3092. return true
  3093. }
  3094. }
  3095. if (state.switchU && !noError) {
  3096. state.raise("Incomplete quantifier");
  3097. }
  3098. state.pos = start;
  3099. }
  3100. return false
  3101. };
  3102. // https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
  3103. pp$8.regexp_eatAtom = function(state) {
  3104. return (
  3105. this.regexp_eatPatternCharacters(state) ||
  3106. state.eat(0x2E /* . */) ||
  3107. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3108. this.regexp_eatCharacterClass(state) ||
  3109. this.regexp_eatUncapturingGroup(state) ||
  3110. this.regexp_eatCapturingGroup(state)
  3111. )
  3112. };
  3113. pp$8.regexp_eatReverseSolidusAtomEscape = function(state) {
  3114. var start = state.pos;
  3115. if (state.eat(0x5C /* \ */)) {
  3116. if (this.regexp_eatAtomEscape(state)) {
  3117. return true
  3118. }
  3119. state.pos = start;
  3120. }
  3121. return false
  3122. };
  3123. pp$8.regexp_eatUncapturingGroup = function(state) {
  3124. var start = state.pos;
  3125. if (state.eat(0x28 /* ( */)) {
  3126. if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
  3127. this.regexp_disjunction(state);
  3128. if (state.eat(0x29 /* ) */)) {
  3129. return true
  3130. }
  3131. state.raise("Unterminated group");
  3132. }
  3133. state.pos = start;
  3134. }
  3135. return false
  3136. };
  3137. pp$8.regexp_eatCapturingGroup = function(state) {
  3138. if (state.eat(0x28 /* ( */)) {
  3139. if (this.options.ecmaVersion >= 9) {
  3140. this.regexp_groupSpecifier(state);
  3141. } else if (state.current() === 0x3F /* ? */) {
  3142. state.raise("Invalid group");
  3143. }
  3144. this.regexp_disjunction(state);
  3145. if (state.eat(0x29 /* ) */)) {
  3146. state.numCapturingParens += 1;
  3147. return true
  3148. }
  3149. state.raise("Unterminated group");
  3150. }
  3151. return false
  3152. };
  3153. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
  3154. pp$8.regexp_eatExtendedAtom = function(state) {
  3155. return (
  3156. state.eat(0x2E /* . */) ||
  3157. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3158. this.regexp_eatCharacterClass(state) ||
  3159. this.regexp_eatUncapturingGroup(state) ||
  3160. this.regexp_eatCapturingGroup(state) ||
  3161. this.regexp_eatInvalidBracedQuantifier(state) ||
  3162. this.regexp_eatExtendedPatternCharacter(state)
  3163. )
  3164. };
  3165. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
  3166. pp$8.regexp_eatInvalidBracedQuantifier = function(state) {
  3167. if (this.regexp_eatBracedQuantifier(state, true)) {
  3168. state.raise("Nothing to repeat");
  3169. }
  3170. return false
  3171. };
  3172. // https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
  3173. pp$8.regexp_eatSyntaxCharacter = function(state) {
  3174. var ch = state.current();
  3175. if (isSyntaxCharacter(ch)) {
  3176. state.lastIntValue = ch;
  3177. state.advance();
  3178. return true
  3179. }
  3180. return false
  3181. };
  3182. function isSyntaxCharacter(ch) {
  3183. return (
  3184. ch === 0x24 /* $ */ ||
  3185. ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
  3186. ch === 0x2E /* . */ ||
  3187. ch === 0x3F /* ? */ ||
  3188. ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
  3189. ch >= 0x7B /* { */ && ch <= 0x7D /* } */
  3190. )
  3191. }
  3192. // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
  3193. // But eat eager.
  3194. pp$8.regexp_eatPatternCharacters = function(state) {
  3195. var start = state.pos;
  3196. var ch = 0;
  3197. while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
  3198. state.advance();
  3199. }
  3200. return state.pos !== start
  3201. };
  3202. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
  3203. pp$8.regexp_eatExtendedPatternCharacter = function(state) {
  3204. var ch = state.current();
  3205. if (
  3206. ch !== -1 &&
  3207. ch !== 0x24 /* $ */ &&
  3208. !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
  3209. ch !== 0x2E /* . */ &&
  3210. ch !== 0x3F /* ? */ &&
  3211. ch !== 0x5B /* [ */ &&
  3212. ch !== 0x5E /* ^ */ &&
  3213. ch !== 0x7C /* | */
  3214. ) {
  3215. state.advance();
  3216. return true
  3217. }
  3218. return false
  3219. };
  3220. // GroupSpecifier ::
  3221. // [empty]
  3222. // `?` GroupName
  3223. pp$8.regexp_groupSpecifier = function(state) {
  3224. if (state.eat(0x3F /* ? */)) {
  3225. if (this.regexp_eatGroupName(state)) {
  3226. if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
  3227. state.raise("Duplicate capture group name");
  3228. }
  3229. state.groupNames.push(state.lastStringValue);
  3230. return
  3231. }
  3232. state.raise("Invalid group");
  3233. }
  3234. };
  3235. // GroupName ::
  3236. // `<` RegExpIdentifierName `>`
  3237. // Note: this updates `state.lastStringValue` property with the eaten name.
  3238. pp$8.regexp_eatGroupName = function(state) {
  3239. state.lastStringValue = "";
  3240. if (state.eat(0x3C /* < */)) {
  3241. if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
  3242. return true
  3243. }
  3244. state.raise("Invalid capture group name");
  3245. }
  3246. return false
  3247. };
  3248. // RegExpIdentifierName ::
  3249. // RegExpIdentifierStart
  3250. // RegExpIdentifierName RegExpIdentifierPart
  3251. // Note: this updates `state.lastStringValue` property with the eaten name.
  3252. pp$8.regexp_eatRegExpIdentifierName = function(state) {
  3253. state.lastStringValue = "";
  3254. if (this.regexp_eatRegExpIdentifierStart(state)) {
  3255. state.lastStringValue += codePointToString(state.lastIntValue);
  3256. while (this.regexp_eatRegExpIdentifierPart(state)) {
  3257. state.lastStringValue += codePointToString(state.lastIntValue);
  3258. }
  3259. return true
  3260. }
  3261. return false
  3262. };
  3263. // RegExpIdentifierStart ::
  3264. // UnicodeIDStart
  3265. // `$`
  3266. // `_`
  3267. // `\` RegExpUnicodeEscapeSequence[+U]
  3268. pp$8.regexp_eatRegExpIdentifierStart = function(state) {
  3269. var start = state.pos;
  3270. var forceU = this.options.ecmaVersion >= 11;
  3271. var ch = state.current(forceU);
  3272. state.advance(forceU);
  3273. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
  3274. ch = state.lastIntValue;
  3275. }
  3276. if (isRegExpIdentifierStart(ch)) {
  3277. state.lastIntValue = ch;
  3278. return true
  3279. }
  3280. state.pos = start;
  3281. return false
  3282. };
  3283. function isRegExpIdentifierStart(ch) {
  3284. return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
  3285. }
  3286. // RegExpIdentifierPart ::
  3287. // UnicodeIDContinue
  3288. // `$`
  3289. // `_`
  3290. // `\` RegExpUnicodeEscapeSequence[+U]
  3291. // <ZWNJ>
  3292. // <ZWJ>
  3293. pp$8.regexp_eatRegExpIdentifierPart = function(state) {
  3294. var start = state.pos;
  3295. var forceU = this.options.ecmaVersion >= 11;
  3296. var ch = state.current(forceU);
  3297. state.advance(forceU);
  3298. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
  3299. ch = state.lastIntValue;
  3300. }
  3301. if (isRegExpIdentifierPart(ch)) {
  3302. state.lastIntValue = ch;
  3303. return true
  3304. }
  3305. state.pos = start;
  3306. return false
  3307. };
  3308. function isRegExpIdentifierPart(ch) {
  3309. return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
  3310. }
  3311. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
  3312. pp$8.regexp_eatAtomEscape = function(state) {
  3313. if (
  3314. this.regexp_eatBackReference(state) ||
  3315. this.regexp_eatCharacterClassEscape(state) ||
  3316. this.regexp_eatCharacterEscape(state) ||
  3317. (state.switchN && this.regexp_eatKGroupName(state))
  3318. ) {
  3319. return true
  3320. }
  3321. if (state.switchU) {
  3322. // Make the same message as V8.
  3323. if (state.current() === 0x63 /* c */) {
  3324. state.raise("Invalid unicode escape");
  3325. }
  3326. state.raise("Invalid escape");
  3327. }
  3328. return false
  3329. };
  3330. pp$8.regexp_eatBackReference = function(state) {
  3331. var start = state.pos;
  3332. if (this.regexp_eatDecimalEscape(state)) {
  3333. var n = state.lastIntValue;
  3334. if (state.switchU) {
  3335. // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
  3336. if (n > state.maxBackReference) {
  3337. state.maxBackReference = n;
  3338. }
  3339. return true
  3340. }
  3341. if (n <= state.numCapturingParens) {
  3342. return true
  3343. }
  3344. state.pos = start;
  3345. }
  3346. return false
  3347. };
  3348. pp$8.regexp_eatKGroupName = function(state) {
  3349. if (state.eat(0x6B /* k */)) {
  3350. if (this.regexp_eatGroupName(state)) {
  3351. state.backReferenceNames.push(state.lastStringValue);
  3352. return true
  3353. }
  3354. state.raise("Invalid named reference");
  3355. }
  3356. return false
  3357. };
  3358. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
  3359. pp$8.regexp_eatCharacterEscape = function(state) {
  3360. return (
  3361. this.regexp_eatControlEscape(state) ||
  3362. this.regexp_eatCControlLetter(state) ||
  3363. this.regexp_eatZero(state) ||
  3364. this.regexp_eatHexEscapeSequence(state) ||
  3365. this.regexp_eatRegExpUnicodeEscapeSequence(state, false) ||
  3366. (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
  3367. this.regexp_eatIdentityEscape(state)
  3368. )
  3369. };
  3370. pp$8.regexp_eatCControlLetter = function(state) {
  3371. var start = state.pos;
  3372. if (state.eat(0x63 /* c */)) {
  3373. if (this.regexp_eatControlLetter(state)) {
  3374. return true
  3375. }
  3376. state.pos = start;
  3377. }
  3378. return false
  3379. };
  3380. pp$8.regexp_eatZero = function(state) {
  3381. if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
  3382. state.lastIntValue = 0;
  3383. state.advance();
  3384. return true
  3385. }
  3386. return false
  3387. };
  3388. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
  3389. pp$8.regexp_eatControlEscape = function(state) {
  3390. var ch = state.current();
  3391. if (ch === 0x74 /* t */) {
  3392. state.lastIntValue = 0x09; /* \t */
  3393. state.advance();
  3394. return true
  3395. }
  3396. if (ch === 0x6E /* n */) {
  3397. state.lastIntValue = 0x0A; /* \n */
  3398. state.advance();
  3399. return true
  3400. }
  3401. if (ch === 0x76 /* v */) {
  3402. state.lastIntValue = 0x0B; /* \v */
  3403. state.advance();
  3404. return true
  3405. }
  3406. if (ch === 0x66 /* f */) {
  3407. state.lastIntValue = 0x0C; /* \f */
  3408. state.advance();
  3409. return true
  3410. }
  3411. if (ch === 0x72 /* r */) {
  3412. state.lastIntValue = 0x0D; /* \r */
  3413. state.advance();
  3414. return true
  3415. }
  3416. return false
  3417. };
  3418. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
  3419. pp$8.regexp_eatControlLetter = function(state) {
  3420. var ch = state.current();
  3421. if (isControlLetter(ch)) {
  3422. state.lastIntValue = ch % 0x20;
  3423. state.advance();
  3424. return true
  3425. }
  3426. return false
  3427. };
  3428. function isControlLetter(ch) {
  3429. return (
  3430. (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
  3431. (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
  3432. )
  3433. }
  3434. // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
  3435. pp$8.regexp_eatRegExpUnicodeEscapeSequence = function(state, forceU) {
  3436. if ( forceU === void 0 ) forceU = false;
  3437. var start = state.pos;
  3438. var switchU = forceU || state.switchU;
  3439. if (state.eat(0x75 /* u */)) {
  3440. if (this.regexp_eatFixedHexDigits(state, 4)) {
  3441. var lead = state.lastIntValue;
  3442. if (switchU && lead >= 0xD800 && lead <= 0xDBFF) {
  3443. var leadSurrogateEnd = state.pos;
  3444. if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
  3445. var trail = state.lastIntValue;
  3446. if (trail >= 0xDC00 && trail <= 0xDFFF) {
  3447. state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  3448. return true
  3449. }
  3450. }
  3451. state.pos = leadSurrogateEnd;
  3452. state.lastIntValue = lead;
  3453. }
  3454. return true
  3455. }
  3456. if (
  3457. switchU &&
  3458. state.eat(0x7B /* { */) &&
  3459. this.regexp_eatHexDigits(state) &&
  3460. state.eat(0x7D /* } */) &&
  3461. isValidUnicode(state.lastIntValue)
  3462. ) {
  3463. return true
  3464. }
  3465. if (switchU) {
  3466. state.raise("Invalid unicode escape");
  3467. }
  3468. state.pos = start;
  3469. }
  3470. return false
  3471. };
  3472. function isValidUnicode(ch) {
  3473. return ch >= 0 && ch <= 0x10FFFF
  3474. }
  3475. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
  3476. pp$8.regexp_eatIdentityEscape = function(state) {
  3477. if (state.switchU) {
  3478. if (this.regexp_eatSyntaxCharacter(state)) {
  3479. return true
  3480. }
  3481. if (state.eat(0x2F /* / */)) {
  3482. state.lastIntValue = 0x2F; /* / */
  3483. return true
  3484. }
  3485. return false
  3486. }
  3487. var ch = state.current();
  3488. if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
  3489. state.lastIntValue = ch;
  3490. state.advance();
  3491. return true
  3492. }
  3493. return false
  3494. };
  3495. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
  3496. pp$8.regexp_eatDecimalEscape = function(state) {
  3497. state.lastIntValue = 0;
  3498. var ch = state.current();
  3499. if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
  3500. do {
  3501. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3502. state.advance();
  3503. } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
  3504. return true
  3505. }
  3506. return false
  3507. };
  3508. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
  3509. pp$8.regexp_eatCharacterClassEscape = function(state) {
  3510. var ch = state.current();
  3511. if (isCharacterClassEscape(ch)) {
  3512. state.lastIntValue = -1;
  3513. state.advance();
  3514. return true
  3515. }
  3516. if (
  3517. state.switchU &&
  3518. this.options.ecmaVersion >= 9 &&
  3519. (ch === 0x50 /* P */ || ch === 0x70 /* p */)
  3520. ) {
  3521. state.lastIntValue = -1;
  3522. state.advance();
  3523. if (
  3524. state.eat(0x7B /* { */) &&
  3525. this.regexp_eatUnicodePropertyValueExpression(state) &&
  3526. state.eat(0x7D /* } */)
  3527. ) {
  3528. return true
  3529. }
  3530. state.raise("Invalid property name");
  3531. }
  3532. return false
  3533. };
  3534. function isCharacterClassEscape(ch) {
  3535. return (
  3536. ch === 0x64 /* d */ ||
  3537. ch === 0x44 /* D */ ||
  3538. ch === 0x73 /* s */ ||
  3539. ch === 0x53 /* S */ ||
  3540. ch === 0x77 /* w */ ||
  3541. ch === 0x57 /* W */
  3542. )
  3543. }
  3544. // UnicodePropertyValueExpression ::
  3545. // UnicodePropertyName `=` UnicodePropertyValue
  3546. // LoneUnicodePropertyNameOrValue
  3547. pp$8.regexp_eatUnicodePropertyValueExpression = function(state) {
  3548. var start = state.pos;
  3549. // UnicodePropertyName `=` UnicodePropertyValue
  3550. if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
  3551. var name = state.lastStringValue;
  3552. if (this.regexp_eatUnicodePropertyValue(state)) {
  3553. var value = state.lastStringValue;
  3554. this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
  3555. return true
  3556. }
  3557. }
  3558. state.pos = start;
  3559. // LoneUnicodePropertyNameOrValue
  3560. if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
  3561. var nameOrValue = state.lastStringValue;
  3562. this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
  3563. return true
  3564. }
  3565. return false
  3566. };
  3567. pp$8.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
  3568. if (!has(state.unicodeProperties.nonBinary, name))
  3569. { state.raise("Invalid property name"); }
  3570. if (!state.unicodeProperties.nonBinary[name].test(value))
  3571. { state.raise("Invalid property value"); }
  3572. };
  3573. pp$8.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
  3574. if (!state.unicodeProperties.binary.test(nameOrValue))
  3575. { state.raise("Invalid property name"); }
  3576. };
  3577. // UnicodePropertyName ::
  3578. // UnicodePropertyNameCharacters
  3579. pp$8.regexp_eatUnicodePropertyName = function(state) {
  3580. var ch = 0;
  3581. state.lastStringValue = "";
  3582. while (isUnicodePropertyNameCharacter(ch = state.current())) {
  3583. state.lastStringValue += codePointToString(ch);
  3584. state.advance();
  3585. }
  3586. return state.lastStringValue !== ""
  3587. };
  3588. function isUnicodePropertyNameCharacter(ch) {
  3589. return isControlLetter(ch) || ch === 0x5F /* _ */
  3590. }
  3591. // UnicodePropertyValue ::
  3592. // UnicodePropertyValueCharacters
  3593. pp$8.regexp_eatUnicodePropertyValue = function(state) {
  3594. var ch = 0;
  3595. state.lastStringValue = "";
  3596. while (isUnicodePropertyValueCharacter(ch = state.current())) {
  3597. state.lastStringValue += codePointToString(ch);
  3598. state.advance();
  3599. }
  3600. return state.lastStringValue !== ""
  3601. };
  3602. function isUnicodePropertyValueCharacter(ch) {
  3603. return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
  3604. }
  3605. // LoneUnicodePropertyNameOrValue ::
  3606. // UnicodePropertyValueCharacters
  3607. pp$8.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
  3608. return this.regexp_eatUnicodePropertyValue(state)
  3609. };
  3610. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
  3611. pp$8.regexp_eatCharacterClass = function(state) {
  3612. if (state.eat(0x5B /* [ */)) {
  3613. state.eat(0x5E /* ^ */);
  3614. this.regexp_classRanges(state);
  3615. if (state.eat(0x5D /* ] */)) {
  3616. return true
  3617. }
  3618. // Unreachable since it threw "unterminated regular expression" error before.
  3619. state.raise("Unterminated character class");
  3620. }
  3621. return false
  3622. };
  3623. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
  3624. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
  3625. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
  3626. pp$8.regexp_classRanges = function(state) {
  3627. while (this.regexp_eatClassAtom(state)) {
  3628. var left = state.lastIntValue;
  3629. if (state.eat(0x2D /* - */) && this.regexp_eatClassAtom(state)) {
  3630. var right = state.lastIntValue;
  3631. if (state.switchU && (left === -1 || right === -1)) {
  3632. state.raise("Invalid character class");
  3633. }
  3634. if (left !== -1 && right !== -1 && left > right) {
  3635. state.raise("Range out of order in character class");
  3636. }
  3637. }
  3638. }
  3639. };
  3640. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
  3641. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
  3642. pp$8.regexp_eatClassAtom = function(state) {
  3643. var start = state.pos;
  3644. if (state.eat(0x5C /* \ */)) {
  3645. if (this.regexp_eatClassEscape(state)) {
  3646. return true
  3647. }
  3648. if (state.switchU) {
  3649. // Make the same message as V8.
  3650. var ch$1 = state.current();
  3651. if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
  3652. state.raise("Invalid class escape");
  3653. }
  3654. state.raise("Invalid escape");
  3655. }
  3656. state.pos = start;
  3657. }
  3658. var ch = state.current();
  3659. if (ch !== 0x5D /* ] */) {
  3660. state.lastIntValue = ch;
  3661. state.advance();
  3662. return true
  3663. }
  3664. return false
  3665. };
  3666. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
  3667. pp$8.regexp_eatClassEscape = function(state) {
  3668. var start = state.pos;
  3669. if (state.eat(0x62 /* b */)) {
  3670. state.lastIntValue = 0x08; /* <BS> */
  3671. return true
  3672. }
  3673. if (state.switchU && state.eat(0x2D /* - */)) {
  3674. state.lastIntValue = 0x2D; /* - */
  3675. return true
  3676. }
  3677. if (!state.switchU && state.eat(0x63 /* c */)) {
  3678. if (this.regexp_eatClassControlLetter(state)) {
  3679. return true
  3680. }
  3681. state.pos = start;
  3682. }
  3683. return (
  3684. this.regexp_eatCharacterClassEscape(state) ||
  3685. this.regexp_eatCharacterEscape(state)
  3686. )
  3687. };
  3688. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
  3689. pp$8.regexp_eatClassControlLetter = function(state) {
  3690. var ch = state.current();
  3691. if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
  3692. state.lastIntValue = ch % 0x20;
  3693. state.advance();
  3694. return true
  3695. }
  3696. return false
  3697. };
  3698. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  3699. pp$8.regexp_eatHexEscapeSequence = function(state) {
  3700. var start = state.pos;
  3701. if (state.eat(0x78 /* x */)) {
  3702. if (this.regexp_eatFixedHexDigits(state, 2)) {
  3703. return true
  3704. }
  3705. if (state.switchU) {
  3706. state.raise("Invalid escape");
  3707. }
  3708. state.pos = start;
  3709. }
  3710. return false
  3711. };
  3712. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
  3713. pp$8.regexp_eatDecimalDigits = function(state) {
  3714. var start = state.pos;
  3715. var ch = 0;
  3716. state.lastIntValue = 0;
  3717. while (isDecimalDigit(ch = state.current())) {
  3718. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3719. state.advance();
  3720. }
  3721. return state.pos !== start
  3722. };
  3723. function isDecimalDigit(ch) {
  3724. return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
  3725. }
  3726. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
  3727. pp$8.regexp_eatHexDigits = function(state) {
  3728. var start = state.pos;
  3729. var ch = 0;
  3730. state.lastIntValue = 0;
  3731. while (isHexDigit(ch = state.current())) {
  3732. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  3733. state.advance();
  3734. }
  3735. return state.pos !== start
  3736. };
  3737. function isHexDigit(ch) {
  3738. return (
  3739. (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
  3740. (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
  3741. (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
  3742. )
  3743. }
  3744. function hexToInt(ch) {
  3745. if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
  3746. return 10 + (ch - 0x41 /* A */)
  3747. }
  3748. if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
  3749. return 10 + (ch - 0x61 /* a */)
  3750. }
  3751. return ch - 0x30 /* 0 */
  3752. }
  3753. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
  3754. // Allows only 0-377(octal) i.e. 0-255(decimal).
  3755. pp$8.regexp_eatLegacyOctalEscapeSequence = function(state) {
  3756. if (this.regexp_eatOctalDigit(state)) {
  3757. var n1 = state.lastIntValue;
  3758. if (this.regexp_eatOctalDigit(state)) {
  3759. var n2 = state.lastIntValue;
  3760. if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
  3761. state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
  3762. } else {
  3763. state.lastIntValue = n1 * 8 + n2;
  3764. }
  3765. } else {
  3766. state.lastIntValue = n1;
  3767. }
  3768. return true
  3769. }
  3770. return false
  3771. };
  3772. // https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
  3773. pp$8.regexp_eatOctalDigit = function(state) {
  3774. var ch = state.current();
  3775. if (isOctalDigit(ch)) {
  3776. state.lastIntValue = ch - 0x30; /* 0 */
  3777. state.advance();
  3778. return true
  3779. }
  3780. state.lastIntValue = 0;
  3781. return false
  3782. };
  3783. function isOctalDigit(ch) {
  3784. return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
  3785. }
  3786. // https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
  3787. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
  3788. // And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  3789. pp$8.regexp_eatFixedHexDigits = function(state, length) {
  3790. var start = state.pos;
  3791. state.lastIntValue = 0;
  3792. for (var i = 0; i < length; ++i) {
  3793. var ch = state.current();
  3794. if (!isHexDigit(ch)) {
  3795. state.pos = start;
  3796. return false
  3797. }
  3798. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  3799. state.advance();
  3800. }
  3801. return true
  3802. };
  3803. // Object type used to represent tokens. Note that normally, tokens
  3804. // simply exist as properties on the parser object. This is only
  3805. // used for the onToken callback and the external tokenizer.
  3806. var Token = function Token(p) {
  3807. this.type = p.type;
  3808. this.value = p.value;
  3809. this.start = p.start;
  3810. this.end = p.end;
  3811. if (p.options.locations)
  3812. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  3813. if (p.options.ranges)
  3814. { this.range = [p.start, p.end]; }
  3815. };
  3816. // ## Tokenizer
  3817. var pp$9 = Parser.prototype;
  3818. // Move to the next token
  3819. pp$9.next = function(ignoreEscapeSequenceInKeyword) {
  3820. if (!ignoreEscapeSequenceInKeyword && this.type.keyword && this.containsEsc)
  3821. { this.raiseRecoverable(this.start, "Escape sequence in keyword " + this.type.keyword); }
  3822. if (this.options.onToken)
  3823. { this.options.onToken(new Token(this)); }
  3824. this.lastTokEnd = this.end;
  3825. this.lastTokStart = this.start;
  3826. this.lastTokEndLoc = this.endLoc;
  3827. this.lastTokStartLoc = this.startLoc;
  3828. this.nextToken();
  3829. };
  3830. pp$9.getToken = function() {
  3831. this.next();
  3832. return new Token(this)
  3833. };
  3834. // If we're in an ES6 environment, make parsers iterable
  3835. if (typeof Symbol !== "undefined")
  3836. { pp$9[Symbol.iterator] = function() {
  3837. var this$1 = this;
  3838. return {
  3839. next: function () {
  3840. var token = this$1.getToken();
  3841. return {
  3842. done: token.type === types.eof,
  3843. value: token
  3844. }
  3845. }
  3846. }
  3847. }; }
  3848. // Toggle strict mode. Re-reads the next number or string to please
  3849. // pedantic tests (`"use strict"; 010;` should fail).
  3850. pp$9.curContext = function() {
  3851. return this.context[this.context.length - 1]
  3852. };
  3853. // Read a single token, updating the parser object's token-related
  3854. // properties.
  3855. pp$9.nextToken = function() {
  3856. var curContext = this.curContext();
  3857. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  3858. this.start = this.pos;
  3859. if (this.options.locations) { this.startLoc = this.curPosition(); }
  3860. if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
  3861. if (curContext.override) { return curContext.override(this) }
  3862. else { this.readToken(this.fullCharCodeAtPos()); }
  3863. };
  3864. pp$9.readToken = function(code) {
  3865. // Identifier or keyword. '\uXXXX' sequences are allowed in
  3866. // identifiers, so '\' also dispatches to that.
  3867. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  3868. { return this.readWord() }
  3869. return this.getTokenFromCode(code)
  3870. };
  3871. pp$9.fullCharCodeAtPos = function() {
  3872. var code = this.input.charCodeAt(this.pos);
  3873. if (code <= 0xd7ff || code >= 0xe000) { return code }
  3874. var next = this.input.charCodeAt(this.pos + 1);
  3875. return (code << 10) + next - 0x35fdc00
  3876. };
  3877. pp$9.skipBlockComment = function() {
  3878. var startLoc = this.options.onComment && this.curPosition();
  3879. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  3880. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  3881. this.pos = end + 2;
  3882. if (this.options.locations) {
  3883. lineBreakG.lastIndex = start;
  3884. var match;
  3885. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  3886. ++this.curLine;
  3887. this.lineStart = match.index + match[0].length;
  3888. }
  3889. }
  3890. if (this.options.onComment)
  3891. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  3892. startLoc, this.curPosition()); }
  3893. };
  3894. pp$9.skipLineComment = function(startSkip) {
  3895. var start = this.pos;
  3896. var startLoc = this.options.onComment && this.curPosition();
  3897. var ch = this.input.charCodeAt(this.pos += startSkip);
  3898. while (this.pos < this.input.length && !isNewLine(ch)) {
  3899. ch = this.input.charCodeAt(++this.pos);
  3900. }
  3901. if (this.options.onComment)
  3902. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  3903. startLoc, this.curPosition()); }
  3904. };
  3905. // Called at the start of the parse and after every token. Skips
  3906. // whitespace and comments, and.
  3907. pp$9.skipSpace = function() {
  3908. loop: while (this.pos < this.input.length) {
  3909. var ch = this.input.charCodeAt(this.pos);
  3910. switch (ch) {
  3911. case 32: case 160: // ' '
  3912. ++this.pos;
  3913. break
  3914. case 13:
  3915. if (this.input.charCodeAt(this.pos + 1) === 10) {
  3916. ++this.pos;
  3917. }
  3918. case 10: case 8232: case 8233:
  3919. ++this.pos;
  3920. if (this.options.locations) {
  3921. ++this.curLine;
  3922. this.lineStart = this.pos;
  3923. }
  3924. break
  3925. case 47: // '/'
  3926. switch (this.input.charCodeAt(this.pos + 1)) {
  3927. case 42: // '*'
  3928. this.skipBlockComment();
  3929. break
  3930. case 47:
  3931. this.skipLineComment(2);
  3932. break
  3933. default:
  3934. break loop
  3935. }
  3936. break
  3937. default:
  3938. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  3939. ++this.pos;
  3940. } else {
  3941. break loop
  3942. }
  3943. }
  3944. }
  3945. };
  3946. // Called at the end of every token. Sets `end`, `val`, and
  3947. // maintains `context` and `exprAllowed`, and skips the space after
  3948. // the token, so that the next one's `start` will point at the
  3949. // right position.
  3950. pp$9.finishToken = function(type, val) {
  3951. this.end = this.pos;
  3952. if (this.options.locations) { this.endLoc = this.curPosition(); }
  3953. var prevType = this.type;
  3954. this.type = type;
  3955. this.value = val;
  3956. this.updateContext(prevType);
  3957. };
  3958. // ### Token reading
  3959. // This is the function that is called to fetch the next token. It
  3960. // is somewhat obscure, because it works in character codes rather
  3961. // than characters, and because operator parsing has been inlined
  3962. // into it.
  3963. //
  3964. // All in the name of speed.
  3965. //
  3966. pp$9.readToken_dot = function() {
  3967. var next = this.input.charCodeAt(this.pos + 1);
  3968. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  3969. var next2 = this.input.charCodeAt(this.pos + 2);
  3970. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  3971. this.pos += 3;
  3972. return this.finishToken(types.ellipsis)
  3973. } else {
  3974. ++this.pos;
  3975. return this.finishToken(types.dot)
  3976. }
  3977. };
  3978. pp$9.readToken_slash = function() { // '/'
  3979. var next = this.input.charCodeAt(this.pos + 1);
  3980. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  3981. if (next === 61) { return this.finishOp(types.assign, 2) }
  3982. return this.finishOp(types.slash, 1)
  3983. };
  3984. pp$9.readToken_mult_modulo_exp = function(code) { // '%*'
  3985. var next = this.input.charCodeAt(this.pos + 1);
  3986. var size = 1;
  3987. var tokentype = code === 42 ? types.star : types.modulo;
  3988. // exponentiation operator ** and **=
  3989. if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
  3990. ++size;
  3991. tokentype = types.starstar;
  3992. next = this.input.charCodeAt(this.pos + 2);
  3993. }
  3994. if (next === 61) { return this.finishOp(types.assign, size + 1) }
  3995. return this.finishOp(tokentype, size)
  3996. };
  3997. pp$9.readToken_pipe_amp = function(code) { // '|&'
  3998. var next = this.input.charCodeAt(this.pos + 1);
  3999. if (next === code) {
  4000. if (this.options.ecmaVersion >= 12) {
  4001. var next2 = this.input.charCodeAt(this.pos + 2);
  4002. if (next2 === 61) { return this.finishOp(types.assign, 3) }
  4003. }
  4004. return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2)
  4005. }
  4006. if (next === 61) { return this.finishOp(types.assign, 2) }
  4007. return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
  4008. };
  4009. pp$9.readToken_caret = function() { // '^'
  4010. var next = this.input.charCodeAt(this.pos + 1);
  4011. if (next === 61) { return this.finishOp(types.assign, 2) }
  4012. return this.finishOp(types.bitwiseXOR, 1)
  4013. };
  4014. pp$9.readToken_plus_min = function(code) { // '+-'
  4015. var next = this.input.charCodeAt(this.pos + 1);
  4016. if (next === code) {
  4017. if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
  4018. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  4019. // A `-->` line comment
  4020. this.skipLineComment(3);
  4021. this.skipSpace();
  4022. return this.nextToken()
  4023. }
  4024. return this.finishOp(types.incDec, 2)
  4025. }
  4026. if (next === 61) { return this.finishOp(types.assign, 2) }
  4027. return this.finishOp(types.plusMin, 1)
  4028. };
  4029. pp$9.readToken_lt_gt = function(code) { // '<>'
  4030. var next = this.input.charCodeAt(this.pos + 1);
  4031. var size = 1;
  4032. if (next === code) {
  4033. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  4034. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
  4035. return this.finishOp(types.bitShift, size)
  4036. }
  4037. if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
  4038. this.input.charCodeAt(this.pos + 3) === 45) {
  4039. // `<!--`, an XML-style comment that should be interpreted as a line comment
  4040. this.skipLineComment(4);
  4041. this.skipSpace();
  4042. return this.nextToken()
  4043. }
  4044. if (next === 61) { size = 2; }
  4045. return this.finishOp(types.relational, size)
  4046. };
  4047. pp$9.readToken_eq_excl = function(code) { // '=!'
  4048. var next = this.input.charCodeAt(this.pos + 1);
  4049. if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  4050. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  4051. this.pos += 2;
  4052. return this.finishToken(types.arrow)
  4053. }
  4054. return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
  4055. };
  4056. pp$9.readToken_question = function() { // '?'
  4057. var ecmaVersion = this.options.ecmaVersion;
  4058. if (ecmaVersion >= 11) {
  4059. var next = this.input.charCodeAt(this.pos + 1);
  4060. if (next === 46) {
  4061. var next2 = this.input.charCodeAt(this.pos + 2);
  4062. if (next2 < 48 || next2 > 57) { return this.finishOp(types.questionDot, 2) }
  4063. }
  4064. if (next === 63) {
  4065. if (ecmaVersion >= 12) {
  4066. var next2$1 = this.input.charCodeAt(this.pos + 2);
  4067. if (next2$1 === 61) { return this.finishOp(types.assign, 3) }
  4068. }
  4069. return this.finishOp(types.coalesce, 2)
  4070. }
  4071. }
  4072. return this.finishOp(types.question, 1)
  4073. };
  4074. pp$9.getTokenFromCode = function(code) {
  4075. switch (code) {
  4076. // The interpretation of a dot depends on whether it is followed
  4077. // by a digit or another two dots.
  4078. case 46: // '.'
  4079. return this.readToken_dot()
  4080. // Punctuation tokens.
  4081. case 40: ++this.pos; return this.finishToken(types.parenL)
  4082. case 41: ++this.pos; return this.finishToken(types.parenR)
  4083. case 59: ++this.pos; return this.finishToken(types.semi)
  4084. case 44: ++this.pos; return this.finishToken(types.comma)
  4085. case 91: ++this.pos; return this.finishToken(types.bracketL)
  4086. case 93: ++this.pos; return this.finishToken(types.bracketR)
  4087. case 123: ++this.pos; return this.finishToken(types.braceL)
  4088. case 125: ++this.pos; return this.finishToken(types.braceR)
  4089. case 58: ++this.pos; return this.finishToken(types.colon)
  4090. case 96: // '`'
  4091. if (this.options.ecmaVersion < 6) { break }
  4092. ++this.pos;
  4093. return this.finishToken(types.backQuote)
  4094. case 48: // '0'
  4095. var next = this.input.charCodeAt(this.pos + 1);
  4096. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  4097. if (this.options.ecmaVersion >= 6) {
  4098. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  4099. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  4100. }
  4101. // Anything else beginning with a digit is an integer, octal
  4102. // number, or float.
  4103. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  4104. return this.readNumber(false)
  4105. // Quotes produce strings.
  4106. case 34: case 39: // '"', "'"
  4107. return this.readString(code)
  4108. // Operators are parsed inline in tiny state machines. '=' (61) is
  4109. // often referred to. `finishOp` simply skips the amount of
  4110. // characters it is given as second argument, and returns a token
  4111. // of the type given by its first argument.
  4112. case 47: // '/'
  4113. return this.readToken_slash()
  4114. case 37: case 42: // '%*'
  4115. return this.readToken_mult_modulo_exp(code)
  4116. case 124: case 38: // '|&'
  4117. return this.readToken_pipe_amp(code)
  4118. case 94: // '^'
  4119. return this.readToken_caret()
  4120. case 43: case 45: // '+-'
  4121. return this.readToken_plus_min(code)
  4122. case 60: case 62: // '<>'
  4123. return this.readToken_lt_gt(code)
  4124. case 61: case 33: // '=!'
  4125. return this.readToken_eq_excl(code)
  4126. case 63: // '?'
  4127. return this.readToken_question()
  4128. case 126: // '~'
  4129. return this.finishOp(types.prefix, 1)
  4130. }
  4131. this.raise(this.pos, "Unexpected character '" + codePointToString$1(code) + "'");
  4132. };
  4133. pp$9.finishOp = function(type, size) {
  4134. var str = this.input.slice(this.pos, this.pos + size);
  4135. this.pos += size;
  4136. return this.finishToken(type, str)
  4137. };
  4138. pp$9.readRegexp = function() {
  4139. var escaped, inClass, start = this.pos;
  4140. for (;;) {
  4141. if (this.pos >= this.input.length) { this.raise(start, "Unterminated regular expression"); }
  4142. var ch = this.input.charAt(this.pos);
  4143. if (lineBreak.test(ch)) { this.raise(start, "Unterminated regular expression"); }
  4144. if (!escaped) {
  4145. if (ch === "[") { inClass = true; }
  4146. else if (ch === "]" && inClass) { inClass = false; }
  4147. else if (ch === "/" && !inClass) { break }
  4148. escaped = ch === "\\";
  4149. } else { escaped = false; }
  4150. ++this.pos;
  4151. }
  4152. var pattern = this.input.slice(start, this.pos);
  4153. ++this.pos;
  4154. var flagsStart = this.pos;
  4155. var flags = this.readWord1();
  4156. if (this.containsEsc) { this.unexpected(flagsStart); }
  4157. // Validate pattern
  4158. var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
  4159. state.reset(start, pattern, flags);
  4160. this.validateRegExpFlags(state);
  4161. this.validateRegExpPattern(state);
  4162. // Create Literal#value property value.
  4163. var value = null;
  4164. try {
  4165. value = new RegExp(pattern, flags);
  4166. } catch (e) {
  4167. // ESTree requires null if it failed to instantiate RegExp object.
  4168. // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
  4169. }
  4170. return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
  4171. };
  4172. // Read an integer in the given radix. Return null if zero digits
  4173. // were read, the integer value otherwise. When `len` is given, this
  4174. // will return `null` unless the integer has exactly `len` digits.
  4175. pp$9.readInt = function(radix, len, maybeLegacyOctalNumericLiteral) {
  4176. // `len` is used for character escape sequences. In that case, disallow separators.
  4177. var allowSeparators = this.options.ecmaVersion >= 12 && len === undefined;
  4178. // `maybeLegacyOctalNumericLiteral` is true if it doesn't have prefix (0x,0o,0b)
  4179. // and isn't fraction part nor exponent part. In that case, if the first digit
  4180. // is zero then disallow separators.
  4181. var isLegacyOctalNumericLiteral = maybeLegacyOctalNumericLiteral && this.input.charCodeAt(this.pos) === 48;
  4182. var start = this.pos, total = 0, lastCode = 0;
  4183. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i, ++this.pos) {
  4184. var code = this.input.charCodeAt(this.pos), val = (void 0);
  4185. if (allowSeparators && code === 95) {
  4186. if (isLegacyOctalNumericLiteral) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed in legacy octal numeric literals"); }
  4187. if (lastCode === 95) { this.raiseRecoverable(this.pos, "Numeric separator must be exactly one underscore"); }
  4188. if (i === 0) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed at the first of digits"); }
  4189. lastCode = code;
  4190. continue
  4191. }
  4192. if (code >= 97) { val = code - 97 + 10; } // a
  4193. else if (code >= 65) { val = code - 65 + 10; } // A
  4194. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  4195. else { val = Infinity; }
  4196. if (val >= radix) { break }
  4197. lastCode = code;
  4198. total = total * radix + val;
  4199. }
  4200. if (allowSeparators && lastCode === 95) { this.raiseRecoverable(this.pos - 1, "Numeric separator is not allowed at the last of digits"); }
  4201. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  4202. return total
  4203. };
  4204. function stringToNumber(str, isLegacyOctalNumericLiteral) {
  4205. if (isLegacyOctalNumericLiteral) {
  4206. return parseInt(str, 8)
  4207. }
  4208. // `parseFloat(value)` stops parsing at the first numeric separator then returns a wrong value.
  4209. return parseFloat(str.replace(/_/g, ""))
  4210. }
  4211. function stringToBigInt(str) {
  4212. if (typeof BigInt !== "function") {
  4213. return null
  4214. }
  4215. // `BigInt(value)` throws syntax error if the string contains numeric separators.
  4216. return BigInt(str.replace(/_/g, ""))
  4217. }
  4218. pp$9.readRadixNumber = function(radix) {
  4219. var start = this.pos;
  4220. this.pos += 2; // 0x
  4221. var val = this.readInt(radix);
  4222. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  4223. if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
  4224. val = stringToBigInt(this.input.slice(start, this.pos));
  4225. ++this.pos;
  4226. } else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4227. return this.finishToken(types.num, val)
  4228. };
  4229. // Read an integer, octal integer, or floating-point number.
  4230. pp$9.readNumber = function(startsWithDot) {
  4231. var start = this.pos;
  4232. if (!startsWithDot && this.readInt(10, undefined, true) === null) { this.raise(start, "Invalid number"); }
  4233. var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  4234. if (octal && this.strict) { this.raise(start, "Invalid number"); }
  4235. var next = this.input.charCodeAt(this.pos);
  4236. if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
  4237. var val$1 = stringToBigInt(this.input.slice(start, this.pos));
  4238. ++this.pos;
  4239. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4240. return this.finishToken(types.num, val$1)
  4241. }
  4242. if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
  4243. if (next === 46 && !octal) { // '.'
  4244. ++this.pos;
  4245. this.readInt(10);
  4246. next = this.input.charCodeAt(this.pos);
  4247. }
  4248. if ((next === 69 || next === 101) && !octal) { // 'eE'
  4249. next = this.input.charCodeAt(++this.pos);
  4250. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  4251. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4252. }
  4253. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4254. var val = stringToNumber(this.input.slice(start, this.pos), octal);
  4255. return this.finishToken(types.num, val)
  4256. };
  4257. // Read a string value, interpreting backslash-escapes.
  4258. pp$9.readCodePoint = function() {
  4259. var ch = this.input.charCodeAt(this.pos), code;
  4260. if (ch === 123) { // '{'
  4261. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  4262. var codePos = ++this.pos;
  4263. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  4264. ++this.pos;
  4265. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  4266. } else {
  4267. code = this.readHexChar(4);
  4268. }
  4269. return code
  4270. };
  4271. function codePointToString$1(code) {
  4272. // UTF-16 Decoding
  4273. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  4274. code -= 0x10000;
  4275. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  4276. }
  4277. pp$9.readString = function(quote) {
  4278. var out = "", chunkStart = ++this.pos;
  4279. for (;;) {
  4280. if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated string constant"); }
  4281. var ch = this.input.charCodeAt(this.pos);
  4282. if (ch === quote) { break }
  4283. if (ch === 92) { // '\'
  4284. out += this.input.slice(chunkStart, this.pos);
  4285. out += this.readEscapedChar(false);
  4286. chunkStart = this.pos;
  4287. } else {
  4288. if (isNewLine(ch, this.options.ecmaVersion >= 10)) { this.raise(this.start, "Unterminated string constant"); }
  4289. ++this.pos;
  4290. }
  4291. }
  4292. out += this.input.slice(chunkStart, this.pos++);
  4293. return this.finishToken(types.string, out)
  4294. };
  4295. // Reads template string tokens.
  4296. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  4297. pp$9.tryReadTemplateToken = function() {
  4298. this.inTemplateElement = true;
  4299. try {
  4300. this.readTmplToken();
  4301. } catch (err) {
  4302. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  4303. this.readInvalidTemplateToken();
  4304. } else {
  4305. throw err
  4306. }
  4307. }
  4308. this.inTemplateElement = false;
  4309. };
  4310. pp$9.invalidStringToken = function(position, message) {
  4311. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  4312. throw INVALID_TEMPLATE_ESCAPE_ERROR
  4313. } else {
  4314. this.raise(position, message);
  4315. }
  4316. };
  4317. pp$9.readTmplToken = function() {
  4318. var out = "", chunkStart = this.pos;
  4319. for (;;) {
  4320. if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated template"); }
  4321. var ch = this.input.charCodeAt(this.pos);
  4322. if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) { // '`', '${'
  4323. if (this.pos === this.start && (this.type === types.template || this.type === types.invalidTemplate)) {
  4324. if (ch === 36) {
  4325. this.pos += 2;
  4326. return this.finishToken(types.dollarBraceL)
  4327. } else {
  4328. ++this.pos;
  4329. return this.finishToken(types.backQuote)
  4330. }
  4331. }
  4332. out += this.input.slice(chunkStart, this.pos);
  4333. return this.finishToken(types.template, out)
  4334. }
  4335. if (ch === 92) { // '\'
  4336. out += this.input.slice(chunkStart, this.pos);
  4337. out += this.readEscapedChar(true);
  4338. chunkStart = this.pos;
  4339. } else if (isNewLine(ch)) {
  4340. out += this.input.slice(chunkStart, this.pos);
  4341. ++this.pos;
  4342. switch (ch) {
  4343. case 13:
  4344. if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
  4345. case 10:
  4346. out += "\n";
  4347. break
  4348. default:
  4349. out += String.fromCharCode(ch);
  4350. break
  4351. }
  4352. if (this.options.locations) {
  4353. ++this.curLine;
  4354. this.lineStart = this.pos;
  4355. }
  4356. chunkStart = this.pos;
  4357. } else {
  4358. ++this.pos;
  4359. }
  4360. }
  4361. };
  4362. // Reads a template token to search for the end, without validating any escape sequences
  4363. pp$9.readInvalidTemplateToken = function() {
  4364. for (; this.pos < this.input.length; this.pos++) {
  4365. switch (this.input[this.pos]) {
  4366. case "\\":
  4367. ++this.pos;
  4368. break
  4369. case "$":
  4370. if (this.input[this.pos + 1] !== "{") {
  4371. break
  4372. }
  4373. // falls through
  4374. case "`":
  4375. return this.finishToken(types.invalidTemplate, this.input.slice(this.start, this.pos))
  4376. // no default
  4377. }
  4378. }
  4379. this.raise(this.start, "Unterminated template");
  4380. };
  4381. // Used to read escaped characters
  4382. pp$9.readEscapedChar = function(inTemplate) {
  4383. var ch = this.input.charCodeAt(++this.pos);
  4384. ++this.pos;
  4385. switch (ch) {
  4386. case 110: return "\n" // 'n' -> '\n'
  4387. case 114: return "\r" // 'r' -> '\r'
  4388. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  4389. case 117: return codePointToString$1(this.readCodePoint()) // 'u'
  4390. case 116: return "\t" // 't' -> '\t'
  4391. case 98: return "\b" // 'b' -> '\b'
  4392. case 118: return "\u000b" // 'v' -> '\u000b'
  4393. case 102: return "\f" // 'f' -> '\f'
  4394. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  4395. case 10: // ' \n'
  4396. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  4397. return ""
  4398. case 56:
  4399. case 57:
  4400. if (inTemplate) {
  4401. var codePos = this.pos - 1;
  4402. this.invalidStringToken(
  4403. codePos,
  4404. "Invalid escape sequence in template string"
  4405. );
  4406. return null
  4407. }
  4408. default:
  4409. if (ch >= 48 && ch <= 55) {
  4410. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  4411. var octal = parseInt(octalStr, 8);
  4412. if (octal > 255) {
  4413. octalStr = octalStr.slice(0, -1);
  4414. octal = parseInt(octalStr, 8);
  4415. }
  4416. this.pos += octalStr.length - 1;
  4417. ch = this.input.charCodeAt(this.pos);
  4418. if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
  4419. this.invalidStringToken(
  4420. this.pos - 1 - octalStr.length,
  4421. inTemplate
  4422. ? "Octal literal in template string"
  4423. : "Octal literal in strict mode"
  4424. );
  4425. }
  4426. return String.fromCharCode(octal)
  4427. }
  4428. if (isNewLine(ch)) {
  4429. // Unicode new line characters after \ get removed from output in both
  4430. // template literals and strings
  4431. return ""
  4432. }
  4433. return String.fromCharCode(ch)
  4434. }
  4435. };
  4436. // Used to read character escape sequences ('\x', '\u', '\U').
  4437. pp$9.readHexChar = function(len) {
  4438. var codePos = this.pos;
  4439. var n = this.readInt(16, len);
  4440. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  4441. return n
  4442. };
  4443. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  4444. // to whether the word contained a '\u' escape.
  4445. //
  4446. // Incrementally adds only escaped chars, adding other chunks as-is
  4447. // as a micro-optimization.
  4448. pp$9.readWord1 = function() {
  4449. this.containsEsc = false;
  4450. var word = "", first = true, chunkStart = this.pos;
  4451. var astral = this.options.ecmaVersion >= 6;
  4452. while (this.pos < this.input.length) {
  4453. var ch = this.fullCharCodeAtPos();
  4454. if (isIdentifierChar(ch, astral)) {
  4455. this.pos += ch <= 0xffff ? 1 : 2;
  4456. } else if (ch === 92) { // "\"
  4457. this.containsEsc = true;
  4458. word += this.input.slice(chunkStart, this.pos);
  4459. var escStart = this.pos;
  4460. if (this.input.charCodeAt(++this.pos) !== 117) // "u"
  4461. { this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  4462. ++this.pos;
  4463. var esc = this.readCodePoint();
  4464. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  4465. { this.invalidStringToken(escStart, "Invalid Unicode escape"); }
  4466. word += codePointToString$1(esc);
  4467. chunkStart = this.pos;
  4468. } else {
  4469. break
  4470. }
  4471. first = false;
  4472. }
  4473. return word + this.input.slice(chunkStart, this.pos)
  4474. };
  4475. // Read an identifier or keyword token. Will check for reserved
  4476. // words when necessary.
  4477. pp$9.readWord = function() {
  4478. var word = this.readWord1();
  4479. var type = types.name;
  4480. if (this.keywords.test(word)) {
  4481. type = keywords$1[word];
  4482. }
  4483. return this.finishToken(type, word)
  4484. };
  4485. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  4486. var version = "7.4.1";
  4487. Parser.acorn = {
  4488. Parser: Parser,
  4489. version: version,
  4490. defaultOptions: defaultOptions,
  4491. Position: Position,
  4492. SourceLocation: SourceLocation,
  4493. getLineInfo: getLineInfo,
  4494. Node: Node,
  4495. TokenType: TokenType,
  4496. tokTypes: types,
  4497. keywordTypes: keywords$1,
  4498. TokContext: TokContext,
  4499. tokContexts: types$1,
  4500. isIdentifierChar: isIdentifierChar,
  4501. isIdentifierStart: isIdentifierStart,
  4502. Token: Token,
  4503. isNewLine: isNewLine,
  4504. lineBreak: lineBreak,
  4505. lineBreakG: lineBreakG,
  4506. nonASCIIwhitespace: nonASCIIwhitespace
  4507. };
  4508. // The main exported interface (under `self.acorn` when in the
  4509. // browser) is a `parse` function that takes a code string and
  4510. // returns an abstract syntax tree as specified by [Mozilla parser
  4511. // API][api].
  4512. //
  4513. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  4514. function parse(input, options) {
  4515. return Parser.parse(input, options)
  4516. }
  4517. // This function tries to parse a single expression at a given
  4518. // offset in a string. Useful for parsing mixed-language formats
  4519. // that embed JavaScript expressions.
  4520. function parseExpressionAt(input, pos, options) {
  4521. return Parser.parseExpressionAt(input, pos, options)
  4522. }
  4523. // Acorn is organized as a tokenizer and a recursive-descent parser.
  4524. // The `tokenizer` export provides an interface to the tokenizer.
  4525. function tokenizer(input, options) {
  4526. return Parser.tokenizer(input, options)
  4527. }
  4528. export { Node, Parser, Position, SourceLocation, TokContext, Token, TokenType, defaultOptions, getLineInfo, isIdentifierChar, isIdentifierStart, isNewLine, keywords$1 as keywordTypes, lineBreak, lineBreakG, nonASCIIwhitespace, parse, parseExpressionAt, types$1 as tokContexts, types as tokTypes, tokenizer, version };