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.

4979 lines
187 KiB

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