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.

4970 lines
179 KiB

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