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.

16857 lines
488 KiB

4 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. (factory((global.buble = {})));
  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. 6: ecma5AndLessKeywords + " const class extends export import super"
  19. };
  20. var keywordRelationalOperator = /^in(stanceof)?$/;
  21. // ## Character categories
  22. // Big ugly regular expressions that match characters in the
  23. // whitespace, identifier, and identifier-start categories. These
  24. // are only applied when a character is found to actually have a
  25. // code point above 128.
  26. // Generated by `bin/generate-identifier-regex.js`.
  27. 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\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\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-\u1cf1\u1cf5\u1cf6\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-\ua7b9\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-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\uf
  28. 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-\u0eb9\u0ebb\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\u1cf2-\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";
  29. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  30. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  31. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  32. // These are a run-length and offset encoded representation of the
  33. // >0xffff code points that are a valid part of identifiers. The
  34. // offset starts at 0x10000, and each pair of numbers represents an
  35. // offset to the next range, and then a size of the range. They were
  36. // generated by bin/generate-identifier-regex.js
  37. // eslint-disable-next-line comma-spacing
  38. 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,190,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,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,26,230,43,117,63,32,0,257,0,11,39,8,0,22,0,12,39,3,3,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,68,12,0,67,12,65,1,31,6129,15,754,9486,286,82,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,4149,196,60,67,1213,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];
  39. // eslint-disable-next-line comma-spacing
  40. 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,280,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,1016,45,17,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,2214,6,110,6,6,9,792487,239];
  41. // This has a complexity linear to the value of the code. The
  42. // assumption is that looking up astral identifier characters is
  43. // rare.
  44. function isInAstralSet(code, set) {
  45. var pos = 0x10000;
  46. for (var i = 0; i < set.length; i += 2) {
  47. pos += set[i];
  48. if (pos > code) { return false }
  49. pos += set[i + 1];
  50. if (pos >= code) { return true }
  51. }
  52. }
  53. // Test whether a given character code starts an identifier.
  54. function isIdentifierStart(code, astral) {
  55. if (code < 65) { return code === 36 }
  56. if (code < 91) { return true }
  57. if (code < 97) { return code === 95 }
  58. if (code < 123) { return true }
  59. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  60. if (astral === false) { return false }
  61. return isInAstralSet(code, astralIdentifierStartCodes)
  62. }
  63. // Test whether a given character is part of an identifier.
  64. function isIdentifierChar(code, astral) {
  65. if (code < 48) { return code === 36 }
  66. if (code < 58) { return true }
  67. if (code < 65) { return false }
  68. if (code < 91) { return true }
  69. if (code < 97) { return code === 95 }
  70. if (code < 123) { return true }
  71. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  72. if (astral === false) { return false }
  73. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  74. }
  75. // ## Token types
  76. // The assignment of fine-grained, information-carrying type objects
  77. // allows the tokenizer to store the information it has about a
  78. // token in a way that is very cheap for the parser to look up.
  79. // All token type variables start with an underscore, to make them
  80. // easy to recognize.
  81. // The `beforeExpr` property is used to disambiguate between regular
  82. // expressions and divisions. It is set on all token types that can
  83. // be followed by an expression (thus, a slash after them would be a
  84. // regular expression).
  85. //
  86. // The `startsExpr` property is used to check if the token ends a
  87. // `yield` expression. It is set on all token types that either can
  88. // directly start an expression (like a quotation mark) or can
  89. // continue an expression (like the body of a string).
  90. //
  91. // `isLoop` marks a keyword as starting a loop, which is important
  92. // to know when parsing a label, in order to allow or disallow
  93. // continue jumps to that label.
  94. var TokenType = function TokenType(label, conf) {
  95. if ( conf === void 0 ) conf = {};
  96. this.label = label;
  97. this.keyword = conf.keyword;
  98. this.beforeExpr = !!conf.beforeExpr;
  99. this.startsExpr = !!conf.startsExpr;
  100. this.isLoop = !!conf.isLoop;
  101. this.isAssign = !!conf.isAssign;
  102. this.prefix = !!conf.prefix;
  103. this.postfix = !!conf.postfix;
  104. this.binop = conf.binop || null;
  105. this.updateContext = null;
  106. };
  107. function binop(name, prec) {
  108. return new TokenType(name, {beforeExpr: true, binop: prec})
  109. }
  110. var beforeExpr = {beforeExpr: true};
  111. var 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"),
  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\u180e\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. // These are used when `options.locations` is on, for the
  231. // `startLoc` and `endLoc` properties.
  232. var Position = function Position(line, col) {
  233. this.line = line;
  234. this.column = col;
  235. };
  236. Position.prototype.offset = function offset (n) {
  237. return new Position(this.line, this.column + n)
  238. };
  239. var SourceLocation = function SourceLocation(p, start, end) {
  240. this.start = start;
  241. this.end = end;
  242. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  243. };
  244. // The `getLineInfo` function is mostly useful when the
  245. // `locations` option is off (for performance reasons) and you
  246. // want to find the line/column position for a given character
  247. // offset. `input` should be the code string that the offset refers
  248. // into.
  249. function getLineInfo(input, offset) {
  250. for (var line = 1, cur = 0;;) {
  251. lineBreakG.lastIndex = cur;
  252. var match = lineBreakG.exec(input);
  253. if (match && match.index < offset) {
  254. ++line;
  255. cur = match.index + match[0].length;
  256. } else {
  257. return new Position(line, offset - cur)
  258. }
  259. }
  260. }
  261. // A second optional argument can be given to further configure
  262. // the parser process. These options are recognized:
  263. var defaultOptions = {
  264. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  265. // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
  266. // for strict mode, the set of reserved words, and support for
  267. // new syntax features. The default is 7.
  268. ecmaVersion: 7,
  269. // `sourceType` indicates the mode the code should be parsed in.
  270. // Can be either `"script"` or `"module"`. This influences global
  271. // strict mode and parsing of `import` and `export` declarations.
  272. sourceType: "script",
  273. // `onInsertedSemicolon` can be a callback that will be called
  274. // when a semicolon is automatically inserted. It will be passed
  275. // th position of the comma as an offset, and if `locations` is
  276. // enabled, it is given the location as a `{line, column}` object
  277. // as second argument.
  278. onInsertedSemicolon: null,
  279. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  280. // trailing commas.
  281. onTrailingComma: null,
  282. // By default, reserved words are only enforced if ecmaVersion >= 5.
  283. // Set `allowReserved` to a boolean value to explicitly turn this on
  284. // an off. When this option has the value "never", reserved words
  285. // and keywords can also not be used as property names.
  286. allowReserved: null,
  287. // When enabled, a return at the top level is not considered an
  288. // error.
  289. allowReturnOutsideFunction: false,
  290. // When enabled, import/export statements are not constrained to
  291. // appearing at the top of the program.
  292. allowImportExportEverywhere: false,
  293. // When enabled, await identifiers are allowed to appear at the top-level scope,
  294. // but they are still not allowed in non-async functions.
  295. allowAwaitOutsideFunction: false,
  296. // When enabled, hashbang directive in the beginning of file
  297. // is allowed and treated as a line comment.
  298. allowHashBang: false,
  299. // When `locations` is on, `loc` properties holding objects with
  300. // `start` and `end` properties in `{line, column}` form (with
  301. // line being 1-based and column 0-based) will be attached to the
  302. // nodes.
  303. locations: false,
  304. // A function can be passed as `onToken` option, which will
  305. // cause Acorn to call that function with object in the same
  306. // format as tokens returned from `tokenizer().getToken()`. Note
  307. // that you are not allowed to call the parser from the
  308. // callback—that will corrupt its internal state.
  309. onToken: null,
  310. // A function can be passed as `onComment` option, which will
  311. // cause Acorn to call that function with `(block, text, start,
  312. // end)` parameters whenever a comment is skipped. `block` is a
  313. // boolean indicating whether this is a block (`/* */`) comment,
  314. // `text` is the content of the comment, and `start` and `end` are
  315. // character offsets that denote the start and end of the comment.
  316. // When the `locations` option is on, two more parameters are
  317. // passed, the full `{line, column}` locations of the start and
  318. // end of the comments. Note that you are not allowed to call the
  319. // parser from the callback—that will corrupt its internal state.
  320. onComment: null,
  321. // Nodes have their start and end characters offsets recorded in
  322. // `start` and `end` properties (directly on the node, rather than
  323. // the `loc` object, which holds line/column data. To also add a
  324. // [semi-standardized][range] `range` property holding a `[start,
  325. // end]` array with the same numbers, set the `ranges` option to
  326. // `true`.
  327. //
  328. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  329. ranges: false,
  330. // It is possible to parse multiple files into a single AST by
  331. // passing the tree produced by parsing the first file as
  332. // `program` option in subsequent parses. This will add the
  333. // toplevel forms of the parsed file to the `Program` (top) node
  334. // of an existing parse tree.
  335. program: null,
  336. // When `locations` is on, you can pass this to record the source
  337. // file in every node's `loc` object.
  338. sourceFile: null,
  339. // This value, if given, is stored in every node, whether
  340. // `locations` is on or off.
  341. directSourceFile: null,
  342. // When enabled, parenthesized expressions are represented by
  343. // (non-standard) ParenthesizedExpression nodes
  344. preserveParens: false,
  345. plugins: {}
  346. };
  347. // Interpret and default an options object
  348. function getOptions(opts) {
  349. var options = {};
  350. for (var opt in defaultOptions)
  351. { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  352. if (options.ecmaVersion >= 2015)
  353. { options.ecmaVersion -= 2009; }
  354. if (options.allowReserved == null)
  355. { options.allowReserved = options.ecmaVersion < 5; }
  356. if (isArray(options.onToken)) {
  357. var tokens = options.onToken;
  358. options.onToken = function (token) { return tokens.push(token); };
  359. }
  360. if (isArray(options.onComment))
  361. { options.onComment = pushComment(options, options.onComment); }
  362. return options
  363. }
  364. function pushComment(options, array) {
  365. return function(block, text, start, end, startLoc, endLoc) {
  366. var comment = {
  367. type: block ? "Block" : "Line",
  368. value: text,
  369. start: start,
  370. end: end
  371. };
  372. if (options.locations)
  373. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  374. if (options.ranges)
  375. { comment.range = [start, end]; }
  376. array.push(comment);
  377. }
  378. }
  379. // Registered plugins
  380. var plugins = {};
  381. function keywordRegexp(words) {
  382. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  383. }
  384. var Parser = function Parser(options, input, startPos) {
  385. this.options = options = getOptions(options);
  386. this.sourceFile = options.sourceFile;
  387. this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
  388. var reserved = "";
  389. if (!options.allowReserved) {
  390. for (var v = options.ecmaVersion;; v--)
  391. { if (reserved = reservedWords[v]) { break } }
  392. if (options.sourceType === "module") { reserved += " await"; }
  393. }
  394. this.reservedWords = keywordRegexp(reserved);
  395. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  396. this.reservedWordsStrict = keywordRegexp(reservedStrict);
  397. this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
  398. this.input = String(input);
  399. // Used to signal to callers of `readWord1` whether the word
  400. // contained any escape sequences. This is needed because words with
  401. // escape sequences must not be interpreted as keywords.
  402. this.containsEsc = false;
  403. // Load plugins
  404. this.loadPlugins(options.plugins);
  405. // Set up token state
  406. // The current position of the tokenizer in the input.
  407. if (startPos) {
  408. this.pos = startPos;
  409. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  410. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  411. } else {
  412. this.pos = this.lineStart = 0;
  413. this.curLine = 1;
  414. }
  415. // Properties of the current token:
  416. // Its type
  417. this.type = types.eof;
  418. // For tokens that include more information than their type, the value
  419. this.value = null;
  420. // Its start and end offset
  421. this.start = this.end = this.pos;
  422. // And, if locations are used, the {line, column} object
  423. // corresponding to those offsets
  424. this.startLoc = this.endLoc = this.curPosition();
  425. // Position information for the previous token
  426. this.lastTokEndLoc = this.lastTokStartLoc = null;
  427. this.lastTokStart = this.lastTokEnd = this.pos;
  428. // The context stack is used to superficially track syntactic
  429. // context to predict whether a regular expression is allowed in a
  430. // given position.
  431. this.context = this.initialContext();
  432. this.exprAllowed = true;
  433. // Figure out if it's a module code.
  434. this.inModule = options.sourceType === "module";
  435. this.strict = this.inModule || this.strictDirective(this.pos);
  436. // Used to signify the start of a potential arrow function
  437. this.potentialArrowAt = -1;
  438. // Flags to track whether we are in a function, a generator, an async function.
  439. this.inFunction = this.inGenerator = this.inAsync = false;
  440. // Positions to delayed-check that yield/await does not exist in default parameters.
  441. this.yieldPos = this.awaitPos = 0;
  442. // Labels in scope.
  443. this.labels = [];
  444. // If enabled, skip leading hashbang line.
  445. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  446. { this.skipLineComment(2); }
  447. // Scope tracking for duplicate variable names (see scope.js)
  448. this.scopeStack = [];
  449. this.enterFunctionScope();
  450. // For RegExp validation
  451. this.regexpState = null;
  452. };
  453. // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
  454. Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
  455. Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
  456. Parser.prototype.extend = function extend (name, f) {
  457. this[name] = f(this[name]);
  458. };
  459. Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
  460. var this$1 = this;
  461. for (var name in pluginConfigs) {
  462. var plugin = plugins[name];
  463. if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
  464. plugin(this$1, pluginConfigs[name]);
  465. }
  466. };
  467. Parser.prototype.parse = function parse () {
  468. var node = this.options.program || this.startNode();
  469. this.nextToken();
  470. return this.parseTopLevel(node)
  471. };
  472. var pp = Parser.prototype;
  473. // ## Parser utilities
  474. var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
  475. pp.strictDirective = function(start) {
  476. var this$1 = this;
  477. for (;;) {
  478. skipWhiteSpace.lastIndex = start;
  479. start += skipWhiteSpace.exec(this$1.input)[0].length;
  480. var match = literal.exec(this$1.input.slice(start));
  481. if (!match) { return false }
  482. if ((match[1] || match[2]) === "use strict") { return true }
  483. start += match[0].length;
  484. }
  485. };
  486. // Predicate that tests whether the next token is of the given
  487. // type, and if yes, consumes it as a side effect.
  488. pp.eat = function(type) {
  489. if (this.type === type) {
  490. this.next();
  491. return true
  492. } else {
  493. return false
  494. }
  495. };
  496. // Tests whether parsed token is a contextual keyword.
  497. pp.isContextual = function(name) {
  498. return this.type === types.name && this.value === name && !this.containsEsc
  499. };
  500. // Consumes contextual keyword if possible.
  501. pp.eatContextual = function(name) {
  502. if (!this.isContextual(name)) { return false }
  503. this.next();
  504. return true
  505. };
  506. // Asserts that following token is given contextual keyword.
  507. pp.expectContextual = function(name) {
  508. if (!this.eatContextual(name)) { this.unexpected(); }
  509. };
  510. // Test whether a semicolon can be inserted at the current position.
  511. pp.canInsertSemicolon = function() {
  512. return this.type === types.eof ||
  513. this.type === types.braceR ||
  514. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  515. };
  516. pp.insertSemicolon = function() {
  517. if (this.canInsertSemicolon()) {
  518. if (this.options.onInsertedSemicolon)
  519. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  520. return true
  521. }
  522. };
  523. // Consume a semicolon, or, failing that, see if we are allowed to
  524. // pretend that there is a semicolon at this position.
  525. pp.semicolon = function() {
  526. if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
  527. };
  528. pp.afterTrailingComma = function(tokType, notNext) {
  529. if (this.type === tokType) {
  530. if (this.options.onTrailingComma)
  531. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  532. if (!notNext)
  533. { this.next(); }
  534. return true
  535. }
  536. };
  537. // Expect a token of a given type. If found, consume it, otherwise,
  538. // raise an unexpected token error.
  539. pp.expect = function(type) {
  540. this.eat(type) || this.unexpected();
  541. };
  542. // Raise an unexpected token error.
  543. pp.unexpected = function(pos) {
  544. this.raise(pos != null ? pos : this.start, "Unexpected token");
  545. };
  546. function DestructuringErrors() {
  547. this.shorthandAssign =
  548. this.trailingComma =
  549. this.parenthesizedAssign =
  550. this.parenthesizedBind =
  551. this.doubleProto =
  552. -1;
  553. }
  554. pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  555. if (!refDestructuringErrors) { return }
  556. if (refDestructuringErrors.trailingComma > -1)
  557. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  558. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  559. if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
  560. };
  561. pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  562. if (!refDestructuringErrors) { return false }
  563. var shorthandAssign = refDestructuringErrors.shorthandAssign;
  564. var doubleProto = refDestructuringErrors.doubleProto;
  565. if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
  566. if (shorthandAssign >= 0)
  567. { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
  568. if (doubleProto >= 0)
  569. { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
  570. };
  571. pp.checkYieldAwaitInDefaultParams = function() {
  572. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  573. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  574. if (this.awaitPos)
  575. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  576. };
  577. pp.isSimpleAssignTarget = function(expr) {
  578. if (expr.type === "ParenthesizedExpression")
  579. { return this.isSimpleAssignTarget(expr.expression) }
  580. return expr.type === "Identifier" || expr.type === "MemberExpression"
  581. };
  582. var pp$1 = Parser.prototype;
  583. // ### Statement parsing
  584. // Parse a program. Initializes the parser, reads any number of
  585. // statements, and wraps them in a Program node. Optionally takes a
  586. // `program` argument. If present, the statements will be appended
  587. // to its body instead of creating a new node.
  588. pp$1.parseTopLevel = function(node) {
  589. var this$1 = this;
  590. var exports = {};
  591. if (!node.body) { node.body = []; }
  592. while (this.type !== types.eof) {
  593. var stmt = this$1.parseStatement(true, true, exports);
  594. node.body.push(stmt);
  595. }
  596. this.adaptDirectivePrologue(node.body);
  597. this.next();
  598. if (this.options.ecmaVersion >= 6) {
  599. node.sourceType = this.options.sourceType;
  600. }
  601. return this.finishNode(node, "Program")
  602. };
  603. var loopLabel = {kind: "loop"};
  604. var switchLabel = {kind: "switch"};
  605. pp$1.isLet = function() {
  606. if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
  607. skipWhiteSpace.lastIndex = this.pos;
  608. var skip = skipWhiteSpace.exec(this.input);
  609. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  610. if (nextCh === 91 || nextCh === 123) { return true } // '{' and '['
  611. if (isIdentifierStart(nextCh, true)) {
  612. var pos = next + 1;
  613. while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
  614. var ident = this.input.slice(next, pos);
  615. if (!keywordRelationalOperator.test(ident)) { return true }
  616. }
  617. return false
  618. };
  619. // check 'async [no LineTerminator here] function'
  620. // - 'async /*foo*/ function' is OK.
  621. // - 'async /*\n*/ function' is invalid.
  622. pp$1.isAsyncFunction = function() {
  623. if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
  624. { return false }
  625. skipWhiteSpace.lastIndex = this.pos;
  626. var skip = skipWhiteSpace.exec(this.input);
  627. var next = this.pos + skip[0].length;
  628. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  629. this.input.slice(next, next + 8) === "function" &&
  630. (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
  631. };
  632. // Parse a single statement.
  633. //
  634. // If expecting a statement and finding a slash operator, parse a
  635. // regular expression literal. This is to handle cases like
  636. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  637. // does not help.
  638. pp$1.parseStatement = function(declaration, topLevel, exports) {
  639. var starttype = this.type, node = this.startNode(), kind;
  640. if (this.isLet()) {
  641. starttype = types._var;
  642. kind = "let";
  643. }
  644. // Most types of statements are recognized by the keyword they
  645. // start with. Many are trivial to parse, some require a bit of
  646. // complexity.
  647. switch (starttype) {
  648. case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  649. case types._debugger: return this.parseDebuggerStatement(node)
  650. case types._do: return this.parseDoStatement(node)
  651. case types._for: return this.parseForStatement(node)
  652. case types._function:
  653. if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
  654. return this.parseFunctionStatement(node, false)
  655. case types._class:
  656. if (!declaration) { this.unexpected(); }
  657. return this.parseClass(node, true)
  658. case types._if: return this.parseIfStatement(node)
  659. case types._return: return this.parseReturnStatement(node)
  660. case types._switch: return this.parseSwitchStatement(node)
  661. case types._throw: return this.parseThrowStatement(node)
  662. case types._try: return this.parseTryStatement(node)
  663. case types._const: case types._var:
  664. kind = kind || this.value;
  665. if (!declaration && kind !== "var") { this.unexpected(); }
  666. return this.parseVarStatement(node, kind)
  667. case types._while: return this.parseWhileStatement(node)
  668. case types._with: return this.parseWithStatement(node)
  669. case types.braceL: return this.parseBlock()
  670. case types.semi: return this.parseEmptyStatement(node)
  671. case types._export:
  672. case types._import:
  673. if (!this.options.allowImportExportEverywhere) {
  674. if (!topLevel)
  675. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  676. if (!this.inModule)
  677. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  678. }
  679. return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
  680. // If the statement does not start with a statement keyword or a
  681. // brace, it's an ExpressionStatement or LabeledStatement. We
  682. // simply start parsing an expression, and afterwards, if the
  683. // next token is a colon and the expression was a simple
  684. // Identifier node, we switch to interpreting it as a label.
  685. default:
  686. if (this.isAsyncFunction()) {
  687. if (!declaration) { this.unexpected(); }
  688. this.next();
  689. return this.parseFunctionStatement(node, true)
  690. }
  691. var maybeName = this.value, expr = this.parseExpression();
  692. if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
  693. { return this.parseLabeledStatement(node, maybeName, expr) }
  694. else { return this.parseExpressionStatement(node, expr) }
  695. }
  696. };
  697. pp$1.parseBreakContinueStatement = function(node, keyword) {
  698. var this$1 = this;
  699. var isBreak = keyword === "break";
  700. this.next();
  701. if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
  702. else if (this.type !== types.name) { this.unexpected(); }
  703. else {
  704. node.label = this.parseIdent();
  705. this.semicolon();
  706. }
  707. // Verify that there is an actual destination to break or
  708. // continue to.
  709. var i = 0;
  710. for (; i < this.labels.length; ++i) {
  711. var lab = this$1.labels[i];
  712. if (node.label == null || lab.name === node.label.name) {
  713. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  714. if (node.label && isBreak) { break }
  715. }
  716. }
  717. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  718. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  719. };
  720. pp$1.parseDebuggerStatement = function(node) {
  721. this.next();
  722. this.semicolon();
  723. return this.finishNode(node, "DebuggerStatement")
  724. };
  725. pp$1.parseDoStatement = function(node) {
  726. this.next();
  727. this.labels.push(loopLabel);
  728. node.body = this.parseStatement(false);
  729. this.labels.pop();
  730. this.expect(types._while);
  731. node.test = this.parseParenExpression();
  732. if (this.options.ecmaVersion >= 6)
  733. { this.eat(types.semi); }
  734. else
  735. { this.semicolon(); }
  736. return this.finishNode(node, "DoWhileStatement")
  737. };
  738. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  739. // loop is non-trivial. Basically, we have to parse the init `var`
  740. // statement or expression, disallowing the `in` operator (see
  741. // the second parameter to `parseExpression`), and then check
  742. // whether the next token is `in` or `of`. When there is no init
  743. // part (semicolon immediately after the opening parenthesis), it
  744. // is a regular `for` loop.
  745. pp$1.parseForStatement = function(node) {
  746. this.next();
  747. var awaitAt = (this.options.ecmaVersion >= 9 && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction)) && this.eatContextual("await")) ? this.lastTokStart : -1;
  748. this.labels.push(loopLabel);
  749. this.enterLexicalScope();
  750. this.expect(types.parenL);
  751. if (this.type === types.semi) {
  752. if (awaitAt > -1) { this.unexpected(awaitAt); }
  753. return this.parseFor(node, null)
  754. }
  755. var isLet = this.isLet();
  756. if (this.type === types._var || this.type === types._const || isLet) {
  757. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  758. this.next();
  759. this.parseVar(init$1, true, kind);
  760. this.finishNode(init$1, "VariableDeclaration");
  761. if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
  762. !(kind !== "var" && init$1.declarations[0].init)) {
  763. if (this.options.ecmaVersion >= 9) {
  764. if (this.type === types._in) {
  765. if (awaitAt > -1) { this.unexpected(awaitAt); }
  766. } else { node.await = awaitAt > -1; }
  767. }
  768. return this.parseForIn(node, init$1)
  769. }
  770. if (awaitAt > -1) { this.unexpected(awaitAt); }
  771. return this.parseFor(node, init$1)
  772. }
  773. var refDestructuringErrors = new DestructuringErrors;
  774. var init = this.parseExpression(true, refDestructuringErrors);
  775. if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  776. if (this.options.ecmaVersion >= 9) {
  777. if (this.type === types._in) {
  778. if (awaitAt > -1) { this.unexpected(awaitAt); }
  779. } else { node.await = awaitAt > -1; }
  780. }
  781. this.toAssignable(init, false, refDestructuringErrors);
  782. this.checkLVal(init);
  783. return this.parseForIn(node, init)
  784. } else {
  785. this.checkExpressionErrors(refDestructuringErrors, true);
  786. }
  787. if (awaitAt > -1) { this.unexpected(awaitAt); }
  788. return this.parseFor(node, init)
  789. };
  790. pp$1.parseFunctionStatement = function(node, isAsync) {
  791. this.next();
  792. return this.parseFunction(node, true, false, isAsync)
  793. };
  794. pp$1.parseIfStatement = function(node) {
  795. this.next();
  796. node.test = this.parseParenExpression();
  797. // allow function declarations in branches, but only in non-strict mode
  798. node.consequent = this.parseStatement(!this.strict && this.type === types._function);
  799. node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.type === types._function) : null;
  800. return this.finishNode(node, "IfStatement")
  801. };
  802. pp$1.parseReturnStatement = function(node) {
  803. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  804. { this.raise(this.start, "'return' outside of function"); }
  805. this.next();
  806. // In `return` (and `break`/`continue`), the keywords with
  807. // optional arguments, we eagerly look for a semicolon or the
  808. // possibility to insert one.
  809. if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
  810. else { node.argument = this.parseExpression(); this.semicolon(); }
  811. return this.finishNode(node, "ReturnStatement")
  812. };
  813. pp$1.parseSwitchStatement = function(node) {
  814. var this$1 = this;
  815. this.next();
  816. node.discriminant = this.parseParenExpression();
  817. node.cases = [];
  818. this.expect(types.braceL);
  819. this.labels.push(switchLabel);
  820. this.enterLexicalScope();
  821. // Statements under must be grouped (by label) in SwitchCase
  822. // nodes. `cur` is used to keep the node that we are currently
  823. // adding statements to.
  824. var cur;
  825. for (var sawDefault = false; this.type !== types.braceR;) {
  826. if (this$1.type === types._case || this$1.type === types._default) {
  827. var isCase = this$1.type === types._case;
  828. if (cur) { this$1.finishNode(cur, "SwitchCase"); }
  829. node.cases.push(cur = this$1.startNode());
  830. cur.consequent = [];
  831. this$1.next();
  832. if (isCase) {
  833. cur.test = this$1.parseExpression();
  834. } else {
  835. if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
  836. sawDefault = true;
  837. cur.test = null;
  838. }
  839. this$1.expect(types.colon);
  840. } else {
  841. if (!cur) { this$1.unexpected(); }
  842. cur.consequent.push(this$1.parseStatement(true));
  843. }
  844. }
  845. this.exitLexicalScope();
  846. if (cur) { this.finishNode(cur, "SwitchCase"); }
  847. this.next(); // Closing brace
  848. this.labels.pop();
  849. return this.finishNode(node, "SwitchStatement")
  850. };
  851. pp$1.parseThrowStatement = function(node) {
  852. this.next();
  853. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  854. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  855. node.argument = this.parseExpression();
  856. this.semicolon();
  857. return this.finishNode(node, "ThrowStatement")
  858. };
  859. // Reused empty array added for node fields that are always empty.
  860. var empty = [];
  861. pp$1.parseTryStatement = function(node) {
  862. this.next();
  863. node.block = this.parseBlock();
  864. node.handler = null;
  865. if (this.type === types._catch) {
  866. var clause = this.startNode();
  867. this.next();
  868. if (this.eat(types.parenL)) {
  869. clause.param = this.parseBindingAtom();
  870. this.enterLexicalScope();
  871. this.checkLVal(clause.param, "let");
  872. this.expect(types.parenR);
  873. } else {
  874. if (this.options.ecmaVersion < 10) { this.unexpected(); }
  875. clause.param = null;
  876. this.enterLexicalScope();
  877. }
  878. clause.body = this.parseBlock(false);
  879. this.exitLexicalScope();
  880. node.handler = this.finishNode(clause, "CatchClause");
  881. }
  882. node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
  883. if (!node.handler && !node.finalizer)
  884. { this.raise(node.start, "Missing catch or finally clause"); }
  885. return this.finishNode(node, "TryStatement")
  886. };
  887. pp$1.parseVarStatement = function(node, kind) {
  888. this.next();
  889. this.parseVar(node, false, kind);
  890. this.semicolon();
  891. return this.finishNode(node, "VariableDeclaration")
  892. };
  893. pp$1.parseWhileStatement = function(node) {
  894. this.next();
  895. node.test = this.parseParenExpression();
  896. this.labels.push(loopLabel);
  897. node.body = this.parseStatement(false);
  898. this.labels.pop();
  899. return this.finishNode(node, "WhileStatement")
  900. };
  901. pp$1.parseWithStatement = function(node) {
  902. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  903. this.next();
  904. node.object = this.parseParenExpression();
  905. node.body = this.parseStatement(false);
  906. return this.finishNode(node, "WithStatement")
  907. };
  908. pp$1.parseEmptyStatement = function(node) {
  909. this.next();
  910. return this.finishNode(node, "EmptyStatement")
  911. };
  912. pp$1.parseLabeledStatement = function(node, maybeName, expr) {
  913. var this$1 = this;
  914. for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
  915. {
  916. var label = list[i$1];
  917. if (label.name === maybeName)
  918. { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
  919. } }
  920. var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
  921. for (var i = this.labels.length - 1; i >= 0; i--) {
  922. var label$1 = this$1.labels[i];
  923. if (label$1.statementStart === node.start) {
  924. // Update information about previous labels on this node
  925. label$1.statementStart = this$1.start;
  926. label$1.kind = kind;
  927. } else { break }
  928. }
  929. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  930. node.body = this.parseStatement(true);
  931. if (node.body.type === "ClassDeclaration" ||
  932. node.body.type === "VariableDeclaration" && node.body.kind !== "var" ||
  933. node.body.type === "FunctionDeclaration" && (this.strict || node.body.generator || node.body.async))
  934. { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
  935. this.labels.pop();
  936. node.label = expr;
  937. return this.finishNode(node, "LabeledStatement")
  938. };
  939. pp$1.parseExpressionStatement = function(node, expr) {
  940. node.expression = expr;
  941. this.semicolon();
  942. return this.finishNode(node, "ExpressionStatement")
  943. };
  944. // Parse a semicolon-enclosed block of statements, handling `"use
  945. // strict"` declarations when `allowStrict` is true (used for
  946. // function bodies).
  947. pp$1.parseBlock = function(createNewLexicalScope) {
  948. var this$1 = this;
  949. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  950. var node = this.startNode();
  951. node.body = [];
  952. this.expect(types.braceL);
  953. if (createNewLexicalScope) {
  954. this.enterLexicalScope();
  955. }
  956. while (!this.eat(types.braceR)) {
  957. var stmt = this$1.parseStatement(true);
  958. node.body.push(stmt);
  959. }
  960. if (createNewLexicalScope) {
  961. this.exitLexicalScope();
  962. }
  963. return this.finishNode(node, "BlockStatement")
  964. };
  965. // Parse a regular `for` loop. The disambiguation code in
  966. // `parseStatement` will already have parsed the init statement or
  967. // expression.
  968. pp$1.parseFor = function(node, init) {
  969. node.init = init;
  970. this.expect(types.semi);
  971. node.test = this.type === types.semi ? null : this.parseExpression();
  972. this.expect(types.semi);
  973. node.update = this.type === types.parenR ? null : this.parseExpression();
  974. this.expect(types.parenR);
  975. this.exitLexicalScope();
  976. node.body = this.parseStatement(false);
  977. this.labels.pop();
  978. return this.finishNode(node, "ForStatement")
  979. };
  980. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  981. // same from parser's perspective.
  982. pp$1.parseForIn = function(node, init) {
  983. var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
  984. this.next();
  985. if (type === "ForInStatement") {
  986. if (init.type === "AssignmentPattern" ||
  987. (init.type === "VariableDeclaration" && init.declarations[0].init != null &&
  988. (this.strict || init.declarations[0].id.type !== "Identifier")))
  989. { this.raise(init.start, "Invalid assignment in for-in loop head"); }
  990. }
  991. node.left = init;
  992. node.right = type === "ForInStatement" ? this.parseExpression() : this.parseMaybeAssign();
  993. this.expect(types.parenR);
  994. this.exitLexicalScope();
  995. node.body = this.parseStatement(false);
  996. this.labels.pop();
  997. return this.finishNode(node, type)
  998. };
  999. // Parse a list of variable declarations.
  1000. pp$1.parseVar = function(node, isFor, kind) {
  1001. var this$1 = this;
  1002. node.declarations = [];
  1003. node.kind = kind;
  1004. for (;;) {
  1005. var decl = this$1.startNode();
  1006. this$1.parseVarId(decl, kind);
  1007. if (this$1.eat(types.eq)) {
  1008. decl.init = this$1.parseMaybeAssign(isFor);
  1009. } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
  1010. this$1.unexpected();
  1011. } else if (decl.id.type !== "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
  1012. this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
  1013. } else {
  1014. decl.init = null;
  1015. }
  1016. node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
  1017. if (!this$1.eat(types.comma)) { break }
  1018. }
  1019. return node
  1020. };
  1021. pp$1.parseVarId = function(decl, kind) {
  1022. decl.id = this.parseBindingAtom(kind);
  1023. this.checkLVal(decl.id, kind, false);
  1024. };
  1025. // Parse a function declaration or literal (depending on the
  1026. // `isStatement` parameter).
  1027. pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
  1028. this.initFunction(node);
  1029. if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync)
  1030. { node.generator = this.eat(types.star); }
  1031. if (this.options.ecmaVersion >= 8)
  1032. { node.async = !!isAsync; }
  1033. if (isStatement) {
  1034. node.id = isStatement === "nullableID" && this.type !== types.name ? null : this.parseIdent();
  1035. if (node.id) {
  1036. this.checkLVal(node.id, this.inModule && !this.inFunction ? "let" : "var");
  1037. }
  1038. }
  1039. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  1040. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  1041. this.inGenerator = node.generator;
  1042. this.inAsync = node.async;
  1043. this.yieldPos = 0;
  1044. this.awaitPos = 0;
  1045. this.inFunction = true;
  1046. this.enterFunctionScope();
  1047. if (!isStatement)
  1048. { node.id = this.type === types.name ? this.parseIdent() : null; }
  1049. this.parseFunctionParams(node);
  1050. this.parseFunctionBody(node, allowExpressionBody);
  1051. this.inGenerator = oldInGen;
  1052. this.inAsync = oldInAsync;
  1053. this.yieldPos = oldYieldPos;
  1054. this.awaitPos = oldAwaitPos;
  1055. this.inFunction = oldInFunc;
  1056. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
  1057. };
  1058. pp$1.parseFunctionParams = function(node) {
  1059. this.expect(types.parenL);
  1060. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  1061. this.checkYieldAwaitInDefaultParams();
  1062. };
  1063. // Parse a class declaration or literal (depending on the
  1064. // `isStatement` parameter).
  1065. pp$1.parseClass = function(node, isStatement) {
  1066. var this$1 = this;
  1067. this.next();
  1068. this.parseClassId(node, isStatement);
  1069. this.parseClassSuper(node);
  1070. var classBody = this.startNode();
  1071. var hadConstructor = false;
  1072. classBody.body = [];
  1073. this.expect(types.braceL);
  1074. while (!this.eat(types.braceR)) {
  1075. var member = this$1.parseClassMember(classBody);
  1076. if (member && member.type === "MethodDefinition" && member.kind === "constructor") {
  1077. if (hadConstructor) { this$1.raise(member.start, "Duplicate constructor in the same class"); }
  1078. hadConstructor = true;
  1079. }
  1080. }
  1081. node.body = this.finishNode(classBody, "ClassBody");
  1082. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1083. };
  1084. pp$1.parseClassMember = function(classBody) {
  1085. var this$1 = this;
  1086. if (this.eat(types.semi)) { return null }
  1087. var method = this.startNode();
  1088. var tryContextual = function (k, noLineBreak) {
  1089. if ( noLineBreak === void 0 ) noLineBreak = false;
  1090. var start = this$1.start, startLoc = this$1.startLoc;
  1091. if (!this$1.eatContextual(k)) { return false }
  1092. if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
  1093. if (method.key) { this$1.unexpected(); }
  1094. method.computed = false;
  1095. method.key = this$1.startNodeAt(start, startLoc);
  1096. method.key.name = k;
  1097. this$1.finishNode(method.key, "Identifier");
  1098. return false
  1099. };
  1100. method.kind = "method";
  1101. method.static = tryContextual("static");
  1102. var isGenerator = this.eat(types.star);
  1103. var isAsync = false;
  1104. if (!isGenerator) {
  1105. if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
  1106. isAsync = true;
  1107. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  1108. } else if (tryContextual("get")) {
  1109. method.kind = "get";
  1110. } else if (tryContextual("set")) {
  1111. method.kind = "set";
  1112. }
  1113. }
  1114. if (!method.key) { this.parsePropertyName(method); }
  1115. var key = method.key;
  1116. if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
  1117. key.type === "Literal" && key.value === "constructor")) {
  1118. if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
  1119. if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
  1120. if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
  1121. method.kind = "constructor";
  1122. } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
  1123. this.raise(key.start, "Classes may not have a static property named prototype");
  1124. }
  1125. this.parseClassMethod(classBody, method, isGenerator, isAsync);
  1126. if (method.kind === "get" && method.value.params.length !== 0)
  1127. { this.raiseRecoverable(method.value.start, "getter should have no params"); }
  1128. if (method.kind === "set" && method.value.params.length !== 1)
  1129. { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
  1130. if (method.kind === "set" && method.value.params[0].type === "RestElement")
  1131. { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
  1132. return method
  1133. };
  1134. pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
  1135. method.value = this.parseMethod(isGenerator, isAsync);
  1136. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  1137. };
  1138. pp$1.parseClassId = function(node, isStatement) {
  1139. node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
  1140. };
  1141. pp$1.parseClassSuper = function(node) {
  1142. node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
  1143. };
  1144. // Parses module export declaration.
  1145. pp$1.parseExport = function(node, exports) {
  1146. var this$1 = this;
  1147. this.next();
  1148. // export * from '...'
  1149. if (this.eat(types.star)) {
  1150. this.expectContextual("from");
  1151. if (this.type !== types.string) { this.unexpected(); }
  1152. node.source = this.parseExprAtom();
  1153. this.semicolon();
  1154. return this.finishNode(node, "ExportAllDeclaration")
  1155. }
  1156. if (this.eat(types._default)) { // export default ...
  1157. this.checkExport(exports, "default", this.lastTokStart);
  1158. var isAsync;
  1159. if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
  1160. var fNode = this.startNode();
  1161. this.next();
  1162. if (isAsync) { this.next(); }
  1163. node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
  1164. } else if (this.type === types._class) {
  1165. var cNode = this.startNode();
  1166. node.declaration = this.parseClass(cNode, "nullableID");
  1167. } else {
  1168. node.declaration = this.parseMaybeAssign();
  1169. this.semicolon();
  1170. }
  1171. return this.finishNode(node, "ExportDefaultDeclaration")
  1172. }
  1173. // export var|const|let|function|class ...
  1174. if (this.shouldParseExportStatement()) {
  1175. node.declaration = this.parseStatement(true);
  1176. if (node.declaration.type === "VariableDeclaration")
  1177. { this.checkVariableExport(exports, node.declaration.declarations); }
  1178. else
  1179. { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
  1180. node.specifiers = [];
  1181. node.source = null;
  1182. } else { // export { x, y as z } [from '...']
  1183. node.declaration = null;
  1184. node.specifiers = this.parseExportSpecifiers(exports);
  1185. if (this.eatContextual("from")) {
  1186. if (this.type !== types.string) { this.unexpected(); }
  1187. node.source = this.parseExprAtom();
  1188. } else {
  1189. // check for keywords used as local names
  1190. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1191. var spec = list[i];
  1192. this$1.checkUnreserved(spec.local);
  1193. }
  1194. node.source = null;
  1195. }
  1196. this.semicolon();
  1197. }
  1198. return this.finishNode(node, "ExportNamedDeclaration")
  1199. };
  1200. pp$1.checkExport = function(exports, name, pos) {
  1201. if (!exports) { return }
  1202. if (has(exports, name))
  1203. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1204. exports[name] = true;
  1205. };
  1206. pp$1.checkPatternExport = function(exports, pat) {
  1207. var this$1 = this;
  1208. var type = pat.type;
  1209. if (type === "Identifier")
  1210. { this.checkExport(exports, pat.name, pat.start); }
  1211. else if (type === "ObjectPattern")
  1212. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1213. {
  1214. var prop = list[i];
  1215. this$1.checkPatternExport(exports, prop);
  1216. } }
  1217. else if (type === "ArrayPattern")
  1218. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1219. var elt = list$1[i$1];
  1220. if (elt) { this$1.checkPatternExport(exports, elt); }
  1221. } }
  1222. else if (type === "Property")
  1223. { this.checkPatternExport(exports, pat.value); }
  1224. else if (type === "AssignmentPattern")
  1225. { this.checkPatternExport(exports, pat.left); }
  1226. else if (type === "RestElement")
  1227. { this.checkPatternExport(exports, pat.argument); }
  1228. else if (type === "ParenthesizedExpression")
  1229. { this.checkPatternExport(exports, pat.expression); }
  1230. };
  1231. pp$1.checkVariableExport = function(exports, decls) {
  1232. var this$1 = this;
  1233. if (!exports) { return }
  1234. for (var i = 0, list = decls; i < list.length; i += 1)
  1235. {
  1236. var decl = list[i];
  1237. this$1.checkPatternExport(exports, decl.id);
  1238. }
  1239. };
  1240. pp$1.shouldParseExportStatement = function() {
  1241. return this.type.keyword === "var" ||
  1242. this.type.keyword === "const" ||
  1243. this.type.keyword === "class" ||
  1244. this.type.keyword === "function" ||
  1245. this.isLet() ||
  1246. this.isAsyncFunction()
  1247. };
  1248. // Parses a comma-separated list of module exports.
  1249. pp$1.parseExportSpecifiers = function(exports) {
  1250. var this$1 = this;
  1251. var nodes = [], first = true;
  1252. // export { x, y as z } [from '...']
  1253. this.expect(types.braceL);
  1254. while (!this.eat(types.braceR)) {
  1255. if (!first) {
  1256. this$1.expect(types.comma);
  1257. if (this$1.afterTrailingComma(types.braceR)) { break }
  1258. } else { first = false; }
  1259. var node = this$1.startNode();
  1260. node.local = this$1.parseIdent(true);
  1261. node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
  1262. this$1.checkExport(exports, node.exported.name, node.exported.start);
  1263. nodes.push(this$1.finishNode(node, "ExportSpecifier"));
  1264. }
  1265. return nodes
  1266. };
  1267. // Parses import declaration.
  1268. pp$1.parseImport = function(node) {
  1269. this.next();
  1270. // import '...'
  1271. if (this.type === types.string) {
  1272. node.specifiers = empty;
  1273. node.source = this.parseExprAtom();
  1274. } else {
  1275. node.specifiers = this.parseImportSpecifiers();
  1276. this.expectContextual("from");
  1277. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1278. }
  1279. this.semicolon();
  1280. return this.finishNode(node, "ImportDeclaration")
  1281. };
  1282. // Parses a comma-separated list of module imports.
  1283. pp$1.parseImportSpecifiers = function() {
  1284. var this$1 = this;
  1285. var nodes = [], first = true;
  1286. if (this.type === types.name) {
  1287. // import defaultObj, { x, y as z } from '...'
  1288. var node = this.startNode();
  1289. node.local = this.parseIdent();
  1290. this.checkLVal(node.local, "let");
  1291. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1292. if (!this.eat(types.comma)) { return nodes }
  1293. }
  1294. if (this.type === types.star) {
  1295. var node$1 = this.startNode();
  1296. this.next();
  1297. this.expectContextual("as");
  1298. node$1.local = this.parseIdent();
  1299. this.checkLVal(node$1.local, "let");
  1300. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1301. return nodes
  1302. }
  1303. this.expect(types.braceL);
  1304. while (!this.eat(types.braceR)) {
  1305. if (!first) {
  1306. this$1.expect(types.comma);
  1307. if (this$1.afterTrailingComma(types.braceR)) { break }
  1308. } else { first = false; }
  1309. var node$2 = this$1.startNode();
  1310. node$2.imported = this$1.parseIdent(true);
  1311. if (this$1.eatContextual("as")) {
  1312. node$2.local = this$1.parseIdent();
  1313. } else {
  1314. this$1.checkUnreserved(node$2.imported);
  1315. node$2.local = node$2.imported;
  1316. }
  1317. this$1.checkLVal(node$2.local, "let");
  1318. nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
  1319. }
  1320. return nodes
  1321. };
  1322. // Set `ExpressionStatement#directive` property for directive prologues.
  1323. pp$1.adaptDirectivePrologue = function(statements) {
  1324. for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
  1325. statements[i].directive = statements[i].expression.raw.slice(1, -1);
  1326. }
  1327. };
  1328. pp$1.isDirectiveCandidate = function(statement) {
  1329. return (
  1330. statement.type === "ExpressionStatement" &&
  1331. statement.expression.type === "Literal" &&
  1332. typeof statement.expression.value === "string" &&
  1333. // Reject parenthesized strings.
  1334. (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
  1335. )
  1336. };
  1337. var pp$2 = Parser.prototype;
  1338. // Convert existing expression atom to assignable pattern
  1339. // if possible.
  1340. pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
  1341. var this$1 = this;
  1342. if (this.options.ecmaVersion >= 6 && node) {
  1343. switch (node.type) {
  1344. case "Identifier":
  1345. if (this.inAsync && node.name === "await")
  1346. { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
  1347. break
  1348. case "ObjectPattern":
  1349. case "ArrayPattern":
  1350. case "RestElement":
  1351. break
  1352. case "ObjectExpression":
  1353. node.type = "ObjectPattern";
  1354. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1355. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1356. var prop = list[i];
  1357. this$1.toAssignable(prop, isBinding);
  1358. // Early error:
  1359. // AssignmentRestProperty[Yield, Await] :
  1360. // `...` DestructuringAssignmentTarget[Yield, Await]
  1361. //
  1362. // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
  1363. if (
  1364. prop.type === "RestElement" &&
  1365. (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
  1366. ) {
  1367. this$1.raise(prop.argument.start, "Unexpected token");
  1368. }
  1369. }
  1370. break
  1371. case "Property":
  1372. // AssignmentProperty has type === "Property"
  1373. if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
  1374. this.toAssignable(node.value, isBinding);
  1375. break
  1376. case "ArrayExpression":
  1377. node.type = "ArrayPattern";
  1378. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1379. this.toAssignableList(node.elements, isBinding);
  1380. break
  1381. case "SpreadElement":
  1382. node.type = "RestElement";
  1383. this.toAssignable(node.argument, isBinding);
  1384. if (node.argument.type === "AssignmentPattern")
  1385. { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
  1386. break
  1387. case "AssignmentExpression":
  1388. if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
  1389. node.type = "AssignmentPattern";
  1390. delete node.operator;
  1391. this.toAssignable(node.left, isBinding);
  1392. // falls through to AssignmentPattern
  1393. case "AssignmentPattern":
  1394. break
  1395. case "ParenthesizedExpression":
  1396. this.toAssignable(node.expression, isBinding);
  1397. break
  1398. case "MemberExpression":
  1399. if (!isBinding) { break }
  1400. default:
  1401. this.raise(node.start, "Assigning to rvalue");
  1402. }
  1403. } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1404. return node
  1405. };
  1406. // Convert list of expression atoms to binding list.
  1407. pp$2.toAssignableList = function(exprList, isBinding) {
  1408. var this$1 = this;
  1409. var end = exprList.length;
  1410. for (var i = 0; i < end; i++) {
  1411. var elt = exprList[i];
  1412. if (elt) { this$1.toAssignable(elt, isBinding); }
  1413. }
  1414. if (end) {
  1415. var last = exprList[end - 1];
  1416. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1417. { this.unexpected(last.argument.start); }
  1418. }
  1419. return exprList
  1420. };
  1421. // Parses spread element.
  1422. pp$2.parseSpread = function(refDestructuringErrors) {
  1423. var node = this.startNode();
  1424. this.next();
  1425. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1426. return this.finishNode(node, "SpreadElement")
  1427. };
  1428. pp$2.parseRestBinding = function() {
  1429. var node = this.startNode();
  1430. this.next();
  1431. // RestElement inside of a function parameter must be an identifier
  1432. if (this.options.ecmaVersion === 6 && this.type !== types.name)
  1433. { this.unexpected(); }
  1434. node.argument = this.parseBindingAtom();
  1435. return this.finishNode(node, "RestElement")
  1436. };
  1437. // Parses lvalue (assignable) atom.
  1438. pp$2.parseBindingAtom = function() {
  1439. if (this.options.ecmaVersion >= 6) {
  1440. switch (this.type) {
  1441. case types.bracketL:
  1442. var node = this.startNode();
  1443. this.next();
  1444. node.elements = this.parseBindingList(types.bracketR, true, true);
  1445. return this.finishNode(node, "ArrayPattern")
  1446. case types.braceL:
  1447. return this.parseObj(true)
  1448. }
  1449. }
  1450. return this.parseIdent()
  1451. };
  1452. pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  1453. var this$1 = this;
  1454. var elts = [], first = true;
  1455. while (!this.eat(close)) {
  1456. if (first) { first = false; }
  1457. else { this$1.expect(types.comma); }
  1458. if (allowEmpty && this$1.type === types.comma) {
  1459. elts.push(null);
  1460. } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
  1461. break
  1462. } else if (this$1.type === types.ellipsis) {
  1463. var rest = this$1.parseRestBinding();
  1464. this$1.parseBindingListItem(rest);
  1465. elts.push(rest);
  1466. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1467. this$1.expect(close);
  1468. break
  1469. } else {
  1470. var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
  1471. this$1.parseBindingListItem(elem);
  1472. elts.push(elem);
  1473. }
  1474. }
  1475. return elts
  1476. };
  1477. pp$2.parseBindingListItem = function(param) {
  1478. return param
  1479. };
  1480. // Parses assignment pattern around given atom if possible.
  1481. pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
  1482. left = left || this.parseBindingAtom();
  1483. if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
  1484. var node = this.startNodeAt(startPos, startLoc);
  1485. node.left = left;
  1486. node.right = this.parseMaybeAssign();
  1487. return this.finishNode(node, "AssignmentPattern")
  1488. };
  1489. // Verify that a node is an lval — something that can be assigned
  1490. // to.
  1491. // bindingType can be either:
  1492. // 'var' indicating that the lval creates a 'var' binding
  1493. // 'let' indicating that the lval creates a lexical ('let' or 'const') binding
  1494. // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
  1495. pp$2.checkLVal = function(expr, bindingType, checkClashes) {
  1496. var this$1 = this;
  1497. switch (expr.type) {
  1498. case "Identifier":
  1499. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1500. { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1501. if (checkClashes) {
  1502. if (has(checkClashes, expr.name))
  1503. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1504. checkClashes[expr.name] = true;
  1505. }
  1506. if (bindingType && bindingType !== "none") {
  1507. if (
  1508. bindingType === "var" && !this.canDeclareVarName(expr.name) ||
  1509. bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
  1510. ) {
  1511. this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
  1512. }
  1513. if (bindingType === "var") {
  1514. this.declareVarName(expr.name);
  1515. } else {
  1516. this.declareLexicalName(expr.name);
  1517. }
  1518. }
  1519. break
  1520. case "MemberExpression":
  1521. if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
  1522. break
  1523. case "ObjectPattern":
  1524. for (var i = 0, list = expr.properties; i < list.length; i += 1)
  1525. {
  1526. var prop = list[i];
  1527. this$1.checkLVal(prop, bindingType, checkClashes);
  1528. }
  1529. break
  1530. case "Property":
  1531. // AssignmentProperty has type === "Property"
  1532. this.checkLVal(expr.value, bindingType, checkClashes);
  1533. break
  1534. case "ArrayPattern":
  1535. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1536. var elem = list$1[i$1];
  1537. if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
  1538. }
  1539. break
  1540. case "AssignmentPattern":
  1541. this.checkLVal(expr.left, bindingType, checkClashes);
  1542. break
  1543. case "RestElement":
  1544. this.checkLVal(expr.argument, bindingType, checkClashes);
  1545. break
  1546. case "ParenthesizedExpression":
  1547. this.checkLVal(expr.expression, bindingType, checkClashes);
  1548. break
  1549. default:
  1550. this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
  1551. }
  1552. };
  1553. // A recursive descent parser operates by defining functions for all
  1554. // syntactic elements, and recursively calling those, each function
  1555. // advancing the input stream and returning an AST node. Precedence
  1556. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  1557. // instead of `(!x)[1]` is handled by the fact that the parser
  1558. // function that parses unary prefix operators is called first, and
  1559. // in turn calls the function that parses `[]` subscripts — that
  1560. // way, it'll receive the node for `x[1]` already parsed, and wraps
  1561. // *that* in the unary operator node.
  1562. //
  1563. // Acorn uses an [operator precedence parser][opp] to handle binary
  1564. // operator precedence, because it is much more compact than using
  1565. // the technique outlined above, which uses different, nesting
  1566. // functions to specify precedence, for all of the ten binary
  1567. // precedence levels that JavaScript defines.
  1568. //
  1569. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  1570. var pp$3 = Parser.prototype;
  1571. // Check if property name clashes with already added.
  1572. // Object/class getters and setters are not allowed to clash —
  1573. // either with each other or with an init property — and in
  1574. // strict mode, init properties are also not allowed to be repeated.
  1575. pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
  1576. if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
  1577. { return }
  1578. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  1579. { return }
  1580. var key = prop.key;
  1581. var name;
  1582. switch (key.type) {
  1583. case "Identifier": name = key.name; break
  1584. case "Literal": name = String(key.value); break
  1585. default: return
  1586. }
  1587. var kind = prop.kind;
  1588. if (this.options.ecmaVersion >= 6) {
  1589. if (name === "__proto__" && kind === "init") {
  1590. if (propHash.proto) {
  1591. if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) { refDestructuringErrors.doubleProto = key.start; }
  1592. // Backwards-compat kludge. Can be removed in version 6.0
  1593. else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
  1594. }
  1595. propHash.proto = true;
  1596. }
  1597. return
  1598. }
  1599. name = "$" + name;
  1600. var other = propHash[name];
  1601. if (other) {
  1602. var redefinition;
  1603. if (kind === "init") {
  1604. redefinition = this.strict && other.init || other.get || other.set;
  1605. } else {
  1606. redefinition = other.init || other[kind];
  1607. }
  1608. if (redefinition)
  1609. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  1610. } else {
  1611. other = propHash[name] = {
  1612. init: false,
  1613. get: false,
  1614. set: false
  1615. };
  1616. }
  1617. other[kind] = true;
  1618. };
  1619. // ### Expression parsing
  1620. // These nest, from the most general expression type at the top to
  1621. // 'atomic', nondivisible expression types at the bottom. Most of
  1622. // the functions will simply let the function(s) below them parse,
  1623. // and, *if* the syntactic construct they handle is present, wrap
  1624. // the AST node that the inner parser gave them in another node.
  1625. // Parse a full expression. The optional arguments are used to
  1626. // forbid the `in` operator (in for loops initalization expressions)
  1627. // and provide reference for storing '=' operator inside shorthand
  1628. // property assignment in contexts where both object expression
  1629. // and object pattern might appear (so it's possible to raise
  1630. // delayed syntax error at correct position).
  1631. pp$3.parseExpression = function(noIn, refDestructuringErrors) {
  1632. var this$1 = this;
  1633. var startPos = this.start, startLoc = this.startLoc;
  1634. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  1635. if (this.type === types.comma) {
  1636. var node = this.startNodeAt(startPos, startLoc);
  1637. node.expressions = [expr];
  1638. while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
  1639. return this.finishNode(node, "SequenceExpression")
  1640. }
  1641. return expr
  1642. };
  1643. // Parse an assignment expression. This includes applications of
  1644. // operators like `+=`.
  1645. pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
  1646. if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
  1647. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
  1648. if (refDestructuringErrors) {
  1649. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  1650. oldTrailingComma = refDestructuringErrors.trailingComma;
  1651. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  1652. } else {
  1653. refDestructuringErrors = new DestructuringErrors;
  1654. ownDestructuringErrors = true;
  1655. }
  1656. var startPos = this.start, startLoc = this.startLoc;
  1657. if (this.type === types.parenL || this.type === types.name)
  1658. { this.potentialArrowAt = this.start; }
  1659. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  1660. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  1661. if (this.type.isAssign) {
  1662. var node = this.startNodeAt(startPos, startLoc);
  1663. node.operator = this.value;
  1664. node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left;
  1665. if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
  1666. refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
  1667. this.checkLVal(left);
  1668. this.next();
  1669. node.right = this.parseMaybeAssign(noIn);
  1670. return this.finishNode(node, "AssignmentExpression")
  1671. } else {
  1672. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  1673. }
  1674. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  1675. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  1676. return left
  1677. };
  1678. // Parse a ternary conditional (`?:`) operator.
  1679. pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
  1680. var startPos = this.start, startLoc = this.startLoc;
  1681. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  1682. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1683. if (this.eat(types.question)) {
  1684. var node = this.startNodeAt(startPos, startLoc);
  1685. node.test = expr;
  1686. node.consequent = this.parseMaybeAssign();
  1687. this.expect(types.colon);
  1688. node.alternate = this.parseMaybeAssign(noIn);
  1689. return this.finishNode(node, "ConditionalExpression")
  1690. }
  1691. return expr
  1692. };
  1693. // Start the precedence parser.
  1694. pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
  1695. var startPos = this.start, startLoc = this.startLoc;
  1696. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  1697. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1698. return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
  1699. };
  1700. // Parse binary operators with the operator precedence parsing
  1701. // algorithm. `left` is the left-hand side of the operator.
  1702. // `minPrec` provides context that allows the function to stop and
  1703. // defer further parser to one of its callers when it encounters an
  1704. // operator that has a lower precedence than the set it is parsing.
  1705. pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
  1706. var prec = this.type.binop;
  1707. if (prec != null && (!noIn || this.type !== types._in)) {
  1708. if (prec > minPrec) {
  1709. var logical = this.type === types.logicalOR || this.type === types.logicalAND;
  1710. var op = this.value;
  1711. this.next();
  1712. var startPos = this.start, startLoc = this.startLoc;
  1713. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  1714. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
  1715. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
  1716. }
  1717. }
  1718. return left
  1719. };
  1720. pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  1721. var node = this.startNodeAt(startPos, startLoc);
  1722. node.left = left;
  1723. node.operator = op;
  1724. node.right = right;
  1725. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  1726. };
  1727. // Parse unary operators, both prefix and postfix.
  1728. pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
  1729. var this$1 = this;
  1730. var startPos = this.start, startLoc = this.startLoc, expr;
  1731. if (this.isContextual("await") && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction))) {
  1732. expr = this.parseAwait();
  1733. sawUnary = true;
  1734. } else if (this.type.prefix) {
  1735. var node = this.startNode(), update = this.type === types.incDec;
  1736. node.operator = this.value;
  1737. node.prefix = true;
  1738. this.next();
  1739. node.argument = this.parseMaybeUnary(null, true);
  1740. this.checkExpressionErrors(refDestructuringErrors, true);
  1741. if (update) { this.checkLVal(node.argument); }
  1742. else if (this.strict && node.operator === "delete" &&
  1743. node.argument.type === "Identifier")
  1744. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  1745. else { sawUnary = true; }
  1746. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  1747. } else {
  1748. expr = this.parseExprSubscripts(refDestructuringErrors);
  1749. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1750. while (this.type.postfix && !this.canInsertSemicolon()) {
  1751. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1752. node$1.operator = this$1.value;
  1753. node$1.prefix = false;
  1754. node$1.argument = expr;
  1755. this$1.checkLVal(expr);
  1756. this$1.next();
  1757. expr = this$1.finishNode(node$1, "UpdateExpression");
  1758. }
  1759. }
  1760. if (!sawUnary && this.eat(types.starstar))
  1761. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
  1762. else
  1763. { return expr }
  1764. };
  1765. // Parse call, dot, and `[]`-subscript expressions.
  1766. pp$3.parseExprSubscripts = function(refDestructuringErrors) {
  1767. var startPos = this.start, startLoc = this.startLoc;
  1768. var expr = this.parseExprAtom(refDestructuringErrors);
  1769. var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
  1770. if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
  1771. var result = this.parseSubscripts(expr, startPos, startLoc);
  1772. if (refDestructuringErrors && result.type === "MemberExpression") {
  1773. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  1774. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  1775. }
  1776. return result
  1777. };
  1778. pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
  1779. var this$1 = this;
  1780. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  1781. this.lastTokEnd === base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async";
  1782. for (var computed = (void 0);;) {
  1783. if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
  1784. var node = this$1.startNodeAt(startPos, startLoc);
  1785. node.object = base;
  1786. node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
  1787. node.computed = !!computed;
  1788. if (computed) { this$1.expect(types.bracketR); }
  1789. base = this$1.finishNode(node, "MemberExpression");
  1790. } else if (!noCalls && this$1.eat(types.parenL)) {
  1791. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
  1792. this$1.yieldPos = 0;
  1793. this$1.awaitPos = 0;
  1794. var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
  1795. if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
  1796. this$1.checkPatternErrors(refDestructuringErrors, false);
  1797. this$1.checkYieldAwaitInDefaultParams();
  1798. this$1.yieldPos = oldYieldPos;
  1799. this$1.awaitPos = oldAwaitPos;
  1800. return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
  1801. }
  1802. this$1.checkExpressionErrors(refDestructuringErrors, true);
  1803. this$1.yieldPos = oldYieldPos || this$1.yieldPos;
  1804. this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
  1805. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1806. node$1.callee = base;
  1807. node$1.arguments = exprList;
  1808. base = this$1.finishNode(node$1, "CallExpression");
  1809. } else if (this$1.type === types.backQuote) {
  1810. var node$2 = this$1.startNodeAt(startPos, startLoc);
  1811. node$2.tag = base;
  1812. node$2.quasi = this$1.parseTemplate({isTagged: true});
  1813. base = this$1.finishNode(node$2, "TaggedTemplateExpression");
  1814. } else {
  1815. return base
  1816. }
  1817. }
  1818. };
  1819. // Parse an atomic expression — either a single token that is an
  1820. // expression, an expression started by a keyword like `function` or
  1821. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  1822. // or `{}`.
  1823. pp$3.parseExprAtom = function(refDestructuringErrors) {
  1824. var node, canBeArrow = this.potentialArrowAt === this.start;
  1825. switch (this.type) {
  1826. case types._super:
  1827. if (!this.inFunction)
  1828. { this.raise(this.start, "'super' outside of function or class"); }
  1829. node = this.startNode();
  1830. this.next();
  1831. // The `super` keyword can appear at below:
  1832. // SuperProperty:
  1833. // super [ Expression ]
  1834. // super . IdentifierName
  1835. // SuperCall:
  1836. // super Arguments
  1837. if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
  1838. { this.unexpected(); }
  1839. return this.finishNode(node, "Super")
  1840. case types._this:
  1841. node = this.startNode();
  1842. this.next();
  1843. return this.finishNode(node, "ThisExpression")
  1844. case types.name:
  1845. var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
  1846. var id = this.parseIdent(this.type !== types.name);
  1847. if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
  1848. { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
  1849. if (canBeArrow && !this.canInsertSemicolon()) {
  1850. if (this.eat(types.arrow))
  1851. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
  1852. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
  1853. id = this.parseIdent();
  1854. if (this.canInsertSemicolon() || !this.eat(types.arrow))
  1855. { this.unexpected(); }
  1856. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
  1857. }
  1858. }
  1859. return id
  1860. case types.regexp:
  1861. var value = this.value;
  1862. node = this.parseLiteral(value.value);
  1863. node.regex = {pattern: value.pattern, flags: value.flags};
  1864. return node
  1865. case types.num: case types.string:
  1866. return this.parseLiteral(this.value)
  1867. case types._null: case types._true: case types._false:
  1868. node = this.startNode();
  1869. node.value = this.type === types._null ? null : this.type === types._true;
  1870. node.raw = this.type.keyword;
  1871. this.next();
  1872. return this.finishNode(node, "Literal")
  1873. case types.parenL:
  1874. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
  1875. if (refDestructuringErrors) {
  1876. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  1877. { refDestructuringErrors.parenthesizedAssign = start; }
  1878. if (refDestructuringErrors.parenthesizedBind < 0)
  1879. { refDestructuringErrors.parenthesizedBind = start; }
  1880. }
  1881. return expr
  1882. case types.bracketL:
  1883. node = this.startNode();
  1884. this.next();
  1885. node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
  1886. return this.finishNode(node, "ArrayExpression")
  1887. case types.braceL:
  1888. return this.parseObj(false, refDestructuringErrors)
  1889. case types._function:
  1890. node = this.startNode();
  1891. this.next();
  1892. return this.parseFunction(node, false)
  1893. case types._class:
  1894. return this.parseClass(this.startNode(), false)
  1895. case types._new:
  1896. return this.parseNew()
  1897. case types.backQuote:
  1898. return this.parseTemplate()
  1899. default:
  1900. this.unexpected();
  1901. }
  1902. };
  1903. pp$3.parseLiteral = function(value) {
  1904. var node = this.startNode();
  1905. node.value = value;
  1906. node.raw = this.input.slice(this.start, this.end);
  1907. this.next();
  1908. return this.finishNode(node, "Literal")
  1909. };
  1910. pp$3.parseParenExpression = function() {
  1911. this.expect(types.parenL);
  1912. var val = this.parseExpression();
  1913. this.expect(types.parenR);
  1914. return val
  1915. };
  1916. pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
  1917. var this$1 = this;
  1918. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  1919. if (this.options.ecmaVersion >= 6) {
  1920. this.next();
  1921. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  1922. var exprList = [], first = true, lastIsComma = false;
  1923. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
  1924. this.yieldPos = 0;
  1925. this.awaitPos = 0;
  1926. while (this.type !== types.parenR) {
  1927. first ? first = false : this$1.expect(types.comma);
  1928. if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
  1929. lastIsComma = true;
  1930. break
  1931. } else if (this$1.type === types.ellipsis) {
  1932. spreadStart = this$1.start;
  1933. exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
  1934. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1935. break
  1936. } else {
  1937. exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
  1938. }
  1939. }
  1940. var innerEndPos = this.start, innerEndLoc = this.startLoc;
  1941. this.expect(types.parenR);
  1942. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  1943. this.checkPatternErrors(refDestructuringErrors, false);
  1944. this.checkYieldAwaitInDefaultParams();
  1945. this.yieldPos = oldYieldPos;
  1946. this.awaitPos = oldAwaitPos;
  1947. return this.parseParenArrowList(startPos, startLoc, exprList)
  1948. }
  1949. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  1950. if (spreadStart) { this.unexpected(spreadStart); }
  1951. this.checkExpressionErrors(refDestructuringErrors, true);
  1952. this.yieldPos = oldYieldPos || this.yieldPos;
  1953. this.awaitPos = oldAwaitPos || this.awaitPos;
  1954. if (exprList.length > 1) {
  1955. val = this.startNodeAt(innerStartPos, innerStartLoc);
  1956. val.expressions = exprList;
  1957. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  1958. } else {
  1959. val = exprList[0];
  1960. }
  1961. } else {
  1962. val = this.parseParenExpression();
  1963. }
  1964. if (this.options.preserveParens) {
  1965. var par = this.startNodeAt(startPos, startLoc);
  1966. par.expression = val;
  1967. return this.finishNode(par, "ParenthesizedExpression")
  1968. } else {
  1969. return val
  1970. }
  1971. };
  1972. pp$3.parseParenItem = function(item) {
  1973. return item
  1974. };
  1975. pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
  1976. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
  1977. };
  1978. // New's precedence is slightly tricky. It must allow its argument to
  1979. // be a `[]` or dot subscript expression, but not a call — at least,
  1980. // not without wrapping it in parentheses. Thus, it uses the noCalls
  1981. // argument to parseSubscripts to prevent it from consuming the
  1982. // argument list.
  1983. var empty$1 = [];
  1984. pp$3.parseNew = function() {
  1985. var node = this.startNode();
  1986. var meta = this.parseIdent(true);
  1987. if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
  1988. node.meta = meta;
  1989. var containsEsc = this.containsEsc;
  1990. node.property = this.parseIdent(true);
  1991. if (node.property.name !== "target" || containsEsc)
  1992. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
  1993. if (!this.inFunction)
  1994. { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
  1995. return this.finishNode(node, "MetaProperty")
  1996. }
  1997. var startPos = this.start, startLoc = this.startLoc;
  1998. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  1999. if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
  2000. else { node.arguments = empty$1; }
  2001. return this.finishNode(node, "NewExpression")
  2002. };
  2003. // Parse template expression.
  2004. pp$3.parseTemplateElement = function(ref) {
  2005. var isTagged = ref.isTagged;
  2006. var elem = this.startNode();
  2007. if (this.type === types.invalidTemplate) {
  2008. if (!isTagged) {
  2009. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  2010. }
  2011. elem.value = {
  2012. raw: this.value,
  2013. cooked: null
  2014. };
  2015. } else {
  2016. elem.value = {
  2017. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  2018. cooked: this.value
  2019. };
  2020. }
  2021. this.next();
  2022. elem.tail = this.type === types.backQuote;
  2023. return this.finishNode(elem, "TemplateElement")
  2024. };
  2025. pp$3.parseTemplate = function(ref) {
  2026. var this$1 = this;
  2027. if ( ref === void 0 ) ref = {};
  2028. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  2029. var node = this.startNode();
  2030. this.next();
  2031. node.expressions = [];
  2032. var curElt = this.parseTemplateElement({isTagged: isTagged});
  2033. node.quasis = [curElt];
  2034. while (!curElt.tail) {
  2035. if (this$1.type === types.eof) { this$1.raise(this$1.pos, "Unterminated template literal"); }
  2036. this$1.expect(types.dollarBraceL);
  2037. node.expressions.push(this$1.parseExpression());
  2038. this$1.expect(types.braceR);
  2039. node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
  2040. }
  2041. this.next();
  2042. return this.finishNode(node, "TemplateLiteral")
  2043. };
  2044. pp$3.isAsyncProp = function(prop) {
  2045. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  2046. (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)) &&
  2047. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  2048. };
  2049. // Parse an object literal or binding pattern.
  2050. pp$3.parseObj = function(isPattern, refDestructuringErrors) {
  2051. var this$1 = this;
  2052. var node = this.startNode(), first = true, propHash = {};
  2053. node.properties = [];
  2054. this.next();
  2055. while (!this.eat(types.braceR)) {
  2056. if (!first) {
  2057. this$1.expect(types.comma);
  2058. if (this$1.afterTrailingComma(types.braceR)) { break }
  2059. } else { first = false; }
  2060. var prop = this$1.parseProperty(isPattern, refDestructuringErrors);
  2061. if (!isPattern) { this$1.checkPropClash(prop, propHash, refDestructuringErrors); }
  2062. node.properties.push(prop);
  2063. }
  2064. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  2065. };
  2066. pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
  2067. var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
  2068. if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
  2069. if (isPattern) {
  2070. prop.argument = this.parseIdent(false);
  2071. if (this.type === types.comma) {
  2072. this.raise(this.start, "Comma is not permitted after the rest element");
  2073. }
  2074. return this.finishNode(prop, "RestElement")
  2075. }
  2076. // To disallow parenthesized identifier via `this.toAssignable()`.
  2077. if (this.type === types.parenL && refDestructuringErrors) {
  2078. if (refDestructuringErrors.parenthesizedAssign < 0) {
  2079. refDestructuringErrors.parenthesizedAssign = this.start;
  2080. }
  2081. if (refDestructuringErrors.parenthesizedBind < 0) {
  2082. refDestructuringErrors.parenthesizedBind = this.start;
  2083. }
  2084. }
  2085. // Parse argument.
  2086. prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  2087. // To disallow trailing comma via `this.toAssignable()`.
  2088. if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
  2089. refDestructuringErrors.trailingComma = this.start;
  2090. }
  2091. // Finish
  2092. return this.finishNode(prop, "SpreadElement")
  2093. }
  2094. if (this.options.ecmaVersion >= 6) {
  2095. prop.method = false;
  2096. prop.shorthand = false;
  2097. if (isPattern || refDestructuringErrors) {
  2098. startPos = this.start;
  2099. startLoc = this.startLoc;
  2100. }
  2101. if (!isPattern)
  2102. { isGenerator = this.eat(types.star); }
  2103. }
  2104. var containsEsc = this.containsEsc;
  2105. this.parsePropertyName(prop);
  2106. if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
  2107. isAsync = true;
  2108. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  2109. this.parsePropertyName(prop, refDestructuringErrors);
  2110. } else {
  2111. isAsync = false;
  2112. }
  2113. this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
  2114. return this.finishNode(prop, "Property")
  2115. };
  2116. pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
  2117. if ((isGenerator || isAsync) && this.type === types.colon)
  2118. { this.unexpected(); }
  2119. if (this.eat(types.colon)) {
  2120. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  2121. prop.kind = "init";
  2122. } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
  2123. if (isPattern) { this.unexpected(); }
  2124. prop.kind = "init";
  2125. prop.method = true;
  2126. prop.value = this.parseMethod(isGenerator, isAsync);
  2127. } else if (!isPattern && !containsEsc &&
  2128. this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  2129. (prop.key.name === "get" || prop.key.name === "set") &&
  2130. (this.type !== types.comma && this.type !== types.braceR)) {
  2131. if (isGenerator || isAsync) { this.unexpected(); }
  2132. prop.kind = prop.key.name;
  2133. this.parsePropertyName(prop);
  2134. prop.value = this.parseMethod(false);
  2135. var paramCount = prop.kind === "get" ? 0 : 1;
  2136. if (prop.value.params.length !== paramCount) {
  2137. var start = prop.value.start;
  2138. if (prop.kind === "get")
  2139. { this.raiseRecoverable(start, "getter should have no params"); }
  2140. else
  2141. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2142. } else {
  2143. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2144. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2145. }
  2146. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2147. this.checkUnreserved(prop.key);
  2148. prop.kind = "init";
  2149. if (isPattern) {
  2150. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2151. } else if (this.type === types.eq && refDestructuringErrors) {
  2152. if (refDestructuringErrors.shorthandAssign < 0)
  2153. { refDestructuringErrors.shorthandAssign = this.start; }
  2154. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2155. } else {
  2156. prop.value = prop.key;
  2157. }
  2158. prop.shorthand = true;
  2159. } else { this.unexpected(); }
  2160. };
  2161. pp$3.parsePropertyName = function(prop) {
  2162. if (this.options.ecmaVersion >= 6) {
  2163. if (this.eat(types.bracketL)) {
  2164. prop.computed = true;
  2165. prop.key = this.parseMaybeAssign();
  2166. this.expect(types.bracketR);
  2167. return prop.key
  2168. } else {
  2169. prop.computed = false;
  2170. }
  2171. }
  2172. return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
  2173. };
  2174. // Initialize empty function node.
  2175. pp$3.initFunction = function(node) {
  2176. node.id = null;
  2177. if (this.options.ecmaVersion >= 6) {
  2178. node.generator = false;
  2179. node.expression = false;
  2180. }
  2181. if (this.options.ecmaVersion >= 8)
  2182. { node.async = false; }
  2183. };
  2184. // Parse object or class method.
  2185. pp$3.parseMethod = function(isGenerator, isAsync) {
  2186. var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2187. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2188. this.initFunction(node);
  2189. if (this.options.ecmaVersion >= 6)
  2190. { node.generator = isGenerator; }
  2191. if (this.options.ecmaVersion >= 8)
  2192. { node.async = !!isAsync; }
  2193. this.inGenerator = node.generator;
  2194. this.inAsync = node.async;
  2195. this.yieldPos = 0;
  2196. this.awaitPos = 0;
  2197. this.inFunction = true;
  2198. this.enterFunctionScope();
  2199. this.expect(types.parenL);
  2200. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  2201. this.checkYieldAwaitInDefaultParams();
  2202. this.parseFunctionBody(node, false);
  2203. this.inGenerator = oldInGen;
  2204. this.inAsync = oldInAsync;
  2205. this.yieldPos = oldYieldPos;
  2206. this.awaitPos = oldAwaitPos;
  2207. this.inFunction = oldInFunc;
  2208. return this.finishNode(node, "FunctionExpression")
  2209. };
  2210. // Parse arrow function expression with given parameters.
  2211. pp$3.parseArrowExpression = function(node, params, isAsync) {
  2212. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2213. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2214. this.enterFunctionScope();
  2215. this.initFunction(node);
  2216. if (this.options.ecmaVersion >= 8)
  2217. { node.async = !!isAsync; }
  2218. this.inGenerator = false;
  2219. this.inAsync = node.async;
  2220. this.yieldPos = 0;
  2221. this.awaitPos = 0;
  2222. this.inFunction = true;
  2223. node.params = this.toAssignableList(params, true);
  2224. this.parseFunctionBody(node, true);
  2225. this.inGenerator = oldInGen;
  2226. this.inAsync = oldInAsync;
  2227. this.yieldPos = oldYieldPos;
  2228. this.awaitPos = oldAwaitPos;
  2229. this.inFunction = oldInFunc;
  2230. return this.finishNode(node, "ArrowFunctionExpression")
  2231. };
  2232. // Parse function body and check parameters.
  2233. pp$3.parseFunctionBody = function(node, isArrowFunction) {
  2234. var isExpression = isArrowFunction && this.type !== types.braceL;
  2235. var oldStrict = this.strict, useStrict = false;
  2236. if (isExpression) {
  2237. node.body = this.parseMaybeAssign();
  2238. node.expression = true;
  2239. this.checkParams(node, false);
  2240. } else {
  2241. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2242. if (!oldStrict || nonSimple) {
  2243. useStrict = this.strictDirective(this.end);
  2244. // If this is a strict mode function, verify that argument names
  2245. // are not repeated, and it does not try to bind the words `eval`
  2246. // or `arguments`.
  2247. if (useStrict && nonSimple)
  2248. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2249. }
  2250. // Start a new scope with regard to labels and the `inFunction`
  2251. // flag (restore them to their old value afterwards).
  2252. var oldLabels = this.labels;
  2253. this.labels = [];
  2254. if (useStrict) { this.strict = true; }
  2255. // Add the params to varDeclaredNames to ensure that an error is thrown
  2256. // if a let/const declaration in the function clashes with one of the params.
  2257. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
  2258. node.body = this.parseBlock(false);
  2259. node.expression = false;
  2260. this.adaptDirectivePrologue(node.body.body);
  2261. this.labels = oldLabels;
  2262. }
  2263. this.exitFunctionScope();
  2264. if (this.strict && node.id) {
  2265. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2266. this.checkLVal(node.id, "none");
  2267. }
  2268. this.strict = oldStrict;
  2269. };
  2270. pp$3.isSimpleParamList = function(params) {
  2271. for (var i = 0, list = params; i < list.length; i += 1)
  2272. {
  2273. var param = list[i];
  2274. if (param.type !== "Identifier") { return false
  2275. } }
  2276. return true
  2277. };
  2278. // Checks function params for various disallowed patterns such as using "eval"
  2279. // or "arguments" and duplicate parameters.
  2280. pp$3.checkParams = function(node, allowDuplicates) {
  2281. var this$1 = this;
  2282. var nameHash = {};
  2283. for (var i = 0, list = node.params; i < list.length; i += 1)
  2284. {
  2285. var param = list[i];
  2286. this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
  2287. }
  2288. };
  2289. // Parses a comma-separated list of expressions, and returns them as
  2290. // an array. `close` is the token type that ends the list, and
  2291. // `allowEmpty` can be turned on to allow subsequent commas with
  2292. // nothing in between them to be parsed as `null` (which is needed
  2293. // for array literals).
  2294. pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2295. var this$1 = this;
  2296. var elts = [], first = true;
  2297. while (!this.eat(close)) {
  2298. if (!first) {
  2299. this$1.expect(types.comma);
  2300. if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
  2301. } else { first = false; }
  2302. var elt = (void 0);
  2303. if (allowEmpty && this$1.type === types.comma)
  2304. { elt = null; }
  2305. else if (this$1.type === types.ellipsis) {
  2306. elt = this$1.parseSpread(refDestructuringErrors);
  2307. if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
  2308. { refDestructuringErrors.trailingComma = this$1.start; }
  2309. } else {
  2310. elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
  2311. }
  2312. elts.push(elt);
  2313. }
  2314. return elts
  2315. };
  2316. pp$3.checkUnreserved = function(ref) {
  2317. var start = ref.start;
  2318. var end = ref.end;
  2319. var name = ref.name;
  2320. if (this.inGenerator && name === "yield")
  2321. { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
  2322. if (this.inAsync && name === "await")
  2323. { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
  2324. if (this.isKeyword(name))
  2325. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  2326. if (this.options.ecmaVersion < 6 &&
  2327. this.input.slice(start, end).indexOf("\\") !== -1) { return }
  2328. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  2329. if (re.test(name)) {
  2330. if (!this.inAsync && name === "await")
  2331. { this.raiseRecoverable(start, "Can not use keyword 'await' outside an async function"); }
  2332. this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
  2333. }
  2334. };
  2335. // Parse the next token as an identifier. If `liberal` is true (used
  2336. // when parsing properties), it will also convert keywords into
  2337. // identifiers.
  2338. pp$3.parseIdent = function(liberal, isBinding) {
  2339. var node = this.startNode();
  2340. if (liberal && this.options.allowReserved === "never") { liberal = false; }
  2341. if (this.type === types.name) {
  2342. node.name = this.value;
  2343. } else if (this.type.keyword) {
  2344. node.name = this.type.keyword;
  2345. // To fix https://github.com/acornjs/acorn/issues/575
  2346. // `class` and `function` keywords push new context into this.context.
  2347. // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
  2348. // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
  2349. if ((node.name === "class" || node.name === "function") &&
  2350. (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
  2351. this.context.pop();
  2352. }
  2353. } else {
  2354. this.unexpected();
  2355. }
  2356. this.next();
  2357. this.finishNode(node, "Identifier");
  2358. if (!liberal) { this.checkUnreserved(node); }
  2359. return node
  2360. };
  2361. // Parses yield expression inside generator.
  2362. pp$3.parseYield = function() {
  2363. if (!this.yieldPos) { this.yieldPos = this.start; }
  2364. var node = this.startNode();
  2365. this.next();
  2366. if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) {
  2367. node.delegate = false;
  2368. node.argument = null;
  2369. } else {
  2370. node.delegate = this.eat(types.star);
  2371. node.argument = this.parseMaybeAssign();
  2372. }
  2373. return this.finishNode(node, "YieldExpression")
  2374. };
  2375. pp$3.parseAwait = function() {
  2376. if (!this.awaitPos) { this.awaitPos = this.start; }
  2377. var node = this.startNode();
  2378. this.next();
  2379. node.argument = this.parseMaybeUnary(null, true);
  2380. return this.finishNode(node, "AwaitExpression")
  2381. };
  2382. var pp$4 = Parser.prototype;
  2383. // This function is used to raise exceptions on parse errors. It
  2384. // takes an offset integer (into the current `input`) to indicate
  2385. // the location of the error, attaches the position to the end
  2386. // of the error message, and then raises a `SyntaxError` with that
  2387. // message.
  2388. pp$4.raise = function(pos, message) {
  2389. var loc = getLineInfo(this.input, pos);
  2390. message += " (" + loc.line + ":" + loc.column + ")";
  2391. var err = new SyntaxError(message);
  2392. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  2393. throw err
  2394. };
  2395. pp$4.raiseRecoverable = pp$4.raise;
  2396. pp$4.curPosition = function() {
  2397. if (this.options.locations) {
  2398. return new Position(this.curLine, this.pos - this.lineStart)
  2399. }
  2400. };
  2401. var pp$5 = Parser.prototype;
  2402. // Object.assign polyfill
  2403. var assign = Object.assign || function(target) {
  2404. var sources = [], len = arguments.length - 1;
  2405. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  2406. for (var i = 0, list = sources; i < list.length; i += 1) {
  2407. var source = list[i];
  2408. for (var key in source) {
  2409. if (has(source, key)) {
  2410. target[key] = source[key];
  2411. }
  2412. }
  2413. }
  2414. return target
  2415. };
  2416. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  2417. pp$5.enterFunctionScope = function() {
  2418. // var: a hash of var-declared names in the current lexical scope
  2419. // lexical: a hash of lexically-declared names in the current lexical scope
  2420. // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
  2421. // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
  2422. this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
  2423. };
  2424. pp$5.exitFunctionScope = function() {
  2425. this.scopeStack.pop();
  2426. };
  2427. pp$5.enterLexicalScope = function() {
  2428. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2429. var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
  2430. this.scopeStack.push(childScope);
  2431. assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
  2432. };
  2433. pp$5.exitLexicalScope = function() {
  2434. var childScope = this.scopeStack.pop();
  2435. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2436. assign(parentScope.childVar, childScope.var, childScope.childVar);
  2437. };
  2438. /**
  2439. * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
  2440. * in the current lexical scope or any of the parent lexical scopes in this function.
  2441. */
  2442. pp$5.canDeclareVarName = function(name) {
  2443. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2444. return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
  2445. };
  2446. /**
  2447. * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
  2448. * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
  2449. * any child lexical scopes in this function.
  2450. */
  2451. pp$5.canDeclareLexicalName = function(name) {
  2452. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2453. return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
  2454. };
  2455. pp$5.declareVarName = function(name) {
  2456. this.scopeStack[this.scopeStack.length - 1].var[name] = true;
  2457. };
  2458. pp$5.declareLexicalName = function(name) {
  2459. this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
  2460. };
  2461. var Node = function Node(parser, pos, loc) {
  2462. this.type = "";
  2463. this.start = pos;
  2464. this.end = 0;
  2465. if (parser.options.locations)
  2466. { this.loc = new SourceLocation(parser, loc); }
  2467. if (parser.options.directSourceFile)
  2468. { this.sourceFile = parser.options.directSourceFile; }
  2469. if (parser.options.ranges)
  2470. { this.range = [pos, 0]; }
  2471. };
  2472. // Start an AST node, attaching a start offset.
  2473. var pp$6 = Parser.prototype;
  2474. pp$6.startNode = function() {
  2475. return new Node(this, this.start, this.startLoc)
  2476. };
  2477. pp$6.startNodeAt = function(pos, loc) {
  2478. return new Node(this, pos, loc)
  2479. };
  2480. // Finish an AST node, adding `type` and `end` properties.
  2481. function finishNodeAt(node, type, pos, loc) {
  2482. node.type = type;
  2483. node.end = pos;
  2484. if (this.options.locations)
  2485. { node.loc.end = loc; }
  2486. if (this.options.ranges)
  2487. { node.range[1] = pos; }
  2488. return node
  2489. }
  2490. pp$6.finishNode = function(node, type) {
  2491. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  2492. };
  2493. // Finish node at given position
  2494. pp$6.finishNodeAt = function(node, type, pos, loc) {
  2495. return finishNodeAt.call(this, node, type, pos, loc)
  2496. };
  2497. // The algorithm used to determine whether a regexp can appear at a
  2498. // given point in the program is loosely based on sweet.js' approach.
  2499. // See https://github.com/mozilla/sweet.js/wiki/design
  2500. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  2501. this.token = token;
  2502. this.isExpr = !!isExpr;
  2503. this.preserveSpace = !!preserveSpace;
  2504. this.override = override;
  2505. this.generator = !!generator;
  2506. };
  2507. var types$1 = {
  2508. b_stat: new TokContext("{", false),
  2509. b_expr: new TokContext("{", true),
  2510. b_tmpl: new TokContext("${", false),
  2511. p_stat: new TokContext("(", false),
  2512. p_expr: new TokContext("(", true),
  2513. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  2514. f_stat: new TokContext("function", false),
  2515. f_expr: new TokContext("function", true),
  2516. f_expr_gen: new TokContext("function", true, false, null, true),
  2517. f_gen: new TokContext("function", false, false, null, true)
  2518. };
  2519. var pp$7 = Parser.prototype;
  2520. pp$7.initialContext = function() {
  2521. return [types$1.b_stat]
  2522. };
  2523. pp$7.braceIsBlock = function(prevType) {
  2524. var parent = this.curContext();
  2525. if (parent === types$1.f_expr || parent === types$1.f_stat)
  2526. { return true }
  2527. if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
  2528. { return !parent.isExpr }
  2529. // The check for `tt.name && exprAllowed` detects whether we are
  2530. // after a `yield` or `of` construct. See the `updateContext` for
  2531. // `tt.name`.
  2532. if (prevType === types._return || prevType === types.name && this.exprAllowed)
  2533. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  2534. if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow)
  2535. { return true }
  2536. if (prevType === types.braceL)
  2537. { return parent === types$1.b_stat }
  2538. if (prevType === types._var || prevType === types.name)
  2539. { return false }
  2540. return !this.exprAllowed
  2541. };
  2542. pp$7.inGeneratorContext = function() {
  2543. var this$1 = this;
  2544. for (var i = this.context.length - 1; i >= 1; i--) {
  2545. var context = this$1.context[i];
  2546. if (context.token === "function")
  2547. { return context.generator }
  2548. }
  2549. return false
  2550. };
  2551. pp$7.updateContext = function(prevType) {
  2552. var update, type = this.type;
  2553. if (type.keyword && prevType === types.dot)
  2554. { this.exprAllowed = false; }
  2555. else if (update = type.updateContext)
  2556. { update.call(this, prevType); }
  2557. else
  2558. { this.exprAllowed = type.beforeExpr; }
  2559. };
  2560. // Token-specific context update code
  2561. types.parenR.updateContext = types.braceR.updateContext = function() {
  2562. if (this.context.length === 1) {
  2563. this.exprAllowed = true;
  2564. return
  2565. }
  2566. var out = this.context.pop();
  2567. if (out === types$1.b_stat && this.curContext().token === "function") {
  2568. out = this.context.pop();
  2569. }
  2570. this.exprAllowed = !out.isExpr;
  2571. };
  2572. types.braceL.updateContext = function(prevType) {
  2573. this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
  2574. this.exprAllowed = true;
  2575. };
  2576. types.dollarBraceL.updateContext = function() {
  2577. this.context.push(types$1.b_tmpl);
  2578. this.exprAllowed = true;
  2579. };
  2580. types.parenL.updateContext = function(prevType) {
  2581. var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
  2582. this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
  2583. this.exprAllowed = true;
  2584. };
  2585. types.incDec.updateContext = function() {
  2586. // tokExprAllowed stays unchanged
  2587. };
  2588. types._function.updateContext = types._class.updateContext = function(prevType) {
  2589. if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
  2590. !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
  2591. { this.context.push(types$1.f_expr); }
  2592. else
  2593. { this.context.push(types$1.f_stat); }
  2594. this.exprAllowed = false;
  2595. };
  2596. types.backQuote.updateContext = function() {
  2597. if (this.curContext() === types$1.q_tmpl)
  2598. { this.context.pop(); }
  2599. else
  2600. { this.context.push(types$1.q_tmpl); }
  2601. this.exprAllowed = false;
  2602. };
  2603. types.star.updateContext = function(prevType) {
  2604. if (prevType === types._function) {
  2605. var index = this.context.length - 1;
  2606. if (this.context[index] === types$1.f_expr)
  2607. { this.context[index] = types$1.f_expr_gen; }
  2608. else
  2609. { this.context[index] = types$1.f_gen; }
  2610. }
  2611. this.exprAllowed = true;
  2612. };
  2613. types.name.updateContext = function(prevType) {
  2614. var allowed = false;
  2615. if (this.options.ecmaVersion >= 6 && prevType !== types.dot) {
  2616. if (this.value === "of" && !this.exprAllowed ||
  2617. this.value === "yield" && this.inGeneratorContext())
  2618. { allowed = true; }
  2619. }
  2620. this.exprAllowed = allowed;
  2621. };
  2622. var data = {
  2623. "$LONE": [
  2624. "ASCII",
  2625. "ASCII_Hex_Digit",
  2626. "AHex",
  2627. "Alphabetic",
  2628. "Alpha",
  2629. "Any",
  2630. "Assigned",
  2631. "Bidi_Control",
  2632. "Bidi_C",
  2633. "Bidi_Mirrored",
  2634. "Bidi_M",
  2635. "Case_Ignorable",
  2636. "CI",
  2637. "Cased",
  2638. "Changes_When_Casefolded",
  2639. "CWCF",
  2640. "Changes_When_Casemapped",
  2641. "CWCM",
  2642. "Changes_When_Lowercased",
  2643. "CWL",
  2644. "Changes_When_NFKC_Casefolded",
  2645. "CWKCF",
  2646. "Changes_When_Titlecased",
  2647. "CWT",
  2648. "Changes_When_Uppercased",
  2649. "CWU",
  2650. "Dash",
  2651. "Default_Ignorable_Code_Point",
  2652. "DI",
  2653. "Deprecated",
  2654. "Dep",
  2655. "Diacritic",
  2656. "Dia",
  2657. "Emoji",
  2658. "Emoji_Component",
  2659. "Emoji_Modifier",
  2660. "Emoji_Modifier_Base",
  2661. "Emoji_Presentation",
  2662. "Extender",
  2663. "Ext",
  2664. "Grapheme_Base",
  2665. "Gr_Base",
  2666. "Grapheme_Extend",
  2667. "Gr_Ext",
  2668. "Hex_Digit",
  2669. "Hex",
  2670. "IDS_Binary_Operator",
  2671. "IDSB",
  2672. "IDS_Trinary_Operator",
  2673. "IDST",
  2674. "ID_Continue",
  2675. "IDC",
  2676. "ID_Start",
  2677. "IDS",
  2678. "Ideographic",
  2679. "Ideo",
  2680. "Join_Control",
  2681. "Join_C",
  2682. "Logical_Order_Exception",
  2683. "LOE",
  2684. "Lowercase",
  2685. "Lower",
  2686. "Math",
  2687. "Noncharacter_Code_Point",
  2688. "NChar",
  2689. "Pattern_Syntax",
  2690. "Pat_Syn",
  2691. "Pattern_White_Space",
  2692. "Pat_WS",
  2693. "Quotation_Mark",
  2694. "QMark",
  2695. "Radical",
  2696. "Regional_Indicator",
  2697. "RI",
  2698. "Sentence_Terminal",
  2699. "STerm",
  2700. "Soft_Dotted",
  2701. "SD",
  2702. "Terminal_Punctuation",
  2703. "Term",
  2704. "Unified_Ideograph",
  2705. "UIdeo",
  2706. "Uppercase",
  2707. "Upper",
  2708. "Variation_Selector",
  2709. "VS",
  2710. "White_Space",
  2711. "space",
  2712. "XID_Continue",
  2713. "XIDC",
  2714. "XID_Start",
  2715. "XIDS"
  2716. ],
  2717. "General_Category": [
  2718. "Cased_Letter",
  2719. "LC",
  2720. "Close_Punctuation",
  2721. "Pe",
  2722. "Connector_Punctuation",
  2723. "Pc",
  2724. "Control",
  2725. "Cc",
  2726. "cntrl",
  2727. "Currency_Symbol",
  2728. "Sc",
  2729. "Dash_Punctuation",
  2730. "Pd",
  2731. "Decimal_Number",
  2732. "Nd",
  2733. "digit",
  2734. "Enclosing_Mark",
  2735. "Me",
  2736. "Final_Punctuation",
  2737. "Pf",
  2738. "Format",
  2739. "Cf",
  2740. "Initial_Punctuation",
  2741. "Pi",
  2742. "Letter",
  2743. "L",
  2744. "Letter_Number",
  2745. "Nl",
  2746. "Line_Separator",
  2747. "Zl",
  2748. "Lowercase_Letter",
  2749. "Ll",
  2750. "Mark",
  2751. "M",
  2752. "Combining_Mark",
  2753. "Math_Symbol",
  2754. "Sm",
  2755. "Modifier_Letter",
  2756. "Lm",
  2757. "Modifier_Symbol",
  2758. "Sk",
  2759. "Nonspacing_Mark",
  2760. "Mn",
  2761. "Number",
  2762. "N",
  2763. "Open_Punctuation",
  2764. "Ps",
  2765. "Other",
  2766. "C",
  2767. "Other_Letter",
  2768. "Lo",
  2769. "Other_Number",
  2770. "No",
  2771. "Other_Punctuation",
  2772. "Po",
  2773. "Other_Symbol",
  2774. "So",
  2775. "Paragraph_Separator",
  2776. "Zp",
  2777. "Private_Use",
  2778. "Co",
  2779. "Punctuation",
  2780. "P",
  2781. "punct",
  2782. "Separator",
  2783. "Z",
  2784. "Space_Separator",
  2785. "Zs",
  2786. "Spacing_Mark",
  2787. "Mc",
  2788. "Surrogate",
  2789. "Cs",
  2790. "Symbol",
  2791. "S",
  2792. "Titlecase_Letter",
  2793. "Lt",
  2794. "Unassigned",
  2795. "Cn",
  2796. "Uppercase_Letter",
  2797. "Lu"
  2798. ],
  2799. "Script": [
  2800. "Adlam",
  2801. "Adlm",
  2802. "Ahom",
  2803. "Anatolian_Hieroglyphs",
  2804. "Hluw",
  2805. "Arabic",
  2806. "Arab",
  2807. "Armenian",
  2808. "Armn",
  2809. "Avestan",
  2810. "Avst",
  2811. "Balinese",
  2812. "Bali",
  2813. "Bamum",
  2814. "Bamu",
  2815. "Bassa_Vah",
  2816. "Bass",
  2817. "Batak",
  2818. "Batk",
  2819. "Bengali",
  2820. "Beng",
  2821. "Bhaiksuki",
  2822. "Bhks",
  2823. "Bopomofo",
  2824. "Bopo",
  2825. "Brahmi",
  2826. "Brah",
  2827. "Braille",
  2828. "Brai",
  2829. "Buginese",
  2830. "Bugi",
  2831. "Buhid",
  2832. "Buhd",
  2833. "Canadian_Aboriginal",
  2834. "Cans",
  2835. "Carian",
  2836. "Cari",
  2837. "Caucasian_Albanian",
  2838. "Aghb",
  2839. "Chakma",
  2840. "Cakm",
  2841. "Cham",
  2842. "Cherokee",
  2843. "Cher",
  2844. "Common",
  2845. "Zyyy",
  2846. "Coptic",
  2847. "Copt",
  2848. "Qaac",
  2849. "Cuneiform",
  2850. "Xsux",
  2851. "Cypriot",
  2852. "Cprt",
  2853. "Cyrillic",
  2854. "Cyrl",
  2855. "Deseret",
  2856. "Dsrt",
  2857. "Devanagari",
  2858. "Deva",
  2859. "Duployan",
  2860. "Dupl",
  2861. "Egyptian_Hieroglyphs",
  2862. "Egyp",
  2863. "Elbasan",
  2864. "Elba",
  2865. "Ethiopic",
  2866. "Ethi",
  2867. "Georgian",
  2868. "Geor",
  2869. "Glagolitic",
  2870. "Glag",
  2871. "Gothic",
  2872. "Goth",
  2873. "Grantha",
  2874. "Gran",
  2875. "Greek",
  2876. "Grek",
  2877. "Gujarati",
  2878. "Gujr",
  2879. "Gurmukhi",
  2880. "Guru",
  2881. "Han",
  2882. "Hani",
  2883. "Hangul",
  2884. "Hang",
  2885. "Hanunoo",
  2886. "Hano",
  2887. "Hatran",
  2888. "Hatr",
  2889. "Hebrew",
  2890. "Hebr",
  2891. "Hiragana",
  2892. "Hira",
  2893. "Imperial_Aramaic",
  2894. "Armi",
  2895. "Inherited",
  2896. "Zinh",
  2897. "Qaai",
  2898. "Inscriptional_Pahlavi",
  2899. "Phli",
  2900. "Inscriptional_Parthian",
  2901. "Prti",
  2902. "Javanese",
  2903. "Java",
  2904. "Kaithi",
  2905. "Kthi",
  2906. "Kannada",
  2907. "Knda",
  2908. "Katakana",
  2909. "Kana",
  2910. "Kayah_Li",
  2911. "Kali",
  2912. "Kharoshthi",
  2913. "Khar",
  2914. "Khmer",
  2915. "Khmr",
  2916. "Khojki",
  2917. "Khoj",
  2918. "Khudawadi",
  2919. "Sind",
  2920. "Lao",
  2921. "Laoo",
  2922. "Latin",
  2923. "Latn",
  2924. "Lepcha",
  2925. "Lepc",
  2926. "Limbu",
  2927. "Limb",
  2928. "Linear_A",
  2929. "Lina",
  2930. "Linear_B",
  2931. "Linb",
  2932. "Lisu",
  2933. "Lycian",
  2934. "Lyci",
  2935. "Lydian",
  2936. "Lydi",
  2937. "Mahajani",
  2938. "Mahj",
  2939. "Malayalam",
  2940. "Mlym",
  2941. "Mandaic",
  2942. "Mand",
  2943. "Manichaean",
  2944. "Mani",
  2945. "Marchen",
  2946. "Marc",
  2947. "Masaram_Gondi",
  2948. "Gonm",
  2949. "Meetei_Mayek",
  2950. "Mtei",
  2951. "Mende_Kikakui",
  2952. "Mend",
  2953. "Meroitic_Cursive",
  2954. "Merc",
  2955. "Meroitic_Hieroglyphs",
  2956. "Mero",
  2957. "Miao",
  2958. "Plrd",
  2959. "Modi",
  2960. "Mongolian",
  2961. "Mong",
  2962. "Mro",
  2963. "Mroo",
  2964. "Multani",
  2965. "Mult",
  2966. "Myanmar",
  2967. "Mymr",
  2968. "Nabataean",
  2969. "Nbat",
  2970. "New_Tai_Lue",
  2971. "Talu",
  2972. "Newa",
  2973. "Nko",
  2974. "Nkoo",
  2975. "Nushu",
  2976. "Nshu",
  2977. "Ogham",
  2978. "Ogam",
  2979. "Ol_Chiki",
  2980. "Olck",
  2981. "Old_Hungarian",
  2982. "Hung",
  2983. "Old_Italic",
  2984. "Ital",
  2985. "Old_North_Arabian",
  2986. "Narb",
  2987. "Old_Permic",
  2988. "Perm",
  2989. "Old_Persian",
  2990. "Xpeo",
  2991. "Old_South_Arabian",
  2992. "Sarb",
  2993. "Old_Turkic",
  2994. "Orkh",
  2995. "Oriya",
  2996. "Orya",
  2997. "Osage",
  2998. "Osge",
  2999. "Osmanya",
  3000. "Osma",
  3001. "Pahawh_Hmong",
  3002. "Hmng",
  3003. "Palmyrene",
  3004. "Palm",
  3005. "Pau_Cin_Hau",
  3006. "Pauc",
  3007. "Phags_Pa",
  3008. "Phag",
  3009. "Phoenician",
  3010. "Phnx",
  3011. "Psalter_Pahlavi",
  3012. "Phlp",
  3013. "Rejang",
  3014. "Rjng",
  3015. "Runic",
  3016. "Runr",
  3017. "Samaritan",
  3018. "Samr",
  3019. "Saurashtra",
  3020. "Saur",
  3021. "Sharada",
  3022. "Shrd",
  3023. "Shavian",
  3024. "Shaw",
  3025. "Siddham",
  3026. "Sidd",
  3027. "SignWriting",
  3028. "Sgnw",
  3029. "Sinhala",
  3030. "Sinh",
  3031. "Sora_Sompeng",
  3032. "Sora",
  3033. "Soyombo",
  3034. "Soyo",
  3035. "Sundanese",
  3036. "Sund",
  3037. "Syloti_Nagri",
  3038. "Sylo",
  3039. "Syriac",
  3040. "Syrc",
  3041. "Tagalog",
  3042. "Tglg",
  3043. "Tagbanwa",
  3044. "Tagb",
  3045. "Tai_Le",
  3046. "Tale",
  3047. "Tai_Tham",
  3048. "Lana",
  3049. "Tai_Viet",
  3050. "Tavt",
  3051. "Takri",
  3052. "Takr",
  3053. "Tamil",
  3054. "Taml",
  3055. "Tangut",
  3056. "Tang",
  3057. "Telugu",
  3058. "Telu",
  3059. "Thaana",
  3060. "Thaa",
  3061. "Thai",
  3062. "Tibetan",
  3063. "Tibt",
  3064. "Tifinagh",
  3065. "Tfng",
  3066. "Tirhuta",
  3067. "Tirh",
  3068. "Ugaritic",
  3069. "Ugar",
  3070. "Vai",
  3071. "Vaii",
  3072. "Warang_Citi",
  3073. "Wara",
  3074. "Yi",
  3075. "Yiii",
  3076. "Zanabazar_Square",
  3077. "Zanb"
  3078. ]
  3079. };
  3080. Array.prototype.push.apply(data.$LONE, data.General_Category);
  3081. data.gc = data.General_Category;
  3082. data.sc = data.Script_Extensions = data.scx = data.Script;
  3083. var pp$9 = Parser.prototype;
  3084. var RegExpValidationState = function RegExpValidationState(parser) {
  3085. this.parser = parser;
  3086. this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
  3087. this.source = "";
  3088. this.flags = "";
  3089. this.start = 0;
  3090. this.switchU = false;
  3091. this.switchN = false;
  3092. this.pos = 0;
  3093. this.lastIntValue = 0;
  3094. this.lastStringValue = "";
  3095. this.lastAssertionIsQuantifiable = false;
  3096. this.numCapturingParens = 0;
  3097. this.maxBackReference = 0;
  3098. this.groupNames = [];
  3099. this.backReferenceNames = [];
  3100. };
  3101. RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
  3102. var unicode = flags.indexOf("u") !== -1;
  3103. this.start = start | 0;
  3104. this.source = pattern + "";
  3105. this.flags = flags;
  3106. this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
  3107. this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
  3108. };
  3109. RegExpValidationState.prototype.raise = function raise (message) {
  3110. this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
  3111. };
  3112. // If u flag is given, this returns the code point at the index (it combines a surrogate pair).
  3113. // Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
  3114. RegExpValidationState.prototype.at = function at (i) {
  3115. var s = this.source;
  3116. var l = s.length;
  3117. if (i >= l) {
  3118. return -1
  3119. }
  3120. var c = s.charCodeAt(i);
  3121. if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  3122. return c
  3123. }
  3124. return (c << 10) + s.charCodeAt(i + 1) - 0x35FDC00
  3125. };
  3126. RegExpValidationState.prototype.nextIndex = function nextIndex (i) {
  3127. var s = this.source;
  3128. var l = s.length;
  3129. if (i >= l) {
  3130. return l
  3131. }
  3132. var c = s.charCodeAt(i);
  3133. if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  3134. return i + 1
  3135. }
  3136. return i + 2
  3137. };
  3138. RegExpValidationState.prototype.current = function current () {
  3139. return this.at(this.pos)
  3140. };
  3141. RegExpValidationState.prototype.lookahead = function lookahead () {
  3142. return this.at(this.nextIndex(this.pos))
  3143. };
  3144. RegExpValidationState.prototype.advance = function advance () {
  3145. this.pos = this.nextIndex(this.pos);
  3146. };
  3147. RegExpValidationState.prototype.eat = function eat (ch) {
  3148. if (this.current() === ch) {
  3149. this.advance();
  3150. return true
  3151. }
  3152. return false
  3153. };
  3154. function codePointToString$1(ch) {
  3155. if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
  3156. ch -= 0x10000;
  3157. return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
  3158. }
  3159. /**
  3160. * Validate the flags part of a given RegExpLiteral.
  3161. *
  3162. * @param {RegExpValidationState} state The state to validate RegExp.
  3163. * @returns {void}
  3164. */
  3165. pp$9.validateRegExpFlags = function(state) {
  3166. var this$1 = this;
  3167. var validFlags = state.validFlags;
  3168. var flags = state.flags;
  3169. for (var i = 0; i < flags.length; i++) {
  3170. var flag = flags.charAt(i);
  3171. if (validFlags.indexOf(flag) === -1) {
  3172. this$1.raise(state.start, "Invalid regular expression flag");
  3173. }
  3174. if (flags.indexOf(flag, i + 1) > -1) {
  3175. this$1.raise(state.start, "Duplicate regular expression flag");
  3176. }
  3177. }
  3178. };
  3179. /**
  3180. * Validate the pattern part of a given RegExpLiteral.
  3181. *
  3182. * @param {RegExpValidationState} state The state to validate RegExp.
  3183. * @returns {void}
  3184. */
  3185. pp$9.validateRegExpPattern = function(state) {
  3186. this.regexp_pattern(state);
  3187. // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
  3188. // parsing contains a |GroupName|, reparse with the goal symbol
  3189. // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
  3190. // exception if _P_ did not conform to the grammar, if any elements of _P_
  3191. // were not matched by the parse, or if any Early Error conditions exist.
  3192. if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
  3193. state.switchN = true;
  3194. this.regexp_pattern(state);
  3195. }
  3196. };
  3197. // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
  3198. pp$9.regexp_pattern = function(state) {
  3199. state.pos = 0;
  3200. state.lastIntValue = 0;
  3201. state.lastStringValue = "";
  3202. state.lastAssertionIsQuantifiable = false;
  3203. state.numCapturingParens = 0;
  3204. state.maxBackReference = 0;
  3205. state.groupNames.length = 0;
  3206. state.backReferenceNames.length = 0;
  3207. this.regexp_disjunction(state);
  3208. if (state.pos !== state.source.length) {
  3209. // Make the same messages as V8.
  3210. if (state.eat(0x29 /* ) */)) {
  3211. state.raise("Unmatched ')'");
  3212. }
  3213. if (state.eat(0x5D /* [ */) || state.eat(0x7D /* } */)) {
  3214. state.raise("Lone quantifier brackets");
  3215. }
  3216. }
  3217. if (state.maxBackReference > state.numCapturingParens) {
  3218. state.raise("Invalid escape");
  3219. }
  3220. for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
  3221. var name = list[i];
  3222. if (state.groupNames.indexOf(name) === -1) {
  3223. state.raise("Invalid named capture referenced");
  3224. }
  3225. }
  3226. };
  3227. // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
  3228. pp$9.regexp_disjunction = function(state) {
  3229. var this$1 = this;
  3230. this.regexp_alternative(state);
  3231. while (state.eat(0x7C /* | */)) {
  3232. this$1.regexp_alternative(state);
  3233. }
  3234. // Make the same message as V8.
  3235. if (this.regexp_eatQuantifier(state, true)) {
  3236. state.raise("Nothing to repeat");
  3237. }
  3238. if (state.eat(0x7B /* { */)) {
  3239. state.raise("Lone quantifier brackets");
  3240. }
  3241. };
  3242. // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
  3243. pp$9.regexp_alternative = function(state) {
  3244. while (state.pos < state.source.length && this.regexp_eatTerm(state))
  3245. { }
  3246. };
  3247. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
  3248. pp$9.regexp_eatTerm = function(state) {
  3249. if (this.regexp_eatAssertion(state)) {
  3250. // Handle `QuantifiableAssertion Quantifier` alternative.
  3251. // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
  3252. // is a QuantifiableAssertion.
  3253. if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
  3254. // Make the same message as V8.
  3255. if (state.switchU) {
  3256. state.raise("Invalid quantifier");
  3257. }
  3258. }
  3259. return true
  3260. }
  3261. if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
  3262. this.regexp_eatQuantifier(state);
  3263. return true
  3264. }
  3265. return false
  3266. };
  3267. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
  3268. pp$9.regexp_eatAssertion = function(state) {
  3269. var start = state.pos;
  3270. state.lastAssertionIsQuantifiable = false;
  3271. // ^, $
  3272. if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
  3273. return true
  3274. }
  3275. // \b \B
  3276. if (state.eat(0x5C /* \ */)) {
  3277. if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
  3278. return true
  3279. }
  3280. state.pos = start;
  3281. }
  3282. // Lookahead / Lookbehind
  3283. if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
  3284. var lookbehind = false;
  3285. if (this.options.ecmaVersion >= 9) {
  3286. lookbehind = state.eat(0x3C /* < */);
  3287. }
  3288. if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
  3289. this.regexp_disjunction(state);
  3290. if (!state.eat(0x29 /* ) */)) {
  3291. state.raise("Unterminated group");
  3292. }
  3293. state.lastAssertionIsQuantifiable = !lookbehind;
  3294. return true
  3295. }
  3296. }
  3297. state.pos = start;
  3298. return false
  3299. };
  3300. // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
  3301. pp$9.regexp_eatQuantifier = function(state, noError) {
  3302. if ( noError === void 0 ) noError = false;
  3303. if (this.regexp_eatQuantifierPrefix(state, noError)) {
  3304. state.eat(0x3F /* ? */);
  3305. return true
  3306. }
  3307. return false
  3308. };
  3309. // https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
  3310. pp$9.regexp_eatQuantifierPrefix = function(state, noError) {
  3311. return (
  3312. state.eat(0x2A /* * */) ||
  3313. state.eat(0x2B /* + */) ||
  3314. state.eat(0x3F /* ? */) ||
  3315. this.regexp_eatBracedQuantifier(state, noError)
  3316. )
  3317. };
  3318. pp$9.regexp_eatBracedQuantifier = function(state, noError) {
  3319. var start = state.pos;
  3320. if (state.eat(0x7B /* { */)) {
  3321. var min = 0, max = -1;
  3322. if (this.regexp_eatDecimalDigits(state)) {
  3323. min = state.lastIntValue;
  3324. if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
  3325. max = state.lastIntValue;
  3326. }
  3327. if (state.eat(0x7D /* } */)) {
  3328. // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
  3329. if (max !== -1 && max < min && !noError) {
  3330. state.raise("numbers out of order in {} quantifier");
  3331. }
  3332. return true
  3333. }
  3334. }
  3335. if (state.switchU && !noError) {
  3336. state.raise("Incomplete quantifier");
  3337. }
  3338. state.pos = start;
  3339. }
  3340. return false
  3341. };
  3342. // https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
  3343. pp$9.regexp_eatAtom = function(state) {
  3344. return (
  3345. this.regexp_eatPatternCharacters(state) ||
  3346. state.eat(0x2E /* . */) ||
  3347. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3348. this.regexp_eatCharacterClass(state) ||
  3349. this.regexp_eatUncapturingGroup(state) ||
  3350. this.regexp_eatCapturingGroup(state)
  3351. )
  3352. };
  3353. pp$9.regexp_eatReverseSolidusAtomEscape = function(state) {
  3354. var start = state.pos;
  3355. if (state.eat(0x5C /* \ */)) {
  3356. if (this.regexp_eatAtomEscape(state)) {
  3357. return true
  3358. }
  3359. state.pos = start;
  3360. }
  3361. return false
  3362. };
  3363. pp$9.regexp_eatUncapturingGroup = function(state) {
  3364. var start = state.pos;
  3365. if (state.eat(0x28 /* ( */)) {
  3366. if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
  3367. this.regexp_disjunction(state);
  3368. if (state.eat(0x29 /* ) */)) {
  3369. return true
  3370. }
  3371. state.raise("Unterminated group");
  3372. }
  3373. state.pos = start;
  3374. }
  3375. return false
  3376. };
  3377. pp$9.regexp_eatCapturingGroup = function(state) {
  3378. if (state.eat(0x28 /* ( */)) {
  3379. if (this.options.ecmaVersion >= 9) {
  3380. this.regexp_groupSpecifier(state);
  3381. } else if (state.current() === 0x3F /* ? */) {
  3382. state.raise("Invalid group");
  3383. }
  3384. this.regexp_disjunction(state);
  3385. if (state.eat(0x29 /* ) */)) {
  3386. state.numCapturingParens += 1;
  3387. return true
  3388. }
  3389. state.raise("Unterminated group");
  3390. }
  3391. return false
  3392. };
  3393. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
  3394. pp$9.regexp_eatExtendedAtom = function(state) {
  3395. return (
  3396. state.eat(0x2E /* . */) ||
  3397. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3398. this.regexp_eatCharacterClass(state) ||
  3399. this.regexp_eatUncapturingGroup(state) ||
  3400. this.regexp_eatCapturingGroup(state) ||
  3401. this.regexp_eatInvalidBracedQuantifier(state) ||
  3402. this.regexp_eatExtendedPatternCharacter(state)
  3403. )
  3404. };
  3405. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
  3406. pp$9.regexp_eatInvalidBracedQuantifier = function(state) {
  3407. if (this.regexp_eatBracedQuantifier(state, true)) {
  3408. state.raise("Nothing to repeat");
  3409. }
  3410. return false
  3411. };
  3412. // https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
  3413. pp$9.regexp_eatSyntaxCharacter = function(state) {
  3414. var ch = state.current();
  3415. if (isSyntaxCharacter(ch)) {
  3416. state.lastIntValue = ch;
  3417. state.advance();
  3418. return true
  3419. }
  3420. return false
  3421. };
  3422. function isSyntaxCharacter(ch) {
  3423. return (
  3424. ch === 0x24 /* $ */ ||
  3425. ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
  3426. ch === 0x2E /* . */ ||
  3427. ch === 0x3F /* ? */ ||
  3428. ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
  3429. ch >= 0x7B /* { */ && ch <= 0x7D /* } */
  3430. )
  3431. }
  3432. // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
  3433. // But eat eager.
  3434. pp$9.regexp_eatPatternCharacters = function(state) {
  3435. var start = state.pos;
  3436. var ch = 0;
  3437. while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
  3438. state.advance();
  3439. }
  3440. return state.pos !== start
  3441. };
  3442. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
  3443. pp$9.regexp_eatExtendedPatternCharacter = function(state) {
  3444. var ch = state.current();
  3445. if (
  3446. ch !== -1 &&
  3447. ch !== 0x24 /* $ */ &&
  3448. !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
  3449. ch !== 0x2E /* . */ &&
  3450. ch !== 0x3F /* ? */ &&
  3451. ch !== 0x5B /* [ */ &&
  3452. ch !== 0x5E /* ^ */ &&
  3453. ch !== 0x7C /* | */
  3454. ) {
  3455. state.advance();
  3456. return true
  3457. }
  3458. return false
  3459. };
  3460. // GroupSpecifier[U] ::
  3461. // [empty]
  3462. // `?` GroupName[?U]
  3463. pp$9.regexp_groupSpecifier = function(state) {
  3464. if (state.eat(0x3F /* ? */)) {
  3465. if (this.regexp_eatGroupName(state)) {
  3466. if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
  3467. state.raise("Duplicate capture group name");
  3468. }
  3469. state.groupNames.push(state.lastStringValue);
  3470. return
  3471. }
  3472. state.raise("Invalid group");
  3473. }
  3474. };
  3475. // GroupName[U] ::
  3476. // `<` RegExpIdentifierName[?U] `>`
  3477. // Note: this updates `state.lastStringValue` property with the eaten name.
  3478. pp$9.regexp_eatGroupName = function(state) {
  3479. state.lastStringValue = "";
  3480. if (state.eat(0x3C /* < */)) {
  3481. if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
  3482. return true
  3483. }
  3484. state.raise("Invalid capture group name");
  3485. }
  3486. return false
  3487. };
  3488. // RegExpIdentifierName[U] ::
  3489. // RegExpIdentifierStart[?U]
  3490. // RegExpIdentifierName[?U] RegExpIdentifierPart[?U]
  3491. // Note: this updates `state.lastStringValue` property with the eaten name.
  3492. pp$9.regexp_eatRegExpIdentifierName = function(state) {
  3493. state.lastStringValue = "";
  3494. if (this.regexp_eatRegExpIdentifierStart(state)) {
  3495. state.lastStringValue += codePointToString$1(state.lastIntValue);
  3496. while (this.regexp_eatRegExpIdentifierPart(state)) {
  3497. state.lastStringValue += codePointToString$1(state.lastIntValue);
  3498. }
  3499. return true
  3500. }
  3501. return false
  3502. };
  3503. // RegExpIdentifierStart[U] ::
  3504. // UnicodeIDStart
  3505. // `$`
  3506. // `_`
  3507. // `\` RegExpUnicodeEscapeSequence[?U]
  3508. pp$9.regexp_eatRegExpIdentifierStart = function(state) {
  3509. var start = state.pos;
  3510. var ch = state.current();
  3511. state.advance();
  3512. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
  3513. ch = state.lastIntValue;
  3514. }
  3515. if (isRegExpIdentifierStart(ch)) {
  3516. state.lastIntValue = ch;
  3517. return true
  3518. }
  3519. state.pos = start;
  3520. return false
  3521. };
  3522. function isRegExpIdentifierStart(ch) {
  3523. return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
  3524. }
  3525. // RegExpIdentifierPart[U] ::
  3526. // UnicodeIDContinue
  3527. // `$`
  3528. // `_`
  3529. // `\` RegExpUnicodeEscapeSequence[?U]
  3530. // <ZWNJ>
  3531. // <ZWJ>
  3532. pp$9.regexp_eatRegExpIdentifierPart = function(state) {
  3533. var start = state.pos;
  3534. var ch = state.current();
  3535. state.advance();
  3536. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
  3537. ch = state.lastIntValue;
  3538. }
  3539. if (isRegExpIdentifierPart(ch)) {
  3540. state.lastIntValue = ch;
  3541. return true
  3542. }
  3543. state.pos = start;
  3544. return false
  3545. };
  3546. function isRegExpIdentifierPart(ch) {
  3547. return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
  3548. }
  3549. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
  3550. pp$9.regexp_eatAtomEscape = function(state) {
  3551. if (
  3552. this.regexp_eatBackReference(state) ||
  3553. this.regexp_eatCharacterClassEscape(state) ||
  3554. this.regexp_eatCharacterEscape(state) ||
  3555. (state.switchN && this.regexp_eatKGroupName(state))
  3556. ) {
  3557. return true
  3558. }
  3559. if (state.switchU) {
  3560. // Make the same message as V8.
  3561. if (state.current() === 0x63 /* c */) {
  3562. state.raise("Invalid unicode escape");
  3563. }
  3564. state.raise("Invalid escape");
  3565. }
  3566. return false
  3567. };
  3568. pp$9.regexp_eatBackReference = function(state) {
  3569. var start = state.pos;
  3570. if (this.regexp_eatDecimalEscape(state)) {
  3571. var n = state.lastIntValue;
  3572. if (state.switchU) {
  3573. // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
  3574. if (n > state.maxBackReference) {
  3575. state.maxBackReference = n;
  3576. }
  3577. return true
  3578. }
  3579. if (n <= state.numCapturingParens) {
  3580. return true
  3581. }
  3582. state.pos = start;
  3583. }
  3584. return false
  3585. };
  3586. pp$9.regexp_eatKGroupName = function(state) {
  3587. if (state.eat(0x6B /* k */)) {
  3588. if (this.regexp_eatGroupName(state)) {
  3589. state.backReferenceNames.push(state.lastStringValue);
  3590. return true
  3591. }
  3592. state.raise("Invalid named reference");
  3593. }
  3594. return false
  3595. };
  3596. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
  3597. pp$9.regexp_eatCharacterEscape = function(state) {
  3598. return (
  3599. this.regexp_eatControlEscape(state) ||
  3600. this.regexp_eatCControlLetter(state) ||
  3601. this.regexp_eatZero(state) ||
  3602. this.regexp_eatHexEscapeSequence(state) ||
  3603. this.regexp_eatRegExpUnicodeEscapeSequence(state) ||
  3604. (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
  3605. this.regexp_eatIdentityEscape(state)
  3606. )
  3607. };
  3608. pp$9.regexp_eatCControlLetter = function(state) {
  3609. var start = state.pos;
  3610. if (state.eat(0x63 /* c */)) {
  3611. if (this.regexp_eatControlLetter(state)) {
  3612. return true
  3613. }
  3614. state.pos = start;
  3615. }
  3616. return false
  3617. };
  3618. pp$9.regexp_eatZero = function(state) {
  3619. if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
  3620. state.lastIntValue = 0;
  3621. state.advance();
  3622. return true
  3623. }
  3624. return false
  3625. };
  3626. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
  3627. pp$9.regexp_eatControlEscape = function(state) {
  3628. var ch = state.current();
  3629. if (ch === 0x74 /* t */) {
  3630. state.lastIntValue = 0x09; /* \t */
  3631. state.advance();
  3632. return true
  3633. }
  3634. if (ch === 0x6E /* n */) {
  3635. state.lastIntValue = 0x0A; /* \n */
  3636. state.advance();
  3637. return true
  3638. }
  3639. if (ch === 0x76 /* v */) {
  3640. state.lastIntValue = 0x0B; /* \v */
  3641. state.advance();
  3642. return true
  3643. }
  3644. if (ch === 0x66 /* f */) {
  3645. state.lastIntValue = 0x0C; /* \f */
  3646. state.advance();
  3647. return true
  3648. }
  3649. if (ch === 0x72 /* r */) {
  3650. state.lastIntValue = 0x0D; /* \r */
  3651. state.advance();
  3652. return true
  3653. }
  3654. return false
  3655. };
  3656. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
  3657. pp$9.regexp_eatControlLetter = function(state) {
  3658. var ch = state.current();
  3659. if (isControlLetter(ch)) {
  3660. state.lastIntValue = ch % 0x20;
  3661. state.advance();
  3662. return true
  3663. }
  3664. return false
  3665. };
  3666. function isControlLetter(ch) {
  3667. return (
  3668. (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
  3669. (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
  3670. )
  3671. }
  3672. // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
  3673. pp$9.regexp_eatRegExpUnicodeEscapeSequence = function(state) {
  3674. var start = state.pos;
  3675. if (state.eat(0x75 /* u */)) {
  3676. if (this.regexp_eatFixedHexDigits(state, 4)) {
  3677. var lead = state.lastIntValue;
  3678. if (state.switchU && lead >= 0xD800 && lead <= 0xDBFF) {
  3679. var leadSurrogateEnd = state.pos;
  3680. if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
  3681. var trail = state.lastIntValue;
  3682. if (trail >= 0xDC00 && trail <= 0xDFFF) {
  3683. state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  3684. return true
  3685. }
  3686. }
  3687. state.pos = leadSurrogateEnd;
  3688. state.lastIntValue = lead;
  3689. }
  3690. return true
  3691. }
  3692. if (
  3693. state.switchU &&
  3694. state.eat(0x7B /* { */) &&
  3695. this.regexp_eatHexDigits(state) &&
  3696. state.eat(0x7D /* } */) &&
  3697. isValidUnicode(state.lastIntValue)
  3698. ) {
  3699. return true
  3700. }
  3701. if (state.switchU) {
  3702. state.raise("Invalid unicode escape");
  3703. }
  3704. state.pos = start;
  3705. }
  3706. return false
  3707. };
  3708. function isValidUnicode(ch) {
  3709. return ch >= 0 && ch <= 0x10FFFF
  3710. }
  3711. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
  3712. pp$9.regexp_eatIdentityEscape = function(state) {
  3713. if (state.switchU) {
  3714. if (this.regexp_eatSyntaxCharacter(state)) {
  3715. return true
  3716. }
  3717. if (state.eat(0x2F /* / */)) {
  3718. state.lastIntValue = 0x2F; /* / */
  3719. return true
  3720. }
  3721. return false
  3722. }
  3723. var ch = state.current();
  3724. if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
  3725. state.lastIntValue = ch;
  3726. state.advance();
  3727. return true
  3728. }
  3729. return false
  3730. };
  3731. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
  3732. pp$9.regexp_eatDecimalEscape = function(state) {
  3733. state.lastIntValue = 0;
  3734. var ch = state.current();
  3735. if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
  3736. do {
  3737. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3738. state.advance();
  3739. } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
  3740. return true
  3741. }
  3742. return false
  3743. };
  3744. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
  3745. pp$9.regexp_eatCharacterClassEscape = function(state) {
  3746. var ch = state.current();
  3747. if (isCharacterClassEscape(ch)) {
  3748. state.lastIntValue = -1;
  3749. state.advance();
  3750. return true
  3751. }
  3752. if (
  3753. state.switchU &&
  3754. this.options.ecmaVersion >= 9 &&
  3755. (ch === 0x50 /* P */ || ch === 0x70 /* p */)
  3756. ) {
  3757. state.lastIntValue = -1;
  3758. state.advance();
  3759. if (
  3760. state.eat(0x7B /* { */) &&
  3761. this.regexp_eatUnicodePropertyValueExpression(state) &&
  3762. state.eat(0x7D /* } */)
  3763. ) {
  3764. return true
  3765. }
  3766. state.raise("Invalid property name");
  3767. }
  3768. return false
  3769. };
  3770. function isCharacterClassEscape(ch) {
  3771. return (
  3772. ch === 0x64 /* d */ ||
  3773. ch === 0x44 /* D */ ||
  3774. ch === 0x73 /* s */ ||
  3775. ch === 0x53 /* S */ ||
  3776. ch === 0x77 /* w */ ||
  3777. ch === 0x57 /* W */
  3778. )
  3779. }
  3780. // UnicodePropertyValueExpression ::
  3781. // UnicodePropertyName `=` UnicodePropertyValue
  3782. // LoneUnicodePropertyNameOrValue
  3783. pp$9.regexp_eatUnicodePropertyValueExpression = function(state) {
  3784. var start = state.pos;
  3785. // UnicodePropertyName `=` UnicodePropertyValue
  3786. if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
  3787. var name = state.lastStringValue;
  3788. if (this.regexp_eatUnicodePropertyValue(state)) {
  3789. var value = state.lastStringValue;
  3790. this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
  3791. return true
  3792. }
  3793. }
  3794. state.pos = start;
  3795. // LoneUnicodePropertyNameOrValue
  3796. if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
  3797. var nameOrValue = state.lastStringValue;
  3798. this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
  3799. return true
  3800. }
  3801. return false
  3802. };
  3803. pp$9.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
  3804. if (!data.hasOwnProperty(name) || data[name].indexOf(value) === -1) {
  3805. state.raise("Invalid property name");
  3806. }
  3807. };
  3808. pp$9.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
  3809. if (data.$LONE.indexOf(nameOrValue) === -1) {
  3810. state.raise("Invalid property name");
  3811. }
  3812. };
  3813. // UnicodePropertyName ::
  3814. // UnicodePropertyNameCharacters
  3815. pp$9.regexp_eatUnicodePropertyName = function(state) {
  3816. var ch = 0;
  3817. state.lastStringValue = "";
  3818. while (isUnicodePropertyNameCharacter(ch = state.current())) {
  3819. state.lastStringValue += codePointToString$1(ch);
  3820. state.advance();
  3821. }
  3822. return state.lastStringValue !== ""
  3823. };
  3824. function isUnicodePropertyNameCharacter(ch) {
  3825. return isControlLetter(ch) || ch === 0x5F /* _ */
  3826. }
  3827. // UnicodePropertyValue ::
  3828. // UnicodePropertyValueCharacters
  3829. pp$9.regexp_eatUnicodePropertyValue = function(state) {
  3830. var ch = 0;
  3831. state.lastStringValue = "";
  3832. while (isUnicodePropertyValueCharacter(ch = state.current())) {
  3833. state.lastStringValue += codePointToString$1(ch);
  3834. state.advance();
  3835. }
  3836. return state.lastStringValue !== ""
  3837. };
  3838. function isUnicodePropertyValueCharacter(ch) {
  3839. return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
  3840. }
  3841. // LoneUnicodePropertyNameOrValue ::
  3842. // UnicodePropertyValueCharacters
  3843. pp$9.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
  3844. return this.regexp_eatUnicodePropertyValue(state)
  3845. };
  3846. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
  3847. pp$9.regexp_eatCharacterClass = function(state) {
  3848. if (state.eat(0x5B /* [ */)) {
  3849. state.eat(0x5E /* ^ */);
  3850. this.regexp_classRanges(state);
  3851. if (state.eat(0x5D /* [ */)) {
  3852. return true
  3853. }
  3854. // Unreachable since it threw "unterminated regular expression" error before.
  3855. state.raise("Unterminated character class");
  3856. }
  3857. return false
  3858. };
  3859. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
  3860. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
  3861. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
  3862. pp$9.regexp_classRanges = function(state) {
  3863. var this$1 = this;
  3864. while (this.regexp_eatClassAtom(state)) {
  3865. var left = state.lastIntValue;
  3866. if (state.eat(0x2D /* - */) && this$1.regexp_eatClassAtom(state)) {
  3867. var right = state.lastIntValue;
  3868. if (state.switchU && (left === -1 || right === -1)) {
  3869. state.raise("Invalid character class");
  3870. }
  3871. if (left !== -1 && right !== -1 && left > right) {
  3872. state.raise("Range out of order in character class");
  3873. }
  3874. }
  3875. }
  3876. };
  3877. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
  3878. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
  3879. pp$9.regexp_eatClassAtom = function(state) {
  3880. var start = state.pos;
  3881. if (state.eat(0x5C /* \ */)) {
  3882. if (this.regexp_eatClassEscape(state)) {
  3883. return true
  3884. }
  3885. if (state.switchU) {
  3886. // Make the same message as V8.
  3887. var ch$1 = state.current();
  3888. if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
  3889. state.raise("Invalid class escape");
  3890. }
  3891. state.raise("Invalid escape");
  3892. }
  3893. state.pos = start;
  3894. }
  3895. var ch = state.current();
  3896. if (ch !== 0x5D /* [ */) {
  3897. state.lastIntValue = ch;
  3898. state.advance();
  3899. return true
  3900. }
  3901. return false
  3902. };
  3903. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
  3904. pp$9.regexp_eatClassEscape = function(state) {
  3905. var start = state.pos;
  3906. if (state.eat(0x62 /* b */)) {
  3907. state.lastIntValue = 0x08; /* <BS> */
  3908. return true
  3909. }
  3910. if (state.switchU && state.eat(0x2D /* - */)) {
  3911. state.lastIntValue = 0x2D; /* - */
  3912. return true
  3913. }
  3914. if (!state.switchU && state.eat(0x63 /* c */)) {
  3915. if (this.regexp_eatClassControlLetter(state)) {
  3916. return true
  3917. }
  3918. state.pos = start;
  3919. }
  3920. return (
  3921. this.regexp_eatCharacterClassEscape(state) ||
  3922. this.regexp_eatCharacterEscape(state)
  3923. )
  3924. };
  3925. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
  3926. pp$9.regexp_eatClassControlLetter = function(state) {
  3927. var ch = state.current();
  3928. if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
  3929. state.lastIntValue = ch % 0x20;
  3930. state.advance();
  3931. return true
  3932. }
  3933. return false
  3934. };
  3935. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  3936. pp$9.regexp_eatHexEscapeSequence = function(state) {
  3937. var start = state.pos;
  3938. if (state.eat(0x78 /* x */)) {
  3939. if (this.regexp_eatFixedHexDigits(state, 2)) {
  3940. return true
  3941. }
  3942. if (state.switchU) {
  3943. state.raise("Invalid escape");
  3944. }
  3945. state.pos = start;
  3946. }
  3947. return false
  3948. };
  3949. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
  3950. pp$9.regexp_eatDecimalDigits = function(state) {
  3951. var start = state.pos;
  3952. var ch = 0;
  3953. state.lastIntValue = 0;
  3954. while (isDecimalDigit(ch = state.current())) {
  3955. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3956. state.advance();
  3957. }
  3958. return state.pos !== start
  3959. };
  3960. function isDecimalDigit(ch) {
  3961. return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
  3962. }
  3963. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
  3964. pp$9.regexp_eatHexDigits = function(state) {
  3965. var start = state.pos;
  3966. var ch = 0;
  3967. state.lastIntValue = 0;
  3968. while (isHexDigit(ch = state.current())) {
  3969. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  3970. state.advance();
  3971. }
  3972. return state.pos !== start
  3973. };
  3974. function isHexDigit(ch) {
  3975. return (
  3976. (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
  3977. (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
  3978. (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
  3979. )
  3980. }
  3981. function hexToInt(ch) {
  3982. if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
  3983. return 10 + (ch - 0x41 /* A */)
  3984. }
  3985. if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
  3986. return 10 + (ch - 0x61 /* a */)
  3987. }
  3988. return ch - 0x30 /* 0 */
  3989. }
  3990. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
  3991. // Allows only 0-377(octal) i.e. 0-255(decimal).
  3992. pp$9.regexp_eatLegacyOctalEscapeSequence = function(state) {
  3993. if (this.regexp_eatOctalDigit(state)) {
  3994. var n1 = state.lastIntValue;
  3995. if (this.regexp_eatOctalDigit(state)) {
  3996. var n2 = state.lastIntValue;
  3997. if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
  3998. state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
  3999. } else {
  4000. state.lastIntValue = n1 * 8 + n2;
  4001. }
  4002. } else {
  4003. state.lastIntValue = n1;
  4004. }
  4005. return true
  4006. }
  4007. return false
  4008. };
  4009. // https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
  4010. pp$9.regexp_eatOctalDigit = function(state) {
  4011. var ch = state.current();
  4012. if (isOctalDigit(ch)) {
  4013. state.lastIntValue = ch - 0x30; /* 0 */
  4014. state.advance();
  4015. return true
  4016. }
  4017. state.lastIntValue = 0;
  4018. return false
  4019. };
  4020. function isOctalDigit(ch) {
  4021. return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
  4022. }
  4023. // https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
  4024. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
  4025. // And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  4026. pp$9.regexp_eatFixedHexDigits = function(state, length) {
  4027. var start = state.pos;
  4028. state.lastIntValue = 0;
  4029. for (var i = 0; i < length; ++i) {
  4030. var ch = state.current();
  4031. if (!isHexDigit(ch)) {
  4032. state.pos = start;
  4033. return false
  4034. }
  4035. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  4036. state.advance();
  4037. }
  4038. return true
  4039. };
  4040. // Object type used to represent tokens. Note that normally, tokens
  4041. // simply exist as properties on the parser object. This is only
  4042. // used for the onToken callback and the external tokenizer.
  4043. var Token = function Token(p) {
  4044. this.type = p.type;
  4045. this.value = p.value;
  4046. this.start = p.start;
  4047. this.end = p.end;
  4048. if (p.options.locations)
  4049. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  4050. if (p.options.ranges)
  4051. { this.range = [p.start, p.end]; }
  4052. };
  4053. // ## Tokenizer
  4054. var pp$8 = Parser.prototype;
  4055. // Move to the next token
  4056. pp$8.next = function() {
  4057. if (this.options.onToken)
  4058. { this.options.onToken(new Token(this)); }
  4059. this.lastTokEnd = this.end;
  4060. this.lastTokStart = this.start;
  4061. this.lastTokEndLoc = this.endLoc;
  4062. this.lastTokStartLoc = this.startLoc;
  4063. this.nextToken();
  4064. };
  4065. pp$8.getToken = function() {
  4066. this.next();
  4067. return new Token(this)
  4068. };
  4069. // If we're in an ES6 environment, make parsers iterable
  4070. if (typeof Symbol !== "undefined")
  4071. { pp$8[Symbol.iterator] = function() {
  4072. var this$1 = this;
  4073. return {
  4074. next: function () {
  4075. var token = this$1.getToken();
  4076. return {
  4077. done: token.type === types.eof,
  4078. value: token
  4079. }
  4080. }
  4081. }
  4082. }; }
  4083. // Toggle strict mode. Re-reads the next number or string to please
  4084. // pedantic tests (`"use strict"; 010;` should fail).
  4085. pp$8.curContext = function() {
  4086. return this.context[this.context.length - 1]
  4087. };
  4088. // Read a single token, updating the parser object's token-related
  4089. // properties.
  4090. pp$8.nextToken = function() {
  4091. var curContext = this.curContext();
  4092. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  4093. this.start = this.pos;
  4094. if (this.options.locations) { this.startLoc = this.curPosition(); }
  4095. if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
  4096. if (curContext.override) { return curContext.override(this) }
  4097. else { this.readToken(this.fullCharCodeAtPos()); }
  4098. };
  4099. pp$8.readToken = function(code) {
  4100. // Identifier or keyword. '\uXXXX' sequences are allowed in
  4101. // identifiers, so '\' also dispatches to that.
  4102. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  4103. { return this.readWord() }
  4104. return this.getTokenFromCode(code)
  4105. };
  4106. pp$8.fullCharCodeAtPos = function() {
  4107. var code = this.input.charCodeAt(this.pos);
  4108. if (code <= 0xd7ff || code >= 0xe000) { return code }
  4109. var next = this.input.charCodeAt(this.pos + 1);
  4110. return (code << 10) + next - 0x35fdc00
  4111. };
  4112. pp$8.skipBlockComment = function() {
  4113. var this$1 = this;
  4114. var startLoc = this.options.onComment && this.curPosition();
  4115. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  4116. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  4117. this.pos = end + 2;
  4118. if (this.options.locations) {
  4119. lineBreakG.lastIndex = start;
  4120. var match;
  4121. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  4122. ++this$1.curLine;
  4123. this$1.lineStart = match.index + match[0].length;
  4124. }
  4125. }
  4126. if (this.options.onComment)
  4127. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  4128. startLoc, this.curPosition()); }
  4129. };
  4130. pp$8.skipLineComment = function(startSkip) {
  4131. var this$1 = this;
  4132. var start = this.pos;
  4133. var startLoc = this.options.onComment && this.curPosition();
  4134. var ch = this.input.charCodeAt(this.pos += startSkip);
  4135. while (this.pos < this.input.length && !isNewLine(ch)) {
  4136. ch = this$1.input.charCodeAt(++this$1.pos);
  4137. }
  4138. if (this.options.onComment)
  4139. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  4140. startLoc, this.curPosition()); }
  4141. };
  4142. // Called at the start of the parse and after every token. Skips
  4143. // whitespace and comments, and.
  4144. pp$8.skipSpace = function() {
  4145. var this$1 = this;
  4146. loop: while (this.pos < this.input.length) {
  4147. var ch = this$1.input.charCodeAt(this$1.pos);
  4148. switch (ch) {
  4149. case 32: case 160: // ' '
  4150. ++this$1.pos;
  4151. break
  4152. case 13:
  4153. if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
  4154. ++this$1.pos;
  4155. }
  4156. case 10: case 8232: case 8233:
  4157. ++this$1.pos;
  4158. if (this$1.options.locations) {
  4159. ++this$1.curLine;
  4160. this$1.lineStart = this$1.pos;
  4161. }
  4162. break
  4163. case 47: // '/'
  4164. switch (this$1.input.charCodeAt(this$1.pos + 1)) {
  4165. case 42: // '*'
  4166. this$1.skipBlockComment();
  4167. break
  4168. case 47:
  4169. this$1.skipLineComment(2);
  4170. break
  4171. default:
  4172. break loop
  4173. }
  4174. break
  4175. default:
  4176. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  4177. ++this$1.pos;
  4178. } else {
  4179. break loop
  4180. }
  4181. }
  4182. }
  4183. };
  4184. // Called at the end of every token. Sets `end`, `val`, and
  4185. // maintains `context` and `exprAllowed`, and skips the space after
  4186. // the token, so that the next one's `start` will point at the
  4187. // right position.
  4188. pp$8.finishToken = function(type, val) {
  4189. this.end = this.pos;
  4190. if (this.options.locations) { this.endLoc = this.curPosition(); }
  4191. var prevType = this.type;
  4192. this.type = type;
  4193. this.value = val;
  4194. this.updateContext(prevType);
  4195. };
  4196. // ### Token reading
  4197. // This is the function that is called to fetch the next token. It
  4198. // is somewhat obscure, because it works in character codes rather
  4199. // than characters, and because operator parsing has been inlined
  4200. // into it.
  4201. //
  4202. // All in the name of speed.
  4203. //
  4204. pp$8.readToken_dot = function() {
  4205. var next = this.input.charCodeAt(this.pos + 1);
  4206. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  4207. var next2 = this.input.charCodeAt(this.pos + 2);
  4208. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  4209. this.pos += 3;
  4210. return this.finishToken(types.ellipsis)
  4211. } else {
  4212. ++this.pos;
  4213. return this.finishToken(types.dot)
  4214. }
  4215. };
  4216. pp$8.readToken_slash = function() { // '/'
  4217. var next = this.input.charCodeAt(this.pos + 1);
  4218. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  4219. if (next === 61) { return this.finishOp(types.assign, 2) }
  4220. return this.finishOp(types.slash, 1)
  4221. };
  4222. pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
  4223. var next = this.input.charCodeAt(this.pos + 1);
  4224. var size = 1;
  4225. var tokentype = code === 42 ? types.star : types.modulo;
  4226. // exponentiation operator ** and **=
  4227. if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
  4228. ++size;
  4229. tokentype = types.starstar;
  4230. next = this.input.charCodeAt(this.pos + 2);
  4231. }
  4232. if (next === 61) { return this.finishOp(types.assign, size + 1) }
  4233. return this.finishOp(tokentype, size)
  4234. };
  4235. pp$8.readToken_pipe_amp = function(code) { // '|&'
  4236. var next = this.input.charCodeAt(this.pos + 1);
  4237. if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
  4238. if (next === 61) { return this.finishOp(types.assign, 2) }
  4239. return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
  4240. };
  4241. pp$8.readToken_caret = function() { // '^'
  4242. var next = this.input.charCodeAt(this.pos + 1);
  4243. if (next === 61) { return this.finishOp(types.assign, 2) }
  4244. return this.finishOp(types.bitwiseXOR, 1)
  4245. };
  4246. pp$8.readToken_plus_min = function(code) { // '+-'
  4247. var next = this.input.charCodeAt(this.pos + 1);
  4248. if (next === code) {
  4249. if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
  4250. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  4251. // A `-->` line comment
  4252. this.skipLineComment(3);
  4253. this.skipSpace();
  4254. return this.nextToken()
  4255. }
  4256. return this.finishOp(types.incDec, 2)
  4257. }
  4258. if (next === 61) { return this.finishOp(types.assign, 2) }
  4259. return this.finishOp(types.plusMin, 1)
  4260. };
  4261. pp$8.readToken_lt_gt = function(code) { // '<>'
  4262. var next = this.input.charCodeAt(this.pos + 1);
  4263. var size = 1;
  4264. if (next === code) {
  4265. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  4266. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
  4267. return this.finishOp(types.bitShift, size)
  4268. }
  4269. if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
  4270. this.input.charCodeAt(this.pos + 3) === 45) {
  4271. // `<!--`, an XML-style comment that should be interpreted as a line comment
  4272. this.skipLineComment(4);
  4273. this.skipSpace();
  4274. return this.nextToken()
  4275. }
  4276. if (next === 61) { size = 2; }
  4277. return this.finishOp(types.relational, size)
  4278. };
  4279. pp$8.readToken_eq_excl = function(code) { // '=!'
  4280. var next = this.input.charCodeAt(this.pos + 1);
  4281. if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  4282. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  4283. this.pos += 2;
  4284. return this.finishToken(types.arrow)
  4285. }
  4286. return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
  4287. };
  4288. pp$8.getTokenFromCode = function(code) {
  4289. switch (code) {
  4290. // The interpretation of a dot depends on whether it is followed
  4291. // by a digit or another two dots.
  4292. case 46: // '.'
  4293. return this.readToken_dot()
  4294. // Punctuation tokens.
  4295. case 40: ++this.pos; return this.finishToken(types.parenL)
  4296. case 41: ++this.pos; return this.finishToken(types.parenR)
  4297. case 59: ++this.pos; return this.finishToken(types.semi)
  4298. case 44: ++this.pos; return this.finishToken(types.comma)
  4299. case 91: ++this.pos; return this.finishToken(types.bracketL)
  4300. case 93: ++this.pos; return this.finishToken(types.bracketR)
  4301. case 123: ++this.pos; return this.finishToken(types.braceL)
  4302. case 125: ++this.pos; return this.finishToken(types.braceR)
  4303. case 58: ++this.pos; return this.finishToken(types.colon)
  4304. case 63: ++this.pos; return this.finishToken(types.question)
  4305. case 96: // '`'
  4306. if (this.options.ecmaVersion < 6) { break }
  4307. ++this.pos;
  4308. return this.finishToken(types.backQuote)
  4309. case 48: // '0'
  4310. var next = this.input.charCodeAt(this.pos + 1);
  4311. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  4312. if (this.options.ecmaVersion >= 6) {
  4313. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  4314. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  4315. }
  4316. // Anything else beginning with a digit is an integer, octal
  4317. // number, or float.
  4318. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  4319. return this.readNumber(false)
  4320. // Quotes produce strings.
  4321. case 34: case 39: // '"', "'"
  4322. return this.readString(code)
  4323. // Operators are parsed inline in tiny state machines. '=' (61) is
  4324. // often referred to. `finishOp` simply skips the amount of
  4325. // characters it is given as second argument, and returns a token
  4326. // of the type given by its first argument.
  4327. case 47: // '/'
  4328. return this.readToken_slash()
  4329. case 37: case 42: // '%*'
  4330. return this.readToken_mult_modulo_exp(code)
  4331. case 124: case 38: // '|&'
  4332. return this.readToken_pipe_amp(code)
  4333. case 94: // '^'
  4334. return this.readToken_caret()
  4335. case 43: case 45: // '+-'
  4336. return this.readToken_plus_min(code)
  4337. case 60: case 62: // '<>'
  4338. return this.readToken_lt_gt(code)
  4339. case 61: case 33: // '=!'
  4340. return this.readToken_eq_excl(code)
  4341. case 126: // '~'
  4342. return this.finishOp(types.prefix, 1)
  4343. }
  4344. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  4345. };
  4346. pp$8.finishOp = function(type, size) {
  4347. var str = this.input.slice(this.pos, this.pos + size);
  4348. this.pos += size;
  4349. return this.finishToken(type, str)
  4350. };
  4351. pp$8.readRegexp = function() {
  4352. var this$1 = this;
  4353. var escaped, inClass, start = this.pos;
  4354. for (;;) {
  4355. if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
  4356. var ch = this$1.input.charAt(this$1.pos);
  4357. if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
  4358. if (!escaped) {
  4359. if (ch === "[") { inClass = true; }
  4360. else if (ch === "]" && inClass) { inClass = false; }
  4361. else if (ch === "/" && !inClass) { break }
  4362. escaped = ch === "\\";
  4363. } else { escaped = false; }
  4364. ++this$1.pos;
  4365. }
  4366. var pattern = this.input.slice(start, this.pos);
  4367. ++this.pos;
  4368. var flagsStart = this.pos;
  4369. var flags = this.readWord1();
  4370. if (this.containsEsc) { this.unexpected(flagsStart); }
  4371. // Validate pattern
  4372. var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
  4373. state.reset(start, pattern, flags);
  4374. this.validateRegExpFlags(state);
  4375. this.validateRegExpPattern(state);
  4376. // Create Literal#value property value.
  4377. var value = null;
  4378. try {
  4379. value = new RegExp(pattern, flags);
  4380. } catch (e) {
  4381. // ESTree requires null if it failed to instantiate RegExp object.
  4382. // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
  4383. }
  4384. return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
  4385. };
  4386. // Read an integer in the given radix. Return null if zero digits
  4387. // were read, the integer value otherwise. When `len` is given, this
  4388. // will return `null` unless the integer has exactly `len` digits.
  4389. pp$8.readInt = function(radix, len) {
  4390. var this$1 = this;
  4391. var start = this.pos, total = 0;
  4392. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  4393. var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
  4394. if (code >= 97) { val = code - 97 + 10; } // a
  4395. else if (code >= 65) { val = code - 65 + 10; } // A
  4396. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  4397. else { val = Infinity; }
  4398. if (val >= radix) { break }
  4399. ++this$1.pos;
  4400. total = total * radix + val;
  4401. }
  4402. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  4403. return total
  4404. };
  4405. pp$8.readRadixNumber = function(radix) {
  4406. this.pos += 2; // 0x
  4407. var val = this.readInt(radix);
  4408. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  4409. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4410. return this.finishToken(types.num, val)
  4411. };
  4412. // Read an integer, octal integer, or floating-point number.
  4413. pp$8.readNumber = function(startsWithDot) {
  4414. var start = this.pos;
  4415. if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4416. var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  4417. if (octal && this.strict) { this.raise(start, "Invalid number"); }
  4418. if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
  4419. var next = this.input.charCodeAt(this.pos);
  4420. if (next === 46 && !octal) { // '.'
  4421. ++this.pos;
  4422. this.readInt(10);
  4423. next = this.input.charCodeAt(this.pos);
  4424. }
  4425. if ((next === 69 || next === 101) && !octal) { // 'eE'
  4426. next = this.input.charCodeAt(++this.pos);
  4427. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  4428. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4429. }
  4430. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4431. var str = this.input.slice(start, this.pos);
  4432. var val = octal ? parseInt(str, 8) : parseFloat(str);
  4433. return this.finishToken(types.num, val)
  4434. };
  4435. // Read a string value, interpreting backslash-escapes.
  4436. pp$8.readCodePoint = function() {
  4437. var ch = this.input.charCodeAt(this.pos), code;
  4438. if (ch === 123) { // '{'
  4439. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  4440. var codePos = ++this.pos;
  4441. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  4442. ++this.pos;
  4443. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  4444. } else {
  4445. code = this.readHexChar(4);
  4446. }
  4447. return code
  4448. };
  4449. function codePointToString(code) {
  4450. // UTF-16 Decoding
  4451. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  4452. code -= 0x10000;
  4453. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  4454. }
  4455. pp$8.readString = function(quote) {
  4456. var this$1 = this;
  4457. var out = "", chunkStart = ++this.pos;
  4458. for (;;) {
  4459. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
  4460. var ch = this$1.input.charCodeAt(this$1.pos);
  4461. if (ch === quote) { break }
  4462. if (ch === 92) { // '\'
  4463. out += this$1.input.slice(chunkStart, this$1.pos);
  4464. out += this$1.readEscapedChar(false);
  4465. chunkStart = this$1.pos;
  4466. } else {
  4467. if (isNewLine(ch, this$1.options.ecmaVersion >= 10)) { this$1.raise(this$1.start, "Unterminated string constant"); }
  4468. ++this$1.pos;
  4469. }
  4470. }
  4471. out += this.input.slice(chunkStart, this.pos++);
  4472. return this.finishToken(types.string, out)
  4473. };
  4474. // Reads template string tokens.
  4475. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  4476. pp$8.tryReadTemplateToken = function() {
  4477. this.inTemplateElement = true;
  4478. try {
  4479. this.readTmplToken();
  4480. } catch (err) {
  4481. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  4482. this.readInvalidTemplateToken();
  4483. } else {
  4484. throw err
  4485. }
  4486. }
  4487. this.inTemplateElement = false;
  4488. };
  4489. pp$8.invalidStringToken = function(position, message) {
  4490. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  4491. throw INVALID_TEMPLATE_ESCAPE_ERROR
  4492. } else {
  4493. this.raise(position, message);
  4494. }
  4495. };
  4496. pp$8.readTmplToken = function() {
  4497. var this$1 = this;
  4498. var out = "", chunkStart = this.pos;
  4499. for (;;) {
  4500. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
  4501. var ch = this$1.input.charCodeAt(this$1.pos);
  4502. if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
  4503. if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
  4504. if (ch === 36) {
  4505. this$1.pos += 2;
  4506. return this$1.finishToken(types.dollarBraceL)
  4507. } else {
  4508. ++this$1.pos;
  4509. return this$1.finishToken(types.backQuote)
  4510. }
  4511. }
  4512. out += this$1.input.slice(chunkStart, this$1.pos);
  4513. return this$1.finishToken(types.template, out)
  4514. }
  4515. if (ch === 92) { // '\'
  4516. out += this$1.input.slice(chunkStart, this$1.pos);
  4517. out += this$1.readEscapedChar(true);
  4518. chunkStart = this$1.pos;
  4519. } else if (isNewLine(ch)) {
  4520. out += this$1.input.slice(chunkStart, this$1.pos);
  4521. ++this$1.pos;
  4522. switch (ch) {
  4523. case 13:
  4524. if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
  4525. case 10:
  4526. out += "\n";
  4527. break
  4528. default:
  4529. out += String.fromCharCode(ch);
  4530. break
  4531. }
  4532. if (this$1.options.locations) {
  4533. ++this$1.curLine;
  4534. this$1.lineStart = this$1.pos;
  4535. }
  4536. chunkStart = this$1.pos;
  4537. } else {
  4538. ++this$1.pos;
  4539. }
  4540. }
  4541. };
  4542. // Reads a template token to search for the end, without validating any escape sequences
  4543. pp$8.readInvalidTemplateToken = function() {
  4544. var this$1 = this;
  4545. for (; this.pos < this.input.length; this.pos++) {
  4546. switch (this$1.input[this$1.pos]) {
  4547. case "\\":
  4548. ++this$1.pos;
  4549. break
  4550. case "$":
  4551. if (this$1.input[this$1.pos + 1] !== "{") {
  4552. break
  4553. }
  4554. // falls through
  4555. case "`":
  4556. return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
  4557. // no default
  4558. }
  4559. }
  4560. this.raise(this.start, "Unterminated template");
  4561. };
  4562. // Used to read escaped characters
  4563. pp$8.readEscapedChar = function(inTemplate) {
  4564. var ch = this.input.charCodeAt(++this.pos);
  4565. ++this.pos;
  4566. switch (ch) {
  4567. case 110: return "\n" // 'n' -> '\n'
  4568. case 114: return "\r" // 'r' -> '\r'
  4569. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  4570. case 117: return codePointToString(this.readCodePoint()) // 'u'
  4571. case 116: return "\t" // 't' -> '\t'
  4572. case 98: return "\b" // 'b' -> '\b'
  4573. case 118: return "\u000b" // 'v' -> '\u000b'
  4574. case 102: return "\f" // 'f' -> '\f'
  4575. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  4576. case 10: // ' \n'
  4577. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  4578. return ""
  4579. default:
  4580. if (ch >= 48 && ch <= 55) {
  4581. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  4582. var octal = parseInt(octalStr, 8);
  4583. if (octal > 255) {
  4584. octalStr = octalStr.slice(0, -1);
  4585. octal = parseInt(octalStr, 8);
  4586. }
  4587. this.pos += octalStr.length - 1;
  4588. ch = this.input.charCodeAt(this.pos);
  4589. if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
  4590. this.invalidStringToken(
  4591. this.pos - 1 - octalStr.length,
  4592. inTemplate
  4593. ? "Octal literal in template string"
  4594. : "Octal literal in strict mode"
  4595. );
  4596. }
  4597. return String.fromCharCode(octal)
  4598. }
  4599. return String.fromCharCode(ch)
  4600. }
  4601. };
  4602. // Used to read character escape sequences ('\x', '\u', '\U').
  4603. pp$8.readHexChar = function(len) {
  4604. var codePos = this.pos;
  4605. var n = this.readInt(16, len);
  4606. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  4607. return n
  4608. };
  4609. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  4610. // to whether the word contained a '\u' escape.
  4611. //
  4612. // Incrementally adds only escaped chars, adding other chunks as-is
  4613. // as a micro-optimization.
  4614. pp$8.readWord1 = function() {
  4615. var this$1 = this;
  4616. this.containsEsc = false;
  4617. var word = "", first = true, chunkStart = this.pos;
  4618. var astral = this.options.ecmaVersion >= 6;
  4619. while (this.pos < this.input.length) {
  4620. var ch = this$1.fullCharCodeAtPos();
  4621. if (isIdentifierChar(ch, astral)) {
  4622. this$1.pos += ch <= 0xffff ? 1 : 2;
  4623. } else if (ch === 92) { // "\"
  4624. this$1.containsEsc = true;
  4625. word += this$1.input.slice(chunkStart, this$1.pos);
  4626. var escStart = this$1.pos;
  4627. if (this$1.input.charCodeAt(++this$1.pos) !== 117) // "u"
  4628. { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  4629. ++this$1.pos;
  4630. var esc = this$1.readCodePoint();
  4631. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  4632. { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
  4633. word += codePointToString(esc);
  4634. chunkStart = this$1.pos;
  4635. } else {
  4636. break
  4637. }
  4638. first = false;
  4639. }
  4640. return word + this.input.slice(chunkStart, this.pos)
  4641. };
  4642. // Read an identifier or keyword token. Will check for reserved
  4643. // words when necessary.
  4644. pp$8.readWord = function() {
  4645. var word = this.readWord1();
  4646. var type = types.name;
  4647. if (this.keywords.test(word)) {
  4648. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
  4649. type = keywords$1[word];
  4650. }
  4651. return this.finishToken(type, word)
  4652. };
  4653. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  4654. //
  4655. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  4656. // various contributors and released under an MIT license.
  4657. //
  4658. // Git repositories for Acorn are available at
  4659. //
  4660. // http://marijnhaverbeke.nl/git/acorn
  4661. // https://github.com/acornjs/acorn.git
  4662. //
  4663. // Please use the [github bug tracker][ghbt] to report issues.
  4664. //
  4665. // [ghbt]: https://github.com/acornjs/acorn/issues
  4666. //
  4667. // This file defines the main parser interface. The library also comes
  4668. // with a [error-tolerant parser][dammit] and an
  4669. // [abstract syntax tree walker][walk], defined in other files.
  4670. //
  4671. // [dammit]: acorn_loose.js
  4672. // [walk]: util/walk.js
  4673. var version = "5.7.3";
  4674. // The main exported interface (under `self.acorn` when in the
  4675. // browser) is a `parse` function that takes a code string and
  4676. // returns an abstract syntax tree as specified by [Mozilla parser
  4677. // API][api].
  4678. //
  4679. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  4680. function parse(input, options) {
  4681. return new Parser(options, input).parse()
  4682. }
  4683. // This function tries to parse a single expression at a given
  4684. // offset in a string. Useful for parsing mixed-language formats
  4685. // that embed JavaScript expressions.
  4686. function parseExpressionAt(input, pos, options) {
  4687. var p = new Parser(options, input, pos);
  4688. p.nextToken();
  4689. return p.parseExpression()
  4690. }
  4691. // Acorn is organized as a tokenizer and a recursive-descent parser.
  4692. // The `tokenizer` export provides an interface to the tokenizer.
  4693. function tokenizer(input, options) {
  4694. return new Parser(options, input)
  4695. }
  4696. // This is a terrible kludge to support the existing, pre-ES6
  4697. // interface where the loose parser module retroactively adds exports
  4698. // to this module.
  4699. var parse_dammit;
  4700. var LooseParser;
  4701. var pluginsLoose; // eslint-disable-line camelcase
  4702. function addLooseExports(parse, Parser$$1, plugins$$1) {
  4703. parse_dammit = parse; // eslint-disable-line camelcase
  4704. LooseParser = Parser$$1;
  4705. pluginsLoose = plugins$$1;
  4706. }
  4707. var acorn = Object.freeze({
  4708. version: version,
  4709. parse: parse,
  4710. parseExpressionAt: parseExpressionAt,
  4711. tokenizer: tokenizer,
  4712. get parse_dammit () { return parse_dammit; },
  4713. get LooseParser () { return LooseParser; },
  4714. get pluginsLoose () { return pluginsLoose; },
  4715. addLooseExports: addLooseExports,
  4716. Parser: Parser,
  4717. plugins: plugins,
  4718. defaultOptions: defaultOptions,
  4719. Position: Position,
  4720. SourceLocation: SourceLocation,
  4721. getLineInfo: getLineInfo,
  4722. Node: Node,
  4723. TokenType: TokenType,
  4724. tokTypes: types,
  4725. keywordTypes: keywords$1,
  4726. TokContext: TokContext,
  4727. tokContexts: types$1,
  4728. isIdentifierChar: isIdentifierChar,
  4729. isIdentifierStart: isIdentifierStart,
  4730. Token: Token,
  4731. isNewLine: isNewLine,
  4732. lineBreak: lineBreak,
  4733. lineBreakG: lineBreakG,
  4734. nonASCIIwhitespace: nonASCIIwhitespace
  4735. });
  4736. var xhtml = {
  4737. quot: '\u0022',
  4738. amp: '&',
  4739. apos: '\u0027',
  4740. lt: '<',
  4741. gt: '>',
  4742. nbsp: '\u00A0',
  4743. iexcl: '\u00A1',
  4744. cent: '\u00A2',
  4745. pound: '\u00A3',
  4746. curren: '\u00A4',
  4747. yen: '\u00A5',
  4748. brvbar: '\u00A6',
  4749. sect: '\u00A7',
  4750. uml: '\u00A8',
  4751. copy: '\u00A9',
  4752. ordf: '\u00AA',
  4753. laquo: '\u00AB',
  4754. not: '\u00AC',
  4755. shy: '\u00AD',
  4756. reg: '\u00AE',
  4757. macr: '\u00AF',
  4758. deg: '\u00B0',
  4759. plusmn: '\u00B1',
  4760. sup2: '\u00B2',
  4761. sup3: '\u00B3',
  4762. acute: '\u00B4',
  4763. micro: '\u00B5',
  4764. para: '\u00B6',
  4765. middot: '\u00B7',
  4766. cedil: '\u00B8',
  4767. sup1: '\u00B9',
  4768. ordm: '\u00BA',
  4769. raquo: '\u00BB',
  4770. frac14: '\u00BC',
  4771. frac12: '\u00BD',
  4772. frac34: '\u00BE',
  4773. iquest: '\u00BF',
  4774. Agrave: '\u00C0',
  4775. Aacute: '\u00C1',
  4776. Acirc: '\u00C2',
  4777. Atilde: '\u00C3',
  4778. Auml: '\u00C4',
  4779. Aring: '\u00C5',
  4780. AElig: '\u00C6',
  4781. Ccedil: '\u00C7',
  4782. Egrave: '\u00C8',
  4783. Eacute: '\u00C9',
  4784. Ecirc: '\u00CA',
  4785. Euml: '\u00CB',
  4786. Igrave: '\u00CC',
  4787. Iacute: '\u00CD',
  4788. Icirc: '\u00CE',
  4789. Iuml: '\u00CF',
  4790. ETH: '\u00D0',
  4791. Ntilde: '\u00D1',
  4792. Ograve: '\u00D2',
  4793. Oacute: '\u00D3',
  4794. Ocirc: '\u00D4',
  4795. Otilde: '\u00D5',
  4796. Ouml: '\u00D6',
  4797. times: '\u00D7',
  4798. Oslash: '\u00D8',
  4799. Ugrave: '\u00D9',
  4800. Uacute: '\u00DA',
  4801. Ucirc: '\u00DB',
  4802. Uuml: '\u00DC',
  4803. Yacute: '\u00DD',
  4804. THORN: '\u00DE',
  4805. szlig: '\u00DF',
  4806. agrave: '\u00E0',
  4807. aacute: '\u00E1',
  4808. acirc: '\u00E2',
  4809. atilde: '\u00E3',
  4810. auml: '\u00E4',
  4811. aring: '\u00E5',
  4812. aelig: '\u00E6',
  4813. ccedil: '\u00E7',
  4814. egrave: '\u00E8',
  4815. eacute: '\u00E9',
  4816. ecirc: '\u00EA',
  4817. euml: '\u00EB',
  4818. igrave: '\u00EC',
  4819. iacute: '\u00ED',
  4820. icirc: '\u00EE',
  4821. iuml: '\u00EF',
  4822. eth: '\u00F0',
  4823. ntilde: '\u00F1',
  4824. ograve: '\u00F2',
  4825. oacute: '\u00F3',
  4826. ocirc: '\u00F4',
  4827. otilde: '\u00F5',
  4828. ouml: '\u00F6',
  4829. divide: '\u00F7',
  4830. oslash: '\u00F8',
  4831. ugrave: '\u00F9',
  4832. uacute: '\u00FA',
  4833. ucirc: '\u00FB',
  4834. uuml: '\u00FC',
  4835. yacute: '\u00FD',
  4836. thorn: '\u00FE',
  4837. yuml: '\u00FF',
  4838. OElig: '\u0152',
  4839. oelig: '\u0153',
  4840. Scaron: '\u0160',
  4841. scaron: '\u0161',
  4842. Yuml: '\u0178',
  4843. fnof: '\u0192',
  4844. circ: '\u02C6',
  4845. tilde: '\u02DC',
  4846. Alpha: '\u0391',
  4847. Beta: '\u0392',
  4848. Gamma: '\u0393',
  4849. Delta: '\u0394',
  4850. Epsilon: '\u0395',
  4851. Zeta: '\u0396',
  4852. Eta: '\u0397',
  4853. Theta: '\u0398',
  4854. Iota: '\u0399',
  4855. Kappa: '\u039A',
  4856. Lambda: '\u039B',
  4857. Mu: '\u039C',
  4858. Nu: '\u039D',
  4859. Xi: '\u039E',
  4860. Omicron: '\u039F',
  4861. Pi: '\u03A0',
  4862. Rho: '\u03A1',
  4863. Sigma: '\u03A3',
  4864. Tau: '\u03A4',
  4865. Upsilon: '\u03A5',
  4866. Phi: '\u03A6',
  4867. Chi: '\u03A7',
  4868. Psi: '\u03A8',
  4869. Omega: '\u03A9',
  4870. alpha: '\u03B1',
  4871. beta: '\u03B2',
  4872. gamma: '\u03B3',
  4873. delta: '\u03B4',
  4874. epsilon: '\u03B5',
  4875. zeta: '\u03B6',
  4876. eta: '\u03B7',
  4877. theta: '\u03B8',
  4878. iota: '\u03B9',
  4879. kappa: '\u03BA',
  4880. lambda: '\u03BB',
  4881. mu: '\u03BC',
  4882. nu: '\u03BD',
  4883. xi: '\u03BE',
  4884. omicron: '\u03BF',
  4885. pi: '\u03C0',
  4886. rho: '\u03C1',
  4887. sigmaf: '\u03C2',
  4888. sigma: '\u03C3',
  4889. tau: '\u03C4',
  4890. upsilon: '\u03C5',
  4891. phi: '\u03C6',
  4892. chi: '\u03C7',
  4893. psi: '\u03C8',
  4894. omega: '\u03C9',
  4895. thetasym: '\u03D1',
  4896. upsih: '\u03D2',
  4897. piv: '\u03D6',
  4898. ensp: '\u2002',
  4899. emsp: '\u2003',
  4900. thinsp: '\u2009',
  4901. zwnj: '\u200C',
  4902. zwj: '\u200D',
  4903. lrm: '\u200E',
  4904. rlm: '\u200F',
  4905. ndash: '\u2013',
  4906. mdash: '\u2014',
  4907. lsquo: '\u2018',
  4908. rsquo: '\u2019',
  4909. sbquo: '\u201A',
  4910. ldquo: '\u201C',
  4911. rdquo: '\u201D',
  4912. bdquo: '\u201E',
  4913. dagger: '\u2020',
  4914. Dagger: '\u2021',
  4915. bull: '\u2022',
  4916. hellip: '\u2026',
  4917. permil: '\u2030',
  4918. prime: '\u2032',
  4919. Prime: '\u2033',
  4920. lsaquo: '\u2039',
  4921. rsaquo: '\u203A',
  4922. oline: '\u203E',
  4923. frasl: '\u2044',
  4924. euro: '\u20AC',
  4925. image: '\u2111',
  4926. weierp: '\u2118',
  4927. real: '\u211C',
  4928. trade: '\u2122',
  4929. alefsym: '\u2135',
  4930. larr: '\u2190',
  4931. uarr: '\u2191',
  4932. rarr: '\u2192',
  4933. darr: '\u2193',
  4934. harr: '\u2194',
  4935. crarr: '\u21B5',
  4936. lArr: '\u21D0',
  4937. uArr: '\u21D1',
  4938. rArr: '\u21D2',
  4939. dArr: '\u21D3',
  4940. hArr: '\u21D4',
  4941. forall: '\u2200',
  4942. part: '\u2202',
  4943. exist: '\u2203',
  4944. empty: '\u2205',
  4945. nabla: '\u2207',
  4946. isin: '\u2208',
  4947. notin: '\u2209',
  4948. ni: '\u220B',
  4949. prod: '\u220F',
  4950. sum: '\u2211',
  4951. minus: '\u2212',
  4952. lowast: '\u2217',
  4953. radic: '\u221A',
  4954. prop: '\u221D',
  4955. infin: '\u221E',
  4956. ang: '\u2220',
  4957. and: '\u2227',
  4958. or: '\u2228',
  4959. cap: '\u2229',
  4960. cup: '\u222A',
  4961. 'int': '\u222B',
  4962. there4: '\u2234',
  4963. sim: '\u223C',
  4964. cong: '\u2245',
  4965. asymp: '\u2248',
  4966. ne: '\u2260',
  4967. equiv: '\u2261',
  4968. le: '\u2264',
  4969. ge: '\u2265',
  4970. sub: '\u2282',
  4971. sup: '\u2283',
  4972. nsub: '\u2284',
  4973. sube: '\u2286',
  4974. supe: '\u2287',
  4975. oplus: '\u2295',
  4976. otimes: '\u2297',
  4977. perp: '\u22A5',
  4978. sdot: '\u22C5',
  4979. lceil: '\u2308',
  4980. rceil: '\u2309',
  4981. lfloor: '\u230A',
  4982. rfloor: '\u230B',
  4983. lang: '\u2329',
  4984. rang: '\u232A',
  4985. loz: '\u25CA',
  4986. spades: '\u2660',
  4987. clubs: '\u2663',
  4988. hearts: '\u2665',
  4989. diams: '\u2666'
  4990. };
  4991. var hexNumber = /^[\da-fA-F]+$/;
  4992. var decimalNumber = /^\d+$/;
  4993. var inject = function(acorn) {
  4994. var tt = acorn.tokTypes;
  4995. var tc = acorn.tokContexts;
  4996. tc.j_oTag = new acorn.TokContext('<tag', false);
  4997. tc.j_cTag = new acorn.TokContext('</tag', false);
  4998. tc.j_expr = new acorn.TokContext('<tag>...</tag>', true, true);
  4999. tt.jsxName = new acorn.TokenType('jsxName');
  5000. tt.jsxText = new acorn.TokenType('jsxText', {beforeExpr: true});
  5001. tt.jsxTagStart = new acorn.TokenType('jsxTagStart');
  5002. tt.jsxTagEnd = new acorn.TokenType('jsxTagEnd');
  5003. tt.jsxTagStart.updateContext = function() {
  5004. this.context.push(tc.j_expr); // treat as beginning of JSX expression
  5005. this.context.push(tc.j_oTag); // start opening tag context
  5006. this.exprAllowed = false;
  5007. };
  5008. tt.jsxTagEnd.updateContext = function(prevType) {
  5009. var out = this.context.pop();
  5010. if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) {
  5011. this.context.pop();
  5012. this.exprAllowed = this.curContext() === tc.j_expr;
  5013. } else {
  5014. this.exprAllowed = true;
  5015. }
  5016. };
  5017. var pp = acorn.Parser.prototype;
  5018. // Reads inline JSX contents token.
  5019. pp.jsx_readToken = function() {
  5020. var out = '', chunkStart = this.pos;
  5021. for (;;) {
  5022. if (this.pos >= this.input.length)
  5023. this.raise(this.start, 'Unterminated JSX contents');
  5024. var ch = this.input.charCodeAt(this.pos);
  5025. switch (ch) {
  5026. case 60: // '<'
  5027. case 123: // '{'
  5028. if (this.pos === this.start) {
  5029. if (ch === 60 && this.exprAllowed) {
  5030. ++this.pos;
  5031. return this.finishToken(tt.jsxTagStart);
  5032. }
  5033. return this.getTokenFromCode(ch);
  5034. }
  5035. out += this.input.slice(chunkStart, this.pos);
  5036. return this.finishToken(tt.jsxText, out);
  5037. case 38: // '&'
  5038. out += this.input.slice(chunkStart, this.pos);
  5039. out += this.jsx_readEntity();
  5040. chunkStart = this.pos;
  5041. break;
  5042. default:
  5043. if (acorn.isNewLine(ch)) {
  5044. out += this.input.slice(chunkStart, this.pos);
  5045. out += this.jsx_readNewLine(true);
  5046. chunkStart = this.pos;
  5047. } else {
  5048. ++this.pos;
  5049. }
  5050. }
  5051. }
  5052. };
  5053. pp.jsx_readNewLine = function(normalizeCRLF) {
  5054. var ch = this.input.charCodeAt(this.pos);
  5055. var out;
  5056. ++this.pos;
  5057. if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
  5058. ++this.pos;
  5059. out = normalizeCRLF ? '\n' : '\r\n';
  5060. } else {
  5061. out = String.fromCharCode(ch);
  5062. }
  5063. if (this.options.locations) {
  5064. ++this.curLine;
  5065. this.lineStart = this.pos;
  5066. }
  5067. return out;
  5068. };
  5069. pp.jsx_readString = function(quote) {
  5070. var out = '', chunkStart = ++this.pos;
  5071. for (;;) {
  5072. if (this.pos >= this.input.length)
  5073. this.raise(this.start, 'Unterminated string constant');
  5074. var ch = this.input.charCodeAt(this.pos);
  5075. if (ch === quote) break;
  5076. if (ch === 38) { // '&'
  5077. out += this.input.slice(chunkStart, this.pos);
  5078. out += this.jsx_readEntity();
  5079. chunkStart = this.pos;
  5080. } else if (acorn.isNewLine(ch)) {
  5081. out += this.input.slice(chunkStart, this.pos);
  5082. out += this.jsx_readNewLine(false);
  5083. chunkStart = this.pos;
  5084. } else {
  5085. ++this.pos;
  5086. }
  5087. }
  5088. out += this.input.slice(chunkStart, this.pos++);
  5089. return this.finishToken(tt.string, out);
  5090. };
  5091. pp.jsx_readEntity = function() {
  5092. var str = '', count = 0, entity;
  5093. var ch = this.input[this.pos];
  5094. if (ch !== '&')
  5095. this.raise(this.pos, 'Entity must start with an ampersand');
  5096. var startPos = ++this.pos;
  5097. while (this.pos < this.input.length && count++ < 10) {
  5098. ch = this.input[this.pos++];
  5099. if (ch === ';') {
  5100. if (str[0] === '#') {
  5101. if (str[1] === 'x') {
  5102. str = str.substr(2);
  5103. if (hexNumber.test(str))
  5104. entity = String.fromCharCode(parseInt(str, 16));
  5105. } else {
  5106. str = str.substr(1);
  5107. if (decimalNumber.test(str))
  5108. entity = String.fromCharCode(parseInt(str, 10));
  5109. }
  5110. } else {
  5111. entity = xhtml[str];
  5112. }
  5113. break;
  5114. }
  5115. str += ch;
  5116. }
  5117. if (!entity) {
  5118. this.pos = startPos;
  5119. return '&';
  5120. }
  5121. return entity;
  5122. };
  5123. // Read a JSX identifier (valid tag or attribute name).
  5124. //
  5125. // Optimized version since JSX identifiers can't contain
  5126. // escape characters and so can be read as single slice.
  5127. // Also assumes that first character was already checked
  5128. // by isIdentifierStart in readToken.
  5129. pp.jsx_readWord = function() {
  5130. var ch, start = this.pos;
  5131. do {
  5132. ch = this.input.charCodeAt(++this.pos);
  5133. } while (acorn.isIdentifierChar(ch) || ch === 45); // '-'
  5134. return this.finishToken(tt.jsxName, this.input.slice(start, this.pos));
  5135. };
  5136. // Transforms JSX element name to string.
  5137. function getQualifiedJSXName(object) {
  5138. if (!object)
  5139. return object;
  5140. if (object.type === 'JSXIdentifier')
  5141. return object.name;
  5142. if (object.type === 'JSXNamespacedName')
  5143. return object.namespace.name + ':' + object.name.name;
  5144. if (object.type === 'JSXMemberExpression')
  5145. return getQualifiedJSXName(object.object) + '.' +
  5146. getQualifiedJSXName(object.property);
  5147. }
  5148. // Parse next token as JSX identifier
  5149. pp.jsx_parseIdentifier = function() {
  5150. var node = this.startNode();
  5151. if (this.type === tt.jsxName)
  5152. node.name = this.value;
  5153. else if (this.type.keyword)
  5154. node.name = this.type.keyword;
  5155. else
  5156. this.unexpected();
  5157. this.next();
  5158. return this.finishNode(node, 'JSXIdentifier');
  5159. };
  5160. // Parse namespaced identifier.
  5161. pp.jsx_parseNamespacedName = function() {
  5162. var startPos = this.start, startLoc = this.startLoc;
  5163. var name = this.jsx_parseIdentifier();
  5164. if (!this.options.plugins.jsx.allowNamespaces || !this.eat(tt.colon)) return name;
  5165. var node = this.startNodeAt(startPos, startLoc);
  5166. node.namespace = name;
  5167. node.name = this.jsx_parseIdentifier();
  5168. return this.finishNode(node, 'JSXNamespacedName');
  5169. };
  5170. // Parses element name in any form - namespaced, member
  5171. // or single identifier.
  5172. pp.jsx_parseElementName = function() {
  5173. if (this.type === tt.jsxTagEnd)
  5174. return '';
  5175. var startPos = this.start, startLoc = this.startLoc;
  5176. var node = this.jsx_parseNamespacedName();
  5177. if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !this.options.plugins.jsx.allowNamespacedObjects) {
  5178. this.unexpected();
  5179. }
  5180. while (this.eat(tt.dot)) {
  5181. var newNode = this.startNodeAt(startPos, startLoc);
  5182. newNode.object = node;
  5183. newNode.property = this.jsx_parseIdentifier();
  5184. node = this.finishNode(newNode, 'JSXMemberExpression');
  5185. }
  5186. return node;
  5187. };
  5188. // Parses any type of JSX attribute value.
  5189. pp.jsx_parseAttributeValue = function() {
  5190. switch (this.type) {
  5191. case tt.braceL:
  5192. var node = this.jsx_parseExpressionContainer();
  5193. if (node.expression.type === 'JSXEmptyExpression')
  5194. this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression');
  5195. return node;
  5196. case tt.jsxTagStart:
  5197. case tt.string:
  5198. return this.parseExprAtom();
  5199. default:
  5200. this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
  5201. }
  5202. };
  5203. // JSXEmptyExpression is unique type since it doesn't actually parse anything,
  5204. // and so it should start at the end of last read token (left brace) and finish
  5205. // at the beginning of the next one (right brace).
  5206. pp.jsx_parseEmptyExpression = function() {
  5207. var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
  5208. return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
  5209. };
  5210. // Parses JSX expression enclosed into curly brackets.
  5211. pp.jsx_parseExpressionContainer = function() {
  5212. var node = this.startNode();
  5213. this.next();
  5214. node.expression = this.type === tt.braceR
  5215. ? this.jsx_parseEmptyExpression()
  5216. : this.parseExpression();
  5217. this.expect(tt.braceR);
  5218. return this.finishNode(node, 'JSXExpressionContainer');
  5219. };
  5220. // Parses following JSX attribute name-value pair.
  5221. pp.jsx_parseAttribute = function() {
  5222. var node = this.startNode();
  5223. if (this.eat(tt.braceL)) {
  5224. this.expect(tt.ellipsis);
  5225. node.argument = this.parseMaybeAssign();
  5226. this.expect(tt.braceR);
  5227. return this.finishNode(node, 'JSXSpreadAttribute');
  5228. }
  5229. node.name = this.jsx_parseNamespacedName();
  5230. node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
  5231. return this.finishNode(node, 'JSXAttribute');
  5232. };
  5233. // Parses JSX opening tag starting after '<'.
  5234. pp.jsx_parseOpeningElementAt = function(startPos, startLoc) {
  5235. var node = this.startNodeAt(startPos, startLoc);
  5236. node.attributes = [];
  5237. var nodeName = this.jsx_parseElementName();
  5238. if (nodeName) node.name = nodeName;
  5239. while (this.type !== tt.slash && this.type !== tt.jsxTagEnd)
  5240. node.attributes.push(this.jsx_parseAttribute());
  5241. node.selfClosing = this.eat(tt.slash);
  5242. this.expect(tt.jsxTagEnd);
  5243. return this.finishNode(node, nodeName ? 'JSXOpeningElement' : 'JSXOpeningFragment');
  5244. };
  5245. // Parses JSX closing tag starting after '</'.
  5246. pp.jsx_parseClosingElementAt = function(startPos, startLoc) {
  5247. var node = this.startNodeAt(startPos, startLoc);
  5248. var nodeName = this.jsx_parseElementName();
  5249. if (nodeName) node.name = nodeName;
  5250. this.expect(tt.jsxTagEnd);
  5251. return this.finishNode(node, nodeName ? 'JSXClosingElement' : 'JSXClosingFragment');
  5252. };
  5253. // Parses entire JSX element, including it's opening tag
  5254. // (starting after '<'), attributes, contents and closing tag.
  5255. pp.jsx_parseElementAt = function(startPos, startLoc) {
  5256. var node = this.startNodeAt(startPos, startLoc);
  5257. var children = [];
  5258. var openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
  5259. var closingElement = null;
  5260. if (!openingElement.selfClosing) {
  5261. contents: for (;;) {
  5262. switch (this.type) {
  5263. case tt.jsxTagStart:
  5264. startPos = this.start; startLoc = this.startLoc;
  5265. this.next();
  5266. if (this.eat(tt.slash)) {
  5267. closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
  5268. break contents;
  5269. }
  5270. children.push(this.jsx_parseElementAt(startPos, startLoc));
  5271. break;
  5272. case tt.jsxText:
  5273. children.push(this.parseExprAtom());
  5274. break;
  5275. case tt.braceL:
  5276. children.push(this.jsx_parseExpressionContainer());
  5277. break;
  5278. default:
  5279. this.unexpected();
  5280. }
  5281. }
  5282. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  5283. this.raise(
  5284. closingElement.start,
  5285. 'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
  5286. }
  5287. }
  5288. node.openingElement = openingElement;
  5289. node.closingElement = closingElement;
  5290. node.children = children;
  5291. if (this.type === tt.relational && this.value === "<") {
  5292. this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
  5293. }
  5294. return this.finishNode(node, openingElement.name ? 'JSXElement' : 'JSXFragment');
  5295. };
  5296. // Parse JSX text
  5297. pp.jsx_parseText = function(value) {
  5298. var node = this.parseLiteral(value);
  5299. node.type = "JSXText";
  5300. return node;
  5301. };
  5302. // Parses entire JSX element from current position.
  5303. pp.jsx_parseElement = function() {
  5304. var startPos = this.start, startLoc = this.startLoc;
  5305. this.next();
  5306. return this.jsx_parseElementAt(startPos, startLoc);
  5307. };
  5308. acorn.plugins.jsx = function(instance, opts) {
  5309. if (!opts) {
  5310. return;
  5311. }
  5312. if (typeof opts !== 'object') {
  5313. opts = {};
  5314. }
  5315. instance.options.plugins.jsx = {
  5316. allowNamespaces: opts.allowNamespaces !== false,
  5317. allowNamespacedObjects: !!opts.allowNamespacedObjects
  5318. };
  5319. instance.extend('parseExprAtom', function(inner) {
  5320. return function(refShortHandDefaultPos) {
  5321. if (this.type === tt.jsxText)
  5322. return this.jsx_parseText(this.value);
  5323. else if (this.type === tt.jsxTagStart)
  5324. return this.jsx_parseElement();
  5325. else
  5326. return inner.call(this, refShortHandDefaultPos);
  5327. };
  5328. });
  5329. instance.extend('readToken', function(inner) {
  5330. return function(code) {
  5331. var context = this.curContext();
  5332. if (context === tc.j_expr) return this.jsx_readToken();
  5333. if (context === tc.j_oTag || context === tc.j_cTag) {
  5334. if (acorn.isIdentifierStart(code)) return this.jsx_readWord();
  5335. if (code == 62) {
  5336. ++this.pos;
  5337. return this.finishToken(tt.jsxTagEnd);
  5338. }
  5339. if ((code === 34 || code === 39) && context == tc.j_oTag)
  5340. return this.jsx_readString(code);
  5341. }
  5342. if (code === 60 && this.exprAllowed && this.input.charCodeAt(this.pos + 1) !== 33) {
  5343. ++this.pos;
  5344. return this.finishToken(tt.jsxTagStart);
  5345. }
  5346. return inner.call(this, code);
  5347. };
  5348. });
  5349. instance.extend('updateContext', function(inner) {
  5350. return function(prevType) {
  5351. if (this.type == tt.braceL) {
  5352. var curContext = this.curContext();
  5353. if (curContext == tc.j_oTag) this.context.push(tc.b_expr);
  5354. else if (curContext == tc.j_expr) this.context.push(tc.b_tmpl);
  5355. else inner.call(this, prevType);
  5356. this.exprAllowed = true;
  5357. } else if (this.type === tt.slash && prevType === tt.jsxTagStart) {
  5358. this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
  5359. this.context.push(tc.j_cTag); // reconsider as closing tag context
  5360. this.exprAllowed = false;
  5361. } else {
  5362. return inner.call(this, prevType);
  5363. }
  5364. };
  5365. });
  5366. };
  5367. return acorn;
  5368. };
  5369. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  5370. function commonjsRequire () {
  5371. throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
  5372. }
  5373. function unwrapExports (x) {
  5374. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  5375. }
  5376. function createCommonjsModule(fn, module) {
  5377. return module = { exports: {} }, fn(module, module.exports), module.exports;
  5378. }
  5379. var inject$1 = createCommonjsModule(function (module, exports) {
  5380. Object.defineProperty(exports, "__esModule", {
  5381. value: true
  5382. });
  5383. exports['default'] = injectDynamicImport;
  5384. /* eslint-disable no-underscore-dangle */
  5385. var DynamicImportKey = exports.DynamicImportKey = 'Import';
  5386. function injectDynamicImport(acorn) {
  5387. var tt = acorn.tokTypes;
  5388. // NOTE: This allows `yield import()` to parse correctly.
  5389. tt._import.startsExpr = true;
  5390. function parseDynamicImport() {
  5391. var node = this.startNode();
  5392. this.next();
  5393. if (this.type !== tt.parenL) {
  5394. this.unexpected();
  5395. }
  5396. return this.finishNode(node, DynamicImportKey);
  5397. }
  5398. function peekNext() {
  5399. return this.input[this.pos];
  5400. }
  5401. // eslint-disable-next-line no-param-reassign
  5402. acorn.plugins.dynamicImport = function () {
  5403. function dynamicImportPlugin(instance) {
  5404. instance.extend('parseStatement', function (nextMethod) {
  5405. return function () {
  5406. function parseStatement() {
  5407. var node = this.startNode();
  5408. if (this.type === tt._import) {
  5409. var nextToken = peekNext.call(this);
  5410. if (nextToken === tt.parenL.label) {
  5411. var expr = this.parseExpression();
  5412. return this.parseExpressionStatement(node, expr);
  5413. }
  5414. }
  5415. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  5416. args[_key] = arguments[_key];
  5417. }
  5418. return nextMethod.apply(this, args);
  5419. }
  5420. return parseStatement;
  5421. }();
  5422. });
  5423. instance.extend('parseExprAtom', function (nextMethod) {
  5424. return function () {
  5425. function parseExprAtom(refDestructuringErrors) {
  5426. if (this.type === tt._import) {
  5427. return parseDynamicImport.call(this);
  5428. }
  5429. return nextMethod.call(this, refDestructuringErrors);
  5430. }
  5431. return parseExprAtom;
  5432. }();
  5433. });
  5434. }
  5435. return dynamicImportPlugin;
  5436. }();
  5437. return acorn;
  5438. }
  5439. });
  5440. var acornDynamicImport = unwrapExports(inject$1);
  5441. var inject_1 = inject$1.DynamicImportKey;
  5442. var integerToChar = {};
  5443. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
  5444. integerToChar[ i ] = char;
  5445. });
  5446. function encode ( value ) {
  5447. var result;
  5448. if ( typeof value === 'number' ) {
  5449. result = encodeInteger( value );
  5450. } else {
  5451. result = '';
  5452. for ( var i = 0; i < value.length; i += 1 ) {
  5453. result += encodeInteger( value[i] );
  5454. }
  5455. }
  5456. return result;
  5457. }
  5458. function encodeInteger ( num ) {
  5459. var result = '';
  5460. if ( num < 0 ) {
  5461. num = ( -num << 1 ) | 1;
  5462. } else {
  5463. num <<= 1;
  5464. }
  5465. do {
  5466. var clamped = num & 31;
  5467. num >>= 5;
  5468. if ( num > 0 ) {
  5469. clamped |= 32;
  5470. }
  5471. result += integerToChar[ clamped ];
  5472. } while ( num > 0 );
  5473. return result;
  5474. }
  5475. function Chunk ( start, end, content ) {
  5476. this.start = start;
  5477. this.end = end;
  5478. this.original = content;
  5479. this.intro = '';
  5480. this.outro = '';
  5481. this.content = content;
  5482. this.storeName = false;
  5483. this.edited = false;
  5484. // we make these non-enumerable, for sanity while debugging
  5485. Object.defineProperties( this, {
  5486. previous: { writable: true, value: null },
  5487. next: { writable: true, value: null }
  5488. });
  5489. }
  5490. Chunk.prototype = {
  5491. appendLeft: function appendLeft ( content ) {
  5492. this.outro += content;
  5493. },
  5494. appendRight: function appendRight ( content ) {
  5495. this.intro = this.intro + content;
  5496. },
  5497. clone: function clone () {
  5498. var chunk = new Chunk( this.start, this.end, this.original );
  5499. chunk.intro = this.intro;
  5500. chunk.outro = this.outro;
  5501. chunk.content = this.content;
  5502. chunk.storeName = this.storeName;
  5503. chunk.edited = this.edited;
  5504. return chunk;
  5505. },
  5506. contains: function contains ( index ) {
  5507. return this.start < index && index < this.end;
  5508. },
  5509. eachNext: function eachNext ( fn ) {
  5510. var chunk = this;
  5511. while ( chunk ) {
  5512. fn( chunk );
  5513. chunk = chunk.next;
  5514. }
  5515. },
  5516. eachPrevious: function eachPrevious ( fn ) {
  5517. var chunk = this;
  5518. while ( chunk ) {
  5519. fn( chunk );
  5520. chunk = chunk.previous;
  5521. }
  5522. },
  5523. edit: function edit ( content, storeName, contentOnly ) {
  5524. this.content = content;
  5525. if ( !contentOnly ) {
  5526. this.intro = '';
  5527. this.outro = '';
  5528. }
  5529. this.storeName = storeName;
  5530. this.edited = true;
  5531. return this;
  5532. },
  5533. prependLeft: function prependLeft ( content ) {
  5534. this.outro = content + this.outro;
  5535. },
  5536. prependRight: function prependRight ( content ) {
  5537. this.intro = content + this.intro;
  5538. },
  5539. split: function split ( index ) {
  5540. var sliceIndex = index - this.start;
  5541. var originalBefore = this.original.slice( 0, sliceIndex );
  5542. var originalAfter = this.original.slice( sliceIndex );
  5543. this.original = originalBefore;
  5544. var newChunk = new Chunk( index, this.end, originalAfter );
  5545. newChunk.outro = this.outro;
  5546. this.outro = '';
  5547. this.end = index;
  5548. if ( this.edited ) {
  5549. // TODO is this block necessary?...
  5550. newChunk.edit( '', false );
  5551. this.content = '';
  5552. } else {
  5553. this.content = originalBefore;
  5554. }
  5555. newChunk.next = this.next;
  5556. if ( newChunk.next ) { newChunk.next.previous = newChunk; }
  5557. newChunk.previous = this;
  5558. this.next = newChunk;
  5559. return newChunk;
  5560. },
  5561. toString: function toString () {
  5562. return this.intro + this.content + this.outro;
  5563. },
  5564. trimEnd: function trimEnd ( rx ) {
  5565. this.outro = this.outro.replace( rx, '' );
  5566. if ( this.outro.length ) { return true; }
  5567. var trimmed = this.content.replace( rx, '' );
  5568. if ( trimmed.length ) {
  5569. if ( trimmed !== this.content ) {
  5570. this.split( this.start + trimmed.length ).edit( '', false );
  5571. }
  5572. return true;
  5573. } else {
  5574. this.edit( '', false );
  5575. this.intro = this.intro.replace( rx, '' );
  5576. if ( this.intro.length ) { return true; }
  5577. }
  5578. },
  5579. trimStart: function trimStart ( rx ) {
  5580. this.intro = this.intro.replace( rx, '' );
  5581. if ( this.intro.length ) { return true; }
  5582. var trimmed = this.content.replace( rx, '' );
  5583. if ( trimmed.length ) {
  5584. if ( trimmed !== this.content ) {
  5585. this.split( this.end - trimmed.length );
  5586. this.edit( '', false );
  5587. }
  5588. return true;
  5589. } else {
  5590. this.edit( '', false );
  5591. this.outro = this.outro.replace( rx, '' );
  5592. if ( this.outro.length ) { return true; }
  5593. }
  5594. }
  5595. };
  5596. var _btoa;
  5597. if ( typeof window !== 'undefined' && typeof window.btoa === 'function' ) {
  5598. _btoa = window.btoa;
  5599. } else if ( typeof Buffer === 'function' ) {
  5600. _btoa = function (str) { return new Buffer( str ).toString( 'base64' ); };
  5601. } else {
  5602. _btoa = function () {
  5603. throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
  5604. };
  5605. }
  5606. var btoa = _btoa;
  5607. function SourceMap ( properties ) {
  5608. this.version = 3;
  5609. this.file = properties.file;
  5610. this.sources = properties.sources;
  5611. this.sourcesContent = properties.sourcesContent;
  5612. this.names = properties.names;
  5613. this.mappings = properties.mappings;
  5614. }
  5615. SourceMap.prototype = {
  5616. toString: function toString () {
  5617. return JSON.stringify( this );
  5618. },
  5619. toUrl: function toUrl () {
  5620. return 'data:application/json;charset=utf-8;base64,' + btoa( this.toString() );
  5621. }
  5622. };
  5623. function guessIndent ( code ) {
  5624. var lines = code.split( '\n' );
  5625. var tabbed = lines.filter( function (line) { return /^\t+/.test( line ); } );
  5626. var spaced = lines.filter( function (line) { return /^ {2,}/.test( line ); } );
  5627. if ( tabbed.length === 0 && spaced.length === 0 ) {
  5628. return null;
  5629. }
  5630. // More lines tabbed than spaced? Assume tabs, and
  5631. // default to tabs in the case of a tie (or nothing
  5632. // to go on)
  5633. if ( tabbed.length >= spaced.length ) {
  5634. return '\t';
  5635. }
  5636. // Otherwise, we need to guess the multiple
  5637. var min = spaced.reduce( function ( previous, current ) {
  5638. var numSpaces = /^ +/.exec( current )[0].length;
  5639. return Math.min( numSpaces, previous );
  5640. }, Infinity );
  5641. return new Array( min + 1 ).join( ' ' );
  5642. }
  5643. function getRelativePath ( from, to ) {
  5644. var fromParts = from.split( /[\/\\]/ );
  5645. var toParts = to.split( /[\/\\]/ );
  5646. fromParts.pop(); // get dirname
  5647. while ( fromParts[0] === toParts[0] ) {
  5648. fromParts.shift();
  5649. toParts.shift();
  5650. }
  5651. if ( fromParts.length ) {
  5652. var i = fromParts.length;
  5653. while ( i-- ) { fromParts[i] = '..'; }
  5654. }
  5655. return fromParts.concat( toParts ).join( '/' );
  5656. }
  5657. var toString$1 = Object.prototype.toString;
  5658. function isObject ( thing ) {
  5659. return toString$1.call( thing ) === '[object Object]';
  5660. }
  5661. function getLocator ( source ) {
  5662. var originalLines = source.split( '\n' );
  5663. var start = 0;
  5664. var lineRanges = originalLines.map( function ( line, i ) {
  5665. var end = start + line.length + 1;
  5666. var range = { start: start, end: end, line: i };
  5667. start = end;
  5668. return range;
  5669. });
  5670. var i = 0;
  5671. function rangeContains ( range, index ) {
  5672. return range.start <= index && index < range.end;
  5673. }
  5674. function getLocation ( range, index ) {
  5675. return { line: range.line, column: index - range.start };
  5676. }
  5677. return function locate ( index ) {
  5678. var range = lineRanges[i];
  5679. var d = index >= range.end ? 1 : -1;
  5680. while ( range ) {
  5681. if ( rangeContains( range, index ) ) { return getLocation( range, index ); }
  5682. i += d;
  5683. range = lineRanges[i];
  5684. }
  5685. };
  5686. }
  5687. function Mappings ( hires ) {
  5688. var this$1 = this;
  5689. var offsets = {
  5690. generatedCodeColumn: 0,
  5691. sourceIndex: 0,
  5692. sourceCodeLine: 0,
  5693. sourceCodeColumn: 0,
  5694. sourceCodeName: 0
  5695. };
  5696. var generatedCodeLine = 0;
  5697. var generatedCodeColumn = 0;
  5698. this.raw = [];
  5699. var rawSegments = this.raw[ generatedCodeLine ] = [];
  5700. var pending = null;
  5701. this.addEdit = function ( sourceIndex, content, original, loc, nameIndex ) {
  5702. if ( content.length ) {
  5703. rawSegments.push([
  5704. generatedCodeColumn,
  5705. sourceIndex,
  5706. loc.line,
  5707. loc.column,
  5708. nameIndex ]);
  5709. } else if ( pending ) {
  5710. rawSegments.push( pending );
  5711. }
  5712. this$1.advance( content );
  5713. pending = null;
  5714. };
  5715. this.addUneditedChunk = function ( sourceIndex, chunk, original, loc, sourcemapLocations ) {
  5716. var originalCharIndex = chunk.start;
  5717. var first = true;
  5718. while ( originalCharIndex < chunk.end ) {
  5719. if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {
  5720. rawSegments.push([
  5721. generatedCodeColumn,
  5722. sourceIndex,
  5723. loc.line,
  5724. loc.column,
  5725. -1
  5726. ]);
  5727. }
  5728. if ( original[ originalCharIndex ] === '\n' ) {
  5729. loc.line += 1;
  5730. loc.column = 0;
  5731. generatedCodeLine += 1;
  5732. this$1.raw[ generatedCodeLine ] = rawSegments = [];
  5733. generatedCodeColumn = 0;
  5734. } else {
  5735. loc.column += 1;
  5736. generatedCodeColumn += 1;
  5737. }
  5738. originalCharIndex += 1;
  5739. first = false;
  5740. }
  5741. pending = [
  5742. generatedCodeColumn,
  5743. sourceIndex,
  5744. loc.line,
  5745. loc.column,
  5746. -1 ];
  5747. };
  5748. this.advance = function (str) {
  5749. if ( !str ) { return; }
  5750. var lines = str.split( '\n' );
  5751. var lastLine = lines.pop();
  5752. if ( lines.length ) {
  5753. generatedCodeLine += lines.length;
  5754. this$1.raw[ generatedCodeLine ] = rawSegments = [];
  5755. generatedCodeColumn = lastLine.length;
  5756. } else {
  5757. generatedCodeColumn += lastLine.length;
  5758. }
  5759. };
  5760. this.encode = function () {
  5761. return this$1.raw.map( function (segments) {
  5762. var generatedCodeColumn = 0;
  5763. return segments.map( function (segment) {
  5764. var arr = [
  5765. segment[0] - generatedCodeColumn,
  5766. segment[1] - offsets.sourceIndex,
  5767. segment[2] - offsets.sourceCodeLine,
  5768. segment[3] - offsets.sourceCodeColumn
  5769. ];
  5770. generatedCodeColumn = segment[0];
  5771. offsets.sourceIndex = segment[1];
  5772. offsets.sourceCodeLine = segment[2];
  5773. offsets.sourceCodeColumn = segment[3];
  5774. if ( ~segment[4] ) {
  5775. arr.push( segment[4] - offsets.sourceCodeName );
  5776. offsets.sourceCodeName = segment[4];
  5777. }
  5778. return encode( arr );
  5779. }).join( ',' );
  5780. }).join( ';' );
  5781. };
  5782. }
  5783. var warned = {
  5784. insertLeft: false,
  5785. insertRight: false,
  5786. storeName: false
  5787. };
  5788. function MagicString$1 ( string, options ) {
  5789. if ( options === void 0 ) options = {};
  5790. var chunk = new Chunk( 0, string.length, string );
  5791. Object.defineProperties( this, {
  5792. original: { writable: true, value: string },
  5793. outro: { writable: true, value: '' },
  5794. intro: { writable: true, value: '' },
  5795. firstChunk: { writable: true, value: chunk },
  5796. lastChunk: { writable: true, value: chunk },
  5797. lastSearchedChunk: { writable: true, value: chunk },
  5798. byStart: { writable: true, value: {} },
  5799. byEnd: { writable: true, value: {} },
  5800. filename: { writable: true, value: options.filename },
  5801. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  5802. sourcemapLocations: { writable: true, value: {} },
  5803. storedNames: { writable: true, value: {} },
  5804. indentStr: { writable: true, value: guessIndent( string ) }
  5805. });
  5806. this.byStart[ 0 ] = chunk;
  5807. this.byEnd[ string.length ] = chunk;
  5808. }
  5809. MagicString$1.prototype = {
  5810. addSourcemapLocation: function addSourcemapLocation ( char ) {
  5811. this.sourcemapLocations[ char ] = true;
  5812. },
  5813. append: function append ( content ) {
  5814. if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
  5815. this.outro += content;
  5816. return this;
  5817. },
  5818. appendLeft: function appendLeft ( index, content ) {
  5819. if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
  5820. this._split( index );
  5821. var chunk = this.byEnd[ index ];
  5822. if ( chunk ) {
  5823. chunk.appendLeft( content );
  5824. } else {
  5825. this.intro += content;
  5826. }
  5827. return this;
  5828. },
  5829. appendRight: function appendRight ( index, content ) {
  5830. if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
  5831. this._split( index );
  5832. var chunk = this.byStart[ index ];
  5833. if ( chunk ) {
  5834. chunk.appendRight( content );
  5835. } else {
  5836. this.outro += content;
  5837. }
  5838. return this;
  5839. },
  5840. clone: function clone () {
  5841. var cloned = new MagicString$1( this.original, { filename: this.filename });
  5842. var originalChunk = this.firstChunk;
  5843. var clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
  5844. while ( originalChunk ) {
  5845. cloned.byStart[ clonedChunk.start ] = clonedChunk;
  5846. cloned.byEnd[ clonedChunk.end ] = clonedChunk;
  5847. var nextOriginalChunk = originalChunk.next;
  5848. var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  5849. if ( nextClonedChunk ) {
  5850. clonedChunk.next = nextClonedChunk;
  5851. nextClonedChunk.previous = clonedChunk;
  5852. clonedChunk = nextClonedChunk;
  5853. }
  5854. originalChunk = nextOriginalChunk;
  5855. }
  5856. cloned.lastChunk = clonedChunk;
  5857. if ( this.indentExclusionRanges ) {
  5858. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  5859. }
  5860. Object.keys( this.sourcemapLocations ).forEach( function (loc) {
  5861. cloned.sourcemapLocations[ loc ] = true;
  5862. });
  5863. return cloned;
  5864. },
  5865. generateMap: function generateMap ( options ) {
  5866. var this$1 = this;
  5867. options = options || {};
  5868. var sourceIndex = 0;
  5869. var names = Object.keys( this.storedNames );
  5870. var mappings = new Mappings( options.hires );
  5871. var locate = getLocator( this.original );
  5872. if ( this.intro ) {
  5873. mappings.advance( this.intro );
  5874. }
  5875. this.firstChunk.eachNext( function (chunk) {
  5876. var loc = locate( chunk.start );
  5877. if ( chunk.intro.length ) { mappings.advance( chunk.intro ); }
  5878. if ( chunk.edited ) {
  5879. mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
  5880. } else {
  5881. mappings.addUneditedChunk( sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations );
  5882. }
  5883. if ( chunk.outro.length ) { mappings.advance( chunk.outro ); }
  5884. });
  5885. var map = new SourceMap({
  5886. file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
  5887. sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],
  5888. sourcesContent: options.includeContent ? [ this.original ] : [ null ],
  5889. names: names,
  5890. mappings: mappings.encode()
  5891. });
  5892. return map;
  5893. },
  5894. getIndentString: function getIndentString () {
  5895. return this.indentStr === null ? '\t' : this.indentStr;
  5896. },
  5897. indent: function indent ( indentStr, options ) {
  5898. var this$1 = this;
  5899. var pattern = /^[^\r\n]/gm;
  5900. if ( isObject( indentStr ) ) {
  5901. options = indentStr;
  5902. indentStr = undefined;
  5903. }
  5904. indentStr = indentStr !== undefined ? indentStr : ( this.indentStr || '\t' );
  5905. if ( indentStr === '' ) { return this; } // noop
  5906. options = options || {};
  5907. // Process exclusion ranges
  5908. var isExcluded = {};
  5909. if ( options.exclude ) {
  5910. var exclusions = typeof options.exclude[0] === 'number' ? [ options.exclude ] : options.exclude;
  5911. exclusions.forEach( function (exclusion) {
  5912. for ( var i = exclusion[0]; i < exclusion[1]; i += 1 ) {
  5913. isExcluded[i] = true;
  5914. }
  5915. });
  5916. }
  5917. var shouldIndentNextCharacter = options.indentStart !== false;
  5918. var replacer = function (match) {
  5919. if ( shouldIndentNextCharacter ) { return ("" + indentStr + match); }
  5920. shouldIndentNextCharacter = true;
  5921. return match;
  5922. };
  5923. this.intro = this.intro.replace( pattern, replacer );
  5924. var charIndex = 0;
  5925. var chunk = this.firstChunk;
  5926. while ( chunk ) {
  5927. var end = chunk.end;
  5928. if ( chunk.edited ) {
  5929. if ( !isExcluded[ charIndex ] ) {
  5930. chunk.content = chunk.content.replace( pattern, replacer );
  5931. if ( chunk.content.length ) {
  5932. shouldIndentNextCharacter = chunk.content[ chunk.content.length - 1 ] === '\n';
  5933. }
  5934. }
  5935. } else {
  5936. charIndex = chunk.start;
  5937. while ( charIndex < end ) {
  5938. if ( !isExcluded[ charIndex ] ) {
  5939. var char = this$1.original[ charIndex ];
  5940. if ( char === '\n' ) {
  5941. shouldIndentNextCharacter = true;
  5942. } else if ( char !== '\r' && shouldIndentNextCharacter ) {
  5943. shouldIndentNextCharacter = false;
  5944. if ( charIndex === chunk.start ) {
  5945. chunk.prependRight( indentStr );
  5946. } else {
  5947. this$1._splitChunk( chunk, charIndex );
  5948. chunk = chunk.next;
  5949. chunk.prependRight( indentStr );
  5950. }
  5951. }
  5952. }
  5953. charIndex += 1;
  5954. }
  5955. }
  5956. charIndex = chunk.end;
  5957. chunk = chunk.next;
  5958. }
  5959. this.outro = this.outro.replace( pattern, replacer );
  5960. return this;
  5961. },
  5962. insert: function insert () {
  5963. throw new Error( 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)' );
  5964. },
  5965. insertLeft: function insertLeft ( index, content ) {
  5966. if ( !warned.insertLeft ) {
  5967. console.warn( 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead' ); // eslint-disable-line no-console
  5968. warned.insertLeft = true;
  5969. }
  5970. return this.appendLeft( index, content );
  5971. },
  5972. insertRight: function insertRight ( index, content ) {
  5973. if ( !warned.insertRight ) {
  5974. console.warn( 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead' ); // eslint-disable-line no-console
  5975. warned.insertRight = true;
  5976. }
  5977. return this.prependRight( index, content );
  5978. },
  5979. move: function move ( start, end, index ) {
  5980. if ( index >= start && index <= end ) { throw new Error( 'Cannot move a selection inside itself' ); }
  5981. this._split( start );
  5982. this._split( end );
  5983. this._split( index );
  5984. var first = this.byStart[ start ];
  5985. var last = this.byEnd[ end ];
  5986. var oldLeft = first.previous;
  5987. var oldRight = last.next;
  5988. var newRight = this.byStart[ index ];
  5989. if ( !newRight && last === this.lastChunk ) { return this; }
  5990. var newLeft = newRight ? newRight.previous : this.lastChunk;
  5991. if ( oldLeft ) { oldLeft.next = oldRight; }
  5992. if ( oldRight ) { oldRight.previous = oldLeft; }
  5993. if ( newLeft ) { newLeft.next = first; }
  5994. if ( newRight ) { newRight.previous = last; }
  5995. if ( !first.previous ) { this.firstChunk = last.next; }
  5996. if ( !last.next ) {
  5997. this.lastChunk = first.previous;
  5998. this.lastChunk.next = null;
  5999. }
  6000. first.previous = newLeft;
  6001. last.next = newRight || null;
  6002. if ( !newLeft ) { this.firstChunk = first; }
  6003. if ( !newRight ) { this.lastChunk = last; }
  6004. return this;
  6005. },
  6006. overwrite: function overwrite ( start, end, content, options ) {
  6007. var this$1 = this;
  6008. if ( typeof content !== 'string' ) { throw new TypeError( 'replacement content must be a string' ); }
  6009. while ( start < 0 ) { start += this$1.original.length; }
  6010. while ( end < 0 ) { end += this$1.original.length; }
  6011. if ( end > this.original.length ) { throw new Error( 'end is out of bounds' ); }
  6012. if ( start === end ) { throw new Error( 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead' ); }
  6013. this._split( start );
  6014. this._split( end );
  6015. if ( options === true ) {
  6016. if ( !warned.storeName ) {
  6017. console.warn( 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string' ); // eslint-disable-line no-console
  6018. warned.storeName = true;
  6019. }
  6020. options = { storeName: true };
  6021. }
  6022. var storeName = options !== undefined ? options.storeName : false;
  6023. var contentOnly = options !== undefined ? options.contentOnly : false;
  6024. if ( storeName ) {
  6025. var original = this.original.slice( start, end );
  6026. this.storedNames[ original ] = true;
  6027. }
  6028. var first = this.byStart[ start ];
  6029. var last = this.byEnd[ end ];
  6030. if ( first ) {
  6031. if ( end > first.end && first.next !== this.byStart[ first.end ] ) {
  6032. throw new Error( 'Cannot overwrite across a split point' );
  6033. }
  6034. first.edit( content, storeName, contentOnly );
  6035. if ( first !== last ) {
  6036. var chunk = first.next;
  6037. while ( chunk !== last ) {
  6038. chunk.edit( '', false );
  6039. chunk = chunk.next;
  6040. }
  6041. chunk.edit( '', false );
  6042. }
  6043. }
  6044. else {
  6045. // must be inserting at the end
  6046. var newChunk = new Chunk( start, end, '' ).edit( content, storeName );
  6047. // TODO last chunk in the array may not be the last chunk, if it's moved...
  6048. last.next = newChunk;
  6049. newChunk.previous = last;
  6050. }
  6051. return this;
  6052. },
  6053. prepend: function prepend ( content ) {
  6054. if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
  6055. this.intro = content + this.intro;
  6056. return this;
  6057. },
  6058. prependLeft: function prependLeft ( index, content ) {
  6059. if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
  6060. this._split( index );
  6061. var chunk = this.byEnd[ index ];
  6062. if ( chunk ) {
  6063. chunk.prependLeft( content );
  6064. } else {
  6065. this.intro = content + this.intro;
  6066. }
  6067. return this;
  6068. },
  6069. prependRight: function prependRight ( index, content ) {
  6070. if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
  6071. this._split( index );
  6072. var chunk = this.byStart[ index ];
  6073. if ( chunk ) {
  6074. chunk.prependRight( content );
  6075. } else {
  6076. this.outro = content + this.outro;
  6077. }
  6078. return this;
  6079. },
  6080. remove: function remove ( start, end ) {
  6081. var this$1 = this;
  6082. while ( start < 0 ) { start += this$1.original.length; }
  6083. while ( end < 0 ) { end += this$1.original.length; }
  6084. if ( start === end ) { return this; }
  6085. if ( start < 0 || end > this.original.length ) { throw new Error( 'Character is out of bounds' ); }
  6086. if ( start > end ) { throw new Error( 'end must be greater than start' ); }
  6087. this._split( start );
  6088. this._split( end );
  6089. var chunk = this.byStart[ start ];
  6090. while ( chunk ) {
  6091. chunk.intro = '';
  6092. chunk.outro = '';
  6093. chunk.edit( '' );
  6094. chunk = end > chunk.end ? this$1.byStart[ chunk.end ] : null;
  6095. }
  6096. return this;
  6097. },
  6098. slice: function slice ( start, end ) {
  6099. var this$1 = this;
  6100. if ( start === void 0 ) start = 0;
  6101. if ( end === void 0 ) end = this.original.length;
  6102. while ( start < 0 ) { start += this$1.original.length; }
  6103. while ( end < 0 ) { end += this$1.original.length; }
  6104. var result = '';
  6105. // find start chunk
  6106. var chunk = this.firstChunk;
  6107. while ( chunk && ( chunk.start > start || chunk.end <= start ) ) {
  6108. // found end chunk before start
  6109. if ( chunk.start < end && chunk.end >= end ) {
  6110. return result;
  6111. }
  6112. chunk = chunk.next;
  6113. }
  6114. if ( chunk && chunk.edited && chunk.start !== start ) { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
  6115. var startChunk = chunk;
  6116. while ( chunk ) {
  6117. if ( chunk.intro && ( startChunk !== chunk || chunk.start === start ) ) {
  6118. result += chunk.intro;
  6119. }
  6120. var containsEnd = chunk.start < end && chunk.end >= end;
  6121. if ( containsEnd && chunk.edited && chunk.end !== end ) { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
  6122. var sliceStart = startChunk === chunk ? start - chunk.start : 0;
  6123. var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  6124. result += chunk.content.slice( sliceStart, sliceEnd );
  6125. if ( chunk.outro && ( !containsEnd || chunk.end === end ) ) {
  6126. result += chunk.outro;
  6127. }
  6128. if ( containsEnd ) {
  6129. break;
  6130. }
  6131. chunk = chunk.next;
  6132. }
  6133. return result;
  6134. },
  6135. // TODO deprecate this? not really very useful
  6136. snip: function snip ( start, end ) {
  6137. var clone = this.clone();
  6138. clone.remove( 0, start );
  6139. clone.remove( end, clone.original.length );
  6140. return clone;
  6141. },
  6142. _split: function _split ( index ) {
  6143. var this$1 = this;
  6144. if ( this.byStart[ index ] || this.byEnd[ index ] ) { return; }
  6145. var chunk = this.lastSearchedChunk;
  6146. var searchForward = index > chunk.end;
  6147. while ( true ) {
  6148. if ( chunk.contains( index ) ) { return this$1._splitChunk( chunk, index ); }
  6149. chunk = searchForward ?
  6150. this$1.byStart[ chunk.end ] :
  6151. this$1.byEnd[ chunk.start ];
  6152. }
  6153. },
  6154. _splitChunk: function _splitChunk ( chunk, index ) {
  6155. if ( chunk.edited && chunk.content.length ) { // zero-length edited chunks are a special case (overlapping replacements)
  6156. var loc = getLocator( this.original )( index );
  6157. throw new Error( ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")") );
  6158. }
  6159. var newChunk = chunk.split( index );
  6160. this.byEnd[ index ] = chunk;
  6161. this.byStart[ index ] = newChunk;
  6162. this.byEnd[ newChunk.end ] = newChunk;
  6163. if ( chunk === this.lastChunk ) { this.lastChunk = newChunk; }
  6164. this.lastSearchedChunk = chunk;
  6165. return true;
  6166. },
  6167. toString: function toString () {
  6168. var str = this.intro;
  6169. var chunk = this.firstChunk;
  6170. while ( chunk ) {
  6171. str += chunk.toString();
  6172. chunk = chunk.next;
  6173. }
  6174. return str + this.outro;
  6175. },
  6176. trimLines: function trimLines () {
  6177. return this.trim('[\\r\\n]');
  6178. },
  6179. trim: function trim ( charType ) {
  6180. return this.trimStart( charType ).trimEnd( charType );
  6181. },
  6182. trimEnd: function trimEnd ( charType ) {
  6183. var this$1 = this;
  6184. var rx = new RegExp( ( charType || '\\s' ) + '+$' );
  6185. this.outro = this.outro.replace( rx, '' );
  6186. if ( this.outro.length ) { return this; }
  6187. var chunk = this.lastChunk;
  6188. do {
  6189. var end = chunk.end;
  6190. var aborted = chunk.trimEnd( rx );
  6191. // if chunk was trimmed, we have a new lastChunk
  6192. if ( chunk.end !== end ) {
  6193. if ( this$1.lastChunk === chunk ) {
  6194. this$1.lastChunk = chunk.next;
  6195. }
  6196. this$1.byEnd[ chunk.end ] = chunk;
  6197. this$1.byStart[ chunk.next.start ] = chunk.next;
  6198. this$1.byEnd[ chunk.next.end ] = chunk.next;
  6199. }
  6200. if ( aborted ) { return this$1; }
  6201. chunk = chunk.previous;
  6202. } while ( chunk );
  6203. return this;
  6204. },
  6205. trimStart: function trimStart ( charType ) {
  6206. var this$1 = this;
  6207. var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
  6208. this.intro = this.intro.replace( rx, '' );
  6209. if ( this.intro.length ) { return this; }
  6210. var chunk = this.firstChunk;
  6211. do {
  6212. var end = chunk.end;
  6213. var aborted = chunk.trimStart( rx );
  6214. if ( chunk.end !== end ) {
  6215. // special case...
  6216. if ( chunk === this$1.lastChunk ) { this$1.lastChunk = chunk.next; }
  6217. this$1.byEnd[ chunk.end ] = chunk;
  6218. this$1.byStart[ chunk.next.start ] = chunk.next;
  6219. this$1.byEnd[ chunk.next.end ] = chunk.next;
  6220. }
  6221. if ( aborted ) { return this$1; }
  6222. chunk = chunk.next;
  6223. } while ( chunk );
  6224. return this;
  6225. }
  6226. };
  6227. // used for debugging, without the noise created by
  6228. // circular references
  6229. function toJSON(node) {
  6230. var obj = {};
  6231. Object.keys(node).forEach(function (key) {
  6232. if (
  6233. key === 'parent' ||
  6234. key === 'program' ||
  6235. key === 'keys' ||
  6236. key === '__wrapped'
  6237. )
  6238. { return; }
  6239. if (Array.isArray(node[key])) {
  6240. obj[key] = node[key].map(toJSON);
  6241. } else if (node[key] && node[key].toJSON) {
  6242. obj[key] = node[key].toJSON();
  6243. } else {
  6244. obj[key] = node[key];
  6245. }
  6246. });
  6247. return obj;
  6248. }
  6249. var Node$1 = function Node () {};
  6250. Node$1.prototype.ancestor = function ancestor (level) {
  6251. var node = this;
  6252. while (level--) {
  6253. node = node.parent;
  6254. if (!node) { return null; }
  6255. }
  6256. return node;
  6257. };
  6258. Node$1.prototype.contains = function contains (node) {
  6259. while (node) {
  6260. if (node === this) { return true; }
  6261. node = node.parent;
  6262. }
  6263. return false;
  6264. };
  6265. Node$1.prototype.findLexicalBoundary = function findLexicalBoundary () {
  6266. return this.parent.findLexicalBoundary();
  6267. };
  6268. Node$1.prototype.findNearest = function findNearest (type) {
  6269. if (typeof type === 'string') { type = new RegExp(("^" + type + "$")); }
  6270. if (type.test(this.type)) { return this; }
  6271. return this.parent.findNearest(type);
  6272. };
  6273. Node$1.prototype.unparenthesizedParent = function unparenthesizedParent () {
  6274. var node = this.parent;
  6275. while (node && node.type === 'ParenthesizedExpression') {
  6276. node = node.parent;
  6277. }
  6278. return node;
  6279. };
  6280. Node$1.prototype.unparenthesize = function unparenthesize () {
  6281. var node = this;
  6282. while (node.type === 'ParenthesizedExpression') {
  6283. node = node.expression;
  6284. }
  6285. return node;
  6286. };
  6287. Node$1.prototype.findScope = function findScope (functionScope) {
  6288. return this.parent.findScope(functionScope);
  6289. };
  6290. Node$1.prototype.getIndentation = function getIndentation () {
  6291. return this.parent.getIndentation();
  6292. };
  6293. Node$1.prototype.initialise = function initialise (transforms) {
  6294. for (var i = 0, list = this.keys; i < list.length; i += 1) {
  6295. var key = list[i];
  6296. var value = this[key];
  6297. if (Array.isArray(value)) {
  6298. value.forEach(function (node) { return node && node.initialise(transforms); });
  6299. } else if (value && typeof value === 'object') {
  6300. value.initialise(transforms);
  6301. }
  6302. }
  6303. };
  6304. Node$1.prototype.toJSON = function toJSON$1 () {
  6305. return toJSON(this);
  6306. };
  6307. Node$1.prototype.toString = function toString () {
  6308. return this.program.magicString.original.slice(this.start, this.end);
  6309. };
  6310. Node$1.prototype.transpile = function transpile (code, transforms) {
  6311. for (var i = 0, list = this.keys; i < list.length; i += 1) {
  6312. var key = list[i];
  6313. var value = this[key];
  6314. if (Array.isArray(value)) {
  6315. value.forEach(function (node) { return node && node.transpile(code, transforms); });
  6316. } else if (value && typeof value === 'object') {
  6317. value.transpile(code, transforms);
  6318. }
  6319. }
  6320. };
  6321. function extractNames(node) {
  6322. var names = [];
  6323. extractors[node.type](names, node);
  6324. return names;
  6325. }
  6326. var extractors = {
  6327. Identifier: function Identifier(names, node) {
  6328. names.push(node);
  6329. },
  6330. ObjectPattern: function ObjectPattern(names, node) {
  6331. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  6332. var prop = list[i];
  6333. extractors[prop.type](names, prop);
  6334. }
  6335. },
  6336. Property: function Property(names, node) {
  6337. extractors[node.value.type](names, node.value);
  6338. },
  6339. ArrayPattern: function ArrayPattern(names, node) {
  6340. for (var i = 0, list = node.elements; i < list.length; i += 1) {
  6341. var element = list[i];
  6342. if (element) { extractors[element.type](names, element); }
  6343. }
  6344. },
  6345. RestElement: function RestElement(names, node) {
  6346. extractors[node.argument.type](names, node.argument);
  6347. },
  6348. AssignmentPattern: function AssignmentPattern(names, node) {
  6349. extractors[node.left.type](names, node.left);
  6350. }
  6351. };
  6352. var reserved = Object.create(null);
  6353. 'do if in for let new try var case else enum eval null this true void with await break catch class const false super throw while yield delete export import public return static switch typeof default extends finally package private continue debugger function arguments interface protected implements instanceof'
  6354. .split(' ')
  6355. .forEach(function (word) { return (reserved[word] = true); });
  6356. function Scope(options) {
  6357. options = options || {};
  6358. this.parent = options.parent;
  6359. this.isBlockScope = !!options.block;
  6360. this.createDeclarationCallback = options.declare;
  6361. var scope = this;
  6362. while (scope.isBlockScope) { scope = scope.parent; }
  6363. this.functionScope = scope;
  6364. this.identifiers = [];
  6365. this.declarations = Object.create(null);
  6366. this.references = Object.create(null);
  6367. this.blockScopedDeclarations = this.isBlockScope ? null : Object.create(null);
  6368. this.aliases = Object.create(null);
  6369. }
  6370. Scope.prototype = {
  6371. addDeclaration: function addDeclaration(node, kind) {
  6372. for (var i = 0, list = extractNames(node); i < list.length; i += 1) {
  6373. var identifier = list[i];
  6374. var name = identifier.name;
  6375. var declaration = { name: name, node: identifier, kind: kind, instances: [] };
  6376. this.declarations[name] = declaration;
  6377. if (this.isBlockScope) {
  6378. if (!this.functionScope.blockScopedDeclarations[name])
  6379. { this.functionScope.blockScopedDeclarations[name] = []; }
  6380. this.functionScope.blockScopedDeclarations[name].push(declaration);
  6381. }
  6382. }
  6383. },
  6384. addReference: function addReference(identifier) {
  6385. if (this.consolidated) {
  6386. this.consolidateReference(identifier);
  6387. } else {
  6388. this.identifiers.push(identifier);
  6389. }
  6390. },
  6391. consolidate: function consolidate() {
  6392. for (var i = 0; i < this.identifiers.length; i += 1) {
  6393. // we might push to the array during consolidation, so don't cache length
  6394. var identifier = this.identifiers[i];
  6395. this.consolidateReference(identifier);
  6396. }
  6397. this.consolidated = true; // TODO understand why this is necessary... seems bad
  6398. },
  6399. consolidateReference: function consolidateReference(identifier) {
  6400. var declaration = this.declarations[identifier.name];
  6401. if (declaration) {
  6402. declaration.instances.push(identifier);
  6403. } else {
  6404. this.references[identifier.name] = true;
  6405. if (this.parent) { this.parent.addReference(identifier); }
  6406. }
  6407. },
  6408. contains: function contains(name) {
  6409. return (
  6410. this.declarations[name] ||
  6411. (this.parent ? this.parent.contains(name) : false)
  6412. );
  6413. },
  6414. createIdentifier: function createIdentifier(base) {
  6415. if (typeof base === 'number') { base = base.toString(); }
  6416. base = base
  6417. .replace(/\s/g, '')
  6418. .replace(/\[([^\]]+)\]/g, '_$1')
  6419. .replace(/[^a-zA-Z0-9_$]/g, '_')
  6420. .replace(/_{2,}/, '_');
  6421. var name = base;
  6422. var counter = 1;
  6423. while (
  6424. this.declarations[name] ||
  6425. this.references[name] ||
  6426. this.aliases[name] ||
  6427. name in reserved
  6428. ) {
  6429. name = base + "$" + (counter++);
  6430. }
  6431. this.aliases[name] = true;
  6432. return name;
  6433. },
  6434. createDeclaration: function createDeclaration(base) {
  6435. var id = this.createIdentifier(base);
  6436. this.createDeclarationCallback(id);
  6437. return id;
  6438. },
  6439. findDeclaration: function findDeclaration(name) {
  6440. return (
  6441. this.declarations[name] ||
  6442. (this.parent && this.parent.findDeclaration(name))
  6443. );
  6444. },
  6445. // Sometimes, block scope declarations change name during transpilation
  6446. resolveName: function resolveName(name) {
  6447. var declaration = this.findDeclaration(name);
  6448. return declaration ? declaration.name : name;
  6449. }
  6450. };
  6451. function locate(source, index) {
  6452. var lines = source.split('\n');
  6453. var len = lines.length;
  6454. var lineStart = 0;
  6455. var i;
  6456. for (i = 0; i < len; i += 1) {
  6457. var line = lines[i];
  6458. var lineEnd = lineStart + line.length + 1; // +1 for newline
  6459. if (lineEnd > index) {
  6460. return { line: i + 1, column: index - lineStart, char: i };
  6461. }
  6462. lineStart = lineEnd;
  6463. }
  6464. throw new Error('Could not determine location of character');
  6465. }
  6466. function pad(num, len) {
  6467. var result = String(num);
  6468. return result + repeat(' ', len - result.length);
  6469. }
  6470. function repeat(str, times) {
  6471. var result = '';
  6472. while (times--) { result += str; }
  6473. return result;
  6474. }
  6475. function getSnippet(source, loc, length) {
  6476. if ( length === void 0 ) length = 1;
  6477. var first = Math.max(loc.line - 5, 0);
  6478. var last = loc.line;
  6479. var numDigits = String(last).length;
  6480. var lines = source.split('\n').slice(first, last);
  6481. var lastLine = lines[lines.length - 1];
  6482. var offset = lastLine.slice(0, loc.column).replace(/\t/g, ' ').length;
  6483. var snippet = lines
  6484. .map(function (line, i) { return ((pad(i + first + 1, numDigits)) + " : " + (line.replace(/\t/g, ' '))); })
  6485. .join('\n');
  6486. snippet += '\n' + repeat(' ', numDigits + 3 + offset) + repeat('^', length);
  6487. return snippet;
  6488. }
  6489. var CompileError = /*@__PURE__*/(function (Error) {
  6490. function CompileError(message, node) {
  6491. Error.call(this, message);
  6492. this.name = 'CompileError';
  6493. if (!node) {
  6494. return;
  6495. }
  6496. var source = node.program.magicString.original;
  6497. var loc = locate(source, node.start);
  6498. this.message = message + " (" + (loc.line) + ":" + (loc.column) + ")";
  6499. this.stack = new Error().stack.replace(
  6500. new RegExp((".+new " + (this.name) + ".+\\n"), 'm'),
  6501. ''
  6502. );
  6503. this.loc = loc;
  6504. this.snippet = getSnippet(source, loc, node.end - node.start);
  6505. }
  6506. if ( Error ) CompileError.__proto__ = Error;
  6507. CompileError.prototype = Object.create( Error && Error.prototype );
  6508. CompileError.prototype.constructor = CompileError;
  6509. CompileError.prototype.toString = function toString () {
  6510. return ((this.name) + ": " + (this.message) + "\n" + (this.snippet));
  6511. };
  6512. return CompileError;
  6513. }(Error));
  6514. function findIndex(array, fn) {
  6515. for (var i = 0; i < array.length; i += 1) {
  6516. if (fn(array[i], i)) { return i; }
  6517. }
  6518. return -1;
  6519. }
  6520. var handlers = {
  6521. Identifier: destructureIdentifier,
  6522. AssignmentPattern: destructureAssignmentPattern,
  6523. ArrayPattern: destructureArrayPattern,
  6524. ObjectPattern: destructureObjectPattern
  6525. };
  6526. function destructure(
  6527. code,
  6528. createIdentifier,
  6529. resolveName,
  6530. node,
  6531. ref,
  6532. inline,
  6533. statementGenerators
  6534. ) {
  6535. handlers[node.type](code, createIdentifier, resolveName, node, ref, inline, statementGenerators);
  6536. }
  6537. function destructureIdentifier(
  6538. code,
  6539. createIdentifier,
  6540. resolveName,
  6541. node,
  6542. ref,
  6543. inline,
  6544. statementGenerators
  6545. ) {
  6546. statementGenerators.push(function (start, prefix, suffix) {
  6547. code.overwrite(node.start, node.end, (inline ? prefix : (prefix + "var ")) + resolveName(node) + " = " + ref + suffix);
  6548. code.move(node.start, node.end, start);
  6549. });
  6550. }
  6551. function destructureMemberExpression(
  6552. code,
  6553. createIdentifier,
  6554. resolveName,
  6555. node,
  6556. ref,
  6557. inline,
  6558. statementGenerators
  6559. ) {
  6560. statementGenerators.push(function (start, prefix, suffix) {
  6561. code.prependRight(node.start, inline ? prefix : (prefix + "var "));
  6562. code.appendLeft(node.end, (" = " + ref + suffix));
  6563. code.move(node.start, node.end, start);
  6564. });
  6565. }
  6566. function destructureAssignmentPattern(
  6567. code,
  6568. createIdentifier,
  6569. resolveName,
  6570. node,
  6571. ref,
  6572. inline,
  6573. statementGenerators
  6574. ) {
  6575. var isIdentifier = node.left.type === 'Identifier';
  6576. var name = isIdentifier ? node.left.name : ref;
  6577. if (!inline) {
  6578. statementGenerators.push(function (start, prefix, suffix) {
  6579. code.prependRight(
  6580. node.left.end,
  6581. (prefix + "if ( " + name + " === void 0 ) " + name)
  6582. );
  6583. code.move(node.left.end, node.right.end, start);
  6584. code.appendLeft(node.right.end, suffix);
  6585. });
  6586. }
  6587. if (!isIdentifier) {
  6588. destructure(code, createIdentifier, resolveName, node.left, ref, inline, statementGenerators);
  6589. }
  6590. }
  6591. function destructureArrayPattern(
  6592. code,
  6593. createIdentifier,
  6594. resolveName,
  6595. node,
  6596. ref,
  6597. inline,
  6598. statementGenerators
  6599. ) {
  6600. var c = node.start;
  6601. node.elements.forEach(function (element, i) {
  6602. if (!element) { return; }
  6603. if (element.type === 'RestElement') {
  6604. handleProperty(
  6605. code,
  6606. createIdentifier,
  6607. resolveName,
  6608. c,
  6609. element.argument,
  6610. (ref + ".slice(" + i + ")"),
  6611. inline,
  6612. statementGenerators
  6613. );
  6614. } else {
  6615. handleProperty(
  6616. code,
  6617. createIdentifier,
  6618. resolveName,
  6619. c,
  6620. element,
  6621. (ref + "[" + i + "]"),
  6622. inline,
  6623. statementGenerators
  6624. );
  6625. }
  6626. c = element.end;
  6627. });
  6628. code.remove(c, node.end);
  6629. }
  6630. function destructureObjectPattern(
  6631. code,
  6632. createIdentifier,
  6633. resolveName,
  6634. node,
  6635. ref,
  6636. inline,
  6637. statementGenerators
  6638. ) {
  6639. var this$1 = this;
  6640. var c = node.start;
  6641. var nonRestKeys = [];
  6642. node.properties.forEach(function (prop) {
  6643. var value;
  6644. var content;
  6645. if (prop.type === 'Property') {
  6646. var isComputedKey = prop.computed || prop.key.type !== 'Identifier';
  6647. var key = isComputedKey
  6648. ? code.slice(prop.key.start, prop.key.end)
  6649. : prop.key.name;
  6650. value = isComputedKey ? (ref + "[" + key + "]") : (ref + "." + key);
  6651. content = prop.value;
  6652. nonRestKeys.push(isComputedKey ? key : '"' + key + '"');
  6653. } else if (prop.type === 'RestElement') {
  6654. content = prop.argument;
  6655. value = createIdentifier('rest');
  6656. statementGenerators.push(function (start, prefix, suffix) {
  6657. var helper = prop.program.getObjectWithoutPropertiesHelper(code);
  6658. code.overwrite(
  6659. prop.start,
  6660. (c = prop.argument.start),
  6661. (inline ? prefix : (prefix + "var ")) + value + " = " + helper + "( " + ref + ", [" + (nonRestKeys.join(', ')) + "] )" + suffix
  6662. );
  6663. code.move(prop.start, c, start);
  6664. });
  6665. } else {
  6666. throw new CompileError(
  6667. this$1,
  6668. ("Unexpected node of type " + (prop.type) + " in object pattern")
  6669. );
  6670. }
  6671. handleProperty(code, createIdentifier, resolveName, c, content, value, inline, statementGenerators);
  6672. c = prop.end;
  6673. });
  6674. code.remove(c, node.end);
  6675. }
  6676. function handleProperty(
  6677. code,
  6678. createIdentifier,
  6679. resolveName,
  6680. c,
  6681. node,
  6682. value,
  6683. inline,
  6684. statementGenerators
  6685. ) {
  6686. switch (node.type) {
  6687. case 'Identifier': {
  6688. code.remove(c, node.start);
  6689. destructureIdentifier(
  6690. code,
  6691. createIdentifier,
  6692. resolveName,
  6693. node,
  6694. value,
  6695. inline,
  6696. statementGenerators
  6697. );
  6698. break;
  6699. }
  6700. case 'MemberExpression':
  6701. code.remove(c, node.start);
  6702. destructureMemberExpression(
  6703. code,
  6704. createIdentifier,
  6705. resolveName,
  6706. node,
  6707. value,
  6708. true,
  6709. statementGenerators
  6710. );
  6711. break;
  6712. case 'AssignmentPattern': {
  6713. var name;
  6714. var isIdentifier = node.left.type === 'Identifier';
  6715. if (isIdentifier) {
  6716. name = resolveName(node.left);
  6717. } else {
  6718. name = createIdentifier(value);
  6719. }
  6720. statementGenerators.push(function (start, prefix, suffix) {
  6721. if (inline) {
  6722. code.prependRight(
  6723. node.right.start,
  6724. (name + " = " + value + ", " + name + " = " + name + " === void 0 ? ")
  6725. );
  6726. code.appendLeft(node.right.end, (" : " + name + suffix));
  6727. } else {
  6728. code.prependRight(
  6729. node.right.start,
  6730. (prefix + "var " + name + " = " + value + "; if ( " + name + " === void 0 ) " + name + " = ")
  6731. );
  6732. code.appendLeft(node.right.end, suffix);
  6733. }
  6734. code.move(node.right.start, node.right.end, start);
  6735. });
  6736. if (isIdentifier) {
  6737. code.remove(c, node.right.start);
  6738. } else {
  6739. code.remove(c, node.left.start);
  6740. code.remove(node.left.end, node.right.start);
  6741. handleProperty(
  6742. code,
  6743. createIdentifier,
  6744. resolveName,
  6745. c,
  6746. node.left,
  6747. name,
  6748. inline,
  6749. statementGenerators
  6750. );
  6751. }
  6752. break;
  6753. }
  6754. case 'ObjectPattern': {
  6755. code.remove(c, (c = node.start));
  6756. var ref = value;
  6757. if (node.properties.length > 1) {
  6758. ref = createIdentifier(value);
  6759. statementGenerators.push(function (start, prefix, suffix) {
  6760. // this feels a tiny bit hacky, but we can't do a
  6761. // straightforward appendLeft and keep correct order...
  6762. code.prependRight(node.start, (inline ? '' : (prefix + "var ")) + ref + " = ");
  6763. code.overwrite(node.start, (c = node.start + 1), value);
  6764. code.appendLeft(c, suffix);
  6765. code.overwrite(
  6766. node.start,
  6767. (c = node.start + 1),
  6768. (inline ? '' : (prefix + "var ")) + ref + " = " + value + suffix
  6769. );
  6770. code.move(node.start, c, start);
  6771. });
  6772. }
  6773. destructureObjectPattern(
  6774. code,
  6775. createIdentifier,
  6776. resolveName,
  6777. node,
  6778. ref,
  6779. inline,
  6780. statementGenerators
  6781. );
  6782. break;
  6783. }
  6784. case 'ArrayPattern': {
  6785. code.remove(c, (c = node.start));
  6786. if (node.elements.filter(Boolean).length > 1) {
  6787. var ref$1 = createIdentifier(value);
  6788. statementGenerators.push(function (start, prefix, suffix) {
  6789. code.prependRight(node.start, (inline ? '' : (prefix + "var ")) + ref$1 + " = ");
  6790. code.overwrite(node.start, (c = node.start + 1), value, {
  6791. contentOnly: true
  6792. });
  6793. code.appendLeft(c, suffix);
  6794. code.move(node.start, c, start);
  6795. });
  6796. node.elements.forEach(function (element, i) {
  6797. if (!element) { return; }
  6798. if (element.type === 'RestElement') {
  6799. handleProperty(
  6800. code,
  6801. createIdentifier,
  6802. resolveName,
  6803. c,
  6804. element.argument,
  6805. (ref$1 + ".slice(" + i + ")"),
  6806. inline,
  6807. statementGenerators
  6808. );
  6809. } else {
  6810. handleProperty(
  6811. code,
  6812. createIdentifier,
  6813. resolveName,
  6814. c,
  6815. element,
  6816. (ref$1 + "[" + i + "]"),
  6817. inline,
  6818. statementGenerators
  6819. );
  6820. }
  6821. c = element.end;
  6822. });
  6823. } else {
  6824. var index = findIndex(node.elements, Boolean);
  6825. var element = node.elements[index];
  6826. if (element.type === 'RestElement') {
  6827. handleProperty(
  6828. code,
  6829. createIdentifier,
  6830. resolveName,
  6831. c,
  6832. element.argument,
  6833. (value + ".slice(" + index + ")"),
  6834. inline,
  6835. statementGenerators
  6836. );
  6837. } else {
  6838. handleProperty(
  6839. code,
  6840. createIdentifier,
  6841. resolveName,
  6842. c,
  6843. element,
  6844. (value + "[" + index + "]"),
  6845. inline,
  6846. statementGenerators
  6847. );
  6848. }
  6849. c = element.end;
  6850. }
  6851. code.remove(c, node.end);
  6852. break;
  6853. }
  6854. default: {
  6855. throw new Error(("Unexpected node type in destructuring (" + (node.type) + ")"));
  6856. }
  6857. }
  6858. }
  6859. function isUseStrict(node) {
  6860. if (!node) { return false; }
  6861. if (node.type !== 'ExpressionStatement') { return false; }
  6862. if (node.expression.type !== 'Literal') { return false; }
  6863. return node.expression.value === 'use strict';
  6864. }
  6865. var BlockStatement = /*@__PURE__*/(function (Node) {
  6866. function BlockStatement () {
  6867. Node.apply(this, arguments);
  6868. }
  6869. if ( Node ) BlockStatement.__proto__ = Node;
  6870. BlockStatement.prototype = Object.create( Node && Node.prototype );
  6871. BlockStatement.prototype.constructor = BlockStatement;
  6872. BlockStatement.prototype.createScope = function createScope () {
  6873. var this$1 = this;
  6874. this.parentIsFunction = /Function/.test(this.parent.type);
  6875. this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root';
  6876. this.scope = new Scope({
  6877. block: !this.isFunctionBlock,
  6878. parent: this.parent.findScope(false),
  6879. declare: function (id) { return this$1.createdDeclarations.push(id); }
  6880. });
  6881. if (this.parentIsFunction) {
  6882. this.parent.params.forEach(function (node) {
  6883. this$1.scope.addDeclaration(node, 'param');
  6884. });
  6885. }
  6886. };
  6887. BlockStatement.prototype.initialise = function initialise (transforms) {
  6888. this.thisAlias = null;
  6889. this.argumentsAlias = null;
  6890. this.defaultParameters = [];
  6891. this.createdDeclarations = [];
  6892. // normally the scope gets created here, during initialisation,
  6893. // but in some cases (e.g. `for` statements), we need to create
  6894. // the scope early, as it pertains to both the init block and
  6895. // the body of the statement
  6896. if (!this.scope) { this.createScope(); }
  6897. this.body.forEach(function (node) { return node.initialise(transforms); });
  6898. this.scope.consolidate();
  6899. };
  6900. BlockStatement.prototype.findLexicalBoundary = function findLexicalBoundary () {
  6901. if (this.type === 'Program') { return this; }
  6902. if (/^Function/.test(this.parent.type)) { return this; }
  6903. return this.parent.findLexicalBoundary();
  6904. };
  6905. BlockStatement.prototype.findScope = function findScope (functionScope) {
  6906. if (functionScope && !this.isFunctionBlock)
  6907. { return this.parent.findScope(functionScope); }
  6908. return this.scope;
  6909. };
  6910. BlockStatement.prototype.getArgumentsAlias = function getArgumentsAlias () {
  6911. if (!this.argumentsAlias) {
  6912. this.argumentsAlias = this.scope.createIdentifier('arguments');
  6913. }
  6914. return this.argumentsAlias;
  6915. };
  6916. BlockStatement.prototype.getArgumentsArrayAlias = function getArgumentsArrayAlias () {
  6917. if (!this.argumentsArrayAlias) {
  6918. this.argumentsArrayAlias = this.scope.createIdentifier('argsArray');
  6919. }
  6920. return this.argumentsArrayAlias;
  6921. };
  6922. BlockStatement.prototype.getThisAlias = function getThisAlias () {
  6923. if (!this.thisAlias) {
  6924. this.thisAlias = this.scope.createIdentifier('this');
  6925. }
  6926. return this.thisAlias;
  6927. };
  6928. BlockStatement.prototype.getIndentation = function getIndentation () {
  6929. if (this.indentation === undefined) {
  6930. var source = this.program.magicString.original;
  6931. var useOuter = this.synthetic || !this.body.length;
  6932. var c = useOuter ? this.start : this.body[0].start;
  6933. while (c && source[c] !== '\n') { c -= 1; }
  6934. this.indentation = '';
  6935. // eslint-disable-next-line no-constant-condition
  6936. while (true) {
  6937. c += 1;
  6938. var char = source[c];
  6939. if (char !== ' ' && char !== '\t') { break; }
  6940. this.indentation += char;
  6941. }
  6942. var indentString = this.program.magicString.getIndentString();
  6943. // account for dedented class constructors
  6944. var parent = this.parent;
  6945. while (parent) {
  6946. if (parent.kind === 'constructor' && !parent.parent.parent.superClass) {
  6947. this.indentation = this.indentation.replace(indentString, '');
  6948. }
  6949. parent = parent.parent;
  6950. }
  6951. if (useOuter) { this.indentation += indentString; }
  6952. }
  6953. return this.indentation;
  6954. };
  6955. BlockStatement.prototype.transpile = function transpile (code, transforms) {
  6956. var this$1 = this;
  6957. var indentation = this.getIndentation();
  6958. var introStatementGenerators = [];
  6959. if (this.argumentsAlias) {
  6960. introStatementGenerators.push(function (start, prefix, suffix) {
  6961. var assignment = prefix + "var " + (this$1.argumentsAlias) + " = arguments" + suffix;
  6962. code.appendLeft(start, assignment);
  6963. });
  6964. }
  6965. if (this.thisAlias) {
  6966. introStatementGenerators.push(function (start, prefix, suffix) {
  6967. var assignment = prefix + "var " + (this$1.thisAlias) + " = this" + suffix;
  6968. code.appendLeft(start, assignment);
  6969. });
  6970. }
  6971. if (this.argumentsArrayAlias) {
  6972. introStatementGenerators.push(function (start, prefix, suffix) {
  6973. var i = this$1.scope.createIdentifier('i');
  6974. var assignment = prefix + "var " + i + " = arguments.length, " + (this$1.argumentsArrayAlias) + " = Array(" + i + ");\n" + indentation + "while ( " + i + "-- ) " + (this$1.argumentsArrayAlias) + "[" + i + "] = arguments[" + i + "]" + suffix;
  6975. code.appendLeft(start, assignment);
  6976. });
  6977. }
  6978. if (/Function/.test(this.parent.type)) {
  6979. this.transpileParameters(
  6980. this.parent.params,
  6981. code,
  6982. transforms,
  6983. indentation,
  6984. introStatementGenerators
  6985. );
  6986. } else if ('CatchClause' === this.parent.type) {
  6987. this.transpileParameters(
  6988. [this.parent.param],
  6989. code,
  6990. transforms,
  6991. indentation,
  6992. introStatementGenerators
  6993. );
  6994. }
  6995. if (transforms.letConst && this.isFunctionBlock) {
  6996. this.transpileBlockScopedIdentifiers(code);
  6997. }
  6998. Node.prototype.transpile.call(this, code, transforms);
  6999. if (this.createdDeclarations.length) {
  7000. introStatementGenerators.push(function (start, prefix, suffix) {
  7001. var assignment = prefix + "var " + (this$1.createdDeclarations.join(', ')) + suffix;
  7002. code.appendLeft(start, assignment);
  7003. });
  7004. }
  7005. if (this.synthetic) {
  7006. if (this.parent.type === 'ArrowFunctionExpression') {
  7007. var expr = this.body[0];
  7008. if (introStatementGenerators.length) {
  7009. code
  7010. .appendLeft(this.start, "{")
  7011. .prependRight(this.end, ((this.parent.getIndentation()) + "}"));
  7012. code.prependRight(expr.start, ("\n" + indentation + "return "));
  7013. code.appendLeft(expr.end, ";\n");
  7014. } else if (transforms.arrow) {
  7015. code.prependRight(expr.start, "{ return ");
  7016. code.appendLeft(expr.end, "; }");
  7017. }
  7018. } else if (introStatementGenerators.length) {
  7019. code.prependRight(this.start, "{").appendLeft(this.end, "}");
  7020. }
  7021. }
  7022. var start;
  7023. if (isUseStrict(this.body[0])) {
  7024. start = this.body[0].end;
  7025. } else if (this.synthetic || this.parent.type === 'Root') {
  7026. start = this.start;
  7027. } else {
  7028. start = this.start + 1;
  7029. }
  7030. var prefix = "\n" + indentation;
  7031. var suffix = ';';
  7032. introStatementGenerators.forEach(function (fn, i) {
  7033. if (i === introStatementGenerators.length - 1) { suffix = ";\n"; }
  7034. fn(start, prefix, suffix);
  7035. });
  7036. };
  7037. BlockStatement.prototype.transpileParameters = function transpileParameters (params, code, transforms, indentation, introStatementGenerators) {
  7038. var this$1 = this;
  7039. params.forEach(function (param) {
  7040. if (
  7041. param.type === 'AssignmentPattern' &&
  7042. param.left.type === 'Identifier'
  7043. ) {
  7044. if (transforms.defaultParameter) {
  7045. introStatementGenerators.push(function (start, prefix, suffix) {
  7046. var lhs = prefix + "if ( " + (param.left.name) + " === void 0 ) " + (param.left.name);
  7047. code
  7048. .prependRight(param.left.end, lhs)
  7049. .move(param.left.end, param.right.end, start)
  7050. .appendLeft(param.right.end, suffix);
  7051. });
  7052. }
  7053. } else if (param.type === 'RestElement') {
  7054. if (transforms.spreadRest) {
  7055. introStatementGenerators.push(function (start, prefix, suffix) {
  7056. var penultimateParam = params[params.length - 2];
  7057. if (penultimateParam) {
  7058. code.remove(
  7059. penultimateParam ? penultimateParam.end : param.start,
  7060. param.end
  7061. );
  7062. } else {
  7063. var start$1 = param.start,
  7064. end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8
  7065. while (/\s/.test(code.original[start$1 - 1])) { start$1 -= 1; }
  7066. while (/\s/.test(code.original[end])) { end += 1; }
  7067. code.remove(start$1, end);
  7068. }
  7069. var name = param.argument.name;
  7070. var len = this$1.scope.createIdentifier('len');
  7071. var count = params.length - 1;
  7072. if (count) {
  7073. code.prependRight(
  7074. start,
  7075. (prefix + "var " + name + " = [], " + len + " = arguments.length - " + count + ";\n" + indentation + "while ( " + len + "-- > 0 ) " + name + "[ " + len + " ] = arguments[ " + len + " + " + count + " ]" + suffix)
  7076. );
  7077. } else {
  7078. code.prependRight(
  7079. start,
  7080. (prefix + "var " + name + " = [], " + len + " = arguments.length;\n" + indentation + "while ( " + len + "-- ) " + name + "[ " + len + " ] = arguments[ " + len + " ]" + suffix)
  7081. );
  7082. }
  7083. });
  7084. }
  7085. } else if (param.type !== 'Identifier') {
  7086. if (transforms.parameterDestructuring) {
  7087. var ref = this$1.scope.createIdentifier('ref');
  7088. destructure(
  7089. code,
  7090. function (id) { return this$1.scope.createIdentifier(id); },
  7091. function (ref) {
  7092. var name = ref.name;
  7093. return this$1.scope.resolveName(name);
  7094. },
  7095. param,
  7096. ref,
  7097. false,
  7098. introStatementGenerators
  7099. );
  7100. code.prependRight(param.start, ref);
  7101. }
  7102. }
  7103. });
  7104. };
  7105. BlockStatement.prototype.transpileBlockScopedIdentifiers = function transpileBlockScopedIdentifiers (code) {
  7106. var this$1 = this;
  7107. Object.keys(this.scope.blockScopedDeclarations).forEach(function (name) {
  7108. var declarations = this$1.scope.blockScopedDeclarations[name];
  7109. for (var i$2 = 0, list$2 = declarations; i$2 < list$2.length; i$2 += 1) {
  7110. var declaration = list$2[i$2];
  7111. var cont = false; // TODO implement proper continue...
  7112. if (declaration.kind === 'for.let') {
  7113. // special case
  7114. var forStatement = declaration.node.findNearest('ForStatement');
  7115. if (forStatement.shouldRewriteAsFunction) {
  7116. var outerAlias = this$1.scope.createIdentifier(name);
  7117. var innerAlias = forStatement.reassigned[name]
  7118. ? this$1.scope.createIdentifier(name)
  7119. : name;
  7120. declaration.name = outerAlias;
  7121. code.overwrite(
  7122. declaration.node.start,
  7123. declaration.node.end,
  7124. outerAlias,
  7125. { storeName: true }
  7126. );
  7127. forStatement.aliases[name] = {
  7128. outer: outerAlias,
  7129. inner: innerAlias
  7130. };
  7131. for (var i = 0, list = declaration.instances; i < list.length; i += 1) {
  7132. var identifier = list[i];
  7133. var alias = forStatement.body.contains(identifier)
  7134. ? innerAlias
  7135. : outerAlias;
  7136. if (name !== alias) {
  7137. code.overwrite(identifier.start, identifier.end, alias, {
  7138. storeName: true
  7139. });
  7140. }
  7141. }
  7142. cont = true;
  7143. }
  7144. }
  7145. if (!cont) {
  7146. var alias$1 = this$1.scope.createIdentifier(name);
  7147. if (name !== alias$1) {
  7148. declaration.name = alias$1;
  7149. code.overwrite(
  7150. declaration.node.start,
  7151. declaration.node.end,
  7152. alias$1,
  7153. { storeName: true }
  7154. );
  7155. for (var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1) {
  7156. var identifier$1 = list$1[i$1];
  7157. identifier$1.rewritten = true;
  7158. code.overwrite(identifier$1.start, identifier$1.end, alias$1, {
  7159. storeName: true
  7160. });
  7161. }
  7162. }
  7163. }
  7164. }
  7165. });
  7166. };
  7167. return BlockStatement;
  7168. }(Node$1));
  7169. function isArguments(node) {
  7170. return node.type === 'Identifier' && node.name === 'arguments';
  7171. }
  7172. function spread(
  7173. code,
  7174. elements,
  7175. start,
  7176. argumentsArrayAlias,
  7177. isNew
  7178. ) {
  7179. var i = elements.length;
  7180. var firstSpreadIndex = -1;
  7181. while (i--) {
  7182. var element$1 = elements[i];
  7183. if (element$1 && element$1.type === 'SpreadElement') {
  7184. if (isArguments(element$1.argument)) {
  7185. code.overwrite(
  7186. element$1.argument.start,
  7187. element$1.argument.end,
  7188. argumentsArrayAlias
  7189. );
  7190. }
  7191. firstSpreadIndex = i;
  7192. }
  7193. }
  7194. if (firstSpreadIndex === -1) { return false; } // false indicates no spread elements
  7195. if (isNew) {
  7196. for (i = 0; i < elements.length; i += 1) {
  7197. var element$2 = elements[i];
  7198. if (element$2.type === 'SpreadElement') {
  7199. code.remove(element$2.start, element$2.argument.start);
  7200. } else {
  7201. code.prependRight(element$2.start, '[');
  7202. code.prependRight(element$2.end, ']');
  7203. }
  7204. }
  7205. return true; // true indicates some spread elements
  7206. }
  7207. var element = elements[firstSpreadIndex];
  7208. var previousElement = elements[firstSpreadIndex - 1];
  7209. if (!previousElement) {
  7210. code.remove(start, element.start);
  7211. code.overwrite(element.end, elements[1].start, '.concat( ');
  7212. } else {
  7213. code.overwrite(previousElement.end, element.start, ' ].concat( ');
  7214. }
  7215. for (i = firstSpreadIndex; i < elements.length; i += 1) {
  7216. element = elements[i];
  7217. if (element) {
  7218. if (element.type === 'SpreadElement') {
  7219. code.remove(element.start, element.argument.start);
  7220. } else {
  7221. code.appendLeft(element.start, '[');
  7222. code.appendLeft(element.end, ']');
  7223. }
  7224. }
  7225. }
  7226. return true; // true indicates some spread elements
  7227. }
  7228. var ArrayExpression = /*@__PURE__*/(function (Node) {
  7229. function ArrayExpression () {
  7230. Node.apply(this, arguments);
  7231. }
  7232. if ( Node ) ArrayExpression.__proto__ = Node;
  7233. ArrayExpression.prototype = Object.create( Node && Node.prototype );
  7234. ArrayExpression.prototype.constructor = ArrayExpression;
  7235. ArrayExpression.prototype.initialise = function initialise (transforms) {
  7236. if (transforms.spreadRest && this.elements.length) {
  7237. var lexicalBoundary = this.findLexicalBoundary();
  7238. var i = this.elements.length;
  7239. while (i--) {
  7240. var element = this.elements[i];
  7241. if (
  7242. element &&
  7243. element.type === 'SpreadElement' &&
  7244. isArguments(element.argument)
  7245. ) {
  7246. this.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
  7247. }
  7248. }
  7249. }
  7250. Node.prototype.initialise.call(this, transforms);
  7251. };
  7252. ArrayExpression.prototype.transpile = function transpile (code, transforms) {
  7253. Node.prototype.transpile.call(this, code, transforms);
  7254. if (transforms.spreadRest) {
  7255. // erase trailing comma after last array element if not an array hole
  7256. if (this.elements.length) {
  7257. var lastElement = this.elements[this.elements.length - 1];
  7258. if (
  7259. lastElement &&
  7260. /\s*,/.test(code.original.slice(lastElement.end, this.end))
  7261. ) {
  7262. code.overwrite(lastElement.end, this.end - 1, ' ');
  7263. }
  7264. }
  7265. if (this.elements.length === 1) {
  7266. var element = this.elements[0];
  7267. if (element && element.type === 'SpreadElement') {
  7268. // special case – [ ...arguments ]
  7269. if (isArguments(element.argument)) {
  7270. code.overwrite(
  7271. this.start,
  7272. this.end,
  7273. ("[].concat( " + (this.argumentsArrayAlias) + " )")
  7274. ); // TODO if this is the only use of argsArray, don't bother concating
  7275. } else {
  7276. code.overwrite(this.start, element.argument.start, '[].concat( ');
  7277. code.overwrite(element.end, this.end, ' )');
  7278. }
  7279. }
  7280. } else {
  7281. var hasSpreadElements = spread(
  7282. code,
  7283. this.elements,
  7284. this.start,
  7285. this.argumentsArrayAlias
  7286. );
  7287. if (hasSpreadElements) {
  7288. code.overwrite(this.end - 1, this.end, ')');
  7289. }
  7290. }
  7291. }
  7292. };
  7293. return ArrayExpression;
  7294. }(Node$1));
  7295. function removeTrailingComma(code, c) {
  7296. while (code.original[c] !== ')') {
  7297. if (code.original[c] === ',') {
  7298. code.remove(c, c + 1);
  7299. return;
  7300. }
  7301. if (code.original[c] === '/') {
  7302. c = code.original.indexOf(code.original[c + 1] === '/' ? '\n' : '*/', c) + 1;
  7303. }
  7304. c += 1;
  7305. }
  7306. }
  7307. var ArrowFunctionExpression = /*@__PURE__*/(function (Node) {
  7308. function ArrowFunctionExpression () {
  7309. Node.apply(this, arguments);
  7310. }
  7311. if ( Node ) ArrowFunctionExpression.__proto__ = Node;
  7312. ArrowFunctionExpression.prototype = Object.create( Node && Node.prototype );
  7313. ArrowFunctionExpression.prototype.constructor = ArrowFunctionExpression;
  7314. ArrowFunctionExpression.prototype.initialise = function initialise (transforms) {
  7315. this.body.createScope();
  7316. Node.prototype.initialise.call(this, transforms);
  7317. };
  7318. ArrowFunctionExpression.prototype.transpile = function transpile (code, transforms) {
  7319. var naked = this.params.length === 1 && this.start === this.params[0].start;
  7320. if (transforms.arrow || this.needsArguments(transforms)) {
  7321. // remove arrow
  7322. var charIndex = this.body.start;
  7323. while (code.original[charIndex] !== '=') {
  7324. charIndex -= 1;
  7325. }
  7326. code.remove(charIndex, this.body.start);
  7327. Node.prototype.transpile.call(this, code, transforms);
  7328. // wrap naked parameter
  7329. if (naked) {
  7330. code.prependRight(this.params[0].start, '(');
  7331. code.appendLeft(this.params[0].end, ')');
  7332. }
  7333. // add function
  7334. if (this.parent && this.parent.type === 'ExpressionStatement') {
  7335. // standalone expression statement
  7336. code.prependRight(this.start, '!function');
  7337. } else {
  7338. code.prependRight(this.start, 'function ');
  7339. }
  7340. } else {
  7341. Node.prototype.transpile.call(this, code, transforms);
  7342. }
  7343. if (transforms.trailingFunctionCommas && this.params.length && !naked) {
  7344. removeTrailingComma(code, this.params[this.params.length - 1].end);
  7345. }
  7346. };
  7347. // Returns whether any transforms that will happen use `arguments`
  7348. ArrowFunctionExpression.prototype.needsArguments = function needsArguments (transforms) {
  7349. return (
  7350. transforms.spreadRest &&
  7351. this.params.filter(function (param) { return param.type === 'RestElement'; }).length > 0
  7352. );
  7353. };
  7354. return ArrowFunctionExpression;
  7355. }(Node$1));
  7356. function checkConst(identifier, scope) {
  7357. var declaration = scope.findDeclaration(identifier.name);
  7358. if (declaration && declaration.kind === 'const') {
  7359. throw new CompileError(((identifier.name) + " is read-only"), identifier);
  7360. }
  7361. }
  7362. var AssignmentExpression = /*@__PURE__*/(function (Node) {
  7363. function AssignmentExpression () {
  7364. Node.apply(this, arguments);
  7365. }
  7366. if ( Node ) AssignmentExpression.__proto__ = Node;
  7367. AssignmentExpression.prototype = Object.create( Node && Node.prototype );
  7368. AssignmentExpression.prototype.constructor = AssignmentExpression;
  7369. AssignmentExpression.prototype.initialise = function initialise (transforms) {
  7370. if (this.left.type === 'Identifier') {
  7371. var declaration = this.findScope(false).findDeclaration(this.left.name);
  7372. // special case – https://gitlab.com/Rich-Harris/buble/issues/11
  7373. var statement = declaration && declaration.node.ancestor(3);
  7374. if (
  7375. statement &&
  7376. statement.type === 'ForStatement' &&
  7377. statement.body.contains(this)
  7378. ) {
  7379. statement.reassigned[this.left.name] = true;
  7380. }
  7381. }
  7382. Node.prototype.initialise.call(this, transforms);
  7383. };
  7384. AssignmentExpression.prototype.transpile = function transpile (code, transforms) {
  7385. if (this.left.type === 'Identifier') {
  7386. // Do this check after everything has been initialized to find
  7387. // shadowing declarations after this expression
  7388. checkConst(this.left, this.findScope(false));
  7389. }
  7390. if (this.operator === '**=' && transforms.exponentiation) {
  7391. this.transpileExponentiation(code, transforms);
  7392. } else if (/Pattern/.test(this.left.type) && transforms.destructuring) {
  7393. this.transpileDestructuring(code, transforms);
  7394. }
  7395. Node.prototype.transpile.call(this, code, transforms);
  7396. };
  7397. AssignmentExpression.prototype.transpileDestructuring = function transpileDestructuring (code) {
  7398. var this$1 = this;
  7399. var writeScope = this.findScope(true);
  7400. var lookupScope = this.findScope(false);
  7401. var assign = writeScope.createDeclaration('assign');
  7402. code.appendRight(this.left.end, ("(" + assign));
  7403. code.appendLeft(this.right.end, ', ');
  7404. var statementGenerators = [];
  7405. destructure(
  7406. code,
  7407. function (id) { return writeScope.createDeclaration(id); },
  7408. function (node) {
  7409. var name = lookupScope.resolveName(node.name);
  7410. checkConst(node, lookupScope);
  7411. return name;
  7412. },
  7413. this.left,
  7414. assign,
  7415. true,
  7416. statementGenerators
  7417. );
  7418. var suffix = ', ';
  7419. statementGenerators.forEach(function (fn, j) {
  7420. if (j === statementGenerators.length - 1) {
  7421. suffix = '';
  7422. }
  7423. fn(this$1.end, '', suffix);
  7424. });
  7425. if (this.unparenthesizedParent().type === 'ExpressionStatement') {
  7426. // no rvalue needed for expression statement
  7427. code.appendRight(this.end, ")");
  7428. } else {
  7429. // destructuring is part of an expression - need an rvalue
  7430. code.appendRight(this.end, (", " + assign + ")"));
  7431. }
  7432. };
  7433. AssignmentExpression.prototype.transpileExponentiation = function transpileExponentiation (code) {
  7434. var scope = this.findScope(false);
  7435. // first, the easy part – `**=` -> `=`
  7436. var charIndex = this.left.end;
  7437. while (code.original[charIndex] !== '*') { charIndex += 1; }
  7438. code.remove(charIndex, charIndex + 2);
  7439. // how we do the next part depends on a number of factors – whether
  7440. // this is a top-level statement, and whether we're updating a
  7441. // simple or complex reference
  7442. var base;
  7443. var left = this.left.unparenthesize();
  7444. if (left.type === 'Identifier') {
  7445. base = scope.resolveName(left.name);
  7446. } else if (left.type === 'MemberExpression') {
  7447. var object;
  7448. var needsObjectVar = false;
  7449. var property;
  7450. var needsPropertyVar = false;
  7451. var statement = this.findNearest(/(?:Statement|Declaration)$/);
  7452. var i0 = statement.getIndentation();
  7453. if (left.property.type === 'Identifier') {
  7454. property = left.computed
  7455. ? scope.resolveName(left.property.name)
  7456. : left.property.name;
  7457. } else {
  7458. property = scope.createDeclaration('property');
  7459. needsPropertyVar = true;
  7460. }
  7461. if (left.object.type === 'Identifier') {
  7462. object = scope.resolveName(left.object.name);
  7463. } else {
  7464. object = scope.createDeclaration('object');
  7465. needsObjectVar = true;
  7466. }
  7467. if (left.start === statement.start) {
  7468. if (needsObjectVar && needsPropertyVar) {
  7469. code.prependRight(statement.start, (object + " = "));
  7470. code.overwrite(
  7471. left.object.end,
  7472. left.property.start,
  7473. (";\n" + i0 + property + " = ")
  7474. );
  7475. code.overwrite(
  7476. left.property.end,
  7477. left.end,
  7478. (";\n" + i0 + object + "[" + property + "]")
  7479. );
  7480. } else if (needsObjectVar) {
  7481. code.prependRight(statement.start, (object + " = "));
  7482. code.appendLeft(left.object.end, (";\n" + i0));
  7483. code.appendLeft(left.object.end, object);
  7484. } else if (needsPropertyVar) {
  7485. code.prependRight(left.property.start, (property + " = "));
  7486. code.appendLeft(left.property.end, (";\n" + i0));
  7487. code.move(left.property.start, left.property.end, this.start);
  7488. code.appendLeft(left.object.end, ("[" + property + "]"));
  7489. code.remove(left.object.end, left.property.start);
  7490. code.remove(left.property.end, left.end);
  7491. }
  7492. } else {
  7493. if (needsObjectVar && needsPropertyVar) {
  7494. code.prependRight(left.start, ("( " + object + " = "));
  7495. code.overwrite(
  7496. left.object.end,
  7497. left.property.start,
  7498. (", " + property + " = ")
  7499. );
  7500. code.overwrite(
  7501. left.property.end,
  7502. left.end,
  7503. (", " + object + "[" + property + "]")
  7504. );
  7505. } else if (needsObjectVar) {
  7506. code.prependRight(left.start, ("( " + object + " = "));
  7507. code.appendLeft(left.object.end, (", " + object));
  7508. } else if (needsPropertyVar) {
  7509. code.prependRight(left.property.start, ("( " + property + " = "));
  7510. code.appendLeft(left.property.end, ", ");
  7511. code.move(left.property.start, left.property.end, left.start);
  7512. code.overwrite(left.object.end, left.property.start, ("[" + property + "]"));
  7513. code.remove(left.property.end, left.end);
  7514. }
  7515. if (needsPropertyVar) {
  7516. code.appendLeft(this.end, " )");
  7517. }
  7518. }
  7519. base =
  7520. object +
  7521. (left.computed || needsPropertyVar ? ("[" + property + "]") : ("." + property));
  7522. }
  7523. code.prependRight(this.right.start, ("Math.pow( " + base + ", "));
  7524. code.appendLeft(this.right.end, " )");
  7525. };
  7526. return AssignmentExpression;
  7527. }(Node$1));
  7528. var BinaryExpression = /*@__PURE__*/(function (Node) {
  7529. function BinaryExpression () {
  7530. Node.apply(this, arguments);
  7531. }
  7532. if ( Node ) BinaryExpression.__proto__ = Node;
  7533. BinaryExpression.prototype = Object.create( Node && Node.prototype );
  7534. BinaryExpression.prototype.constructor = BinaryExpression;
  7535. BinaryExpression.prototype.transpile = function transpile (code, transforms) {
  7536. if (this.operator === '**' && transforms.exponentiation) {
  7537. code.prependRight(this.start, "Math.pow( ");
  7538. code.overwrite(this.left.end, this.right.start, ", ");
  7539. code.appendLeft(this.end, " )");
  7540. }
  7541. Node.prototype.transpile.call(this, code, transforms);
  7542. };
  7543. return BinaryExpression;
  7544. }(Node$1));
  7545. var loopStatement = /(?:For(?:In|Of)?|While)Statement/;
  7546. var BreakStatement = /*@__PURE__*/(function (Node) {
  7547. function BreakStatement () {
  7548. Node.apply(this, arguments);
  7549. }
  7550. if ( Node ) BreakStatement.__proto__ = Node;
  7551. BreakStatement.prototype = Object.create( Node && Node.prototype );
  7552. BreakStatement.prototype.constructor = BreakStatement;
  7553. BreakStatement.prototype.initialise = function initialise () {
  7554. var loop = this.findNearest(loopStatement);
  7555. var switchCase = this.findNearest('SwitchCase');
  7556. if (loop && (!switchCase || loop.depth > switchCase.depth)) {
  7557. loop.canBreak = true;
  7558. this.loop = loop;
  7559. }
  7560. };
  7561. BreakStatement.prototype.transpile = function transpile (code) {
  7562. if (this.loop && this.loop.shouldRewriteAsFunction) {
  7563. if (this.label)
  7564. { throw new CompileError(
  7565. 'Labels are not currently supported in a loop with locally-scoped variables',
  7566. this
  7567. ); }
  7568. code.overwrite(this.start, this.start + 5, "return 'break'");
  7569. }
  7570. };
  7571. return BreakStatement;
  7572. }(Node$1));
  7573. // allowed globals in Vue render functions.
  7574. // same as in src/core/instance/proxy.js
  7575. var names = 'Infinity,undefined,NaN,isFinite,isNaN,' +
  7576. 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
  7577. 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
  7578. 'require,' + // for webpack
  7579. 'arguments,' + // parsed as identifier but is a special keyword...
  7580. '_h,_c'; // cached to save property access (_c for ^2.1.5)
  7581. var hash = Object.create(null);
  7582. names.split(',').forEach(function (name) {
  7583. hash[name] = true;
  7584. });
  7585. var isDeclaration = function (type) { return /Declaration$/.test(type); };
  7586. var isFunction = function (type) { return /Function(Expression|Declaration)$/.test(type); };
  7587. function shouldPrependVm (identifier) {
  7588. if (
  7589. identifier.program.inWith > 0 &&
  7590. // not id of a Declaration
  7591. !(isDeclaration(identifier.parent.type) && identifier.parent.id === identifier) &&
  7592. // not a params of a function
  7593. !(isFunction(identifier.parent.type) && identifier.parent.params.indexOf(identifier) > -1) &&
  7594. // not a key of Property
  7595. !(identifier.parent.type === 'Property' && identifier.parent.key === identifier && !identifier.parent.computed) &&
  7596. // not a property of a MemberExpression
  7597. !(identifier.parent.type === 'MemberExpression' && identifier.parent.property === identifier && !identifier.parent.computed) &&
  7598. // not in an Array destructure pattern
  7599. !(identifier.parent.type === 'ArrayPattern') &&
  7600. // not in an Object destructure pattern
  7601. !(identifier.parent.parent.type === 'ObjectPattern') &&
  7602. // skip globals + commonly used shorthands
  7603. !hash[identifier.name] &&
  7604. // not already in scope
  7605. !identifier.findScope(false).contains(identifier.name)
  7606. ) {
  7607. return true;
  7608. }
  7609. }
  7610. var CallExpression = /*@__PURE__*/(function (Node) {
  7611. function CallExpression () {
  7612. Node.apply(this, arguments);
  7613. }
  7614. if ( Node ) CallExpression.__proto__ = Node;
  7615. CallExpression.prototype = Object.create( Node && Node.prototype );
  7616. CallExpression.prototype.constructor = CallExpression;
  7617. CallExpression.prototype.initialise = function initialise (transforms) {
  7618. if (transforms.spreadRest && this.arguments.length > 1) {
  7619. var lexicalBoundary = this.findLexicalBoundary();
  7620. var i = this.arguments.length;
  7621. while (i--) {
  7622. var arg = this.arguments[i];
  7623. if (arg.type === 'SpreadElement' && isArguments(arg.argument)) {
  7624. this.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
  7625. }
  7626. }
  7627. }
  7628. Node.prototype.initialise.call(this, transforms);
  7629. };
  7630. CallExpression.prototype.transpile = function transpile (code, transforms) {
  7631. if (transforms.spreadRest && this.arguments.length) {
  7632. var hasSpreadElements = false;
  7633. var context;
  7634. var firstArgument = this.arguments[0];
  7635. if (this.arguments.length === 1) {
  7636. if (firstArgument.type === 'SpreadElement') {
  7637. code.remove(firstArgument.start, firstArgument.argument.start);
  7638. hasSpreadElements = true;
  7639. }
  7640. } else {
  7641. hasSpreadElements = spread(
  7642. code,
  7643. this.arguments,
  7644. firstArgument.start,
  7645. this.argumentsArrayAlias
  7646. );
  7647. }
  7648. if (hasSpreadElements) {
  7649. // we need to handle super() and super.method() differently
  7650. // due to its instance
  7651. var _super = null;
  7652. if (this.callee.type === 'Super') {
  7653. _super = this.callee;
  7654. } else if (
  7655. this.callee.type === 'MemberExpression' &&
  7656. this.callee.object.type === 'Super'
  7657. ) {
  7658. _super = this.callee.object;
  7659. }
  7660. if ( !_super && this.callee.type === 'MemberExpression' ) {
  7661. if ( this.callee.object.type === 'Identifier' ) {
  7662. var callee = this.callee.object;
  7663. context = shouldPrependVm(callee) ? ("_vm." + (callee.name)) : callee.name;
  7664. } else {
  7665. context = this.findScope(true).createDeclaration('ref');
  7666. var callExpression = this.callee.object;
  7667. code.prependRight(callExpression.start, ("(" + context + " = "));
  7668. code.appendLeft(callExpression.end, ")");
  7669. }
  7670. } else {
  7671. context = 'void 0';
  7672. }
  7673. code.appendLeft(this.callee.end, '.apply');
  7674. if (_super) {
  7675. _super.noCall = true; // bit hacky...
  7676. if (this.arguments.length > 1) {
  7677. if (firstArgument.type !== 'SpreadElement') {
  7678. code.prependRight(firstArgument.start, "[ ");
  7679. }
  7680. code.appendLeft(
  7681. this.arguments[this.arguments.length - 1].end,
  7682. ' )'
  7683. );
  7684. }
  7685. } else if (this.arguments.length === 1) {
  7686. code.prependRight(firstArgument.start, (context + ", "));
  7687. } else {
  7688. if (firstArgument.type === 'SpreadElement') {
  7689. code.appendLeft(firstArgument.start, (context + ", "));
  7690. } else {
  7691. code.appendLeft(firstArgument.start, (context + ", [ "));
  7692. }
  7693. code.appendLeft(this.arguments[this.arguments.length - 1].end, ' )');
  7694. }
  7695. }
  7696. }
  7697. if (transforms.trailingFunctionCommas && this.arguments.length) {
  7698. removeTrailingComma(code, this.arguments[this.arguments.length - 1].end);
  7699. }
  7700. Node.prototype.transpile.call(this, code, transforms);
  7701. };
  7702. return CallExpression;
  7703. }(Node$1));
  7704. // TODO this code is pretty wild, tidy it up
  7705. var ClassBody = /*@__PURE__*/(function (Node) {
  7706. function ClassBody () {
  7707. Node.apply(this, arguments);
  7708. }
  7709. if ( Node ) ClassBody.__proto__ = Node;
  7710. ClassBody.prototype = Object.create( Node && Node.prototype );
  7711. ClassBody.prototype.constructor = ClassBody;
  7712. ClassBody.prototype.transpile = function transpile (code, transforms, inFunctionExpression, superName) {
  7713. var this$1 = this;
  7714. if (transforms.classes) {
  7715. var name = this.parent.name;
  7716. var indentStr = code.getIndentString();
  7717. var i0 =
  7718. this.getIndentation() + (inFunctionExpression ? indentStr : '');
  7719. var i1 = i0 + indentStr;
  7720. var constructorIndex = findIndex(
  7721. this.body,
  7722. function (node) { return node.kind === 'constructor'; }
  7723. );
  7724. var constructor = this.body[constructorIndex];
  7725. var introBlock = '';
  7726. var outroBlock = '';
  7727. if (this.body.length) {
  7728. code.remove(this.start, this.body[0].start);
  7729. code.remove(this.body[this.body.length - 1].end, this.end);
  7730. } else {
  7731. code.remove(this.start, this.end);
  7732. }
  7733. if (constructor) {
  7734. constructor.value.body.isConstructorBody = true;
  7735. var previousMethod = this.body[constructorIndex - 1];
  7736. var nextMethod = this.body[constructorIndex + 1];
  7737. // ensure constructor is first
  7738. if (constructorIndex > 0) {
  7739. code.remove(previousMethod.end, constructor.start);
  7740. code.move(
  7741. constructor.start,
  7742. nextMethod ? nextMethod.start : this.end - 1,
  7743. this.body[0].start
  7744. );
  7745. }
  7746. if (!inFunctionExpression) { code.appendLeft(constructor.end, ';'); }
  7747. }
  7748. var namedFunctions =
  7749. this.program.options.namedFunctionExpressions !== false;
  7750. var namedConstructor =
  7751. namedFunctions ||
  7752. this.parent.superClass ||
  7753. this.parent.type !== 'ClassDeclaration';
  7754. if (this.parent.superClass) {
  7755. var inheritanceBlock = "if ( " + superName + " ) " + name + ".__proto__ = " + superName + ";\n" + i0 + name + ".prototype = Object.create( " + superName + " && " + superName + ".prototype );\n" + i0 + name + ".prototype.constructor = " + name + ";";
  7756. if (constructor) {
  7757. introBlock += "\n\n" + i0 + inheritanceBlock;
  7758. } else {
  7759. var fn =
  7760. "function " + name + " () {" +
  7761. (superName
  7762. ? ("\n" + i1 + superName + ".apply(this, arguments);\n" + i0 + "}")
  7763. : "}") +
  7764. (inFunctionExpression ? '' : ';') +
  7765. (this.body.length ? ("\n\n" + i0) : '');
  7766. inheritanceBlock = fn + inheritanceBlock;
  7767. introBlock += inheritanceBlock + "\n\n" + i0;
  7768. }
  7769. } else if (!constructor) {
  7770. var fn$1 = 'function ' + (namedConstructor ? name + ' ' : '') + '() {}';
  7771. if (this.parent.type === 'ClassDeclaration') { fn$1 += ';'; }
  7772. if (this.body.length) { fn$1 += "\n\n" + i0; }
  7773. introBlock += fn$1;
  7774. }
  7775. var scope = this.findScope(false);
  7776. var prototypeGettersAndSetters = [];
  7777. var staticGettersAndSetters = [];
  7778. var prototypeAccessors;
  7779. var staticAccessors;
  7780. this.body.forEach(function (method, i) {
  7781. if (method.kind === 'constructor') {
  7782. var constructorName = namedConstructor ? ' ' + name : '';
  7783. code.overwrite(
  7784. method.key.start,
  7785. method.key.end,
  7786. ("function" + constructorName)
  7787. );
  7788. return;
  7789. }
  7790. if (method.static) {
  7791. var len = code.original[method.start + 6] == ' ' ? 7 : 6;
  7792. code.remove(method.start, method.start + len);
  7793. }
  7794. var isAccessor = method.kind !== 'method';
  7795. var lhs;
  7796. var methodName = method.key.name;
  7797. if (
  7798. reserved[methodName] ||
  7799. method.value.body.scope.references[methodName]
  7800. ) {
  7801. methodName = scope.createIdentifier(methodName);
  7802. }
  7803. // when method name is a string or a number let's pretend it's a computed method
  7804. var fake_computed = false;
  7805. if (!method.computed && method.key.type === 'Literal') {
  7806. fake_computed = true;
  7807. method.computed = true;
  7808. }
  7809. if (isAccessor) {
  7810. if (method.computed) {
  7811. throw new Error(
  7812. 'Computed accessor properties are not currently supported'
  7813. );
  7814. }
  7815. code.remove(method.start, method.key.start);
  7816. if (method.static) {
  7817. if (!~staticGettersAndSetters.indexOf(method.key.name))
  7818. { staticGettersAndSetters.push(method.key.name); }
  7819. if (!staticAccessors)
  7820. { staticAccessors = scope.createIdentifier('staticAccessors'); }
  7821. lhs = "" + staticAccessors;
  7822. } else {
  7823. if (!~prototypeGettersAndSetters.indexOf(method.key.name))
  7824. { prototypeGettersAndSetters.push(method.key.name); }
  7825. if (!prototypeAccessors)
  7826. { prototypeAccessors = scope.createIdentifier('prototypeAccessors'); }
  7827. lhs = "" + prototypeAccessors;
  7828. }
  7829. } else {
  7830. lhs = method.static ? ("" + name) : (name + ".prototype");
  7831. }
  7832. if (!method.computed) { lhs += '.'; }
  7833. var insertNewlines =
  7834. (constructorIndex > 0 && i === constructorIndex + 1) ||
  7835. (i === 0 && constructorIndex === this$1.body.length - 1);
  7836. if (insertNewlines) { lhs = "\n\n" + i0 + lhs; }
  7837. var c = method.key.end;
  7838. if (method.computed) {
  7839. if (fake_computed) {
  7840. code.prependRight(method.key.start, '[');
  7841. code.appendLeft(method.key.end, ']');
  7842. } else {
  7843. while (code.original[c] !== ']') { c += 1; }
  7844. c += 1;
  7845. }
  7846. }
  7847. var funcName =
  7848. method.computed || isAccessor || !namedFunctions
  7849. ? ''
  7850. : (methodName + " ");
  7851. var rhs =
  7852. (isAccessor ? ("." + (method.kind)) : '') +
  7853. " = function" +
  7854. (method.value.generator ? '* ' : ' ') +
  7855. funcName;
  7856. code.remove(c, method.value.start);
  7857. code.prependRight(method.value.start, rhs);
  7858. code.appendLeft(method.end, ';');
  7859. if (method.value.generator) { code.remove(method.start, method.key.start); }
  7860. code.prependRight(method.start, lhs);
  7861. });
  7862. if (prototypeGettersAndSetters.length || staticGettersAndSetters.length) {
  7863. var intro = [];
  7864. var outro = [];
  7865. if (prototypeGettersAndSetters.length) {
  7866. intro.push(
  7867. ("var " + prototypeAccessors + " = { " + (prototypeGettersAndSetters
  7868. .map(function (name) { return (name + ": { configurable: true }"); })
  7869. .join(',')) + " };")
  7870. );
  7871. outro.push(
  7872. ("Object.defineProperties( " + name + ".prototype, " + prototypeAccessors + " );")
  7873. );
  7874. }
  7875. if (staticGettersAndSetters.length) {
  7876. intro.push(
  7877. ("var " + staticAccessors + " = { " + (staticGettersAndSetters
  7878. .map(function (name) { return (name + ": { configurable: true }"); })
  7879. .join(',')) + " };")
  7880. );
  7881. outro.push(("Object.defineProperties( " + name + ", " + staticAccessors + " );"));
  7882. }
  7883. if (constructor) { introBlock += "\n\n" + i0; }
  7884. introBlock += intro.join(("\n" + i0));
  7885. if (!constructor) { introBlock += "\n\n" + i0; }
  7886. outroBlock += "\n\n" + i0 + outro.join(("\n" + i0));
  7887. }
  7888. if (constructor) {
  7889. code.appendLeft(constructor.end, introBlock);
  7890. } else {
  7891. code.prependRight(this.start, introBlock);
  7892. }
  7893. code.appendLeft(this.end, outroBlock);
  7894. }
  7895. Node.prototype.transpile.call(this, code, transforms);
  7896. };
  7897. return ClassBody;
  7898. }(Node$1));
  7899. // TODO this function is slightly flawed – it works on the original string,
  7900. // not its current edited state.
  7901. // That's not a problem for the way that it's currently used, but it could
  7902. // be in future...
  7903. function deindent(node, code) {
  7904. var start = node.start;
  7905. var end = node.end;
  7906. var indentStr = code.getIndentString();
  7907. var indentStrLen = indentStr.length;
  7908. var indentStart = start - indentStrLen;
  7909. if (
  7910. !node.program.indentExclusions[indentStart] &&
  7911. code.original.slice(indentStart, start) === indentStr
  7912. ) {
  7913. code.remove(indentStart, start);
  7914. }
  7915. var pattern = new RegExp(indentStr + '\\S', 'g');
  7916. var slice = code.original.slice(start, end);
  7917. var match;
  7918. while ((match = pattern.exec(slice))) {
  7919. var removeStart = start + match.index;
  7920. if (!node.program.indentExclusions[removeStart]) {
  7921. code.remove(removeStart, removeStart + indentStrLen);
  7922. }
  7923. }
  7924. }
  7925. var ClassDeclaration = /*@__PURE__*/(function (Node) {
  7926. function ClassDeclaration () {
  7927. Node.apply(this, arguments);
  7928. }
  7929. if ( Node ) ClassDeclaration.__proto__ = Node;
  7930. ClassDeclaration.prototype = Object.create( Node && Node.prototype );
  7931. ClassDeclaration.prototype.constructor = ClassDeclaration;
  7932. ClassDeclaration.prototype.initialise = function initialise (transforms) {
  7933. if (this.id) {
  7934. this.name = this.id.name;
  7935. this.findScope(true).addDeclaration(this.id, 'class');
  7936. } else {
  7937. this.name = this.findScope(true).createIdentifier("defaultExport");
  7938. }
  7939. Node.prototype.initialise.call(this, transforms);
  7940. };
  7941. ClassDeclaration.prototype.transpile = function transpile (code, transforms) {
  7942. if (transforms.classes) {
  7943. if (!this.superClass) { deindent(this.body, code); }
  7944. var superName =
  7945. this.superClass && (this.superClass.name || 'superclass');
  7946. var i0 = this.getIndentation();
  7947. var i1 = i0 + code.getIndentString();
  7948. // if this is an export default statement, we have to move the export to
  7949. // after the declaration, because `export default var Foo = ...` is illegal
  7950. var isExportDefaultDeclaration = this.parent.type === 'ExportDefaultDeclaration';
  7951. if (isExportDefaultDeclaration) {
  7952. code.remove(this.parent.start, this.start);
  7953. }
  7954. var c = this.start;
  7955. if (this.id) {
  7956. code.overwrite(c, this.id.start, 'var ');
  7957. c = this.id.end;
  7958. } else {
  7959. code.prependLeft(c, ("var " + (this.name)));
  7960. }
  7961. if (this.superClass) {
  7962. if (this.superClass.end === this.body.start) {
  7963. code.remove(c, this.superClass.start);
  7964. code.appendLeft(c, (" = (function (" + superName + ") {\n" + i1));
  7965. } else {
  7966. code.overwrite(c, this.superClass.start, ' = ');
  7967. code.overwrite(
  7968. this.superClass.end,
  7969. this.body.start,
  7970. ("(function (" + superName + ") {\n" + i1)
  7971. );
  7972. }
  7973. } else {
  7974. if (c === this.body.start) {
  7975. code.appendLeft(c, ' = ');
  7976. } else {
  7977. code.overwrite(c, this.body.start, ' = ');
  7978. }
  7979. }
  7980. this.body.transpile(code, transforms, !!this.superClass, superName);
  7981. var syntheticDefaultExport =
  7982. isExportDefaultDeclaration
  7983. ? ("\n\n" + i0 + "export default " + (this.name) + ";")
  7984. : '';
  7985. if (this.superClass) {
  7986. code.appendLeft(this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}("));
  7987. code.move(this.superClass.start, this.superClass.end, this.end);
  7988. code.prependRight(this.end, ("));" + syntheticDefaultExport));
  7989. } else if (syntheticDefaultExport) {
  7990. code.prependRight(this.end, syntheticDefaultExport);
  7991. }
  7992. } else {
  7993. this.body.transpile(code, transforms, false, null);
  7994. }
  7995. };
  7996. return ClassDeclaration;
  7997. }(Node$1));
  7998. var ClassExpression = /*@__PURE__*/(function (Node) {
  7999. function ClassExpression () {
  8000. Node.apply(this, arguments);
  8001. }
  8002. if ( Node ) ClassExpression.__proto__ = Node;
  8003. ClassExpression.prototype = Object.create( Node && Node.prototype );
  8004. ClassExpression.prototype.constructor = ClassExpression;
  8005. ClassExpression.prototype.initialise = function initialise (transforms) {
  8006. this.name = ( this.id
  8007. ? this.id.name
  8008. : this.parent.type === 'VariableDeclarator'
  8009. ? this.parent.id.name
  8010. : this.parent.type !== 'AssignmentExpression'
  8011. ? null
  8012. : this.parent.left.type === 'Identifier'
  8013. ? this.parent.left.name
  8014. : this.parent.left.type === 'MemberExpression'
  8015. ? this.parent.left.property.name
  8016. : null ) || this.findScope(true).createIdentifier('anonymous');
  8017. Node.prototype.initialise.call(this, transforms);
  8018. };
  8019. ClassExpression.prototype.transpile = function transpile (code, transforms) {
  8020. if (transforms.classes) {
  8021. var superName =
  8022. this.superClass && (this.superClass.name || 'superclass');
  8023. var i0 = this.getIndentation();
  8024. var i1 = i0 + code.getIndentString();
  8025. if (this.superClass) {
  8026. code.remove(this.start, this.superClass.start);
  8027. code.remove(this.superClass.end, this.body.start);
  8028. code.appendLeft(this.start, ("(function (" + superName + ") {\n" + i1));
  8029. } else {
  8030. code.overwrite(this.start, this.body.start, ("(function () {\n" + i1));
  8031. }
  8032. this.body.transpile(code, transforms, true, superName);
  8033. var outro = "\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(";
  8034. if (this.superClass) {
  8035. code.appendLeft(this.end, outro);
  8036. code.move(this.superClass.start, this.superClass.end, this.end);
  8037. code.prependRight(this.end, '))');
  8038. } else {
  8039. code.appendLeft(this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}())"));
  8040. }
  8041. } else {
  8042. this.body.transpile(code, transforms, false);
  8043. }
  8044. };
  8045. return ClassExpression;
  8046. }(Node$1));
  8047. var ContinueStatement = /*@__PURE__*/(function (Node) {
  8048. function ContinueStatement () {
  8049. Node.apply(this, arguments);
  8050. }
  8051. if ( Node ) ContinueStatement.__proto__ = Node;
  8052. ContinueStatement.prototype = Object.create( Node && Node.prototype );
  8053. ContinueStatement.prototype.constructor = ContinueStatement;
  8054. ContinueStatement.prototype.transpile = function transpile (code) {
  8055. var loop = this.findNearest(loopStatement);
  8056. if (loop.shouldRewriteAsFunction) {
  8057. if (this.label)
  8058. { throw new CompileError(
  8059. 'Labels are not currently supported in a loop with locally-scoped variables',
  8060. this
  8061. ); }
  8062. code.overwrite(this.start, this.start + 8, 'return');
  8063. }
  8064. };
  8065. return ContinueStatement;
  8066. }(Node$1));
  8067. var ExportDefaultDeclaration = /*@__PURE__*/(function (Node) {
  8068. function ExportDefaultDeclaration () {
  8069. Node.apply(this, arguments);
  8070. }
  8071. if ( Node ) ExportDefaultDeclaration.__proto__ = Node;
  8072. ExportDefaultDeclaration.prototype = Object.create( Node && Node.prototype );
  8073. ExportDefaultDeclaration.prototype.constructor = ExportDefaultDeclaration;
  8074. ExportDefaultDeclaration.prototype.initialise = function initialise (transforms) {
  8075. if (transforms.moduleExport)
  8076. { throw new CompileError('export is not supported', this); }
  8077. Node.prototype.initialise.call(this, transforms);
  8078. };
  8079. return ExportDefaultDeclaration;
  8080. }(Node$1));
  8081. var ExportNamedDeclaration = /*@__PURE__*/(function (Node) {
  8082. function ExportNamedDeclaration () {
  8083. Node.apply(this, arguments);
  8084. }
  8085. if ( Node ) ExportNamedDeclaration.__proto__ = Node;
  8086. ExportNamedDeclaration.prototype = Object.create( Node && Node.prototype );
  8087. ExportNamedDeclaration.prototype.constructor = ExportNamedDeclaration;
  8088. ExportNamedDeclaration.prototype.initialise = function initialise (transforms) {
  8089. if (transforms.moduleExport)
  8090. { throw new CompileError('export is not supported', this); }
  8091. Node.prototype.initialise.call(this, transforms);
  8092. };
  8093. return ExportNamedDeclaration;
  8094. }(Node$1));
  8095. var LoopStatement = /*@__PURE__*/(function (Node) {
  8096. function LoopStatement () {
  8097. Node.apply(this, arguments);
  8098. }
  8099. if ( Node ) LoopStatement.__proto__ = Node;
  8100. LoopStatement.prototype = Object.create( Node && Node.prototype );
  8101. LoopStatement.prototype.constructor = LoopStatement;
  8102. LoopStatement.prototype.findScope = function findScope (functionScope) {
  8103. return functionScope || !this.createdScope
  8104. ? this.parent.findScope(functionScope)
  8105. : this.body.scope;
  8106. };
  8107. LoopStatement.prototype.initialise = function initialise (transforms) {
  8108. this.body.createScope();
  8109. this.createdScope = true;
  8110. // this is populated as and when reassignments occur
  8111. this.reassigned = Object.create(null);
  8112. this.aliases = Object.create(null);
  8113. Node.prototype.initialise.call(this, transforms);
  8114. if (transforms.letConst) {
  8115. // see if any block-scoped declarations are referenced
  8116. // inside function expressions
  8117. var names = Object.keys(this.body.scope.declarations);
  8118. var i = names.length;
  8119. while (i--) {
  8120. var name = names[i];
  8121. var declaration = this.body.scope.declarations[name];
  8122. var j = declaration.instances.length;
  8123. while (j--) {
  8124. var instance = declaration.instances[j];
  8125. var nearestFunctionExpression = instance.findNearest(/Function/);
  8126. if (
  8127. nearestFunctionExpression &&
  8128. nearestFunctionExpression.depth > this.depth
  8129. ) {
  8130. this.shouldRewriteAsFunction = true;
  8131. break;
  8132. }
  8133. }
  8134. if (this.shouldRewriteAsFunction) { break; }
  8135. }
  8136. }
  8137. };
  8138. LoopStatement.prototype.transpile = function transpile (code, transforms) {
  8139. var needsBlock =
  8140. this.type != 'ForOfStatement' &&
  8141. (this.body.type !== 'BlockStatement' ||
  8142. (this.body.type === 'BlockStatement' && this.body.synthetic));
  8143. if (this.shouldRewriteAsFunction) {
  8144. var i0 = this.getIndentation();
  8145. var i1 = i0 + code.getIndentString();
  8146. var argString = this.args ? (" " + (this.args.join(', ')) + " ") : '';
  8147. var paramString = this.params ? (" " + (this.params.join(', ')) + " ") : '';
  8148. var functionScope = this.findScope(true);
  8149. var loop = functionScope.createIdentifier('loop');
  8150. var before =
  8151. "var " + loop + " = function (" + paramString + ") " +
  8152. (this.body.synthetic ? ("{\n" + i0 + (code.getIndentString())) : '');
  8153. var after = (this.body.synthetic ? ("\n" + i0 + "}") : '') + ";\n\n" + i0;
  8154. code.prependRight(this.body.start, before);
  8155. code.appendLeft(this.body.end, after);
  8156. code.move(this.start, this.body.start, this.body.end);
  8157. if (this.canBreak || this.canReturn) {
  8158. var returned = functionScope.createIdentifier('returned');
  8159. var insert = "{\n" + i1 + "var " + returned + " = " + loop + "(" + argString + ");\n";
  8160. if (this.canBreak)
  8161. { insert += "\n" + i1 + "if ( " + returned + " === 'break' ) break;"; }
  8162. if (this.canReturn)
  8163. { insert += "\n" + i1 + "if ( " + returned + " ) return " + returned + ".v;"; }
  8164. insert += "\n" + i0 + "}";
  8165. code.prependRight(this.body.end, insert);
  8166. } else {
  8167. var callExpression = loop + "(" + argString + ");";
  8168. if (this.type === 'DoWhileStatement') {
  8169. code.overwrite(
  8170. this.start,
  8171. this.body.start,
  8172. ("do {\n" + i1 + callExpression + "\n" + i0 + "}")
  8173. );
  8174. } else {
  8175. code.prependRight(this.body.end, callExpression);
  8176. }
  8177. }
  8178. } else if (needsBlock) {
  8179. code.appendLeft(this.body.start, '{ ');
  8180. code.prependRight(this.body.end, ' }');
  8181. }
  8182. Node.prototype.transpile.call(this, code, transforms);
  8183. };
  8184. return LoopStatement;
  8185. }(Node$1));
  8186. var ForStatement = /*@__PURE__*/(function (LoopStatement$$1) {
  8187. function ForStatement () {
  8188. LoopStatement$$1.apply(this, arguments);
  8189. }
  8190. if ( LoopStatement$$1 ) ForStatement.__proto__ = LoopStatement$$1;
  8191. ForStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
  8192. ForStatement.prototype.constructor = ForStatement;
  8193. ForStatement.prototype.findScope = function findScope (functionScope) {
  8194. return functionScope || !this.createdScope
  8195. ? this.parent.findScope(functionScope)
  8196. : this.body.scope;
  8197. };
  8198. ForStatement.prototype.transpile = function transpile (code, transforms) {
  8199. var this$1 = this;
  8200. var i1 = this.getIndentation() + code.getIndentString();
  8201. if (this.shouldRewriteAsFunction) {
  8202. // which variables are declared in the init statement?
  8203. var names =
  8204. this.init.type === 'VariableDeclaration'
  8205. ? [].concat.apply(
  8206. [],
  8207. this.init.declarations.map(function (declarator) { return extractNames(declarator.id); }
  8208. )
  8209. )
  8210. : [];
  8211. var aliases = this.aliases;
  8212. this.args = names.map(
  8213. function (name) { return (name in this$1.aliases ? this$1.aliases[name].outer : name); }
  8214. );
  8215. this.params = names.map(
  8216. function (name) { return (name in this$1.aliases ? this$1.aliases[name].inner : name); }
  8217. );
  8218. var updates = Object.keys(this.reassigned).map(
  8219. function (name) { return ((aliases[name].outer) + " = " + (aliases[name].inner) + ";"); }
  8220. );
  8221. if (updates.length) {
  8222. if (this.body.synthetic) {
  8223. code.appendLeft(this.body.body[0].end, ("; " + (updates.join(" "))));
  8224. } else {
  8225. var lastStatement = this.body.body[this.body.body.length - 1];
  8226. code.appendLeft(
  8227. lastStatement.end,
  8228. ("\n\n" + i1 + (updates.join(("\n" + i1))))
  8229. );
  8230. }
  8231. }
  8232. }
  8233. LoopStatement$$1.prototype.transpile.call(this, code, transforms);
  8234. };
  8235. return ForStatement;
  8236. }(LoopStatement));
  8237. var ForInStatement = /*@__PURE__*/(function (LoopStatement$$1) {
  8238. function ForInStatement () {
  8239. LoopStatement$$1.apply(this, arguments);
  8240. }
  8241. if ( LoopStatement$$1 ) ForInStatement.__proto__ = LoopStatement$$1;
  8242. ForInStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
  8243. ForInStatement.prototype.constructor = ForInStatement;
  8244. ForInStatement.prototype.findScope = function findScope (functionScope) {
  8245. return functionScope || !this.createdScope
  8246. ? this.parent.findScope(functionScope)
  8247. : this.body.scope;
  8248. };
  8249. ForInStatement.prototype.transpile = function transpile (code, transforms) {
  8250. var this$1 = this;
  8251. var hasDeclaration = this.left.type === 'VariableDeclaration';
  8252. if (this.shouldRewriteAsFunction) {
  8253. // which variables are declared in the init statement?
  8254. var names =
  8255. hasDeclaration
  8256. ? [].concat.apply(
  8257. [],
  8258. this.left.declarations.map(function (declarator) { return extractNames(declarator.id); }
  8259. )
  8260. )
  8261. : [];
  8262. this.args = names.map(
  8263. function (name) { return (name in this$1.aliases ? this$1.aliases[name].outer : name); }
  8264. );
  8265. this.params = names.map(
  8266. function (name) { return (name in this$1.aliases ? this$1.aliases[name].inner : name); }
  8267. );
  8268. }
  8269. LoopStatement$$1.prototype.transpile.call(this, code, transforms);
  8270. var maybePattern = hasDeclaration ? this.left.declarations[0].id : this.left;
  8271. if (maybePattern.type !== 'Identifier') {
  8272. this.destructurePattern(code, maybePattern, hasDeclaration);
  8273. }
  8274. };
  8275. ForInStatement.prototype.destructurePattern = function destructurePattern (code, pattern, isDeclaration) {
  8276. var scope = this.findScope(true);
  8277. var i0 = this.getIndentation();
  8278. var i1 = i0 + code.getIndentString();
  8279. var ref = scope.createIdentifier('ref');
  8280. var bodyStart = this.body.body.length ? this.body.body[0].start : this.body.start + 1;
  8281. code.move(pattern.start, pattern.end, bodyStart);
  8282. code.prependRight(pattern.end, isDeclaration ? ref : ("var " + ref));
  8283. var statementGenerators = [];
  8284. destructure(
  8285. code,
  8286. function (id) { return scope.createIdentifier(id); },
  8287. function (ref) {
  8288. var name = ref.name;
  8289. return scope.resolveName(name);
  8290. },
  8291. pattern,
  8292. ref,
  8293. false,
  8294. statementGenerators
  8295. );
  8296. var suffix = ";\n" + i1;
  8297. statementGenerators.forEach(function (fn, i) {
  8298. if (i === statementGenerators.length - 1) {
  8299. suffix = ";\n\n" + i1;
  8300. }
  8301. fn(bodyStart, '', suffix);
  8302. });
  8303. };
  8304. return ForInStatement;
  8305. }(LoopStatement));
  8306. var ForOfStatement = /*@__PURE__*/(function (LoopStatement$$1) {
  8307. function ForOfStatement () {
  8308. LoopStatement$$1.apply(this, arguments);
  8309. }
  8310. if ( LoopStatement$$1 ) ForOfStatement.__proto__ = LoopStatement$$1;
  8311. ForOfStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
  8312. ForOfStatement.prototype.constructor = ForOfStatement;
  8313. ForOfStatement.prototype.initialise = function initialise (transforms) {
  8314. if (transforms.forOf && !transforms.dangerousForOf)
  8315. { throw new CompileError(
  8316. "for...of statements are not supported. Use `transforms: { forOf: false }` to skip transformation and disable this error, or `transforms: { dangerousForOf: true }` if you know what you're doing",
  8317. this
  8318. ); }
  8319. LoopStatement$$1.prototype.initialise.call(this, transforms);
  8320. };
  8321. ForOfStatement.prototype.transpile = function transpile (code, transforms) {
  8322. LoopStatement$$1.prototype.transpile.call(this, code, transforms);
  8323. if (!transforms.dangerousForOf) { return; }
  8324. // edge case (#80)
  8325. if (!this.body.body[0]) {
  8326. if (
  8327. this.left.type === 'VariableDeclaration' &&
  8328. this.left.kind === 'var'
  8329. ) {
  8330. code.remove(this.start, this.left.start);
  8331. code.appendLeft(this.left.end, ';');
  8332. code.remove(this.left.end, this.end);
  8333. } else {
  8334. code.remove(this.start, this.end);
  8335. }
  8336. return;
  8337. }
  8338. var scope = this.findScope(true);
  8339. var i0 = this.getIndentation();
  8340. var i1 = i0 + code.getIndentString();
  8341. var key = scope.createIdentifier('i');
  8342. var list = scope.createIdentifier('list');
  8343. if (this.body.synthetic) {
  8344. code.prependRight(this.left.start, ("{\n" + i1));
  8345. code.appendLeft(this.body.body[0].end, ("\n" + i0 + "}"));
  8346. }
  8347. var bodyStart = this.body.body[0].start;
  8348. code.remove(this.left.end, this.right.start);
  8349. code.move(this.left.start, this.left.end, bodyStart);
  8350. code.prependRight(this.right.start, ("var " + key + " = 0, " + list + " = "));
  8351. code.appendLeft(this.right.end, ("; " + key + " < " + list + ".length; " + key + " += 1"));
  8352. var isDeclaration = this.left.type === 'VariableDeclaration';
  8353. var maybeDestructuring = isDeclaration ? this.left.declarations[0].id : this.left;
  8354. if (maybeDestructuring.type !== 'Identifier') {
  8355. var statementGenerators = [];
  8356. var ref = scope.createIdentifier('ref');
  8357. destructure(
  8358. code,
  8359. function (id) { return scope.createIdentifier(id); },
  8360. function (ref) {
  8361. var name = ref.name;
  8362. return scope.resolveName(name);
  8363. },
  8364. maybeDestructuring,
  8365. ref,
  8366. !isDeclaration,
  8367. statementGenerators
  8368. );
  8369. var suffix = ";\n" + i1;
  8370. statementGenerators.forEach(function (fn, i) {
  8371. if (i === statementGenerators.length - 1) {
  8372. suffix = ";\n\n" + i1;
  8373. }
  8374. fn(bodyStart, '', suffix);
  8375. });
  8376. if (isDeclaration) {
  8377. code.appendLeft(this.left.start + this.left.kind.length + 1, ref);
  8378. code.appendLeft(this.left.end, (" = " + list + "[" + key + "];\n" + i1));
  8379. } else {
  8380. code.appendLeft(this.left.end, ("var " + ref + " = " + list + "[" + key + "];\n" + i1));
  8381. }
  8382. } else {
  8383. code.appendLeft(this.left.end, (" = " + list + "[" + key + "];\n\n" + i1));
  8384. }
  8385. };
  8386. return ForOfStatement;
  8387. }(LoopStatement));
  8388. var FunctionDeclaration = /*@__PURE__*/(function (Node) {
  8389. function FunctionDeclaration () {
  8390. Node.apply(this, arguments);
  8391. }
  8392. if ( Node ) FunctionDeclaration.__proto__ = Node;
  8393. FunctionDeclaration.prototype = Object.create( Node && Node.prototype );
  8394. FunctionDeclaration.prototype.constructor = FunctionDeclaration;
  8395. FunctionDeclaration.prototype.initialise = function initialise (transforms) {
  8396. if (this.generator && transforms.generator) {
  8397. throw new CompileError('Generators are not supported', this);
  8398. }
  8399. this.body.createScope();
  8400. if (this.id) {
  8401. this.findScope(true).addDeclaration(this.id, 'function');
  8402. }
  8403. Node.prototype.initialise.call(this, transforms);
  8404. };
  8405. FunctionDeclaration.prototype.transpile = function transpile (code, transforms) {
  8406. Node.prototype.transpile.call(this, code, transforms);
  8407. if (transforms.trailingFunctionCommas && this.params.length) {
  8408. removeTrailingComma(code, this.params[this.params.length - 1].end);
  8409. }
  8410. };
  8411. return FunctionDeclaration;
  8412. }(Node$1));
  8413. var FunctionExpression = /*@__PURE__*/(function (Node) {
  8414. function FunctionExpression () {
  8415. Node.apply(this, arguments);
  8416. }
  8417. if ( Node ) FunctionExpression.__proto__ = Node;
  8418. FunctionExpression.prototype = Object.create( Node && Node.prototype );
  8419. FunctionExpression.prototype.constructor = FunctionExpression;
  8420. FunctionExpression.prototype.initialise = function initialise (transforms) {
  8421. if (this.generator && transforms.generator) {
  8422. throw new CompileError('Generators are not supported', this);
  8423. }
  8424. this.body.createScope();
  8425. if (this.id) {
  8426. // function expression IDs belong to the child scope...
  8427. this.body.scope.addDeclaration(this.id, 'function');
  8428. }
  8429. Node.prototype.initialise.call(this, transforms);
  8430. var parent = this.parent;
  8431. var methodName;
  8432. if (
  8433. transforms.conciseMethodProperty &&
  8434. parent.type === 'Property' &&
  8435. parent.kind === 'init' &&
  8436. parent.method &&
  8437. parent.key.type === 'Identifier'
  8438. ) {
  8439. // object literal concise method
  8440. methodName = parent.key.name;
  8441. } else if (
  8442. transforms.classes &&
  8443. parent.type === 'MethodDefinition' &&
  8444. parent.kind === 'method' &&
  8445. parent.key.type === 'Identifier'
  8446. ) {
  8447. // method definition in a class
  8448. methodName = parent.key.name;
  8449. } else if (this.id && this.id.type === 'Identifier') {
  8450. // naked function expression
  8451. methodName = this.id.alias || this.id.name;
  8452. }
  8453. if (methodName) {
  8454. for (var i$1 = 0, list$1 = this.params; i$1 < list$1.length; i$1 += 1) {
  8455. var param = list$1[i$1];
  8456. if (param.type === 'Identifier' && methodName === param.name) {
  8457. // workaround for Safari 9/WebKit bug:
  8458. // https://gitlab.com/Rich-Harris/buble/issues/154
  8459. // change parameter name when same as method name
  8460. var scope = this.body.scope;
  8461. var declaration = scope.declarations[methodName];
  8462. var alias = scope.createIdentifier(methodName);
  8463. param.alias = alias;
  8464. for (var i = 0, list = declaration.instances; i < list.length; i += 1) {
  8465. var identifier = list[i];
  8466. identifier.alias = alias;
  8467. }
  8468. break;
  8469. }
  8470. }
  8471. }
  8472. };
  8473. FunctionExpression.prototype.transpile = function transpile (code, transforms) {
  8474. Node.prototype.transpile.call(this, code, transforms);
  8475. if (transforms.trailingFunctionCommas && this.params.length) {
  8476. removeTrailingComma(code, this.params[this.params.length - 1].end);
  8477. }
  8478. };
  8479. return FunctionExpression;
  8480. }(Node$1));
  8481. function isReference(node, parent) {
  8482. if (node.type === 'MemberExpression') {
  8483. return !node.computed && isReference(node.object, node);
  8484. }
  8485. if (node.type === 'Identifier') {
  8486. // the only time we could have an identifier node without a parent is
  8487. // if it's the entire body of a function without a block statement –
  8488. // i.e. an arrow function expression like `a => a`
  8489. if (!parent) { return true; }
  8490. if (/(Function|Class)Expression/.test(parent.type)) { return false; }
  8491. if (parent.type === 'VariableDeclarator') { return node === parent.init; }
  8492. // TODO is this right?
  8493. if (
  8494. parent.type === 'MemberExpression' ||
  8495. parent.type === 'MethodDefinition'
  8496. ) {
  8497. return parent.computed || node === parent.object;
  8498. }
  8499. if (parent.type === 'ArrayPattern') { return false; }
  8500. // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
  8501. if (parent.type === 'Property') {
  8502. if (parent.parent.type === 'ObjectPattern') { return false; }
  8503. return parent.computed || node === parent.value;
  8504. }
  8505. // disregard the `bar` in `class Foo { bar () {...} }`
  8506. if (parent.type === 'MethodDefinition') { return false; }
  8507. // disregard the `bar` in `export { foo as bar }`
  8508. if (parent.type === 'ExportSpecifier' && node !== parent.local)
  8509. { return false; }
  8510. return true;
  8511. }
  8512. }
  8513. var Identifier = /*@__PURE__*/(function (Node) {
  8514. function Identifier () {
  8515. Node.apply(this, arguments);
  8516. }
  8517. if ( Node ) Identifier.__proto__ = Node;
  8518. Identifier.prototype = Object.create( Node && Node.prototype );
  8519. Identifier.prototype.constructor = Identifier;
  8520. Identifier.prototype.findScope = function findScope (functionScope) {
  8521. if (this.parent.params && ~this.parent.params.indexOf(this)) {
  8522. return this.parent.body.scope;
  8523. }
  8524. if (this.parent.type === 'FunctionExpression' && this === this.parent.id) {
  8525. return this.parent.body.scope;
  8526. }
  8527. return this.parent.findScope(functionScope);
  8528. };
  8529. Identifier.prototype.initialise = function initialise (transforms) {
  8530. if (isReference(this, this.parent)) {
  8531. if (
  8532. transforms.arrow &&
  8533. this.name === 'arguments' &&
  8534. !this.findScope(false).contains(this.name)
  8535. ) {
  8536. var lexicalBoundary = this.findLexicalBoundary();
  8537. var arrowFunction = this.findNearest('ArrowFunctionExpression');
  8538. var loop = this.findNearest(loopStatement);
  8539. if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) {
  8540. this.alias = lexicalBoundary.getArgumentsAlias();
  8541. }
  8542. if (
  8543. loop &&
  8544. loop.body.contains(this) &&
  8545. loop.depth > lexicalBoundary.depth
  8546. ) {
  8547. this.alias = lexicalBoundary.getArgumentsAlias();
  8548. }
  8549. }
  8550. this.findScope(false).addReference(this);
  8551. }
  8552. };
  8553. Identifier.prototype.transpile = function transpile (code) {
  8554. if (this.alias) {
  8555. code.overwrite(this.start, this.end, this.alias, {
  8556. storeName: true,
  8557. contentOnly: true
  8558. });
  8559. }
  8560. if (shouldPrependVm(this)) {
  8561. code.overwrite(this.start, this.end, ("_vm." + (this.name)), {
  8562. storeName: true,
  8563. contentOnly: true
  8564. });
  8565. }
  8566. };
  8567. return Identifier;
  8568. }(Node$1));
  8569. var IfStatement = /*@__PURE__*/(function (Node) {
  8570. function IfStatement () {
  8571. Node.apply(this, arguments);
  8572. }
  8573. if ( Node ) IfStatement.__proto__ = Node;
  8574. IfStatement.prototype = Object.create( Node && Node.prototype );
  8575. IfStatement.prototype.constructor = IfStatement;
  8576. IfStatement.prototype.initialise = function initialise (transforms) {
  8577. Node.prototype.initialise.call(this, transforms);
  8578. };
  8579. IfStatement.prototype.transpile = function transpile (code, transforms) {
  8580. if (
  8581. this.consequent.type !== 'BlockStatement' ||
  8582. (this.consequent.type === 'BlockStatement' && this.consequent.synthetic)
  8583. ) {
  8584. code.appendLeft(this.consequent.start, '{ ');
  8585. code.prependRight(this.consequent.end, ' }');
  8586. }
  8587. if (
  8588. this.alternate &&
  8589. this.alternate.type !== 'IfStatement' &&
  8590. (this.alternate.type !== 'BlockStatement' ||
  8591. (this.alternate.type === 'BlockStatement' && this.alternate.synthetic))
  8592. ) {
  8593. code.appendLeft(this.alternate.start, '{ ');
  8594. code.prependRight(this.alternate.end, ' }');
  8595. }
  8596. Node.prototype.transpile.call(this, code, transforms);
  8597. };
  8598. return IfStatement;
  8599. }(Node$1));
  8600. var ImportDeclaration = /*@__PURE__*/(function (Node) {
  8601. function ImportDeclaration () {
  8602. Node.apply(this, arguments);
  8603. }
  8604. if ( Node ) ImportDeclaration.__proto__ = Node;
  8605. ImportDeclaration.prototype = Object.create( Node && Node.prototype );
  8606. ImportDeclaration.prototype.constructor = ImportDeclaration;
  8607. ImportDeclaration.prototype.initialise = function initialise (transforms) {
  8608. if (transforms.moduleImport)
  8609. { throw new CompileError('import is not supported', this); }
  8610. Node.prototype.initialise.call(this, transforms);
  8611. };
  8612. return ImportDeclaration;
  8613. }(Node$1));
  8614. var ImportDefaultSpecifier = /*@__PURE__*/(function (Node) {
  8615. function ImportDefaultSpecifier () {
  8616. Node.apply(this, arguments);
  8617. }
  8618. if ( Node ) ImportDefaultSpecifier.__proto__ = Node;
  8619. ImportDefaultSpecifier.prototype = Object.create( Node && Node.prototype );
  8620. ImportDefaultSpecifier.prototype.constructor = ImportDefaultSpecifier;
  8621. ImportDefaultSpecifier.prototype.initialise = function initialise (transforms) {
  8622. this.findScope(true).addDeclaration(this.local, 'import');
  8623. Node.prototype.initialise.call(this, transforms);
  8624. };
  8625. return ImportDefaultSpecifier;
  8626. }(Node$1));
  8627. var ImportSpecifier = /*@__PURE__*/(function (Node) {
  8628. function ImportSpecifier () {
  8629. Node.apply(this, arguments);
  8630. }
  8631. if ( Node ) ImportSpecifier.__proto__ = Node;
  8632. ImportSpecifier.prototype = Object.create( Node && Node.prototype );
  8633. ImportSpecifier.prototype.constructor = ImportSpecifier;
  8634. ImportSpecifier.prototype.initialise = function initialise (transforms) {
  8635. this.findScope(true).addDeclaration(this.local, 'import');
  8636. Node.prototype.initialise.call(this, transforms);
  8637. };
  8638. return ImportSpecifier;
  8639. }(Node$1));
  8640. var hasDashes = function (val) { return /-/.test(val); };
  8641. var formatKey = function (key) { return (hasDashes(key) ? ("'" + key + "'") : key); };
  8642. var formatVal = function (val) { return (val ? '' : 'true'); };
  8643. var JSXAttribute = /*@__PURE__*/(function (Node) {
  8644. function JSXAttribute () {
  8645. Node.apply(this, arguments);
  8646. }
  8647. if ( Node ) JSXAttribute.__proto__ = Node;
  8648. JSXAttribute.prototype = Object.create( Node && Node.prototype );
  8649. JSXAttribute.prototype.constructor = JSXAttribute;
  8650. JSXAttribute.prototype.transpile = function transpile (code, transforms) {
  8651. var ref = this.name;
  8652. var start = ref.start;
  8653. var name = ref.name;
  8654. // Overwrite equals sign if value is present.
  8655. var end = this.value ? this.value.start : this.name.end;
  8656. code.overwrite(start, end, ((formatKey(name)) + ": " + (formatVal(this.value))));
  8657. Node.prototype.transpile.call(this, code, transforms);
  8658. };
  8659. return JSXAttribute;
  8660. }(Node$1));
  8661. function containsNewLine(node) {
  8662. return (
  8663. node.type === 'JSXText' && !/\S/.test(node.value) && /\n/.test(node.value)
  8664. );
  8665. }
  8666. var JSXClosingElement = /*@__PURE__*/(function (Node) {
  8667. function JSXClosingElement () {
  8668. Node.apply(this, arguments);
  8669. }
  8670. if ( Node ) JSXClosingElement.__proto__ = Node;
  8671. JSXClosingElement.prototype = Object.create( Node && Node.prototype );
  8672. JSXClosingElement.prototype.constructor = JSXClosingElement;
  8673. JSXClosingElement.prototype.transpile = function transpile (code) {
  8674. var spaceBeforeParen = true;
  8675. var lastChild = this.parent.children[this.parent.children.length - 1];
  8676. // omit space before closing paren if
  8677. // a) this is on a separate line, or
  8678. // b) there are no children but there are attributes
  8679. if (
  8680. (lastChild && containsNewLine(lastChild)) ||
  8681. this.parent.openingElement.attributes.length
  8682. ) {
  8683. spaceBeforeParen = false;
  8684. }
  8685. code.overwrite(this.start, this.end, spaceBeforeParen ? ' )' : ')');
  8686. };
  8687. return JSXClosingElement;
  8688. }(Node$1));
  8689. function containsNewLine$1(node) {
  8690. return (
  8691. node.type === 'JSXText' && !/\S/.test(node.value) && /\n/.test(node.value)
  8692. );
  8693. }
  8694. var JSXClosingFragment = /*@__PURE__*/(function (Node) {
  8695. function JSXClosingFragment () {
  8696. Node.apply(this, arguments);
  8697. }
  8698. if ( Node ) JSXClosingFragment.__proto__ = Node;
  8699. JSXClosingFragment.prototype = Object.create( Node && Node.prototype );
  8700. JSXClosingFragment.prototype.constructor = JSXClosingFragment;
  8701. JSXClosingFragment.prototype.transpile = function transpile (code) {
  8702. var spaceBeforeParen = true;
  8703. var lastChild = this.parent.children[this.parent.children.length - 1];
  8704. // omit space before closing paren if this is on a separate line
  8705. if (lastChild && containsNewLine$1(lastChild)) {
  8706. spaceBeforeParen = false;
  8707. }
  8708. code.overwrite(this.start, this.end, spaceBeforeParen ? ' )' : ')');
  8709. };
  8710. return JSXClosingFragment;
  8711. }(Node$1));
  8712. function normalise(str, removeTrailingWhitespace) {
  8713. str = str.replace(/\u00a0/g, '&nbsp;');
  8714. if (removeTrailingWhitespace && /\n/.test(str)) {
  8715. str = str.replace(/\s+$/, '');
  8716. }
  8717. str = str
  8718. .replace(/^\n\r?\s+/, '') // remove leading newline + space
  8719. .replace(/\s*\n\r?\s*/gm, ' '); // replace newlines with spaces
  8720. // TODO prefer single quotes?
  8721. return JSON.stringify(str);
  8722. }
  8723. var JSXElement = /*@__PURE__*/(function (Node) {
  8724. function JSXElement () {
  8725. Node.apply(this, arguments);
  8726. }
  8727. if ( Node ) JSXElement.__proto__ = Node;
  8728. JSXElement.prototype = Object.create( Node && Node.prototype );
  8729. JSXElement.prototype.constructor = JSXElement;
  8730. JSXElement.prototype.transpile = function transpile (code, transforms) {
  8731. Node.prototype.transpile.call(this, code, transforms);
  8732. var children = this.children.filter(function (child) {
  8733. if (child.type !== 'JSXText') { return true; }
  8734. // remove whitespace-only literals, unless on a single line
  8735. return /\S/.test(child.raw) || !/\n/.test(child.raw);
  8736. });
  8737. if (children.length) {
  8738. var c = this.openingElement.end;
  8739. var i;
  8740. for (i = 0; i < children.length; i += 1) {
  8741. var child = children[i];
  8742. if (
  8743. child.type === 'JSXExpressionContainer' &&
  8744. child.expression.type === 'JSXEmptyExpression'
  8745. ) {
  8746. // empty block is a no op
  8747. } else {
  8748. var tail =
  8749. code.original[c] === '\n' && child.type !== 'JSXText' ? '' : ' ';
  8750. code.appendLeft(c, ("," + tail));
  8751. }
  8752. if (child.type === 'JSXText') {
  8753. var str = normalise(child.value, i === children.length - 1);
  8754. code.overwrite(child.start, child.end, str);
  8755. }
  8756. c = child.end;
  8757. }
  8758. }
  8759. };
  8760. return JSXElement;
  8761. }(Node$1));
  8762. var JSXExpressionContainer = /*@__PURE__*/(function (Node) {
  8763. function JSXExpressionContainer () {
  8764. Node.apply(this, arguments);
  8765. }
  8766. if ( Node ) JSXExpressionContainer.__proto__ = Node;
  8767. JSXExpressionContainer.prototype = Object.create( Node && Node.prototype );
  8768. JSXExpressionContainer.prototype.constructor = JSXExpressionContainer;
  8769. JSXExpressionContainer.prototype.transpile = function transpile (code, transforms) {
  8770. code.remove(this.start, this.expression.start);
  8771. code.remove(this.expression.end, this.end);
  8772. Node.prototype.transpile.call(this, code, transforms);
  8773. };
  8774. return JSXExpressionContainer;
  8775. }(Node$1));
  8776. var JSXFragment = /*@__PURE__*/(function (JSXElement$$1) {
  8777. function JSXFragment () {
  8778. JSXElement$$1.apply(this, arguments);
  8779. }if ( JSXElement$$1 ) JSXFragment.__proto__ = JSXElement$$1;
  8780. JSXFragment.prototype = Object.create( JSXElement$$1 && JSXElement$$1.prototype );
  8781. JSXFragment.prototype.constructor = JSXFragment;
  8782. return JSXFragment;
  8783. }(JSXElement));
  8784. var JSXOpeningElement = /*@__PURE__*/(function (Node) {
  8785. function JSXOpeningElement () {
  8786. Node.apply(this, arguments);
  8787. }
  8788. if ( Node ) JSXOpeningElement.__proto__ = Node;
  8789. JSXOpeningElement.prototype = Object.create( Node && Node.prototype );
  8790. JSXOpeningElement.prototype.constructor = JSXOpeningElement;
  8791. JSXOpeningElement.prototype.transpile = function transpile (code, transforms) {
  8792. Node.prototype.transpile.call(this, code, transforms);
  8793. code.overwrite(this.start, this.name.start, ((this.program.jsx) + "( "));
  8794. var html =
  8795. this.name.type === 'JSXIdentifier' &&
  8796. this.name.name[0] === this.name.name[0].toLowerCase();
  8797. if (html) { code.prependRight(this.name.start, "'"); }
  8798. var len = this.attributes.length;
  8799. var c = this.name.end;
  8800. if (len) {
  8801. var i;
  8802. var hasSpread = false;
  8803. for (i = 0; i < len; i += 1) {
  8804. if (this.attributes[i].type === 'JSXSpreadAttribute') {
  8805. hasSpread = true;
  8806. break;
  8807. }
  8808. }
  8809. c = this.attributes[0].end;
  8810. for (i = 0; i < len; i += 1) {
  8811. var attr = this.attributes[i];
  8812. if (i > 0) {
  8813. if (attr.start === c) { code.prependRight(c, ', '); }
  8814. else { code.overwrite(c, attr.start, ', '); }
  8815. }
  8816. if (hasSpread && attr.type !== 'JSXSpreadAttribute') {
  8817. var lastAttr = this.attributes[i - 1];
  8818. var nextAttr = this.attributes[i + 1];
  8819. if (!lastAttr || lastAttr.type === 'JSXSpreadAttribute') {
  8820. code.prependRight(attr.start, '{ ');
  8821. }
  8822. if (!nextAttr || nextAttr.type === 'JSXSpreadAttribute') {
  8823. code.appendLeft(attr.end, ' }');
  8824. }
  8825. }
  8826. c = attr.end;
  8827. }
  8828. var after;
  8829. var before;
  8830. if (hasSpread) {
  8831. if (len === 1) {
  8832. before = html ? "'," : ',';
  8833. } else {
  8834. if (!this.program.options.objectAssign) {
  8835. throw new CompileError(
  8836. "Mixed JSX attributes ending in spread requires specified objectAssign option with 'Object.assign' or polyfill helper.",
  8837. this
  8838. );
  8839. }
  8840. before = html
  8841. ? ("', " + (this.program.options.objectAssign) + "({},")
  8842. : (", " + (this.program.options.objectAssign) + "({},");
  8843. after = ')';
  8844. }
  8845. } else {
  8846. before = html ? "', {" : ', {';
  8847. after = ' }';
  8848. }
  8849. code.prependRight(this.name.end, before);
  8850. if (after) {
  8851. code.appendLeft(this.attributes[len - 1].end, after);
  8852. }
  8853. } else {
  8854. code.appendLeft(this.name.end, html ? "', null" : ", null");
  8855. c = this.name.end;
  8856. }
  8857. if (this.selfClosing) {
  8858. code.overwrite(c, this.end, this.attributes.length ? ")" : " )");
  8859. } else {
  8860. code.remove(c, this.end);
  8861. }
  8862. };
  8863. return JSXOpeningElement;
  8864. }(Node$1));
  8865. var JSXOpeningFragment = /*@__PURE__*/(function (Node) {
  8866. function JSXOpeningFragment () {
  8867. Node.apply(this, arguments);
  8868. }
  8869. if ( Node ) JSXOpeningFragment.__proto__ = Node;
  8870. JSXOpeningFragment.prototype = Object.create( Node && Node.prototype );
  8871. JSXOpeningFragment.prototype.constructor = JSXOpeningFragment;
  8872. JSXOpeningFragment.prototype.transpile = function transpile (code, transforms) {
  8873. code.overwrite(this.start, this.end, ((this.program.jsx) + "( React.Fragment, null"));
  8874. };
  8875. return JSXOpeningFragment;
  8876. }(Node$1));
  8877. var JSXSpreadAttribute = /*@__PURE__*/(function (Node) {
  8878. function JSXSpreadAttribute () {
  8879. Node.apply(this, arguments);
  8880. }
  8881. if ( Node ) JSXSpreadAttribute.__proto__ = Node;
  8882. JSXSpreadAttribute.prototype = Object.create( Node && Node.prototype );
  8883. JSXSpreadAttribute.prototype.constructor = JSXSpreadAttribute;
  8884. JSXSpreadAttribute.prototype.transpile = function transpile (code, transforms) {
  8885. code.remove(this.start, this.argument.start);
  8886. code.remove(this.argument.end, this.end);
  8887. Node.prototype.transpile.call(this, code, transforms);
  8888. };
  8889. return JSXSpreadAttribute;
  8890. }(Node$1));
  8891. var regjsgen = createCommonjsModule(function (module, exports) {
  8892. /*!
  8893. * regjsgen 0.5.0
  8894. * Copyright 2014-2018 Benjamin Tan <https://bnjmnt4n.now.sh/>
  8895. * Available under MIT license <https://github.com/bnjmnt4n/regjsgen/blob/master/LICENSE>
  8896. */
  8897. (function() {
  8898. var objectTypes = {
  8899. 'function': true,
  8900. 'object': true
  8901. };
  8902. // Used as a reference to the global object.
  8903. var root = (objectTypes[typeof window] && window) || this;
  8904. // Detect free variable `exports`.
  8905. var freeExports = objectTypes['object'] && exports && !exports.nodeType && exports;
  8906. // Detect free variable `module`.
  8907. var hasFreeModule = objectTypes['object'] && module && !module.nodeType;
  8908. // Detect free variable `global` from Node.js or Browserified code and use it as `root`.
  8909. var freeGlobal = freeExports && hasFreeModule && typeof commonjsGlobal == 'object' && commonjsGlobal;
  8910. if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
  8911. root = freeGlobal;
  8912. }
  8913. // Used to check objects for own properties.
  8914. var hasOwnProperty = Object.prototype.hasOwnProperty;
  8915. /*--------------------------------------------------------------------------*/
  8916. // Generates a string based on the given code point.
  8917. // Based on https://mths.be/fromcodepoint by @mathias.
  8918. function fromCodePoint() {
  8919. var codePoint = Number(arguments[0]);
  8920. if (
  8921. !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
  8922. codePoint < 0 || // not a valid Unicode code point
  8923. codePoint > 0x10FFFF || // not a valid Unicode code point
  8924. Math.floor(codePoint) != codePoint // not an integer
  8925. ) {
  8926. throw RangeError('Invalid code point: ' + codePoint);
  8927. }
  8928. if (codePoint <= 0xFFFF) {
  8929. // BMP code point
  8930. return String.fromCharCode(codePoint);
  8931. } else {
  8932. // Astral code point; split in surrogate halves
  8933. // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  8934. codePoint -= 0x10000;
  8935. var highSurrogate = (codePoint >> 10) + 0xD800;
  8936. var lowSurrogate = (codePoint % 0x400) + 0xDC00;
  8937. return String.fromCharCode(highSurrogate, lowSurrogate);
  8938. }
  8939. }
  8940. /*--------------------------------------------------------------------------*/
  8941. // Ensures that nodes have the correct types.
  8942. var assertTypeRegexMap = {};
  8943. function assertType(type, expected) {
  8944. if (expected.indexOf('|') == -1) {
  8945. if (type == expected) {
  8946. return;
  8947. }
  8948. throw Error('Invalid node type: ' + type + '; expected type: ' + expected);
  8949. }
  8950. expected = hasOwnProperty.call(assertTypeRegexMap, expected)
  8951. ? assertTypeRegexMap[expected]
  8952. : (assertTypeRegexMap[expected] = RegExp('^(?:' + expected + ')$'));
  8953. if (expected.test(type)) {
  8954. return;
  8955. }
  8956. throw Error('Invalid node type: ' + type + '; expected types: ' + expected);
  8957. }
  8958. /*--------------------------------------------------------------------------*/
  8959. // Generates a regular expression string based on an AST.
  8960. function generate(node) {
  8961. var type = node.type;
  8962. if (hasOwnProperty.call(generators, type)) {
  8963. return generators[type](node);
  8964. }
  8965. throw Error('Invalid node type: ' + type);
  8966. }
  8967. /*--------------------------------------------------------------------------*/
  8968. function generateAlternative(node) {
  8969. assertType(node.type, 'alternative');
  8970. var terms = node.body,
  8971. i = -1,
  8972. length = terms.length,
  8973. result = '';
  8974. while (++i < length) {
  8975. result += generateTerm(terms[i]);
  8976. }
  8977. return result;
  8978. }
  8979. function generateAnchor(node) {
  8980. assertType(node.type, 'anchor');
  8981. switch (node.kind) {
  8982. case 'start':
  8983. return '^';
  8984. case 'end':
  8985. return '$';
  8986. case 'boundary':
  8987. return '\\b';
  8988. case 'not-boundary':
  8989. return '\\B';
  8990. default:
  8991. throw Error('Invalid assertion');
  8992. }
  8993. }
  8994. function generateAtom(node) {
  8995. assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
  8996. return generate(node);
  8997. }
  8998. function generateCharacterClass(node) {
  8999. assertType(node.type, 'characterClass');
  9000. var classRanges = node.body,
  9001. i = -1,
  9002. length = classRanges.length,
  9003. result = '';
  9004. if (node.negative) {
  9005. result += '^';
  9006. }
  9007. while (++i < length) {
  9008. result += generateClassAtom(classRanges[i]);
  9009. }
  9010. return '[' + result + ']';
  9011. }
  9012. function generateCharacterClassEscape(node) {
  9013. assertType(node.type, 'characterClassEscape');
  9014. return '\\' + node.value;
  9015. }
  9016. function generateUnicodePropertyEscape(node) {
  9017. assertType(node.type, 'unicodePropertyEscape');
  9018. return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
  9019. }
  9020. function generateCharacterClassRange(node) {
  9021. assertType(node.type, 'characterClassRange');
  9022. var min = node.min,
  9023. max = node.max;
  9024. if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
  9025. throw Error('Invalid character class range');
  9026. }
  9027. return generateClassAtom(min) + '-' + generateClassAtom(max);
  9028. }
  9029. function generateClassAtom(node) {
  9030. assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value');
  9031. return generate(node);
  9032. }
  9033. function generateDisjunction(node) {
  9034. assertType(node.type, 'disjunction');
  9035. var body = node.body,
  9036. i = -1,
  9037. length = body.length,
  9038. result = '';
  9039. while (++i < length) {
  9040. if (i != 0) {
  9041. result += '|';
  9042. }
  9043. result += generate(body[i]);
  9044. }
  9045. return result;
  9046. }
  9047. function generateDot(node) {
  9048. assertType(node.type, 'dot');
  9049. return '.';
  9050. }
  9051. function generateGroup(node) {
  9052. assertType(node.type, 'group');
  9053. var result = '';
  9054. switch (node.behavior) {
  9055. case 'normal':
  9056. if (node.name) {
  9057. result += '?<' + generateIdentifier(node.name) + '>';
  9058. }
  9059. break;
  9060. case 'ignore':
  9061. result += '?:';
  9062. break;
  9063. case 'lookahead':
  9064. result += '?=';
  9065. break;
  9066. case 'negativeLookahead':
  9067. result += '?!';
  9068. break;
  9069. case 'lookbehind':
  9070. result += '?<=';
  9071. break;
  9072. case 'negativeLookbehind':
  9073. result += '?<!';
  9074. break;
  9075. default:
  9076. throw Error('Invalid behaviour: ' + node.behaviour);
  9077. }
  9078. var body = node.body,
  9079. i = -1,
  9080. length = body.length;
  9081. while (++i < length) {
  9082. result += generate(body[i]);
  9083. }
  9084. return '(' + result + ')';
  9085. }
  9086. function generateIdentifier(node) {
  9087. assertType(node.type, 'identifier');
  9088. return node.value;
  9089. }
  9090. function generateQuantifier(node) {
  9091. assertType(node.type, 'quantifier');
  9092. var quantifier = '',
  9093. min = node.min,
  9094. max = node.max;
  9095. if (max == null) {
  9096. if (min == 0) {
  9097. quantifier = '*';
  9098. } else if (min == 1) {
  9099. quantifier = '+';
  9100. } else {
  9101. quantifier = '{' + min + ',}';
  9102. }
  9103. } else if (min == max) {
  9104. quantifier = '{' + min + '}';
  9105. } else if (min == 0 && max == 1) {
  9106. quantifier = '?';
  9107. } else {
  9108. quantifier = '{' + min + ',' + max + '}';
  9109. }
  9110. if (!node.greedy) {
  9111. quantifier += '?';
  9112. }
  9113. return generateAtom(node.body[0]) + quantifier;
  9114. }
  9115. function generateReference(node) {
  9116. assertType(node.type, 'reference');
  9117. if (node.matchIndex) {
  9118. return '\\' + node.matchIndex;
  9119. }
  9120. if (node.name) {
  9121. return '\\k<' + generateIdentifier(node.name) + '>';
  9122. }
  9123. throw new Error('Unknown reference type');
  9124. }
  9125. function generateTerm(node) {
  9126. assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value');
  9127. return generate(node);
  9128. }
  9129. function generateValue(node) {
  9130. assertType(node.type, 'value');
  9131. var kind = node.kind,
  9132. codePoint = node.codePoint;
  9133. if (typeof codePoint != 'number') {
  9134. throw new Error('Invalid code point: ' + codePoint);
  9135. }
  9136. switch (kind) {
  9137. case 'controlLetter':
  9138. return '\\c' + fromCodePoint(codePoint + 64);
  9139. case 'hexadecimalEscape':
  9140. return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
  9141. case 'identifier':
  9142. return '\\' + fromCodePoint(codePoint);
  9143. case 'null':
  9144. return '\\' + codePoint;
  9145. case 'octal':
  9146. return '\\' + codePoint.toString(8);
  9147. case 'singleEscape':
  9148. switch (codePoint) {
  9149. case 0x0008:
  9150. return '\\b';
  9151. case 0x0009:
  9152. return '\\t';
  9153. case 0x000A:
  9154. return '\\n';
  9155. case 0x000B:
  9156. return '\\v';
  9157. case 0x000C:
  9158. return '\\f';
  9159. case 0x000D:
  9160. return '\\r';
  9161. default:
  9162. throw Error('Invalid code point: ' + codePoint);
  9163. }
  9164. case 'symbol':
  9165. return fromCodePoint(codePoint);
  9166. case 'unicodeEscape':
  9167. return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
  9168. case 'unicodeCodePointEscape':
  9169. return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
  9170. default:
  9171. throw Error('Unsupported node kind: ' + kind);
  9172. }
  9173. }
  9174. /*--------------------------------------------------------------------------*/
  9175. // Used to generate strings for each node type.
  9176. var generators = {
  9177. 'alternative': generateAlternative,
  9178. 'anchor': generateAnchor,
  9179. 'characterClass': generateCharacterClass,
  9180. 'characterClassEscape': generateCharacterClassEscape,
  9181. 'characterClassRange': generateCharacterClassRange,
  9182. 'unicodePropertyEscape': generateUnicodePropertyEscape,
  9183. 'disjunction': generateDisjunction,
  9184. 'dot': generateDot,
  9185. 'group': generateGroup,
  9186. 'quantifier': generateQuantifier,
  9187. 'reference': generateReference,
  9188. 'value': generateValue
  9189. };
  9190. /*--------------------------------------------------------------------------*/
  9191. // Export regjsgen.
  9192. var regjsgen = {
  9193. 'generate': generate
  9194. };
  9195. // Some AMD build optimizers, like r.js, check for condition patterns like the following:
  9196. if (typeof undefined == 'function' && typeof undefined.amd == 'object' && undefined.amd) {
  9197. // Define as an anonymous module so it can be aliased through path mapping.
  9198. undefined(function() {
  9199. return regjsgen;
  9200. });
  9201. root.regjsgen = regjsgen;
  9202. }
  9203. // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
  9204. else if (freeExports && hasFreeModule) {
  9205. // Export for CommonJS support.
  9206. freeExports.generate = generate;
  9207. }
  9208. else {
  9209. // Export to the global object.
  9210. root.regjsgen = regjsgen;
  9211. }
  9212. }.call(commonjsGlobal));
  9213. });
  9214. var parser = createCommonjsModule(function (module) {
  9215. // regjsparser
  9216. //
  9217. // ==================================================================
  9218. //
  9219. // See ECMA-262 Standard: 15.10.1
  9220. //
  9221. // NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the
  9222. // term "Anchor" is used.
  9223. //
  9224. // Pattern ::
  9225. // Disjunction
  9226. //
  9227. // Disjunction ::
  9228. // Alternative
  9229. // Alternative | Disjunction
  9230. //
  9231. // Alternative ::
  9232. // [empty]
  9233. // Alternative Term
  9234. //
  9235. // Term ::
  9236. // Anchor
  9237. // Atom
  9238. // Atom Quantifier
  9239. //
  9240. // Anchor ::
  9241. // ^
  9242. // $
  9243. // \ b
  9244. // \ B
  9245. // ( ? = Disjunction )
  9246. // ( ? ! Disjunction )
  9247. // ( ? < = Disjunction )
  9248. // ( ? < ! Disjunction )
  9249. //
  9250. // Quantifier ::
  9251. // QuantifierPrefix
  9252. // QuantifierPrefix ?
  9253. //
  9254. // QuantifierPrefix ::
  9255. // *
  9256. // +
  9257. // ?
  9258. // { DecimalDigits }
  9259. // { DecimalDigits , }
  9260. // { DecimalDigits , DecimalDigits }
  9261. //
  9262. // Atom ::
  9263. // PatternCharacter
  9264. // .
  9265. // \ AtomEscape
  9266. // CharacterClass
  9267. // ( GroupSpecifier Disjunction )
  9268. // ( ? : Disjunction )
  9269. //
  9270. // PatternCharacter ::
  9271. // SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |
  9272. //
  9273. // AtomEscape ::
  9274. // DecimalEscape
  9275. // CharacterEscape
  9276. // CharacterClassEscape
  9277. // k GroupName
  9278. //
  9279. // CharacterEscape[U] ::
  9280. // ControlEscape
  9281. // c ControlLetter
  9282. // HexEscapeSequence
  9283. // RegExpUnicodeEscapeSequence[?U] (ES6)
  9284. // IdentityEscape[?U]
  9285. //
  9286. // ControlEscape ::
  9287. // one of f n r t v
  9288. // ControlLetter ::
  9289. // one of
  9290. // a b c d e f g h i j k l m n o p q r s t u v w x y z
  9291. // A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  9292. //
  9293. // IdentityEscape ::
  9294. // SourceCharacter but not c
  9295. //
  9296. // DecimalEscape ::
  9297. // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
  9298. //
  9299. // CharacterClassEscape ::
  9300. // one of d D s S w W
  9301. //
  9302. // CharacterClass ::
  9303. // [ [lookahead ∉ {^}] ClassRanges ]
  9304. // [ ^ ClassRanges ]
  9305. //
  9306. // ClassRanges ::
  9307. // [empty]
  9308. // NonemptyClassRanges
  9309. //
  9310. // NonemptyClassRanges ::
  9311. // ClassAtom
  9312. // ClassAtom NonemptyClassRangesNoDash
  9313. // ClassAtom - ClassAtom ClassRanges
  9314. //
  9315. // NonemptyClassRangesNoDash ::
  9316. // ClassAtom
  9317. // ClassAtomNoDash NonemptyClassRangesNoDash
  9318. // ClassAtomNoDash - ClassAtom ClassRanges
  9319. //
  9320. // ClassAtom ::
  9321. // -
  9322. // ClassAtomNoDash
  9323. //
  9324. // ClassAtomNoDash ::
  9325. // SourceCharacter but not one of \ or ] or -
  9326. // \ ClassEscape
  9327. //
  9328. // ClassEscape ::
  9329. // DecimalEscape
  9330. // b
  9331. // CharacterEscape
  9332. // CharacterClassEscape
  9333. //
  9334. // GroupSpecifier ::
  9335. // [empty]
  9336. // ? GroupName
  9337. //
  9338. // GroupName ::
  9339. // < RegExpIdentifierName >
  9340. //
  9341. // RegExpIdentifierName ::
  9342. // RegExpIdentifierStart
  9343. // RegExpIdentifierName RegExpIdentifierContinue
  9344. //
  9345. // RegExpIdentifierStart ::
  9346. // UnicodeIDStart
  9347. // $
  9348. // _
  9349. // \ RegExpUnicodeEscapeSequence
  9350. //
  9351. // RegExpIdentifierContinue ::
  9352. // UnicodeIDContinue
  9353. // $
  9354. // _
  9355. // \ RegExpUnicodeEscapeSequence
  9356. // <ZWNJ>
  9357. // <ZWJ>
  9358. (function() {
  9359. var fromCodePoint = String.fromCodePoint || (function() {
  9360. // Implementation taken from
  9361. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
  9362. var stringFromCharCode = String.fromCharCode;
  9363. var floor = Math.floor;
  9364. return function fromCodePoint() {
  9365. var MAX_SIZE = 0x4000;
  9366. var codeUnits = [];
  9367. var highSurrogate;
  9368. var lowSurrogate;
  9369. var index = -1;
  9370. var length = arguments.length;
  9371. if (!length) {
  9372. return '';
  9373. }
  9374. var result = '';
  9375. while (++index < length) {
  9376. var codePoint = Number(arguments[index]);
  9377. if (
  9378. !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
  9379. codePoint < 0 || // not a valid Unicode code point
  9380. codePoint > 0x10FFFF || // not a valid Unicode code point
  9381. floor(codePoint) != codePoint // not an integer
  9382. ) {
  9383. throw RangeError('Invalid code point: ' + codePoint);
  9384. }
  9385. if (codePoint <= 0xFFFF) { // BMP code point
  9386. codeUnits.push(codePoint);
  9387. } else { // Astral code point; split in surrogate halves
  9388. // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  9389. codePoint -= 0x10000;
  9390. highSurrogate = (codePoint >> 10) + 0xD800;
  9391. lowSurrogate = (codePoint % 0x400) + 0xDC00;
  9392. codeUnits.push(highSurrogate, lowSurrogate);
  9393. }
  9394. if (index + 1 == length || codeUnits.length > MAX_SIZE) {
  9395. result += stringFromCharCode.apply(null, codeUnits);
  9396. codeUnits.length = 0;
  9397. }
  9398. }
  9399. return result;
  9400. };
  9401. }());
  9402. function parse(str, flags, features) {
  9403. if (!features) {
  9404. features = {};
  9405. }
  9406. function addRaw(node) {
  9407. node.raw = str.substring(node.range[0], node.range[1]);
  9408. return node;
  9409. }
  9410. function updateRawStart(node, start) {
  9411. node.range[0] = start;
  9412. return addRaw(node);
  9413. }
  9414. function createAnchor(kind, rawLength) {
  9415. return addRaw({
  9416. type: 'anchor',
  9417. kind: kind,
  9418. range: [
  9419. pos - rawLength,
  9420. pos
  9421. ]
  9422. });
  9423. }
  9424. function createValue(kind, codePoint, from, to) {
  9425. return addRaw({
  9426. type: 'value',
  9427. kind: kind,
  9428. codePoint: codePoint,
  9429. range: [from, to]
  9430. });
  9431. }
  9432. function createEscaped(kind, codePoint, value, fromOffset) {
  9433. fromOffset = fromOffset || 0;
  9434. return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);
  9435. }
  9436. function createCharacter(matches) {
  9437. var _char = matches[0];
  9438. var first = _char.charCodeAt(0);
  9439. if (hasUnicodeFlag) {
  9440. var second;
  9441. if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
  9442. second = lookahead().charCodeAt(0);
  9443. if (second >= 0xDC00 && second <= 0xDFFF) {
  9444. // Unicode surrogate pair
  9445. pos++;
  9446. return createValue(
  9447. 'symbol',
  9448. (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,
  9449. pos - 2, pos);
  9450. }
  9451. }
  9452. }
  9453. return createValue('symbol', first, pos - 1, pos);
  9454. }
  9455. function createDisjunction(alternatives, from, to) {
  9456. return addRaw({
  9457. type: 'disjunction',
  9458. body: alternatives,
  9459. range: [
  9460. from,
  9461. to
  9462. ]
  9463. });
  9464. }
  9465. function createDot() {
  9466. return addRaw({
  9467. type: 'dot',
  9468. range: [
  9469. pos - 1,
  9470. pos
  9471. ]
  9472. });
  9473. }
  9474. function createCharacterClassEscape(value) {
  9475. return addRaw({
  9476. type: 'characterClassEscape',
  9477. value: value,
  9478. range: [
  9479. pos - 2,
  9480. pos
  9481. ]
  9482. });
  9483. }
  9484. function createReference(matchIndex) {
  9485. return addRaw({
  9486. type: 'reference',
  9487. matchIndex: parseInt(matchIndex, 10),
  9488. range: [
  9489. pos - 1 - matchIndex.length,
  9490. pos
  9491. ]
  9492. });
  9493. }
  9494. function createNamedReference(name) {
  9495. return addRaw({
  9496. type: 'reference',
  9497. name: name,
  9498. range: [
  9499. name.range[0] - 3,
  9500. pos
  9501. ]
  9502. });
  9503. }
  9504. function createGroup(behavior, disjunction, from, to) {
  9505. return addRaw({
  9506. type: 'group',
  9507. behavior: behavior,
  9508. body: disjunction,
  9509. range: [
  9510. from,
  9511. to
  9512. ]
  9513. });
  9514. }
  9515. function createQuantifier(min, max, from, to) {
  9516. if (to == null) {
  9517. from = pos - 1;
  9518. to = pos;
  9519. }
  9520. return addRaw({
  9521. type: 'quantifier',
  9522. min: min,
  9523. max: max,
  9524. greedy: true,
  9525. body: null, // set later on
  9526. range: [
  9527. from,
  9528. to
  9529. ]
  9530. });
  9531. }
  9532. function createAlternative(terms, from, to) {
  9533. return addRaw({
  9534. type: 'alternative',
  9535. body: terms,
  9536. range: [
  9537. from,
  9538. to
  9539. ]
  9540. });
  9541. }
  9542. function createCharacterClass(classRanges, negative, from, to) {
  9543. return addRaw({
  9544. type: 'characterClass',
  9545. body: classRanges,
  9546. negative: negative,
  9547. range: [
  9548. from,
  9549. to
  9550. ]
  9551. });
  9552. }
  9553. function createClassRange(min, max, from, to) {
  9554. // See 15.10.2.15:
  9555. if (min.codePoint > max.codePoint) {
  9556. bail('invalid range in character class', min.raw + '-' + max.raw, from, to);
  9557. }
  9558. return addRaw({
  9559. type: 'characterClassRange',
  9560. min: min,
  9561. max: max,
  9562. range: [
  9563. from,
  9564. to
  9565. ]
  9566. });
  9567. }
  9568. function flattenBody(body) {
  9569. if (body.type === 'alternative') {
  9570. return body.body;
  9571. } else {
  9572. return [body];
  9573. }
  9574. }
  9575. function incr(amount) {
  9576. amount = (amount || 1);
  9577. var res = str.substring(pos, pos + amount);
  9578. pos += (amount || 1);
  9579. return res;
  9580. }
  9581. function skip(value) {
  9582. if (!match(value)) {
  9583. bail('character', value);
  9584. }
  9585. }
  9586. function match(value) {
  9587. if (str.indexOf(value, pos) === pos) {
  9588. return incr(value.length);
  9589. }
  9590. }
  9591. function lookahead() {
  9592. return str[pos];
  9593. }
  9594. function current(value) {
  9595. return str.indexOf(value, pos) === pos;
  9596. }
  9597. function next(value) {
  9598. return str[pos + 1] === value;
  9599. }
  9600. function matchReg(regExp) {
  9601. var subStr = str.substring(pos);
  9602. var res = subStr.match(regExp);
  9603. if (res) {
  9604. res.range = [];
  9605. res.range[0] = pos;
  9606. incr(res[0].length);
  9607. res.range[1] = pos;
  9608. }
  9609. return res;
  9610. }
  9611. function parseDisjunction() {
  9612. // Disjunction ::
  9613. // Alternative
  9614. // Alternative | Disjunction
  9615. var res = [], from = pos;
  9616. res.push(parseAlternative());
  9617. while (match('|')) {
  9618. res.push(parseAlternative());
  9619. }
  9620. if (res.length === 1) {
  9621. return res[0];
  9622. }
  9623. return createDisjunction(res, from, pos);
  9624. }
  9625. function parseAlternative() {
  9626. var res = [], from = pos;
  9627. var term;
  9628. // Alternative ::
  9629. // [empty]
  9630. // Alternative Term
  9631. while (term = parseTerm()) {
  9632. res.push(term);
  9633. }
  9634. if (res.length === 1) {
  9635. return res[0];
  9636. }
  9637. return createAlternative(res, from, pos);
  9638. }
  9639. function parseTerm() {
  9640. // Term ::
  9641. // Anchor
  9642. // Atom
  9643. // Atom Quantifier
  9644. if (pos >= str.length || current('|') || current(')')) {
  9645. return null; /* Means: The term is empty */
  9646. }
  9647. var anchor = parseAnchor();
  9648. if (anchor) {
  9649. return anchor;
  9650. }
  9651. var atom = parseAtom();
  9652. if (!atom) {
  9653. bail('Expected atom');
  9654. }
  9655. var quantifier = parseQuantifier() || false;
  9656. if (quantifier) {
  9657. quantifier.body = flattenBody(atom);
  9658. // The quantifier contains the atom. Therefore, the beginning of the
  9659. // quantifier range is given by the beginning of the atom.
  9660. updateRawStart(quantifier, atom.range[0]);
  9661. return quantifier;
  9662. }
  9663. return atom;
  9664. }
  9665. function parseGroup(matchA, typeA, matchB, typeB) {
  9666. var type = null, from = pos;
  9667. if (match(matchA)) {
  9668. type = typeA;
  9669. } else if (match(matchB)) {
  9670. type = typeB;
  9671. } else {
  9672. return false;
  9673. }
  9674. return finishGroup(type, from);
  9675. }
  9676. function finishGroup(type, from) {
  9677. var body = parseDisjunction();
  9678. if (!body) {
  9679. bail('Expected disjunction');
  9680. }
  9681. skip(')');
  9682. var group = createGroup(type, flattenBody(body), from, pos);
  9683. if (type == 'normal') {
  9684. // Keep track of the number of closed groups. This is required for
  9685. // parseDecimalEscape(). In case the string is parsed a second time the
  9686. // value already holds the total count and no incrementation is required.
  9687. if (firstIteration) {
  9688. closedCaptureCounter++;
  9689. }
  9690. }
  9691. return group;
  9692. }
  9693. function parseAnchor() {
  9694. // Anchor ::
  9695. // ^
  9696. // $
  9697. // \ b
  9698. // \ B
  9699. // ( ? = Disjunction )
  9700. // ( ? ! Disjunction )
  9701. if (match('^')) {
  9702. return createAnchor('start', 1 /* rawLength */);
  9703. } else if (match('$')) {
  9704. return createAnchor('end', 1 /* rawLength */);
  9705. } else if (match('\\b')) {
  9706. return createAnchor('boundary', 2 /* rawLength */);
  9707. } else if (match('\\B')) {
  9708. return createAnchor('not-boundary', 2 /* rawLength */);
  9709. } else {
  9710. return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');
  9711. }
  9712. }
  9713. function parseQuantifier() {
  9714. // Quantifier ::
  9715. // QuantifierPrefix
  9716. // QuantifierPrefix ?
  9717. //
  9718. // QuantifierPrefix ::
  9719. // *
  9720. // +
  9721. // ?
  9722. // { DecimalDigits }
  9723. // { DecimalDigits , }
  9724. // { DecimalDigits , DecimalDigits }
  9725. var res, from = pos;
  9726. var quantifier;
  9727. var min, max;
  9728. if (match('*')) {
  9729. quantifier = createQuantifier(0);
  9730. }
  9731. else if (match('+')) {
  9732. quantifier = createQuantifier(1);
  9733. }
  9734. else if (match('?')) {
  9735. quantifier = createQuantifier(0, 1);
  9736. }
  9737. else if (res = matchReg(/^\{([0-9]+)\}/)) {
  9738. min = parseInt(res[1], 10);
  9739. quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
  9740. }
  9741. else if (res = matchReg(/^\{([0-9]+),\}/)) {
  9742. min = parseInt(res[1], 10);
  9743. quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
  9744. }
  9745. else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
  9746. min = parseInt(res[1], 10);
  9747. max = parseInt(res[2], 10);
  9748. if (min > max) {
  9749. bail('numbers out of order in {} quantifier', '', from, pos);
  9750. }
  9751. quantifier = createQuantifier(min, max, res.range[0], res.range[1]);
  9752. }
  9753. if (quantifier) {
  9754. if (match('?')) {
  9755. quantifier.greedy = false;
  9756. quantifier.range[1] += 1;
  9757. }
  9758. }
  9759. return quantifier;
  9760. }
  9761. function parseAtom() {
  9762. // Atom ::
  9763. // PatternCharacter
  9764. // .
  9765. // \ AtomEscape
  9766. // CharacterClass
  9767. // ( GroupSpecifier Disjunction )
  9768. // ( ? : Disjunction )
  9769. var res;
  9770. // jviereck: allow ']', '}' here as well to be compatible with browser's
  9771. // implementations: ']'.match(/]/);
  9772. // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) {
  9773. if (res = matchReg(/^[^^$\\.*+?(){[|]/)) {
  9774. // PatternCharacter
  9775. return createCharacter(res);
  9776. }
  9777. else if (match('.')) {
  9778. // .
  9779. return createDot();
  9780. }
  9781. else if (match('\\')) {
  9782. // \ AtomEscape
  9783. res = parseAtomEscape();
  9784. if (!res) {
  9785. if (!hasUnicodeFlag && lookahead() == 'c') {
  9786. // B.1.4 ExtendedAtom
  9787. // \[lookahead = c]
  9788. return createValue('symbol', 92, pos - 1, pos);
  9789. }
  9790. bail('atomEscape');
  9791. }
  9792. return res;
  9793. }
  9794. else if (res = parseCharacterClass()) {
  9795. return res;
  9796. }
  9797. else if (features.lookbehind && (res = parseGroup('(?<=', 'lookbehind', '(?<!', 'negativeLookbehind'))) {
  9798. return res;
  9799. }
  9800. else if (features.namedGroups && match("(?<")) {
  9801. var name = parseIdentifier();
  9802. skip(">");
  9803. var group = finishGroup("normal", name.range[0] - 3);
  9804. group.name = name;
  9805. return group;
  9806. }
  9807. else {
  9808. // ( Disjunction )
  9809. // ( ? : Disjunction )
  9810. return parseGroup('(?:', 'ignore', '(', 'normal');
  9811. }
  9812. }
  9813. function parseUnicodeSurrogatePairEscape(firstEscape) {
  9814. if (hasUnicodeFlag) {
  9815. var first, second;
  9816. if (firstEscape.kind == 'unicodeEscape' &&
  9817. (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&
  9818. current('\\') && next('u') ) {
  9819. var prevPos = pos;
  9820. pos++;
  9821. var secondEscape = parseClassEscape();
  9822. if (secondEscape.kind == 'unicodeEscape' &&
  9823. (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {
  9824. // Unicode surrogate pair
  9825. firstEscape.range[1] = secondEscape.range[1];
  9826. firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  9827. firstEscape.type = 'value';
  9828. firstEscape.kind = 'unicodeCodePointEscape';
  9829. addRaw(firstEscape);
  9830. }
  9831. else {
  9832. pos = prevPos;
  9833. }
  9834. }
  9835. }
  9836. return firstEscape;
  9837. }
  9838. function parseClassEscape() {
  9839. return parseAtomEscape(true);
  9840. }
  9841. function parseAtomEscape(insideCharacterClass) {
  9842. // AtomEscape ::
  9843. // DecimalEscape
  9844. // CharacterEscape
  9845. // CharacterClassEscape
  9846. // k GroupName
  9847. var res, from = pos;
  9848. res = parseDecimalEscape() || parseNamedReference();
  9849. if (res) {
  9850. return res;
  9851. }
  9852. // For ClassEscape
  9853. if (insideCharacterClass) {
  9854. if (match('b')) {
  9855. // 15.10.2.19
  9856. // The production ClassEscape :: b evaluates by returning the
  9857. // CharSet containing the one character <BS> (Unicode value 0008).
  9858. return createEscaped('singleEscape', 0x0008, '\\b');
  9859. } else if (match('B')) {
  9860. bail('\\B not possible inside of CharacterClass', '', from);
  9861. } else if (!hasUnicodeFlag && (res = matchReg(/^c([0-9])/))) {
  9862. // B.1.4
  9863. // c ClassControlLetter
  9864. return createEscaped('controlLetter', res[1] + 16, res[1], 2);
  9865. }
  9866. }
  9867. res = parseCharacterEscape();
  9868. return res;
  9869. }
  9870. function parseDecimalEscape() {
  9871. // DecimalEscape ::
  9872. // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
  9873. // CharacterClassEscape :: one of d D s S w W
  9874. var res, match;
  9875. if (res = matchReg(/^(?!0)\d+/)) {
  9876. match = res[0];
  9877. var refIdx = parseInt(res[0], 10);
  9878. if (refIdx <= closedCaptureCounter) {
  9879. // If the number is smaller than the normal-groups found so
  9880. // far, then it is a reference...
  9881. return createReference(res[0]);
  9882. } else {
  9883. // ... otherwise it needs to be interpreted as a octal (if the
  9884. // number is in an octal format). If it is NOT octal format,
  9885. // then the slash is ignored and the number is matched later
  9886. // as normal characters.
  9887. // Recall the negative decision to decide if the input must be parsed
  9888. // a second time with the total normal-groups.
  9889. backrefDenied.push(refIdx);
  9890. // Reset the position again, as maybe only parts of the previous
  9891. // matched numbers are actual octal numbers. E.g. in '019' only
  9892. // the '01' should be matched.
  9893. incr(-res[0].length);
  9894. if (res = matchReg(/^[0-7]{1,3}/)) {
  9895. return createEscaped('octal', parseInt(res[0], 8), res[0], 1);
  9896. } else {
  9897. // If we end up here, we have a case like /\91/. Then the
  9898. // first slash is to be ignored and the 9 & 1 to be treated
  9899. // like ordinary characters. Create a character for the
  9900. // first number only here - other number-characters
  9901. // (if available) will be matched later.
  9902. res = createCharacter(matchReg(/^[89]/));
  9903. return updateRawStart(res, res.range[0] - 1);
  9904. }
  9905. }
  9906. }
  9907. // Only allow octal numbers in the following. All matched numbers start
  9908. // with a zero (if the do not, the previous if-branch is executed).
  9909. // If the number is not octal format and starts with zero (e.g. `091`)
  9910. // then only the zeros `0` is treated here and the `91` are ordinary
  9911. // characters.
  9912. // Example:
  9913. // /\091/.exec('\091')[0].length === 3
  9914. else if (res = matchReg(/^[0-7]{1,3}/)) {
  9915. match = res[0];
  9916. if (/^0{1,3}$/.test(match)) {
  9917. // If they are all zeros, then only take the first one.
  9918. return createEscaped('null', 0x0000, '0', match.length + 1);
  9919. } else {
  9920. return createEscaped('octal', parseInt(match, 8), match, 1);
  9921. }
  9922. } else if (res = matchReg(/^[dDsSwW]/)) {
  9923. return createCharacterClassEscape(res[0]);
  9924. }
  9925. return false;
  9926. }
  9927. function parseNamedReference() {
  9928. if (features.namedGroups && matchReg(/^k<(?=.*?>)/)) {
  9929. var name = parseIdentifier();
  9930. skip('>');
  9931. return createNamedReference(name);
  9932. }
  9933. }
  9934. function parseRegExpUnicodeEscapeSequence() {
  9935. var res;
  9936. if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {
  9937. // UnicodeEscapeSequence
  9938. return parseUnicodeSurrogatePairEscape(
  9939. createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2)
  9940. );
  9941. } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {
  9942. // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)
  9943. return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);
  9944. }
  9945. }
  9946. function parseCharacterEscape() {
  9947. // CharacterEscape ::
  9948. // ControlEscape
  9949. // c ControlLetter
  9950. // HexEscapeSequence
  9951. // UnicodeEscapeSequence
  9952. // IdentityEscape
  9953. var res;
  9954. var from = pos;
  9955. if (res = matchReg(/^[fnrtv]/)) {
  9956. // ControlEscape
  9957. var codePoint = 0;
  9958. switch (res[0]) {
  9959. case 't': codePoint = 0x009; break;
  9960. case 'n': codePoint = 0x00A; break;
  9961. case 'v': codePoint = 0x00B; break;
  9962. case 'f': codePoint = 0x00C; break;
  9963. case 'r': codePoint = 0x00D; break;
  9964. }
  9965. return createEscaped('singleEscape', codePoint, '\\' + res[0]);
  9966. } else if (res = matchReg(/^c([a-zA-Z])/)) {
  9967. // c ControlLetter
  9968. return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);
  9969. } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) {
  9970. // HexEscapeSequence
  9971. return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2);
  9972. } else if (res = parseRegExpUnicodeEscapeSequence()) {
  9973. if (!res || res.codePoint > 0x10FFFF) {
  9974. bail('Invalid escape sequence', null, from, pos);
  9975. }
  9976. return res;
  9977. } else if (features.unicodePropertyEscape && hasUnicodeFlag && (res = matchReg(/^([pP])\{([^\}]+)\}/))) {
  9978. // https://github.com/jviereck/regjsparser/issues/77
  9979. return addRaw({
  9980. type: 'unicodePropertyEscape',
  9981. negative: res[1] === 'P',
  9982. value: res[2],
  9983. range: [res.range[0] - 1, res.range[1]],
  9984. raw: res[0]
  9985. });
  9986. } else {
  9987. // IdentityEscape
  9988. return parseIdentityEscape();
  9989. }
  9990. }
  9991. function parseIdentifierAtom(check) {
  9992. var ch = lookahead();
  9993. var from = pos;
  9994. if (ch === '\\') {
  9995. incr();
  9996. var esc = parseRegExpUnicodeEscapeSequence();
  9997. if (!esc || !check(esc.codePoint)) {
  9998. bail('Invalid escape sequence', null, from, pos);
  9999. }
  10000. return fromCodePoint(esc.codePoint);
  10001. }
  10002. var code = ch.charCodeAt(0);
  10003. if (code >= 0xD800 && code <= 0xDBFF) {
  10004. ch += str[pos + 1];
  10005. var second = ch.charCodeAt(1);
  10006. if (second >= 0xDC00 && second <= 0xDFFF) {
  10007. // Unicode surrogate pair
  10008. code = (code - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  10009. }
  10010. }
  10011. if (!check(code)) return;
  10012. incr();
  10013. if (code > 0xFFFF) incr();
  10014. return ch;
  10015. }
  10016. function parseIdentifier() {
  10017. // RegExpIdentifierName ::
  10018. // RegExpIdentifierStart
  10019. // RegExpIdentifierName RegExpIdentifierContinue
  10020. //
  10021. // RegExpIdentifierStart ::
  10022. // UnicodeIDStart
  10023. // $
  10024. // _
  10025. // \ RegExpUnicodeEscapeSequence
  10026. //
  10027. // RegExpIdentifierContinue ::
  10028. // UnicodeIDContinue
  10029. // $
  10030. // _
  10031. // \ RegExpUnicodeEscapeSequence
  10032. // <ZWNJ>
  10033. // <ZWJ>
  10034. var start = pos;
  10035. var res = parseIdentifierAtom(isIdentifierStart);
  10036. if (!res) {
  10037. bail('Invalid identifier');
  10038. }
  10039. var ch;
  10040. while (ch = parseIdentifierAtom(isIdentifierPart)) {
  10041. res += ch;
  10042. }
  10043. return addRaw({
  10044. type: 'identifier',
  10045. value: res,
  10046. range: [start, pos]
  10047. });
  10048. }
  10049. function isIdentifierStart(ch) {
  10050. // Generated by `tools/generate-identifier-regex.js`.
  10051. var NonAsciiIdentifierStart = /[\$A-Z_a-z\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\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\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-\u1CF1\u1CF5\u1CF6\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-\uA7B9\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-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB1
  10052. return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
  10053. (ch >= 65 && ch <= 90) || // A..Z
  10054. (ch >= 97 && ch <= 122) || // a..z
  10055. ((ch >= 0x80) && NonAsciiIdentifierStart.test(fromCodePoint(ch)));
  10056. }
  10057. // Taken from the Esprima parser.
  10058. function isIdentifierPart(ch) {
  10059. // Generated by `tools/generate-identifier-regex.js`.
  10060. var NonAsciiIdentifierPartOnly = /[0-9_\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-\u0EB9\u0EBB\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\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u200C\u200D\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]|\uD800[\uDDFD\uDEE0\uDF76-\uDF7A]|\uD801[\uDCA0-\uDCA9]|\uD802[\uDE01-\uDE03\uDE05\uDE06\uDE0C-\uDE0F\uDE38-\uDE3A\uDE3F\uDEE5\uDEE6]|\uD803[\uDD24-\uDD27\uDD30-\uDD39\uDF46-\uDF50]|\uD804[\uDC00-\uDC02\uDC38-\uDC46\uDC66-\uDC6F\uDC7F-\uDC82\uDCB0-\uDCBA\uDCF0-\uDCF9\uDD00-\uDD02\uDD27-\uDD34\uDD36-\uDD3F\uDD45\uDD46\uDD73\uDD80-\uDD82\uDDB3-\uDDC0\uDDC9-\uDDCC\uDDD0-\uDDD9\uDE2C-\uDE37\uDE3E\uDEDF-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF3B\uDF3C\uDF3E-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF57\uDF62\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC35-\uDC46\uDC50-\uDC59\uDC5E\uDCB0-\uDCC3\uDCD0-\uDCD9\uDDAF-\uDDB5\uDDB8-\uDDC0\uDDDC\uDDDD\uDE30-\uDE40\uDE50-\uDE59\uDEAB-\uDEB7\uDEC0-\uDEC9\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDC2C-\uDC3A\uDCE0-\uDCE9\uDE01-\uDE0A\uDE33-\uDE39\uDE3B-\uDE3E\uDE47\uDE51-\uDE5B\uDE8A-\uDE99]|\uD807[\uDC2F-\uDC36\uDC38-\uDC3F\uDC50-\uDC59\uDC92-\uDCA7\uDCA9-\uDCB6\uDD31-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD45\uDD47\uDD50-\uDD59\uDD8A-\uDD8E\uDD90\uDD91\uDD93-\uDD97\uDDA0-\uDDA9\uDEF3-\uDEF6]|\uD81A[\uDE60-\uDE69\uDEF0-\uDEF4\uDF30-\uDF36\uDF50-\uDF59]|\uD81B[\uDF51-\uDF7E\uDF8F-\uDF92]|\uD82F[\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDCD0-\uDCD6\uDD44-\uDD4A\uDD50-\uDD5
  10061. return isIdentifierStart(ch) ||
  10062. (ch >= 48 && ch <= 57) || // 0..9
  10063. ((ch >= 0x80) && NonAsciiIdentifierPartOnly.test(fromCodePoint(ch)));
  10064. }
  10065. function parseIdentityEscape() {
  10066. // IdentityEscape ::
  10067. // SourceCharacter but not c
  10068. var tmp;
  10069. if (lookahead() !== 'c') {
  10070. tmp = incr();
  10071. return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1);
  10072. }
  10073. return null;
  10074. }
  10075. function parseCharacterClass() {
  10076. // CharacterClass ::
  10077. // [ [lookahead ∉ {^}] ClassRanges ]
  10078. // [ ^ ClassRanges ]
  10079. var res, from = pos;
  10080. if (res = matchReg(/^\[\^/)) {
  10081. res = parseClassRanges();
  10082. skip(']');
  10083. return createCharacterClass(res, true, from, pos);
  10084. } else if (match('[')) {
  10085. res = parseClassRanges();
  10086. skip(']');
  10087. return createCharacterClass(res, false, from, pos);
  10088. }
  10089. return null;
  10090. }
  10091. function parseClassRanges() {
  10092. // ClassRanges ::
  10093. // [empty]
  10094. // NonemptyClassRanges
  10095. var res;
  10096. if (current(']')) {
  10097. // Empty array means nothing insinde of the ClassRange.
  10098. return [];
  10099. } else {
  10100. res = parseNonemptyClassRanges();
  10101. if (!res) {
  10102. bail('nonEmptyClassRanges');
  10103. }
  10104. return res;
  10105. }
  10106. }
  10107. function parseHelperClassRanges(atom) {
  10108. var from, to, res;
  10109. if (current('-') && !next(']')) {
  10110. // ClassAtom - ClassAtom ClassRanges
  10111. skip('-');
  10112. res = parseClassAtom();
  10113. if (!res) {
  10114. bail('classAtom');
  10115. }
  10116. to = pos;
  10117. var classRanges = parseClassRanges();
  10118. if (!classRanges) {
  10119. bail('classRanges');
  10120. }
  10121. from = atom.range[0];
  10122. if (classRanges.type === 'empty') {
  10123. return [createClassRange(atom, res, from, to)];
  10124. }
  10125. return [createClassRange(atom, res, from, to)].concat(classRanges);
  10126. }
  10127. res = parseNonemptyClassRangesNoDash();
  10128. if (!res) {
  10129. bail('nonEmptyClassRangesNoDash');
  10130. }
  10131. return [atom].concat(res);
  10132. }
  10133. function parseNonemptyClassRanges() {
  10134. // NonemptyClassRanges ::
  10135. // ClassAtom
  10136. // ClassAtom NonemptyClassRangesNoDash
  10137. // ClassAtom - ClassAtom ClassRanges
  10138. var atom = parseClassAtom();
  10139. if (!atom) {
  10140. bail('classAtom');
  10141. }
  10142. if (current(']')) {
  10143. // ClassAtom
  10144. return [atom];
  10145. }
  10146. // ClassAtom NonemptyClassRangesNoDash
  10147. // ClassAtom - ClassAtom ClassRanges
  10148. return parseHelperClassRanges(atom);
  10149. }
  10150. function parseNonemptyClassRangesNoDash() {
  10151. // NonemptyClassRangesNoDash ::
  10152. // ClassAtom
  10153. // ClassAtomNoDash NonemptyClassRangesNoDash
  10154. // ClassAtomNoDash - ClassAtom ClassRanges
  10155. var res = parseClassAtom();
  10156. if (!res) {
  10157. bail('classAtom');
  10158. }
  10159. if (current(']')) {
  10160. // ClassAtom
  10161. return res;
  10162. }
  10163. // ClassAtomNoDash NonemptyClassRangesNoDash
  10164. // ClassAtomNoDash - ClassAtom ClassRanges
  10165. return parseHelperClassRanges(res);
  10166. }
  10167. function parseClassAtom() {
  10168. // ClassAtom ::
  10169. // -
  10170. // ClassAtomNoDash
  10171. if (match('-')) {
  10172. return createCharacter('-');
  10173. } else {
  10174. return parseClassAtomNoDash();
  10175. }
  10176. }
  10177. function parseClassAtomNoDash() {
  10178. // ClassAtomNoDash ::
  10179. // SourceCharacter but not one of \ or ] or -
  10180. // \ ClassEscape
  10181. var res;
  10182. if (res = matchReg(/^[^\\\]-]/)) {
  10183. return createCharacter(res[0]);
  10184. } else if (match('\\')) {
  10185. res = parseClassEscape();
  10186. if (!res) {
  10187. bail('classEscape');
  10188. }
  10189. return parseUnicodeSurrogatePairEscape(res);
  10190. }
  10191. }
  10192. function bail(message, details, from, to) {
  10193. from = from == null ? pos : from;
  10194. to = to == null ? from : to;
  10195. var contextStart = Math.max(0, from - 10);
  10196. var contextEnd = Math.min(to + 10, str.length);
  10197. // Output a bit of context and a line pointing to where our error is.
  10198. //
  10199. // We are assuming that there are no actual newlines in the content as this is a regular expression.
  10200. var context = ' ' + str.substring(contextStart, contextEnd);
  10201. var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^';
  10202. throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer);
  10203. }
  10204. var backrefDenied = [];
  10205. var closedCaptureCounter = 0;
  10206. var firstIteration = true;
  10207. var hasUnicodeFlag = (flags || "").indexOf("u") !== -1;
  10208. var pos = 0;
  10209. // Convert the input to a string and treat the empty string special.
  10210. str = String(str);
  10211. if (str === '') {
  10212. str = '(?:)';
  10213. }
  10214. var result = parseDisjunction();
  10215. if (result.range[1] !== str.length) {
  10216. bail('Could not parse entire input - got stuck', '', result.range[1]);
  10217. }
  10218. // The spec requires to interpret the `\2` in `/\2()()/` as backreference.
  10219. // As the parser collects the number of capture groups as the string is
  10220. // parsed it is impossible to make these decisions at the point when the
  10221. // `\2` is handled. In case the local decision turns out to be wrong after
  10222. // the parsing has finished, the input string is parsed a second time with
  10223. // the total number of capture groups set.
  10224. //
  10225. // SEE: https://github.com/jviereck/regjsparser/issues/70
  10226. for (var i = 0; i < backrefDenied.length; i++) {
  10227. if (backrefDenied[i] <= closedCaptureCounter) {
  10228. // Parse the input a second time.
  10229. pos = 0;
  10230. firstIteration = false;
  10231. return parseDisjunction();
  10232. }
  10233. }
  10234. return result;
  10235. }
  10236. var regjsparser = {
  10237. parse: parse
  10238. };
  10239. if ('object' !== 'undefined' && module.exports) {
  10240. module.exports = regjsparser;
  10241. } else {
  10242. window.regjsparser = regjsparser;
  10243. }
  10244. }());
  10245. });
  10246. var regenerate = createCommonjsModule(function (module, exports) {
  10247. /*! https://mths.be/regenerate v1.3.3 by @mathias | MIT license */
  10248. (function(root) {
  10249. // Detect free variables `exports`.
  10250. var freeExports = 'object' == 'object' && exports;
  10251. // Detect free variable `module`.
  10252. var freeModule = 'object' == 'object' && module &&
  10253. module.exports == freeExports && module;
  10254. // Detect free variable `global`, from Node.js/io.js or Browserified code,
  10255. // and use it as `root`.
  10256. var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
  10257. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  10258. root = freeGlobal;
  10259. }
  10260. /*--------------------------------------------------------------------------*/
  10261. var ERRORS = {
  10262. 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
  10263. 'to the `start` value.',
  10264. 'codePointRange': 'Invalid code point value. Code points range from ' +
  10265. 'U+000000 to U+10FFFF.'
  10266. };
  10267. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
  10268. var HIGH_SURROGATE_MIN = 0xD800;
  10269. var HIGH_SURROGATE_MAX = 0xDBFF;
  10270. var LOW_SURROGATE_MIN = 0xDC00;
  10271. var LOW_SURROGATE_MAX = 0xDFFF;
  10272. // In Regenerate output, `\0` is never preceded by `\` because we sort by
  10273. // code point value, so let’s keep this regular expression simple.
  10274. var regexNull = /\\x00([^0123456789]|$)/g;
  10275. var object = {};
  10276. var hasOwnProperty = object.hasOwnProperty;
  10277. var extend = function(destination, source) {
  10278. var key;
  10279. for (key in source) {
  10280. if (hasOwnProperty.call(source, key)) {
  10281. destination[key] = source[key];
  10282. }
  10283. }
  10284. return destination;
  10285. };
  10286. var forEach = function(array, callback) {
  10287. var index = -1;
  10288. var length = array.length;
  10289. while (++index < length) {
  10290. callback(array[index], index);
  10291. }
  10292. };
  10293. var toString = object.toString;
  10294. var isArray = function(value) {
  10295. return toString.call(value) == '[object Array]';
  10296. };
  10297. var isNumber = function(value) {
  10298. return typeof value == 'number' ||
  10299. toString.call(value) == '[object Number]';
  10300. };
  10301. // This assumes that `number` is a positive integer that `toString()`s nicely
  10302. // (which is the case for all code point values).
  10303. var zeroes = '0000';
  10304. var pad = function(number, totalCharacters) {
  10305. var string = String(number);
  10306. return string.length < totalCharacters
  10307. ? (zeroes + string).slice(-totalCharacters)
  10308. : string;
  10309. };
  10310. var hex = function(number) {
  10311. return Number(number).toString(16).toUpperCase();
  10312. };
  10313. var slice = [].slice;
  10314. /*--------------------------------------------------------------------------*/
  10315. var dataFromCodePoints = function(codePoints) {
  10316. var index = -1;
  10317. var length = codePoints.length;
  10318. var max = length - 1;
  10319. var result = [];
  10320. var isStart = true;
  10321. var tmp;
  10322. var previous = 0;
  10323. while (++index < length) {
  10324. tmp = codePoints[index];
  10325. if (isStart) {
  10326. result.push(tmp);
  10327. previous = tmp;
  10328. isStart = false;
  10329. } else {
  10330. if (tmp == previous + 1) {
  10331. if (index != max) {
  10332. previous = tmp;
  10333. continue;
  10334. } else {
  10335. isStart = true;
  10336. result.push(tmp + 1);
  10337. }
  10338. } else {
  10339. // End the previous range and start a new one.
  10340. result.push(previous + 1, tmp);
  10341. previous = tmp;
  10342. }
  10343. }
  10344. }
  10345. if (!isStart) {
  10346. result.push(tmp + 1);
  10347. }
  10348. return result;
  10349. };
  10350. var dataRemove = function(data, codePoint) {
  10351. // Iterate over the data per `(start, end)` pair.
  10352. var index = 0;
  10353. var start;
  10354. var end;
  10355. var length = data.length;
  10356. while (index < length) {
  10357. start = data[index];
  10358. end = data[index + 1];
  10359. if (codePoint >= start && codePoint < end) {
  10360. // Modify this pair.
  10361. if (codePoint == start) {
  10362. if (end == start + 1) {
  10363. // Just remove `start` and `end`.
  10364. data.splice(index, 2);
  10365. return data;
  10366. } else {
  10367. // Just replace `start` with a new value.
  10368. data[index] = codePoint + 1;
  10369. return data;
  10370. }
  10371. } else if (codePoint == end - 1) {
  10372. // Just replace `end` with a new value.
  10373. data[index + 1] = codePoint;
  10374. return data;
  10375. } else {
  10376. // Replace `[start, end]` with `[startA, endA, startB, endB]`.
  10377. data.splice(index, 2, start, codePoint, codePoint + 1, end);
  10378. return data;
  10379. }
  10380. }
  10381. index += 2;
  10382. }
  10383. return data;
  10384. };
  10385. var dataRemoveRange = function(data, rangeStart, rangeEnd) {
  10386. if (rangeEnd < rangeStart) {
  10387. throw Error(ERRORS.rangeOrder);
  10388. }
  10389. // Iterate over the data per `(start, end)` pair.
  10390. var index = 0;
  10391. var start;
  10392. var end;
  10393. while (index < data.length) {
  10394. start = data[index];
  10395. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  10396. // Exit as soon as no more matching pairs can be found.
  10397. if (start > rangeEnd) {
  10398. return data;
  10399. }
  10400. // Check if this range pair is equal to, or forms a subset of, the range
  10401. // to be removed.
  10402. // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
  10403. // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
  10404. if (rangeStart <= start && rangeEnd >= end) {
  10405. // Remove this pair.
  10406. data.splice(index, 2);
  10407. continue;
  10408. }
  10409. // Check if both `rangeStart` and `rangeEnd` are within the bounds of
  10410. // this pair.
  10411. // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
  10412. if (rangeStart >= start && rangeEnd < end) {
  10413. if (rangeStart == start) {
  10414. // Replace `[start, end]` with `[startB, endB]`.
  10415. data[index] = rangeEnd + 1;
  10416. data[index + 1] = end + 1;
  10417. return data;
  10418. }
  10419. // Replace `[start, end]` with `[startA, endA, startB, endB]`.
  10420. data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
  10421. return data;
  10422. }
  10423. // Check if only `rangeStart` is within the bounds of this pair.
  10424. // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
  10425. if (rangeStart >= start && rangeStart <= end) {
  10426. // Replace `end` with `rangeStart`.
  10427. data[index + 1] = rangeStart;
  10428. // Note: we cannot `return` just yet, in case any following pairs still
  10429. // contain matching code points.
  10430. // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
  10431. // → `[0, 4, 21, 31]`.
  10432. }
  10433. // Check if only `rangeEnd` is within the bounds of this pair.
  10434. // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
  10435. else if (rangeEnd >= start && rangeEnd <= end) {
  10436. // Just replace `start`.
  10437. data[index] = rangeEnd + 1;
  10438. return data;
  10439. }
  10440. index += 2;
  10441. }
  10442. return data;
  10443. };
  10444. var dataAdd = function(data, codePoint) {
  10445. // Iterate over the data per `(start, end)` pair.
  10446. var index = 0;
  10447. var start;
  10448. var end;
  10449. var lastIndex = null;
  10450. var length = data.length;
  10451. if (codePoint < 0x0 || codePoint > 0x10FFFF) {
  10452. throw RangeError(ERRORS.codePointRange);
  10453. }
  10454. while (index < length) {
  10455. start = data[index];
  10456. end = data[index + 1];
  10457. // Check if the code point is already in the set.
  10458. if (codePoint >= start && codePoint < end) {
  10459. return data;
  10460. }
  10461. if (codePoint == start - 1) {
  10462. // Just replace `start` with a new value.
  10463. data[index] = codePoint;
  10464. return data;
  10465. }
  10466. // At this point, if `start` is `greater` than `codePoint`, insert a new
  10467. // `[start, end]` pair before the current pair, or after the current pair
  10468. // if there is a known `lastIndex`.
  10469. if (start > codePoint) {
  10470. data.splice(
  10471. lastIndex != null ? lastIndex + 2 : 0,
  10472. 0,
  10473. codePoint,
  10474. codePoint + 1
  10475. );
  10476. return data;
  10477. }
  10478. if (codePoint == end) {
  10479. // Check if adding this code point causes two separate ranges to become
  10480. // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
  10481. if (codePoint + 1 == data[index + 2]) {
  10482. data.splice(index, 4, start, data[index + 3]);
  10483. return data;
  10484. }
  10485. // Else, just replace `end` with a new value.
  10486. data[index + 1] = codePoint + 1;
  10487. return data;
  10488. }
  10489. lastIndex = index;
  10490. index += 2;
  10491. }
  10492. // The loop has finished; add the new pair to the end of the data set.
  10493. data.push(codePoint, codePoint + 1);
  10494. return data;
  10495. };
  10496. var dataAddData = function(dataA, dataB) {
  10497. // Iterate over the data per `(start, end)` pair.
  10498. var index = 0;
  10499. var start;
  10500. var end;
  10501. var data = dataA.slice();
  10502. var length = dataB.length;
  10503. while (index < length) {
  10504. start = dataB[index];
  10505. end = dataB[index + 1] - 1;
  10506. if (start == end) {
  10507. data = dataAdd(data, start);
  10508. } else {
  10509. data = dataAddRange(data, start, end);
  10510. }
  10511. index += 2;
  10512. }
  10513. return data;
  10514. };
  10515. var dataRemoveData = function(dataA, dataB) {
  10516. // Iterate over the data per `(start, end)` pair.
  10517. var index = 0;
  10518. var start;
  10519. var end;
  10520. var data = dataA.slice();
  10521. var length = dataB.length;
  10522. while (index < length) {
  10523. start = dataB[index];
  10524. end = dataB[index + 1] - 1;
  10525. if (start == end) {
  10526. data = dataRemove(data, start);
  10527. } else {
  10528. data = dataRemoveRange(data, start, end);
  10529. }
  10530. index += 2;
  10531. }
  10532. return data;
  10533. };
  10534. var dataAddRange = function(data, rangeStart, rangeEnd) {
  10535. if (rangeEnd < rangeStart) {
  10536. throw Error(ERRORS.rangeOrder);
  10537. }
  10538. if (
  10539. rangeStart < 0x0 || rangeStart > 0x10FFFF ||
  10540. rangeEnd < 0x0 || rangeEnd > 0x10FFFF
  10541. ) {
  10542. throw RangeError(ERRORS.codePointRange);
  10543. }
  10544. // Iterate over the data per `(start, end)` pair.
  10545. var index = 0;
  10546. var start;
  10547. var end;
  10548. var added = false;
  10549. var length = data.length;
  10550. while (index < length) {
  10551. start = data[index];
  10552. end = data[index + 1];
  10553. if (added) {
  10554. // The range has already been added to the set; at this point, we just
  10555. // need to get rid of the following ranges in case they overlap.
  10556. // Check if this range can be combined with the previous range.
  10557. if (start == rangeEnd + 1) {
  10558. data.splice(index - 1, 2);
  10559. return data;
  10560. }
  10561. // Exit as soon as no more possibly overlapping pairs can be found.
  10562. if (start > rangeEnd) {
  10563. return data;
  10564. }
  10565. // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
  10566. // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
  10567. // `0,16` range that was previously added.
  10568. if (start >= rangeStart && start <= rangeEnd) {
  10569. // `start` lies within the range that was previously added.
  10570. if (end > rangeStart && end - 1 <= rangeEnd) {
  10571. // `end` lies within the range that was previously added as well,
  10572. // so remove this pair.
  10573. data.splice(index, 2);
  10574. index -= 2;
  10575. // Note: we cannot `return` just yet, as there may still be other
  10576. // overlapping pairs.
  10577. } else {
  10578. // `start` lies within the range that was previously added, but
  10579. // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
  10580. // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
  10581. // Remove the previously added `end` and the current `start`.
  10582. data.splice(index - 1, 2);
  10583. index -= 2;
  10584. }
  10585. // Note: we cannot return yet.
  10586. }
  10587. }
  10588. else if (start == rangeEnd + 1) {
  10589. data[index] = rangeStart;
  10590. return data;
  10591. }
  10592. // Check if a new pair must be inserted *before* the current one.
  10593. else if (start > rangeEnd) {
  10594. data.splice(index, 0, rangeStart, rangeEnd + 1);
  10595. return data;
  10596. }
  10597. else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
  10598. // The new range lies entirely within an existing range pair. No action
  10599. // needed.
  10600. return data;
  10601. }
  10602. else if (
  10603. // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
  10604. (rangeStart >= start && rangeStart < end) ||
  10605. // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
  10606. end == rangeStart
  10607. ) {
  10608. // Replace `end` with the new value.
  10609. data[index + 1] = rangeEnd + 1;
  10610. // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
  10611. // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
  10612. added = true;
  10613. // Note: we cannot `return` just yet.
  10614. }
  10615. else if (rangeStart <= start && rangeEnd + 1 >= end) {
  10616. // The new range is a superset of the old range.
  10617. data[index] = rangeStart;
  10618. data[index + 1] = rangeEnd + 1;
  10619. added = true;
  10620. }
  10621. index += 2;
  10622. }
  10623. // The loop has finished without doing anything; add the new pair to the end
  10624. // of the data set.
  10625. if (!added) {
  10626. data.push(rangeStart, rangeEnd + 1);
  10627. }
  10628. return data;
  10629. };
  10630. var dataContains = function(data, codePoint) {
  10631. var index = 0;
  10632. var length = data.length;
  10633. // Exit early if `codePoint` is not within `data`’s overall range.
  10634. var start = data[index];
  10635. var end = data[length - 1];
  10636. if (length >= 2) {
  10637. if (codePoint < start || codePoint > end) {
  10638. return false;
  10639. }
  10640. }
  10641. // Iterate over the data per `(start, end)` pair.
  10642. while (index < length) {
  10643. start = data[index];
  10644. end = data[index + 1];
  10645. if (codePoint >= start && codePoint < end) {
  10646. return true;
  10647. }
  10648. index += 2;
  10649. }
  10650. return false;
  10651. };
  10652. var dataIntersection = function(data, codePoints) {
  10653. var index = 0;
  10654. var length = codePoints.length;
  10655. var codePoint;
  10656. var result = [];
  10657. while (index < length) {
  10658. codePoint = codePoints[index];
  10659. if (dataContains(data, codePoint)) {
  10660. result.push(codePoint);
  10661. }
  10662. ++index;
  10663. }
  10664. return dataFromCodePoints(result);
  10665. };
  10666. var dataIsEmpty = function(data) {
  10667. return !data.length;
  10668. };
  10669. var dataIsSingleton = function(data) {
  10670. // Check if the set only represents a single code point.
  10671. return data.length == 2 && data[0] + 1 == data[1];
  10672. };
  10673. var dataToArray = function(data) {
  10674. // Iterate over the data per `(start, end)` pair.
  10675. var index = 0;
  10676. var start;
  10677. var end;
  10678. var result = [];
  10679. var length = data.length;
  10680. while (index < length) {
  10681. start = data[index];
  10682. end = data[index + 1];
  10683. while (start < end) {
  10684. result.push(start);
  10685. ++start;
  10686. }
  10687. index += 2;
  10688. }
  10689. return result;
  10690. };
  10691. /*--------------------------------------------------------------------------*/
  10692. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  10693. var floor = Math.floor;
  10694. var highSurrogate = function(codePoint) {
  10695. return parseInt(
  10696. floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
  10697. 10
  10698. );
  10699. };
  10700. var lowSurrogate = function(codePoint) {
  10701. return parseInt(
  10702. (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
  10703. 10
  10704. );
  10705. };
  10706. var stringFromCharCode = String.fromCharCode;
  10707. var codePointToString = function(codePoint) {
  10708. var string;
  10709. // https://mathiasbynens.be/notes/javascript-escapes#single
  10710. // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
  10711. // different meaning in regular expressions (word boundary), so it cannot
  10712. // be used here.
  10713. if (codePoint == 0x09) {
  10714. string = '\\t';
  10715. }
  10716. // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
  10717. // else if (codePoint == 0x0B) {
  10718. // string = '\\v';
  10719. // }
  10720. else if (codePoint == 0x0A) {
  10721. string = '\\n';
  10722. }
  10723. else if (codePoint == 0x0C) {
  10724. string = '\\f';
  10725. }
  10726. else if (codePoint == 0x0D) {
  10727. string = '\\r';
  10728. }
  10729. else if (codePoint == 0x2D) {
  10730. // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
  10731. // Note: `-` (U+002D HYPHEN-MINUS) is escaped in this way rather
  10732. // than by backslash-escaping, in case the output is used outside
  10733. // of a character class in a `u` RegExp. /\-/u throws, but
  10734. // /\x2D/u is fine.
  10735. string = '\\x2D';
  10736. }
  10737. else if (codePoint == 0x5C) {
  10738. string = '\\\\';
  10739. }
  10740. else if (
  10741. codePoint == 0x24 ||
  10742. (codePoint >= 0x28 && codePoint <= 0x2B) ||
  10743. codePoint == 0x2E || codePoint == 0x2F ||
  10744. codePoint == 0x3F ||
  10745. (codePoint >= 0x5B && codePoint <= 0x5E) ||
  10746. (codePoint >= 0x7B && codePoint <= 0x7D)
  10747. ) {
  10748. // The code point maps to an unsafe printable ASCII character;
  10749. // backslash-escape it. Here’s the list of those symbols:
  10750. //
  10751. // $()*+./?[\]^{|}
  10752. //
  10753. // This matches SyntaxCharacters as well as `/` (U+002F SOLIDUS).
  10754. // https://tc39.github.io/ecma262/#prod-SyntaxCharacter
  10755. string = '\\' + stringFromCharCode(codePoint);
  10756. }
  10757. else if (codePoint >= 0x20 && codePoint <= 0x7E) {
  10758. // The code point maps to one of these printable ASCII symbols
  10759. // (including the space character):
  10760. //
  10761. // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
  10762. // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
  10763. //
  10764. // These can safely be used directly.
  10765. string = stringFromCharCode(codePoint);
  10766. }
  10767. else if (codePoint <= 0xFF) {
  10768. string = '\\x' + pad(hex(codePoint), 2);
  10769. }
  10770. else { // `codePoint <= 0xFFFF` holds true.
  10771. // https://mathiasbynens.be/notes/javascript-escapes#unicode
  10772. string = '\\u' + pad(hex(codePoint), 4);
  10773. }
  10774. // There’s no need to account for astral symbols / surrogate pairs here,
  10775. // since `codePointToString` is private and only used for BMP code points.
  10776. // But if that’s what you need, just add an `else` block with this code:
  10777. //
  10778. // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
  10779. // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
  10780. return string;
  10781. };
  10782. var codePointToStringUnicode = function(codePoint) {
  10783. if (codePoint <= 0xFFFF) {
  10784. return codePointToString(codePoint);
  10785. }
  10786. return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
  10787. };
  10788. var symbolToCodePoint = function(symbol) {
  10789. var length = symbol.length;
  10790. var first = symbol.charCodeAt(0);
  10791. var second;
  10792. if (
  10793. first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
  10794. length > 1 // There is a next code unit.
  10795. ) {
  10796. // `first` is a high surrogate, and there is a next character. Assume
  10797. // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
  10798. second = symbol.charCodeAt(1);
  10799. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  10800. return (first - HIGH_SURROGATE_MIN) * 0x400 +
  10801. second - LOW_SURROGATE_MIN + 0x10000;
  10802. }
  10803. return first;
  10804. };
  10805. var createBMPCharacterClasses = function(data) {
  10806. // Iterate over the data per `(start, end)` pair.
  10807. var result = '';
  10808. var index = 0;
  10809. var start;
  10810. var end;
  10811. var length = data.length;
  10812. if (dataIsSingleton(data)) {
  10813. return codePointToString(data[0]);
  10814. }
  10815. while (index < length) {
  10816. start = data[index];
  10817. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  10818. if (start == end) {
  10819. result += codePointToString(start);
  10820. } else if (start + 1 == end) {
  10821. result += codePointToString(start) + codePointToString(end);
  10822. } else {
  10823. result += codePointToString(start) + '-' + codePointToString(end);
  10824. }
  10825. index += 2;
  10826. }
  10827. return '[' + result + ']';
  10828. };
  10829. var createUnicodeCharacterClasses = function(data) {
  10830. // Iterate over the data per `(start, end)` pair.
  10831. var result = '';
  10832. var index = 0;
  10833. var start;
  10834. var end;
  10835. var length = data.length;
  10836. if (dataIsSingleton(data)) {
  10837. return codePointToStringUnicode(data[0]);
  10838. }
  10839. while (index < length) {
  10840. start = data[index];
  10841. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  10842. if (start == end) {
  10843. result += codePointToStringUnicode(start);
  10844. } else if (start + 1 == end) {
  10845. result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
  10846. } else {
  10847. result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
  10848. }
  10849. index += 2;
  10850. }
  10851. return '[' + result + ']';
  10852. };
  10853. var splitAtBMP = function(data) {
  10854. // Iterate over the data per `(start, end)` pair.
  10855. var loneHighSurrogates = [];
  10856. var loneLowSurrogates = [];
  10857. var bmp = [];
  10858. var astral = [];
  10859. var index = 0;
  10860. var start;
  10861. var end;
  10862. var length = data.length;
  10863. while (index < length) {
  10864. start = data[index];
  10865. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  10866. if (start < HIGH_SURROGATE_MIN) {
  10867. // The range starts and ends before the high surrogate range.
  10868. // E.g. (0, 0x10).
  10869. if (end < HIGH_SURROGATE_MIN) {
  10870. bmp.push(start, end + 1);
  10871. }
  10872. // The range starts before the high surrogate range and ends within it.
  10873. // E.g. (0, 0xD855).
  10874. if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
  10875. bmp.push(start, HIGH_SURROGATE_MIN);
  10876. loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
  10877. }
  10878. // The range starts before the high surrogate range and ends in the low
  10879. // surrogate range. E.g. (0, 0xDCFF).
  10880. if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
  10881. bmp.push(start, HIGH_SURROGATE_MIN);
  10882. loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
  10883. loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
  10884. }
  10885. // The range starts before the high surrogate range and ends after the
  10886. // low surrogate range. E.g. (0, 0x10FFFF).
  10887. if (end > LOW_SURROGATE_MAX) {
  10888. bmp.push(start, HIGH_SURROGATE_MIN);
  10889. loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
  10890. loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
  10891. if (end <= 0xFFFF) {
  10892. bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
  10893. } else {
  10894. bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
  10895. astral.push(0xFFFF + 1, end + 1);
  10896. }
  10897. }
  10898. } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
  10899. // The range starts and ends in the high surrogate range.
  10900. // E.g. (0xD855, 0xD866).
  10901. if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
  10902. loneHighSurrogates.push(start, end + 1);
  10903. }
  10904. // The range starts in the high surrogate range and ends in the low
  10905. // surrogate range. E.g. (0xD855, 0xDCFF).
  10906. if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
  10907. loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
  10908. loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
  10909. }
  10910. // The range starts in the high surrogate range and ends after the low
  10911. // surrogate range. E.g. (0xD855, 0x10FFFF).
  10912. if (end > LOW_SURROGATE_MAX) {
  10913. loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
  10914. loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
  10915. if (end <= 0xFFFF) {
  10916. bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
  10917. } else {
  10918. bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
  10919. astral.push(0xFFFF + 1, end + 1);
  10920. }
  10921. }
  10922. } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
  10923. // The range starts and ends in the low surrogate range.
  10924. // E.g. (0xDCFF, 0xDDFF).
  10925. if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
  10926. loneLowSurrogates.push(start, end + 1);
  10927. }
  10928. // The range starts in the low surrogate range and ends after the low
  10929. // surrogate range. E.g. (0xDCFF, 0x10FFFF).
  10930. if (end > LOW_SURROGATE_MAX) {
  10931. loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
  10932. if (end <= 0xFFFF) {
  10933. bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
  10934. } else {
  10935. bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
  10936. astral.push(0xFFFF + 1, end + 1);
  10937. }
  10938. }
  10939. } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
  10940. // The range starts and ends after the low surrogate range.
  10941. // E.g. (0xFFAA, 0x10FFFF).
  10942. if (end <= 0xFFFF) {
  10943. bmp.push(start, end + 1);
  10944. } else {
  10945. bmp.push(start, 0xFFFF + 1);
  10946. astral.push(0xFFFF + 1, end + 1);
  10947. }
  10948. } else {
  10949. // The range starts and ends in the astral range.
  10950. astral.push(start, end + 1);
  10951. }
  10952. index += 2;
  10953. }
  10954. return {
  10955. 'loneHighSurrogates': loneHighSurrogates,
  10956. 'loneLowSurrogates': loneLowSurrogates,
  10957. 'bmp': bmp,
  10958. 'astral': astral
  10959. };
  10960. };
  10961. var optimizeSurrogateMappings = function(surrogateMappings) {
  10962. var result = [];
  10963. var tmpLow = [];
  10964. var addLow = false;
  10965. var mapping;
  10966. var nextMapping;
  10967. var highSurrogates;
  10968. var lowSurrogates;
  10969. var nextHighSurrogates;
  10970. var nextLowSurrogates;
  10971. var index = -1;
  10972. var length = surrogateMappings.length;
  10973. while (++index < length) {
  10974. mapping = surrogateMappings[index];
  10975. nextMapping = surrogateMappings[index + 1];
  10976. if (!nextMapping) {
  10977. result.push(mapping);
  10978. continue;
  10979. }
  10980. highSurrogates = mapping[0];
  10981. lowSurrogates = mapping[1];
  10982. nextHighSurrogates = nextMapping[0];
  10983. nextLowSurrogates = nextMapping[1];
  10984. // Check for identical high surrogate ranges.
  10985. tmpLow = lowSurrogates;
  10986. while (
  10987. nextHighSurrogates &&
  10988. highSurrogates[0] == nextHighSurrogates[0] &&
  10989. highSurrogates[1] == nextHighSurrogates[1]
  10990. ) {
  10991. // Merge with the next item.
  10992. if (dataIsSingleton(nextLowSurrogates)) {
  10993. tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
  10994. } else {
  10995. tmpLow = dataAddRange(
  10996. tmpLow,
  10997. nextLowSurrogates[0],
  10998. nextLowSurrogates[1] - 1
  10999. );
  11000. }
  11001. ++index;
  11002. mapping = surrogateMappings[index];
  11003. highSurrogates = mapping[0];
  11004. lowSurrogates = mapping[1];
  11005. nextMapping = surrogateMappings[index + 1];
  11006. nextHighSurrogates = nextMapping && nextMapping[0];
  11007. nextLowSurrogates = nextMapping && nextMapping[1];
  11008. addLow = true;
  11009. }
  11010. result.push([
  11011. highSurrogates,
  11012. addLow ? tmpLow : lowSurrogates
  11013. ]);
  11014. addLow = false;
  11015. }
  11016. return optimizeByLowSurrogates(result);
  11017. };
  11018. var optimizeByLowSurrogates = function(surrogateMappings) {
  11019. if (surrogateMappings.length == 1) {
  11020. return surrogateMappings;
  11021. }
  11022. var index = -1;
  11023. var innerIndex = -1;
  11024. while (++index < surrogateMappings.length) {
  11025. var mapping = surrogateMappings[index];
  11026. var lowSurrogates = mapping[1];
  11027. var lowSurrogateStart = lowSurrogates[0];
  11028. var lowSurrogateEnd = lowSurrogates[1];
  11029. innerIndex = index; // Note: the loop starts at the next index.
  11030. while (++innerIndex < surrogateMappings.length) {
  11031. var otherMapping = surrogateMappings[innerIndex];
  11032. var otherLowSurrogates = otherMapping[1];
  11033. var otherLowSurrogateStart = otherLowSurrogates[0];
  11034. var otherLowSurrogateEnd = otherLowSurrogates[1];
  11035. if (
  11036. lowSurrogateStart == otherLowSurrogateStart &&
  11037. lowSurrogateEnd == otherLowSurrogateEnd
  11038. ) {
  11039. // Add the code points in the other item to this one.
  11040. if (dataIsSingleton(otherMapping[0])) {
  11041. mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
  11042. } else {
  11043. mapping[0] = dataAddRange(
  11044. mapping[0],
  11045. otherMapping[0][0],
  11046. otherMapping[0][1] - 1
  11047. );
  11048. }
  11049. // Remove the other, now redundant, item.
  11050. surrogateMappings.splice(innerIndex, 1);
  11051. --innerIndex;
  11052. }
  11053. }
  11054. }
  11055. return surrogateMappings;
  11056. };
  11057. var surrogateSet = function(data) {
  11058. // Exit early if `data` is an empty set.
  11059. if (!data.length) {
  11060. return [];
  11061. }
  11062. // Iterate over the data per `(start, end)` pair.
  11063. var index = 0;
  11064. var start;
  11065. var end;
  11066. var startHigh;
  11067. var startLow;
  11068. var endHigh;
  11069. var endLow;
  11070. var surrogateMappings = [];
  11071. var length = data.length;
  11072. while (index < length) {
  11073. start = data[index];
  11074. end = data[index + 1] - 1;
  11075. startHigh = highSurrogate(start);
  11076. startLow = lowSurrogate(start);
  11077. endHigh = highSurrogate(end);
  11078. endLow = lowSurrogate(end);
  11079. var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
  11080. var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
  11081. var complete = false;
  11082. // Append the previous high-surrogate-to-low-surrogate mappings.
  11083. // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
  11084. if (
  11085. startHigh == endHigh ||
  11086. startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
  11087. ) {
  11088. surrogateMappings.push([
  11089. [startHigh, endHigh + 1],
  11090. [startLow, endLow + 1]
  11091. ]);
  11092. complete = true;
  11093. } else {
  11094. surrogateMappings.push([
  11095. [startHigh, startHigh + 1],
  11096. [startLow, LOW_SURROGATE_MAX + 1]
  11097. ]);
  11098. }
  11099. // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
  11100. // `(endHigh - 1, LOW_SURROGATE_MAX)`.
  11101. if (!complete && startHigh + 1 < endHigh) {
  11102. if (endsWithHighestLowSurrogate) {
  11103. // Combine step 2 and step 3.
  11104. surrogateMappings.push([
  11105. [startHigh + 1, endHigh + 1],
  11106. [LOW_SURROGATE_MIN, endLow + 1]
  11107. ]);
  11108. complete = true;
  11109. } else {
  11110. surrogateMappings.push([
  11111. [startHigh + 1, endHigh],
  11112. [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
  11113. ]);
  11114. }
  11115. }
  11116. // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
  11117. if (!complete) {
  11118. surrogateMappings.push([
  11119. [endHigh, endHigh + 1],
  11120. [LOW_SURROGATE_MIN, endLow + 1]
  11121. ]);
  11122. }
  11123. index += 2;
  11124. }
  11125. // The format of `surrogateMappings` is as follows:
  11126. //
  11127. // [ surrogateMapping1, surrogateMapping2 ]
  11128. //
  11129. // i.e.:
  11130. //
  11131. // [
  11132. // [ highSurrogates1, lowSurrogates1 ],
  11133. // [ highSurrogates2, lowSurrogates2 ]
  11134. // ]
  11135. return optimizeSurrogateMappings(surrogateMappings);
  11136. };
  11137. var createSurrogateCharacterClasses = function(surrogateMappings) {
  11138. var result = [];
  11139. forEach(surrogateMappings, function(surrogateMapping) {
  11140. var highSurrogates = surrogateMapping[0];
  11141. var lowSurrogates = surrogateMapping[1];
  11142. result.push(
  11143. createBMPCharacterClasses(highSurrogates) +
  11144. createBMPCharacterClasses(lowSurrogates)
  11145. );
  11146. });
  11147. return result.join('|');
  11148. };
  11149. var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
  11150. if (hasUnicodeFlag) {
  11151. return createUnicodeCharacterClasses(data);
  11152. }
  11153. var result = [];
  11154. var parts = splitAtBMP(data);
  11155. var loneHighSurrogates = parts.loneHighSurrogates;
  11156. var loneLowSurrogates = parts.loneLowSurrogates;
  11157. var bmp = parts.bmp;
  11158. var astral = parts.astral;
  11159. var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
  11160. var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
  11161. var surrogateMappings = surrogateSet(astral);
  11162. if (bmpOnly) {
  11163. bmp = dataAddData(bmp, loneHighSurrogates);
  11164. hasLoneHighSurrogates = false;
  11165. bmp = dataAddData(bmp, loneLowSurrogates);
  11166. hasLoneLowSurrogates = false;
  11167. }
  11168. if (!dataIsEmpty(bmp)) {
  11169. // The data set contains BMP code points that are not high surrogates
  11170. // needed for astral code points in the set.
  11171. result.push(createBMPCharacterClasses(bmp));
  11172. }
  11173. if (surrogateMappings.length) {
  11174. // The data set contains astral code points; append character classes
  11175. // based on their surrogate pairs.
  11176. result.push(createSurrogateCharacterClasses(surrogateMappings));
  11177. }
  11178. // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
  11179. if (hasLoneHighSurrogates) {
  11180. result.push(
  11181. createBMPCharacterClasses(loneHighSurrogates) +
  11182. // Make sure the high surrogates aren’t part of a surrogate pair.
  11183. '(?![\\uDC00-\\uDFFF])'
  11184. );
  11185. }
  11186. if (hasLoneLowSurrogates) {
  11187. result.push(
  11188. // It is not possible to accurately assert the low surrogates aren’t
  11189. // part of a surrogate pair, since JavaScript regular expressions do
  11190. // not support lookbehind.
  11191. '(?:[^\\uD800-\\uDBFF]|^)' +
  11192. createBMPCharacterClasses(loneLowSurrogates)
  11193. );
  11194. }
  11195. return result.join('|');
  11196. };
  11197. /*--------------------------------------------------------------------------*/
  11198. // `regenerate` can be used as a constructor (and new methods can be added to
  11199. // its prototype) but also as a regular function, the latter of which is the
  11200. // documented and most common usage. For that reason, it’s not capitalized.
  11201. var regenerate = function(value) {
  11202. if (arguments.length > 1) {
  11203. value = slice.call(arguments);
  11204. }
  11205. if (this instanceof regenerate) {
  11206. this.data = [];
  11207. return value ? this.add(value) : this;
  11208. }
  11209. return (new regenerate).add(value);
  11210. };
  11211. regenerate.version = '1.3.3';
  11212. var proto = regenerate.prototype;
  11213. extend(proto, {
  11214. 'add': function(value) {
  11215. var $this = this;
  11216. if (value == null) {
  11217. return $this;
  11218. }
  11219. if (value instanceof regenerate) {
  11220. // Allow passing other Regenerate instances.
  11221. $this.data = dataAddData($this.data, value.data);
  11222. return $this;
  11223. }
  11224. if (arguments.length > 1) {
  11225. value = slice.call(arguments);
  11226. }
  11227. if (isArray(value)) {
  11228. forEach(value, function(item) {
  11229. $this.add(item);
  11230. });
  11231. return $this;
  11232. }
  11233. $this.data = dataAdd(
  11234. $this.data,
  11235. isNumber(value) ? value : symbolToCodePoint(value)
  11236. );
  11237. return $this;
  11238. },
  11239. 'remove': function(value) {
  11240. var $this = this;
  11241. if (value == null) {
  11242. return $this;
  11243. }
  11244. if (value instanceof regenerate) {
  11245. // Allow passing other Regenerate instances.
  11246. $this.data = dataRemoveData($this.data, value.data);
  11247. return $this;
  11248. }
  11249. if (arguments.length > 1) {
  11250. value = slice.call(arguments);
  11251. }
  11252. if (isArray(value)) {
  11253. forEach(value, function(item) {
  11254. $this.remove(item);
  11255. });
  11256. return $this;
  11257. }
  11258. $this.data = dataRemove(
  11259. $this.data,
  11260. isNumber(value) ? value : symbolToCodePoint(value)
  11261. );
  11262. return $this;
  11263. },
  11264. 'addRange': function(start, end) {
  11265. var $this = this;
  11266. $this.data = dataAddRange($this.data,
  11267. isNumber(start) ? start : symbolToCodePoint(start),
  11268. isNumber(end) ? end : symbolToCodePoint(end)
  11269. );
  11270. return $this;
  11271. },
  11272. 'removeRange': function(start, end) {
  11273. var $this = this;
  11274. var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
  11275. var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
  11276. $this.data = dataRemoveRange(
  11277. $this.data,
  11278. startCodePoint,
  11279. endCodePoint
  11280. );
  11281. return $this;
  11282. },
  11283. 'intersection': function(argument) {
  11284. var $this = this;
  11285. // Allow passing other Regenerate instances.
  11286. // TODO: Optimize this by writing and using `dataIntersectionData()`.
  11287. var array = argument instanceof regenerate ?
  11288. dataToArray(argument.data) :
  11289. argument;
  11290. $this.data = dataIntersection($this.data, array);
  11291. return $this;
  11292. },
  11293. 'contains': function(codePoint) {
  11294. return dataContains(
  11295. this.data,
  11296. isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
  11297. );
  11298. },
  11299. 'clone': function() {
  11300. var set = new regenerate;
  11301. set.data = this.data.slice(0);
  11302. return set;
  11303. },
  11304. 'toString': function(options) {
  11305. var result = createCharacterClassesFromData(
  11306. this.data,
  11307. options ? options.bmpOnly : false,
  11308. options ? options.hasUnicodeFlag : false
  11309. );
  11310. if (!result) {
  11311. // For an empty set, return something that can be inserted `/here/` to
  11312. // form a valid regular expression. Avoid `(?:)` since that matches the
  11313. // empty string.
  11314. return '[]';
  11315. }
  11316. // Use `\0` instead of `\x00` where possible.
  11317. return result.replace(regexNull, '\\0$1');
  11318. },
  11319. 'toRegExp': function(flags) {
  11320. var pattern = this.toString(
  11321. flags && flags.indexOf('u') != -1 ?
  11322. { 'hasUnicodeFlag': true } :
  11323. null
  11324. );
  11325. return RegExp(pattern, flags || '');
  11326. },
  11327. 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
  11328. return dataToArray(this.data);
  11329. }
  11330. });
  11331. proto.toArray = proto.valueOf;
  11332. // Some AMD build optimizers, like r.js, check for specific condition patterns
  11333. // like the following:
  11334. if (
  11335. typeof undefined == 'function' &&
  11336. typeof undefined.amd == 'object' &&
  11337. undefined.amd
  11338. ) {
  11339. undefined(function() {
  11340. return regenerate;
  11341. });
  11342. } else if (freeExports && !freeExports.nodeType) {
  11343. if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
  11344. freeModule.exports = regenerate;
  11345. } else { // in Narwhal or RingoJS v0.7.0-
  11346. freeExports.regenerate = regenerate;
  11347. }
  11348. } else { // in Rhino or a web browser
  11349. root.regenerate = regenerate;
  11350. }
  11351. }(commonjsGlobal));
  11352. });
  11353. var unicodeCanonicalPropertyNamesEcmascript = new Set([
  11354. // Non-binary properties:
  11355. 'General_Category',
  11356. 'Script',
  11357. 'Script_Extensions',
  11358. // Binary properties:
  11359. 'Alphabetic',
  11360. 'Any',
  11361. 'ASCII',
  11362. 'ASCII_Hex_Digit',
  11363. 'Assigned',
  11364. 'Bidi_Control',
  11365. 'Bidi_Mirrored',
  11366. 'Case_Ignorable',
  11367. 'Cased',
  11368. 'Changes_When_Casefolded',
  11369. 'Changes_When_Casemapped',
  11370. 'Changes_When_Lowercased',
  11371. 'Changes_When_NFKC_Casefolded',
  11372. 'Changes_When_Titlecased',
  11373. 'Changes_When_Uppercased',
  11374. 'Dash',
  11375. 'Default_Ignorable_Code_Point',
  11376. 'Deprecated',
  11377. 'Diacritic',
  11378. 'Emoji',
  11379. 'Emoji_Component',
  11380. 'Emoji_Modifier',
  11381. 'Emoji_Modifier_Base',
  11382. 'Emoji_Presentation',
  11383. 'Extended_Pictographic',
  11384. 'Extender',
  11385. 'Grapheme_Base',
  11386. 'Grapheme_Extend',
  11387. 'Hex_Digit',
  11388. 'ID_Continue',
  11389. 'ID_Start',
  11390. 'Ideographic',
  11391. 'IDS_Binary_Operator',
  11392. 'IDS_Trinary_Operator',
  11393. 'Join_Control',
  11394. 'Logical_Order_Exception',
  11395. 'Lowercase',
  11396. 'Math',
  11397. 'Noncharacter_Code_Point',
  11398. 'Pattern_Syntax',
  11399. 'Pattern_White_Space',
  11400. 'Quotation_Mark',
  11401. 'Radical',
  11402. 'Regional_Indicator',
  11403. 'Sentence_Terminal',
  11404. 'Soft_Dotted',
  11405. 'Terminal_Punctuation',
  11406. 'Unified_Ideograph',
  11407. 'Uppercase',
  11408. 'Variation_Selector',
  11409. 'White_Space',
  11410. 'XID_Continue',
  11411. 'XID_Start'
  11412. ]);
  11413. // Generated using `npm run build`. Do not edit!
  11414. var unicodePropertyAliasesEcmascript = new Map([
  11415. ['scx', 'Script_Extensions'],
  11416. ['sc', 'Script'],
  11417. ['gc', 'General_Category'],
  11418. ['AHex', 'ASCII_Hex_Digit'],
  11419. ['Alpha', 'Alphabetic'],
  11420. ['Bidi_C', 'Bidi_Control'],
  11421. ['Bidi_M', 'Bidi_Mirrored'],
  11422. ['Cased', 'Cased'],
  11423. ['CI', 'Case_Ignorable'],
  11424. ['CWCF', 'Changes_When_Casefolded'],
  11425. ['CWCM', 'Changes_When_Casemapped'],
  11426. ['CWKCF', 'Changes_When_NFKC_Casefolded'],
  11427. ['CWL', 'Changes_When_Lowercased'],
  11428. ['CWT', 'Changes_When_Titlecased'],
  11429. ['CWU', 'Changes_When_Uppercased'],
  11430. ['Dash', 'Dash'],
  11431. ['Dep', 'Deprecated'],
  11432. ['DI', 'Default_Ignorable_Code_Point'],
  11433. ['Dia', 'Diacritic'],
  11434. ['Ext', 'Extender'],
  11435. ['Gr_Base', 'Grapheme_Base'],
  11436. ['Gr_Ext', 'Grapheme_Extend'],
  11437. ['Hex', 'Hex_Digit'],
  11438. ['IDC', 'ID_Continue'],
  11439. ['Ideo', 'Ideographic'],
  11440. ['IDS', 'ID_Start'],
  11441. ['IDSB', 'IDS_Binary_Operator'],
  11442. ['IDST', 'IDS_Trinary_Operator'],
  11443. ['Join_C', 'Join_Control'],
  11444. ['LOE', 'Logical_Order_Exception'],
  11445. ['Lower', 'Lowercase'],
  11446. ['Math', 'Math'],
  11447. ['NChar', 'Noncharacter_Code_Point'],
  11448. ['Pat_Syn', 'Pattern_Syntax'],
  11449. ['Pat_WS', 'Pattern_White_Space'],
  11450. ['QMark', 'Quotation_Mark'],
  11451. ['Radical', 'Radical'],
  11452. ['RI', 'Regional_Indicator'],
  11453. ['SD', 'Soft_Dotted'],
  11454. ['STerm', 'Sentence_Terminal'],
  11455. ['Term', 'Terminal_Punctuation'],
  11456. ['UIdeo', 'Unified_Ideograph'],
  11457. ['Upper', 'Uppercase'],
  11458. ['VS', 'Variation_Selector'],
  11459. ['WSpace', 'White_Space'],
  11460. ['space', 'White_Space'],
  11461. ['XIDC', 'XID_Continue'],
  11462. ['XIDS', 'XID_Start']
  11463. ]);
  11464. var matchProperty = function(property) {
  11465. if (unicodeCanonicalPropertyNamesEcmascript.has(property)) {
  11466. return property;
  11467. }
  11468. if (unicodePropertyAliasesEcmascript.has(property)) {
  11469. return unicodePropertyAliasesEcmascript.get(property);
  11470. }
  11471. throw new Error(("Unknown property: " + property));
  11472. };
  11473. var unicodeMatchPropertyEcmascript = matchProperty;
  11474. var mappings = new Map([
  11475. ['General_Category', new Map([
  11476. ['C', 'Other'],
  11477. ['Cc', 'Control'],
  11478. ['cntrl', 'Control'],
  11479. ['Cf', 'Format'],
  11480. ['Cn', 'Unassigned'],
  11481. ['Co', 'Private_Use'],
  11482. ['Cs', 'Surrogate'],
  11483. ['L', 'Letter'],
  11484. ['LC', 'Cased_Letter'],
  11485. ['Ll', 'Lowercase_Letter'],
  11486. ['Lm', 'Modifier_Letter'],
  11487. ['Lo', 'Other_Letter'],
  11488. ['Lt', 'Titlecase_Letter'],
  11489. ['Lu', 'Uppercase_Letter'],
  11490. ['M', 'Mark'],
  11491. ['Combining_Mark', 'Mark'],
  11492. ['Mc', 'Spacing_Mark'],
  11493. ['Me', 'Enclosing_Mark'],
  11494. ['Mn', 'Nonspacing_Mark'],
  11495. ['N', 'Number'],
  11496. ['Nd', 'Decimal_Number'],
  11497. ['digit', 'Decimal_Number'],
  11498. ['Nl', 'Letter_Number'],
  11499. ['No', 'Other_Number'],
  11500. ['P', 'Punctuation'],
  11501. ['punct', 'Punctuation'],
  11502. ['Pc', 'Connector_Punctuation'],
  11503. ['Pd', 'Dash_Punctuation'],
  11504. ['Pe', 'Close_Punctuation'],
  11505. ['Pf', 'Final_Punctuation'],
  11506. ['Pi', 'Initial_Punctuation'],
  11507. ['Po', 'Other_Punctuation'],
  11508. ['Ps', 'Open_Punctuation'],
  11509. ['S', 'Symbol'],
  11510. ['Sc', 'Currency_Symbol'],
  11511. ['Sk', 'Modifier_Symbol'],
  11512. ['Sm', 'Math_Symbol'],
  11513. ['So', 'Other_Symbol'],
  11514. ['Z', 'Separator'],
  11515. ['Zl', 'Line_Separator'],
  11516. ['Zp', 'Paragraph_Separator'],
  11517. ['Zs', 'Space_Separator'],
  11518. ['Other', 'Other'],
  11519. ['Control', 'Control'],
  11520. ['Format', 'Format'],
  11521. ['Unassigned', 'Unassigned'],
  11522. ['Private_Use', 'Private_Use'],
  11523. ['Surrogate', 'Surrogate'],
  11524. ['Letter', 'Letter'],
  11525. ['Cased_Letter', 'Cased_Letter'],
  11526. ['Lowercase_Letter', 'Lowercase_Letter'],
  11527. ['Modifier_Letter', 'Modifier_Letter'],
  11528. ['Other_Letter', 'Other_Letter'],
  11529. ['Titlecase_Letter', 'Titlecase_Letter'],
  11530. ['Uppercase_Letter', 'Uppercase_Letter'],
  11531. ['Mark', 'Mark'],
  11532. ['Spacing_Mark', 'Spacing_Mark'],
  11533. ['Enclosing_Mark', 'Enclosing_Mark'],
  11534. ['Nonspacing_Mark', 'Nonspacing_Mark'],
  11535. ['Number', 'Number'],
  11536. ['Decimal_Number', 'Decimal_Number'],
  11537. ['Letter_Number', 'Letter_Number'],
  11538. ['Other_Number', 'Other_Number'],
  11539. ['Punctuation', 'Punctuation'],
  11540. ['Connector_Punctuation', 'Connector_Punctuation'],
  11541. ['Dash_Punctuation', 'Dash_Punctuation'],
  11542. ['Close_Punctuation', 'Close_Punctuation'],
  11543. ['Final_Punctuation', 'Final_Punctuation'],
  11544. ['Initial_Punctuation', 'Initial_Punctuation'],
  11545. ['Other_Punctuation', 'Other_Punctuation'],
  11546. ['Open_Punctuation', 'Open_Punctuation'],
  11547. ['Symbol', 'Symbol'],
  11548. ['Currency_Symbol', 'Currency_Symbol'],
  11549. ['Modifier_Symbol', 'Modifier_Symbol'],
  11550. ['Math_Symbol', 'Math_Symbol'],
  11551. ['Other_Symbol', 'Other_Symbol'],
  11552. ['Separator', 'Separator'],
  11553. ['Line_Separator', 'Line_Separator'],
  11554. ['Paragraph_Separator', 'Paragraph_Separator'],
  11555. ['Space_Separator', 'Space_Separator']
  11556. ])],
  11557. ['Script', new Map([
  11558. ['Adlm', 'Adlam'],
  11559. ['Aghb', 'Caucasian_Albanian'],
  11560. ['Ahom', 'Ahom'],
  11561. ['Arab', 'Arabic'],
  11562. ['Armi', 'Imperial_Aramaic'],
  11563. ['Armn', 'Armenian'],
  11564. ['Avst', 'Avestan'],
  11565. ['Bali', 'Balinese'],
  11566. ['Bamu', 'Bamum'],
  11567. ['Bass', 'Bassa_Vah'],
  11568. ['Batk', 'Batak'],
  11569. ['Beng', 'Bengali'],
  11570. ['Bhks', 'Bhaiksuki'],
  11571. ['Bopo', 'Bopomofo'],
  11572. ['Brah', 'Brahmi'],
  11573. ['Brai', 'Braille'],
  11574. ['Bugi', 'Buginese'],
  11575. ['Buhd', 'Buhid'],
  11576. ['Cakm', 'Chakma'],
  11577. ['Cans', 'Canadian_Aboriginal'],
  11578. ['Cari', 'Carian'],
  11579. ['Cham', 'Cham'],
  11580. ['Cher', 'Cherokee'],
  11581. ['Copt', 'Coptic'],
  11582. ['Qaac', 'Coptic'],
  11583. ['Cprt', 'Cypriot'],
  11584. ['Cyrl', 'Cyrillic'],
  11585. ['Deva', 'Devanagari'],
  11586. ['Dogr', 'Dogra'],
  11587. ['Dsrt', 'Deseret'],
  11588. ['Dupl', 'Duployan'],
  11589. ['Egyp', 'Egyptian_Hieroglyphs'],
  11590. ['Elba', 'Elbasan'],
  11591. ['Ethi', 'Ethiopic'],
  11592. ['Geor', 'Georgian'],
  11593. ['Glag', 'Glagolitic'],
  11594. ['Gong', 'Gunjala_Gondi'],
  11595. ['Gonm', 'Masaram_Gondi'],
  11596. ['Goth', 'Gothic'],
  11597. ['Gran', 'Grantha'],
  11598. ['Grek', 'Greek'],
  11599. ['Gujr', 'Gujarati'],
  11600. ['Guru', 'Gurmukhi'],
  11601. ['Hang', 'Hangul'],
  11602. ['Hani', 'Han'],
  11603. ['Hano', 'Hanunoo'],
  11604. ['Hatr', 'Hatran'],
  11605. ['Hebr', 'Hebrew'],
  11606. ['Hira', 'Hiragana'],
  11607. ['Hluw', 'Anatolian_Hieroglyphs'],
  11608. ['Hmng', 'Pahawh_Hmong'],
  11609. ['Hrkt', 'Katakana_Or_Hiragana'],
  11610. ['Hung', 'Old_Hungarian'],
  11611. ['Ital', 'Old_Italic'],
  11612. ['Java', 'Javanese'],
  11613. ['Kali', 'Kayah_Li'],
  11614. ['Kana', 'Katakana'],
  11615. ['Khar', 'Kharoshthi'],
  11616. ['Khmr', 'Khmer'],
  11617. ['Khoj', 'Khojki'],
  11618. ['Knda', 'Kannada'],
  11619. ['Kthi', 'Kaithi'],
  11620. ['Lana', 'Tai_Tham'],
  11621. ['Laoo', 'Lao'],
  11622. ['Latn', 'Latin'],
  11623. ['Lepc', 'Lepcha'],
  11624. ['Limb', 'Limbu'],
  11625. ['Lina', 'Linear_A'],
  11626. ['Linb', 'Linear_B'],
  11627. ['Lisu', 'Lisu'],
  11628. ['Lyci', 'Lycian'],
  11629. ['Lydi', 'Lydian'],
  11630. ['Mahj', 'Mahajani'],
  11631. ['Maka', 'Makasar'],
  11632. ['Mand', 'Mandaic'],
  11633. ['Mani', 'Manichaean'],
  11634. ['Marc', 'Marchen'],
  11635. ['Medf', 'Medefaidrin'],
  11636. ['Mend', 'Mende_Kikakui'],
  11637. ['Merc', 'Meroitic_Cursive'],
  11638. ['Mero', 'Meroitic_Hieroglyphs'],
  11639. ['Mlym', 'Malayalam'],
  11640. ['Modi', 'Modi'],
  11641. ['Mong', 'Mongolian'],
  11642. ['Mroo', 'Mro'],
  11643. ['Mtei', 'Meetei_Mayek'],
  11644. ['Mult', 'Multani'],
  11645. ['Mymr', 'Myanmar'],
  11646. ['Narb', 'Old_North_Arabian'],
  11647. ['Nbat', 'Nabataean'],
  11648. ['Newa', 'Newa'],
  11649. ['Nkoo', 'Nko'],
  11650. ['Nshu', 'Nushu'],
  11651. ['Ogam', 'Ogham'],
  11652. ['Olck', 'Ol_Chiki'],
  11653. ['Orkh', 'Old_Turkic'],
  11654. ['Orya', 'Oriya'],
  11655. ['Osge', 'Osage'],
  11656. ['Osma', 'Osmanya'],
  11657. ['Palm', 'Palmyrene'],
  11658. ['Pauc', 'Pau_Cin_Hau'],
  11659. ['Perm', 'Old_Permic'],
  11660. ['Phag', 'Phags_Pa'],
  11661. ['Phli', 'Inscriptional_Pahlavi'],
  11662. ['Phlp', 'Psalter_Pahlavi'],
  11663. ['Phnx', 'Phoenician'],
  11664. ['Plrd', 'Miao'],
  11665. ['Prti', 'Inscriptional_Parthian'],
  11666. ['Rjng', 'Rejang'],
  11667. ['Rohg', 'Hanifi_Rohingya'],
  11668. ['Runr', 'Runic'],
  11669. ['Samr', 'Samaritan'],
  11670. ['Sarb', 'Old_South_Arabian'],
  11671. ['Saur', 'Saurashtra'],
  11672. ['Sgnw', 'SignWriting'],
  11673. ['Shaw', 'Shavian'],
  11674. ['Shrd', 'Sharada'],
  11675. ['Sidd', 'Siddham'],
  11676. ['Sind', 'Khudawadi'],
  11677. ['Sinh', 'Sinhala'],
  11678. ['Sogd', 'Sogdian'],
  11679. ['Sogo', 'Old_Sogdian'],
  11680. ['Sora', 'Sora_Sompeng'],
  11681. ['Soyo', 'Soyombo'],
  11682. ['Sund', 'Sundanese'],
  11683. ['Sylo', 'Syloti_Nagri'],
  11684. ['Syrc', 'Syriac'],
  11685. ['Tagb', 'Tagbanwa'],
  11686. ['Takr', 'Takri'],
  11687. ['Tale', 'Tai_Le'],
  11688. ['Talu', 'New_Tai_Lue'],
  11689. ['Taml', 'Tamil'],
  11690. ['Tang', 'Tangut'],
  11691. ['Tavt', 'Tai_Viet'],
  11692. ['Telu', 'Telugu'],
  11693. ['Tfng', 'Tifinagh'],
  11694. ['Tglg', 'Tagalog'],
  11695. ['Thaa', 'Thaana'],
  11696. ['Thai', 'Thai'],
  11697. ['Tibt', 'Tibetan'],
  11698. ['Tirh', 'Tirhuta'],
  11699. ['Ugar', 'Ugaritic'],
  11700. ['Vaii', 'Vai'],
  11701. ['Wara', 'Warang_Citi'],
  11702. ['Xpeo', 'Old_Persian'],
  11703. ['Xsux', 'Cuneiform'],
  11704. ['Yiii', 'Yi'],
  11705. ['Zanb', 'Zanabazar_Square'],
  11706. ['Zinh', 'Inherited'],
  11707. ['Qaai', 'Inherited'],
  11708. ['Zyyy', 'Common'],
  11709. ['Zzzz', 'Unknown'],
  11710. ['Adlam', 'Adlam'],
  11711. ['Caucasian_Albanian', 'Caucasian_Albanian'],
  11712. ['Arabic', 'Arabic'],
  11713. ['Imperial_Aramaic', 'Imperial_Aramaic'],
  11714. ['Armenian', 'Armenian'],
  11715. ['Avestan', 'Avestan'],
  11716. ['Balinese', 'Balinese'],
  11717. ['Bamum', 'Bamum'],
  11718. ['Bassa_Vah', 'Bassa_Vah'],
  11719. ['Batak', 'Batak'],
  11720. ['Bengali', 'Bengali'],
  11721. ['Bhaiksuki', 'Bhaiksuki'],
  11722. ['Bopomofo', 'Bopomofo'],
  11723. ['Brahmi', 'Brahmi'],
  11724. ['Braille', 'Braille'],
  11725. ['Buginese', 'Buginese'],
  11726. ['Buhid', 'Buhid'],
  11727. ['Chakma', 'Chakma'],
  11728. ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
  11729. ['Carian', 'Carian'],
  11730. ['Cherokee', 'Cherokee'],
  11731. ['Coptic', 'Coptic'],
  11732. ['Cypriot', 'Cypriot'],
  11733. ['Cyrillic', 'Cyrillic'],
  11734. ['Devanagari', 'Devanagari'],
  11735. ['Dogra', 'Dogra'],
  11736. ['Deseret', 'Deseret'],
  11737. ['Duployan', 'Duployan'],
  11738. ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
  11739. ['Elbasan', 'Elbasan'],
  11740. ['Ethiopic', 'Ethiopic'],
  11741. ['Georgian', 'Georgian'],
  11742. ['Glagolitic', 'Glagolitic'],
  11743. ['Gunjala_Gondi', 'Gunjala_Gondi'],
  11744. ['Masaram_Gondi', 'Masaram_Gondi'],
  11745. ['Gothic', 'Gothic'],
  11746. ['Grantha', 'Grantha'],
  11747. ['Greek', 'Greek'],
  11748. ['Gujarati', 'Gujarati'],
  11749. ['Gurmukhi', 'Gurmukhi'],
  11750. ['Hangul', 'Hangul'],
  11751. ['Han', 'Han'],
  11752. ['Hanunoo', 'Hanunoo'],
  11753. ['Hatran', 'Hatran'],
  11754. ['Hebrew', 'Hebrew'],
  11755. ['Hiragana', 'Hiragana'],
  11756. ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
  11757. ['Pahawh_Hmong', 'Pahawh_Hmong'],
  11758. ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
  11759. ['Old_Hungarian', 'Old_Hungarian'],
  11760. ['Old_Italic', 'Old_Italic'],
  11761. ['Javanese', 'Javanese'],
  11762. ['Kayah_Li', 'Kayah_Li'],
  11763. ['Katakana', 'Katakana'],
  11764. ['Kharoshthi', 'Kharoshthi'],
  11765. ['Khmer', 'Khmer'],
  11766. ['Khojki', 'Khojki'],
  11767. ['Kannada', 'Kannada'],
  11768. ['Kaithi', 'Kaithi'],
  11769. ['Tai_Tham', 'Tai_Tham'],
  11770. ['Lao', 'Lao'],
  11771. ['Latin', 'Latin'],
  11772. ['Lepcha', 'Lepcha'],
  11773. ['Limbu', 'Limbu'],
  11774. ['Linear_A', 'Linear_A'],
  11775. ['Linear_B', 'Linear_B'],
  11776. ['Lycian', 'Lycian'],
  11777. ['Lydian', 'Lydian'],
  11778. ['Mahajani', 'Mahajani'],
  11779. ['Makasar', 'Makasar'],
  11780. ['Mandaic', 'Mandaic'],
  11781. ['Manichaean', 'Manichaean'],
  11782. ['Marchen', 'Marchen'],
  11783. ['Medefaidrin', 'Medefaidrin'],
  11784. ['Mende_Kikakui', 'Mende_Kikakui'],
  11785. ['Meroitic_Cursive', 'Meroitic_Cursive'],
  11786. ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
  11787. ['Malayalam', 'Malayalam'],
  11788. ['Mongolian', 'Mongolian'],
  11789. ['Mro', 'Mro'],
  11790. ['Meetei_Mayek', 'Meetei_Mayek'],
  11791. ['Multani', 'Multani'],
  11792. ['Myanmar', 'Myanmar'],
  11793. ['Old_North_Arabian', 'Old_North_Arabian'],
  11794. ['Nabataean', 'Nabataean'],
  11795. ['Nko', 'Nko'],
  11796. ['Nushu', 'Nushu'],
  11797. ['Ogham', 'Ogham'],
  11798. ['Ol_Chiki', 'Ol_Chiki'],
  11799. ['Old_Turkic', 'Old_Turkic'],
  11800. ['Oriya', 'Oriya'],
  11801. ['Osage', 'Osage'],
  11802. ['Osmanya', 'Osmanya'],
  11803. ['Palmyrene', 'Palmyrene'],
  11804. ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
  11805. ['Old_Permic', 'Old_Permic'],
  11806. ['Phags_Pa', 'Phags_Pa'],
  11807. ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
  11808. ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
  11809. ['Phoenician', 'Phoenician'],
  11810. ['Miao', 'Miao'],
  11811. ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
  11812. ['Rejang', 'Rejang'],
  11813. ['Hanifi_Rohingya', 'Hanifi_Rohingya'],
  11814. ['Runic', 'Runic'],
  11815. ['Samaritan', 'Samaritan'],
  11816. ['Old_South_Arabian', 'Old_South_Arabian'],
  11817. ['Saurashtra', 'Saurashtra'],
  11818. ['SignWriting', 'SignWriting'],
  11819. ['Shavian', 'Shavian'],
  11820. ['Sharada', 'Sharada'],
  11821. ['Siddham', 'Siddham'],
  11822. ['Khudawadi', 'Khudawadi'],
  11823. ['Sinhala', 'Sinhala'],
  11824. ['Sogdian', 'Sogdian'],
  11825. ['Old_Sogdian', 'Old_Sogdian'],
  11826. ['Sora_Sompeng', 'Sora_Sompeng'],
  11827. ['Soyombo', 'Soyombo'],
  11828. ['Sundanese', 'Sundanese'],
  11829. ['Syloti_Nagri', 'Syloti_Nagri'],
  11830. ['Syriac', 'Syriac'],
  11831. ['Tagbanwa', 'Tagbanwa'],
  11832. ['Takri', 'Takri'],
  11833. ['Tai_Le', 'Tai_Le'],
  11834. ['New_Tai_Lue', 'New_Tai_Lue'],
  11835. ['Tamil', 'Tamil'],
  11836. ['Tangut', 'Tangut'],
  11837. ['Tai_Viet', 'Tai_Viet'],
  11838. ['Telugu', 'Telugu'],
  11839. ['Tifinagh', 'Tifinagh'],
  11840. ['Tagalog', 'Tagalog'],
  11841. ['Thaana', 'Thaana'],
  11842. ['Tibetan', 'Tibetan'],
  11843. ['Tirhuta', 'Tirhuta'],
  11844. ['Ugaritic', 'Ugaritic'],
  11845. ['Vai', 'Vai'],
  11846. ['Warang_Citi', 'Warang_Citi'],
  11847. ['Old_Persian', 'Old_Persian'],
  11848. ['Cuneiform', 'Cuneiform'],
  11849. ['Yi', 'Yi'],
  11850. ['Zanabazar_Square', 'Zanabazar_Square'],
  11851. ['Inherited', 'Inherited'],
  11852. ['Common', 'Common'],
  11853. ['Unknown', 'Unknown']
  11854. ])],
  11855. ['Script_Extensions', new Map([
  11856. ['Adlm', 'Adlam'],
  11857. ['Aghb', 'Caucasian_Albanian'],
  11858. ['Ahom', 'Ahom'],
  11859. ['Arab', 'Arabic'],
  11860. ['Armi', 'Imperial_Aramaic'],
  11861. ['Armn', 'Armenian'],
  11862. ['Avst', 'Avestan'],
  11863. ['Bali', 'Balinese'],
  11864. ['Bamu', 'Bamum'],
  11865. ['Bass', 'Bassa_Vah'],
  11866. ['Batk', 'Batak'],
  11867. ['Beng', 'Bengali'],
  11868. ['Bhks', 'Bhaiksuki'],
  11869. ['Bopo', 'Bopomofo'],
  11870. ['Brah', 'Brahmi'],
  11871. ['Brai', 'Braille'],
  11872. ['Bugi', 'Buginese'],
  11873. ['Buhd', 'Buhid'],
  11874. ['Cakm', 'Chakma'],
  11875. ['Cans', 'Canadian_Aboriginal'],
  11876. ['Cari', 'Carian'],
  11877. ['Cham', 'Cham'],
  11878. ['Cher', 'Cherokee'],
  11879. ['Copt', 'Coptic'],
  11880. ['Qaac', 'Coptic'],
  11881. ['Cprt', 'Cypriot'],
  11882. ['Cyrl', 'Cyrillic'],
  11883. ['Deva', 'Devanagari'],
  11884. ['Dogr', 'Dogra'],
  11885. ['Dsrt', 'Deseret'],
  11886. ['Dupl', 'Duployan'],
  11887. ['Egyp', 'Egyptian_Hieroglyphs'],
  11888. ['Elba', 'Elbasan'],
  11889. ['Ethi', 'Ethiopic'],
  11890. ['Geor', 'Georgian'],
  11891. ['Glag', 'Glagolitic'],
  11892. ['Gong', 'Gunjala_Gondi'],
  11893. ['Gonm', 'Masaram_Gondi'],
  11894. ['Goth', 'Gothic'],
  11895. ['Gran', 'Grantha'],
  11896. ['Grek', 'Greek'],
  11897. ['Gujr', 'Gujarati'],
  11898. ['Guru', 'Gurmukhi'],
  11899. ['Hang', 'Hangul'],
  11900. ['Hani', 'Han'],
  11901. ['Hano', 'Hanunoo'],
  11902. ['Hatr', 'Hatran'],
  11903. ['Hebr', 'Hebrew'],
  11904. ['Hira', 'Hiragana'],
  11905. ['Hluw', 'Anatolian_Hieroglyphs'],
  11906. ['Hmng', 'Pahawh_Hmong'],
  11907. ['Hrkt', 'Katakana_Or_Hiragana'],
  11908. ['Hung', 'Old_Hungarian'],
  11909. ['Ital', 'Old_Italic'],
  11910. ['Java', 'Javanese'],
  11911. ['Kali', 'Kayah_Li'],
  11912. ['Kana', 'Katakana'],
  11913. ['Khar', 'Kharoshthi'],
  11914. ['Khmr', 'Khmer'],
  11915. ['Khoj', 'Khojki'],
  11916. ['Knda', 'Kannada'],
  11917. ['Kthi', 'Kaithi'],
  11918. ['Lana', 'Tai_Tham'],
  11919. ['Laoo', 'Lao'],
  11920. ['Latn', 'Latin'],
  11921. ['Lepc', 'Lepcha'],
  11922. ['Limb', 'Limbu'],
  11923. ['Lina', 'Linear_A'],
  11924. ['Linb', 'Linear_B'],
  11925. ['Lisu', 'Lisu'],
  11926. ['Lyci', 'Lycian'],
  11927. ['Lydi', 'Lydian'],
  11928. ['Mahj', 'Mahajani'],
  11929. ['Maka', 'Makasar'],
  11930. ['Mand', 'Mandaic'],
  11931. ['Mani', 'Manichaean'],
  11932. ['Marc', 'Marchen'],
  11933. ['Medf', 'Medefaidrin'],
  11934. ['Mend', 'Mende_Kikakui'],
  11935. ['Merc', 'Meroitic_Cursive'],
  11936. ['Mero', 'Meroitic_Hieroglyphs'],
  11937. ['Mlym', 'Malayalam'],
  11938. ['Modi', 'Modi'],
  11939. ['Mong', 'Mongolian'],
  11940. ['Mroo', 'Mro'],
  11941. ['Mtei', 'Meetei_Mayek'],
  11942. ['Mult', 'Multani'],
  11943. ['Mymr', 'Myanmar'],
  11944. ['Narb', 'Old_North_Arabian'],
  11945. ['Nbat', 'Nabataean'],
  11946. ['Newa', 'Newa'],
  11947. ['Nkoo', 'Nko'],
  11948. ['Nshu', 'Nushu'],
  11949. ['Ogam', 'Ogham'],
  11950. ['Olck', 'Ol_Chiki'],
  11951. ['Orkh', 'Old_Turkic'],
  11952. ['Orya', 'Oriya'],
  11953. ['Osge', 'Osage'],
  11954. ['Osma', 'Osmanya'],
  11955. ['Palm', 'Palmyrene'],
  11956. ['Pauc', 'Pau_Cin_Hau'],
  11957. ['Perm', 'Old_Permic'],
  11958. ['Phag', 'Phags_Pa'],
  11959. ['Phli', 'Inscriptional_Pahlavi'],
  11960. ['Phlp', 'Psalter_Pahlavi'],
  11961. ['Phnx', 'Phoenician'],
  11962. ['Plrd', 'Miao'],
  11963. ['Prti', 'Inscriptional_Parthian'],
  11964. ['Rjng', 'Rejang'],
  11965. ['Rohg', 'Hanifi_Rohingya'],
  11966. ['Runr', 'Runic'],
  11967. ['Samr', 'Samaritan'],
  11968. ['Sarb', 'Old_South_Arabian'],
  11969. ['Saur', 'Saurashtra'],
  11970. ['Sgnw', 'SignWriting'],
  11971. ['Shaw', 'Shavian'],
  11972. ['Shrd', 'Sharada'],
  11973. ['Sidd', 'Siddham'],
  11974. ['Sind', 'Khudawadi'],
  11975. ['Sinh', 'Sinhala'],
  11976. ['Sogd', 'Sogdian'],
  11977. ['Sogo', 'Old_Sogdian'],
  11978. ['Sora', 'Sora_Sompeng'],
  11979. ['Soyo', 'Soyombo'],
  11980. ['Sund', 'Sundanese'],
  11981. ['Sylo', 'Syloti_Nagri'],
  11982. ['Syrc', 'Syriac'],
  11983. ['Tagb', 'Tagbanwa'],
  11984. ['Takr', 'Takri'],
  11985. ['Tale', 'Tai_Le'],
  11986. ['Talu', 'New_Tai_Lue'],
  11987. ['Taml', 'Tamil'],
  11988. ['Tang', 'Tangut'],
  11989. ['Tavt', 'Tai_Viet'],
  11990. ['Telu', 'Telugu'],
  11991. ['Tfng', 'Tifinagh'],
  11992. ['Tglg', 'Tagalog'],
  11993. ['Thaa', 'Thaana'],
  11994. ['Thai', 'Thai'],
  11995. ['Tibt', 'Tibetan'],
  11996. ['Tirh', 'Tirhuta'],
  11997. ['Ugar', 'Ugaritic'],
  11998. ['Vaii', 'Vai'],
  11999. ['Wara', 'Warang_Citi'],
  12000. ['Xpeo', 'Old_Persian'],
  12001. ['Xsux', 'Cuneiform'],
  12002. ['Yiii', 'Yi'],
  12003. ['Zanb', 'Zanabazar_Square'],
  12004. ['Zinh', 'Inherited'],
  12005. ['Qaai', 'Inherited'],
  12006. ['Zyyy', 'Common'],
  12007. ['Zzzz', 'Unknown'],
  12008. ['Adlam', 'Adlam'],
  12009. ['Caucasian_Albanian', 'Caucasian_Albanian'],
  12010. ['Arabic', 'Arabic'],
  12011. ['Imperial_Aramaic', 'Imperial_Aramaic'],
  12012. ['Armenian', 'Armenian'],
  12013. ['Avestan', 'Avestan'],
  12014. ['Balinese', 'Balinese'],
  12015. ['Bamum', 'Bamum'],
  12016. ['Bassa_Vah', 'Bassa_Vah'],
  12017. ['Batak', 'Batak'],
  12018. ['Bengali', 'Bengali'],
  12019. ['Bhaiksuki', 'Bhaiksuki'],
  12020. ['Bopomofo', 'Bopomofo'],
  12021. ['Brahmi', 'Brahmi'],
  12022. ['Braille', 'Braille'],
  12023. ['Buginese', 'Buginese'],
  12024. ['Buhid', 'Buhid'],
  12025. ['Chakma', 'Chakma'],
  12026. ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
  12027. ['Carian', 'Carian'],
  12028. ['Cherokee', 'Cherokee'],
  12029. ['Coptic', 'Coptic'],
  12030. ['Cypriot', 'Cypriot'],
  12031. ['Cyrillic', 'Cyrillic'],
  12032. ['Devanagari', 'Devanagari'],
  12033. ['Dogra', 'Dogra'],
  12034. ['Deseret', 'Deseret'],
  12035. ['Duployan', 'Duployan'],
  12036. ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
  12037. ['Elbasan', 'Elbasan'],
  12038. ['Ethiopic', 'Ethiopic'],
  12039. ['Georgian', 'Georgian'],
  12040. ['Glagolitic', 'Glagolitic'],
  12041. ['Gunjala_Gondi', 'Gunjala_Gondi'],
  12042. ['Masaram_Gondi', 'Masaram_Gondi'],
  12043. ['Gothic', 'Gothic'],
  12044. ['Grantha', 'Grantha'],
  12045. ['Greek', 'Greek'],
  12046. ['Gujarati', 'Gujarati'],
  12047. ['Gurmukhi', 'Gurmukhi'],
  12048. ['Hangul', 'Hangul'],
  12049. ['Han', 'Han'],
  12050. ['Hanunoo', 'Hanunoo'],
  12051. ['Hatran', 'Hatran'],
  12052. ['Hebrew', 'Hebrew'],
  12053. ['Hiragana', 'Hiragana'],
  12054. ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
  12055. ['Pahawh_Hmong', 'Pahawh_Hmong'],
  12056. ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
  12057. ['Old_Hungarian', 'Old_Hungarian'],
  12058. ['Old_Italic', 'Old_Italic'],
  12059. ['Javanese', 'Javanese'],
  12060. ['Kayah_Li', 'Kayah_Li'],
  12061. ['Katakana', 'Katakana'],
  12062. ['Kharoshthi', 'Kharoshthi'],
  12063. ['Khmer', 'Khmer'],
  12064. ['Khojki', 'Khojki'],
  12065. ['Kannada', 'Kannada'],
  12066. ['Kaithi', 'Kaithi'],
  12067. ['Tai_Tham', 'Tai_Tham'],
  12068. ['Lao', 'Lao'],
  12069. ['Latin', 'Latin'],
  12070. ['Lepcha', 'Lepcha'],
  12071. ['Limbu', 'Limbu'],
  12072. ['Linear_A', 'Linear_A'],
  12073. ['Linear_B', 'Linear_B'],
  12074. ['Lycian', 'Lycian'],
  12075. ['Lydian', 'Lydian'],
  12076. ['Mahajani', 'Mahajani'],
  12077. ['Makasar', 'Makasar'],
  12078. ['Mandaic', 'Mandaic'],
  12079. ['Manichaean', 'Manichaean'],
  12080. ['Marchen', 'Marchen'],
  12081. ['Medefaidrin', 'Medefaidrin'],
  12082. ['Mende_Kikakui', 'Mende_Kikakui'],
  12083. ['Meroitic_Cursive', 'Meroitic_Cursive'],
  12084. ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
  12085. ['Malayalam', 'Malayalam'],
  12086. ['Mongolian', 'Mongolian'],
  12087. ['Mro', 'Mro'],
  12088. ['Meetei_Mayek', 'Meetei_Mayek'],
  12089. ['Multani', 'Multani'],
  12090. ['Myanmar', 'Myanmar'],
  12091. ['Old_North_Arabian', 'Old_North_Arabian'],
  12092. ['Nabataean', 'Nabataean'],
  12093. ['Nko', 'Nko'],
  12094. ['Nushu', 'Nushu'],
  12095. ['Ogham', 'Ogham'],
  12096. ['Ol_Chiki', 'Ol_Chiki'],
  12097. ['Old_Turkic', 'Old_Turkic'],
  12098. ['Oriya', 'Oriya'],
  12099. ['Osage', 'Osage'],
  12100. ['Osmanya', 'Osmanya'],
  12101. ['Palmyrene', 'Palmyrene'],
  12102. ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
  12103. ['Old_Permic', 'Old_Permic'],
  12104. ['Phags_Pa', 'Phags_Pa'],
  12105. ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
  12106. ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
  12107. ['Phoenician', 'Phoenician'],
  12108. ['Miao', 'Miao'],
  12109. ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
  12110. ['Rejang', 'Rejang'],
  12111. ['Hanifi_Rohingya', 'Hanifi_Rohingya'],
  12112. ['Runic', 'Runic'],
  12113. ['Samaritan', 'Samaritan'],
  12114. ['Old_South_Arabian', 'Old_South_Arabian'],
  12115. ['Saurashtra', 'Saurashtra'],
  12116. ['SignWriting', 'SignWriting'],
  12117. ['Shavian', 'Shavian'],
  12118. ['Sharada', 'Sharada'],
  12119. ['Siddham', 'Siddham'],
  12120. ['Khudawadi', 'Khudawadi'],
  12121. ['Sinhala', 'Sinhala'],
  12122. ['Sogdian', 'Sogdian'],
  12123. ['Old_Sogdian', 'Old_Sogdian'],
  12124. ['Sora_Sompeng', 'Sora_Sompeng'],
  12125. ['Soyombo', 'Soyombo'],
  12126. ['Sundanese', 'Sundanese'],
  12127. ['Syloti_Nagri', 'Syloti_Nagri'],
  12128. ['Syriac', 'Syriac'],
  12129. ['Tagbanwa', 'Tagbanwa'],
  12130. ['Takri', 'Takri'],
  12131. ['Tai_Le', 'Tai_Le'],
  12132. ['New_Tai_Lue', 'New_Tai_Lue'],
  12133. ['Tamil', 'Tamil'],
  12134. ['Tangut', 'Tangut'],
  12135. ['Tai_Viet', 'Tai_Viet'],
  12136. ['Telugu', 'Telugu'],
  12137. ['Tifinagh', 'Tifinagh'],
  12138. ['Tagalog', 'Tagalog'],
  12139. ['Thaana', 'Thaana'],
  12140. ['Tibetan', 'Tibetan'],
  12141. ['Tirhuta', 'Tirhuta'],
  12142. ['Ugaritic', 'Ugaritic'],
  12143. ['Vai', 'Vai'],
  12144. ['Warang_Citi', 'Warang_Citi'],
  12145. ['Old_Persian', 'Old_Persian'],
  12146. ['Cuneiform', 'Cuneiform'],
  12147. ['Yi', 'Yi'],
  12148. ['Zanabazar_Square', 'Zanabazar_Square'],
  12149. ['Inherited', 'Inherited'],
  12150. ['Common', 'Common'],
  12151. ['Unknown', 'Unknown']
  12152. ])]
  12153. ]);
  12154. var matchPropertyValue = function(property, value) {
  12155. var aliasToValue = mappings.get(property);
  12156. if (!aliasToValue) {
  12157. throw new Error(("Unknown property `" + property + "`."));
  12158. }
  12159. var canonicalValue = aliasToValue.get(value);
  12160. if (canonicalValue) {
  12161. return canonicalValue;
  12162. }
  12163. throw new Error(
  12164. ("Unknown value `" + value + "` for property `" + property + "`.")
  12165. );
  12166. };
  12167. var unicodeMatchPropertyValueEcmascript = matchPropertyValue;
  12168. var iuMappings = new Map([
  12169. [0x4B, 0x212A],
  12170. [0x53, 0x17F],
  12171. [0x6B, 0x212A],
  12172. [0x73, 0x17F],
  12173. [0xB5, 0x39C],
  12174. [0xC5, 0x212B],
  12175. [0xDF, 0x1E9E],
  12176. [0xE5, 0x212B],
  12177. [0x17F, 0x53],
  12178. [0x1C4, 0x1C5],
  12179. [0x1C5, 0x1C4],
  12180. [0x1C7, 0x1C8],
  12181. [0x1C8, 0x1C7],
  12182. [0x1CA, 0x1CB],
  12183. [0x1CB, 0x1CA],
  12184. [0x1F1, 0x1F2],
  12185. [0x1F2, 0x1F1],
  12186. [0x26A, 0xA7AE],
  12187. [0x29D, 0xA7B2],
  12188. [0x345, 0x1FBE],
  12189. [0x392, 0x3D0],
  12190. [0x395, 0x3F5],
  12191. [0x398, 0x3F4],
  12192. [0x399, 0x1FBE],
  12193. [0x39A, 0x3F0],
  12194. [0x39C, 0xB5],
  12195. [0x3A0, 0x3D6],
  12196. [0x3A1, 0x3F1],
  12197. [0x3A3, 0x3C2],
  12198. [0x3A6, 0x3D5],
  12199. [0x3A9, 0x2126],
  12200. [0x3B8, 0x3F4],
  12201. [0x3C2, 0x3A3],
  12202. [0x3C9, 0x2126],
  12203. [0x3D0, 0x392],
  12204. [0x3D1, 0x3F4],
  12205. [0x3D5, 0x3A6],
  12206. [0x3D6, 0x3A0],
  12207. [0x3F0, 0x39A],
  12208. [0x3F1, 0x3A1],
  12209. [0x3F4, [
  12210. 0x398,
  12211. 0x3D1,
  12212. 0x3B8
  12213. ]],
  12214. [0x3F5, 0x395],
  12215. [0x412, 0x1C80],
  12216. [0x414, 0x1C81],
  12217. [0x41E, 0x1C82],
  12218. [0x421, 0x1C83],
  12219. [0x422, 0x1C85],
  12220. [0x42A, 0x1C86],
  12221. [0x432, 0x1C80],
  12222. [0x434, 0x1C81],
  12223. [0x43E, 0x1C82],
  12224. [0x441, 0x1C83],
  12225. [0x442, [
  12226. 0x1C84,
  12227. 0x1C85
  12228. ]],
  12229. [0x44A, 0x1C86],
  12230. [0x462, 0x1C87],
  12231. [0x463, 0x1C87],
  12232. [0x10D0, 0x1C90],
  12233. [0x10D1, 0x1C91],
  12234. [0x10D2, 0x1C92],
  12235. [0x10D3, 0x1C93],
  12236. [0x10D4, 0x1C94],
  12237. [0x10D5, 0x1C95],
  12238. [0x10D6, 0x1C96],
  12239. [0x10D7, 0x1C97],
  12240. [0x10D8, 0x1C98],
  12241. [0x10D9, 0x1C99],
  12242. [0x10DA, 0x1C9A],
  12243. [0x10DB, 0x1C9B],
  12244. [0x10DC, 0x1C9C],
  12245. [0x10DD, 0x1C9D],
  12246. [0x10DE, 0x1C9E],
  12247. [0x10DF, 0x1C9F],
  12248. [0x10E0, 0x1CA0],
  12249. [0x10E1, 0x1CA1],
  12250. [0x10E2, 0x1CA2],
  12251. [0x10E3, 0x1CA3],
  12252. [0x10E4, 0x1CA4],
  12253. [0x10E5, 0x1CA5],
  12254. [0x10E6, 0x1CA6],
  12255. [0x10E7, 0x1CA7],
  12256. [0x10E8, 0x1CA8],
  12257. [0x10E9, 0x1CA9],
  12258. [0x10EA, 0x1CAA],
  12259. [0x10EB, 0x1CAB],
  12260. [0x10EC, 0x1CAC],
  12261. [0x10ED, 0x1CAD],
  12262. [0x10EE, 0x1CAE],
  12263. [0x10EF, 0x1CAF],
  12264. [0x10F0, 0x1CB0],
  12265. [0x10F1, 0x1CB1],
  12266. [0x10F2, 0x1CB2],
  12267. [0x10F3, 0x1CB3],
  12268. [0x10F4, 0x1CB4],
  12269. [0x10F5, 0x1CB5],
  12270. [0x10F6, 0x1CB6],
  12271. [0x10F7, 0x1CB7],
  12272. [0x10F8, 0x1CB8],
  12273. [0x10F9, 0x1CB9],
  12274. [0x10FA, 0x1CBA],
  12275. [0x10FD, 0x1CBD],
  12276. [0x10FE, 0x1CBE],
  12277. [0x10FF, 0x1CBF],
  12278. [0x13A0, 0xAB70],
  12279. [0x13A1, 0xAB71],
  12280. [0x13A2, 0xAB72],
  12281. [0x13A3, 0xAB73],
  12282. [0x13A4, 0xAB74],
  12283. [0x13A5, 0xAB75],
  12284. [0x13A6, 0xAB76],
  12285. [0x13A7, 0xAB77],
  12286. [0x13A8, 0xAB78],
  12287. [0x13A9, 0xAB79],
  12288. [0x13AA, 0xAB7A],
  12289. [0x13AB, 0xAB7B],
  12290. [0x13AC, 0xAB7C],
  12291. [0x13AD, 0xAB7D],
  12292. [0x13AE, 0xAB7E],
  12293. [0x13AF, 0xAB7F],
  12294. [0x13B0, 0xAB80],
  12295. [0x13B1, 0xAB81],
  12296. [0x13B2, 0xAB82],
  12297. [0x13B3, 0xAB83],
  12298. [0x13B4, 0xAB84],
  12299. [0x13B5, 0xAB85],
  12300. [0x13B6, 0xAB86],
  12301. [0x13B7, 0xAB87],
  12302. [0x13B8, 0xAB88],
  12303. [0x13B9, 0xAB89],
  12304. [0x13BA, 0xAB8A],
  12305. [0x13BB, 0xAB8B],
  12306. [0x13BC, 0xAB8C],
  12307. [0x13BD, 0xAB8D],
  12308. [0x13BE, 0xAB8E],
  12309. [0x13BF, 0xAB8F],
  12310. [0x13C0, 0xAB90],
  12311. [0x13C1, 0xAB91],
  12312. [0x13C2, 0xAB92],
  12313. [0x13C3, 0xAB93],
  12314. [0x13C4, 0xAB94],
  12315. [0x13C5, 0xAB95],
  12316. [0x13C6, 0xAB96],
  12317. [0x13C7, 0xAB97],
  12318. [0x13C8, 0xAB98],
  12319. [0x13C9, 0xAB99],
  12320. [0x13CA, 0xAB9A],
  12321. [0x13CB, 0xAB9B],
  12322. [0x13CC, 0xAB9C],
  12323. [0x13CD, 0xAB9D],
  12324. [0x13CE, 0xAB9E],
  12325. [0x13CF, 0xAB9F],
  12326. [0x13D0, 0xABA0],
  12327. [0x13D1, 0xABA1],
  12328. [0x13D2, 0xABA2],
  12329. [0x13D3, 0xABA3],
  12330. [0x13D4, 0xABA4],
  12331. [0x13D5, 0xABA5],
  12332. [0x13D6, 0xABA6],
  12333. [0x13D7, 0xABA7],
  12334. [0x13D8, 0xABA8],
  12335. [0x13D9, 0xABA9],
  12336. [0x13DA, 0xABAA],
  12337. [0x13DB, 0xABAB],
  12338. [0x13DC, 0xABAC],
  12339. [0x13DD, 0xABAD],
  12340. [0x13DE, 0xABAE],
  12341. [0x13DF, 0xABAF],
  12342. [0x13E0, 0xABB0],
  12343. [0x13E1, 0xABB1],
  12344. [0x13E2, 0xABB2],
  12345. [0x13E3, 0xABB3],
  12346. [0x13E4, 0xABB4],
  12347. [0x13E5, 0xABB5],
  12348. [0x13E6, 0xABB6],
  12349. [0x13E7, 0xABB7],
  12350. [0x13E8, 0xABB8],
  12351. [0x13E9, 0xABB9],
  12352. [0x13EA, 0xABBA],
  12353. [0x13EB, 0xABBB],
  12354. [0x13EC, 0xABBC],
  12355. [0x13ED, 0xABBD],
  12356. [0x13EE, 0xABBE],
  12357. [0x13EF, 0xABBF],
  12358. [0x13F0, 0x13F8],
  12359. [0x13F1, 0x13F9],
  12360. [0x13F2, 0x13FA],
  12361. [0x13F3, 0x13FB],
  12362. [0x13F4, 0x13FC],
  12363. [0x13F5, 0x13FD],
  12364. [0x13F8, 0x13F0],
  12365. [0x13F9, 0x13F1],
  12366. [0x13FA, 0x13F2],
  12367. [0x13FB, 0x13F3],
  12368. [0x13FC, 0x13F4],
  12369. [0x13FD, 0x13F5],
  12370. [0x1C80, [
  12371. 0x412,
  12372. 0x432
  12373. ]],
  12374. [0x1C81, [
  12375. 0x414,
  12376. 0x434
  12377. ]],
  12378. [0x1C82, [
  12379. 0x41E,
  12380. 0x43E
  12381. ]],
  12382. [0x1C83, [
  12383. 0x421,
  12384. 0x441
  12385. ]],
  12386. [0x1C84, [
  12387. 0x1C85,
  12388. 0x442
  12389. ]],
  12390. [0x1C85, [
  12391. 0x422,
  12392. 0x1C84,
  12393. 0x442
  12394. ]],
  12395. [0x1C86, [
  12396. 0x42A,
  12397. 0x44A
  12398. ]],
  12399. [0x1C87, [
  12400. 0x462,
  12401. 0x463
  12402. ]],
  12403. [0x1C88, [
  12404. 0xA64A,
  12405. 0xA64B
  12406. ]],
  12407. [0x1C90, 0x10D0],
  12408. [0x1C91, 0x10D1],
  12409. [0x1C92, 0x10D2],
  12410. [0x1C93, 0x10D3],
  12411. [0x1C94, 0x10D4],
  12412. [0x1C95, 0x10D5],
  12413. [0x1C96, 0x10D6],
  12414. [0x1C97, 0x10D7],
  12415. [0x1C98, 0x10D8],
  12416. [0x1C99, 0x10D9],
  12417. [0x1C9A, 0x10DA],
  12418. [0x1C9B, 0x10DB],
  12419. [0x1C9C, 0x10DC],
  12420. [0x1C9D, 0x10DD],
  12421. [0x1C9E, 0x10DE],
  12422. [0x1C9F, 0x10DF],
  12423. [0x1CA0, 0x10E0],
  12424. [0x1CA1, 0x10E1],
  12425. [0x1CA2, 0x10E2],
  12426. [0x1CA3, 0x10E3],
  12427. [0x1CA4, 0x10E4],
  12428. [0x1CA5, 0x10E5],
  12429. [0x1CA6, 0x10E6],
  12430. [0x1CA7, 0x10E7],
  12431. [0x1CA8, 0x10E8],
  12432. [0x1CA9, 0x10E9],
  12433. [0x1CAA, 0x10EA],
  12434. [0x1CAB, 0x10EB],
  12435. [0x1CAC, 0x10EC],
  12436. [0x1CAD, 0x10ED],
  12437. [0x1CAE, 0x10EE],
  12438. [0x1CAF, 0x10EF],
  12439. [0x1CB0, 0x10F0],
  12440. [0x1CB1, 0x10F1],
  12441. [0x1CB2, 0x10F2],
  12442. [0x1CB3, 0x10F3],
  12443. [0x1CB4, 0x10F4],
  12444. [0x1CB5, 0x10F5],
  12445. [0x1CB6, 0x10F6],
  12446. [0x1CB7, 0x10F7],
  12447. [0x1CB8, 0x10F8],
  12448. [0x1CB9, 0x10F9],
  12449. [0x1CBA, 0x10FA],
  12450. [0x1CBD, 0x10FD],
  12451. [0x1CBE, 0x10FE],
  12452. [0x1CBF, 0x10FF],
  12453. [0x1E60, 0x1E9B],
  12454. [0x1E9B, 0x1E60],
  12455. [0x1E9E, 0xDF],
  12456. [0x1F80, 0x1F88],
  12457. [0x1F81, 0x1F89],
  12458. [0x1F82, 0x1F8A],
  12459. [0x1F83, 0x1F8B],
  12460. [0x1F84, 0x1F8C],
  12461. [0x1F85, 0x1F8D],
  12462. [0x1F86, 0x1F8E],
  12463. [0x1F87, 0x1F8F],
  12464. [0x1F88, 0x1F80],
  12465. [0x1F89, 0x1F81],
  12466. [0x1F8A, 0x1F82],
  12467. [0x1F8B, 0x1F83],
  12468. [0x1F8C, 0x1F84],
  12469. [0x1F8D, 0x1F85],
  12470. [0x1F8E, 0x1F86],
  12471. [0x1F8F, 0x1F87],
  12472. [0x1F90, 0x1F98],
  12473. [0x1F91, 0x1F99],
  12474. [0x1F92, 0x1F9A],
  12475. [0x1F93, 0x1F9B],
  12476. [0x1F94, 0x1F9C],
  12477. [0x1F95, 0x1F9D],
  12478. [0x1F96, 0x1F9E],
  12479. [0x1F97, 0x1F9F],
  12480. [0x1F98, 0x1F90],
  12481. [0x1F99, 0x1F91],
  12482. [0x1F9A, 0x1F92],
  12483. [0x1F9B, 0x1F93],
  12484. [0x1F9C, 0x1F94],
  12485. [0x1F9D, 0x1F95],
  12486. [0x1F9E, 0x1F96],
  12487. [0x1F9F, 0x1F97],
  12488. [0x1FA0, 0x1FA8],
  12489. [0x1FA1, 0x1FA9],
  12490. [0x1FA2, 0x1FAA],
  12491. [0x1FA3, 0x1FAB],
  12492. [0x1FA4, 0x1FAC],
  12493. [0x1FA5, 0x1FAD],
  12494. [0x1FA6, 0x1FAE],
  12495. [0x1FA7, 0x1FAF],
  12496. [0x1FA8, 0x1FA0],
  12497. [0x1FA9, 0x1FA1],
  12498. [0x1FAA, 0x1FA2],
  12499. [0x1FAB, 0x1FA3],
  12500. [0x1FAC, 0x1FA4],
  12501. [0x1FAD, 0x1FA5],
  12502. [0x1FAE, 0x1FA6],
  12503. [0x1FAF, 0x1FA7],
  12504. [0x1FB3, 0x1FBC],
  12505. [0x1FBC, 0x1FB3],
  12506. [0x1FBE, [
  12507. 0x345,
  12508. 0x399
  12509. ]],
  12510. [0x1FC3, 0x1FCC],
  12511. [0x1FCC, 0x1FC3],
  12512. [0x1FF3, 0x1FFC],
  12513. [0x1FFC, 0x1FF3],
  12514. [0x2126, [
  12515. 0x3A9,
  12516. 0x3C9
  12517. ]],
  12518. [0x212A, 0x4B],
  12519. [0x212B, [
  12520. 0xC5,
  12521. 0xE5
  12522. ]],
  12523. [0xA64A, 0x1C88],
  12524. [0xA64B, 0x1C88],
  12525. [0xA7AE, 0x26A],
  12526. [0xA7B2, 0x29D],
  12527. [0xA7B3, 0xAB53],
  12528. [0xA7B4, 0xA7B5],
  12529. [0xA7B5, 0xA7B4],
  12530. [0xA7B6, 0xA7B7],
  12531. [0xA7B7, 0xA7B6],
  12532. [0xA7B8, 0xA7B9],
  12533. [0xA7B9, 0xA7B8],
  12534. [0xAB53, 0xA7B3],
  12535. [0xAB70, 0x13A0],
  12536. [0xAB71, 0x13A1],
  12537. [0xAB72, 0x13A2],
  12538. [0xAB73, 0x13A3],
  12539. [0xAB74, 0x13A4],
  12540. [0xAB75, 0x13A5],
  12541. [0xAB76, 0x13A6],
  12542. [0xAB77, 0x13A7],
  12543. [0xAB78, 0x13A8],
  12544. [0xAB79, 0x13A9],
  12545. [0xAB7A, 0x13AA],
  12546. [0xAB7B, 0x13AB],
  12547. [0xAB7C, 0x13AC],
  12548. [0xAB7D, 0x13AD],
  12549. [0xAB7E, 0x13AE],
  12550. [0xAB7F, 0x13AF],
  12551. [0xAB80, 0x13B0],
  12552. [0xAB81, 0x13B1],
  12553. [0xAB82, 0x13B2],
  12554. [0xAB83, 0x13B3],
  12555. [0xAB84, 0x13B4],
  12556. [0xAB85, 0x13B5],
  12557. [0xAB86, 0x13B6],
  12558. [0xAB87, 0x13B7],
  12559. [0xAB88, 0x13B8],
  12560. [0xAB89, 0x13B9],
  12561. [0xAB8A, 0x13BA],
  12562. [0xAB8B, 0x13BB],
  12563. [0xAB8C, 0x13BC],
  12564. [0xAB8D, 0x13BD],
  12565. [0xAB8E, 0x13BE],
  12566. [0xAB8F, 0x13BF],
  12567. [0xAB90, 0x13C0],
  12568. [0xAB91, 0x13C1],
  12569. [0xAB92, 0x13C2],
  12570. [0xAB93, 0x13C3],
  12571. [0xAB94, 0x13C4],
  12572. [0xAB95, 0x13C5],
  12573. [0xAB96, 0x13C6],
  12574. [0xAB97, 0x13C7],
  12575. [0xAB98, 0x13C8],
  12576. [0xAB99, 0x13C9],
  12577. [0xAB9A, 0x13CA],
  12578. [0xAB9B, 0x13CB],
  12579. [0xAB9C, 0x13CC],
  12580. [0xAB9D, 0x13CD],
  12581. [0xAB9E, 0x13CE],
  12582. [0xAB9F, 0x13CF],
  12583. [0xABA0, 0x13D0],
  12584. [0xABA1, 0x13D1],
  12585. [0xABA2, 0x13D2],
  12586. [0xABA3, 0x13D3],
  12587. [0xABA4, 0x13D4],
  12588. [0xABA5, 0x13D5],
  12589. [0xABA6, 0x13D6],
  12590. [0xABA7, 0x13D7],
  12591. [0xABA8, 0x13D8],
  12592. [0xABA9, 0x13D9],
  12593. [0xABAA, 0x13DA],
  12594. [0xABAB, 0x13DB],
  12595. [0xABAC, 0x13DC],
  12596. [0xABAD, 0x13DD],
  12597. [0xABAE, 0x13DE],
  12598. [0xABAF, 0x13DF],
  12599. [0xABB0, 0x13E0],
  12600. [0xABB1, 0x13E1],
  12601. [0xABB2, 0x13E2],
  12602. [0xABB3, 0x13E3],
  12603. [0xABB4, 0x13E4],
  12604. [0xABB5, 0x13E5],
  12605. [0xABB6, 0x13E6],
  12606. [0xABB7, 0x13E7],
  12607. [0xABB8, 0x13E8],
  12608. [0xABB9, 0x13E9],
  12609. [0xABBA, 0x13EA],
  12610. [0xABBB, 0x13EB],
  12611. [0xABBC, 0x13EC],
  12612. [0xABBD, 0x13ED],
  12613. [0xABBE, 0x13EE],
  12614. [0xABBF, 0x13EF],
  12615. [0x10400, 0x10428],
  12616. [0x10401, 0x10429],
  12617. [0x10402, 0x1042A],
  12618. [0x10403, 0x1042B],
  12619. [0x10404, 0x1042C],
  12620. [0x10405, 0x1042D],
  12621. [0x10406, 0x1042E],
  12622. [0x10407, 0x1042F],
  12623. [0x10408, 0x10430],
  12624. [0x10409, 0x10431],
  12625. [0x1040A, 0x10432],
  12626. [0x1040B, 0x10433],
  12627. [0x1040C, 0x10434],
  12628. [0x1040D, 0x10435],
  12629. [0x1040E, 0x10436],
  12630. [0x1040F, 0x10437],
  12631. [0x10410, 0x10438],
  12632. [0x10411, 0x10439],
  12633. [0x10412, 0x1043A],
  12634. [0x10413, 0x1043B],
  12635. [0x10414, 0x1043C],
  12636. [0x10415, 0x1043D],
  12637. [0x10416, 0x1043E],
  12638. [0x10417, 0x1043F],
  12639. [0x10418, 0x10440],
  12640. [0x10419, 0x10441],
  12641. [0x1041A, 0x10442],
  12642. [0x1041B, 0x10443],
  12643. [0x1041C, 0x10444],
  12644. [0x1041D, 0x10445],
  12645. [0x1041E, 0x10446],
  12646. [0x1041F, 0x10447],
  12647. [0x10420, 0x10448],
  12648. [0x10421, 0x10449],
  12649. [0x10422, 0x1044A],
  12650. [0x10423, 0x1044B],
  12651. [0x10424, 0x1044C],
  12652. [0x10425, 0x1044D],
  12653. [0x10426, 0x1044E],
  12654. [0x10427, 0x1044F],
  12655. [0x10428, 0x10400],
  12656. [0x10429, 0x10401],
  12657. [0x1042A, 0x10402],
  12658. [0x1042B, 0x10403],
  12659. [0x1042C, 0x10404],
  12660. [0x1042D, 0x10405],
  12661. [0x1042E, 0x10406],
  12662. [0x1042F, 0x10407],
  12663. [0x10430, 0x10408],
  12664. [0x10431, 0x10409],
  12665. [0x10432, 0x1040A],
  12666. [0x10433, 0x1040B],
  12667. [0x10434, 0x1040C],
  12668. [0x10435, 0x1040D],
  12669. [0x10436, 0x1040E],
  12670. [0x10437, 0x1040F],
  12671. [0x10438, 0x10410],
  12672. [0x10439, 0x10411],
  12673. [0x1043A, 0x10412],
  12674. [0x1043B, 0x10413],
  12675. [0x1043C, 0x10414],
  12676. [0x1043D, 0x10415],
  12677. [0x1043E, 0x10416],
  12678. [0x1043F, 0x10417],
  12679. [0x10440, 0x10418],
  12680. [0x10441, 0x10419],
  12681. [0x10442, 0x1041A],
  12682. [0x10443, 0x1041B],
  12683. [0x10444, 0x1041C],
  12684. [0x10445, 0x1041D],
  12685. [0x10446, 0x1041E],
  12686. [0x10447, 0x1041F],
  12687. [0x10448, 0x10420],
  12688. [0x10449, 0x10421],
  12689. [0x1044A, 0x10422],
  12690. [0x1044B, 0x10423],
  12691. [0x1044C, 0x10424],
  12692. [0x1044D, 0x10425],
  12693. [0x1044E, 0x10426],
  12694. [0x1044F, 0x10427],
  12695. [0x104B0, 0x104D8],
  12696. [0x104B1, 0x104D9],
  12697. [0x104B2, 0x104DA],
  12698. [0x104B3, 0x104DB],
  12699. [0x104B4, 0x104DC],
  12700. [0x104B5, 0x104DD],
  12701. [0x104B6, 0x104DE],
  12702. [0x104B7, 0x104DF],
  12703. [0x104B8, 0x104E0],
  12704. [0x104B9, 0x104E1],
  12705. [0x104BA, 0x104E2],
  12706. [0x104BB, 0x104E3],
  12707. [0x104BC, 0x104E4],
  12708. [0x104BD, 0x104E5],
  12709. [0x104BE, 0x104E6],
  12710. [0x104BF, 0x104E7],
  12711. [0x104C0, 0x104E8],
  12712. [0x104C1, 0x104E9],
  12713. [0x104C2, 0x104EA],
  12714. [0x104C3, 0x104EB],
  12715. [0x104C4, 0x104EC],
  12716. [0x104C5, 0x104ED],
  12717. [0x104C6, 0x104EE],
  12718. [0x104C7, 0x104EF],
  12719. [0x104C8, 0x104F0],
  12720. [0x104C9, 0x104F1],
  12721. [0x104CA, 0x104F2],
  12722. [0x104CB, 0x104F3],
  12723. [0x104CC, 0x104F4],
  12724. [0x104CD, 0x104F5],
  12725. [0x104CE, 0x104F6],
  12726. [0x104CF, 0x104F7],
  12727. [0x104D0, 0x104F8],
  12728. [0x104D1, 0x104F9],
  12729. [0x104D2, 0x104FA],
  12730. [0x104D3, 0x104FB],
  12731. [0x104D8, 0x104B0],
  12732. [0x104D9, 0x104B1],
  12733. [0x104DA, 0x104B2],
  12734. [0x104DB, 0x104B3],
  12735. [0x104DC, 0x104B4],
  12736. [0x104DD, 0x104B5],
  12737. [0x104DE, 0x104B6],
  12738. [0x104DF, 0x104B7],
  12739. [0x104E0, 0x104B8],
  12740. [0x104E1, 0x104B9],
  12741. [0x104E2, 0x104BA],
  12742. [0x104E3, 0x104BB],
  12743. [0x104E4, 0x104BC],
  12744. [0x104E5, 0x104BD],
  12745. [0x104E6, 0x104BE],
  12746. [0x104E7, 0x104BF],
  12747. [0x104E8, 0x104C0],
  12748. [0x104E9, 0x104C1],
  12749. [0x104EA, 0x104C2],
  12750. [0x104EB, 0x104C3],
  12751. [0x104EC, 0x104C4],
  12752. [0x104ED, 0x104C5],
  12753. [0x104EE, 0x104C6],
  12754. [0x104EF, 0x104C7],
  12755. [0x104F0, 0x104C8],
  12756. [0x104F1, 0x104C9],
  12757. [0x104F2, 0x104CA],
  12758. [0x104F3, 0x104CB],
  12759. [0x104F4, 0x104CC],
  12760. [0x104F5, 0x104CD],
  12761. [0x104F6, 0x104CE],
  12762. [0x104F7, 0x104CF],
  12763. [0x104F8, 0x104D0],
  12764. [0x104F9, 0x104D1],
  12765. [0x104FA, 0x104D2],
  12766. [0x104FB, 0x104D3],
  12767. [0x10C80, 0x10CC0],
  12768. [0x10C81, 0x10CC1],
  12769. [0x10C82, 0x10CC2],
  12770. [0x10C83, 0x10CC3],
  12771. [0x10C84, 0x10CC4],
  12772. [0x10C85, 0x10CC5],
  12773. [0x10C86, 0x10CC6],
  12774. [0x10C87, 0x10CC7],
  12775. [0x10C88, 0x10CC8],
  12776. [0x10C89, 0x10CC9],
  12777. [0x10C8A, 0x10CCA],
  12778. [0x10C8B, 0x10CCB],
  12779. [0x10C8C, 0x10CCC],
  12780. [0x10C8D, 0x10CCD],
  12781. [0x10C8E, 0x10CCE],
  12782. [0x10C8F, 0x10CCF],
  12783. [0x10C90, 0x10CD0],
  12784. [0x10C91, 0x10CD1],
  12785. [0x10C92, 0x10CD2],
  12786. [0x10C93, 0x10CD3],
  12787. [0x10C94, 0x10CD4],
  12788. [0x10C95, 0x10CD5],
  12789. [0x10C96, 0x10CD6],
  12790. [0x10C97, 0x10CD7],
  12791. [0x10C98, 0x10CD8],
  12792. [0x10C99, 0x10CD9],
  12793. [0x10C9A, 0x10CDA],
  12794. [0x10C9B, 0x10CDB],
  12795. [0x10C9C, 0x10CDC],
  12796. [0x10C9D, 0x10CDD],
  12797. [0x10C9E, 0x10CDE],
  12798. [0x10C9F, 0x10CDF],
  12799. [0x10CA0, 0x10CE0],
  12800. [0x10CA1, 0x10CE1],
  12801. [0x10CA2, 0x10CE2],
  12802. [0x10CA3, 0x10CE3],
  12803. [0x10CA4, 0x10CE4],
  12804. [0x10CA5, 0x10CE5],
  12805. [0x10CA6, 0x10CE6],
  12806. [0x10CA7, 0x10CE7],
  12807. [0x10CA8, 0x10CE8],
  12808. [0x10CA9, 0x10CE9],
  12809. [0x10CAA, 0x10CEA],
  12810. [0x10CAB, 0x10CEB],
  12811. [0x10CAC, 0x10CEC],
  12812. [0x10CAD, 0x10CED],
  12813. [0x10CAE, 0x10CEE],
  12814. [0x10CAF, 0x10CEF],
  12815. [0x10CB0, 0x10CF0],
  12816. [0x10CB1, 0x10CF1],
  12817. [0x10CB2, 0x10CF2],
  12818. [0x10CC0, 0x10C80],
  12819. [0x10CC1, 0x10C81],
  12820. [0x10CC2, 0x10C82],
  12821. [0x10CC3, 0x10C83],
  12822. [0x10CC4, 0x10C84],
  12823. [0x10CC5, 0x10C85],
  12824. [0x10CC6, 0x10C86],
  12825. [0x10CC7, 0x10C87],
  12826. [0x10CC8, 0x10C88],
  12827. [0x10CC9, 0x10C89],
  12828. [0x10CCA, 0x10C8A],
  12829. [0x10CCB, 0x10C8B],
  12830. [0x10CCC, 0x10C8C],
  12831. [0x10CCD, 0x10C8D],
  12832. [0x10CCE, 0x10C8E],
  12833. [0x10CCF, 0x10C8F],
  12834. [0x10CD0, 0x10C90],
  12835. [0x10CD1, 0x10C91],
  12836. [0x10CD2, 0x10C92],
  12837. [0x10CD3, 0x10C93],
  12838. [0x10CD4, 0x10C94],
  12839. [0x10CD5, 0x10C95],
  12840. [0x10CD6, 0x10C96],
  12841. [0x10CD7, 0x10C97],
  12842. [0x10CD8, 0x10C98],
  12843. [0x10CD9, 0x10C99],
  12844. [0x10CDA, 0x10C9A],
  12845. [0x10CDB, 0x10C9B],
  12846. [0x10CDC, 0x10C9C],
  12847. [0x10CDD, 0x10C9D],
  12848. [0x10CDE, 0x10C9E],
  12849. [0x10CDF, 0x10C9F],
  12850. [0x10CE0, 0x10CA0],
  12851. [0x10CE1, 0x10CA1],
  12852. [0x10CE2, 0x10CA2],
  12853. [0x10CE3, 0x10CA3],
  12854. [0x10CE4, 0x10CA4],
  12855. [0x10CE5, 0x10CA5],
  12856. [0x10CE6, 0x10CA6],
  12857. [0x10CE7, 0x10CA7],
  12858. [0x10CE8, 0x10CA8],
  12859. [0x10CE9, 0x10CA9],
  12860. [0x10CEA, 0x10CAA],
  12861. [0x10CEB, 0x10CAB],
  12862. [0x10CEC, 0x10CAC],
  12863. [0x10CED, 0x10CAD],
  12864. [0x10CEE, 0x10CAE],
  12865. [0x10CEF, 0x10CAF],
  12866. [0x10CF0, 0x10CB0],
  12867. [0x10CF1, 0x10CB1],
  12868. [0x10CF2, 0x10CB2],
  12869. [0x118A0, 0x118C0],
  12870. [0x118A1, 0x118C1],
  12871. [0x118A2, 0x118C2],
  12872. [0x118A3, 0x118C3],
  12873. [0x118A4, 0x118C4],
  12874. [0x118A5, 0x118C5],
  12875. [0x118A6, 0x118C6],
  12876. [0x118A7, 0x118C7],
  12877. [0x118A8, 0x118C8],
  12878. [0x118A9, 0x118C9],
  12879. [0x118AA, 0x118CA],
  12880. [0x118AB, 0x118CB],
  12881. [0x118AC, 0x118CC],
  12882. [0x118AD, 0x118CD],
  12883. [0x118AE, 0x118CE],
  12884. [0x118AF, 0x118CF],
  12885. [0x118B0, 0x118D0],
  12886. [0x118B1, 0x118D1],
  12887. [0x118B2, 0x118D2],
  12888. [0x118B3, 0x118D3],
  12889. [0x118B4, 0x118D4],
  12890. [0x118B5, 0x118D5],
  12891. [0x118B6, 0x118D6],
  12892. [0x118B7, 0x118D7],
  12893. [0x118B8, 0x118D8],
  12894. [0x118B9, 0x118D9],
  12895. [0x118BA, 0x118DA],
  12896. [0x118BB, 0x118DB],
  12897. [0x118BC, 0x118DC],
  12898. [0x118BD, 0x118DD],
  12899. [0x118BE, 0x118DE],
  12900. [0x118BF, 0x118DF],
  12901. [0x118C0, 0x118A0],
  12902. [0x118C1, 0x118A1],
  12903. [0x118C2, 0x118A2],
  12904. [0x118C3, 0x118A3],
  12905. [0x118C4, 0x118A4],
  12906. [0x118C5, 0x118A5],
  12907. [0x118C6, 0x118A6],
  12908. [0x118C7, 0x118A7],
  12909. [0x118C8, 0x118A8],
  12910. [0x118C9, 0x118A9],
  12911. [0x118CA, 0x118AA],
  12912. [0x118CB, 0x118AB],
  12913. [0x118CC, 0x118AC],
  12914. [0x118CD, 0x118AD],
  12915. [0x118CE, 0x118AE],
  12916. [0x118CF, 0x118AF],
  12917. [0x118D0, 0x118B0],
  12918. [0x118D1, 0x118B1],
  12919. [0x118D2, 0x118B2],
  12920. [0x118D3, 0x118B3],
  12921. [0x118D4, 0x118B4],
  12922. [0x118D5, 0x118B5],
  12923. [0x118D6, 0x118B6],
  12924. [0x118D7, 0x118B7],
  12925. [0x118D8, 0x118B8],
  12926. [0x118D9, 0x118B9],
  12927. [0x118DA, 0x118BA],
  12928. [0x118DB, 0x118BB],
  12929. [0x118DC, 0x118BC],
  12930. [0x118DD, 0x118BD],
  12931. [0x118DE, 0x118BE],
  12932. [0x118DF, 0x118BF],
  12933. [0x16E40, 0x16E60],
  12934. [0x16E41, 0x16E61],
  12935. [0x16E42, 0x16E62],
  12936. [0x16E43, 0x16E63],
  12937. [0x16E44, 0x16E64],
  12938. [0x16E45, 0x16E65],
  12939. [0x16E46, 0x16E66],
  12940. [0x16E47, 0x16E67],
  12941. [0x16E48, 0x16E68],
  12942. [0x16E49, 0x16E69],
  12943. [0x16E4A, 0x16E6A],
  12944. [0x16E4B, 0x16E6B],
  12945. [0x16E4C, 0x16E6C],
  12946. [0x16E4D, 0x16E6D],
  12947. [0x16E4E, 0x16E6E],
  12948. [0x16E4F, 0x16E6F],
  12949. [0x16E50, 0x16E70],
  12950. [0x16E51, 0x16E71],
  12951. [0x16E52, 0x16E72],
  12952. [0x16E53, 0x16E73],
  12953. [0x16E54, 0x16E74],
  12954. [0x16E55, 0x16E75],
  12955. [0x16E56, 0x16E76],
  12956. [0x16E57, 0x16E77],
  12957. [0x16E58, 0x16E78],
  12958. [0x16E59, 0x16E79],
  12959. [0x16E5A, 0x16E7A],
  12960. [0x16E5B, 0x16E7B],
  12961. [0x16E5C, 0x16E7C],
  12962. [0x16E5D, 0x16E7D],
  12963. [0x16E5E, 0x16E7E],
  12964. [0x16E5F, 0x16E7F],
  12965. [0x16E60, 0x16E40],
  12966. [0x16E61, 0x16E41],
  12967. [0x16E62, 0x16E42],
  12968. [0x16E63, 0x16E43],
  12969. [0x16E64, 0x16E44],
  12970. [0x16E65, 0x16E45],
  12971. [0x16E66, 0x16E46],
  12972. [0x16E67, 0x16E47],
  12973. [0x16E68, 0x16E48],
  12974. [0x16E69, 0x16E49],
  12975. [0x16E6A, 0x16E4A],
  12976. [0x16E6B, 0x16E4B],
  12977. [0x16E6C, 0x16E4C],
  12978. [0x16E6D, 0x16E4D],
  12979. [0x16E6E, 0x16E4E],
  12980. [0x16E6F, 0x16E4F],
  12981. [0x16E70, 0x16E50],
  12982. [0x16E71, 0x16E51],
  12983. [0x16E72, 0x16E52],
  12984. [0x16E73, 0x16E53],
  12985. [0x16E74, 0x16E54],
  12986. [0x16E75, 0x16E55],
  12987. [0x16E76, 0x16E56],
  12988. [0x16E77, 0x16E57],
  12989. [0x16E78, 0x16E58],
  12990. [0x16E79, 0x16E59],
  12991. [0x16E7A, 0x16E5A],
  12992. [0x16E7B, 0x16E5B],
  12993. [0x16E7C, 0x16E5C],
  12994. [0x16E7D, 0x16E5D],
  12995. [0x16E7E, 0x16E5E],
  12996. [0x16E7F, 0x16E5F],
  12997. [0x1E900, 0x1E922],
  12998. [0x1E901, 0x1E923],
  12999. [0x1E902, 0x1E924],
  13000. [0x1E903, 0x1E925],
  13001. [0x1E904, 0x1E926],
  13002. [0x1E905, 0x1E927],
  13003. [0x1E906, 0x1E928],
  13004. [0x1E907, 0x1E929],
  13005. [0x1E908, 0x1E92A],
  13006. [0x1E909, 0x1E92B],
  13007. [0x1E90A, 0x1E92C],
  13008. [0x1E90B, 0x1E92D],
  13009. [0x1E90C, 0x1E92E],
  13010. [0x1E90D, 0x1E92F],
  13011. [0x1E90E, 0x1E930],
  13012. [0x1E90F, 0x1E931],
  13013. [0x1E910, 0x1E932],
  13014. [0x1E911, 0x1E933],
  13015. [0x1E912, 0x1E934],
  13016. [0x1E913, 0x1E935],
  13017. [0x1E914, 0x1E936],
  13018. [0x1E915, 0x1E937],
  13019. [0x1E916, 0x1E938],
  13020. [0x1E917, 0x1E939],
  13021. [0x1E918, 0x1E93A],
  13022. [0x1E919, 0x1E93B],
  13023. [0x1E91A, 0x1E93C],
  13024. [0x1E91B, 0x1E93D],
  13025. [0x1E91C, 0x1E93E],
  13026. [0x1E91D, 0x1E93F],
  13027. [0x1E91E, 0x1E940],
  13028. [0x1E91F, 0x1E941],
  13029. [0x1E920, 0x1E942],
  13030. [0x1E921, 0x1E943],
  13031. [0x1E922, 0x1E900],
  13032. [0x1E923, 0x1E901],
  13033. [0x1E924, 0x1E902],
  13034. [0x1E925, 0x1E903],
  13035. [0x1E926, 0x1E904],
  13036. [0x1E927, 0x1E905],
  13037. [0x1E928, 0x1E906],
  13038. [0x1E929, 0x1E907],
  13039. [0x1E92A, 0x1E908],
  13040. [0x1E92B, 0x1E909],
  13041. [0x1E92C, 0x1E90A],
  13042. [0x1E92D, 0x1E90B],
  13043. [0x1E92E, 0x1E90C],
  13044. [0x1E92F, 0x1E90D],
  13045. [0x1E930, 0x1E90E],
  13046. [0x1E931, 0x1E90F],
  13047. [0x1E932, 0x1E910],
  13048. [0x1E933, 0x1E911],
  13049. [0x1E934, 0x1E912],
  13050. [0x1E935, 0x1E913],
  13051. [0x1E936, 0x1E914],
  13052. [0x1E937, 0x1E915],
  13053. [0x1E938, 0x1E916],
  13054. [0x1E939, 0x1E917],
  13055. [0x1E93A, 0x1E918],
  13056. [0x1E93B, 0x1E919],
  13057. [0x1E93C, 0x1E91A],
  13058. [0x1E93D, 0x1E91B],
  13059. [0x1E93E, 0x1E91C],
  13060. [0x1E93F, 0x1E91D],
  13061. [0x1E940, 0x1E91E],
  13062. [0x1E941, 0x1E91F],
  13063. [0x1E942, 0x1E920],
  13064. [0x1E943, 0x1E921]
  13065. ]);
  13066. var REGULAR = new Map([
  13067. ['d', regenerate()
  13068. .addRange(0x30, 0x39)],
  13069. ['D', regenerate()
  13070. .addRange(0x0, 0x2F)
  13071. .addRange(0x3A, 0xFFFF)],
  13072. ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
  13073. .addRange(0x9, 0xD)
  13074. .addRange(0x2000, 0x200A)
  13075. .addRange(0x2028, 0x2029)],
  13076. ['S', regenerate()
  13077. .addRange(0x0, 0x8)
  13078. .addRange(0xE, 0x1F)
  13079. .addRange(0x21, 0x9F)
  13080. .addRange(0xA1, 0x167F)
  13081. .addRange(0x1681, 0x1FFF)
  13082. .addRange(0x200B, 0x2027)
  13083. .addRange(0x202A, 0x202E)
  13084. .addRange(0x2030, 0x205E)
  13085. .addRange(0x2060, 0x2FFF)
  13086. .addRange(0x3001, 0xFEFE)
  13087. .addRange(0xFF00, 0xFFFF)],
  13088. ['w', regenerate(0x5F)
  13089. .addRange(0x30, 0x39)
  13090. .addRange(0x41, 0x5A)
  13091. .addRange(0x61, 0x7A)],
  13092. ['W', regenerate(0x60)
  13093. .addRange(0x0, 0x2F)
  13094. .addRange(0x3A, 0x40)
  13095. .addRange(0x5B, 0x5E)
  13096. .addRange(0x7B, 0xFFFF)]
  13097. ]);
  13098. var UNICODE = new Map([
  13099. ['d', regenerate()
  13100. .addRange(0x30, 0x39)],
  13101. ['D', regenerate()
  13102. .addRange(0x0, 0x2F)
  13103. .addRange(0x3A, 0x10FFFF)],
  13104. ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
  13105. .addRange(0x9, 0xD)
  13106. .addRange(0x2000, 0x200A)
  13107. .addRange(0x2028, 0x2029)],
  13108. ['S', regenerate()
  13109. .addRange(0x0, 0x8)
  13110. .addRange(0xE, 0x1F)
  13111. .addRange(0x21, 0x9F)
  13112. .addRange(0xA1, 0x167F)
  13113. .addRange(0x1681, 0x1FFF)
  13114. .addRange(0x200B, 0x2027)
  13115. .addRange(0x202A, 0x202E)
  13116. .addRange(0x2030, 0x205E)
  13117. .addRange(0x2060, 0x2FFF)
  13118. .addRange(0x3001, 0xFEFE)
  13119. .addRange(0xFF00, 0x10FFFF)],
  13120. ['w', regenerate(0x5F)
  13121. .addRange(0x30, 0x39)
  13122. .addRange(0x41, 0x5A)
  13123. .addRange(0x61, 0x7A)],
  13124. ['W', regenerate(0x60)
  13125. .addRange(0x0, 0x2F)
  13126. .addRange(0x3A, 0x40)
  13127. .addRange(0x5B, 0x5E)
  13128. .addRange(0x7B, 0x10FFFF)]
  13129. ]);
  13130. var UNICODE_IGNORE_CASE = new Map([
  13131. ['d', regenerate()
  13132. .addRange(0x30, 0x39)],
  13133. ['D', regenerate()
  13134. .addRange(0x0, 0x2F)
  13135. .addRange(0x3A, 0x10FFFF)],
  13136. ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
  13137. .addRange(0x9, 0xD)
  13138. .addRange(0x2000, 0x200A)
  13139. .addRange(0x2028, 0x2029)],
  13140. ['S', regenerate()
  13141. .addRange(0x0, 0x8)
  13142. .addRange(0xE, 0x1F)
  13143. .addRange(0x21, 0x9F)
  13144. .addRange(0xA1, 0x167F)
  13145. .addRange(0x1681, 0x1FFF)
  13146. .addRange(0x200B, 0x2027)
  13147. .addRange(0x202A, 0x202E)
  13148. .addRange(0x2030, 0x205E)
  13149. .addRange(0x2060, 0x2FFF)
  13150. .addRange(0x3001, 0xFEFE)
  13151. .addRange(0xFF00, 0x10FFFF)],
  13152. ['w', regenerate(0x5F, 0x17F, 0x212A)
  13153. .addRange(0x30, 0x39)
  13154. .addRange(0x41, 0x5A)
  13155. .addRange(0x61, 0x7A)],
  13156. ['W', regenerate(0x60)
  13157. .addRange(0x0, 0x2F)
  13158. .addRange(0x3A, 0x40)
  13159. .addRange(0x5B, 0x5E)
  13160. .addRange(0x7B, 0x17E)
  13161. .addRange(0x180, 0x2129)
  13162. .addRange(0x212B, 0x10FFFF)]
  13163. ]);
  13164. var characterClassEscapeSets = {
  13165. REGULAR: REGULAR,
  13166. UNICODE: UNICODE,
  13167. UNICODE_IGNORE_CASE: UNICODE_IGNORE_CASE
  13168. };
  13169. var rewritePattern_1 = createCommonjsModule(function (module) {
  13170. var generate = regjsgen.generate;
  13171. var parse = parser.parse;
  13172. // Prepare a Regenerate set containing all code points, used for negative
  13173. // character classes (if any).
  13174. var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
  13175. // Without the `u` flag, the range stops at 0xFFFF.
  13176. // https://mths.be/es6#sec-pattern-semantics
  13177. var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
  13178. // Prepare a Regenerate set containing all code points that are supposed to be
  13179. // matched by `/./u`. https://mths.be/es6#sec-atom
  13180. var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
  13181. .remove(
  13182. // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
  13183. 0x000A, // Line Feed <LF>
  13184. 0x000D, // Carriage Return <CR>
  13185. 0x2028, // Line Separator <LS>
  13186. 0x2029 // Paragraph Separator <PS>
  13187. );
  13188. // Prepare a Regenerate set containing all code points that are supposed to be
  13189. // matched by `/./` (only BMP code points).
  13190. var DOT_SET = DOT_SET_UNICODE.clone()
  13191. .intersection(BMP_SET);
  13192. var getCharacterClassEscapeSet = function (character, unicode, ignoreCase) {
  13193. if (unicode) {
  13194. if (ignoreCase) {
  13195. return characterClassEscapeSets.UNICODE_IGNORE_CASE.get(character);
  13196. }
  13197. return characterClassEscapeSets.UNICODE.get(character);
  13198. }
  13199. return characterClassEscapeSets.REGULAR.get(character);
  13200. };
  13201. var getDotSet = function (unicode, dotAll) {
  13202. if (dotAll) {
  13203. return unicode ? UNICODE_SET : BMP_SET;
  13204. }
  13205. return unicode ? DOT_SET_UNICODE : DOT_SET;
  13206. };
  13207. var getUnicodePropertyValueSet = function (property, value) {
  13208. var path = value ?
  13209. (property + "/" + value) :
  13210. ("Binary_Property/" + property);
  13211. try {
  13212. return commonjsRequire(("regenerate-unicode-properties/" + path + ".js"));
  13213. } catch (exception) {
  13214. throw new Error(
  13215. "Failed to recognize value `" + value + "` for property " +
  13216. "`" + property + "`."
  13217. );
  13218. }
  13219. };
  13220. var handleLoneUnicodePropertyNameOrValue = function (value) {
  13221. // It could be a `General_Category` value or a binary property.
  13222. // Note: `unicodeMatchPropertyValue` throws on invalid values.
  13223. try {
  13224. var property$1 = 'General_Category';
  13225. var category = unicodeMatchPropertyValueEcmascript(property$1, value);
  13226. return getUnicodePropertyValueSet(property$1, category);
  13227. } catch (exception) {}
  13228. // It’s not a `General_Category` value, so check if it’s a binary
  13229. // property. Note: `unicodeMatchProperty` throws on invalid properties.
  13230. var property = unicodeMatchPropertyEcmascript(value);
  13231. return getUnicodePropertyValueSet(property);
  13232. };
  13233. var getUnicodePropertyEscapeSet = function (value, isNegative) {
  13234. var parts = value.split('=');
  13235. var firstPart = parts[0];
  13236. var set;
  13237. if (parts.length == 1) {
  13238. set = handleLoneUnicodePropertyNameOrValue(firstPart);
  13239. } else {
  13240. // The pattern consists of two parts, i.e. `Property=Value`.
  13241. var property = unicodeMatchPropertyEcmascript(firstPart);
  13242. var value$1 = unicodeMatchPropertyValueEcmascript(property, parts[1]);
  13243. set = getUnicodePropertyValueSet(property, value$1);
  13244. }
  13245. if (isNegative) {
  13246. return UNICODE_SET.clone().remove(set);
  13247. }
  13248. return set.clone();
  13249. };
  13250. // Given a range of code points, add any case-folded code points in that range
  13251. // to a set.
  13252. regenerate.prototype.iuAddRange = function(min, max) {
  13253. var $this = this;
  13254. do {
  13255. var folded = caseFold(min);
  13256. if (folded) {
  13257. $this.add(folded);
  13258. }
  13259. } while (++min <= max);
  13260. return $this;
  13261. };
  13262. var update = function (item, pattern) {
  13263. var tree = parse(pattern, config.useUnicodeFlag ? 'u' : '');
  13264. switch (tree.type) {
  13265. case 'characterClass':
  13266. case 'group':
  13267. case 'value':
  13268. // No wrapping needed.
  13269. break;
  13270. default:
  13271. // Wrap the pattern in a non-capturing group.
  13272. tree = wrap(tree, pattern);
  13273. }
  13274. Object.assign(item, tree);
  13275. };
  13276. var wrap = function (tree, pattern) {
  13277. // Wrap the pattern in a non-capturing group.
  13278. return {
  13279. 'type': 'group',
  13280. 'behavior': 'ignore',
  13281. 'body': [tree],
  13282. 'raw': ("(?:" + pattern + ")")
  13283. };
  13284. };
  13285. var caseFold = function (codePoint) {
  13286. return iuMappings.get(codePoint) || false;
  13287. };
  13288. var processCharacterClass = function (characterClassItem, regenerateOptions) {
  13289. var set = regenerate();
  13290. for (var i = 0, list = characterClassItem.body; i < list.length; i += 1) {
  13291. var item = list[i];
  13292. switch (item.type) {
  13293. case 'value':
  13294. set.add(item.codePoint);
  13295. if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
  13296. var folded = caseFold(item.codePoint);
  13297. if (folded) {
  13298. set.add(folded);
  13299. }
  13300. }
  13301. break;
  13302. case 'characterClassRange':
  13303. var min = item.min.codePoint;
  13304. var max = item.max.codePoint;
  13305. set.addRange(min, max);
  13306. if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
  13307. set.iuAddRange(min, max);
  13308. }
  13309. break;
  13310. case 'characterClassEscape':
  13311. set.add(getCharacterClassEscapeSet(
  13312. item.value,
  13313. config.unicode,
  13314. config.ignoreCase
  13315. ));
  13316. break;
  13317. case 'unicodePropertyEscape':
  13318. set.add(getUnicodePropertyEscapeSet(item.value, item.negative));
  13319. break;
  13320. // The `default` clause is only here as a safeguard; it should never be
  13321. // reached. Code coverage tools should ignore it.
  13322. /* istanbul ignore next */
  13323. default:
  13324. throw new Error(("Unknown term type: " + (item.type)));
  13325. }
  13326. }
  13327. if (characterClassItem.negative) {
  13328. set = (config.unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
  13329. }
  13330. update(characterClassItem, set.toString(regenerateOptions));
  13331. return characterClassItem;
  13332. };
  13333. var updateNamedReference = function (item, index) {
  13334. delete item.name;
  13335. item.matchIndex = index;
  13336. };
  13337. var assertNoUnmatchedReferences = function (groups) {
  13338. var unmatchedReferencesNames = Object.keys(groups.unmatchedReferences);
  13339. if (unmatchedReferencesNames.length > 0) {
  13340. throw new Error(("Unknown group names: " + unmatchedReferencesNames));
  13341. }
  13342. };
  13343. var processTerm = function (item, regenerateOptions, groups) {
  13344. switch (item.type) {
  13345. case 'dot':
  13346. update(
  13347. item,
  13348. getDotSet(config.unicode, config.dotAll).toString(regenerateOptions)
  13349. );
  13350. break;
  13351. case 'characterClass':
  13352. item = processCharacterClass(item, regenerateOptions);
  13353. break;
  13354. case 'unicodePropertyEscape':
  13355. update(
  13356. item,
  13357. getUnicodePropertyEscapeSet(item.value, item.negative)
  13358. .toString(regenerateOptions)
  13359. );
  13360. break;
  13361. case 'characterClassEscape':
  13362. update(
  13363. item,
  13364. getCharacterClassEscapeSet(
  13365. item.value,
  13366. config.unicode,
  13367. config.ignoreCase
  13368. ).toString(regenerateOptions)
  13369. );
  13370. break;
  13371. case 'group':
  13372. groups.lastIndex++;
  13373. if (item.name) {
  13374. var name = item.name.value;
  13375. if (groups.names[name]) {
  13376. throw new Error(
  13377. ("Multiple groups with the same name (" + name + ") are not allowed.")
  13378. );
  13379. }
  13380. var index = groups.lastIndex;
  13381. delete item.name;
  13382. groups.names[name] = index;
  13383. if (groups.onNamedGroup) {
  13384. groups.onNamedGroup.call(null, name, index);
  13385. }
  13386. if (groups.unmatchedReferences[name]) {
  13387. groups.unmatchedReferences[name].forEach(function (reference) {
  13388. updateNamedReference(reference, index);
  13389. });
  13390. delete groups.unmatchedReferences[name];
  13391. }
  13392. }
  13393. /* falls through */
  13394. case 'alternative':
  13395. case 'disjunction':
  13396. case 'quantifier':
  13397. item.body = item.body.map(function (term) {
  13398. return processTerm(term, regenerateOptions, groups);
  13399. });
  13400. break;
  13401. case 'value':
  13402. var codePoint = item.codePoint;
  13403. var set = regenerate(codePoint);
  13404. if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
  13405. var folded = caseFold(codePoint);
  13406. if (folded) {
  13407. set.add(folded);
  13408. }
  13409. }
  13410. update(item, set.toString(regenerateOptions));
  13411. break;
  13412. case 'reference':
  13413. if (item.name) {
  13414. var name$1 = item.name.value;
  13415. var index$1 = groups.names[name$1];
  13416. if (index$1) {
  13417. updateNamedReference(item, index$1);
  13418. break;
  13419. }
  13420. if (!groups.unmatchedReferences[name$1]) {
  13421. groups.unmatchedReferences[name$1] = [];
  13422. }
  13423. // Keep track of references used before the corresponding group.
  13424. groups.unmatchedReferences[name$1].push(item);
  13425. }
  13426. break;
  13427. case 'anchor':
  13428. case 'empty':
  13429. case 'group':
  13430. // Nothing to do here.
  13431. break;
  13432. // The `default` clause is only here as a safeguard; it should never be
  13433. // reached. Code coverage tools should ignore it.
  13434. /* istanbul ignore next */
  13435. default:
  13436. throw new Error(("Unknown term type: " + (item.type)));
  13437. }
  13438. return item;
  13439. };
  13440. var config = {
  13441. 'ignoreCase': false,
  13442. 'unicode': false,
  13443. 'dotAll': false,
  13444. 'useUnicodeFlag': false
  13445. };
  13446. var rewritePattern = function (pattern, flags, options) {
  13447. var regjsparserFeatures = {
  13448. 'unicodePropertyEscape': options && options.unicodePropertyEscape,
  13449. 'namedGroups': options && options.namedGroup,
  13450. 'lookbehind': options && options.lookbehind
  13451. };
  13452. config.ignoreCase = flags && flags.includes('i');
  13453. config.unicode = flags && flags.includes('u');
  13454. var supportDotAllFlag = options && options.dotAllFlag;
  13455. config.dotAll = supportDotAllFlag && flags && flags.includes('s');
  13456. config.useUnicodeFlag = options && options.useUnicodeFlag;
  13457. var regenerateOptions = {
  13458. 'hasUnicodeFlag': config.useUnicodeFlag,
  13459. 'bmpOnly': !config.unicode
  13460. };
  13461. var groups = {
  13462. 'onNamedGroup': options && options.onNamedGroup,
  13463. 'lastIndex': 0,
  13464. 'names': Object.create(null), // { [name]: index }
  13465. 'unmatchedReferences': Object.create(null) // { [name]: Array<reference> }
  13466. };
  13467. var tree = parse(pattern, flags, regjsparserFeatures);
  13468. // Note: `processTerm` mutates `tree` and `groups`.
  13469. processTerm(tree, regenerateOptions, groups);
  13470. assertNoUnmatchedReferences(groups);
  13471. return generate(tree);
  13472. };
  13473. module.exports = rewritePattern;
  13474. });
  13475. var Literal = /*@__PURE__*/(function (Node) {
  13476. function Literal () {
  13477. Node.apply(this, arguments);
  13478. }
  13479. if ( Node ) Literal.__proto__ = Node;
  13480. Literal.prototype = Object.create( Node && Node.prototype );
  13481. Literal.prototype.constructor = Literal;
  13482. Literal.prototype.initialise = function initialise () {
  13483. if (typeof this.value === 'string') {
  13484. this.program.indentExclusionElements.push(this);
  13485. }
  13486. };
  13487. Literal.prototype.transpile = function transpile (code, transforms) {
  13488. if (transforms.numericLiteral) {
  13489. var leading = this.raw.slice(0, 2);
  13490. if (leading === '0b' || leading === '0o') {
  13491. code.overwrite(this.start, this.end, String(this.value), {
  13492. storeName: true,
  13493. contentOnly: true
  13494. });
  13495. }
  13496. }
  13497. if (this.regex) {
  13498. var ref = this.regex;
  13499. var pattern = ref.pattern;
  13500. var flags = ref.flags;
  13501. if (transforms.stickyRegExp && /y/.test(flags))
  13502. { throw new CompileError(
  13503. 'Regular expression sticky flag is not supported',
  13504. this
  13505. ); }
  13506. if (transforms.unicodeRegExp && /u/.test(flags)) {
  13507. code.overwrite(
  13508. this.start,
  13509. this.end,
  13510. ("/" + (rewritePattern_1(pattern, flags)) + "/" + (flags.replace('u', ''))),
  13511. {
  13512. contentOnly: true
  13513. }
  13514. );
  13515. }
  13516. }
  13517. };
  13518. return Literal;
  13519. }(Node$1));
  13520. var MemberExpression = /*@__PURE__*/(function (Node) {
  13521. function MemberExpression () {
  13522. Node.apply(this, arguments);
  13523. }
  13524. if ( Node ) MemberExpression.__proto__ = Node;
  13525. MemberExpression.prototype = Object.create( Node && Node.prototype );
  13526. MemberExpression.prototype.constructor = MemberExpression;
  13527. MemberExpression.prototype.transpile = function transpile (code, transforms) {
  13528. if (transforms.reservedProperties && reserved[this.property.name]) {
  13529. code.overwrite(this.object.end, this.property.start, "['");
  13530. code.appendLeft(this.property.end, "']");
  13531. }
  13532. Node.prototype.transpile.call(this, code, transforms);
  13533. };
  13534. return MemberExpression;
  13535. }(Node$1));
  13536. var NewExpression = /*@__PURE__*/(function (Node) {
  13537. function NewExpression () {
  13538. Node.apply(this, arguments);
  13539. }
  13540. if ( Node ) NewExpression.__proto__ = Node;
  13541. NewExpression.prototype = Object.create( Node && Node.prototype );
  13542. NewExpression.prototype.constructor = NewExpression;
  13543. NewExpression.prototype.initialise = function initialise (transforms) {
  13544. if (transforms.spreadRest && this.arguments.length) {
  13545. var lexicalBoundary = this.findLexicalBoundary();
  13546. var i = this.arguments.length;
  13547. while (i--) {
  13548. var arg = this.arguments[i];
  13549. if (arg.type === 'SpreadElement' && isArguments(arg.argument)) {
  13550. this.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
  13551. break;
  13552. }
  13553. }
  13554. }
  13555. Node.prototype.initialise.call(this, transforms);
  13556. };
  13557. NewExpression.prototype.transpile = function transpile (code, transforms) {
  13558. Node.prototype.transpile.call(this, code, transforms);
  13559. if (transforms.spreadRest && this.arguments.length) {
  13560. var firstArgument = this.arguments[0];
  13561. var isNew = true;
  13562. var hasSpreadElements = spread(
  13563. code,
  13564. this.arguments,
  13565. firstArgument.start,
  13566. this.argumentsArrayAlias,
  13567. isNew
  13568. );
  13569. if (hasSpreadElements) {
  13570. code.prependRight(
  13571. this.start + 'new'.length,
  13572. ' (Function.prototype.bind.apply('
  13573. );
  13574. code.overwrite(
  13575. this.callee.end,
  13576. firstArgument.start,
  13577. ', [ null ].concat( '
  13578. );
  13579. code.appendLeft(this.end, ' ))');
  13580. }
  13581. }
  13582. if (this.arguments.length) {
  13583. removeTrailingComma(code, this.arguments[this.arguments.length - 1].end);
  13584. }
  13585. };
  13586. return NewExpression;
  13587. }(Node$1));
  13588. var ObjectExpression = /*@__PURE__*/(function (Node) {
  13589. function ObjectExpression () {
  13590. Node.apply(this, arguments);
  13591. }
  13592. if ( Node ) ObjectExpression.__proto__ = Node;
  13593. ObjectExpression.prototype = Object.create( Node && Node.prototype );
  13594. ObjectExpression.prototype.constructor = ObjectExpression;
  13595. ObjectExpression.prototype.transpile = function transpile (code, transforms) {
  13596. Node.prototype.transpile.call(this, code, transforms);
  13597. var firstPropertyStart = this.start + 1;
  13598. var regularPropertyCount = 0;
  13599. var spreadPropertyCount = 0;
  13600. var computedPropertyCount = 0;
  13601. var firstSpreadProperty = null;
  13602. var firstComputedProperty = null;
  13603. for (var i = 0; i < this.properties.length; ++i) {
  13604. var prop = this.properties[i];
  13605. if (prop.type === 'SpreadElement') {
  13606. spreadPropertyCount += 1;
  13607. if (firstSpreadProperty === null) { firstSpreadProperty = i; }
  13608. } else if (prop.computed) {
  13609. computedPropertyCount += 1;
  13610. if (firstComputedProperty === null) { firstComputedProperty = i; }
  13611. } else if (prop.type === 'Property') {
  13612. regularPropertyCount += 1;
  13613. }
  13614. }
  13615. if (spreadPropertyCount) {
  13616. if (!this.program.options.objectAssign) {
  13617. throw new CompileError(
  13618. "Object spread operator requires specified objectAssign option with 'Object.assign' or polyfill helper.",
  13619. this
  13620. );
  13621. }
  13622. // enclose run of non-spread properties in curlies
  13623. var i$1 = this.properties.length;
  13624. if (regularPropertyCount && !computedPropertyCount) {
  13625. while (i$1--) {
  13626. var prop$1 = this.properties[i$1];
  13627. if (prop$1.type === 'Property' && !prop$1.computed) {
  13628. var lastProp = this.properties[i$1 - 1];
  13629. var nextProp = this.properties[i$1 + 1];
  13630. if (
  13631. !lastProp ||
  13632. lastProp.type !== 'Property' ||
  13633. lastProp.computed
  13634. ) {
  13635. code.prependRight(prop$1.start, '{');
  13636. }
  13637. if (
  13638. !nextProp ||
  13639. nextProp.type !== 'Property' ||
  13640. nextProp.computed
  13641. ) {
  13642. code.appendLeft(prop$1.end, '}');
  13643. }
  13644. }
  13645. }
  13646. }
  13647. // wrap the whole thing in Object.assign
  13648. firstPropertyStart = this.properties[0].start;
  13649. if (!computedPropertyCount) {
  13650. code.overwrite(
  13651. this.start,
  13652. firstPropertyStart,
  13653. ((this.program.options.objectAssign) + "({}, ")
  13654. );
  13655. code.overwrite(
  13656. this.properties[this.properties.length - 1].end,
  13657. this.end,
  13658. ')'
  13659. );
  13660. } else if (this.properties[0].type === 'SpreadElement') {
  13661. code.overwrite(
  13662. this.start,
  13663. firstPropertyStart,
  13664. ((this.program.options.objectAssign) + "({}, ")
  13665. );
  13666. code.remove(this.end - 1, this.end);
  13667. code.appendRight(this.end, ')');
  13668. } else {
  13669. code.prependLeft(this.start, ((this.program.options.objectAssign) + "("));
  13670. code.appendRight(this.end, ')');
  13671. }
  13672. }
  13673. if (computedPropertyCount && transforms.computedProperty) {
  13674. var i0 = this.getIndentation();
  13675. var isSimpleAssignment;
  13676. var name;
  13677. if (
  13678. this.parent.type === 'VariableDeclarator' &&
  13679. this.parent.parent.declarations.length === 1 &&
  13680. this.parent.id.type === 'Identifier'
  13681. ) {
  13682. isSimpleAssignment = true;
  13683. name = this.parent.id.alias || this.parent.id.name; // TODO is this right?
  13684. } else if (
  13685. this.parent.type === 'AssignmentExpression' &&
  13686. this.parent.parent.type === 'ExpressionStatement' &&
  13687. this.parent.left.type === 'Identifier'
  13688. ) {
  13689. isSimpleAssignment = true;
  13690. name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
  13691. } else if (
  13692. this.parent.type === 'AssignmentPattern' &&
  13693. this.parent.left.type === 'Identifier'
  13694. ) {
  13695. isSimpleAssignment = true;
  13696. name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
  13697. }
  13698. if (spreadPropertyCount) { isSimpleAssignment = false; }
  13699. // handle block scoping
  13700. name = this.findScope(false).resolveName(name);
  13701. var start = firstPropertyStart;
  13702. var end = this.end;
  13703. if (isSimpleAssignment) {
  13704. // ???
  13705. } else {
  13706. if (
  13707. firstSpreadProperty === null ||
  13708. firstComputedProperty < firstSpreadProperty
  13709. ) {
  13710. name = this.findScope(true).createDeclaration('_obj');
  13711. code.prependRight(this.start, ("( " + name + " = "));
  13712. } else { name = null; } // We don't actually need this variable
  13713. }
  13714. var len = this.properties.length;
  13715. var lastComputedProp;
  13716. var sawNonComputedProperty = false;
  13717. var isFirst = true;
  13718. for (var i$2 = 0; i$2 < len; i$2 += 1) {
  13719. var prop$2 = this.properties[i$2];
  13720. var moveStart = i$2 > 0 ? this.properties[i$2 - 1].end : start;
  13721. if (
  13722. prop$2.type === 'Property' &&
  13723. (prop$2.computed || (lastComputedProp && !spreadPropertyCount))
  13724. ) {
  13725. if (i$2 === 0) { moveStart = this.start + 1; } // Trim leading whitespace
  13726. lastComputedProp = prop$2;
  13727. if (!name) {
  13728. name = this.findScope(true).createDeclaration('_obj');
  13729. var propId = name + (prop$2.computed ? '' : '.');
  13730. code.appendRight(prop$2.start, ("( " + name + " = {}, " + propId));
  13731. } else {
  13732. var propId$1 =
  13733. (isSimpleAssignment ? (";\n" + i0 + name) : (", " + name)) +
  13734. (prop$2.key.type === 'Literal' || prop$2.computed ? '' : '.');
  13735. if (moveStart < prop$2.start) {
  13736. code.overwrite(moveStart, prop$2.start, propId$1);
  13737. } else {
  13738. code.prependRight(prop$2.start, propId$1);
  13739. }
  13740. }
  13741. var c = prop$2.key.end;
  13742. if (prop$2.computed) {
  13743. while (code.original[c] !== ']') { c += 1; }
  13744. c += 1;
  13745. }
  13746. if (prop$2.key.type === 'Literal' && !prop$2.computed) {
  13747. code.overwrite(
  13748. prop$2.start,
  13749. prop$2.key.end + 1,
  13750. '[' + code.slice(prop$2.start, prop$2.key.end) + '] = '
  13751. );
  13752. } else if (prop$2.shorthand || (prop$2.method && !prop$2.computed && transforms.conciseMethodProperty)) {
  13753. // Replace : with = if Property::transpile inserted the :
  13754. code.overwrite(
  13755. prop$2.key.start,
  13756. prop$2.key.end,
  13757. code.slice(prop$2.key.start, prop$2.key.end).replace(/:/, ' =')
  13758. );
  13759. } else {
  13760. if (prop$2.value.start > c) { code.remove(c, prop$2.value.start); }
  13761. code.prependLeft(c, ' = ');
  13762. }
  13763. // This duplicates behavior from Property::transpile which is disabled
  13764. // for computed properties or if conciseMethodProperty is false
  13765. if (prop$2.method && (prop$2.computed || !transforms.conciseMethodProperty)) {
  13766. if (prop$2.value.generator) { code.remove(prop$2.start, prop$2.key.start); }
  13767. code.prependRight(prop$2.value.start, ("function" + (prop$2.value.generator ? '*' : '') + " "));
  13768. }
  13769. } else if (prop$2.type === 'SpreadElement') {
  13770. if (name && i$2 > 0) {
  13771. if (!lastComputedProp) {
  13772. lastComputedProp = this.properties[i$2 - 1];
  13773. }
  13774. code.appendLeft(lastComputedProp.end, (", " + name + " )"));
  13775. lastComputedProp = null;
  13776. name = null;
  13777. }
  13778. } else {
  13779. if (!isFirst && spreadPropertyCount) {
  13780. // We are in an Object.assign context, so we need to wrap regular properties
  13781. code.prependRight(prop$2.start, '{');
  13782. code.appendLeft(prop$2.end, '}');
  13783. }
  13784. sawNonComputedProperty = true;
  13785. }
  13786. if (isFirst && (prop$2.type === 'SpreadElement' || prop$2.computed)) {
  13787. var beginEnd = sawNonComputedProperty
  13788. ? this.properties[this.properties.length - 1].end
  13789. : this.end - 1;
  13790. // Trim trailing comma because it can easily become a leading comma which is illegal
  13791. if (code.original[beginEnd] == ',') { ++beginEnd; }
  13792. var closing = code.slice(beginEnd, end);
  13793. code.prependLeft(moveStart, closing);
  13794. code.remove(beginEnd, end);
  13795. isFirst = false;
  13796. }
  13797. // Clean up some extranous whitespace
  13798. var c$1 = prop$2.end;
  13799. if (i$2 < len - 1 && !sawNonComputedProperty) {
  13800. while (code.original[c$1] !== ',') { c$1 += 1; }
  13801. } else if (i$2 == len - 1) { c$1 = this.end; }
  13802. code.remove(prop$2.end, c$1);
  13803. }
  13804. // special case
  13805. if (computedPropertyCount === len) {
  13806. code.remove(this.properties[len - 1].end, this.end - 1);
  13807. }
  13808. if (!isSimpleAssignment && name) {
  13809. code.appendLeft(lastComputedProp.end, (", " + name + " )"));
  13810. }
  13811. }
  13812. };
  13813. return ObjectExpression;
  13814. }(Node$1));
  13815. var Property = /*@__PURE__*/(function (Node) {
  13816. function Property () {
  13817. Node.apply(this, arguments);
  13818. }
  13819. if ( Node ) Property.__proto__ = Node;
  13820. Property.prototype = Object.create( Node && Node.prototype );
  13821. Property.prototype.constructor = Property;
  13822. Property.prototype.transpile = function transpile (code, transforms) {
  13823. Node.prototype.transpile.call(this, code, transforms);
  13824. if (
  13825. transforms.conciseMethodProperty &&
  13826. !this.computed &&
  13827. this.parent.type !== 'ObjectPattern'
  13828. ) {
  13829. if (this.shorthand) {
  13830. code.prependRight(this.start, ((this.key.name) + ": " + (this.shouldPrefix() ? '_vm.' : '')));
  13831. } else if (this.method) {
  13832. var name = '';
  13833. if (this.program.options.namedFunctionExpressions !== false) {
  13834. if (
  13835. this.key.type === 'Literal' &&
  13836. typeof this.key.value === 'number'
  13837. ) {
  13838. name = '';
  13839. } else if (this.key.type === 'Identifier') {
  13840. if (
  13841. reserved[this.key.name] ||
  13842. !/^[a-z_$][a-z0-9_$]*$/i.test(this.key.name) ||
  13843. this.value.body.scope.references[this.key.name]
  13844. ) {
  13845. name = this.findScope(true).createIdentifier(this.key.name);
  13846. } else {
  13847. name = this.key.name;
  13848. }
  13849. } else {
  13850. name = this.findScope(true).createIdentifier(this.key.value);
  13851. }
  13852. name = ' ' + name;
  13853. }
  13854. if (this.value.generator) { code.remove(this.start, this.key.start); }
  13855. code.appendLeft(
  13856. this.key.end,
  13857. (": function" + (this.value.generator ? '*' : '') + name)
  13858. );
  13859. }
  13860. }
  13861. if (transforms.reservedProperties && reserved[this.key.name]) {
  13862. code.prependRight(this.key.start, "'");
  13863. code.appendLeft(this.key.end, "'");
  13864. }
  13865. };
  13866. Property.prototype.shouldPrefix = function shouldPrefix () {
  13867. if (
  13868. this.program.inWith > 0 &&
  13869. !hash[this.key.name] &&
  13870. !this.findScope(false).contains(this.key.name)
  13871. ) {
  13872. return true
  13873. }
  13874. return false
  13875. };
  13876. return Property;
  13877. }(Node$1));
  13878. var ReturnStatement = /*@__PURE__*/(function (Node) {
  13879. function ReturnStatement () {
  13880. Node.apply(this, arguments);
  13881. }
  13882. if ( Node ) ReturnStatement.__proto__ = Node;
  13883. ReturnStatement.prototype = Object.create( Node && Node.prototype );
  13884. ReturnStatement.prototype.constructor = ReturnStatement;
  13885. ReturnStatement.prototype.initialise = function initialise (transforms) {
  13886. this.loop = this.findNearest(loopStatement);
  13887. this.nearestFunction = this.findNearest(/Function/);
  13888. if (
  13889. this.loop &&
  13890. (!this.nearestFunction || this.loop.depth > this.nearestFunction.depth)
  13891. ) {
  13892. this.loop.canReturn = true;
  13893. this.shouldWrap = true;
  13894. }
  13895. if (this.argument) { this.argument.initialise(transforms); }
  13896. };
  13897. ReturnStatement.prototype.transpile = function transpile (code, transforms) {
  13898. var shouldWrap =
  13899. this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;
  13900. if (this.argument) {
  13901. if (shouldWrap) { code.prependRight(this.argument.start, "{ v: "); }
  13902. this.argument.transpile(code, transforms);
  13903. if (shouldWrap) { code.appendLeft(this.argument.end, " }"); }
  13904. } else if (shouldWrap) {
  13905. code.appendLeft(this.start + 6, ' {}');
  13906. }
  13907. };
  13908. return ReturnStatement;
  13909. }(Node$1));
  13910. var SpreadElement = /*@__PURE__*/(function (Node) {
  13911. function SpreadElement () {
  13912. Node.apply(this, arguments);
  13913. }
  13914. if ( Node ) SpreadElement.__proto__ = Node;
  13915. SpreadElement.prototype = Object.create( Node && Node.prototype );
  13916. SpreadElement.prototype.constructor = SpreadElement;
  13917. SpreadElement.prototype.transpile = function transpile (code, transforms) {
  13918. if (this.parent.type == 'ObjectExpression') {
  13919. code.remove(this.start, this.argument.start);
  13920. code.remove(this.argument.end, this.end);
  13921. }
  13922. Node.prototype.transpile.call(this, code, transforms);
  13923. };
  13924. return SpreadElement;
  13925. }(Node$1));
  13926. var Super = /*@__PURE__*/(function (Node) {
  13927. function Super () {
  13928. Node.apply(this, arguments);
  13929. }
  13930. if ( Node ) Super.__proto__ = Node;
  13931. Super.prototype = Object.create( Node && Node.prototype );
  13932. Super.prototype.constructor = Super;
  13933. Super.prototype.initialise = function initialise (transforms) {
  13934. if (transforms.classes) {
  13935. this.method = this.findNearest('MethodDefinition');
  13936. if (!this.method)
  13937. { throw new CompileError('use of super outside class method', this); }
  13938. var parentClass = this.findNearest('ClassBody').parent;
  13939. this.superClassName =
  13940. parentClass.superClass && (parentClass.superClass.name || 'superclass');
  13941. if (!this.superClassName)
  13942. { throw new CompileError('super used in base class', this); }
  13943. this.isCalled =
  13944. this.parent.type === 'CallExpression' && this === this.parent.callee;
  13945. if (this.method.kind !== 'constructor' && this.isCalled) {
  13946. throw new CompileError(
  13947. 'super() not allowed outside class constructor',
  13948. this
  13949. );
  13950. }
  13951. this.isMember = this.parent.type === 'MemberExpression';
  13952. if (!this.isCalled && !this.isMember) {
  13953. throw new CompileError(
  13954. 'Unexpected use of `super` (expected `super(...)` or `super.*`)',
  13955. this
  13956. );
  13957. }
  13958. }
  13959. if (transforms.arrow) {
  13960. var lexicalBoundary = this.findLexicalBoundary();
  13961. var arrowFunction = this.findNearest('ArrowFunctionExpression');
  13962. var loop = this.findNearest(loopStatement);
  13963. if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) {
  13964. this.thisAlias = lexicalBoundary.getThisAlias();
  13965. }
  13966. if (
  13967. loop &&
  13968. loop.body.contains(this) &&
  13969. loop.depth > lexicalBoundary.depth
  13970. ) {
  13971. this.thisAlias = lexicalBoundary.getThisAlias();
  13972. }
  13973. }
  13974. };
  13975. Super.prototype.transpile = function transpile (code, transforms) {
  13976. if (transforms.classes) {
  13977. var expression =
  13978. this.isCalled || this.method.static
  13979. ? this.superClassName
  13980. : ((this.superClassName) + ".prototype");
  13981. code.overwrite(this.start, this.end, expression, {
  13982. storeName: true,
  13983. contentOnly: true
  13984. });
  13985. var callExpression = this.isCalled ? this.parent : this.parent.parent;
  13986. if (callExpression && callExpression.type === 'CallExpression') {
  13987. if (!this.noCall) {
  13988. // special case – `super( ...args )`
  13989. code.appendLeft(callExpression.callee.end, '.call');
  13990. }
  13991. var thisAlias = this.thisAlias || 'this';
  13992. if (callExpression.arguments.length) {
  13993. code.appendLeft(callExpression.arguments[0].start, (thisAlias + ", "));
  13994. } else {
  13995. code.appendLeft(callExpression.end - 1, ("" + thisAlias));
  13996. }
  13997. }
  13998. }
  13999. };
  14000. return Super;
  14001. }(Node$1));
  14002. var TaggedTemplateExpression = /*@__PURE__*/(function (Node) {
  14003. function TaggedTemplateExpression () {
  14004. Node.apply(this, arguments);
  14005. }
  14006. if ( Node ) TaggedTemplateExpression.__proto__ = Node;
  14007. TaggedTemplateExpression.prototype = Object.create( Node && Node.prototype );
  14008. TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
  14009. TaggedTemplateExpression.prototype.initialise = function initialise (transforms) {
  14010. if (
  14011. transforms.templateString &&
  14012. !transforms.dangerousTaggedTemplateString
  14013. ) {
  14014. throw new CompileError(
  14015. "Tagged template strings are not supported. Use `transforms: { templateString: false }` to skip transformation and disable this error, or `transforms: { dangerousTaggedTemplateString: true }` if you know what you're doing",
  14016. this
  14017. );
  14018. }
  14019. Node.prototype.initialise.call(this, transforms);
  14020. };
  14021. TaggedTemplateExpression.prototype.transpile = function transpile (code, transforms) {
  14022. if (transforms.templateString && transforms.dangerousTaggedTemplateString) {
  14023. var ordered = this.quasi.expressions
  14024. .concat(this.quasi.quasis)
  14025. .sort(function (a, b) { return a.start - b.start; });
  14026. var program = this.program;
  14027. var rootScope = program.body.scope;
  14028. // insert strings at start
  14029. var templateStrings = this.quasi.quasis.map(function (quasi) { return JSON.stringify(quasi.value.cooked); }
  14030. ).join(', ');
  14031. var templateObject = this.program.templateLiteralQuasis[templateStrings];
  14032. if (!templateObject) {
  14033. templateObject = rootScope.createIdentifier('templateObject');
  14034. code.prependRight(this.program.prependAt, ("var " + templateObject + " = Object.freeze([" + templateStrings + "]);\n"));
  14035. this.program.templateLiteralQuasis[templateStrings] = templateObject;
  14036. }
  14037. code.overwrite(
  14038. this.tag.end,
  14039. ordered[0].start,
  14040. ("(" + templateObject)
  14041. );
  14042. var lastIndex = ordered[0].start;
  14043. ordered.forEach(function (node) {
  14044. if (node.type === 'TemplateElement') {
  14045. code.remove(lastIndex, node.end);
  14046. } else {
  14047. code.overwrite(lastIndex, node.start, ', ');
  14048. }
  14049. lastIndex = node.end;
  14050. });
  14051. code.overwrite(lastIndex, this.end, ')');
  14052. }
  14053. Node.prototype.transpile.call(this, code, transforms);
  14054. };
  14055. return TaggedTemplateExpression;
  14056. }(Node$1));
  14057. var TemplateElement = /*@__PURE__*/(function (Node) {
  14058. function TemplateElement () {
  14059. Node.apply(this, arguments);
  14060. }
  14061. if ( Node ) TemplateElement.__proto__ = Node;
  14062. TemplateElement.prototype = Object.create( Node && Node.prototype );
  14063. TemplateElement.prototype.constructor = TemplateElement;
  14064. TemplateElement.prototype.initialise = function initialise () {
  14065. this.program.indentExclusionElements.push(this);
  14066. };
  14067. return TemplateElement;
  14068. }(Node$1));
  14069. var TemplateLiteral = /*@__PURE__*/(function (Node) {
  14070. function TemplateLiteral () {
  14071. Node.apply(this, arguments);
  14072. }
  14073. if ( Node ) TemplateLiteral.__proto__ = Node;
  14074. TemplateLiteral.prototype = Object.create( Node && Node.prototype );
  14075. TemplateLiteral.prototype.constructor = TemplateLiteral;
  14076. TemplateLiteral.prototype.transpile = function transpile (code, transforms) {
  14077. Node.prototype.transpile.call(this, code, transforms);
  14078. if (
  14079. transforms.templateString &&
  14080. this.parent.type !== 'TaggedTemplateExpression'
  14081. ) {
  14082. var ordered = this.expressions
  14083. .concat(this.quasis)
  14084. .sort(function (a, b) { return a.start - b.start || a.end - b.end; })
  14085. .filter(function (node, i) {
  14086. // include all expressions
  14087. if (node.type !== 'TemplateElement') { return true; }
  14088. // include all non-empty strings
  14089. if (node.value.raw) { return true; }
  14090. // exclude all empty strings not at the head
  14091. return !i;
  14092. });
  14093. // special case – we may be able to skip the first element,
  14094. // if it's the empty string, but only if the second and
  14095. // third elements aren't both expressions (since they maybe
  14096. // be numeric, and `1 + 2 + '3' === '33'`)
  14097. if (ordered.length >= 3) {
  14098. var first = ordered[0];
  14099. var third = ordered[2];
  14100. if (
  14101. first.type === 'TemplateElement' &&
  14102. first.value.raw === '' &&
  14103. third.type === 'TemplateElement'
  14104. ) {
  14105. ordered.shift();
  14106. }
  14107. }
  14108. var parenthesise =
  14109. (this.quasis.length !== 1 || this.expressions.length !== 0) &&
  14110. this.parent.type !== 'TemplateLiteral' &&
  14111. this.parent.type !== 'AssignmentExpression' &&
  14112. this.parent.type !== 'AssignmentPattern' &&
  14113. this.parent.type !== 'VariableDeclarator' &&
  14114. (this.parent.type !== 'BinaryExpression' ||
  14115. this.parent.operator !== '+');
  14116. if (parenthesise) { code.appendRight(this.start, '('); }
  14117. var lastIndex = this.start;
  14118. ordered.forEach(function (node, i) {
  14119. var prefix = i === 0 ? (parenthesise ? '(' : '') : ' + ';
  14120. if (node.type === 'TemplateElement') {
  14121. code.overwrite(
  14122. lastIndex,
  14123. node.end,
  14124. prefix + JSON.stringify(node.value.cooked)
  14125. );
  14126. } else {
  14127. var parenthesise$1 = node.type !== 'Identifier'; // TODO other cases where it's safe
  14128. if (parenthesise$1) { prefix += '('; }
  14129. code.remove(lastIndex, node.start);
  14130. if (prefix) { code.prependRight(node.start, prefix); }
  14131. if (parenthesise$1) { code.appendLeft(node.end, ')'); }
  14132. }
  14133. lastIndex = node.end;
  14134. });
  14135. if (parenthesise) { code.appendLeft(lastIndex, ')'); }
  14136. code.overwrite(lastIndex, this.end, "", { contentOnly: true } );
  14137. }
  14138. };
  14139. return TemplateLiteral;
  14140. }(Node$1));
  14141. var ThisExpression = /*@__PURE__*/(function (Node) {
  14142. function ThisExpression () {
  14143. Node.apply(this, arguments);
  14144. }
  14145. if ( Node ) ThisExpression.__proto__ = Node;
  14146. ThisExpression.prototype = Object.create( Node && Node.prototype );
  14147. ThisExpression.prototype.constructor = ThisExpression;
  14148. ThisExpression.prototype.initialise = function initialise (transforms) {
  14149. if (transforms.arrow) {
  14150. var lexicalBoundary = this.findLexicalBoundary();
  14151. var arrowFunction = this.findNearest('ArrowFunctionExpression');
  14152. var loop = this.findNearest(loopStatement);
  14153. if (
  14154. (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) ||
  14155. (loop &&
  14156. loop.body.contains(this) &&
  14157. loop.depth > lexicalBoundary.depth) ||
  14158. (loop && loop.right && loop.right.contains(this))
  14159. ) {
  14160. this.alias = lexicalBoundary.getThisAlias();
  14161. }
  14162. }
  14163. };
  14164. ThisExpression.prototype.transpile = function transpile (code) {
  14165. if (this.alias) {
  14166. code.overwrite(this.start, this.end, this.alias, {
  14167. storeName: true,
  14168. contentOnly: true
  14169. });
  14170. }
  14171. };
  14172. return ThisExpression;
  14173. }(Node$1));
  14174. var UpdateExpression = /*@__PURE__*/(function (Node) {
  14175. function UpdateExpression () {
  14176. Node.apply(this, arguments);
  14177. }
  14178. if ( Node ) UpdateExpression.__proto__ = Node;
  14179. UpdateExpression.prototype = Object.create( Node && Node.prototype );
  14180. UpdateExpression.prototype.constructor = UpdateExpression;
  14181. UpdateExpression.prototype.initialise = function initialise (transforms) {
  14182. if (this.argument.type === 'Identifier') {
  14183. var declaration = this.findScope(false).findDeclaration(
  14184. this.argument.name
  14185. );
  14186. // special case – https://gitlab.com/Rich-Harris/buble/issues/150
  14187. var statement = declaration && declaration.node.ancestor(3);
  14188. if (
  14189. statement &&
  14190. statement.type === 'ForStatement' &&
  14191. statement.body.contains(this)
  14192. ) {
  14193. statement.reassigned[this.argument.name] = true;
  14194. }
  14195. }
  14196. Node.prototype.initialise.call(this, transforms);
  14197. };
  14198. UpdateExpression.prototype.transpile = function transpile (code, transforms) {
  14199. if (this.argument.type === 'Identifier') {
  14200. // Do this check after everything has been initialized to find
  14201. // shadowing declarations after this expression
  14202. checkConst(this.argument, this.findScope(false));
  14203. }
  14204. Node.prototype.transpile.call(this, code, transforms);
  14205. };
  14206. return UpdateExpression;
  14207. }(Node$1));
  14208. var VariableDeclaration = /*@__PURE__*/(function (Node) {
  14209. function VariableDeclaration () {
  14210. Node.apply(this, arguments);
  14211. }
  14212. if ( Node ) VariableDeclaration.__proto__ = Node;
  14213. VariableDeclaration.prototype = Object.create( Node && Node.prototype );
  14214. VariableDeclaration.prototype.constructor = VariableDeclaration;
  14215. VariableDeclaration.prototype.initialise = function initialise (transforms) {
  14216. this.scope = this.findScope(this.kind === 'var');
  14217. this.declarations.forEach(function (declarator) { return declarator.initialise(transforms); });
  14218. };
  14219. VariableDeclaration.prototype.transpile = function transpile (code, transforms) {
  14220. var this$1 = this;
  14221. var i0 = this.getIndentation();
  14222. var kind = this.kind;
  14223. if (transforms.letConst && kind !== 'var') {
  14224. kind = 'var';
  14225. code.overwrite(this.start, this.start + this.kind.length, kind, {
  14226. storeName: true
  14227. });
  14228. }
  14229. if (transforms.destructuring && this.parent.type !== 'ForOfStatement' && this.parent.type !== 'ForInStatement') {
  14230. var c = this.start;
  14231. var lastDeclaratorIsPattern;
  14232. this.declarations.forEach(function (declarator, i) {
  14233. declarator.transpile(code, transforms);
  14234. if (declarator.id.type === 'Identifier') {
  14235. if (i > 0 && this$1.declarations[i - 1].id.type !== 'Identifier') {
  14236. code.overwrite(c, declarator.id.start, "var ");
  14237. }
  14238. } else {
  14239. var inline = loopStatement.test(this$1.parent.type);
  14240. if (i === 0) {
  14241. code.remove(c, declarator.id.start);
  14242. } else {
  14243. code.overwrite(c, declarator.id.start, (";\n" + i0));
  14244. }
  14245. var simple =
  14246. declarator.init.type === 'Identifier' && !declarator.init.rewritten;
  14247. var name = simple
  14248. ? (declarator.init.alias || declarator.init.name)
  14249. : declarator.findScope(true).createIdentifier('ref');
  14250. c = declarator.start;
  14251. var statementGenerators = [];
  14252. if (simple) {
  14253. code.remove(declarator.id.end, declarator.end);
  14254. } else {
  14255. statementGenerators.push(function (start, prefix, suffix) {
  14256. code.prependRight(declarator.id.end, ("var " + name));
  14257. code.appendLeft(declarator.init.end, ("" + suffix));
  14258. code.move(declarator.id.end, declarator.end, start);
  14259. });
  14260. }
  14261. var scope = declarator.findScope(false);
  14262. destructure(
  14263. code,
  14264. function (id) { return scope.createIdentifier(id); },
  14265. function (ref) {
  14266. var name = ref.name;
  14267. return scope.resolveName(name);
  14268. },
  14269. declarator.id,
  14270. name,
  14271. inline,
  14272. statementGenerators
  14273. );
  14274. var prefix = inline ? 'var ' : '';
  14275. var suffix = inline ? ", " : (";\n" + i0);
  14276. statementGenerators.forEach(function (fn, j) {
  14277. if (
  14278. i === this$1.declarations.length - 1 &&
  14279. j === statementGenerators.length - 1
  14280. ) {
  14281. suffix = inline ? '' : ';';
  14282. }
  14283. fn(declarator.start, j === 0 ? prefix : '', suffix);
  14284. });
  14285. }
  14286. c = declarator.end;
  14287. lastDeclaratorIsPattern = declarator.id.type !== 'Identifier';
  14288. });
  14289. if (lastDeclaratorIsPattern && this.end > c) {
  14290. code.overwrite(c, this.end, '', { contentOnly: true });
  14291. }
  14292. } else {
  14293. this.declarations.forEach(function (declarator) {
  14294. declarator.transpile(code, transforms);
  14295. });
  14296. }
  14297. };
  14298. return VariableDeclaration;
  14299. }(Node$1));
  14300. var VariableDeclarator = /*@__PURE__*/(function (Node) {
  14301. function VariableDeclarator () {
  14302. Node.apply(this, arguments);
  14303. }
  14304. if ( Node ) VariableDeclarator.__proto__ = Node;
  14305. VariableDeclarator.prototype = Object.create( Node && Node.prototype );
  14306. VariableDeclarator.prototype.constructor = VariableDeclarator;
  14307. VariableDeclarator.prototype.initialise = function initialise (transforms) {
  14308. var kind = this.parent.kind;
  14309. if (kind === 'let' && this.parent.parent.type === 'ForStatement') {
  14310. kind = 'for.let'; // special case...
  14311. }
  14312. this.parent.scope.addDeclaration(this.id, kind);
  14313. Node.prototype.initialise.call(this, transforms);
  14314. };
  14315. VariableDeclarator.prototype.transpile = function transpile (code, transforms) {
  14316. if (!this.init && transforms.letConst && this.parent.kind !== 'var') {
  14317. var inLoop = this.findNearest(
  14318. /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/
  14319. );
  14320. if (
  14321. inLoop &&
  14322. !/Function/.test(inLoop.type) &&
  14323. !this.isLeftDeclaratorOfLoop()
  14324. ) {
  14325. code.appendLeft(this.id.end, ' = (void 0)');
  14326. }
  14327. }
  14328. if (this.id) { this.id.transpile(code, transforms); }
  14329. if (this.init) { this.init.transpile(code, transforms); }
  14330. };
  14331. VariableDeclarator.prototype.isLeftDeclaratorOfLoop = function isLeftDeclaratorOfLoop () {
  14332. return (
  14333. this.parent &&
  14334. this.parent.type === 'VariableDeclaration' &&
  14335. this.parent.parent &&
  14336. (this.parent.parent.type === 'ForInStatement' ||
  14337. this.parent.parent.type === 'ForOfStatement') &&
  14338. this.parent.parent.left &&
  14339. this.parent.parent.left.declarations[0] === this
  14340. );
  14341. };
  14342. return VariableDeclarator;
  14343. }(Node$1));
  14344. var WithStatement = /*@__PURE__*/(function (Node) {
  14345. function WithStatement () {
  14346. Node.apply(this, arguments);
  14347. }
  14348. if ( Node ) WithStatement.__proto__ = Node;
  14349. WithStatement.prototype = Object.create( Node && Node.prototype );
  14350. WithStatement.prototype.constructor = WithStatement;
  14351. WithStatement.prototype.transpile = function transpile (code, transforms) {
  14352. if (transforms.stripWith) {
  14353. this.program.inWith = (this.program.inWith || 0) + 1;
  14354. // remove surrounding with block
  14355. code.remove(this.start, this.body.start + 1);
  14356. code.remove(this.end - 1, this.end);
  14357. if (transforms.stripWithFunctional) {
  14358. code.prependRight(this.start, "var _c=_vm._c;");
  14359. } else {
  14360. code.prependRight(this.start, "var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;");
  14361. }
  14362. Node.prototype.transpile.call(this, code, transforms);
  14363. this.program.inWith--;
  14364. } else {
  14365. Node.prototype.transpile.call(this, code, transforms);
  14366. }
  14367. };
  14368. return WithStatement;
  14369. }(Node$1));
  14370. var types$2 = {
  14371. ArrayExpression: ArrayExpression,
  14372. ArrowFunctionExpression: ArrowFunctionExpression,
  14373. AssignmentExpression: AssignmentExpression,
  14374. BinaryExpression: BinaryExpression,
  14375. BreakStatement: BreakStatement,
  14376. CallExpression: CallExpression,
  14377. ClassBody: ClassBody,
  14378. ClassDeclaration: ClassDeclaration,
  14379. ClassExpression: ClassExpression,
  14380. ContinueStatement: ContinueStatement,
  14381. DoWhileStatement: LoopStatement,
  14382. ExportNamedDeclaration: ExportNamedDeclaration,
  14383. ExportDefaultDeclaration: ExportDefaultDeclaration,
  14384. ForStatement: ForStatement,
  14385. ForInStatement: ForInStatement,
  14386. ForOfStatement: ForOfStatement,
  14387. FunctionDeclaration: FunctionDeclaration,
  14388. FunctionExpression: FunctionExpression,
  14389. Identifier: Identifier,
  14390. IfStatement: IfStatement,
  14391. ImportDeclaration: ImportDeclaration,
  14392. ImportDefaultSpecifier: ImportDefaultSpecifier,
  14393. ImportSpecifier: ImportSpecifier,
  14394. JSXAttribute: JSXAttribute,
  14395. JSXClosingElement: JSXClosingElement,
  14396. JSXClosingFragment: JSXClosingFragment,
  14397. JSXElement: JSXElement,
  14398. JSXExpressionContainer: JSXExpressionContainer,
  14399. JSXFragment: JSXFragment,
  14400. JSXOpeningElement: JSXOpeningElement,
  14401. JSXOpeningFragment: JSXOpeningFragment,
  14402. JSXSpreadAttribute: JSXSpreadAttribute,
  14403. Literal: Literal,
  14404. MemberExpression: MemberExpression,
  14405. NewExpression: NewExpression,
  14406. ObjectExpression: ObjectExpression,
  14407. Property: Property,
  14408. ReturnStatement: ReturnStatement,
  14409. SpreadElement: SpreadElement,
  14410. Super: Super,
  14411. TaggedTemplateExpression: TaggedTemplateExpression,
  14412. TemplateElement: TemplateElement,
  14413. TemplateLiteral: TemplateLiteral,
  14414. ThisExpression: ThisExpression,
  14415. UpdateExpression: UpdateExpression,
  14416. VariableDeclaration: VariableDeclaration,
  14417. VariableDeclarator: VariableDeclarator,
  14418. WhileStatement: LoopStatement,
  14419. WithStatement: WithStatement
  14420. };
  14421. var keys = {
  14422. Program: ['body'],
  14423. Literal: []
  14424. };
  14425. var statementsWithBlocks = {
  14426. IfStatement: 'consequent',
  14427. ForStatement: 'body',
  14428. ForInStatement: 'body',
  14429. ForOfStatement: 'body',
  14430. WhileStatement: 'body',
  14431. DoWhileStatement: 'body',
  14432. ArrowFunctionExpression: 'body'
  14433. };
  14434. function wrap(raw, parent) {
  14435. if (!raw) { return; }
  14436. if ('length' in raw) {
  14437. var i = raw.length;
  14438. while (i--) { wrap(raw[i], parent); }
  14439. return;
  14440. }
  14441. // with e.g. shorthand properties, key and value are
  14442. // the same node. We don't want to wrap an object twice
  14443. if (raw.__wrapped) { return; }
  14444. raw.__wrapped = true;
  14445. if (!keys[raw.type]) {
  14446. keys[raw.type] = Object.keys(raw).filter(
  14447. function (key) { return typeof raw[key] === 'object'; }
  14448. );
  14449. }
  14450. // special case – body-less if/for/while statements. TODO others?
  14451. var bodyType = statementsWithBlocks[raw.type];
  14452. if (bodyType && raw[bodyType].type !== 'BlockStatement') {
  14453. var expression = raw[bodyType];
  14454. // create a synthetic block statement, otherwise all hell
  14455. // breaks loose when it comes to block scoping
  14456. raw[bodyType] = {
  14457. start: expression.start,
  14458. end: expression.end,
  14459. type: 'BlockStatement',
  14460. body: [expression],
  14461. synthetic: true
  14462. };
  14463. }
  14464. raw.parent = parent;
  14465. raw.program = parent.program || parent;
  14466. raw.depth = parent.depth + 1;
  14467. raw.keys = keys[raw.type];
  14468. raw.indentation = undefined;
  14469. for (var i$1 = 0, list = keys[raw.type]; i$1 < list.length; i$1 += 1) {
  14470. var key = list[i$1];
  14471. wrap(raw[key], raw);
  14472. }
  14473. raw.program.magicString.addSourcemapLocation(raw.start);
  14474. raw.program.magicString.addSourcemapLocation(raw.end);
  14475. var type =
  14476. (raw.type === 'BlockStatement' ? BlockStatement : types$2[raw.type]) || Node$1;
  14477. raw.__proto__ = type.prototype;
  14478. }
  14479. function Program(source, ast, transforms, options) {
  14480. this.type = 'Root';
  14481. // options
  14482. this.jsx = options.jsx || 'React.createElement';
  14483. this.options = options;
  14484. this.source = source;
  14485. this.magicString = new MagicString$1(source);
  14486. this.ast = ast;
  14487. this.depth = 0;
  14488. wrap((this.body = ast), this);
  14489. this.body.__proto__ = BlockStatement.prototype;
  14490. this.templateLiteralQuasis = Object.create(null);
  14491. for (var i = 0; i < this.body.body.length; ++i) {
  14492. if (!this.body.body[i].directive) {
  14493. this.prependAt = this.body.body[i].start;
  14494. break;
  14495. }
  14496. }
  14497. this.objectWithoutPropertiesHelper = null;
  14498. this.indentExclusionElements = [];
  14499. this.body.initialise(transforms);
  14500. this.indentExclusions = Object.create(null);
  14501. for (var i$2 = 0, list = this.indentExclusionElements; i$2 < list.length; i$2 += 1) {
  14502. var node = list[i$2];
  14503. for (var i$1 = node.start; i$1 < node.end; i$1 += 1) {
  14504. this.indentExclusions[i$1] = true;
  14505. }
  14506. }
  14507. this.body.transpile(this.magicString, transforms);
  14508. }
  14509. Program.prototype = {
  14510. export: function export$1(options) {
  14511. if ( options === void 0 ) options = {};
  14512. return {
  14513. code: this.magicString.toString(),
  14514. map: this.magicString.generateMap({
  14515. file: options.file,
  14516. source: options.source,
  14517. includeContent: options.includeContent !== false
  14518. })
  14519. };
  14520. },
  14521. findNearest: function findNearest() {
  14522. return null;
  14523. },
  14524. findScope: function findScope() {
  14525. return null;
  14526. },
  14527. getObjectWithoutPropertiesHelper: function getObjectWithoutPropertiesHelper(code) {
  14528. if (!this.objectWithoutPropertiesHelper) {
  14529. this.objectWithoutPropertiesHelper = this.body.scope.createIdentifier('objectWithoutProperties');
  14530. code.prependLeft(this.prependAt, "function " + (this.objectWithoutPropertiesHelper) + " (obj, exclude) { " +
  14531. "var target = {}; for (var k in obj) " +
  14532. "if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) " +
  14533. "target[k] = obj[k]; return target; }\n"
  14534. );
  14535. }
  14536. return this.objectWithoutPropertiesHelper;
  14537. }
  14538. };
  14539. var matrix = {
  14540. chrome: {
  14541. 48: 305357,
  14542. 49: 326143,
  14543. 50: 391679,
  14544. 51: 391679,
  14545. 52: 522751,
  14546. 53: 522751,
  14547. 54: 522751,
  14548. 55: 522751,
  14549. 56: 522751,
  14550. 57: 522751,
  14551. 58: 1047039,
  14552. 59: 1047039,
  14553. 60: 1047039,
  14554. 61: 1047039,
  14555. 62: 1047039,
  14556. 63: 1047039
  14557. },
  14558. firefox: {
  14559. 43: 325853,
  14560. 44: 326109,
  14561. 45: 326111,
  14562. 46: 391647,
  14563. 47: 391679,
  14564. 48: 391679,
  14565. 49: 387583,
  14566. 50: 387583,
  14567. 51: 387583,
  14568. 52: 1047039,
  14569. 53: 1047039,
  14570. 54: 1047039,
  14571. 55: 1047039,
  14572. 56: 1047039,
  14573. 57: 1047039,
  14574. 58: 1047039
  14575. },
  14576. safari: {
  14577. 8: 262148,
  14578. 9: 301166,
  14579. 10: 915967,
  14580. '10.1': 1047039,
  14581. 11: 1047039
  14582. },
  14583. ie: {
  14584. 8: 0,
  14585. 9: 262144,
  14586. 10: 262144,
  14587. 11: 262400
  14588. },
  14589. edge: {
  14590. 12: 305485,
  14591. 13: 387535,
  14592. 14: 1042943,
  14593. 15: 1042943,
  14594. 16: 1042943
  14595. },
  14596. node: {
  14597. '0.10': 262144,
  14598. '0.12': 262208,
  14599. 4: 297167,
  14600. 5: 297167,
  14601. 6: 391679,
  14602. 8: 1047039,
  14603. '8.3': 1047039,
  14604. '8.7': 1047039
  14605. }
  14606. };
  14607. var features = [
  14608. 'arrow',
  14609. 'classes',
  14610. 'computedProperty',
  14611. 'conciseMethodProperty',
  14612. 'defaultParameter',
  14613. 'destructuring',
  14614. 'forOf',
  14615. 'generator',
  14616. 'letConst',
  14617. 'moduleExport',
  14618. 'moduleImport',
  14619. 'numericLiteral',
  14620. 'parameterDestructuring',
  14621. 'spreadRest',
  14622. 'stickyRegExp',
  14623. 'templateString',
  14624. 'unicodeRegExp',
  14625. // ES2016
  14626. 'exponentiation',
  14627. // additional transforms, not from
  14628. // https://featuretests.io
  14629. 'reservedProperties',
  14630. 'trailingFunctionCommas'
  14631. ];
  14632. var version$1 = "0.19.3";
  14633. var ref$1 = [inject, acornDynamicImport].reduce(
  14634. function (final, plugin) { return plugin(final); },
  14635. acorn
  14636. );
  14637. var parse$1 = ref$1.parse;
  14638. var dangerousTransforms = ['dangerousTaggedTemplateString', 'dangerousForOf'];
  14639. function target(target) {
  14640. var targets = Object.keys(target);
  14641. var bitmask = targets.length
  14642. ? 1048575
  14643. : 262144;
  14644. Object.keys(target).forEach(function (environment) {
  14645. var versions = matrix[environment];
  14646. if (!versions)
  14647. { throw new Error(
  14648. ("Unknown environment '" + environment + "'. Please raise an issue at https://github.com/Rich-Harris/buble/issues")
  14649. ); }
  14650. var targetVersion = target[environment];
  14651. if (!(targetVersion in versions))
  14652. { throw new Error(
  14653. ("Support data exists for the following versions of " + environment + ": " + (Object.keys(
  14654. versions
  14655. ).join(
  14656. ', '
  14657. )) + ". Please raise an issue at https://github.com/Rich-Harris/buble/issues")
  14658. ); }
  14659. var support = versions[targetVersion];
  14660. bitmask &= support;
  14661. });
  14662. var transforms = Object.create(null);
  14663. features.forEach(function (name, i) {
  14664. transforms[name] = !(bitmask & (1 << i));
  14665. });
  14666. dangerousTransforms.forEach(function (name) {
  14667. transforms[name] = false;
  14668. });
  14669. transforms.stripWith = false;
  14670. transforms.stripWithFunctional = false;
  14671. return transforms;
  14672. }
  14673. function transform ( source, options ) {
  14674. if ( options === void 0 ) options = {};
  14675. var transforms = target( options.target || {} );
  14676. Object.keys( options.transforms || {} ).forEach( function (name) {
  14677. if ( name === 'modules' ) {
  14678. if ( !( 'moduleImport' in options.transforms ) ) { transforms.moduleImport = options.transforms.modules; }
  14679. if ( !( 'moduleExport' in options.transforms ) ) { transforms.moduleExport = options.transforms.modules; }
  14680. return;
  14681. }
  14682. if ( !( name in transforms ) ) { throw new Error( ("Unknown transform '" + name + "'") ); }
  14683. transforms[ name ] = options.transforms[ name ];
  14684. });
  14685. if (transforms.stripWith) {
  14686. // necessary for { key } to be prefixed properly
  14687. // in case the user uses a target environment that supports this
  14688. transforms.conciseMethodProperty = true;
  14689. }
  14690. var ast;
  14691. var jsx = null;
  14692. try {
  14693. ast = parse$1(source, {
  14694. ecmaVersion: 9,
  14695. preserveParens: true,
  14696. sourceType: transforms.stripWith ? 'script' : 'module',
  14697. onComment: function (block, text) {
  14698. if (!jsx) {
  14699. var match = /@jsx\s+([^\s]+)/.exec(text);
  14700. if (match) { jsx = match[1]; }
  14701. }
  14702. },
  14703. plugins: {
  14704. jsx: true,
  14705. dynamicImport: true
  14706. }
  14707. });
  14708. options.jsx = jsx || options.jsx;
  14709. } catch (err) {
  14710. err.snippet = getSnippet(source, err.loc);
  14711. err.toString = function () { return ((err.name) + ": " + (err.message) + "\n" + (err.snippet)); };
  14712. throw err;
  14713. }
  14714. return new Program( source, ast, transforms, options ).export( options );
  14715. }
  14716. exports.target = target;
  14717. exports.transform = transform;
  14718. exports.VERSION = version$1;
  14719. Object.defineProperty(exports, '__esModule', { value: true });
  14720. })));
  14721. //# sourceMappingURL=buble-browser-deps.umd.js.map