UNPKG

443 kBJavaScriptView Raw
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
7// Reserved word lists for various dialects of the language
8
9var reservedWords = {
10 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",
11 5: "class enum extends super const export import",
12 6: "enum",
13 strict: "implements interface let package private protected public static yield",
14 strictBind: "eval arguments"
15};
16
17// And the keywords
18
19var 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";
20
21var keywords = {
22 5: ecma5AndLessKeywords,
23 6: ecma5AndLessKeywords + " const class extends export import super"
24};
25
26var keywordRelationalOperator = /^in(stanceof)?$/;
27
28// ## Character categories
29
30// Big ugly regular expressions that match characters in the
31// whitespace, identifier, and identifier-start categories. These
32// are only applied when a character is found to actually have a
33// code point above 128.
34// Generated by `bin/generate-identifier-regex.js`.
35
36var 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\u0561-\u0587\u05d0-\u05ea\u05f0-\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\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\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-\u1877\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\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-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fd5\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ae\ua7b0-\ua7b7\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\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\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
37var 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\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d4-\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\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\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-\u0c03\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\u0d01-\u0d03\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\u1cf8\u1cf9\u1dc0-\u1df5\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\ua900-\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";
38
39var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
40var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
41
42nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
43
44// These are a run-length and offset encoded representation of the
45// >0xffff code points that are a valid part of identifiers. The
46// offset starts at 0x10000, and each pair of numbers represents an
47// offset to the next range, and then a size of the range. They were
48// generated by bin/generate-identifier-regex.js
49
50// eslint-disable-next-line comma-spacing
51var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,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,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,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,25,391,63,32,0,449,56,264,8,2,36,18,0,50,29,881,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,65,0,32,6124,20,754,9486,1,3071,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,10591,541];
52
53// eslint-disable-next-line comma-spacing
54var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,7,0,161,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,87,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,9,838,7,2,7,17,9,57,21,2,13,19882,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];
55
56// This has a complexity linear to the value of the code. The
57// assumption is that looking up astral identifier characters is
58// rare.
59function isInAstralSet(code, set) {
60 var pos = 0x10000;
61 for (var i = 0; i < set.length; i += 2) {
62 pos += set[i];
63 if (pos > code) { return false }
64 pos += set[i + 1];
65 if (pos >= code) { return true }
66 }
67}
68
69// Test whether a given character code starts an identifier.
70
71function isIdentifierStart(code, astral) {
72 if (code < 65) { return code === 36 }
73 if (code < 91) { return true }
74 if (code < 97) { return code === 95 }
75 if (code < 123) { return true }
76 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
77 if (astral === false) { return false }
78 return isInAstralSet(code, astralIdentifierStartCodes)
79}
80
81// Test whether a given character is part of an identifier.
82
83function isIdentifierChar(code, astral) {
84 if (code < 48) { return code === 36 }
85 if (code < 58) { return true }
86 if (code < 65) { return false }
87 if (code < 91) { return true }
88 if (code < 97) { return code === 95 }
89 if (code < 123) { return true }
90 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
91 if (astral === false) { return false }
92 return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
93}
94
95// ## Token types
96
97// The assignment of fine-grained, information-carrying type objects
98// allows the tokenizer to store the information it has about a
99// token in a way that is very cheap for the parser to look up.
100
101// All token type variables start with an underscore, to make them
102// easy to recognize.
103
104// The `beforeExpr` property is used to disambiguate between regular
105// expressions and divisions. It is set on all token types that can
106// be followed by an expression (thus, a slash after them would be a
107// regular expression).
108//
109// The `startsExpr` property is used to check if the token ends a
110// `yield` expression. It is set on all token types that either can
111// directly start an expression (like a quotation mark) or can
112// continue an expression (like the body of a string).
113//
114// `isLoop` marks a keyword as starting a loop, which is important
115// to know when parsing a label, in order to allow or disallow
116// continue jumps to that label.
117
118var TokenType = function TokenType(label, conf) {
119 if ( conf === void 0 ) conf = {};
120
121 this.label = label;
122 this.keyword = conf.keyword;
123 this.beforeExpr = !!conf.beforeExpr;
124 this.startsExpr = !!conf.startsExpr;
125 this.isLoop = !!conf.isLoop;
126 this.isAssign = !!conf.isAssign;
127 this.prefix = !!conf.prefix;
128 this.postfix = !!conf.postfix;
129 this.binop = conf.binop || null;
130 this.updateContext = null;
131};
132
133function binop(name, prec) {
134 return new TokenType(name, {beforeExpr: true, binop: prec})
135}
136var beforeExpr = {beforeExpr: true};
137var startsExpr = {startsExpr: true};
138
139// Map keyword names to token types.
140
141var keywords$1 = {};
142
143// Succinct definitions of keyword token types
144function kw(name, options) {
145 if ( options === void 0 ) options = {};
146
147 options.keyword = name;
148 return keywords$1[name] = new TokenType(name, options)
149}
150
151var types = {
152 num: new TokenType("num", startsExpr),
153 regexp: new TokenType("regexp", startsExpr),
154 string: new TokenType("string", startsExpr),
155 name: new TokenType("name", startsExpr),
156 eof: new TokenType("eof"),
157
158 // Punctuation token types.
159 bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
160 bracketR: new TokenType("]"),
161 braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
162 braceR: new TokenType("}"),
163 parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
164 parenR: new TokenType(")"),
165 comma: new TokenType(",", beforeExpr),
166 semi: new TokenType(";", beforeExpr),
167 colon: new TokenType(":", beforeExpr),
168 dot: new TokenType("."),
169 question: new TokenType("?", beforeExpr),
170 arrow: new TokenType("=>", beforeExpr),
171 template: new TokenType("template"),
172 invalidTemplate: new TokenType("invalidTemplate"),
173 ellipsis: new TokenType("...", beforeExpr),
174 backQuote: new TokenType("`", startsExpr),
175 dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
176
177 // Operators. These carry several kinds of properties to help the
178 // parser use them properly (the presence of these properties is
179 // what categorizes them as operators).
180 //
181 // `binop`, when present, specifies that this operator is a binary
182 // operator, and will refer to its precedence.
183 //
184 // `prefix` and `postfix` mark the operator as a prefix or postfix
185 // unary operator.
186 //
187 // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
188 // binary operators with a very low precedence, that should result
189 // in AssignmentExpression nodes.
190
191 eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
192 assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
193 incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
194 prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
195 logicalOR: binop("||", 1),
196 logicalAND: binop("&&", 2),
197 bitwiseOR: binop("|", 3),
198 bitwiseXOR: binop("^", 4),
199 bitwiseAND: binop("&", 5),
200 equality: binop("==/!=/===/!==", 6),
201 relational: binop("</>/<=/>=", 7),
202 bitShift: binop("<</>>/>>>", 8),
203 plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
204 modulo: binop("%", 10),
205 star: binop("*", 10),
206 slash: binop("/", 10),
207 starstar: new TokenType("**", {beforeExpr: true}),
208
209 // Keyword token types.
210 _break: kw("break"),
211 _case: kw("case", beforeExpr),
212 _catch: kw("catch"),
213 _continue: kw("continue"),
214 _debugger: kw("debugger"),
215 _default: kw("default", beforeExpr),
216 _do: kw("do", {isLoop: true, beforeExpr: true}),
217 _else: kw("else", beforeExpr),
218 _finally: kw("finally"),
219 _for: kw("for", {isLoop: true}),
220 _function: kw("function", startsExpr),
221 _if: kw("if"),
222 _return: kw("return", beforeExpr),
223 _switch: kw("switch"),
224 _throw: kw("throw", beforeExpr),
225 _try: kw("try"),
226 _var: kw("var"),
227 _const: kw("const"),
228 _while: kw("while", {isLoop: true}),
229 _with: kw("with"),
230 _new: kw("new", {beforeExpr: true, startsExpr: true}),
231 _this: kw("this", startsExpr),
232 _super: kw("super", startsExpr),
233 _class: kw("class", startsExpr),
234 _extends: kw("extends", beforeExpr),
235 _export: kw("export"),
236 _import: kw("import"),
237 _null: kw("null", startsExpr),
238 _true: kw("true", startsExpr),
239 _false: kw("false", startsExpr),
240 _in: kw("in", {beforeExpr: true, binop: 7}),
241 _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
242 _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
243 _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
244 _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
245};
246
247// Matches a whole line break (where CRLF is considered a single
248// line break). Used to count lines.
249
250var lineBreak = /\r\n?|\n|\u2028|\u2029/;
251var lineBreakG = new RegExp(lineBreak.source, "g");
252
253function isNewLine(code) {
254 return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
255}
256
257var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
258
259var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
260
261var ref = Object.prototype;
262var hasOwnProperty = ref.hasOwnProperty;
263var toString = ref.toString;
264
265// Checks if an object has a property.
266
267function has(obj, propName) {
268 return hasOwnProperty.call(obj, propName)
269}
270
271var isArray = Array.isArray || (function (obj) { return (
272 toString.call(obj) === "[object Array]"
273); });
274
275// These are used when `options.locations` is on, for the
276// `startLoc` and `endLoc` properties.
277
278var Position = function Position(line, col) {
279 this.line = line;
280 this.column = col;
281};
282
283Position.prototype.offset = function offset (n) {
284 return new Position(this.line, this.column + n)
285};
286
287var SourceLocation = function SourceLocation(p, start, end) {
288 this.start = start;
289 this.end = end;
290 if (p.sourceFile !== null) { this.source = p.sourceFile; }
291};
292
293// The `getLineInfo` function is mostly useful when the
294// `locations` option is off (for performance reasons) and you
295// want to find the line/column position for a given character
296// offset. `input` should be the code string that the offset refers
297// into.
298
299function getLineInfo(input, offset) {
300 for (var line = 1, cur = 0;;) {
301 lineBreakG.lastIndex = cur;
302 var match = lineBreakG.exec(input);
303 if (match && match.index < offset) {
304 ++line;
305 cur = match.index + match[0].length;
306 } else {
307 return new Position(line, offset - cur)
308 }
309 }
310}
311
312// A second optional argument can be given to further configure
313// the parser process. These options are recognized:
314
315var defaultOptions = {
316 // `ecmaVersion` indicates the ECMAScript version to parse. Must
317 // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
318 // for strict mode, the set of reserved words, and support for
319 // new syntax features. The default is 7.
320 ecmaVersion: 7,
321 // `sourceType` indicates the mode the code should be parsed in.
322 // Can be either `"script"` or `"module"`. This influences global
323 // strict mode and parsing of `import` and `export` declarations.
324 sourceType: "script",
325 // `onInsertedSemicolon` can be a callback that will be called
326 // when a semicolon is automatically inserted. It will be passed
327 // th position of the comma as an offset, and if `locations` is
328 // enabled, it is given the location as a `{line, column}` object
329 // as second argument.
330 onInsertedSemicolon: null,
331 // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
332 // trailing commas.
333 onTrailingComma: null,
334 // By default, reserved words are only enforced if ecmaVersion >= 5.
335 // Set `allowReserved` to a boolean value to explicitly turn this on
336 // an off. When this option has the value "never", reserved words
337 // and keywords can also not be used as property names.
338 allowReserved: null,
339 // When enabled, a return at the top level is not considered an
340 // error.
341 allowReturnOutsideFunction: false,
342 // When enabled, import/export statements are not constrained to
343 // appearing at the top of the program.
344 allowImportExportEverywhere: false,
345 // When enabled, hashbang directive in the beginning of file
346 // is allowed and treated as a line comment.
347 allowHashBang: false,
348 // When `locations` is on, `loc` properties holding objects with
349 // `start` and `end` properties in `{line, column}` form (with
350 // line being 1-based and column 0-based) will be attached to the
351 // nodes.
352 locations: false,
353 // A function can be passed as `onToken` option, which will
354 // cause Acorn to call that function with object in the same
355 // format as tokens returned from `tokenizer().getToken()`. Note
356 // that you are not allowed to call the parser from the
357 // callback—that will corrupt its internal state.
358 onToken: null,
359 // A function can be passed as `onComment` option, which will
360 // cause Acorn to call that function with `(block, text, start,
361 // end)` parameters whenever a comment is skipped. `block` is a
362 // boolean indicating whether this is a block (`/* */`) comment,
363 // `text` is the content of the comment, and `start` and `end` are
364 // character offsets that denote the start and end of the comment.
365 // When the `locations` option is on, two more parameters are
366 // passed, the full `{line, column}` locations of the start and
367 // end of the comments. Note that you are not allowed to call the
368 // parser from the callback—that will corrupt its internal state.
369 onComment: null,
370 // Nodes have their start and end characters offsets recorded in
371 // `start` and `end` properties (directly on the node, rather than
372 // the `loc` object, which holds line/column data. To also add a
373 // [semi-standardized][range] `range` property holding a `[start,
374 // end]` array with the same numbers, set the `ranges` option to
375 // `true`.
376 //
377 // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
378 ranges: false,
379 // It is possible to parse multiple files into a single AST by
380 // passing the tree produced by parsing the first file as
381 // `program` option in subsequent parses. This will add the
382 // toplevel forms of the parsed file to the `Program` (top) node
383 // of an existing parse tree.
384 program: null,
385 // When `locations` is on, you can pass this to record the source
386 // file in every node's `loc` object.
387 sourceFile: null,
388 // This value, if given, is stored in every node, whether
389 // `locations` is on or off.
390 directSourceFile: null,
391 // When enabled, parenthesized expressions are represented by
392 // (non-standard) ParenthesizedExpression nodes
393 preserveParens: false,
394 plugins: {}
395};
396
397// Interpret and default an options object
398
399function getOptions(opts) {
400 var options = {};
401
402 for (var opt in defaultOptions)
403 { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
404
405 if (options.ecmaVersion >= 2015)
406 { options.ecmaVersion -= 2009; }
407
408 if (options.allowReserved == null)
409 { options.allowReserved = options.ecmaVersion < 5; }
410
411 if (isArray(options.onToken)) {
412 var tokens = options.onToken;
413 options.onToken = function (token) { return tokens.push(token); };
414 }
415 if (isArray(options.onComment))
416 { options.onComment = pushComment(options, options.onComment); }
417
418 return options
419}
420
421function pushComment(options, array) {
422 return function(block, text, start, end, startLoc, endLoc) {
423 var comment = {
424 type: block ? "Block" : "Line",
425 value: text,
426 start: start,
427 end: end
428 };
429 if (options.locations)
430 { comment.loc = new SourceLocation(this, startLoc, endLoc); }
431 if (options.ranges)
432 { comment.range = [start, end]; }
433 array.push(comment);
434 }
435}
436
437// Registered plugins
438var plugins = {};
439
440function keywordRegexp(words) {
441 return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
442}
443
444var Parser = function Parser(options, input, startPos) {
445 this.options = options = getOptions(options);
446 this.sourceFile = options.sourceFile;
447 this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
448 var reserved = "";
449 if (!options.allowReserved) {
450 for (var v = options.ecmaVersion;; v--)
451 { if (reserved = reservedWords[v]) { break } }
452 if (options.sourceType == "module") { reserved += " await"; }
453 }
454 this.reservedWords = keywordRegexp(reserved);
455 var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
456 this.reservedWordsStrict = keywordRegexp(reservedStrict);
457 this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
458 this.input = String(input);
459
460 // Used to signal to callers of `readWord1` whether the word
461 // contained any escape sequences. This is needed because words with
462 // escape sequences must not be interpreted as keywords.
463 this.containsEsc = false;
464
465 // Load plugins
466 this.loadPlugins(options.plugins);
467
468 // Set up token state
469
470 // The current position of the tokenizer in the input.
471 if (startPos) {
472 this.pos = startPos;
473 this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
474 this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
475 } else {
476 this.pos = this.lineStart = 0;
477 this.curLine = 1;
478 }
479
480 // Properties of the current token:
481 // Its type
482 this.type = types.eof;
483 // For tokens that include more information than their type, the value
484 this.value = null;
485 // Its start and end offset
486 this.start = this.end = this.pos;
487 // And, if locations are used, the {line, column} object
488 // corresponding to those offsets
489 this.startLoc = this.endLoc = this.curPosition();
490
491 // Position information for the previous token
492 this.lastTokEndLoc = this.lastTokStartLoc = null;
493 this.lastTokStart = this.lastTokEnd = this.pos;
494
495 // The context stack is used to superficially track syntactic
496 // context to predict whether a regular expression is allowed in a
497 // given position.
498 this.context = this.initialContext();
499 this.exprAllowed = true;
500
501 // Figure out if it's a module code.
502 this.inModule = options.sourceType === "module";
503 this.strict = this.inModule || this.strictDirective(this.pos);
504
505 // Used to signify the start of a potential arrow function
506 this.potentialArrowAt = -1;
507
508 // Flags to track whether we are in a function, a generator, an async function.
509 this.inFunction = this.inGenerator = this.inAsync = false;
510 // Positions to delayed-check that yield/await does not exist in default parameters.
511 this.yieldPos = this.awaitPos = 0;
512 // Labels in scope.
513 this.labels = [];
514
515 // If enabled, skip leading hashbang line.
516 if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
517 { this.skipLineComment(2); }
518
519 // Scope tracking for duplicate variable names (see scope.js)
520 this.scopeStack = [];
521 this.enterFunctionScope();
522};
523
524// DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
525Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
526Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
527
528Parser.prototype.extend = function extend (name, f) {
529 this[name] = f(this[name]);
530};
531
532Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
533 var this$1 = this;
534
535 for (var name in pluginConfigs) {
536 var plugin = plugins[name];
537 if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
538 plugin(this$1, pluginConfigs[name]);
539 }
540};
541
542Parser.prototype.parse = function parse () {
543 var node = this.options.program || this.startNode();
544 this.nextToken();
545 return this.parseTopLevel(node)
546};
547
548var pp = Parser.prototype;
549
550// ## Parser utilities
551
552var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
553pp.strictDirective = function(start) {
554 var this$1 = this;
555
556 for (;;) {
557 skipWhiteSpace.lastIndex = start;
558 start += skipWhiteSpace.exec(this$1.input)[0].length;
559 var match = literal.exec(this$1.input.slice(start));
560 if (!match) { return false }
561 if ((match[1] || match[2]) == "use strict") { return true }
562 start += match[0].length;
563 }
564};
565
566// Predicate that tests whether the next token is of the given
567// type, and if yes, consumes it as a side effect.
568
569pp.eat = function(type) {
570 if (this.type === type) {
571 this.next();
572 return true
573 } else {
574 return false
575 }
576};
577
578// Tests whether parsed token is a contextual keyword.
579
580pp.isContextual = function(name) {
581 return this.type === types.name && this.value === name && !this.containsEsc
582};
583
584// Consumes contextual keyword if possible.
585
586pp.eatContextual = function(name) {
587 if (!this.isContextual(name)) { return false }
588 this.next();
589 return true
590};
591
592// Asserts that following token is given contextual keyword.
593
594pp.expectContextual = function(name) {
595 if (!this.eatContextual(name)) { this.unexpected(); }
596};
597
598// Test whether a semicolon can be inserted at the current position.
599
600pp.canInsertSemicolon = function() {
601 return this.type === types.eof ||
602 this.type === types.braceR ||
603 lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
604};
605
606pp.insertSemicolon = function() {
607 if (this.canInsertSemicolon()) {
608 if (this.options.onInsertedSemicolon)
609 { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
610 return true
611 }
612};
613
614// Consume a semicolon, or, failing that, see if we are allowed to
615// pretend that there is a semicolon at this position.
616
617pp.semicolon = function() {
618 if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
619};
620
621pp.afterTrailingComma = function(tokType, notNext) {
622 if (this.type == tokType) {
623 if (this.options.onTrailingComma)
624 { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
625 if (!notNext)
626 { this.next(); }
627 return true
628 }
629};
630
631// Expect a token of a given type. If found, consume it, otherwise,
632// raise an unexpected token error.
633
634pp.expect = function(type) {
635 this.eat(type) || this.unexpected();
636};
637
638// Raise an unexpected token error.
639
640pp.unexpected = function(pos) {
641 this.raise(pos != null ? pos : this.start, "Unexpected token");
642};
643
644function DestructuringErrors() {
645 this.shorthandAssign =
646 this.trailingComma =
647 this.parenthesizedAssign =
648 this.parenthesizedBind =
649 this.doubleProto =
650 -1;
651}
652
653pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
654 if (!refDestructuringErrors) { return }
655 if (refDestructuringErrors.trailingComma > -1)
656 { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
657 var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
658 if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
659};
660
661pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
662 if (!refDestructuringErrors) { return false }
663 var shorthandAssign = refDestructuringErrors.shorthandAssign;
664 var doubleProto = refDestructuringErrors.doubleProto;
665 if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
666 if (shorthandAssign >= 0)
667 { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
668 if (doubleProto >= 0)
669 { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
670};
671
672pp.checkYieldAwaitInDefaultParams = function() {
673 if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
674 { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
675 if (this.awaitPos)
676 { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
677};
678
679pp.isSimpleAssignTarget = function(expr) {
680 if (expr.type === "ParenthesizedExpression")
681 { return this.isSimpleAssignTarget(expr.expression) }
682 return expr.type === "Identifier" || expr.type === "MemberExpression"
683};
684
685var pp$1 = Parser.prototype;
686
687// ### Statement parsing
688
689// Parse a program. Initializes the parser, reads any number of
690// statements, and wraps them in a Program node. Optionally takes a
691// `program` argument. If present, the statements will be appended
692// to its body instead of creating a new node.
693
694pp$1.parseTopLevel = function(node) {
695 var this$1 = this;
696
697 var exports = {};
698 if (!node.body) { node.body = []; }
699 while (this.type !== types.eof) {
700 var stmt = this$1.parseStatement(true, true, exports);
701 node.body.push(stmt);
702 }
703 this.adaptDirectivePrologue(node.body);
704 this.next();
705 if (this.options.ecmaVersion >= 6) {
706 node.sourceType = this.options.sourceType;
707 }
708 return this.finishNode(node, "Program")
709};
710
711var loopLabel = {kind: "loop"};
712var switchLabel = {kind: "switch"};
713
714pp$1.isLet = function() {
715 if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
716 skipWhiteSpace.lastIndex = this.pos;
717 var skip = skipWhiteSpace.exec(this.input);
718 var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
719 if (nextCh === 91 || nextCh == 123) { return true } // '{' and '['
720 if (isIdentifierStart(nextCh, true)) {
721 var pos = next + 1;
722 while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
723 var ident = this.input.slice(next, pos);
724 if (!keywordRelationalOperator.test(ident)) { return true }
725 }
726 return false
727};
728
729// check 'async [no LineTerminator here] function'
730// - 'async /*foo*/ function' is OK.
731// - 'async /*\n*/ function' is invalid.
732pp$1.isAsyncFunction = function() {
733 if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
734 { return false }
735
736 skipWhiteSpace.lastIndex = this.pos;
737 var skip = skipWhiteSpace.exec(this.input);
738 var next = this.pos + skip[0].length;
739 return !lineBreak.test(this.input.slice(this.pos, next)) &&
740 this.input.slice(next, next + 8) === "function" &&
741 (next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
742};
743
744// Parse a single statement.
745//
746// If expecting a statement and finding a slash operator, parse a
747// regular expression literal. This is to handle cases like
748// `if (foo) /blah/.exec(foo)`, where looking at the previous token
749// does not help.
750
751pp$1.parseStatement = function(declaration, topLevel, exports) {
752 var starttype = this.type, node = this.startNode(), kind;
753
754 if (this.isLet()) {
755 starttype = types._var;
756 kind = "let";
757 }
758
759 // Most types of statements are recognized by the keyword they
760 // start with. Many are trivial to parse, some require a bit of
761 // complexity.
762
763 switch (starttype) {
764 case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
765 case types._debugger: return this.parseDebuggerStatement(node)
766 case types._do: return this.parseDoStatement(node)
767 case types._for: return this.parseForStatement(node)
768 case types._function:
769 if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
770 return this.parseFunctionStatement(node, false)
771 case types._class:
772 if (!declaration) { this.unexpected(); }
773 return this.parseClass(node, true)
774 case types._if: return this.parseIfStatement(node)
775 case types._return: return this.parseReturnStatement(node)
776 case types._switch: return this.parseSwitchStatement(node)
777 case types._throw: return this.parseThrowStatement(node)
778 case types._try: return this.parseTryStatement(node)
779 case types._const: case types._var:
780 kind = kind || this.value;
781 if (!declaration && kind != "var") { this.unexpected(); }
782 return this.parseVarStatement(node, kind)
783 case types._while: return this.parseWhileStatement(node)
784 case types._with: return this.parseWithStatement(node)
785 case types.braceL: return this.parseBlock()
786 case types.semi: return this.parseEmptyStatement(node)
787 case types._export:
788 case types._import:
789 if (!this.options.allowImportExportEverywhere) {
790 if (!topLevel)
791 { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
792 if (!this.inModule)
793 { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
794 }
795 return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
796
797 // If the statement does not start with a statement keyword or a
798 // brace, it's an ExpressionStatement or LabeledStatement. We
799 // simply start parsing an expression, and afterwards, if the
800 // next token is a colon and the expression was a simple
801 // Identifier node, we switch to interpreting it as a label.
802 default:
803 if (this.isAsyncFunction()) {
804 if (!declaration) { this.unexpected(); }
805 this.next();
806 return this.parseFunctionStatement(node, true)
807 }
808
809 var maybeName = this.value, expr = this.parseExpression();
810 if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
811 { return this.parseLabeledStatement(node, maybeName, expr) }
812 else { return this.parseExpressionStatement(node, expr) }
813 }
814};
815
816pp$1.parseBreakContinueStatement = function(node, keyword) {
817 var this$1 = this;
818
819 var isBreak = keyword == "break";
820 this.next();
821 if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
822 else if (this.type !== types.name) { this.unexpected(); }
823 else {
824 node.label = this.parseIdent();
825 this.semicolon();
826 }
827
828 // Verify that there is an actual destination to break or
829 // continue to.
830 var i = 0;
831 for (; i < this.labels.length; ++i) {
832 var lab = this$1.labels[i];
833 if (node.label == null || lab.name === node.label.name) {
834 if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
835 if (node.label && isBreak) { break }
836 }
837 }
838 if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
839 return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
840};
841
842pp$1.parseDebuggerStatement = function(node) {
843 this.next();
844 this.semicolon();
845 return this.finishNode(node, "DebuggerStatement")
846};
847
848pp$1.parseDoStatement = function(node) {
849 this.next();
850 this.labels.push(loopLabel);
851 node.body = this.parseStatement(false);
852 this.labels.pop();
853 this.expect(types._while);
854 node.test = this.parseParenExpression();
855 if (this.options.ecmaVersion >= 6)
856 { this.eat(types.semi); }
857 else
858 { this.semicolon(); }
859 return this.finishNode(node, "DoWhileStatement")
860};
861
862// Disambiguating between a `for` and a `for`/`in` or `for`/`of`
863// loop is non-trivial. Basically, we have to parse the init `var`
864// statement or expression, disallowing the `in` operator (see
865// the second parameter to `parseExpression`), and then check
866// whether the next token is `in` or `of`. When there is no init
867// part (semicolon immediately after the opening parenthesis), it
868// is a regular `for` loop.
869
870pp$1.parseForStatement = function(node) {
871 this.next();
872 var awaitAt = (this.options.ecmaVersion >= 9 && this.inAsync && this.eatContextual("await")) ? this.lastTokStart : -1;
873 this.labels.push(loopLabel);
874 this.enterLexicalScope();
875 this.expect(types.parenL);
876 if (this.type === types.semi) {
877 if (awaitAt > -1) { this.unexpected(awaitAt); }
878 return this.parseFor(node, null)
879 }
880 var isLet = this.isLet();
881 if (this.type === types._var || this.type === types._const || isLet) {
882 var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
883 this.next();
884 this.parseVar(init$1, true, kind);
885 this.finishNode(init$1, "VariableDeclaration");
886 if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
887 !(kind !== "var" && init$1.declarations[0].init)) {
888 if (this.options.ecmaVersion >= 9) {
889 if (this.type === types._in) {
890 if (awaitAt > -1) { this.unexpected(awaitAt); }
891 } else { node.await = awaitAt > -1; }
892 }
893 return this.parseForIn(node, init$1)
894 }
895 if (awaitAt > -1) { this.unexpected(awaitAt); }
896 return this.parseFor(node, init$1)
897 }
898 var refDestructuringErrors = new DestructuringErrors;
899 var init = this.parseExpression(true, refDestructuringErrors);
900 if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
901 if (this.options.ecmaVersion >= 9) {
902 if (this.type === types._in) {
903 if (awaitAt > -1) { this.unexpected(awaitAt); }
904 } else { node.await = awaitAt > -1; }
905 }
906 this.toAssignable(init, false, refDestructuringErrors);
907 this.checkLVal(init);
908 return this.parseForIn(node, init)
909 } else {
910 this.checkExpressionErrors(refDestructuringErrors, true);
911 }
912 if (awaitAt > -1) { this.unexpected(awaitAt); }
913 return this.parseFor(node, init)
914};
915
916pp$1.parseFunctionStatement = function(node, isAsync) {
917 this.next();
918 return this.parseFunction(node, true, false, isAsync)
919};
920
921pp$1.parseIfStatement = function(node) {
922 this.next();
923 node.test = this.parseParenExpression();
924 // allow function declarations in branches, but only in non-strict mode
925 node.consequent = this.parseStatement(!this.strict && this.type == types._function);
926 node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.type == types._function) : null;
927 return this.finishNode(node, "IfStatement")
928};
929
930pp$1.parseReturnStatement = function(node) {
931 if (!this.inFunction && !this.options.allowReturnOutsideFunction)
932 { this.raise(this.start, "'return' outside of function"); }
933 this.next();
934
935 // In `return` (and `break`/`continue`), the keywords with
936 // optional arguments, we eagerly look for a semicolon or the
937 // possibility to insert one.
938
939 if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
940 else { node.argument = this.parseExpression(); this.semicolon(); }
941 return this.finishNode(node, "ReturnStatement")
942};
943
944pp$1.parseSwitchStatement = function(node) {
945 var this$1 = this;
946
947 this.next();
948 node.discriminant = this.parseParenExpression();
949 node.cases = [];
950 this.expect(types.braceL);
951 this.labels.push(switchLabel);
952 this.enterLexicalScope();
953
954 // Statements under must be grouped (by label) in SwitchCase
955 // nodes. `cur` is used to keep the node that we are currently
956 // adding statements to.
957
958 var cur;
959 for (var sawDefault = false; this.type != types.braceR;) {
960 if (this$1.type === types._case || this$1.type === types._default) {
961 var isCase = this$1.type === types._case;
962 if (cur) { this$1.finishNode(cur, "SwitchCase"); }
963 node.cases.push(cur = this$1.startNode());
964 cur.consequent = [];
965 this$1.next();
966 if (isCase) {
967 cur.test = this$1.parseExpression();
968 } else {
969 if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
970 sawDefault = true;
971 cur.test = null;
972 }
973 this$1.expect(types.colon);
974 } else {
975 if (!cur) { this$1.unexpected(); }
976 cur.consequent.push(this$1.parseStatement(true));
977 }
978 }
979 this.exitLexicalScope();
980 if (cur) { this.finishNode(cur, "SwitchCase"); }
981 this.next(); // Closing brace
982 this.labels.pop();
983 return this.finishNode(node, "SwitchStatement")
984};
985
986pp$1.parseThrowStatement = function(node) {
987 this.next();
988 if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
989 { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
990 node.argument = this.parseExpression();
991 this.semicolon();
992 return this.finishNode(node, "ThrowStatement")
993};
994
995// Reused empty array added for node fields that are always empty.
996
997var empty = [];
998
999pp$1.parseTryStatement = function(node) {
1000 this.next();
1001 node.block = this.parseBlock();
1002 node.handler = null;
1003 if (this.type === types._catch) {
1004 var clause = this.startNode();
1005 this.next();
1006 this.expect(types.parenL);
1007 clause.param = this.parseBindingAtom();
1008 this.enterLexicalScope();
1009 this.checkLVal(clause.param, "let");
1010 this.expect(types.parenR);
1011 clause.body = this.parseBlock(false);
1012 this.exitLexicalScope();
1013 node.handler = this.finishNode(clause, "CatchClause");
1014 }
1015 node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
1016 if (!node.handler && !node.finalizer)
1017 { this.raise(node.start, "Missing catch or finally clause"); }
1018 return this.finishNode(node, "TryStatement")
1019};
1020
1021pp$1.parseVarStatement = function(node, kind) {
1022 this.next();
1023 this.parseVar(node, false, kind);
1024 this.semicolon();
1025 return this.finishNode(node, "VariableDeclaration")
1026};
1027
1028pp$1.parseWhileStatement = function(node) {
1029 this.next();
1030 node.test = this.parseParenExpression();
1031 this.labels.push(loopLabel);
1032 node.body = this.parseStatement(false);
1033 this.labels.pop();
1034 return this.finishNode(node, "WhileStatement")
1035};
1036
1037pp$1.parseWithStatement = function(node) {
1038 if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
1039 this.next();
1040 node.object = this.parseParenExpression();
1041 node.body = this.parseStatement(false);
1042 return this.finishNode(node, "WithStatement")
1043};
1044
1045pp$1.parseEmptyStatement = function(node) {
1046 this.next();
1047 return this.finishNode(node, "EmptyStatement")
1048};
1049
1050pp$1.parseLabeledStatement = function(node, maybeName, expr) {
1051 var this$1 = this;
1052
1053 for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
1054 {
1055 var label = list[i$1];
1056
1057 if (label.name === maybeName)
1058 { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
1059 } }
1060 var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
1061 for (var i = this.labels.length - 1; i >= 0; i--) {
1062 var label$1 = this$1.labels[i];
1063 if (label$1.statementStart == node.start) {
1064 // Update information about previous labels on this node
1065 label$1.statementStart = this$1.start;
1066 label$1.kind = kind;
1067 } else { break }
1068 }
1069 this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
1070 node.body = this.parseStatement(true);
1071 if (node.body.type == "ClassDeclaration" ||
1072 node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
1073 node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator))
1074 { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
1075 this.labels.pop();
1076 node.label = expr;
1077 return this.finishNode(node, "LabeledStatement")
1078};
1079
1080pp$1.parseExpressionStatement = function(node, expr) {
1081 node.expression = expr;
1082 this.semicolon();
1083 return this.finishNode(node, "ExpressionStatement")
1084};
1085
1086// Parse a semicolon-enclosed block of statements, handling `"use
1087// strict"` declarations when `allowStrict` is true (used for
1088// function bodies).
1089
1090pp$1.parseBlock = function(createNewLexicalScope) {
1091 var this$1 = this;
1092 if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
1093
1094 var node = this.startNode();
1095 node.body = [];
1096 this.expect(types.braceL);
1097 if (createNewLexicalScope) {
1098 this.enterLexicalScope();
1099 }
1100 while (!this.eat(types.braceR)) {
1101 var stmt = this$1.parseStatement(true);
1102 node.body.push(stmt);
1103 }
1104 if (createNewLexicalScope) {
1105 this.exitLexicalScope();
1106 }
1107 return this.finishNode(node, "BlockStatement")
1108};
1109
1110// Parse a regular `for` loop. The disambiguation code in
1111// `parseStatement` will already have parsed the init statement or
1112// expression.
1113
1114pp$1.parseFor = function(node, init) {
1115 node.init = init;
1116 this.expect(types.semi);
1117 node.test = this.type === types.semi ? null : this.parseExpression();
1118 this.expect(types.semi);
1119 node.update = this.type === types.parenR ? null : this.parseExpression();
1120 this.expect(types.parenR);
1121 this.exitLexicalScope();
1122 node.body = this.parseStatement(false);
1123 this.labels.pop();
1124 return this.finishNode(node, "ForStatement")
1125};
1126
1127// Parse a `for`/`in` and `for`/`of` loop, which are almost
1128// same from parser's perspective.
1129
1130pp$1.parseForIn = function(node, init) {
1131 var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
1132 this.next();
1133 if (type == "ForInStatement") {
1134 if (init.type === "AssignmentPattern" ||
1135 (init.type === "VariableDeclaration" && init.declarations[0].init != null &&
1136 (this.strict || init.declarations[0].id.type !== "Identifier")))
1137 { this.raise(init.start, "Invalid assignment in for-in loop head"); }
1138 }
1139 node.left = init;
1140 node.right = type == "ForInStatement" ? this.parseExpression() : this.parseMaybeAssign();
1141 this.expect(types.parenR);
1142 this.exitLexicalScope();
1143 node.body = this.parseStatement(false);
1144 this.labels.pop();
1145 return this.finishNode(node, type)
1146};
1147
1148// Parse a list of variable declarations.
1149
1150pp$1.parseVar = function(node, isFor, kind) {
1151 var this$1 = this;
1152
1153 node.declarations = [];
1154 node.kind = kind;
1155 for (;;) {
1156 var decl = this$1.startNode();
1157 this$1.parseVarId(decl, kind);
1158 if (this$1.eat(types.eq)) {
1159 decl.init = this$1.parseMaybeAssign(isFor);
1160 } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
1161 this$1.unexpected();
1162 } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
1163 this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
1164 } else {
1165 decl.init = null;
1166 }
1167 node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
1168 if (!this$1.eat(types.comma)) { break }
1169 }
1170 return node
1171};
1172
1173pp$1.parseVarId = function(decl, kind) {
1174 decl.id = this.parseBindingAtom(kind);
1175 this.checkLVal(decl.id, kind, false);
1176};
1177
1178// Parse a function declaration or literal (depending on the
1179// `isStatement` parameter).
1180
1181pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
1182 this.initFunction(node);
1183 if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync)
1184 { node.generator = this.eat(types.star); }
1185 if (this.options.ecmaVersion >= 8)
1186 { node.async = !!isAsync; }
1187
1188 if (isStatement) {
1189 node.id = isStatement === "nullableID" && this.type != types.name ? null : this.parseIdent();
1190 if (node.id) {
1191 this.checkLVal(node.id, "var");
1192 }
1193 }
1194
1195 var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
1196 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
1197 this.inGenerator = node.generator;
1198 this.inAsync = node.async;
1199 this.yieldPos = 0;
1200 this.awaitPos = 0;
1201 this.inFunction = true;
1202 this.enterFunctionScope();
1203
1204 if (!isStatement)
1205 { node.id = this.type == types.name ? this.parseIdent() : null; }
1206
1207 this.parseFunctionParams(node);
1208 this.parseFunctionBody(node, allowExpressionBody);
1209
1210 this.inGenerator = oldInGen;
1211 this.inAsync = oldInAsync;
1212 this.yieldPos = oldYieldPos;
1213 this.awaitPos = oldAwaitPos;
1214 this.inFunction = oldInFunc;
1215 return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
1216};
1217
1218pp$1.parseFunctionParams = function(node) {
1219 this.expect(types.parenL);
1220 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
1221 this.checkYieldAwaitInDefaultParams();
1222};
1223
1224// Parse a class declaration or literal (depending on the
1225// `isStatement` parameter).
1226
1227pp$1.parseClass = function(node, isStatement) {
1228 var this$1 = this;
1229
1230 this.next();
1231
1232 this.parseClassId(node, isStatement);
1233 this.parseClassSuper(node);
1234 var classBody = this.startNode();
1235 var hadConstructor = false;
1236 classBody.body = [];
1237 this.expect(types.braceL);
1238 while (!this.eat(types.braceR)) {
1239 var member = this$1.parseClassMember(classBody);
1240 if (member && member.type === "MethodDefinition" && member.kind === "constructor") {
1241 if (hadConstructor) { this$1.raise(member.start, "Duplicate constructor in the same class"); }
1242 hadConstructor = true;
1243 }
1244 }
1245 node.body = this.finishNode(classBody, "ClassBody");
1246 return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
1247};
1248
1249pp$1.parseClassMember = function(classBody) {
1250 var this$1 = this;
1251
1252 if (this.eat(types.semi)) { return null }
1253
1254 var method = this.startNode();
1255 var tryContextual = function (k, noLineBreak) {
1256 if ( noLineBreak === void 0 ) noLineBreak = false;
1257
1258 var start = this$1.start, startLoc = this$1.startLoc;
1259 if (!this$1.eatContextual(k)) { return false }
1260 if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
1261 if (method.key) { this$1.unexpected(); }
1262 method.computed = false;
1263 method.key = this$1.startNodeAt(start, startLoc);
1264 method.key.name = k;
1265 this$1.finishNode(method.key, "Identifier");
1266 return false
1267 };
1268
1269 method.kind = "method";
1270 method.static = tryContextual("static");
1271 var isGenerator = this.eat(types.star);
1272 var isAsync = false;
1273 if (!isGenerator) {
1274 if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
1275 isAsync = true;
1276 isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
1277 } else if (tryContextual("get")) {
1278 method.kind = "get";
1279 } else if (tryContextual("set")) {
1280 method.kind = "set";
1281 }
1282 }
1283 if (!method.key) { this.parsePropertyName(method); }
1284 var key = method.key;
1285 if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
1286 key.type === "Literal" && key.value === "constructor")) {
1287 if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
1288 if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
1289 if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
1290 method.kind = "constructor";
1291 } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
1292 this.raise(key.start, "Classes may not have a static property named prototype");
1293 }
1294 this.parseClassMethod(classBody, method, isGenerator, isAsync);
1295 if (method.kind === "get" && method.value.params.length !== 0)
1296 { this.raiseRecoverable(method.value.start, "getter should have no params"); }
1297 if (method.kind === "set" && method.value.params.length !== 1)
1298 { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
1299 if (method.kind === "set" && method.value.params[0].type === "RestElement")
1300 { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
1301 return method
1302};
1303
1304pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
1305 method.value = this.parseMethod(isGenerator, isAsync);
1306 classBody.body.push(this.finishNode(method, "MethodDefinition"));
1307};
1308
1309pp$1.parseClassId = function(node, isStatement) {
1310 node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
1311};
1312
1313pp$1.parseClassSuper = function(node) {
1314 node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
1315};
1316
1317// Parses module export declaration.
1318
1319pp$1.parseExport = function(node, exports) {
1320 var this$1 = this;
1321
1322 this.next();
1323 // export * from '...'
1324 if (this.eat(types.star)) {
1325 this.expectContextual("from");
1326 if (this.type !== types.string) { this.unexpected(); }
1327 node.source = this.parseExprAtom();
1328 this.semicolon();
1329 return this.finishNode(node, "ExportAllDeclaration")
1330 }
1331 if (this.eat(types._default)) { // export default ...
1332 this.checkExport(exports, "default", this.lastTokStart);
1333 var isAsync;
1334 if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
1335 var fNode = this.startNode();
1336 this.next();
1337 if (isAsync) { this.next(); }
1338 node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
1339 } else if (this.type === types._class) {
1340 var cNode = this.startNode();
1341 node.declaration = this.parseClass(cNode, "nullableID");
1342 } else {
1343 node.declaration = this.parseMaybeAssign();
1344 this.semicolon();
1345 }
1346 return this.finishNode(node, "ExportDefaultDeclaration")
1347 }
1348 // export var|const|let|function|class ...
1349 if (this.shouldParseExportStatement()) {
1350 node.declaration = this.parseStatement(true);
1351 if (node.declaration.type === "VariableDeclaration")
1352 { this.checkVariableExport(exports, node.declaration.declarations); }
1353 else
1354 { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
1355 node.specifiers = [];
1356 node.source = null;
1357 } else { // export { x, y as z } [from '...']
1358 node.declaration = null;
1359 node.specifiers = this.parseExportSpecifiers(exports);
1360 if (this.eatContextual("from")) {
1361 if (this.type !== types.string) { this.unexpected(); }
1362 node.source = this.parseExprAtom();
1363 } else {
1364 // check for keywords used as local names
1365 for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
1366 var spec = list[i];
1367
1368 this$1.checkUnreserved(spec.local);
1369 }
1370
1371 node.source = null;
1372 }
1373 this.semicolon();
1374 }
1375 return this.finishNode(node, "ExportNamedDeclaration")
1376};
1377
1378pp$1.checkExport = function(exports, name, pos) {
1379 if (!exports) { return }
1380 if (has(exports, name))
1381 { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
1382 exports[name] = true;
1383};
1384
1385pp$1.checkPatternExport = function(exports, pat) {
1386 var this$1 = this;
1387
1388 var type = pat.type;
1389 if (type == "Identifier")
1390 { this.checkExport(exports, pat.name, pat.start); }
1391 else if (type == "ObjectPattern")
1392 { for (var i = 0, list = pat.properties; i < list.length; i += 1)
1393 {
1394 var prop = list[i];
1395
1396 this$1.checkPatternExport(exports, prop);
1397 } }
1398 else if (type == "ArrayPattern")
1399 { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
1400 var elt = list$1[i$1];
1401
1402 if (elt) { this$1.checkPatternExport(exports, elt); }
1403 } }
1404 else if (type == "Property")
1405 { this.checkPatternExport(exports, pat.value); }
1406 else if (type == "AssignmentPattern")
1407 { this.checkPatternExport(exports, pat.left); }
1408 else if (type == "RestElement")
1409 { this.checkPatternExport(exports, pat.argument); }
1410 else if (type == "ParenthesizedExpression")
1411 { this.checkPatternExport(exports, pat.expression); }
1412};
1413
1414pp$1.checkVariableExport = function(exports, decls) {
1415 var this$1 = this;
1416
1417 if (!exports) { return }
1418 for (var i = 0, list = decls; i < list.length; i += 1)
1419 {
1420 var decl = list[i];
1421
1422 this$1.checkPatternExport(exports, decl.id);
1423 }
1424};
1425
1426pp$1.shouldParseExportStatement = function() {
1427 return this.type.keyword === "var" ||
1428 this.type.keyword === "const" ||
1429 this.type.keyword === "class" ||
1430 this.type.keyword === "function" ||
1431 this.isLet() ||
1432 this.isAsyncFunction()
1433};
1434
1435// Parses a comma-separated list of module exports.
1436
1437pp$1.parseExportSpecifiers = function(exports) {
1438 var this$1 = this;
1439
1440 var nodes = [], first = true;
1441 // export { x, y as z } [from '...']
1442 this.expect(types.braceL);
1443 while (!this.eat(types.braceR)) {
1444 if (!first) {
1445 this$1.expect(types.comma);
1446 if (this$1.afterTrailingComma(types.braceR)) { break }
1447 } else { first = false; }
1448
1449 var node = this$1.startNode();
1450 node.local = this$1.parseIdent(true);
1451 node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
1452 this$1.checkExport(exports, node.exported.name, node.exported.start);
1453 nodes.push(this$1.finishNode(node, "ExportSpecifier"));
1454 }
1455 return nodes
1456};
1457
1458// Parses import declaration.
1459
1460pp$1.parseImport = function(node) {
1461 this.next();
1462 // import '...'
1463 if (this.type === types.string) {
1464 node.specifiers = empty;
1465 node.source = this.parseExprAtom();
1466 } else {
1467 node.specifiers = this.parseImportSpecifiers();
1468 this.expectContextual("from");
1469 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1470 }
1471 this.semicolon();
1472 return this.finishNode(node, "ImportDeclaration")
1473};
1474
1475// Parses a comma-separated list of module imports.
1476
1477pp$1.parseImportSpecifiers = function() {
1478 var this$1 = this;
1479
1480 var nodes = [], first = true;
1481 if (this.type === types.name) {
1482 // import defaultObj, { x, y as z } from '...'
1483 var node = this.startNode();
1484 node.local = this.parseIdent();
1485 this.checkLVal(node.local, "let");
1486 nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
1487 if (!this.eat(types.comma)) { return nodes }
1488 }
1489 if (this.type === types.star) {
1490 var node$1 = this.startNode();
1491 this.next();
1492 this.expectContextual("as");
1493 node$1.local = this.parseIdent();
1494 this.checkLVal(node$1.local, "let");
1495 nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
1496 return nodes
1497 }
1498 this.expect(types.braceL);
1499 while (!this.eat(types.braceR)) {
1500 if (!first) {
1501 this$1.expect(types.comma);
1502 if (this$1.afterTrailingComma(types.braceR)) { break }
1503 } else { first = false; }
1504
1505 var node$2 = this$1.startNode();
1506 node$2.imported = this$1.parseIdent(true);
1507 if (this$1.eatContextual("as")) {
1508 node$2.local = this$1.parseIdent();
1509 } else {
1510 this$1.checkUnreserved(node$2.imported);
1511 node$2.local = node$2.imported;
1512 }
1513 this$1.checkLVal(node$2.local, "let");
1514 nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
1515 }
1516 return nodes
1517};
1518
1519// Set `ExpressionStatement#directive` property for directive prologues.
1520pp$1.adaptDirectivePrologue = function(statements) {
1521 for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
1522 statements[i].directive = statements[i].expression.raw.slice(1, -1);
1523 }
1524};
1525pp$1.isDirectiveCandidate = function(statement) {
1526 return (
1527 statement.type === "ExpressionStatement" &&
1528 statement.expression.type === "Literal" &&
1529 typeof statement.expression.value === "string" &&
1530 // Reject parenthesized strings.
1531 (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
1532 )
1533};
1534
1535var pp$2 = Parser.prototype;
1536
1537// Convert existing expression atom to assignable pattern
1538// if possible.
1539
1540pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
1541 var this$1 = this;
1542
1543 if (this.options.ecmaVersion >= 6 && node) {
1544 switch (node.type) {
1545 case "Identifier":
1546 if (this.inAsync && node.name === "await")
1547 { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
1548 break
1549
1550 case "ObjectPattern":
1551 case "ArrayPattern":
1552 case "RestElement":
1553 break
1554
1555 case "ObjectExpression":
1556 node.type = "ObjectPattern";
1557 if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1558 for (var i = 0, list = node.properties; i < list.length; i += 1) {
1559 var prop = list[i];
1560
1561 this$1.toAssignable(prop, isBinding);
1562 // Early error:
1563 // AssignmentRestProperty[Yield, Await] :
1564 // `...` DestructuringAssignmentTarget[Yield, Await]
1565 //
1566 // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
1567 if (
1568 prop.type === "RestElement" &&
1569 (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
1570 ) {
1571 this$1.raise(prop.argument.start, "Unexpected token");
1572 }
1573 }
1574 break
1575
1576 case "Property":
1577 // AssignmentProperty has type == "Property"
1578 if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
1579 this.toAssignable(node.value, isBinding);
1580 break
1581
1582 case "ArrayExpression":
1583 node.type = "ArrayPattern";
1584 if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1585 this.toAssignableList(node.elements, isBinding);
1586 break
1587
1588 case "SpreadElement":
1589 node.type = "RestElement";
1590 this.toAssignable(node.argument, isBinding);
1591 if (node.argument.type === "AssignmentPattern")
1592 { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
1593 break
1594
1595 case "AssignmentExpression":
1596 if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
1597 node.type = "AssignmentPattern";
1598 delete node.operator;
1599 this.toAssignable(node.left, isBinding);
1600 // falls through to AssignmentPattern
1601
1602 case "AssignmentPattern":
1603 break
1604
1605 case "ParenthesizedExpression":
1606 this.toAssignable(node.expression, isBinding);
1607 break
1608
1609 case "MemberExpression":
1610 if (!isBinding) { break }
1611
1612 default:
1613 this.raise(node.start, "Assigning to rvalue");
1614 }
1615 } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1616 return node
1617};
1618
1619// Convert list of expression atoms to binding list.
1620
1621pp$2.toAssignableList = function(exprList, isBinding) {
1622 var this$1 = this;
1623
1624 var end = exprList.length;
1625 for (var i = 0; i < end; i++) {
1626 var elt = exprList[i];
1627 if (elt) { this$1.toAssignable(elt, isBinding); }
1628 }
1629 if (end) {
1630 var last = exprList[end - 1];
1631 if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
1632 { this.unexpected(last.argument.start); }
1633 }
1634 return exprList
1635};
1636
1637// Parses spread element.
1638
1639pp$2.parseSpread = function(refDestructuringErrors) {
1640 var node = this.startNode();
1641 this.next();
1642 node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
1643 return this.finishNode(node, "SpreadElement")
1644};
1645
1646pp$2.parseRestBinding = function() {
1647 var node = this.startNode();
1648 this.next();
1649
1650 // RestElement inside of a function parameter must be an identifier
1651 if (this.options.ecmaVersion === 6 && this.type !== types.name)
1652 { this.unexpected(); }
1653
1654 node.argument = this.parseBindingAtom();
1655
1656 return this.finishNode(node, "RestElement")
1657};
1658
1659// Parses lvalue (assignable) atom.
1660
1661pp$2.parseBindingAtom = function() {
1662 if (this.options.ecmaVersion >= 6) {
1663 switch (this.type) {
1664 case types.bracketL:
1665 var node = this.startNode();
1666 this.next();
1667 node.elements = this.parseBindingList(types.bracketR, true, true);
1668 return this.finishNode(node, "ArrayPattern")
1669
1670 case types.braceL:
1671 return this.parseObj(true)
1672 }
1673 }
1674 return this.parseIdent()
1675};
1676
1677pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
1678 var this$1 = this;
1679
1680 var elts = [], first = true;
1681 while (!this.eat(close)) {
1682 if (first) { first = false; }
1683 else { this$1.expect(types.comma); }
1684 if (allowEmpty && this$1.type === types.comma) {
1685 elts.push(null);
1686 } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
1687 break
1688 } else if (this$1.type === types.ellipsis) {
1689 var rest = this$1.parseRestBinding();
1690 this$1.parseBindingListItem(rest);
1691 elts.push(rest);
1692 if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
1693 this$1.expect(close);
1694 break
1695 } else {
1696 var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
1697 this$1.parseBindingListItem(elem);
1698 elts.push(elem);
1699 }
1700 }
1701 return elts
1702};
1703
1704pp$2.parseBindingListItem = function(param) {
1705 return param
1706};
1707
1708// Parses assignment pattern around given atom if possible.
1709
1710pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
1711 left = left || this.parseBindingAtom();
1712 if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
1713 var node = this.startNodeAt(startPos, startLoc);
1714 node.left = left;
1715 node.right = this.parseMaybeAssign();
1716 return this.finishNode(node, "AssignmentPattern")
1717};
1718
1719// Verify that a node is an lval — something that can be assigned
1720// to.
1721// bindingType can be either:
1722// 'var' indicating that the lval creates a 'var' binding
1723// 'let' indicating that the lval creates a lexical ('let' or 'const') binding
1724// 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
1725
1726pp$2.checkLVal = function(expr, bindingType, checkClashes) {
1727 var this$1 = this;
1728
1729 switch (expr.type) {
1730 case "Identifier":
1731 if (this.strict && this.reservedWordsStrictBind.test(expr.name))
1732 { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
1733 if (checkClashes) {
1734 if (has(checkClashes, expr.name))
1735 { this.raiseRecoverable(expr.start, "Argument name clash"); }
1736 checkClashes[expr.name] = true;
1737 }
1738 if (bindingType && bindingType !== "none") {
1739 if (
1740 bindingType === "var" && !this.canDeclareVarName(expr.name) ||
1741 bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
1742 ) {
1743 this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
1744 }
1745 if (bindingType === "var") {
1746 this.declareVarName(expr.name);
1747 } else {
1748 this.declareLexicalName(expr.name);
1749 }
1750 }
1751 break
1752
1753 case "MemberExpression":
1754 if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
1755 break
1756
1757 case "ObjectPattern":
1758 for (var i = 0, list = expr.properties; i < list.length; i += 1)
1759 {
1760 var prop = list[i];
1761
1762 this$1.checkLVal(prop, bindingType, checkClashes);
1763 }
1764 break
1765
1766 case "Property":
1767 // AssignmentProperty has type == "Property"
1768 this.checkLVal(expr.value, bindingType, checkClashes);
1769 break
1770
1771 case "ArrayPattern":
1772 for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
1773 var elem = list$1[i$1];
1774
1775 if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
1776 }
1777 break
1778
1779 case "AssignmentPattern":
1780 this.checkLVal(expr.left, bindingType, checkClashes);
1781 break
1782
1783 case "RestElement":
1784 this.checkLVal(expr.argument, bindingType, checkClashes);
1785 break
1786
1787 case "ParenthesizedExpression":
1788 this.checkLVal(expr.expression, bindingType, checkClashes);
1789 break
1790
1791 default:
1792 this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
1793 }
1794};
1795
1796// A recursive descent parser operates by defining functions for all
1797// syntactic elements, and recursively calling those, each function
1798// advancing the input stream and returning an AST node. Precedence
1799// of constructs (for example, the fact that `!x[1]` means `!(x[1])`
1800// instead of `(!x)[1]` is handled by the fact that the parser
1801// function that parses unary prefix operators is called first, and
1802// in turn calls the function that parses `[]` subscripts — that
1803// way, it'll receive the node for `x[1]` already parsed, and wraps
1804// *that* in the unary operator node.
1805//
1806// Acorn uses an [operator precedence parser][opp] to handle binary
1807// operator precedence, because it is much more compact than using
1808// the technique outlined above, which uses different, nesting
1809// functions to specify precedence, for all of the ten binary
1810// precedence levels that JavaScript defines.
1811//
1812// [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
1813
1814var pp$3 = Parser.prototype;
1815
1816// Check if property name clashes with already added.
1817// Object/class getters and setters are not allowed to clash —
1818// either with each other or with an init property — and in
1819// strict mode, init properties are also not allowed to be repeated.
1820
1821pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
1822 if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
1823 { return }
1824 if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
1825 { return }
1826 var key = prop.key;
1827 var name;
1828 switch (key.type) {
1829 case "Identifier": name = key.name; break
1830 case "Literal": name = String(key.value); break
1831 default: return
1832 }
1833 var kind = prop.kind;
1834 if (this.options.ecmaVersion >= 6) {
1835 if (name === "__proto__" && kind === "init") {
1836 if (propHash.proto) {
1837 if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) { refDestructuringErrors.doubleProto = key.start; }
1838 // Backwards-compat kludge. Can be removed in version 6.0
1839 else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
1840 }
1841 propHash.proto = true;
1842 }
1843 return
1844 }
1845 name = "$" + name;
1846 var other = propHash[name];
1847 if (other) {
1848 var redefinition;
1849 if (kind === "init") {
1850 redefinition = this.strict && other.init || other.get || other.set;
1851 } else {
1852 redefinition = other.init || other[kind];
1853 }
1854 if (redefinition)
1855 { this.raiseRecoverable(key.start, "Redefinition of property"); }
1856 } else {
1857 other = propHash[name] = {
1858 init: false,
1859 get: false,
1860 set: false
1861 };
1862 }
1863 other[kind] = true;
1864};
1865
1866// ### Expression parsing
1867
1868// These nest, from the most general expression type at the top to
1869// 'atomic', nondivisible expression types at the bottom. Most of
1870// the functions will simply let the function(s) below them parse,
1871// and, *if* the syntactic construct they handle is present, wrap
1872// the AST node that the inner parser gave them in another node.
1873
1874// Parse a full expression. The optional arguments are used to
1875// forbid the `in` operator (in for loops initalization expressions)
1876// and provide reference for storing '=' operator inside shorthand
1877// property assignment in contexts where both object expression
1878// and object pattern might appear (so it's possible to raise
1879// delayed syntax error at correct position).
1880
1881pp$3.parseExpression = function(noIn, refDestructuringErrors) {
1882 var this$1 = this;
1883
1884 var startPos = this.start, startLoc = this.startLoc;
1885 var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
1886 if (this.type === types.comma) {
1887 var node = this.startNodeAt(startPos, startLoc);
1888 node.expressions = [expr];
1889 while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
1890 return this.finishNode(node, "SequenceExpression")
1891 }
1892 return expr
1893};
1894
1895// Parse an assignment expression. This includes applications of
1896// operators like `+=`.
1897
1898pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
1899 if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
1900
1901 var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
1902 if (refDestructuringErrors) {
1903 oldParenAssign = refDestructuringErrors.parenthesizedAssign;
1904 oldTrailingComma = refDestructuringErrors.trailingComma;
1905 refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
1906 } else {
1907 refDestructuringErrors = new DestructuringErrors;
1908 ownDestructuringErrors = true;
1909 }
1910
1911 var startPos = this.start, startLoc = this.startLoc;
1912 if (this.type == types.parenL || this.type == types.name)
1913 { this.potentialArrowAt = this.start; }
1914 var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
1915 if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
1916 if (this.type.isAssign) {
1917 var node = this.startNodeAt(startPos, startLoc);
1918 node.operator = this.value;
1919 node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left;
1920 if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
1921 refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
1922 this.checkLVal(left);
1923 this.next();
1924 node.right = this.parseMaybeAssign(noIn);
1925 return this.finishNode(node, "AssignmentExpression")
1926 } else {
1927 if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
1928 }
1929 if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
1930 if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
1931 return left
1932};
1933
1934// Parse a ternary conditional (`?:`) operator.
1935
1936pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
1937 var startPos = this.start, startLoc = this.startLoc;
1938 var expr = this.parseExprOps(noIn, refDestructuringErrors);
1939 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1940 if (this.eat(types.question)) {
1941 var node = this.startNodeAt(startPos, startLoc);
1942 node.test = expr;
1943 node.consequent = this.parseMaybeAssign();
1944 this.expect(types.colon);
1945 node.alternate = this.parseMaybeAssign(noIn);
1946 return this.finishNode(node, "ConditionalExpression")
1947 }
1948 return expr
1949};
1950
1951// Start the precedence parser.
1952
1953pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
1954 var startPos = this.start, startLoc = this.startLoc;
1955 var expr = this.parseMaybeUnary(refDestructuringErrors, false);
1956 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1957 return expr.start == startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
1958};
1959
1960// Parse binary operators with the operator precedence parsing
1961// algorithm. `left` is the left-hand side of the operator.
1962// `minPrec` provides context that allows the function to stop and
1963// defer further parser to one of its callers when it encounters an
1964// operator that has a lower precedence than the set it is parsing.
1965
1966pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
1967 var prec = this.type.binop;
1968 if (prec != null && (!noIn || this.type !== types._in)) {
1969 if (prec > minPrec) {
1970 var logical = this.type === types.logicalOR || this.type === types.logicalAND;
1971 var op = this.value;
1972 this.next();
1973 var startPos = this.start, startLoc = this.startLoc;
1974 var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
1975 var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
1976 return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
1977 }
1978 }
1979 return left
1980};
1981
1982pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
1983 var node = this.startNodeAt(startPos, startLoc);
1984 node.left = left;
1985 node.operator = op;
1986 node.right = right;
1987 return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
1988};
1989
1990// Parse unary operators, both prefix and postfix.
1991
1992pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
1993 var this$1 = this;
1994
1995 var startPos = this.start, startLoc = this.startLoc, expr;
1996 if (this.inAsync && this.isContextual("await")) {
1997 expr = this.parseAwait();
1998 sawUnary = true;
1999 } else if (this.type.prefix) {
2000 var node = this.startNode(), update = this.type === types.incDec;
2001 node.operator = this.value;
2002 node.prefix = true;
2003 this.next();
2004 node.argument = this.parseMaybeUnary(null, true);
2005 this.checkExpressionErrors(refDestructuringErrors, true);
2006 if (update) { this.checkLVal(node.argument); }
2007 else if (this.strict && node.operator === "delete" &&
2008 node.argument.type === "Identifier")
2009 { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
2010 else { sawUnary = true; }
2011 expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
2012 } else {
2013 expr = this.parseExprSubscripts(refDestructuringErrors);
2014 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
2015 while (this.type.postfix && !this.canInsertSemicolon()) {
2016 var node$1 = this$1.startNodeAt(startPos, startLoc);
2017 node$1.operator = this$1.value;
2018 node$1.prefix = false;
2019 node$1.argument = expr;
2020 this$1.checkLVal(expr);
2021 this$1.next();
2022 expr = this$1.finishNode(node$1, "UpdateExpression");
2023 }
2024 }
2025
2026 if (!sawUnary && this.eat(types.starstar))
2027 { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
2028 else
2029 { return expr }
2030};
2031
2032// Parse call, dot, and `[]`-subscript expressions.
2033
2034pp$3.parseExprSubscripts = function(refDestructuringErrors) {
2035 var startPos = this.start, startLoc = this.startLoc;
2036 var expr = this.parseExprAtom(refDestructuringErrors);
2037 var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
2038 if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
2039 var result = this.parseSubscripts(expr, startPos, startLoc);
2040 if (refDestructuringErrors && result.type === "MemberExpression") {
2041 if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
2042 if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
2043 }
2044 return result
2045};
2046
2047pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
2048 var this$1 = this;
2049
2050 var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
2051 this.lastTokEnd == base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async";
2052 for (var computed = (void 0);;) {
2053 if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
2054 var node = this$1.startNodeAt(startPos, startLoc);
2055 node.object = base;
2056 node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
2057 node.computed = !!computed;
2058 if (computed) { this$1.expect(types.bracketR); }
2059 base = this$1.finishNode(node, "MemberExpression");
2060 } else if (!noCalls && this$1.eat(types.parenL)) {
2061 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
2062 this$1.yieldPos = 0;
2063 this$1.awaitPos = 0;
2064 var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
2065 if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
2066 this$1.checkPatternErrors(refDestructuringErrors, false);
2067 this$1.checkYieldAwaitInDefaultParams();
2068 this$1.yieldPos = oldYieldPos;
2069 this$1.awaitPos = oldAwaitPos;
2070 return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
2071 }
2072 this$1.checkExpressionErrors(refDestructuringErrors, true);
2073 this$1.yieldPos = oldYieldPos || this$1.yieldPos;
2074 this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
2075 var node$1 = this$1.startNodeAt(startPos, startLoc);
2076 node$1.callee = base;
2077 node$1.arguments = exprList;
2078 base = this$1.finishNode(node$1, "CallExpression");
2079 } else if (this$1.type === types.backQuote) {
2080 var node$2 = this$1.startNodeAt(startPos, startLoc);
2081 node$2.tag = base;
2082 node$2.quasi = this$1.parseTemplate({isTagged: true});
2083 base = this$1.finishNode(node$2, "TaggedTemplateExpression");
2084 } else {
2085 return base
2086 }
2087 }
2088};
2089
2090// Parse an atomic expression — either a single token that is an
2091// expression, an expression started by a keyword like `function` or
2092// `new`, or an expression wrapped in punctuation like `()`, `[]`,
2093// or `{}`.
2094
2095pp$3.parseExprAtom = function(refDestructuringErrors) {
2096 var node, canBeArrow = this.potentialArrowAt == this.start;
2097 switch (this.type) {
2098 case types._super:
2099 if (!this.inFunction)
2100 { this.raise(this.start, "'super' outside of function or class"); }
2101 node = this.startNode();
2102 this.next();
2103 // The `super` keyword can appear at below:
2104 // SuperProperty:
2105 // super [ Expression ]
2106 // super . IdentifierName
2107 // SuperCall:
2108 // super Arguments
2109 if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
2110 { this.unexpected(); }
2111 return this.finishNode(node, "Super")
2112
2113 case types._this:
2114 node = this.startNode();
2115 this.next();
2116 return this.finishNode(node, "ThisExpression")
2117
2118 case types.name:
2119 var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
2120 var id = this.parseIdent(this.type !== types.name);
2121 if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
2122 { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
2123 if (canBeArrow && !this.canInsertSemicolon()) {
2124 if (this.eat(types.arrow))
2125 { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
2126 if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
2127 id = this.parseIdent();
2128 if (this.canInsertSemicolon() || !this.eat(types.arrow))
2129 { this.unexpected(); }
2130 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
2131 }
2132 }
2133 return id
2134
2135 case types.regexp:
2136 var value = this.value;
2137 node = this.parseLiteral(value.value);
2138 node.regex = {pattern: value.pattern, flags: value.flags};
2139 return node
2140
2141 case types.num: case types.string:
2142 return this.parseLiteral(this.value)
2143
2144 case types._null: case types._true: case types._false:
2145 node = this.startNode();
2146 node.value = this.type === types._null ? null : this.type === types._true;
2147 node.raw = this.type.keyword;
2148 this.next();
2149 return this.finishNode(node, "Literal")
2150
2151 case types.parenL:
2152 var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
2153 if (refDestructuringErrors) {
2154 if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
2155 { refDestructuringErrors.parenthesizedAssign = start; }
2156 if (refDestructuringErrors.parenthesizedBind < 0)
2157 { refDestructuringErrors.parenthesizedBind = start; }
2158 }
2159 return expr
2160
2161 case types.bracketL:
2162 node = this.startNode();
2163 this.next();
2164 node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
2165 return this.finishNode(node, "ArrayExpression")
2166
2167 case types.braceL:
2168 return this.parseObj(false, refDestructuringErrors)
2169
2170 case types._function:
2171 node = this.startNode();
2172 this.next();
2173 return this.parseFunction(node, false)
2174
2175 case types._class:
2176 return this.parseClass(this.startNode(), false)
2177
2178 case types._new:
2179 return this.parseNew()
2180
2181 case types.backQuote:
2182 return this.parseTemplate()
2183
2184 default:
2185 this.unexpected();
2186 }
2187};
2188
2189pp$3.parseLiteral = function(value) {
2190 var node = this.startNode();
2191 node.value = value;
2192 node.raw = this.input.slice(this.start, this.end);
2193 this.next();
2194 return this.finishNode(node, "Literal")
2195};
2196
2197pp$3.parseParenExpression = function() {
2198 this.expect(types.parenL);
2199 var val = this.parseExpression();
2200 this.expect(types.parenR);
2201 return val
2202};
2203
2204pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
2205 var this$1 = this;
2206
2207 var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
2208 if (this.options.ecmaVersion >= 6) {
2209 this.next();
2210
2211 var innerStartPos = this.start, innerStartLoc = this.startLoc;
2212 var exprList = [], first = true, lastIsComma = false;
2213 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
2214 this.yieldPos = 0;
2215 this.awaitPos = 0;
2216 while (this.type !== types.parenR) {
2217 first ? first = false : this$1.expect(types.comma);
2218 if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
2219 lastIsComma = true;
2220 break
2221 } else if (this$1.type === types.ellipsis) {
2222 spreadStart = this$1.start;
2223 exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
2224 if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
2225 break
2226 } else {
2227 exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
2228 }
2229 }
2230 var innerEndPos = this.start, innerEndLoc = this.startLoc;
2231 this.expect(types.parenR);
2232
2233 if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2234 this.checkPatternErrors(refDestructuringErrors, false);
2235 this.checkYieldAwaitInDefaultParams();
2236 this.yieldPos = oldYieldPos;
2237 this.awaitPos = oldAwaitPos;
2238 return this.parseParenArrowList(startPos, startLoc, exprList)
2239 }
2240
2241 if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
2242 if (spreadStart) { this.unexpected(spreadStart); }
2243 this.checkExpressionErrors(refDestructuringErrors, true);
2244 this.yieldPos = oldYieldPos || this.yieldPos;
2245 this.awaitPos = oldAwaitPos || this.awaitPos;
2246
2247 if (exprList.length > 1) {
2248 val = this.startNodeAt(innerStartPos, innerStartLoc);
2249 val.expressions = exprList;
2250 this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
2251 } else {
2252 val = exprList[0];
2253 }
2254 } else {
2255 val = this.parseParenExpression();
2256 }
2257
2258 if (this.options.preserveParens) {
2259 var par = this.startNodeAt(startPos, startLoc);
2260 par.expression = val;
2261 return this.finishNode(par, "ParenthesizedExpression")
2262 } else {
2263 return val
2264 }
2265};
2266
2267pp$3.parseParenItem = function(item) {
2268 return item
2269};
2270
2271pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
2272 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
2273};
2274
2275// New's precedence is slightly tricky. It must allow its argument to
2276// be a `[]` or dot subscript expression, but not a call — at least,
2277// not without wrapping it in parentheses. Thus, it uses the noCalls
2278// argument to parseSubscripts to prevent it from consuming the
2279// argument list.
2280
2281var empty$1 = [];
2282
2283pp$3.parseNew = function() {
2284 var node = this.startNode();
2285 var meta = this.parseIdent(true);
2286 if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
2287 node.meta = meta;
2288 var containsEsc = this.containsEsc;
2289 node.property = this.parseIdent(true);
2290 if (node.property.name !== "target" || containsEsc)
2291 { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
2292 if (!this.inFunction)
2293 { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
2294 return this.finishNode(node, "MetaProperty")
2295 }
2296 var startPos = this.start, startLoc = this.startLoc;
2297 node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
2298 if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
2299 else { node.arguments = empty$1; }
2300 return this.finishNode(node, "NewExpression")
2301};
2302
2303// Parse template expression.
2304
2305pp$3.parseTemplateElement = function(ref) {
2306 var isTagged = ref.isTagged;
2307
2308 var elem = this.startNode();
2309 if (this.type === types.invalidTemplate) {
2310 if (!isTagged) {
2311 this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
2312 }
2313 elem.value = {
2314 raw: this.value,
2315 cooked: null
2316 };
2317 } else {
2318 elem.value = {
2319 raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
2320 cooked: this.value
2321 };
2322 }
2323 this.next();
2324 elem.tail = this.type === types.backQuote;
2325 return this.finishNode(elem, "TemplateElement")
2326};
2327
2328pp$3.parseTemplate = function(ref) {
2329 var this$1 = this;
2330 if ( ref === void 0 ) ref = {};
2331 var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
2332
2333 var node = this.startNode();
2334 this.next();
2335 node.expressions = [];
2336 var curElt = this.parseTemplateElement({isTagged: isTagged});
2337 node.quasis = [curElt];
2338 while (!curElt.tail) {
2339 this$1.expect(types.dollarBraceL);
2340 node.expressions.push(this$1.parseExpression());
2341 this$1.expect(types.braceR);
2342 node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
2343 }
2344 this.next();
2345 return this.finishNode(node, "TemplateLiteral")
2346};
2347
2348pp$3.isAsyncProp = function(prop) {
2349 return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
2350 (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)) &&
2351 !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
2352};
2353
2354// Parse an object literal or binding pattern.
2355
2356pp$3.parseObj = function(isPattern, refDestructuringErrors) {
2357 var this$1 = this;
2358
2359 var node = this.startNode(), first = true, propHash = {};
2360 node.properties = [];
2361 this.next();
2362 while (!this.eat(types.braceR)) {
2363 if (!first) {
2364 this$1.expect(types.comma);
2365 if (this$1.afterTrailingComma(types.braceR)) { break }
2366 } else { first = false; }
2367
2368 var prop = this$1.parseProperty(isPattern, refDestructuringErrors);
2369 if (!isPattern) { this$1.checkPropClash(prop, propHash, refDestructuringErrors); }
2370 node.properties.push(prop);
2371 }
2372 return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
2373};
2374
2375pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
2376 var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
2377 if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
2378 if (isPattern) {
2379 prop.argument = this.parseIdent(false);
2380 if (this.type === types.comma) {
2381 this.raise(this.start, "Comma is not permitted after the rest element");
2382 }
2383 return this.finishNode(prop, "RestElement")
2384 }
2385 // To disallow parenthesized identifier via `this.toAssignable()`.
2386 if (this.type === types.parenL && refDestructuringErrors) {
2387 if (refDestructuringErrors.parenthesizedAssign < 0) {
2388 refDestructuringErrors.parenthesizedAssign = this.start;
2389 }
2390 if (refDestructuringErrors.parenthesizedBind < 0) {
2391 refDestructuringErrors.parenthesizedBind = this.start;
2392 }
2393 }
2394 // Parse argument.
2395 prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
2396 // To disallow trailing comma via `this.toAssignable()`.
2397 if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
2398 refDestructuringErrors.trailingComma = this.start;
2399 }
2400 // Finish
2401 return this.finishNode(prop, "SpreadElement")
2402 }
2403 if (this.options.ecmaVersion >= 6) {
2404 prop.method = false;
2405 prop.shorthand = false;
2406 if (isPattern || refDestructuringErrors) {
2407 startPos = this.start;
2408 startLoc = this.startLoc;
2409 }
2410 if (!isPattern)
2411 { isGenerator = this.eat(types.star); }
2412 }
2413 var containsEsc = this.containsEsc;
2414 this.parsePropertyName(prop);
2415 if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
2416 isAsync = true;
2417 isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
2418 this.parsePropertyName(prop, refDestructuringErrors);
2419 } else {
2420 isAsync = false;
2421 }
2422 this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
2423 return this.finishNode(prop, "Property")
2424};
2425
2426pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
2427 if ((isGenerator || isAsync) && this.type === types.colon)
2428 { this.unexpected(); }
2429
2430 if (this.eat(types.colon)) {
2431 prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
2432 prop.kind = "init";
2433 } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
2434 if (isPattern) { this.unexpected(); }
2435 prop.kind = "init";
2436 prop.method = true;
2437 prop.value = this.parseMethod(isGenerator, isAsync);
2438 } else if (!isPattern && !containsEsc &&
2439 this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
2440 (prop.key.name === "get" || prop.key.name === "set") &&
2441 (this.type != types.comma && this.type != types.braceR)) {
2442 if (isGenerator || isAsync) { this.unexpected(); }
2443 prop.kind = prop.key.name;
2444 this.parsePropertyName(prop);
2445 prop.value = this.parseMethod(false);
2446 var paramCount = prop.kind === "get" ? 0 : 1;
2447 if (prop.value.params.length !== paramCount) {
2448 var start = prop.value.start;
2449 if (prop.kind === "get")
2450 { this.raiseRecoverable(start, "getter should have no params"); }
2451 else
2452 { this.raiseRecoverable(start, "setter should have exactly one param"); }
2453 } else {
2454 if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
2455 { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
2456 }
2457 } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
2458 this.checkUnreserved(prop.key);
2459 prop.kind = "init";
2460 if (isPattern) {
2461 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2462 } else if (this.type === types.eq && refDestructuringErrors) {
2463 if (refDestructuringErrors.shorthandAssign < 0)
2464 { refDestructuringErrors.shorthandAssign = this.start; }
2465 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2466 } else {
2467 prop.value = prop.key;
2468 }
2469 prop.shorthand = true;
2470 } else { this.unexpected(); }
2471};
2472
2473pp$3.parsePropertyName = function(prop) {
2474 if (this.options.ecmaVersion >= 6) {
2475 if (this.eat(types.bracketL)) {
2476 prop.computed = true;
2477 prop.key = this.parseMaybeAssign();
2478 this.expect(types.bracketR);
2479 return prop.key
2480 } else {
2481 prop.computed = false;
2482 }
2483 }
2484 return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
2485};
2486
2487// Initialize empty function node.
2488
2489pp$3.initFunction = function(node) {
2490 node.id = null;
2491 if (this.options.ecmaVersion >= 6) {
2492 node.generator = false;
2493 node.expression = false;
2494 }
2495 if (this.options.ecmaVersion >= 8)
2496 { node.async = false; }
2497};
2498
2499// Parse object or class method.
2500
2501pp$3.parseMethod = function(isGenerator, isAsync) {
2502 var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
2503 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
2504
2505 this.initFunction(node);
2506 if (this.options.ecmaVersion >= 6)
2507 { node.generator = isGenerator; }
2508 if (this.options.ecmaVersion >= 8)
2509 { node.async = !!isAsync; }
2510
2511 this.inGenerator = node.generator;
2512 this.inAsync = node.async;
2513 this.yieldPos = 0;
2514 this.awaitPos = 0;
2515 this.inFunction = true;
2516 this.enterFunctionScope();
2517
2518 this.expect(types.parenL);
2519 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
2520 this.checkYieldAwaitInDefaultParams();
2521 this.parseFunctionBody(node, false);
2522
2523 this.inGenerator = oldInGen;
2524 this.inAsync = oldInAsync;
2525 this.yieldPos = oldYieldPos;
2526 this.awaitPos = oldAwaitPos;
2527 this.inFunction = oldInFunc;
2528 return this.finishNode(node, "FunctionExpression")
2529};
2530
2531// Parse arrow function expression with given parameters.
2532
2533pp$3.parseArrowExpression = function(node, params, isAsync) {
2534 var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
2535 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
2536
2537 this.enterFunctionScope();
2538 this.initFunction(node);
2539 if (this.options.ecmaVersion >= 8)
2540 { node.async = !!isAsync; }
2541
2542 this.inGenerator = false;
2543 this.inAsync = node.async;
2544 this.yieldPos = 0;
2545 this.awaitPos = 0;
2546 this.inFunction = true;
2547
2548 node.params = this.toAssignableList(params, true);
2549 this.parseFunctionBody(node, true);
2550
2551 this.inGenerator = oldInGen;
2552 this.inAsync = oldInAsync;
2553 this.yieldPos = oldYieldPos;
2554 this.awaitPos = oldAwaitPos;
2555 this.inFunction = oldInFunc;
2556 return this.finishNode(node, "ArrowFunctionExpression")
2557};
2558
2559// Parse function body and check parameters.
2560
2561pp$3.parseFunctionBody = function(node, isArrowFunction) {
2562 var isExpression = isArrowFunction && this.type !== types.braceL;
2563 var oldStrict = this.strict, useStrict = false;
2564
2565 if (isExpression) {
2566 node.body = this.parseMaybeAssign();
2567 node.expression = true;
2568 this.checkParams(node, false);
2569 } else {
2570 var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
2571 if (!oldStrict || nonSimple) {
2572 useStrict = this.strictDirective(this.end);
2573 // If this is a strict mode function, verify that argument names
2574 // are not repeated, and it does not try to bind the words `eval`
2575 // or `arguments`.
2576 if (useStrict && nonSimple)
2577 { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
2578 }
2579 // Start a new scope with regard to labels and the `inFunction`
2580 // flag (restore them to their old value afterwards).
2581 var oldLabels = this.labels;
2582 this.labels = [];
2583 if (useStrict) { this.strict = true; }
2584
2585 // Add the params to varDeclaredNames to ensure that an error is thrown
2586 // if a let/const declaration in the function clashes with one of the params.
2587 this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
2588 node.body = this.parseBlock(false);
2589 node.expression = false;
2590 this.adaptDirectivePrologue(node.body.body);
2591 this.labels = oldLabels;
2592 }
2593 this.exitFunctionScope();
2594
2595 if (this.strict && node.id) {
2596 // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
2597 this.checkLVal(node.id, "none");
2598 }
2599 this.strict = oldStrict;
2600};
2601
2602pp$3.isSimpleParamList = function(params) {
2603 for (var i = 0, list = params; i < list.length; i += 1)
2604 {
2605 var param = list[i];
2606
2607 if (param.type !== "Identifier") { return false
2608 } }
2609 return true
2610};
2611
2612// Checks function params for various disallowed patterns such as using "eval"
2613// or "arguments" and duplicate parameters.
2614
2615pp$3.checkParams = function(node, allowDuplicates) {
2616 var this$1 = this;
2617
2618 var nameHash = {};
2619 for (var i = 0, list = node.params; i < list.length; i += 1)
2620 {
2621 var param = list[i];
2622
2623 this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
2624 }
2625};
2626
2627// Parses a comma-separated list of expressions, and returns them as
2628// an array. `close` is the token type that ends the list, and
2629// `allowEmpty` can be turned on to allow subsequent commas with
2630// nothing in between them to be parsed as `null` (which is needed
2631// for array literals).
2632
2633pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
2634 var this$1 = this;
2635
2636 var elts = [], first = true;
2637 while (!this.eat(close)) {
2638 if (!first) {
2639 this$1.expect(types.comma);
2640 if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
2641 } else { first = false; }
2642
2643 var elt = (void 0);
2644 if (allowEmpty && this$1.type === types.comma)
2645 { elt = null; }
2646 else if (this$1.type === types.ellipsis) {
2647 elt = this$1.parseSpread(refDestructuringErrors);
2648 if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
2649 { refDestructuringErrors.trailingComma = this$1.start; }
2650 } else {
2651 elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
2652 }
2653 elts.push(elt);
2654 }
2655 return elts
2656};
2657
2658pp$3.checkUnreserved = function(ref) {
2659 var start = ref.start;
2660 var end = ref.end;
2661 var name = ref.name;
2662
2663 if (this.inGenerator && name === "yield")
2664 { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
2665 if (this.inAsync && name === "await")
2666 { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
2667 if (this.isKeyword(name))
2668 { this.raise(start, ("Unexpected keyword '" + name + "'")); }
2669 if (this.options.ecmaVersion < 6 &&
2670 this.input.slice(start, end).indexOf("\\") != -1) { return }
2671 var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
2672 if (re.test(name)) {
2673 if (!this.inAsync && name === "await")
2674 { this.raiseRecoverable(start, "Can not use keyword 'await' outside an async function"); }
2675 this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
2676 }
2677};
2678
2679// Parse the next token as an identifier. If `liberal` is true (used
2680// when parsing properties), it will also convert keywords into
2681// identifiers.
2682
2683pp$3.parseIdent = function(liberal, isBinding) {
2684 var node = this.startNode();
2685 if (liberal && this.options.allowReserved == "never") { liberal = false; }
2686 if (this.type === types.name) {
2687 node.name = this.value;
2688 } else if (this.type.keyword) {
2689 node.name = this.type.keyword;
2690
2691 // To fix https://github.com/acornjs/acorn/issues/575
2692 // `class` and `function` keywords push new context into this.context.
2693 // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
2694 // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
2695 if ((node.name === "class" || node.name === "function") &&
2696 (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
2697 this.context.pop();
2698 }
2699 } else {
2700 this.unexpected();
2701 }
2702 this.next();
2703 this.finishNode(node, "Identifier");
2704 if (!liberal) { this.checkUnreserved(node); }
2705 return node
2706};
2707
2708// Parses yield expression inside generator.
2709
2710pp$3.parseYield = function() {
2711 if (!this.yieldPos) { this.yieldPos = this.start; }
2712
2713 var node = this.startNode();
2714 this.next();
2715 if (this.type == types.semi || this.canInsertSemicolon() || (this.type != types.star && !this.type.startsExpr)) {
2716 node.delegate = false;
2717 node.argument = null;
2718 } else {
2719 node.delegate = this.eat(types.star);
2720 node.argument = this.parseMaybeAssign();
2721 }
2722 return this.finishNode(node, "YieldExpression")
2723};
2724
2725pp$3.parseAwait = function() {
2726 if (!this.awaitPos) { this.awaitPos = this.start; }
2727
2728 var node = this.startNode();
2729 this.next();
2730 node.argument = this.parseMaybeUnary(null, true);
2731 return this.finishNode(node, "AwaitExpression")
2732};
2733
2734var pp$4 = Parser.prototype;
2735
2736// This function is used to raise exceptions on parse errors. It
2737// takes an offset integer (into the current `input`) to indicate
2738// the location of the error, attaches the position to the end
2739// of the error message, and then raises a `SyntaxError` with that
2740// message.
2741
2742pp$4.raise = function(pos, message) {
2743 var loc = getLineInfo(this.input, pos);
2744 message += " (" + loc.line + ":" + loc.column + ")";
2745 var err = new SyntaxError(message);
2746 err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
2747 throw err
2748};
2749
2750pp$4.raiseRecoverable = pp$4.raise;
2751
2752pp$4.curPosition = function() {
2753 if (this.options.locations) {
2754 return new Position(this.curLine, this.pos - this.lineStart)
2755 }
2756};
2757
2758var pp$5 = Parser.prototype;
2759
2760// Object.assign polyfill
2761var assign = Object.assign || function(target) {
2762 var sources = [], len = arguments.length - 1;
2763 while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
2764
2765 for (var i = 0, list = sources; i < list.length; i += 1) {
2766 var source = list[i];
2767
2768 for (var key in source) {
2769 if (has(source, key)) {
2770 target[key] = source[key];
2771 }
2772 }
2773 }
2774 return target
2775};
2776
2777// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
2778
2779pp$5.enterFunctionScope = function() {
2780 // var: a hash of var-declared names in the current lexical scope
2781 // lexical: a hash of lexically-declared names in the current lexical scope
2782 // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
2783 // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
2784 this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
2785};
2786
2787pp$5.exitFunctionScope = function() {
2788 this.scopeStack.pop();
2789};
2790
2791pp$5.enterLexicalScope = function() {
2792 var parentScope = this.scopeStack[this.scopeStack.length - 1];
2793 var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
2794
2795 this.scopeStack.push(childScope);
2796 assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
2797};
2798
2799pp$5.exitLexicalScope = function() {
2800 var childScope = this.scopeStack.pop();
2801 var parentScope = this.scopeStack[this.scopeStack.length - 1];
2802
2803 assign(parentScope.childVar, childScope.var, childScope.childVar);
2804};
2805
2806/**
2807 * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
2808 * in the current lexical scope or any of the parent lexical scopes in this function.
2809 */
2810pp$5.canDeclareVarName = function(name) {
2811 var currentScope = this.scopeStack[this.scopeStack.length - 1];
2812
2813 return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
2814};
2815
2816/**
2817 * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
2818 * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
2819 * any child lexical scopes in this function.
2820 */
2821pp$5.canDeclareLexicalName = function(name) {
2822 var currentScope = this.scopeStack[this.scopeStack.length - 1];
2823
2824 return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
2825};
2826
2827pp$5.declareVarName = function(name) {
2828 this.scopeStack[this.scopeStack.length - 1].var[name] = true;
2829};
2830
2831pp$5.declareLexicalName = function(name) {
2832 this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
2833};
2834
2835var Node = function Node(parser, pos, loc) {
2836 this.type = "";
2837 this.start = pos;
2838 this.end = 0;
2839 if (parser.options.locations)
2840 { this.loc = new SourceLocation(parser, loc); }
2841 if (parser.options.directSourceFile)
2842 { this.sourceFile = parser.options.directSourceFile; }
2843 if (parser.options.ranges)
2844 { this.range = [pos, 0]; }
2845};
2846
2847// Start an AST node, attaching a start offset.
2848
2849var pp$6 = Parser.prototype;
2850
2851pp$6.startNode = function() {
2852 return new Node(this, this.start, this.startLoc)
2853};
2854
2855pp$6.startNodeAt = function(pos, loc) {
2856 return new Node(this, pos, loc)
2857};
2858
2859// Finish an AST node, adding `type` and `end` properties.
2860
2861function finishNodeAt(node, type, pos, loc) {
2862 node.type = type;
2863 node.end = pos;
2864 if (this.options.locations)
2865 { node.loc.end = loc; }
2866 if (this.options.ranges)
2867 { node.range[1] = pos; }
2868 return node
2869}
2870
2871pp$6.finishNode = function(node, type) {
2872 return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
2873};
2874
2875// Finish node at given position
2876
2877pp$6.finishNodeAt = function(node, type, pos, loc) {
2878 return finishNodeAt.call(this, node, type, pos, loc)
2879};
2880
2881// The algorithm used to determine whether a regexp can appear at a
2882// given point in the program is loosely based on sweet.js' approach.
2883// See https://github.com/mozilla/sweet.js/wiki/design
2884
2885var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
2886 this.token = token;
2887 this.isExpr = !!isExpr;
2888 this.preserveSpace = !!preserveSpace;
2889 this.override = override;
2890 this.generator = !!generator;
2891};
2892
2893var types$1 = {
2894 b_stat: new TokContext("{", false),
2895 b_expr: new TokContext("{", true),
2896 b_tmpl: new TokContext("${", false),
2897 p_stat: new TokContext("(", false),
2898 p_expr: new TokContext("(", true),
2899 q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
2900 f_stat: new TokContext("function", false),
2901 f_expr: new TokContext("function", true),
2902 f_expr_gen: new TokContext("function", true, false, null, true),
2903 f_gen: new TokContext("function", false, false, null, true)
2904};
2905
2906var pp$7 = Parser.prototype;
2907
2908pp$7.initialContext = function() {
2909 return [types$1.b_stat]
2910};
2911
2912pp$7.braceIsBlock = function(prevType) {
2913 var parent = this.curContext();
2914 if (parent === types$1.f_expr || parent === types$1.f_stat)
2915 { return true }
2916 if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
2917 { return !parent.isExpr }
2918
2919 // The check for `tt.name && exprAllowed` detects whether we are
2920 // after a `yield` or `of` construct. See the `updateContext` for
2921 // `tt.name`.
2922 if (prevType === types._return || prevType == types.name && this.exprAllowed)
2923 { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
2924 if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType == types.arrow)
2925 { return true }
2926 if (prevType == types.braceL)
2927 { return parent === types$1.b_stat }
2928 if (prevType == types._var || prevType == types.name)
2929 { return false }
2930 return !this.exprAllowed
2931};
2932
2933pp$7.inGeneratorContext = function() {
2934 var this$1 = this;
2935
2936 for (var i = this.context.length - 1; i >= 1; i--) {
2937 var context = this$1.context[i];
2938 if (context.token === "function")
2939 { return context.generator }
2940 }
2941 return false
2942};
2943
2944pp$7.updateContext = function(prevType) {
2945 var update, type = this.type;
2946 if (type.keyword && prevType == types.dot)
2947 { this.exprAllowed = false; }
2948 else if (update = type.updateContext)
2949 { update.call(this, prevType); }
2950 else
2951 { this.exprAllowed = type.beforeExpr; }
2952};
2953
2954// Token-specific context update code
2955
2956types.parenR.updateContext = types.braceR.updateContext = function() {
2957 if (this.context.length == 1) {
2958 this.exprAllowed = true;
2959 return
2960 }
2961 var out = this.context.pop();
2962 if (out === types$1.b_stat && this.curContext().token === "function") {
2963 out = this.context.pop();
2964 }
2965 this.exprAllowed = !out.isExpr;
2966};
2967
2968types.braceL.updateContext = function(prevType) {
2969 this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
2970 this.exprAllowed = true;
2971};
2972
2973types.dollarBraceL.updateContext = function() {
2974 this.context.push(types$1.b_tmpl);
2975 this.exprAllowed = true;
2976};
2977
2978types.parenL.updateContext = function(prevType) {
2979 var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
2980 this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
2981 this.exprAllowed = true;
2982};
2983
2984types.incDec.updateContext = function() {
2985 // tokExprAllowed stays unchanged
2986};
2987
2988types._function.updateContext = types._class.updateContext = function(prevType) {
2989 if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
2990 !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
2991 { this.context.push(types$1.f_expr); }
2992 else
2993 { this.context.push(types$1.f_stat); }
2994 this.exprAllowed = false;
2995};
2996
2997types.backQuote.updateContext = function() {
2998 if (this.curContext() === types$1.q_tmpl)
2999 { this.context.pop(); }
3000 else
3001 { this.context.push(types$1.q_tmpl); }
3002 this.exprAllowed = false;
3003};
3004
3005types.star.updateContext = function(prevType) {
3006 if (prevType == types._function) {
3007 var index = this.context.length - 1;
3008 if (this.context[index] === types$1.f_expr)
3009 { this.context[index] = types$1.f_expr_gen; }
3010 else
3011 { this.context[index] = types$1.f_gen; }
3012 }
3013 this.exprAllowed = true;
3014};
3015
3016types.name.updateContext = function(prevType) {
3017 var allowed = false;
3018 if (this.options.ecmaVersion >= 6) {
3019 if (this.value == "of" && !this.exprAllowed ||
3020 this.value == "yield" && this.inGeneratorContext())
3021 { allowed = true; }
3022 }
3023 this.exprAllowed = allowed;
3024};
3025
3026// Object type used to represent tokens. Note that normally, tokens
3027// simply exist as properties on the parser object. This is only
3028// used for the onToken callback and the external tokenizer.
3029
3030var Token = function Token(p) {
3031 this.type = p.type;
3032 this.value = p.value;
3033 this.start = p.start;
3034 this.end = p.end;
3035 if (p.options.locations)
3036 { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
3037 if (p.options.ranges)
3038 { this.range = [p.start, p.end]; }
3039};
3040
3041// ## Tokenizer
3042
3043var pp$8 = Parser.prototype;
3044
3045// Are we running under Rhino?
3046var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
3047
3048// Move to the next token
3049
3050pp$8.next = function() {
3051 if (this.options.onToken)
3052 { this.options.onToken(new Token(this)); }
3053
3054 this.lastTokEnd = this.end;
3055 this.lastTokStart = this.start;
3056 this.lastTokEndLoc = this.endLoc;
3057 this.lastTokStartLoc = this.startLoc;
3058 this.nextToken();
3059};
3060
3061pp$8.getToken = function() {
3062 this.next();
3063 return new Token(this)
3064};
3065
3066// If we're in an ES6 environment, make parsers iterable
3067if (typeof Symbol !== "undefined")
3068 { pp$8[Symbol.iterator] = function() {
3069 var this$1 = this;
3070
3071 return {
3072 next: function () {
3073 var token = this$1.getToken();
3074 return {
3075 done: token.type === types.eof,
3076 value: token
3077 }
3078 }
3079 }
3080 }; }
3081
3082// Toggle strict mode. Re-reads the next number or string to please
3083// pedantic tests (`"use strict"; 010;` should fail).
3084
3085pp$8.curContext = function() {
3086 return this.context[this.context.length - 1]
3087};
3088
3089// Read a single token, updating the parser object's token-related
3090// properties.
3091
3092pp$8.nextToken = function() {
3093 var curContext = this.curContext();
3094 if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
3095
3096 this.start = this.pos;
3097 if (this.options.locations) { this.startLoc = this.curPosition(); }
3098 if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
3099
3100 if (curContext.override) { return curContext.override(this) }
3101 else { this.readToken(this.fullCharCodeAtPos()); }
3102};
3103
3104pp$8.readToken = function(code) {
3105 // Identifier or keyword. '\uXXXX' sequences are allowed in
3106 // identifiers, so '\' also dispatches to that.
3107 if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
3108 { return this.readWord() }
3109
3110 return this.getTokenFromCode(code)
3111};
3112
3113pp$8.fullCharCodeAtPos = function() {
3114 var code = this.input.charCodeAt(this.pos);
3115 if (code <= 0xd7ff || code >= 0xe000) { return code }
3116 var next = this.input.charCodeAt(this.pos + 1);
3117 return (code << 10) + next - 0x35fdc00
3118};
3119
3120pp$8.skipBlockComment = function() {
3121 var this$1 = this;
3122
3123 var startLoc = this.options.onComment && this.curPosition();
3124 var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
3125 if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
3126 this.pos = end + 2;
3127 if (this.options.locations) {
3128 lineBreakG.lastIndex = start;
3129 var match;
3130 while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
3131 ++this$1.curLine;
3132 this$1.lineStart = match.index + match[0].length;
3133 }
3134 }
3135 if (this.options.onComment)
3136 { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
3137 startLoc, this.curPosition()); }
3138};
3139
3140pp$8.skipLineComment = function(startSkip) {
3141 var this$1 = this;
3142
3143 var start = this.pos;
3144 var startLoc = this.options.onComment && this.curPosition();
3145 var ch = this.input.charCodeAt(this.pos += startSkip);
3146 while (this.pos < this.input.length && !isNewLine(ch)) {
3147 ch = this$1.input.charCodeAt(++this$1.pos);
3148 }
3149 if (this.options.onComment)
3150 { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
3151 startLoc, this.curPosition()); }
3152};
3153
3154// Called at the start of the parse and after every token. Skips
3155// whitespace and comments, and.
3156
3157pp$8.skipSpace = function() {
3158 var this$1 = this;
3159
3160 loop: while (this.pos < this.input.length) {
3161 var ch = this$1.input.charCodeAt(this$1.pos);
3162 switch (ch) {
3163 case 32: case 160: // ' '
3164 ++this$1.pos;
3165 break
3166 case 13:
3167 if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
3168 ++this$1.pos;
3169 }
3170 case 10: case 8232: case 8233:
3171 ++this$1.pos;
3172 if (this$1.options.locations) {
3173 ++this$1.curLine;
3174 this$1.lineStart = this$1.pos;
3175 }
3176 break
3177 case 47: // '/'
3178 switch (this$1.input.charCodeAt(this$1.pos + 1)) {
3179 case 42: // '*'
3180 this$1.skipBlockComment();
3181 break
3182 case 47:
3183 this$1.skipLineComment(2);
3184 break
3185 default:
3186 break loop
3187 }
3188 break
3189 default:
3190 if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
3191 ++this$1.pos;
3192 } else {
3193 break loop
3194 }
3195 }
3196 }
3197};
3198
3199// Called at the end of every token. Sets `end`, `val`, and
3200// maintains `context` and `exprAllowed`, and skips the space after
3201// the token, so that the next one's `start` will point at the
3202// right position.
3203
3204pp$8.finishToken = function(type, val) {
3205 this.end = this.pos;
3206 if (this.options.locations) { this.endLoc = this.curPosition(); }
3207 var prevType = this.type;
3208 this.type = type;
3209 this.value = val;
3210
3211 this.updateContext(prevType);
3212};
3213
3214// ### Token reading
3215
3216// This is the function that is called to fetch the next token. It
3217// is somewhat obscure, because it works in character codes rather
3218// than characters, and because operator parsing has been inlined
3219// into it.
3220//
3221// All in the name of speed.
3222//
3223pp$8.readToken_dot = function() {
3224 var next = this.input.charCodeAt(this.pos + 1);
3225 if (next >= 48 && next <= 57) { return this.readNumber(true) }
3226 var next2 = this.input.charCodeAt(this.pos + 2);
3227 if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
3228 this.pos += 3;
3229 return this.finishToken(types.ellipsis)
3230 } else {
3231 ++this.pos;
3232 return this.finishToken(types.dot)
3233 }
3234};
3235
3236pp$8.readToken_slash = function() { // '/'
3237 var next = this.input.charCodeAt(this.pos + 1);
3238 if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
3239 if (next === 61) { return this.finishOp(types.assign, 2) }
3240 return this.finishOp(types.slash, 1)
3241};
3242
3243pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
3244 var next = this.input.charCodeAt(this.pos + 1);
3245 var size = 1;
3246 var tokentype = code === 42 ? types.star : types.modulo;
3247
3248 // exponentiation operator ** and **=
3249 if (this.options.ecmaVersion >= 7 && code == 42 && next === 42) {
3250 ++size;
3251 tokentype = types.starstar;
3252 next = this.input.charCodeAt(this.pos + 2);
3253 }
3254
3255 if (next === 61) { return this.finishOp(types.assign, size + 1) }
3256 return this.finishOp(tokentype, size)
3257};
3258
3259pp$8.readToken_pipe_amp = function(code) { // '|&'
3260 var next = this.input.charCodeAt(this.pos + 1);
3261 if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
3262 if (next === 61) { return this.finishOp(types.assign, 2) }
3263 return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
3264};
3265
3266pp$8.readToken_caret = function() { // '^'
3267 var next = this.input.charCodeAt(this.pos + 1);
3268 if (next === 61) { return this.finishOp(types.assign, 2) }
3269 return this.finishOp(types.bitwiseXOR, 1)
3270};
3271
3272pp$8.readToken_plus_min = function(code) { // '+-'
3273 var next = this.input.charCodeAt(this.pos + 1);
3274 if (next === code) {
3275 if (next == 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 62 &&
3276 (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
3277 // A `-->` line comment
3278 this.skipLineComment(3);
3279 this.skipSpace();
3280 return this.nextToken()
3281 }
3282 return this.finishOp(types.incDec, 2)
3283 }
3284 if (next === 61) { return this.finishOp(types.assign, 2) }
3285 return this.finishOp(types.plusMin, 1)
3286};
3287
3288pp$8.readToken_lt_gt = function(code) { // '<>'
3289 var next = this.input.charCodeAt(this.pos + 1);
3290 var size = 1;
3291 if (next === code) {
3292 size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
3293 if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
3294 return this.finishOp(types.bitShift, size)
3295 }
3296 if (next == 33 && code == 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 45 &&
3297 this.input.charCodeAt(this.pos + 3) == 45) {
3298 // `<!--`, an XML-style comment that should be interpreted as a line comment
3299 this.skipLineComment(4);
3300 this.skipSpace();
3301 return this.nextToken()
3302 }
3303 if (next === 61) { size = 2; }
3304 return this.finishOp(types.relational, size)
3305};
3306
3307pp$8.readToken_eq_excl = function(code) { // '=!'
3308 var next = this.input.charCodeAt(this.pos + 1);
3309 if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
3310 if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
3311 this.pos += 2;
3312 return this.finishToken(types.arrow)
3313 }
3314 return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
3315};
3316
3317pp$8.getTokenFromCode = function(code) {
3318 switch (code) {
3319 // The interpretation of a dot depends on whether it is followed
3320 // by a digit or another two dots.
3321 case 46: // '.'
3322 return this.readToken_dot()
3323
3324 // Punctuation tokens.
3325 case 40: ++this.pos; return this.finishToken(types.parenL)
3326 case 41: ++this.pos; return this.finishToken(types.parenR)
3327 case 59: ++this.pos; return this.finishToken(types.semi)
3328 case 44: ++this.pos; return this.finishToken(types.comma)
3329 case 91: ++this.pos; return this.finishToken(types.bracketL)
3330 case 93: ++this.pos; return this.finishToken(types.bracketR)
3331 case 123: ++this.pos; return this.finishToken(types.braceL)
3332 case 125: ++this.pos; return this.finishToken(types.braceR)
3333 case 58: ++this.pos; return this.finishToken(types.colon)
3334 case 63: ++this.pos; return this.finishToken(types.question)
3335
3336 case 96: // '`'
3337 if (this.options.ecmaVersion < 6) { break }
3338 ++this.pos;
3339 return this.finishToken(types.backQuote)
3340
3341 case 48: // '0'
3342 var next = this.input.charCodeAt(this.pos + 1);
3343 if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
3344 if (this.options.ecmaVersion >= 6) {
3345 if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
3346 if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
3347 }
3348
3349 // Anything else beginning with a digit is an integer, octal
3350 // number, or float.
3351 case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
3352 return this.readNumber(false)
3353
3354 // Quotes produce strings.
3355 case 34: case 39: // '"', "'"
3356 return this.readString(code)
3357
3358 // Operators are parsed inline in tiny state machines. '=' (61) is
3359 // often referred to. `finishOp` simply skips the amount of
3360 // characters it is given as second argument, and returns a token
3361 // of the type given by its first argument.
3362
3363 case 47: // '/'
3364 return this.readToken_slash()
3365
3366 case 37: case 42: // '%*'
3367 return this.readToken_mult_modulo_exp(code)
3368
3369 case 124: case 38: // '|&'
3370 return this.readToken_pipe_amp(code)
3371
3372 case 94: // '^'
3373 return this.readToken_caret()
3374
3375 case 43: case 45: // '+-'
3376 return this.readToken_plus_min(code)
3377
3378 case 60: case 62: // '<>'
3379 return this.readToken_lt_gt(code)
3380
3381 case 61: case 33: // '=!'
3382 return this.readToken_eq_excl(code)
3383
3384 case 126: // '~'
3385 return this.finishOp(types.prefix, 1)
3386 }
3387
3388 this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
3389};
3390
3391pp$8.finishOp = function(type, size) {
3392 var str = this.input.slice(this.pos, this.pos + size);
3393 this.pos += size;
3394 return this.finishToken(type, str)
3395};
3396
3397// Parse a regular expression. Some context-awareness is necessary,
3398// since a '/' inside a '[]' set does not end the expression.
3399
3400function tryCreateRegexp(src, flags, throwErrorAt, parser) {
3401 try {
3402 return new RegExp(src, flags)
3403 } catch (e) {
3404 if (throwErrorAt !== undefined) {
3405 if (e instanceof SyntaxError) { parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message); }
3406 throw e
3407 }
3408 }
3409}
3410
3411var regexpUnicodeSupport = !!tryCreateRegexp("\uffff", "u");
3412
3413pp$8.readRegexp = function() {
3414 var this$1 = this;
3415
3416 var escaped, inClass, start = this.pos;
3417 for (;;) {
3418 if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
3419 var ch = this$1.input.charAt(this$1.pos);
3420 if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
3421 if (!escaped) {
3422 if (ch === "[") { inClass = true; }
3423 else if (ch === "]" && inClass) { inClass = false; }
3424 else if (ch === "/" && !inClass) { break }
3425 escaped = ch === "\\";
3426 } else { escaped = false; }
3427 ++this$1.pos;
3428 }
3429 var content = this.input.slice(start, this.pos);
3430 ++this.pos;
3431 var flagsStart = this.pos;
3432 var mods = this.readWord1();
3433 if (this.containsEsc) { this.unexpected(flagsStart); }
3434
3435 var tmp = content, tmpFlags = "";
3436 if (mods) {
3437 var validFlags = "gim";
3438 if (this.options.ecmaVersion >= 6) { validFlags += "uy"; }
3439 if (this.options.ecmaVersion >= 9) { validFlags += "s"; }
3440 for (var i = 0; i < mods.length; i++) {
3441 var mod = mods.charAt(i);
3442 if (validFlags.indexOf(mod) == -1) { this$1.raise(start, "Invalid regular expression flag"); }
3443 if (mods.indexOf(mod, i + 1) > -1) { this$1.raise(start, "Duplicate regular expression flag"); }
3444 }
3445 if (mods.indexOf("u") >= 0) {
3446 if (regexpUnicodeSupport) {
3447 tmpFlags = "u";
3448 } else {
3449 // Replace each astral symbol and every Unicode escape sequence that
3450 // possibly represents an astral symbol or a paired surrogate with a
3451 // single ASCII symbol to avoid throwing on regular expressions that
3452 // are only valid in combination with the `/u` flag.
3453 // Note: replacing with the ASCII symbol `x` might cause false
3454 // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
3455 // perfectly valid pattern that is equivalent to `[a-b]`, but it would
3456 // be replaced by `[x-b]` which throws an error.
3457 tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
3458 code = Number("0x" + code);
3459 if (code > 0x10FFFF) { this$1.raise(start + offset + 3, "Code point out of bounds"); }
3460 return "x"
3461 });
3462 tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
3463 tmpFlags = tmpFlags.replace("u", "");
3464 }
3465 }
3466 }
3467 // Detect invalid regular expressions.
3468 var value = null;
3469 // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
3470 // so don't do detection if we are running under Rhino
3471 if (!isRhino) {
3472 tryCreateRegexp(tmp, tmpFlags, start, this);
3473 // Get a regular expression object for this pattern-flag pair, or `null` in
3474 // case the current environment doesn't support the flags it uses.
3475 value = tryCreateRegexp(content, mods);
3476 }
3477 return this.finishToken(types.regexp, {pattern: content, flags: mods, value: value})
3478};
3479
3480// Read an integer in the given radix. Return null if zero digits
3481// were read, the integer value otherwise. When `len` is given, this
3482// will return `null` unless the integer has exactly `len` digits.
3483
3484pp$8.readInt = function(radix, len) {
3485 var this$1 = this;
3486
3487 var start = this.pos, total = 0;
3488 for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
3489 var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
3490 if (code >= 97) { val = code - 97 + 10; } // a
3491 else if (code >= 65) { val = code - 65 + 10; } // A
3492 else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
3493 else { val = Infinity; }
3494 if (val >= radix) { break }
3495 ++this$1.pos;
3496 total = total * radix + val;
3497 }
3498 if (this.pos === start || len != null && this.pos - start !== len) { return null }
3499
3500 return total
3501};
3502
3503pp$8.readRadixNumber = function(radix) {
3504 this.pos += 2; // 0x
3505 var val = this.readInt(radix);
3506 if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
3507 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
3508 return this.finishToken(types.num, val)
3509};
3510
3511// Read an integer, octal integer, or floating-point number.
3512
3513pp$8.readNumber = function(startsWithDot) {
3514 var start = this.pos;
3515 if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
3516 var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
3517 if (octal && this.strict) { this.raise(start, "Invalid number"); }
3518 if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
3519 var next = this.input.charCodeAt(this.pos);
3520 if (next === 46 && !octal) { // '.'
3521 ++this.pos;
3522 this.readInt(10);
3523 next = this.input.charCodeAt(this.pos);
3524 }
3525 if ((next === 69 || next === 101) && !octal) { // 'eE'
3526 next = this.input.charCodeAt(++this.pos);
3527 if (next === 43 || next === 45) { ++this.pos; } // '+-'
3528 if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
3529 }
3530 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
3531
3532 var str = this.input.slice(start, this.pos);
3533 var val = octal ? parseInt(str, 8) : parseFloat(str);
3534 return this.finishToken(types.num, val)
3535};
3536
3537// Read a string value, interpreting backslash-escapes.
3538
3539pp$8.readCodePoint = function() {
3540 var ch = this.input.charCodeAt(this.pos), code;
3541
3542 if (ch === 123) { // '{'
3543 if (this.options.ecmaVersion < 6) { this.unexpected(); }
3544 var codePos = ++this.pos;
3545 code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
3546 ++this.pos;
3547 if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
3548 } else {
3549 code = this.readHexChar(4);
3550 }
3551 return code
3552};
3553
3554function codePointToString(code) {
3555 // UTF-16 Decoding
3556 if (code <= 0xFFFF) { return String.fromCharCode(code) }
3557 code -= 0x10000;
3558 return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
3559}
3560
3561pp$8.readString = function(quote) {
3562 var this$1 = this;
3563
3564 var out = "", chunkStart = ++this.pos;
3565 for (;;) {
3566 if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
3567 var ch = this$1.input.charCodeAt(this$1.pos);
3568 if (ch === quote) { break }
3569 if (ch === 92) { // '\'
3570 out += this$1.input.slice(chunkStart, this$1.pos);
3571 out += this$1.readEscapedChar(false);
3572 chunkStart = this$1.pos;
3573 } else {
3574 if (isNewLine(ch)) { this$1.raise(this$1.start, "Unterminated string constant"); }
3575 ++this$1.pos;
3576 }
3577 }
3578 out += this.input.slice(chunkStart, this.pos++);
3579 return this.finishToken(types.string, out)
3580};
3581
3582// Reads template string tokens.
3583
3584var INVALID_TEMPLATE_ESCAPE_ERROR = {};
3585
3586pp$8.tryReadTemplateToken = function() {
3587 this.inTemplateElement = true;
3588 try {
3589 this.readTmplToken();
3590 } catch (err) {
3591 if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
3592 this.readInvalidTemplateToken();
3593 } else {
3594 throw err
3595 }
3596 }
3597
3598 this.inTemplateElement = false;
3599};
3600
3601pp$8.invalidStringToken = function(position, message) {
3602 if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
3603 throw INVALID_TEMPLATE_ESCAPE_ERROR
3604 } else {
3605 this.raise(position, message);
3606 }
3607};
3608
3609pp$8.readTmplToken = function() {
3610 var this$1 = this;
3611
3612 var out = "", chunkStart = this.pos;
3613 for (;;) {
3614 if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
3615 var ch = this$1.input.charCodeAt(this$1.pos);
3616 if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
3617 if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
3618 if (ch === 36) {
3619 this$1.pos += 2;
3620 return this$1.finishToken(types.dollarBraceL)
3621 } else {
3622 ++this$1.pos;
3623 return this$1.finishToken(types.backQuote)
3624 }
3625 }
3626 out += this$1.input.slice(chunkStart, this$1.pos);
3627 return this$1.finishToken(types.template, out)
3628 }
3629 if (ch === 92) { // '\'
3630 out += this$1.input.slice(chunkStart, this$1.pos);
3631 out += this$1.readEscapedChar(true);
3632 chunkStart = this$1.pos;
3633 } else if (isNewLine(ch)) {
3634 out += this$1.input.slice(chunkStart, this$1.pos);
3635 ++this$1.pos;
3636 switch (ch) {
3637 case 13:
3638 if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
3639 case 10:
3640 out += "\n";
3641 break
3642 default:
3643 out += String.fromCharCode(ch);
3644 break
3645 }
3646 if (this$1.options.locations) {
3647 ++this$1.curLine;
3648 this$1.lineStart = this$1.pos;
3649 }
3650 chunkStart = this$1.pos;
3651 } else {
3652 ++this$1.pos;
3653 }
3654 }
3655};
3656
3657// Reads a template token to search for the end, without validating any escape sequences
3658pp$8.readInvalidTemplateToken = function() {
3659 var this$1 = this;
3660
3661 for (; this.pos < this.input.length; this.pos++) {
3662 switch (this$1.input[this$1.pos]) {
3663 case "\\":
3664 ++this$1.pos;
3665 break
3666
3667 case "$":
3668 if (this$1.input[this$1.pos + 1] !== "{") {
3669 break
3670 }
3671 // falls through
3672
3673 case "`":
3674 return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
3675
3676 // no default
3677 }
3678 }
3679 this.raise(this.start, "Unterminated template");
3680};
3681
3682// Used to read escaped characters
3683
3684pp$8.readEscapedChar = function(inTemplate) {
3685 var ch = this.input.charCodeAt(++this.pos);
3686 ++this.pos;
3687 switch (ch) {
3688 case 110: return "\n" // 'n' -> '\n'
3689 case 114: return "\r" // 'r' -> '\r'
3690 case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
3691 case 117: return codePointToString(this.readCodePoint()) // 'u'
3692 case 116: return "\t" // 't' -> '\t'
3693 case 98: return "\b" // 'b' -> '\b'
3694 case 118: return "\u000b" // 'v' -> '\u000b'
3695 case 102: return "\f" // 'f' -> '\f'
3696 case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
3697 case 10: // ' \n'
3698 if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
3699 return ""
3700 default:
3701 if (ch >= 48 && ch <= 55) {
3702 var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
3703 var octal = parseInt(octalStr, 8);
3704 if (octal > 255) {
3705 octalStr = octalStr.slice(0, -1);
3706 octal = parseInt(octalStr, 8);
3707 }
3708 this.pos += octalStr.length - 1;
3709 ch = this.input.charCodeAt(this.pos);
3710 if ((octalStr !== "0" || ch == 56 || ch == 57) && (this.strict || inTemplate)) {
3711 this.invalidStringToken(this.pos - 1 - octalStr.length, "Octal literal in strict mode");
3712 }
3713 return String.fromCharCode(octal)
3714 }
3715 return String.fromCharCode(ch)
3716 }
3717};
3718
3719// Used to read character escape sequences ('\x', '\u', '\U').
3720
3721pp$8.readHexChar = function(len) {
3722 var codePos = this.pos;
3723 var n = this.readInt(16, len);
3724 if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
3725 return n
3726};
3727
3728// Read an identifier, and return it as a string. Sets `this.containsEsc`
3729// to whether the word contained a '\u' escape.
3730//
3731// Incrementally adds only escaped chars, adding other chunks as-is
3732// as a micro-optimization.
3733
3734pp$8.readWord1 = function() {
3735 var this$1 = this;
3736
3737 this.containsEsc = false;
3738 var word = "", first = true, chunkStart = this.pos;
3739 var astral = this.options.ecmaVersion >= 6;
3740 while (this.pos < this.input.length) {
3741 var ch = this$1.fullCharCodeAtPos();
3742 if (isIdentifierChar(ch, astral)) {
3743 this$1.pos += ch <= 0xffff ? 1 : 2;
3744 } else if (ch === 92) { // "\"
3745 this$1.containsEsc = true;
3746 word += this$1.input.slice(chunkStart, this$1.pos);
3747 var escStart = this$1.pos;
3748 if (this$1.input.charCodeAt(++this$1.pos) != 117) // "u"
3749 { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
3750 ++this$1.pos;
3751 var esc = this$1.readCodePoint();
3752 if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
3753 { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
3754 word += codePointToString(esc);
3755 chunkStart = this$1.pos;
3756 } else {
3757 break
3758 }
3759 first = false;
3760 }
3761 return word + this.input.slice(chunkStart, this.pos)
3762};
3763
3764// Read an identifier or keyword token. Will check for reserved
3765// words when necessary.
3766
3767pp$8.readWord = function() {
3768 var word = this.readWord1();
3769 var type = types.name;
3770 if (this.keywords.test(word)) {
3771 if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
3772 type = keywords$1[word];
3773 }
3774 return this.finishToken(type, word)
3775};
3776
3777// Acorn is a tiny, fast JavaScript parser written in JavaScript.
3778//
3779// Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
3780// various contributors and released under an MIT license.
3781//
3782// Git repositories for Acorn are available at
3783//
3784// http://marijnhaverbeke.nl/git/acorn
3785// https://github.com/acornjs/acorn.git
3786//
3787// Please use the [github bug tracker][ghbt] to report issues.
3788//
3789// [ghbt]: https://github.com/acornjs/acorn/issues
3790//
3791// This file defines the main parser interface. The library also comes
3792// with a [error-tolerant parser][dammit] and an
3793// [abstract syntax tree walker][walk], defined in other files.
3794//
3795// [dammit]: acorn_loose.js
3796// [walk]: util/walk.js
3797
3798var version = "5.4.1";
3799
3800// The main exported interface (under `self.acorn` when in the
3801// browser) is a `parse` function that takes a code string and
3802// returns an abstract syntax tree as specified by [Mozilla parser
3803// API][api].
3804//
3805// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
3806
3807function parse(input, options) {
3808 return new Parser(options, input).parse()
3809}
3810
3811// This function tries to parse a single expression at a given
3812// offset in a string. Useful for parsing mixed-language formats
3813// that embed JavaScript expressions.
3814
3815function parseExpressionAt(input, pos, options) {
3816 var p = new Parser(options, input, pos);
3817 p.nextToken();
3818 return p.parseExpression()
3819}
3820
3821// Acorn is organized as a tokenizer and a recursive-descent parser.
3822// The `tokenizer` export provides an interface to the tokenizer.
3823
3824function tokenizer(input, options) {
3825 return new Parser(options, input)
3826}
3827
3828// This is a terrible kludge to support the existing, pre-ES6
3829// interface where the loose parser module retroactively adds exports
3830// to this module.
3831var parse_dammit;
3832var LooseParser;
3833var pluginsLoose; // eslint-disable-line camelcase
3834function addLooseExports(parse, Parser$$1, plugins$$1) {
3835 parse_dammit = parse; // eslint-disable-line camelcase
3836 LooseParser = Parser$$1;
3837 pluginsLoose = plugins$$1;
3838}
3839
3840
3841
3842
3843var acorn = Object.freeze({
3844 version: version,
3845 parse: parse,
3846 parseExpressionAt: parseExpressionAt,
3847 tokenizer: tokenizer,
3848 get parse_dammit () { return parse_dammit; },
3849 get LooseParser () { return LooseParser; },
3850 get pluginsLoose () { return pluginsLoose; },
3851 addLooseExports: addLooseExports,
3852 Parser: Parser,
3853 plugins: plugins,
3854 defaultOptions: defaultOptions,
3855 Position: Position,
3856 SourceLocation: SourceLocation,
3857 getLineInfo: getLineInfo,
3858 Node: Node,
3859 TokenType: TokenType,
3860 tokTypes: types,
3861 keywordTypes: keywords$1,
3862 TokContext: TokContext,
3863 tokContexts: types$1,
3864 isIdentifierChar: isIdentifierChar,
3865 isIdentifierStart: isIdentifierStart,
3866 Token: Token,
3867 isNewLine: isNewLine,
3868 lineBreak: lineBreak,
3869 lineBreakG: lineBreakG,
3870 nonASCIIwhitespace: nonASCIIwhitespace
3871});
3872
3873var xhtml = {
3874 quot: '\u0022',
3875 amp: '&',
3876 apos: '\u0027',
3877 lt: '<',
3878 gt: '>',
3879 nbsp: '\u00A0',
3880 iexcl: '\u00A1',
3881 cent: '\u00A2',
3882 pound: '\u00A3',
3883 curren: '\u00A4',
3884 yen: '\u00A5',
3885 brvbar: '\u00A6',
3886 sect: '\u00A7',
3887 uml: '\u00A8',
3888 copy: '\u00A9',
3889 ordf: '\u00AA',
3890 laquo: '\u00AB',
3891 not: '\u00AC',
3892 shy: '\u00AD',
3893 reg: '\u00AE',
3894 macr: '\u00AF',
3895 deg: '\u00B0',
3896 plusmn: '\u00B1',
3897 sup2: '\u00B2',
3898 sup3: '\u00B3',
3899 acute: '\u00B4',
3900 micro: '\u00B5',
3901 para: '\u00B6',
3902 middot: '\u00B7',
3903 cedil: '\u00B8',
3904 sup1: '\u00B9',
3905 ordm: '\u00BA',
3906 raquo: '\u00BB',
3907 frac14: '\u00BC',
3908 frac12: '\u00BD',
3909 frac34: '\u00BE',
3910 iquest: '\u00BF',
3911 Agrave: '\u00C0',
3912 Aacute: '\u00C1',
3913 Acirc: '\u00C2',
3914 Atilde: '\u00C3',
3915 Auml: '\u00C4',
3916 Aring: '\u00C5',
3917 AElig: '\u00C6',
3918 Ccedil: '\u00C7',
3919 Egrave: '\u00C8',
3920 Eacute: '\u00C9',
3921 Ecirc: '\u00CA',
3922 Euml: '\u00CB',
3923 Igrave: '\u00CC',
3924 Iacute: '\u00CD',
3925 Icirc: '\u00CE',
3926 Iuml: '\u00CF',
3927 ETH: '\u00D0',
3928 Ntilde: '\u00D1',
3929 Ograve: '\u00D2',
3930 Oacute: '\u00D3',
3931 Ocirc: '\u00D4',
3932 Otilde: '\u00D5',
3933 Ouml: '\u00D6',
3934 times: '\u00D7',
3935 Oslash: '\u00D8',
3936 Ugrave: '\u00D9',
3937 Uacute: '\u00DA',
3938 Ucirc: '\u00DB',
3939 Uuml: '\u00DC',
3940 Yacute: '\u00DD',
3941 THORN: '\u00DE',
3942 szlig: '\u00DF',
3943 agrave: '\u00E0',
3944 aacute: '\u00E1',
3945 acirc: '\u00E2',
3946 atilde: '\u00E3',
3947 auml: '\u00E4',
3948 aring: '\u00E5',
3949 aelig: '\u00E6',
3950 ccedil: '\u00E7',
3951 egrave: '\u00E8',
3952 eacute: '\u00E9',
3953 ecirc: '\u00EA',
3954 euml: '\u00EB',
3955 igrave: '\u00EC',
3956 iacute: '\u00ED',
3957 icirc: '\u00EE',
3958 iuml: '\u00EF',
3959 eth: '\u00F0',
3960 ntilde: '\u00F1',
3961 ograve: '\u00F2',
3962 oacute: '\u00F3',
3963 ocirc: '\u00F4',
3964 otilde: '\u00F5',
3965 ouml: '\u00F6',
3966 divide: '\u00F7',
3967 oslash: '\u00F8',
3968 ugrave: '\u00F9',
3969 uacute: '\u00FA',
3970 ucirc: '\u00FB',
3971 uuml: '\u00FC',
3972 yacute: '\u00FD',
3973 thorn: '\u00FE',
3974 yuml: '\u00FF',
3975 OElig: '\u0152',
3976 oelig: '\u0153',
3977 Scaron: '\u0160',
3978 scaron: '\u0161',
3979 Yuml: '\u0178',
3980 fnof: '\u0192',
3981 circ: '\u02C6',
3982 tilde: '\u02DC',
3983 Alpha: '\u0391',
3984 Beta: '\u0392',
3985 Gamma: '\u0393',
3986 Delta: '\u0394',
3987 Epsilon: '\u0395',
3988 Zeta: '\u0396',
3989 Eta: '\u0397',
3990 Theta: '\u0398',
3991 Iota: '\u0399',
3992 Kappa: '\u039A',
3993 Lambda: '\u039B',
3994 Mu: '\u039C',
3995 Nu: '\u039D',
3996 Xi: '\u039E',
3997 Omicron: '\u039F',
3998 Pi: '\u03A0',
3999 Rho: '\u03A1',
4000 Sigma: '\u03A3',
4001 Tau: '\u03A4',
4002 Upsilon: '\u03A5',
4003 Phi: '\u03A6',
4004 Chi: '\u03A7',
4005 Psi: '\u03A8',
4006 Omega: '\u03A9',
4007 alpha: '\u03B1',
4008 beta: '\u03B2',
4009 gamma: '\u03B3',
4010 delta: '\u03B4',
4011 epsilon: '\u03B5',
4012 zeta: '\u03B6',
4013 eta: '\u03B7',
4014 theta: '\u03B8',
4015 iota: '\u03B9',
4016 kappa: '\u03BA',
4017 lambda: '\u03BB',
4018 mu: '\u03BC',
4019 nu: '\u03BD',
4020 xi: '\u03BE',
4021 omicron: '\u03BF',
4022 pi: '\u03C0',
4023 rho: '\u03C1',
4024 sigmaf: '\u03C2',
4025 sigma: '\u03C3',
4026 tau: '\u03C4',
4027 upsilon: '\u03C5',
4028 phi: '\u03C6',
4029 chi: '\u03C7',
4030 psi: '\u03C8',
4031 omega: '\u03C9',
4032 thetasym: '\u03D1',
4033 upsih: '\u03D2',
4034 piv: '\u03D6',
4035 ensp: '\u2002',
4036 emsp: '\u2003',
4037 thinsp: '\u2009',
4038 zwnj: '\u200C',
4039 zwj: '\u200D',
4040 lrm: '\u200E',
4041 rlm: '\u200F',
4042 ndash: '\u2013',
4043 mdash: '\u2014',
4044 lsquo: '\u2018',
4045 rsquo: '\u2019',
4046 sbquo: '\u201A',
4047 ldquo: '\u201C',
4048 rdquo: '\u201D',
4049 bdquo: '\u201E',
4050 dagger: '\u2020',
4051 Dagger: '\u2021',
4052 bull: '\u2022',
4053 hellip: '\u2026',
4054 permil: '\u2030',
4055 prime: '\u2032',
4056 Prime: '\u2033',
4057 lsaquo: '\u2039',
4058 rsaquo: '\u203A',
4059 oline: '\u203E',
4060 frasl: '\u2044',
4061 euro: '\u20AC',
4062 image: '\u2111',
4063 weierp: '\u2118',
4064 real: '\u211C',
4065 trade: '\u2122',
4066 alefsym: '\u2135',
4067 larr: '\u2190',
4068 uarr: '\u2191',
4069 rarr: '\u2192',
4070 darr: '\u2193',
4071 harr: '\u2194',
4072 crarr: '\u21B5',
4073 lArr: '\u21D0',
4074 uArr: '\u21D1',
4075 rArr: '\u21D2',
4076 dArr: '\u21D3',
4077 hArr: '\u21D4',
4078 forall: '\u2200',
4079 part: '\u2202',
4080 exist: '\u2203',
4081 empty: '\u2205',
4082 nabla: '\u2207',
4083 isin: '\u2208',
4084 notin: '\u2209',
4085 ni: '\u220B',
4086 prod: '\u220F',
4087 sum: '\u2211',
4088 minus: '\u2212',
4089 lowast: '\u2217',
4090 radic: '\u221A',
4091 prop: '\u221D',
4092 infin: '\u221E',
4093 ang: '\u2220',
4094 and: '\u2227',
4095 or: '\u2228',
4096 cap: '\u2229',
4097 cup: '\u222A',
4098 'int': '\u222B',
4099 there4: '\u2234',
4100 sim: '\u223C',
4101 cong: '\u2245',
4102 asymp: '\u2248',
4103 ne: '\u2260',
4104 equiv: '\u2261',
4105 le: '\u2264',
4106 ge: '\u2265',
4107 sub: '\u2282',
4108 sup: '\u2283',
4109 nsub: '\u2284',
4110 sube: '\u2286',
4111 supe: '\u2287',
4112 oplus: '\u2295',
4113 otimes: '\u2297',
4114 perp: '\u22A5',
4115 sdot: '\u22C5',
4116 lceil: '\u2308',
4117 rceil: '\u2309',
4118 lfloor: '\u230A',
4119 rfloor: '\u230B',
4120 lang: '\u2329',
4121 rang: '\u232A',
4122 loz: '\u25CA',
4123 spades: '\u2660',
4124 clubs: '\u2663',
4125 hearts: '\u2665',
4126 diams: '\u2666'
4127};
4128
4129var hexNumber = /^[\da-fA-F]+$/;
4130var decimalNumber = /^\d+$/;
4131
4132var inject = function(acorn) {
4133 var tt = acorn.tokTypes;
4134 var tc = acorn.tokContexts;
4135
4136 tc.j_oTag = new acorn.TokContext('<tag', false);
4137 tc.j_cTag = new acorn.TokContext('</tag', false);
4138 tc.j_expr = new acorn.TokContext('<tag>...</tag>', true, true);
4139
4140 tt.jsxName = new acorn.TokenType('jsxName');
4141 tt.jsxText = new acorn.TokenType('jsxText', {beforeExpr: true});
4142 tt.jsxTagStart = new acorn.TokenType('jsxTagStart');
4143 tt.jsxTagEnd = new acorn.TokenType('jsxTagEnd');
4144
4145 tt.jsxTagStart.updateContext = function() {
4146 this.context.push(tc.j_expr); // treat as beginning of JSX expression
4147 this.context.push(tc.j_oTag); // start opening tag context
4148 this.exprAllowed = false;
4149 };
4150 tt.jsxTagEnd.updateContext = function(prevType) {
4151 var out = this.context.pop();
4152 if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) {
4153 this.context.pop();
4154 this.exprAllowed = this.curContext() === tc.j_expr;
4155 } else {
4156 this.exprAllowed = true;
4157 }
4158 };
4159
4160 var pp = acorn.Parser.prototype;
4161
4162 // Reads inline JSX contents token.
4163
4164 pp.jsx_readToken = function() {
4165 var out = '', chunkStart = this.pos;
4166 for (;;) {
4167 if (this.pos >= this.input.length)
4168 this.raise(this.start, 'Unterminated JSX contents');
4169 var ch = this.input.charCodeAt(this.pos);
4170
4171 switch (ch) {
4172 case 60: // '<'
4173 case 123: // '{'
4174 if (this.pos === this.start) {
4175 if (ch === 60 && this.exprAllowed) {
4176 ++this.pos;
4177 return this.finishToken(tt.jsxTagStart);
4178 }
4179 return this.getTokenFromCode(ch);
4180 }
4181 out += this.input.slice(chunkStart, this.pos);
4182 return this.finishToken(tt.jsxText, out);
4183
4184 case 38: // '&'
4185 out += this.input.slice(chunkStart, this.pos);
4186 out += this.jsx_readEntity();
4187 chunkStart = this.pos;
4188 break;
4189
4190 default:
4191 if (acorn.isNewLine(ch)) {
4192 out += this.input.slice(chunkStart, this.pos);
4193 out += this.jsx_readNewLine(true);
4194 chunkStart = this.pos;
4195 } else {
4196 ++this.pos;
4197 }
4198 }
4199 }
4200 };
4201
4202 pp.jsx_readNewLine = function(normalizeCRLF) {
4203 var ch = this.input.charCodeAt(this.pos);
4204 var out;
4205 ++this.pos;
4206 if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
4207 ++this.pos;
4208 out = normalizeCRLF ? '\n' : '\r\n';
4209 } else {
4210 out = String.fromCharCode(ch);
4211 }
4212 if (this.options.locations) {
4213 ++this.curLine;
4214 this.lineStart = this.pos;
4215 }
4216
4217 return out;
4218 };
4219
4220 pp.jsx_readString = function(quote) {
4221 var out = '', chunkStart = ++this.pos;
4222 for (;;) {
4223 if (this.pos >= this.input.length)
4224 this.raise(this.start, 'Unterminated string constant');
4225 var ch = this.input.charCodeAt(this.pos);
4226 if (ch === quote) break;
4227 if (ch === 38) { // '&'
4228 out += this.input.slice(chunkStart, this.pos);
4229 out += this.jsx_readEntity();
4230 chunkStart = this.pos;
4231 } else if (acorn.isNewLine(ch)) {
4232 out += this.input.slice(chunkStart, this.pos);
4233 out += this.jsx_readNewLine(false);
4234 chunkStart = this.pos;
4235 } else {
4236 ++this.pos;
4237 }
4238 }
4239 out += this.input.slice(chunkStart, this.pos++);
4240 return this.finishToken(tt.string, out);
4241 };
4242
4243 pp.jsx_readEntity = function() {
4244 var str = '', count = 0, entity;
4245 var ch = this.input[this.pos];
4246 if (ch !== '&')
4247 this.raise(this.pos, 'Entity must start with an ampersand');
4248 var startPos = ++this.pos;
4249 while (this.pos < this.input.length && count++ < 10) {
4250 ch = this.input[this.pos++];
4251 if (ch === ';') {
4252 if (str[0] === '#') {
4253 if (str[1] === 'x') {
4254 str = str.substr(2);
4255 if (hexNumber.test(str))
4256 entity = String.fromCharCode(parseInt(str, 16));
4257 } else {
4258 str = str.substr(1);
4259 if (decimalNumber.test(str))
4260 entity = String.fromCharCode(parseInt(str, 10));
4261 }
4262 } else {
4263 entity = xhtml[str];
4264 }
4265 break;
4266 }
4267 str += ch;
4268 }
4269 if (!entity) {
4270 this.pos = startPos;
4271 return '&';
4272 }
4273 return entity;
4274 };
4275
4276
4277 // Read a JSX identifier (valid tag or attribute name).
4278 //
4279 // Optimized version since JSX identifiers can't contain
4280 // escape characters and so can be read as single slice.
4281 // Also assumes that first character was already checked
4282 // by isIdentifierStart in readToken.
4283
4284 pp.jsx_readWord = function() {
4285 var ch, start = this.pos;
4286 do {
4287 ch = this.input.charCodeAt(++this.pos);
4288 } while (acorn.isIdentifierChar(ch) || ch === 45); // '-'
4289 return this.finishToken(tt.jsxName, this.input.slice(start, this.pos));
4290 };
4291
4292 // Transforms JSX element name to string.
4293
4294 function getQualifiedJSXName(object) {
4295 if (!object)
4296 return object;
4297
4298 if (object.type === 'JSXIdentifier')
4299 return object.name;
4300
4301 if (object.type === 'JSXNamespacedName')
4302 return object.namespace.name + ':' + object.name.name;
4303
4304 if (object.type === 'JSXMemberExpression')
4305 return getQualifiedJSXName(object.object) + '.' +
4306 getQualifiedJSXName(object.property);
4307 }
4308
4309 // Parse next token as JSX identifier
4310
4311 pp.jsx_parseIdentifier = function() {
4312 var node = this.startNode();
4313 if (this.type === tt.jsxName)
4314 node.name = this.value;
4315 else if (this.type.keyword)
4316 node.name = this.type.keyword;
4317 else
4318 this.unexpected();
4319 this.next();
4320 return this.finishNode(node, 'JSXIdentifier');
4321 };
4322
4323 // Parse namespaced identifier.
4324
4325 pp.jsx_parseNamespacedName = function() {
4326 var startPos = this.start, startLoc = this.startLoc;
4327 var name = this.jsx_parseIdentifier();
4328 if (!this.options.plugins.jsx.allowNamespaces || !this.eat(tt.colon)) return name;
4329 var node = this.startNodeAt(startPos, startLoc);
4330 node.namespace = name;
4331 node.name = this.jsx_parseIdentifier();
4332 return this.finishNode(node, 'JSXNamespacedName');
4333 };
4334
4335 // Parses element name in any form - namespaced, member
4336 // or single identifier.
4337
4338 pp.jsx_parseElementName = function() {
4339 if (this.type === tt.jsxTagEnd)
4340 return '';
4341 var startPos = this.start, startLoc = this.startLoc;
4342 var node = this.jsx_parseNamespacedName();
4343 if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !this.options.plugins.jsx.allowNamespacedObjects) {
4344 this.unexpected();
4345 }
4346 while (this.eat(tt.dot)) {
4347 var newNode = this.startNodeAt(startPos, startLoc);
4348 newNode.object = node;
4349 newNode.property = this.jsx_parseIdentifier();
4350 node = this.finishNode(newNode, 'JSXMemberExpression');
4351 }
4352 return node;
4353 };
4354
4355 // Parses any type of JSX attribute value.
4356
4357 pp.jsx_parseAttributeValue = function() {
4358 switch (this.type) {
4359 case tt.braceL:
4360 var node = this.jsx_parseExpressionContainer();
4361 if (node.expression.type === 'JSXEmptyExpression')
4362 this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression');
4363 return node;
4364
4365 case tt.jsxTagStart:
4366 case tt.string:
4367 return this.parseExprAtom();
4368
4369 default:
4370 this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
4371 }
4372 };
4373
4374 // JSXEmptyExpression is unique type since it doesn't actually parse anything,
4375 // and so it should start at the end of last read token (left brace) and finish
4376 // at the beginning of the next one (right brace).
4377
4378 pp.jsx_parseEmptyExpression = function() {
4379 var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
4380 return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
4381 };
4382
4383 // Parses JSX expression enclosed into curly brackets.
4384
4385
4386 pp.jsx_parseExpressionContainer = function() {
4387 var node = this.startNode();
4388 this.next();
4389 node.expression = this.type === tt.braceR
4390 ? this.jsx_parseEmptyExpression()
4391 : this.parseExpression();
4392 this.expect(tt.braceR);
4393 return this.finishNode(node, 'JSXExpressionContainer');
4394 };
4395
4396 // Parses following JSX attribute name-value pair.
4397
4398 pp.jsx_parseAttribute = function() {
4399 var node = this.startNode();
4400 if (this.eat(tt.braceL)) {
4401 this.expect(tt.ellipsis);
4402 node.argument = this.parseMaybeAssign();
4403 this.expect(tt.braceR);
4404 return this.finishNode(node, 'JSXSpreadAttribute');
4405 }
4406 node.name = this.jsx_parseNamespacedName();
4407 node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
4408 return this.finishNode(node, 'JSXAttribute');
4409 };
4410
4411 // Parses JSX opening tag starting after '<'.
4412
4413 pp.jsx_parseOpeningElementAt = function(startPos, startLoc) {
4414 var node = this.startNodeAt(startPos, startLoc);
4415 node.attributes = [];
4416 var nodeName = this.jsx_parseElementName();
4417 if (nodeName) node.name = nodeName;
4418 while (this.type !== tt.slash && this.type !== tt.jsxTagEnd)
4419 node.attributes.push(this.jsx_parseAttribute());
4420 node.selfClosing = this.eat(tt.slash);
4421 this.expect(tt.jsxTagEnd);
4422 return this.finishNode(node, nodeName ? 'JSXOpeningElement' : 'JSXOpeningFragment');
4423 };
4424
4425 // Parses JSX closing tag starting after '</'.
4426
4427 pp.jsx_parseClosingElementAt = function(startPos, startLoc) {
4428 var node = this.startNodeAt(startPos, startLoc);
4429 var nodeName = this.jsx_parseElementName();
4430 if (nodeName) node.name = nodeName;
4431 this.expect(tt.jsxTagEnd);
4432 return this.finishNode(node, nodeName ? 'JSXClosingElement' : 'JSXClosingFragment');
4433 };
4434
4435 // Parses entire JSX element, including it's opening tag
4436 // (starting after '<'), attributes, contents and closing tag.
4437
4438 pp.jsx_parseElementAt = function(startPos, startLoc) {
4439 var node = this.startNodeAt(startPos, startLoc);
4440 var children = [];
4441 var openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
4442 var closingElement = null;
4443
4444 if (!openingElement.selfClosing) {
4445 contents: for (;;) {
4446 switch (this.type) {
4447 case tt.jsxTagStart:
4448 startPos = this.start; startLoc = this.startLoc;
4449 this.next();
4450 if (this.eat(tt.slash)) {
4451 closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
4452 break contents;
4453 }
4454 children.push(this.jsx_parseElementAt(startPos, startLoc));
4455 break;
4456
4457 case tt.jsxText:
4458 children.push(this.parseExprAtom());
4459 break;
4460
4461 case tt.braceL:
4462 children.push(this.jsx_parseExpressionContainer());
4463 break;
4464
4465 default:
4466 this.unexpected();
4467 }
4468 }
4469 if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
4470 this.raise(
4471 closingElement.start,
4472 'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
4473 }
4474 }
4475
4476 node.openingElement = openingElement;
4477 node.closingElement = closingElement;
4478 node.children = children;
4479 if (this.type === tt.relational && this.value === "<") {
4480 this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
4481 }
4482 return this.finishNode(node, openingElement.name ? 'JSXElement' : 'JSXFragment');
4483 };
4484
4485 // Parse JSX text
4486
4487 pp.jsx_parseText = function(value) {
4488 var node = this.parseLiteral(value);
4489 node.type = "JSXText";
4490
4491 return node;
4492 };
4493
4494 // Parses entire JSX element from current position.
4495
4496 pp.jsx_parseElement = function() {
4497 var startPos = this.start, startLoc = this.startLoc;
4498 this.next();
4499 return this.jsx_parseElementAt(startPos, startLoc);
4500 };
4501
4502 acorn.plugins.jsx = function(instance, opts) {
4503 if (!opts) {
4504 return;
4505 }
4506
4507 if (typeof opts !== 'object') {
4508 opts = {};
4509 }
4510
4511 instance.options.plugins.jsx = {
4512 allowNamespaces: opts.allowNamespaces !== false,
4513 allowNamespacedObjects: !!opts.allowNamespacedObjects
4514 };
4515
4516 instance.extend('parseExprAtom', function(inner) {
4517 return function(refShortHandDefaultPos) {
4518 if (this.type === tt.jsxText)
4519 return this.jsx_parseText(this.value);
4520 else if (this.type === tt.jsxTagStart)
4521 return this.jsx_parseElement();
4522 else
4523 return inner.call(this, refShortHandDefaultPos);
4524 };
4525 });
4526
4527 instance.extend('readToken', function(inner) {
4528 return function(code) {
4529 var context = this.curContext();
4530
4531 if (context === tc.j_expr) return this.jsx_readToken();
4532
4533 if (context === tc.j_oTag || context === tc.j_cTag) {
4534 if (acorn.isIdentifierStart(code)) return this.jsx_readWord();
4535
4536 if (code == 62) {
4537 ++this.pos;
4538 return this.finishToken(tt.jsxTagEnd);
4539 }
4540
4541 if ((code === 34 || code === 39) && context == tc.j_oTag)
4542 return this.jsx_readString(code);
4543 }
4544
4545 if (code === 60 && this.exprAllowed && this.input.charCodeAt(this.pos + 1) !== 33) {
4546 ++this.pos;
4547 return this.finishToken(tt.jsxTagStart);
4548 }
4549 return inner.call(this, code);
4550 };
4551 });
4552
4553 instance.extend('updateContext', function(inner) {
4554 return function(prevType) {
4555 if (this.type == tt.braceL) {
4556 var curContext = this.curContext();
4557 if (curContext == tc.j_oTag) this.context.push(tc.b_expr);
4558 else if (curContext == tc.j_expr) this.context.push(tc.b_tmpl);
4559 else inner.call(this, prevType);
4560 this.exprAllowed = true;
4561 } else if (this.type === tt.slash && prevType === tt.jsxTagStart) {
4562 this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
4563 this.context.push(tc.j_cTag); // reconsider as closing tag context
4564 this.exprAllowed = false;
4565 } else {
4566 return inner.call(this, prevType);
4567 }
4568 };
4569 });
4570 };
4571
4572 return acorn;
4573};
4574
4575var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
4576
4577function commonjsRequire () {
4578 throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
4579}
4580
4581function unwrapExports (x) {
4582 return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
4583}
4584
4585function createCommonjsModule(fn, module) {
4586 return module = { exports: {} }, fn(module, module.exports), module.exports;
4587}
4588
4589var inject$1 = createCommonjsModule(function (module, exports) {
4590Object.defineProperty(exports, "__esModule", {
4591 value: true
4592});
4593exports['default'] = injectDynamicImport;
4594/* eslint-disable no-underscore-dangle */
4595
4596var DynamicImportKey = exports.DynamicImportKey = 'Import';
4597
4598function injectDynamicImport(acorn) {
4599 var tt = acorn.tokTypes;
4600
4601 // NOTE: This allows `yield import()` to parse correctly.
4602 tt._import.startsExpr = true;
4603
4604 function parseDynamicImport() {
4605 var node = this.startNode();
4606 this.next();
4607 if (this.type !== tt.parenL) {
4608 this.unexpected();
4609 }
4610 return this.finishNode(node, DynamicImportKey);
4611 }
4612
4613 function peekNext() {
4614 return this.input[this.pos];
4615 }
4616
4617 // eslint-disable-next-line no-param-reassign
4618 acorn.plugins.dynamicImport = function () {
4619 function dynamicImportPlugin(instance) {
4620 instance.extend('parseStatement', function (nextMethod) {
4621 return function () {
4622 function parseStatement() {
4623 var node = this.startNode();
4624 if (this.type === tt._import) {
4625 var nextToken = peekNext.call(this);
4626 if (nextToken === tt.parenL.label) {
4627 var expr = this.parseExpression();
4628 return this.parseExpressionStatement(node, expr);
4629 }
4630 }
4631
4632 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
4633 args[_key] = arguments[_key];
4634 }
4635
4636 return nextMethod.apply(this, args);
4637 }
4638
4639 return parseStatement;
4640 }();
4641 });
4642
4643 instance.extend('parseExprAtom', function (nextMethod) {
4644 return function () {
4645 function parseExprAtom(refDestructuringErrors) {
4646 if (this.type === tt._import) {
4647 return parseDynamicImport.call(this);
4648 }
4649 return nextMethod.call(this, refDestructuringErrors);
4650 }
4651
4652 return parseExprAtom;
4653 }();
4654 });
4655 }
4656
4657 return dynamicImportPlugin;
4658 }();
4659
4660 return acorn;
4661}
4662});
4663
4664var acornDynamicImport = unwrapExports(inject$1);
4665var inject_1 = inject$1.DynamicImportKey;
4666
4667var integerToChar = {};
4668
4669'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
4670 integerToChar[ i ] = char;
4671});
4672
4673
4674
4675function encode ( value ) {
4676 var result;
4677
4678 if ( typeof value === 'number' ) {
4679 result = encodeInteger( value );
4680 } else {
4681 result = '';
4682 for ( var i = 0; i < value.length; i += 1 ) {
4683 result += encodeInteger( value[i] );
4684 }
4685 }
4686
4687 return result;
4688}
4689
4690function encodeInteger ( num ) {
4691 var result = '';
4692
4693 if ( num < 0 ) {
4694 num = ( -num << 1 ) | 1;
4695 } else {
4696 num <<= 1;
4697 }
4698
4699 do {
4700 var clamped = num & 31;
4701 num >>= 5;
4702
4703 if ( num > 0 ) {
4704 clamped |= 32;
4705 }
4706
4707 result += integerToChar[ clamped ];
4708 } while ( num > 0 );
4709
4710 return result;
4711}
4712
4713function Chunk ( start, end, content ) {
4714 this.start = start;
4715 this.end = end;
4716 this.original = content;
4717
4718 this.intro = '';
4719 this.outro = '';
4720
4721 this.content = content;
4722 this.storeName = false;
4723 this.edited = false;
4724
4725 // we make these non-enumerable, for sanity while debugging
4726 Object.defineProperties( this, {
4727 previous: { writable: true, value: null },
4728 next: { writable: true, value: null }
4729 });
4730}
4731
4732Chunk.prototype = {
4733 appendLeft: function appendLeft ( content ) {
4734 this.outro += content;
4735 },
4736
4737 appendRight: function appendRight ( content ) {
4738 this.intro = this.intro + content;
4739 },
4740
4741 clone: function clone () {
4742 var chunk = new Chunk( this.start, this.end, this.original );
4743
4744 chunk.intro = this.intro;
4745 chunk.outro = this.outro;
4746 chunk.content = this.content;
4747 chunk.storeName = this.storeName;
4748 chunk.edited = this.edited;
4749
4750 return chunk;
4751 },
4752
4753 contains: function contains ( index ) {
4754 return this.start < index && index < this.end;
4755 },
4756
4757 eachNext: function eachNext ( fn ) {
4758 var chunk = this;
4759 while ( chunk ) {
4760 fn( chunk );
4761 chunk = chunk.next;
4762 }
4763 },
4764
4765 eachPrevious: function eachPrevious ( fn ) {
4766 var chunk = this;
4767 while ( chunk ) {
4768 fn( chunk );
4769 chunk = chunk.previous;
4770 }
4771 },
4772
4773 edit: function edit ( content, storeName, contentOnly ) {
4774 this.content = content;
4775 if ( !contentOnly ) {
4776 this.intro = '';
4777 this.outro = '';
4778 }
4779 this.storeName = storeName;
4780
4781 this.edited = true;
4782
4783 return this;
4784 },
4785
4786 prependLeft: function prependLeft ( content ) {
4787 this.outro = content + this.outro;
4788 },
4789
4790 prependRight: function prependRight ( content ) {
4791 this.intro = content + this.intro;
4792 },
4793
4794 split: function split ( index ) {
4795 var sliceIndex = index - this.start;
4796
4797 var originalBefore = this.original.slice( 0, sliceIndex );
4798 var originalAfter = this.original.slice( sliceIndex );
4799
4800 this.original = originalBefore;
4801
4802 var newChunk = new Chunk( index, this.end, originalAfter );
4803 newChunk.outro = this.outro;
4804 this.outro = '';
4805
4806 this.end = index;
4807
4808 if ( this.edited ) {
4809 // TODO is this block necessary?...
4810 newChunk.edit( '', false );
4811 this.content = '';
4812 } else {
4813 this.content = originalBefore;
4814 }
4815
4816 newChunk.next = this.next;
4817 if ( newChunk.next ) { newChunk.next.previous = newChunk; }
4818 newChunk.previous = this;
4819 this.next = newChunk;
4820
4821 return newChunk;
4822 },
4823
4824 toString: function toString () {
4825 return this.intro + this.content + this.outro;
4826 },
4827
4828 trimEnd: function trimEnd ( rx ) {
4829 this.outro = this.outro.replace( rx, '' );
4830 if ( this.outro.length ) { return true; }
4831
4832 var trimmed = this.content.replace( rx, '' );
4833
4834 if ( trimmed.length ) {
4835 if ( trimmed !== this.content ) {
4836 this.split( this.start + trimmed.length ).edit( '', false );
4837 }
4838
4839 return true;
4840 } else {
4841 this.edit( '', false );
4842
4843 this.intro = this.intro.replace( rx, '' );
4844 if ( this.intro.length ) { return true; }
4845 }
4846 },
4847
4848 trimStart: function trimStart ( rx ) {
4849 this.intro = this.intro.replace( rx, '' );
4850 if ( this.intro.length ) { return true; }
4851
4852 var trimmed = this.content.replace( rx, '' );
4853
4854 if ( trimmed.length ) {
4855 if ( trimmed !== this.content ) {
4856 this.split( this.end - trimmed.length );
4857 this.edit( '', false );
4858 }
4859
4860 return true;
4861 } else {
4862 this.edit( '', false );
4863
4864 this.outro = this.outro.replace( rx, '' );
4865 if ( this.outro.length ) { return true; }
4866 }
4867 }
4868};
4869
4870var _btoa;
4871
4872if ( typeof window !== 'undefined' && typeof window.btoa === 'function' ) {
4873 _btoa = window.btoa;
4874} else if ( typeof Buffer === 'function' ) {
4875 _btoa = function (str) { return new Buffer( str ).toString( 'base64' ); };
4876} else {
4877 _btoa = function () {
4878 throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
4879 };
4880}
4881
4882var btoa = _btoa;
4883
4884function SourceMap ( properties ) {
4885 this.version = 3;
4886
4887 this.file = properties.file;
4888 this.sources = properties.sources;
4889 this.sourcesContent = properties.sourcesContent;
4890 this.names = properties.names;
4891 this.mappings = properties.mappings;
4892}
4893
4894SourceMap.prototype = {
4895 toString: function toString () {
4896 return JSON.stringify( this );
4897 },
4898
4899 toUrl: function toUrl () {
4900 return 'data:application/json;charset=utf-8;base64,' + btoa( this.toString() );
4901 }
4902};
4903
4904function guessIndent ( code ) {
4905 var lines = code.split( '\n' );
4906
4907 var tabbed = lines.filter( function (line) { return /^\t+/.test( line ); } );
4908 var spaced = lines.filter( function (line) { return /^ {2,}/.test( line ); } );
4909
4910 if ( tabbed.length === 0 && spaced.length === 0 ) {
4911 return null;
4912 }
4913
4914 // More lines tabbed than spaced? Assume tabs, and
4915 // default to tabs in the case of a tie (or nothing
4916 // to go on)
4917 if ( tabbed.length >= spaced.length ) {
4918 return '\t';
4919 }
4920
4921 // Otherwise, we need to guess the multiple
4922 var min = spaced.reduce( function ( previous, current ) {
4923 var numSpaces = /^ +/.exec( current )[0].length;
4924 return Math.min( numSpaces, previous );
4925 }, Infinity );
4926
4927 return new Array( min + 1 ).join( ' ' );
4928}
4929
4930function getRelativePath ( from, to ) {
4931 var fromParts = from.split( /[\/\\]/ );
4932 var toParts = to.split( /[\/\\]/ );
4933
4934 fromParts.pop(); // get dirname
4935
4936 while ( fromParts[0] === toParts[0] ) {
4937 fromParts.shift();
4938 toParts.shift();
4939 }
4940
4941 if ( fromParts.length ) {
4942 var i = fromParts.length;
4943 while ( i-- ) { fromParts[i] = '..'; }
4944 }
4945
4946 return fromParts.concat( toParts ).join( '/' );
4947}
4948
4949var toString$1 = Object.prototype.toString;
4950
4951function isObject ( thing ) {
4952 return toString$1.call( thing ) === '[object Object]';
4953}
4954
4955function getLocator ( source ) {
4956 var originalLines = source.split( '\n' );
4957
4958 var start = 0;
4959 var lineRanges = originalLines.map( function ( line, i ) {
4960 var end = start + line.length + 1;
4961 var range = { start: start, end: end, line: i };
4962
4963 start = end;
4964 return range;
4965 });
4966
4967 var i = 0;
4968
4969 function rangeContains ( range, index ) {
4970 return range.start <= index && index < range.end;
4971 }
4972
4973 function getLocation ( range, index ) {
4974 return { line: range.line, column: index - range.start };
4975 }
4976
4977 return function locate ( index ) {
4978 var range = lineRanges[i];
4979
4980 var d = index >= range.end ? 1 : -1;
4981
4982 while ( range ) {
4983 if ( rangeContains( range, index ) ) { return getLocation( range, index ); }
4984
4985 i += d;
4986 range = lineRanges[i];
4987 }
4988 };
4989}
4990
4991function Mappings ( hires ) {
4992 var this$1 = this;
4993
4994 var offsets = {
4995 generatedCodeColumn: 0,
4996 sourceIndex: 0,
4997 sourceCodeLine: 0,
4998 sourceCodeColumn: 0,
4999 sourceCodeName: 0
5000 };
5001
5002 var generatedCodeLine = 0;
5003 var generatedCodeColumn = 0;
5004
5005 this.raw = [];
5006 var rawSegments = this.raw[ generatedCodeLine ] = [];
5007
5008 var pending = null;
5009
5010 this.addEdit = function ( sourceIndex, content, original, loc, nameIndex ) {
5011 if ( content.length ) {
5012 rawSegments.push([
5013 generatedCodeColumn,
5014 sourceIndex,
5015 loc.line,
5016 loc.column,
5017 nameIndex ]);
5018 } else if ( pending ) {
5019 rawSegments.push( pending );
5020 }
5021
5022 this$1.advance( content );
5023 pending = null;
5024 };
5025
5026 this.addUneditedChunk = function ( sourceIndex, chunk, original, loc, sourcemapLocations ) {
5027 var originalCharIndex = chunk.start;
5028 var first = true;
5029
5030 while ( originalCharIndex < chunk.end ) {
5031 if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {
5032 rawSegments.push([
5033 generatedCodeColumn,
5034 sourceIndex,
5035 loc.line,
5036 loc.column,
5037 -1
5038 ]);
5039 }
5040
5041 if ( original[ originalCharIndex ] === '\n' ) {
5042 loc.line += 1;
5043 loc.column = 0;
5044 generatedCodeLine += 1;
5045 this$1.raw[ generatedCodeLine ] = rawSegments = [];
5046 generatedCodeColumn = 0;
5047 } else {
5048 loc.column += 1;
5049 generatedCodeColumn += 1;
5050 }
5051
5052 originalCharIndex += 1;
5053 first = false;
5054 }
5055
5056 pending = [
5057 generatedCodeColumn,
5058 sourceIndex,
5059 loc.line,
5060 loc.column,
5061 -1 ];
5062 };
5063
5064 this.advance = function (str) {
5065 if ( !str ) { return; }
5066
5067 var lines = str.split( '\n' );
5068 var lastLine = lines.pop();
5069
5070 if ( lines.length ) {
5071 generatedCodeLine += lines.length;
5072 this$1.raw[ generatedCodeLine ] = rawSegments = [];
5073 generatedCodeColumn = lastLine.length;
5074 } else {
5075 generatedCodeColumn += lastLine.length;
5076 }
5077 };
5078
5079 this.encode = function () {
5080 return this$1.raw.map( function (segments) {
5081 var generatedCodeColumn = 0;
5082
5083 return segments.map( function (segment) {
5084 var arr = [
5085 segment[0] - generatedCodeColumn,
5086 segment[1] - offsets.sourceIndex,
5087 segment[2] - offsets.sourceCodeLine,
5088 segment[3] - offsets.sourceCodeColumn
5089 ];
5090
5091 generatedCodeColumn = segment[0];
5092 offsets.sourceIndex = segment[1];
5093 offsets.sourceCodeLine = segment[2];
5094 offsets.sourceCodeColumn = segment[3];
5095
5096 if ( ~segment[4] ) {
5097 arr.push( segment[4] - offsets.sourceCodeName );
5098 offsets.sourceCodeName = segment[4];
5099 }
5100
5101 return encode( arr );
5102 }).join( ',' );
5103 }).join( ';' );
5104 };
5105}
5106
5107var warned = {
5108 insertLeft: false,
5109 insertRight: false,
5110 storeName: false
5111};
5112
5113function MagicString$1 ( string, options ) {
5114 if ( options === void 0 ) options = {};
5115
5116 var chunk = new Chunk( 0, string.length, string );
5117
5118 Object.defineProperties( this, {
5119 original: { writable: true, value: string },
5120 outro: { writable: true, value: '' },
5121 intro: { writable: true, value: '' },
5122 firstChunk: { writable: true, value: chunk },
5123 lastChunk: { writable: true, value: chunk },
5124 lastSearchedChunk: { writable: true, value: chunk },
5125 byStart: { writable: true, value: {} },
5126 byEnd: { writable: true, value: {} },
5127 filename: { writable: true, value: options.filename },
5128 indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
5129 sourcemapLocations: { writable: true, value: {} },
5130 storedNames: { writable: true, value: {} },
5131 indentStr: { writable: true, value: guessIndent( string ) }
5132 });
5133
5134 this.byStart[ 0 ] = chunk;
5135 this.byEnd[ string.length ] = chunk;
5136}
5137
5138MagicString$1.prototype = {
5139 addSourcemapLocation: function addSourcemapLocation ( char ) {
5140 this.sourcemapLocations[ char ] = true;
5141 },
5142
5143 append: function append ( content ) {
5144 if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
5145
5146 this.outro += content;
5147 return this;
5148 },
5149
5150 appendLeft: function appendLeft ( index, content ) {
5151 if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
5152
5153 this._split( index );
5154
5155 var chunk = this.byEnd[ index ];
5156
5157 if ( chunk ) {
5158 chunk.appendLeft( content );
5159 } else {
5160 this.intro += content;
5161 }
5162
5163 return this;
5164 },
5165
5166 appendRight: function appendRight ( index, content ) {
5167 if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
5168
5169 this._split( index );
5170
5171 var chunk = this.byStart[ index ];
5172
5173 if ( chunk ) {
5174 chunk.appendRight( content );
5175 } else {
5176 this.outro += content;
5177 }
5178
5179 return this;
5180 },
5181
5182 clone: function clone () {
5183 var cloned = new MagicString$1( this.original, { filename: this.filename });
5184
5185 var originalChunk = this.firstChunk;
5186 var clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
5187
5188 while ( originalChunk ) {
5189 cloned.byStart[ clonedChunk.start ] = clonedChunk;
5190 cloned.byEnd[ clonedChunk.end ] = clonedChunk;
5191
5192 var nextOriginalChunk = originalChunk.next;
5193 var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
5194
5195 if ( nextClonedChunk ) {
5196 clonedChunk.next = nextClonedChunk;
5197 nextClonedChunk.previous = clonedChunk;
5198
5199 clonedChunk = nextClonedChunk;
5200 }
5201
5202 originalChunk = nextOriginalChunk;
5203 }
5204
5205 cloned.lastChunk = clonedChunk;
5206
5207 if ( this.indentExclusionRanges ) {
5208 cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
5209 }
5210
5211 Object.keys( this.sourcemapLocations ).forEach( function (loc) {
5212 cloned.sourcemapLocations[ loc ] = true;
5213 });
5214
5215 return cloned;
5216 },
5217
5218 generateMap: function generateMap ( options ) {
5219 var this$1 = this;
5220
5221 options = options || {};
5222
5223 var sourceIndex = 0;
5224 var names = Object.keys( this.storedNames );
5225 var mappings = new Mappings( options.hires );
5226
5227 var locate = getLocator( this.original );
5228
5229 if ( this.intro ) {
5230 mappings.advance( this.intro );
5231 }
5232
5233 this.firstChunk.eachNext( function (chunk) {
5234 var loc = locate( chunk.start );
5235
5236 if ( chunk.intro.length ) { mappings.advance( chunk.intro ); }
5237
5238 if ( chunk.edited ) {
5239 mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
5240 } else {
5241 mappings.addUneditedChunk( sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations );
5242 }
5243
5244 if ( chunk.outro.length ) { mappings.advance( chunk.outro ); }
5245 });
5246
5247 var map = new SourceMap({
5248 file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
5249 sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],
5250 sourcesContent: options.includeContent ? [ this.original ] : [ null ],
5251 names: names,
5252 mappings: mappings.encode()
5253 });
5254 return map;
5255 },
5256
5257 getIndentString: function getIndentString () {
5258 return this.indentStr === null ? '\t' : this.indentStr;
5259 },
5260
5261 indent: function indent ( indentStr, options ) {
5262 var this$1 = this;
5263
5264 var pattern = /^[^\r\n]/gm;
5265
5266 if ( isObject( indentStr ) ) {
5267 options = indentStr;
5268 indentStr = undefined;
5269 }
5270
5271 indentStr = indentStr !== undefined ? indentStr : ( this.indentStr || '\t' );
5272
5273 if ( indentStr === '' ) { return this; } // noop
5274
5275 options = options || {};
5276
5277 // Process exclusion ranges
5278 var isExcluded = {};
5279
5280 if ( options.exclude ) {
5281 var exclusions = typeof options.exclude[0] === 'number' ? [ options.exclude ] : options.exclude;
5282 exclusions.forEach( function (exclusion) {
5283 for ( var i = exclusion[0]; i < exclusion[1]; i += 1 ) {
5284 isExcluded[i] = true;
5285 }
5286 });
5287 }
5288
5289 var shouldIndentNextCharacter = options.indentStart !== false;
5290 var replacer = function (match) {
5291 if ( shouldIndentNextCharacter ) { return ("" + indentStr + match); }
5292 shouldIndentNextCharacter = true;
5293 return match;
5294 };
5295
5296 this.intro = this.intro.replace( pattern, replacer );
5297
5298 var charIndex = 0;
5299
5300 var chunk = this.firstChunk;
5301
5302 while ( chunk ) {
5303 var end = chunk.end;
5304
5305 if ( chunk.edited ) {
5306 if ( !isExcluded[ charIndex ] ) {
5307 chunk.content = chunk.content.replace( pattern, replacer );
5308
5309 if ( chunk.content.length ) {
5310 shouldIndentNextCharacter = chunk.content[ chunk.content.length - 1 ] === '\n';
5311 }
5312 }
5313 } else {
5314 charIndex = chunk.start;
5315
5316 while ( charIndex < end ) {
5317 if ( !isExcluded[ charIndex ] ) {
5318 var char = this$1.original[ charIndex ];
5319
5320 if ( char === '\n' ) {
5321 shouldIndentNextCharacter = true;
5322 } else if ( char !== '\r' && shouldIndentNextCharacter ) {
5323 shouldIndentNextCharacter = false;
5324
5325 if ( charIndex === chunk.start ) {
5326 chunk.prependRight( indentStr );
5327 } else {
5328 this$1._splitChunk( chunk, charIndex );
5329 chunk = chunk.next;
5330 chunk.prependRight( indentStr );
5331 }
5332 }
5333 }
5334
5335 charIndex += 1;
5336 }
5337 }
5338
5339 charIndex = chunk.end;
5340 chunk = chunk.next;
5341 }
5342
5343 this.outro = this.outro.replace( pattern, replacer );
5344
5345 return this;
5346 },
5347
5348 insert: function insert () {
5349 throw new Error( 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)' );
5350 },
5351
5352 insertLeft: function insertLeft ( index, content ) {
5353 if ( !warned.insertLeft ) {
5354 console.warn( 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead' ); // eslint-disable-line no-console
5355 warned.insertLeft = true;
5356 }
5357
5358 return this.appendLeft( index, content );
5359 },
5360
5361 insertRight: function insertRight ( index, content ) {
5362 if ( !warned.insertRight ) {
5363 console.warn( 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead' ); // eslint-disable-line no-console
5364 warned.insertRight = true;
5365 }
5366
5367 return this.prependRight( index, content );
5368 },
5369
5370 move: function move ( start, end, index ) {
5371 if ( index >= start && index <= end ) { throw new Error( 'Cannot move a selection inside itself' ); }
5372
5373 this._split( start );
5374 this._split( end );
5375 this._split( index );
5376
5377 var first = this.byStart[ start ];
5378 var last = this.byEnd[ end ];
5379
5380 var oldLeft = first.previous;
5381 var oldRight = last.next;
5382
5383 var newRight = this.byStart[ index ];
5384 if ( !newRight && last === this.lastChunk ) { return this; }
5385 var newLeft = newRight ? newRight.previous : this.lastChunk;
5386
5387 if ( oldLeft ) { oldLeft.next = oldRight; }
5388 if ( oldRight ) { oldRight.previous = oldLeft; }
5389
5390 if ( newLeft ) { newLeft.next = first; }
5391 if ( newRight ) { newRight.previous = last; }
5392
5393 if ( !first.previous ) { this.firstChunk = last.next; }
5394 if ( !last.next ) {
5395 this.lastChunk = first.previous;
5396 this.lastChunk.next = null;
5397 }
5398
5399 first.previous = newLeft;
5400 last.next = newRight || null;
5401
5402 if ( !newLeft ) { this.firstChunk = first; }
5403 if ( !newRight ) { this.lastChunk = last; }
5404
5405 return this;
5406 },
5407
5408 overwrite: function overwrite ( start, end, content, options ) {
5409 var this$1 = this;
5410
5411 if ( typeof content !== 'string' ) { throw new TypeError( 'replacement content must be a string' ); }
5412
5413 while ( start < 0 ) { start += this$1.original.length; }
5414 while ( end < 0 ) { end += this$1.original.length; }
5415
5416 if ( end > this.original.length ) { throw new Error( 'end is out of bounds' ); }
5417 if ( start === end ) { throw new Error( 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead' ); }
5418
5419 this._split( start );
5420 this._split( end );
5421
5422 if ( options === true ) {
5423 if ( !warned.storeName ) {
5424 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
5425 warned.storeName = true;
5426 }
5427
5428 options = { storeName: true };
5429 }
5430 var storeName = options !== undefined ? options.storeName : false;
5431 var contentOnly = options !== undefined ? options.contentOnly : false;
5432
5433 if ( storeName ) {
5434 var original = this.original.slice( start, end );
5435 this.storedNames[ original ] = true;
5436 }
5437
5438 var first = this.byStart[ start ];
5439 var last = this.byEnd[ end ];
5440
5441 if ( first ) {
5442 if ( end > first.end && first.next !== this.byStart[ first.end ] ) {
5443 throw new Error( 'Cannot overwrite across a split point' );
5444 }
5445
5446 first.edit( content, storeName, contentOnly );
5447
5448 if ( first !== last ) {
5449 var chunk = first.next;
5450 while ( chunk !== last ) {
5451 chunk.edit( '', false );
5452 chunk = chunk.next;
5453 }
5454
5455 chunk.edit( '', false );
5456 }
5457 }
5458
5459 else {
5460 // must be inserting at the end
5461 var newChunk = new Chunk( start, end, '' ).edit( content, storeName );
5462
5463 // TODO last chunk in the array may not be the last chunk, if it's moved...
5464 last.next = newChunk;
5465 newChunk.previous = last;
5466 }
5467
5468 return this;
5469 },
5470
5471 prepend: function prepend ( content ) {
5472 if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
5473
5474 this.intro = content + this.intro;
5475 return this;
5476 },
5477
5478 prependLeft: function prependLeft ( index, content ) {
5479 if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
5480
5481 this._split( index );
5482
5483 var chunk = this.byEnd[ index ];
5484
5485 if ( chunk ) {
5486 chunk.prependLeft( content );
5487 } else {
5488 this.intro = content + this.intro;
5489 }
5490
5491 return this;
5492 },
5493
5494 prependRight: function prependRight ( index, content ) {
5495 if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
5496
5497 this._split( index );
5498
5499 var chunk = this.byStart[ index ];
5500
5501 if ( chunk ) {
5502 chunk.prependRight( content );
5503 } else {
5504 this.outro = content + this.outro;
5505 }
5506
5507 return this;
5508 },
5509
5510 remove: function remove ( start, end ) {
5511 var this$1 = this;
5512
5513 while ( start < 0 ) { start += this$1.original.length; }
5514 while ( end < 0 ) { end += this$1.original.length; }
5515
5516 if ( start === end ) { return this; }
5517
5518 if ( start < 0 || end > this.original.length ) { throw new Error( 'Character is out of bounds' ); }
5519 if ( start > end ) { throw new Error( 'end must be greater than start' ); }
5520
5521 this._split( start );
5522 this._split( end );
5523
5524 var chunk = this.byStart[ start ];
5525
5526 while ( chunk ) {
5527 chunk.intro = '';
5528 chunk.outro = '';
5529 chunk.edit( '' );
5530
5531 chunk = end > chunk.end ? this$1.byStart[ chunk.end ] : null;
5532 }
5533
5534 return this;
5535 },
5536
5537 slice: function slice ( start, end ) {
5538 var this$1 = this;
5539 if ( start === void 0 ) start = 0;
5540 if ( end === void 0 ) end = this.original.length;
5541
5542 while ( start < 0 ) { start += this$1.original.length; }
5543 while ( end < 0 ) { end += this$1.original.length; }
5544
5545 var result = '';
5546
5547 // find start chunk
5548 var chunk = this.firstChunk;
5549 while ( chunk && ( chunk.start > start || chunk.end <= start ) ) {
5550
5551 // found end chunk before start
5552 if ( chunk.start < end && chunk.end >= end ) {
5553 return result;
5554 }
5555
5556 chunk = chunk.next;
5557 }
5558
5559 if ( chunk && chunk.edited && chunk.start !== start ) { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
5560
5561 var startChunk = chunk;
5562 while ( chunk ) {
5563 if ( chunk.intro && ( startChunk !== chunk || chunk.start === start ) ) {
5564 result += chunk.intro;
5565 }
5566
5567 var containsEnd = chunk.start < end && chunk.end >= end;
5568 if ( containsEnd && chunk.edited && chunk.end !== end ) { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
5569
5570 var sliceStart = startChunk === chunk ? start - chunk.start : 0;
5571 var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
5572
5573 result += chunk.content.slice( sliceStart, sliceEnd );
5574
5575 if ( chunk.outro && ( !containsEnd || chunk.end === end ) ) {
5576 result += chunk.outro;
5577 }
5578
5579 if ( containsEnd ) {
5580 break;
5581 }
5582
5583 chunk = chunk.next;
5584 }
5585
5586 return result;
5587 },
5588
5589 // TODO deprecate this? not really very useful
5590 snip: function snip ( start, end ) {
5591 var clone = this.clone();
5592 clone.remove( 0, start );
5593 clone.remove( end, clone.original.length );
5594
5595 return clone;
5596 },
5597
5598 _split: function _split ( index ) {
5599 var this$1 = this;
5600
5601 if ( this.byStart[ index ] || this.byEnd[ index ] ) { return; }
5602
5603 var chunk = this.lastSearchedChunk;
5604 var searchForward = index > chunk.end;
5605
5606 while ( true ) {
5607 if ( chunk.contains( index ) ) { return this$1._splitChunk( chunk, index ); }
5608
5609 chunk = searchForward ?
5610 this$1.byStart[ chunk.end ] :
5611 this$1.byEnd[ chunk.start ];
5612 }
5613 },
5614
5615 _splitChunk: function _splitChunk ( chunk, index ) {
5616 if ( chunk.edited && chunk.content.length ) { // zero-length edited chunks are a special case (overlapping replacements)
5617 var loc = getLocator( this.original )( index );
5618 throw new Error( ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")") );
5619 }
5620
5621 var newChunk = chunk.split( index );
5622
5623 this.byEnd[ index ] = chunk;
5624 this.byStart[ index ] = newChunk;
5625 this.byEnd[ newChunk.end ] = newChunk;
5626
5627 if ( chunk === this.lastChunk ) { this.lastChunk = newChunk; }
5628
5629 this.lastSearchedChunk = chunk;
5630 return true;
5631 },
5632
5633 toString: function toString () {
5634 var str = this.intro;
5635
5636 var chunk = this.firstChunk;
5637 while ( chunk ) {
5638 str += chunk.toString();
5639 chunk = chunk.next;
5640 }
5641
5642 return str + this.outro;
5643 },
5644
5645 trimLines: function trimLines () {
5646 return this.trim('[\\r\\n]');
5647 },
5648
5649 trim: function trim ( charType ) {
5650 return this.trimStart( charType ).trimEnd( charType );
5651 },
5652
5653 trimEnd: function trimEnd ( charType ) {
5654 var this$1 = this;
5655
5656 var rx = new RegExp( ( charType || '\\s' ) + '+$' );
5657
5658 this.outro = this.outro.replace( rx, '' );
5659 if ( this.outro.length ) { return this; }
5660
5661 var chunk = this.lastChunk;
5662
5663 do {
5664 var end = chunk.end;
5665 var aborted = chunk.trimEnd( rx );
5666
5667 // if chunk was trimmed, we have a new lastChunk
5668 if ( chunk.end !== end ) {
5669 if ( this$1.lastChunk === chunk ) {
5670 this$1.lastChunk = chunk.next;
5671 }
5672
5673 this$1.byEnd[ chunk.end ] = chunk;
5674 this$1.byStart[ chunk.next.start ] = chunk.next;
5675 this$1.byEnd[ chunk.next.end ] = chunk.next;
5676 }
5677
5678 if ( aborted ) { return this$1; }
5679 chunk = chunk.previous;
5680 } while ( chunk );
5681
5682 return this;
5683 },
5684
5685 trimStart: function trimStart ( charType ) {
5686 var this$1 = this;
5687
5688 var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
5689
5690 this.intro = this.intro.replace( rx, '' );
5691 if ( this.intro.length ) { return this; }
5692
5693 var chunk = this.firstChunk;
5694
5695 do {
5696 var end = chunk.end;
5697 var aborted = chunk.trimStart( rx );
5698
5699 if ( chunk.end !== end ) {
5700 // special case...
5701 if ( chunk === this$1.lastChunk ) { this$1.lastChunk = chunk.next; }
5702
5703 this$1.byEnd[ chunk.end ] = chunk;
5704 this$1.byStart[ chunk.next.start ] = chunk.next;
5705 this$1.byEnd[ chunk.next.end ] = chunk.next;
5706 }
5707
5708 if ( aborted ) { return this$1; }
5709 chunk = chunk.next;
5710 } while ( chunk );
5711
5712 return this;
5713 }
5714};
5715
5716// used for debugging, without the noise created by
5717// circular references
5718function toJSON(node) {
5719 var obj = {};
5720
5721 Object.keys(node).forEach(function (key) {
5722 if (
5723 key === 'parent' ||
5724 key === 'program' ||
5725 key === 'keys' ||
5726 key === '__wrapped'
5727 )
5728 { return; }
5729
5730 if (Array.isArray(node[key])) {
5731 obj[key] = node[key].map(toJSON);
5732 } else if (node[key] && node[key].toJSON) {
5733 obj[key] = node[key].toJSON();
5734 } else {
5735 obj[key] = node[key];
5736 }
5737 });
5738
5739 return obj;
5740}
5741
5742var Node$1 = function Node () {};
5743
5744Node$1.prototype.ancestor = function ancestor (level) {
5745 var node = this;
5746 while (level--) {
5747 node = node.parent;
5748 if (!node) { return null; }
5749 }
5750
5751 return node;
5752};
5753
5754Node$1.prototype.contains = function contains (node) {
5755 var this$1 = this;
5756
5757 while (node) {
5758 if (node === this$1) { return true; }
5759 node = node.parent;
5760 }
5761
5762 return false;
5763};
5764
5765Node$1.prototype.findLexicalBoundary = function findLexicalBoundary () {
5766 return this.parent.findLexicalBoundary();
5767};
5768
5769Node$1.prototype.findNearest = function findNearest (type) {
5770 if (typeof type === 'string') { type = new RegExp(("^" + type + "$")); }
5771 if (type.test(this.type)) { return this; }
5772 return this.parent.findNearest(type);
5773};
5774
5775Node$1.prototype.unparenthesizedParent = function unparenthesizedParent () {
5776 var node = this.parent;
5777 while (node && node.type === 'ParenthesizedExpression') {
5778 node = node.parent;
5779 }
5780 return node;
5781};
5782
5783Node$1.prototype.unparenthesize = function unparenthesize () {
5784 var node = this;
5785 while (node.type === 'ParenthesizedExpression') {
5786 node = node.expression;
5787 }
5788 return node;
5789};
5790
5791Node$1.prototype.findScope = function findScope (functionScope) {
5792 return this.parent.findScope(functionScope);
5793};
5794
5795Node$1.prototype.getIndentation = function getIndentation () {
5796 return this.parent.getIndentation();
5797};
5798
5799Node$1.prototype.initialise = function initialise (transforms) {
5800 var this$1 = this;
5801
5802 for (var i = 0, list = this$1.keys; i < list.length; i += 1) {
5803 var key = list[i];
5804
5805 var value = this$1[key];
5806
5807 if (Array.isArray(value)) {
5808 value.forEach(function (node) { return node && node.initialise(transforms); });
5809 } else if (value && typeof value === 'object') {
5810 value.initialise(transforms);
5811 }
5812 }
5813};
5814
5815Node$1.prototype.toJSON = function toJSON$1 () {
5816 return toJSON(this);
5817};
5818
5819Node$1.prototype.toString = function toString () {
5820 return this.program.magicString.original.slice(this.start, this.end);
5821};
5822
5823Node$1.prototype.transpile = function transpile (code, transforms) {
5824 var this$1 = this;
5825
5826 for (var i = 0, list = this$1.keys; i < list.length; i += 1) {
5827 var key = list[i];
5828
5829 var value = this$1[key];
5830
5831 if (Array.isArray(value)) {
5832 value.forEach(function (node) { return node && node.transpile(code, transforms); });
5833 } else if (value && typeof value === 'object') {
5834 value.transpile(code, transforms);
5835 }
5836 }
5837};
5838
5839function extractNames(node) {
5840 var names = [];
5841 extractors[node.type](names, node);
5842 return names;
5843}
5844
5845var extractors = {
5846 Identifier: function Identifier(names, node) {
5847 names.push(node);
5848 },
5849
5850 ObjectPattern: function ObjectPattern(names, node) {
5851 for (var i = 0, list = node.properties; i < list.length; i += 1) {
5852 var prop = list[i];
5853
5854 extractors[prop.type](names, prop);
5855 }
5856 },
5857
5858 Property: function Property(names, node) {
5859 extractors[node.value.type](names, node.value);
5860 },
5861
5862 ArrayPattern: function ArrayPattern(names, node) {
5863 for (var i = 0, list = node.elements; i < list.length; i += 1) {
5864 var element = list[i];
5865
5866 if (element) { extractors[element.type](names, element); }
5867 }
5868 },
5869
5870 RestElement: function RestElement(names, node) {
5871 extractors[node.argument.type](names, node.argument);
5872 },
5873
5874 AssignmentPattern: function AssignmentPattern(names, node) {
5875 extractors[node.left.type](names, node.left);
5876 }
5877};
5878
5879var reserved = Object.create(null);
5880'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'
5881 .split(' ')
5882 .forEach(function (word) { return (reserved[word] = true); });
5883
5884function Scope(options) {
5885 options = options || {};
5886
5887 this.parent = options.parent;
5888 this.isBlockScope = !!options.block;
5889 this.createDeclarationCallback = options.declare;
5890
5891 var scope = this;
5892 while (scope.isBlockScope) { scope = scope.parent; }
5893 this.functionScope = scope;
5894
5895 this.identifiers = [];
5896 this.declarations = Object.create(null);
5897 this.references = Object.create(null);
5898 this.blockScopedDeclarations = this.isBlockScope ? null : Object.create(null);
5899 this.aliases = Object.create(null);
5900}
5901
5902Scope.prototype = {
5903 addDeclaration: function addDeclaration(node, kind) {
5904 var this$1 = this;
5905
5906 for (var i = 0, list = extractNames(node); i < list.length; i += 1) {
5907 var identifier = list[i];
5908
5909 var name = identifier.name;
5910
5911 var declaration = { name: name, node: identifier, kind: kind, instances: [] };
5912 this$1.declarations[name] = declaration;
5913
5914 if (this$1.isBlockScope) {
5915 if (!this$1.functionScope.blockScopedDeclarations[name])
5916 { this$1.functionScope.blockScopedDeclarations[name] = []; }
5917 this$1.functionScope.blockScopedDeclarations[name].push(declaration);
5918 }
5919 }
5920 },
5921
5922 addReference: function addReference(identifier) {
5923 if (this.consolidated) {
5924 this.consolidateReference(identifier);
5925 } else {
5926 this.identifiers.push(identifier);
5927 }
5928 },
5929
5930 consolidate: function consolidate() {
5931 var this$1 = this;
5932
5933 for (var i = 0; i < this.identifiers.length; i += 1) {
5934 // we might push to the array during consolidation, so don't cache length
5935 var identifier = this$1.identifiers[i];
5936 this$1.consolidateReference(identifier);
5937 }
5938
5939 this.consolidated = true; // TODO understand why this is necessary... seems bad
5940 },
5941
5942 consolidateReference: function consolidateReference(identifier) {
5943 var declaration = this.declarations[identifier.name];
5944 if (declaration) {
5945 declaration.instances.push(identifier);
5946 } else {
5947 this.references[identifier.name] = true;
5948 if (this.parent) { this.parent.addReference(identifier); }
5949 }
5950 },
5951
5952 contains: function contains(name) {
5953 return (
5954 this.declarations[name] ||
5955 (this.parent ? this.parent.contains(name) : false)
5956 );
5957 },
5958
5959 createIdentifier: function createIdentifier(base) {
5960 if (typeof base === 'number') { base = base.toString(); }
5961
5962 base = base
5963 .replace(/\s/g, '')
5964 .replace(/\[([^\]]+)\]/g, '_$1')
5965 .replace(/[^a-zA-Z0-9_$]/g, '_')
5966 .replace(/_{2,}/, '_');
5967
5968 var name = base;
5969 var counter = 1;
5970
5971 while (
5972 this.declarations[name] ||
5973 this.references[name] ||
5974 this.aliases[name] ||
5975 name in reserved
5976 ) {
5977 name = base + "$" + (counter++);
5978 }
5979
5980 this.aliases[name] = true;
5981 return name;
5982 },
5983
5984 createDeclaration: function createDeclaration(base) {
5985 var id = this.createIdentifier(base);
5986 this.createDeclarationCallback(id);
5987 return id;
5988 },
5989
5990 findDeclaration: function findDeclaration(name) {
5991 return (
5992 this.declarations[name] ||
5993 (this.parent && this.parent.findDeclaration(name))
5994 );
5995 },
5996
5997 // Sometimes, block scope declarations change name during transpilation
5998 resolveName: function resolveName(name) {
5999 var declaration = this.findDeclaration(name);
6000 return declaration ? declaration.name : name;
6001 }
6002};
6003
6004function locate(source, index) {
6005 var lines = source.split('\n');
6006 var len = lines.length;
6007
6008 var lineStart = 0;
6009 var i;
6010
6011 for (i = 0; i < len; i += 1) {
6012 var line = lines[i];
6013 var lineEnd = lineStart + line.length + 1; // +1 for newline
6014
6015 if (lineEnd > index) {
6016 return { line: i + 1, column: index - lineStart, char: i };
6017 }
6018
6019 lineStart = lineEnd;
6020 }
6021
6022 throw new Error('Could not determine location of character');
6023}
6024
6025function pad(num, len) {
6026 var result = String(num);
6027 return result + repeat(' ', len - result.length);
6028}
6029
6030function repeat(str, times) {
6031 var result = '';
6032 while (times--) { result += str; }
6033 return result;
6034}
6035
6036function getSnippet(source, loc, length) {
6037 if ( length === void 0 ) length = 1;
6038
6039 var first = Math.max(loc.line - 5, 0);
6040 var last = loc.line;
6041
6042 var numDigits = String(last).length;
6043
6044 var lines = source.split('\n').slice(first, last);
6045
6046 var lastLine = lines[lines.length - 1];
6047 var offset = lastLine.slice(0, loc.column).replace(/\t/g, ' ').length;
6048
6049 var snippet = lines
6050 .map(function (line, i) { return ((pad(i + first + 1, numDigits)) + " : " + (line.replace(/\t/g, ' '))); })
6051 .join('\n');
6052
6053 snippet += '\n' + repeat(' ', numDigits + 3 + offset) + repeat('^', length);
6054
6055 return snippet;
6056}
6057
6058var CompileError = (function (Error) {
6059 function CompileError(message, node) {
6060 Error.call(this, message);
6061
6062 this.name = 'CompileError';
6063 if (!node) {
6064 return;
6065 }
6066
6067 var source = node.program.magicString.original;
6068 var loc = locate(source, node.start);
6069
6070 this.message = message + " (" + (loc.line) + ":" + (loc.column) + ")";
6071
6072 this.stack = new Error().stack.replace(
6073 new RegExp((".+new " + (this.name) + ".+\\n"), 'm'),
6074 ''
6075 );
6076
6077 this.loc = loc;
6078 this.snippet = getSnippet(source, loc, node.end - node.start);
6079 }
6080
6081 if ( Error ) CompileError.__proto__ = Error;
6082 CompileError.prototype = Object.create( Error && Error.prototype );
6083 CompileError.prototype.constructor = CompileError;
6084
6085 CompileError.prototype.toString = function toString () {
6086 return ((this.name) + ": " + (this.message) + "\n" + (this.snippet));
6087 };
6088
6089 return CompileError;
6090}(Error));
6091
6092function findIndex(array, fn) {
6093 for (var i = 0; i < array.length; i += 1) {
6094 if (fn(array[i], i)) { return i; }
6095 }
6096
6097 return -1;
6098}
6099
6100var handlers = {
6101 Identifier: destructureIdentifier,
6102 AssignmentPattern: destructureAssignmentPattern,
6103 ArrayPattern: destructureArrayPattern,
6104 ObjectPattern: destructureObjectPattern
6105};
6106
6107function destructure(
6108 code,
6109 createIdentifier,
6110 resolveName,
6111 node,
6112 ref,
6113 inline,
6114 statementGenerators
6115) {
6116 handlers[node.type](code, createIdentifier, resolveName, node, ref, inline, statementGenerators);
6117}
6118
6119function destructureIdentifier(
6120 code,
6121 createIdentifier,
6122 resolveName,
6123 node,
6124 ref,
6125 inline,
6126 statementGenerators
6127) {
6128 statementGenerators.push(function (start, prefix, suffix) {
6129 code.overwrite(node.start, node.end, (inline ? prefix : (prefix + "var ")) + resolveName(node) + " = " + ref + suffix);
6130 code.move(node.start, node.end, start);
6131 });
6132}
6133
6134function destructureMemberExpression(
6135 code,
6136 createIdentifier,
6137 resolveName,
6138 node,
6139 ref,
6140 inline,
6141 statementGenerators
6142) {
6143 statementGenerators.push(function (start, prefix, suffix) {
6144 code.prependRight(node.start, inline ? prefix : (prefix + "var "));
6145 code.appendLeft(node.end, (" = " + ref + suffix));
6146 code.move(node.start, node.end, start);
6147 });
6148}
6149
6150function destructureAssignmentPattern(
6151 code,
6152 createIdentifier,
6153 resolveName,
6154 node,
6155 ref,
6156 inline,
6157 statementGenerators
6158) {
6159 var isIdentifier = node.left.type === 'Identifier';
6160 var name = isIdentifier ? node.left.name : ref;
6161
6162 if (!inline) {
6163 statementGenerators.push(function (start, prefix, suffix) {
6164 code.prependRight(
6165 node.left.end,
6166 (prefix + "if ( " + name + " === void 0 ) " + name)
6167 );
6168 code.move(node.left.end, node.right.end, start);
6169 code.appendLeft(node.right.end, suffix);
6170 });
6171 }
6172
6173 if (!isIdentifier) {
6174 destructure(code, createIdentifier, resolveName, node.left, ref, inline, statementGenerators);
6175 }
6176}
6177
6178function destructureArrayPattern(
6179 code,
6180 createIdentifier,
6181 resolveName,
6182 node,
6183 ref,
6184 inline,
6185 statementGenerators
6186) {
6187 var c = node.start;
6188
6189 node.elements.forEach(function (element, i) {
6190 if (!element) { return; }
6191
6192 if (element.type === 'RestElement') {
6193 handleProperty(
6194 code,
6195 createIdentifier,
6196 resolveName,
6197 c,
6198 element.argument,
6199 (ref + ".slice(" + i + ")"),
6200 inline,
6201 statementGenerators
6202 );
6203 } else {
6204 handleProperty(
6205 code,
6206 createIdentifier,
6207 resolveName,
6208 c,
6209 element,
6210 (ref + "[" + i + "]"),
6211 inline,
6212 statementGenerators
6213 );
6214 }
6215 c = element.end;
6216 });
6217
6218 code.remove(c, node.end);
6219}
6220
6221function destructureObjectPattern(
6222 code,
6223 createIdentifier,
6224 resolveName,
6225 node,
6226 ref,
6227 inline,
6228 statementGenerators
6229) {
6230 var this$1 = this;
6231
6232 var c = node.start;
6233
6234 var nonRestKeys = [];
6235 node.properties.forEach(function (prop) {
6236 var value;
6237 var content;
6238 if (prop.type === 'Property') {
6239 var isComputedKey = prop.computed || prop.key.type !== 'Identifier';
6240 var key = isComputedKey
6241 ? code.slice(prop.key.start, prop.key.end)
6242 : prop.key.name;
6243 value = isComputedKey ? (ref + "[" + key + "]") : (ref + "." + key);
6244 content = prop.value;
6245 nonRestKeys.push(isComputedKey ? key : '"' + key + '"');
6246 } else if (prop.type === 'RestElement') {
6247 content = prop.argument;
6248 value = createIdentifier('rest');
6249 statementGenerators.push(function (start, prefix, suffix) {
6250 var helper = prop.program.getObjectWithoutPropertiesHelper(code);
6251 code.overwrite(
6252 prop.start,
6253 (c = prop.argument.start),
6254 (inline ? prefix : (prefix + "var ")) + value + " = " + helper + "( " + ref + ", [" + (nonRestKeys.join(', ')) + "] )" + suffix
6255 );
6256 code.move(prop.start, c, start);
6257 });
6258 } else {
6259 throw new CompileError(
6260 this$1,
6261 ("Unexpected node of type " + (prop.type) + " in object pattern")
6262 );
6263 }
6264 handleProperty(code, createIdentifier, resolveName, c, content, value, inline, statementGenerators);
6265 c = prop.end;
6266 });
6267
6268 code.remove(c, node.end);
6269}
6270
6271function handleProperty(
6272 code,
6273 createIdentifier,
6274 resolveName,
6275 c,
6276 node,
6277 value,
6278 inline,
6279 statementGenerators
6280) {
6281 switch (node.type) {
6282 case 'Identifier': {
6283 code.remove(c, node.start);
6284 destructureIdentifier(
6285 code,
6286 createIdentifier,
6287 resolveName,
6288 node,
6289 value,
6290 inline,
6291 statementGenerators
6292 );
6293 break;
6294 }
6295
6296 case 'MemberExpression':
6297 code.remove(c, node.start);
6298 destructureMemberExpression(
6299 code,
6300 createIdentifier,
6301 resolveName,
6302 node,
6303 value,
6304 true,
6305 statementGenerators
6306 );
6307 break;
6308
6309 case 'AssignmentPattern': {
6310 var name;
6311
6312 var isIdentifier = node.left.type === 'Identifier';
6313
6314 if (isIdentifier) {
6315 name = resolveName(node.left);
6316 } else {
6317 name = createIdentifier(value);
6318 }
6319
6320 statementGenerators.push(function (start, prefix, suffix) {
6321 if (inline) {
6322 code.prependRight(
6323 node.right.start,
6324 (name + " = " + value + ", " + name + " = " + name + " === void 0 ? ")
6325 );
6326 code.appendLeft(node.right.end, (" : " + name + suffix));
6327 } else {
6328 code.prependRight(
6329 node.right.start,
6330 (prefix + "var " + name + " = " + value + "; if ( " + name + " === void 0 ) " + name + " = ")
6331 );
6332 code.appendLeft(node.right.end, suffix);
6333 }
6334
6335 code.move(node.right.start, node.right.end, start);
6336 });
6337
6338 if (isIdentifier) {
6339 code.remove(c, node.right.start);
6340 } else {
6341 code.remove(c, node.left.start);
6342 code.remove(node.left.end, node.right.start);
6343 handleProperty(
6344 code,
6345 createIdentifier,
6346 resolveName,
6347 c,
6348 node.left,
6349 name,
6350 inline,
6351 statementGenerators
6352 );
6353 }
6354
6355 break;
6356 }
6357
6358 case 'ObjectPattern': {
6359 code.remove(c, (c = node.start));
6360
6361 var ref = value;
6362 if (node.properties.length > 1) {
6363 ref = createIdentifier(value);
6364
6365 statementGenerators.push(function (start, prefix, suffix) {
6366 // this feels a tiny bit hacky, but we can't do a
6367 // straightforward appendLeft and keep correct order...
6368 code.prependRight(node.start, (inline ? '' : (prefix + "var ")) + ref + " = ");
6369 code.overwrite(node.start, (c = node.start + 1), value);
6370 code.appendLeft(c, suffix);
6371
6372 code.overwrite(
6373 node.start,
6374 (c = node.start + 1),
6375 (inline ? '' : (prefix + "var ")) + ref + " = " + value + suffix
6376 );
6377 code.move(node.start, c, start);
6378 });
6379 }
6380
6381 destructureObjectPattern(
6382 code,
6383 createIdentifier,
6384 resolveName,
6385 node,
6386 ref,
6387 inline,
6388 statementGenerators
6389 );
6390
6391 break;
6392 }
6393
6394 case 'ArrayPattern': {
6395 code.remove(c, (c = node.start));
6396
6397 if (node.elements.filter(Boolean).length > 1) {
6398 var ref$1 = createIdentifier(value);
6399
6400 statementGenerators.push(function (start, prefix, suffix) {
6401 code.prependRight(node.start, (inline ? '' : (prefix + "var ")) + ref$1 + " = ");
6402 code.overwrite(node.start, (c = node.start + 1), value, {
6403 contentOnly: true
6404 });
6405 code.appendLeft(c, suffix);
6406
6407 code.move(node.start, c, start);
6408 });
6409
6410 node.elements.forEach(function (element, i) {
6411 if (!element) { return; }
6412
6413 if (element.type === 'RestElement') {
6414 handleProperty(
6415 code,
6416 createIdentifier,
6417 resolveName,
6418 c,
6419 element.argument,
6420 (ref$1 + ".slice(" + i + ")"),
6421 inline,
6422 statementGenerators
6423 );
6424 } else {
6425 handleProperty(
6426 code,
6427 createIdentifier,
6428 resolveName,
6429 c,
6430 element,
6431 (ref$1 + "[" + i + "]"),
6432 inline,
6433 statementGenerators
6434 );
6435 }
6436 c = element.end;
6437 });
6438 } else {
6439 var index = findIndex(node.elements, Boolean);
6440 var element = node.elements[index];
6441 if (element.type === 'RestElement') {
6442 handleProperty(
6443 code,
6444 createIdentifier,
6445 resolveName,
6446 c,
6447 element.argument,
6448 (value + ".slice(" + index + ")"),
6449 inline,
6450 statementGenerators
6451 );
6452 } else {
6453 handleProperty(
6454 code,
6455 createIdentifier,
6456 resolveName,
6457 c,
6458 element,
6459 (value + "[" + index + "]"),
6460 inline,
6461 statementGenerators
6462 );
6463 }
6464 c = element.end;
6465 }
6466
6467 code.remove(c, node.end);
6468 break;
6469 }
6470
6471 default: {
6472 throw new Error(("Unexpected node type in destructuring (" + (node.type) + ")"));
6473 }
6474 }
6475}
6476
6477function isUseStrict(node) {
6478 if (!node) { return false; }
6479 if (node.type !== 'ExpressionStatement') { return false; }
6480 if (node.expression.type !== 'Literal') { return false; }
6481 return node.expression.value === 'use strict';
6482}
6483
6484var BlockStatement = (function (Node) {
6485 function BlockStatement () {
6486 Node.apply(this, arguments);
6487 }
6488
6489 if ( Node ) BlockStatement.__proto__ = Node;
6490 BlockStatement.prototype = Object.create( Node && Node.prototype );
6491 BlockStatement.prototype.constructor = BlockStatement;
6492
6493 BlockStatement.prototype.createScope = function createScope () {
6494 var this$1 = this;
6495
6496 this.parentIsFunction = /Function/.test(this.parent.type);
6497 this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root';
6498 this.scope = new Scope({
6499 block: !this.isFunctionBlock,
6500 parent: this.parent.findScope(false),
6501 declare: function (id) { return this$1.createdDeclarations.push(id); }
6502 });
6503
6504 if (this.parentIsFunction) {
6505 this.parent.params.forEach(function (node) {
6506 this$1.scope.addDeclaration(node, 'param');
6507 });
6508 }
6509 };
6510
6511 BlockStatement.prototype.initialise = function initialise (transforms) {
6512 this.thisAlias = null;
6513 this.argumentsAlias = null;
6514 this.defaultParameters = [];
6515 this.createdDeclarations = [];
6516
6517 // normally the scope gets created here, during initialisation,
6518 // but in some cases (e.g. `for` statements), we need to create
6519 // the scope early, as it pertains to both the init block and
6520 // the body of the statement
6521 if (!this.scope) { this.createScope(); }
6522
6523 this.body.forEach(function (node) { return node.initialise(transforms); });
6524
6525 this.scope.consolidate();
6526 };
6527
6528 BlockStatement.prototype.findLexicalBoundary = function findLexicalBoundary () {
6529 if (this.type === 'Program') { return this; }
6530 if (/^Function/.test(this.parent.type)) { return this; }
6531
6532 return this.parent.findLexicalBoundary();
6533 };
6534
6535 BlockStatement.prototype.findScope = function findScope (functionScope) {
6536 if (functionScope && !this.isFunctionBlock)
6537 { return this.parent.findScope(functionScope); }
6538 return this.scope;
6539 };
6540
6541 BlockStatement.prototype.getArgumentsAlias = function getArgumentsAlias () {
6542 if (!this.argumentsAlias) {
6543 this.argumentsAlias = this.scope.createIdentifier('arguments');
6544 }
6545
6546 return this.argumentsAlias;
6547 };
6548
6549 BlockStatement.prototype.getArgumentsArrayAlias = function getArgumentsArrayAlias () {
6550 if (!this.argumentsArrayAlias) {
6551 this.argumentsArrayAlias = this.scope.createIdentifier('argsArray');
6552 }
6553
6554 return this.argumentsArrayAlias;
6555 };
6556
6557 BlockStatement.prototype.getThisAlias = function getThisAlias () {
6558 if (!this.thisAlias) {
6559 this.thisAlias = this.scope.createIdentifier('this');
6560 }
6561
6562 return this.thisAlias;
6563 };
6564
6565 BlockStatement.prototype.getIndentation = function getIndentation () {
6566 var this$1 = this;
6567
6568 if (this.indentation === undefined) {
6569 var source = this.program.magicString.original;
6570
6571 var useOuter = this.synthetic || !this.body.length;
6572 var c = useOuter ? this.start : this.body[0].start;
6573
6574 while (c && source[c] !== '\n') { c -= 1; }
6575
6576 this.indentation = '';
6577
6578 // eslint-disable-next-line no-constant-condition
6579 while (true) {
6580 c += 1;
6581 var char = source[c];
6582
6583 if (char !== ' ' && char !== '\t') { break; }
6584
6585 this$1.indentation += char;
6586 }
6587
6588 var indentString = this.program.magicString.getIndentString();
6589
6590 // account for dedented class constructors
6591 var parent = this.parent;
6592 while (parent) {
6593 if (parent.kind === 'constructor' && !parent.parent.parent.superClass) {
6594 this$1.indentation = this$1.indentation.replace(indentString, '');
6595 }
6596
6597 parent = parent.parent;
6598 }
6599
6600 if (useOuter) { this.indentation += indentString; }
6601 }
6602
6603 return this.indentation;
6604 };
6605
6606 BlockStatement.prototype.transpile = function transpile (code, transforms) {
6607 var this$1 = this;
6608
6609 var indentation = this.getIndentation();
6610
6611 var introStatementGenerators = [];
6612
6613 if (this.argumentsAlias) {
6614 introStatementGenerators.push(function (start, prefix, suffix) {
6615 var assignment = prefix + "var " + (this$1.argumentsAlias) + " = arguments" + suffix;
6616 code.appendLeft(start, assignment);
6617 });
6618 }
6619
6620 if (this.thisAlias) {
6621 introStatementGenerators.push(function (start, prefix, suffix) {
6622 var assignment = prefix + "var " + (this$1.thisAlias) + " = this" + suffix;
6623 code.appendLeft(start, assignment);
6624 });
6625 }
6626
6627 if (this.argumentsArrayAlias) {
6628 introStatementGenerators.push(function (start, prefix, suffix) {
6629 var i = this$1.scope.createIdentifier('i');
6630 var assignment = prefix + "var " + i + " = arguments.length, " + (this$1.argumentsArrayAlias) + " = Array(" + i + ");\n" + indentation + "while ( " + i + "-- ) " + (this$1.argumentsArrayAlias) + "[" + i + "] = arguments[" + i + "]" + suffix;
6631 code.appendLeft(start, assignment);
6632 });
6633 }
6634
6635 if (/Function/.test(this.parent.type)) {
6636 this.transpileParameters(
6637 this.parent.params,
6638 code,
6639 transforms,
6640 indentation,
6641 introStatementGenerators
6642 );
6643 } else if ('CatchClause' === this.parent.type) {
6644 this.transpileParameters(
6645 [this.parent.param],
6646 code,
6647 transforms,
6648 indentation,
6649 introStatementGenerators
6650 );
6651 }
6652
6653 if (transforms.letConst && this.isFunctionBlock) {
6654 this.transpileBlockScopedIdentifiers(code);
6655 }
6656
6657 Node.prototype.transpile.call(this, code, transforms);
6658
6659 if (this.createdDeclarations.length) {
6660 introStatementGenerators.push(function (start, prefix, suffix) {
6661 var assignment = prefix + "var " + (this$1.createdDeclarations.join(', ')) + suffix;
6662 code.appendLeft(start, assignment);
6663 });
6664 }
6665
6666 if (this.synthetic) {
6667 if (this.parent.type === 'ArrowFunctionExpression') {
6668 var expr = this.body[0];
6669
6670 if (introStatementGenerators.length) {
6671 code
6672 .appendLeft(this.start, "{")
6673 .prependRight(this.end, ((this.parent.getIndentation()) + "}"));
6674
6675 code.prependRight(expr.start, ("\n" + indentation + "return "));
6676 code.appendLeft(expr.end, ";\n");
6677 } else if (transforms.arrow) {
6678 code.prependRight(expr.start, "{ return ");
6679 code.appendLeft(expr.end, "; }");
6680 }
6681 } else if (introStatementGenerators.length) {
6682 code.prependRight(this.start, "{").appendLeft(this.end, "}");
6683 }
6684 }
6685
6686 var start;
6687 if (isUseStrict(this.body[0])) {
6688 start = this.body[0].end;
6689 } else if (this.synthetic || this.parent.type === 'Root') {
6690 start = this.start;
6691 } else {
6692 start = this.start + 1;
6693 }
6694
6695 var prefix = "\n" + indentation;
6696 var suffix = ';';
6697 introStatementGenerators.forEach(function (fn, i) {
6698 if (i === introStatementGenerators.length - 1) { suffix = ";\n"; }
6699 fn(start, prefix, suffix);
6700 });
6701 };
6702
6703 BlockStatement.prototype.transpileParameters = function transpileParameters (params, code, transforms, indentation, introStatementGenerators) {
6704 var this$1 = this;
6705
6706 params.forEach(function (param) {
6707 if (
6708 param.type === 'AssignmentPattern' &&
6709 param.left.type === 'Identifier'
6710 ) {
6711 if (transforms.defaultParameter) {
6712 introStatementGenerators.push(function (start, prefix, suffix) {
6713 var lhs = prefix + "if ( " + (param.left.name) + " === void 0 ) " + (param.left.name);
6714
6715 code
6716 .prependRight(param.left.end, lhs)
6717 .move(param.left.end, param.right.end, start)
6718 .appendLeft(param.right.end, suffix);
6719 });
6720 }
6721 } else if (param.type === 'RestElement') {
6722 if (transforms.spreadRest) {
6723 introStatementGenerators.push(function (start, prefix, suffix) {
6724 var penultimateParam = params[params.length - 2];
6725
6726 if (penultimateParam) {
6727 code.remove(
6728 penultimateParam ? penultimateParam.end : param.start,
6729 param.end
6730 );
6731 } else {
6732 var start$1 = param.start,
6733 end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8
6734
6735 while (/\s/.test(code.original[start$1 - 1])) { start$1 -= 1; }
6736 while (/\s/.test(code.original[end])) { end += 1; }
6737
6738 code.remove(start$1, end);
6739 }
6740
6741 var name = param.argument.name;
6742 var len = this$1.scope.createIdentifier('len');
6743 var count = params.length - 1;
6744
6745 if (count) {
6746 code.prependRight(
6747 start,
6748 (prefix + "var " + name + " = [], " + len + " = arguments.length - " + count + ";\n" + indentation + "while ( " + len + "-- > 0 ) " + name + "[ " + len + " ] = arguments[ " + len + " + " + count + " ]" + suffix)
6749 );
6750 } else {
6751 code.prependRight(
6752 start,
6753 (prefix + "var " + name + " = [], " + len + " = arguments.length;\n" + indentation + "while ( " + len + "-- ) " + name + "[ " + len + " ] = arguments[ " + len + " ]" + suffix)
6754 );
6755 }
6756 });
6757 }
6758 } else if (param.type !== 'Identifier') {
6759 if (transforms.parameterDestructuring) {
6760 var ref = this$1.scope.createIdentifier('ref');
6761 destructure(
6762 code,
6763 function (id) { return this$1.scope.createIdentifier(id); },
6764 function (ref) {
6765 var name = ref.name;
6766
6767 return this$1.scope.resolveName(name);
6768 },
6769 param,
6770 ref,
6771 false,
6772 introStatementGenerators
6773 );
6774 code.prependRight(param.start, ref);
6775 }
6776 }
6777 });
6778 };
6779
6780 BlockStatement.prototype.transpileBlockScopedIdentifiers = function transpileBlockScopedIdentifiers (code) {
6781 var this$1 = this;
6782
6783 Object.keys(this.scope.blockScopedDeclarations).forEach(function (name) {
6784 var declarations = this$1.scope.blockScopedDeclarations[name];
6785
6786 for (var i$2 = 0, list$2 = declarations; i$2 < list$2.length; i$2 += 1) {
6787 var declaration = list$2[i$2];
6788
6789 var cont = false; // TODO implement proper continue...
6790
6791 if (declaration.kind === 'for.let') {
6792 // special case
6793 var forStatement = declaration.node.findNearest('ForStatement');
6794
6795 if (forStatement.shouldRewriteAsFunction) {
6796 var outerAlias = this$1.scope.createIdentifier(name);
6797 var innerAlias = forStatement.reassigned[name]
6798 ? this$1.scope.createIdentifier(name)
6799 : name;
6800
6801 declaration.name = outerAlias;
6802 code.overwrite(
6803 declaration.node.start,
6804 declaration.node.end,
6805 outerAlias,
6806 { storeName: true }
6807 );
6808
6809 forStatement.aliases[name] = {
6810 outer: outerAlias,
6811 inner: innerAlias
6812 };
6813
6814 for (var i = 0, list = declaration.instances; i < list.length; i += 1) {
6815 var identifier = list[i];
6816
6817 var alias = forStatement.body.contains(identifier)
6818 ? innerAlias
6819 : outerAlias;
6820
6821 if (name !== alias) {
6822 code.overwrite(identifier.start, identifier.end, alias, {
6823 storeName: true
6824 });
6825 }
6826 }
6827
6828 cont = true;
6829 }
6830 }
6831
6832 if (!cont) {
6833 var alias$1 = this$1.scope.createIdentifier(name);
6834
6835 if (name !== alias$1) {
6836 declaration.name = alias$1;
6837 code.overwrite(
6838 declaration.node.start,
6839 declaration.node.end,
6840 alias$1,
6841 { storeName: true }
6842 );
6843
6844 for (var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1) {
6845 var identifier$1 = list$1[i$1];
6846
6847 identifier$1.rewritten = true;
6848 code.overwrite(identifier$1.start, identifier$1.end, alias$1, {
6849 storeName: true
6850 });
6851 }
6852 }
6853 }
6854 }
6855 });
6856 };
6857
6858 return BlockStatement;
6859}(Node$1));
6860
6861function isArguments(node) {
6862 return node.type === 'Identifier' && node.name === 'arguments';
6863}
6864
6865function spread(
6866 code,
6867 elements,
6868 start,
6869 argumentsArrayAlias,
6870 isNew
6871) {
6872 var i = elements.length;
6873 var firstSpreadIndex = -1;
6874
6875 while (i--) {
6876 var element$1 = elements[i];
6877 if (element$1 && element$1.type === 'SpreadElement') {
6878 if (isArguments(element$1.argument)) {
6879 code.overwrite(
6880 element$1.argument.start,
6881 element$1.argument.end,
6882 argumentsArrayAlias
6883 );
6884 }
6885
6886 firstSpreadIndex = i;
6887 }
6888 }
6889
6890 if (firstSpreadIndex === -1) { return false; } // false indicates no spread elements
6891
6892 if (isNew) {
6893 for (i = 0; i < elements.length; i += 1) {
6894 var element$2 = elements[i];
6895 if (element$2.type === 'SpreadElement') {
6896 code.remove(element$2.start, element$2.argument.start);
6897 } else {
6898 code.prependRight(element$2.start, '[');
6899 code.prependRight(element$2.end, ']');
6900 }
6901 }
6902
6903 return true; // true indicates some spread elements
6904 }
6905
6906 var element = elements[firstSpreadIndex];
6907 var previousElement = elements[firstSpreadIndex - 1];
6908
6909 if (!previousElement) {
6910 code.remove(start, element.start);
6911 code.overwrite(element.end, elements[1].start, '.concat( ');
6912 } else {
6913 code.overwrite(previousElement.end, element.start, ' ].concat( ');
6914 }
6915
6916 for (i = firstSpreadIndex; i < elements.length; i += 1) {
6917 element = elements[i];
6918
6919 if (element) {
6920 if (element.type === 'SpreadElement') {
6921 code.remove(element.start, element.argument.start);
6922 } else {
6923 code.appendLeft(element.start, '[');
6924 code.appendLeft(element.end, ']');
6925 }
6926 }
6927 }
6928
6929 return true; // true indicates some spread elements
6930}
6931
6932var ArrayExpression = (function (Node) {
6933 function ArrayExpression () {
6934 Node.apply(this, arguments);
6935 }
6936
6937 if ( Node ) ArrayExpression.__proto__ = Node;
6938 ArrayExpression.prototype = Object.create( Node && Node.prototype );
6939 ArrayExpression.prototype.constructor = ArrayExpression;
6940
6941 ArrayExpression.prototype.initialise = function initialise (transforms) {
6942 var this$1 = this;
6943
6944 if (transforms.spreadRest && this.elements.length) {
6945 var lexicalBoundary = this.findLexicalBoundary();
6946
6947 var i = this.elements.length;
6948 while (i--) {
6949 var element = this$1.elements[i];
6950 if (
6951 element &&
6952 element.type === 'SpreadElement' &&
6953 isArguments(element.argument)
6954 ) {
6955 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
6956 }
6957 }
6958 }
6959
6960 Node.prototype.initialise.call(this, transforms);
6961 };
6962
6963 ArrayExpression.prototype.transpile = function transpile (code, transforms) {
6964 Node.prototype.transpile.call(this, code, transforms);
6965
6966 if (transforms.spreadRest) {
6967 // erase trailing comma after last array element if not an array hole
6968 if (this.elements.length) {
6969 var lastElement = this.elements[this.elements.length - 1];
6970 if (
6971 lastElement &&
6972 /\s*,/.test(code.original.slice(lastElement.end, this.end))
6973 ) {
6974 code.overwrite(lastElement.end, this.end - 1, ' ');
6975 }
6976 }
6977
6978 if (this.elements.length === 1) {
6979 var element = this.elements[0];
6980
6981 if (element && element.type === 'SpreadElement') {
6982 // special case – [ ...arguments ]
6983 if (isArguments(element.argument)) {
6984 code.overwrite(
6985 this.start,
6986 this.end,
6987 ("[].concat( " + (this.argumentsArrayAlias) + " )")
6988 ); // TODO if this is the only use of argsArray, don't bother concating
6989 } else {
6990 code.overwrite(this.start, element.argument.start, '[].concat( ');
6991 code.overwrite(element.end, this.end, ' )');
6992 }
6993 }
6994 } else {
6995 var hasSpreadElements = spread(
6996 code,
6997 this.elements,
6998 this.start,
6999 this.argumentsArrayAlias
7000 );
7001
7002 if (hasSpreadElements) {
7003 code.overwrite(this.end - 1, this.end, ')');
7004 }
7005 }
7006 }
7007 };
7008
7009 return ArrayExpression;
7010}(Node$1));
7011
7012function removeTrailingComma(code, c) {
7013 while (code.original[c] !== ')') {
7014 if (code.original[c] === ',') {
7015 code.remove(c, c + 1);
7016 return;
7017 }
7018
7019 if (code.original[c] === '/') {
7020 c = code.original.indexOf(code.original[c + 1] === '/' ? '\n' : '*/', c) + 1;
7021 }
7022 c += 1;
7023 }
7024}
7025
7026var ArrowFunctionExpression = (function (Node) {
7027 function ArrowFunctionExpression () {
7028 Node.apply(this, arguments);
7029 }
7030
7031 if ( Node ) ArrowFunctionExpression.__proto__ = Node;
7032 ArrowFunctionExpression.prototype = Object.create( Node && Node.prototype );
7033 ArrowFunctionExpression.prototype.constructor = ArrowFunctionExpression;
7034
7035 ArrowFunctionExpression.prototype.initialise = function initialise (transforms) {
7036 this.body.createScope();
7037 Node.prototype.initialise.call(this, transforms);
7038 };
7039
7040 ArrowFunctionExpression.prototype.transpile = function transpile (code, transforms) {
7041 var naked = this.params.length === 1 && this.start === this.params[0].start;
7042
7043 if (transforms.arrow || this.needsArguments(transforms)) {
7044 // remove arrow
7045 var charIndex = this.body.start;
7046 while (code.original[charIndex] !== '=') {
7047 charIndex -= 1;
7048 }
7049 code.remove(charIndex, this.body.start);
7050
7051 Node.prototype.transpile.call(this, code, transforms);
7052
7053 // wrap naked parameter
7054 if (naked) {
7055 code.prependRight(this.params[0].start, '(');
7056 code.appendLeft(this.params[0].end, ')');
7057 }
7058
7059 // add function
7060 if (this.parent && this.parent.type === 'ExpressionStatement') {
7061 // standalone expression statement
7062 code.prependRight(this.start, '!function');
7063 } else {
7064 code.prependRight(this.start, 'function ');
7065 }
7066 } else {
7067 Node.prototype.transpile.call(this, code, transforms);
7068 }
7069
7070 if (transforms.trailingFunctionCommas && this.params.length && !naked) {
7071 removeTrailingComma(code, this.params[this.params.length - 1].end);
7072 }
7073 };
7074
7075 // Returns whether any transforms that will happen use `arguments`
7076 ArrowFunctionExpression.prototype.needsArguments = function needsArguments (transforms) {
7077 return (
7078 transforms.spreadRest &&
7079 this.params.filter(function (param) { return param.type === 'RestElement'; }).length > 0
7080 );
7081 };
7082
7083 return ArrowFunctionExpression;
7084}(Node$1));
7085
7086function checkConst(identifier, scope) {
7087 var declaration = scope.findDeclaration(identifier.name);
7088 if (declaration && declaration.kind === 'const') {
7089 throw new CompileError(((identifier.name) + " is read-only"), identifier);
7090 }
7091}
7092
7093var AssignmentExpression = (function (Node) {
7094 function AssignmentExpression () {
7095 Node.apply(this, arguments);
7096 }
7097
7098 if ( Node ) AssignmentExpression.__proto__ = Node;
7099 AssignmentExpression.prototype = Object.create( Node && Node.prototype );
7100 AssignmentExpression.prototype.constructor = AssignmentExpression;
7101
7102 AssignmentExpression.prototype.initialise = function initialise (transforms) {
7103 if (this.left.type === 'Identifier') {
7104 var declaration = this.findScope(false).findDeclaration(this.left.name);
7105 // special case – https://gitlab.com/Rich-Harris/buble/issues/11
7106 var statement = declaration && declaration.node.ancestor(3);
7107 if (
7108 statement &&
7109 statement.type === 'ForStatement' &&
7110 statement.body.contains(this)
7111 ) {
7112 statement.reassigned[this.left.name] = true;
7113 }
7114 }
7115
7116 Node.prototype.initialise.call(this, transforms);
7117 };
7118
7119 AssignmentExpression.prototype.transpile = function transpile (code, transforms) {
7120 if (this.left.type === 'Identifier') {
7121 // Do this check after everything has been initialized to find
7122 // shadowing declarations after this expression
7123 checkConst(this.left, this.findScope(false));
7124 }
7125
7126 if (this.operator === '**=' && transforms.exponentiation) {
7127 this.transpileExponentiation(code, transforms);
7128 } else if (/Pattern/.test(this.left.type) && transforms.destructuring) {
7129 this.transpileDestructuring(code, transforms);
7130 }
7131
7132 Node.prototype.transpile.call(this, code, transforms);
7133 };
7134
7135 AssignmentExpression.prototype.transpileDestructuring = function transpileDestructuring (code) {
7136 var this$1 = this;
7137
7138 var writeScope = this.findScope(true);
7139 var lookupScope = this.findScope(false);
7140 var assign = writeScope.createDeclaration('assign');
7141 code.appendRight(this.left.end, ("(" + assign));
7142
7143 code.appendLeft(this.right.end, ', ');
7144 var statementGenerators = [];
7145 destructure(
7146 code,
7147 function (id) { return writeScope.createDeclaration(id); },
7148 function (node) {
7149 var name = lookupScope.resolveName(node.name);
7150 checkConst(node, lookupScope);
7151 return name;
7152 },
7153 this.left,
7154 assign,
7155 true,
7156 statementGenerators
7157 );
7158
7159 var suffix = ', ';
7160 statementGenerators.forEach(function (fn, j) {
7161 if (j === statementGenerators.length - 1) {
7162 suffix = '';
7163 }
7164
7165 fn(this$1.end, '', suffix);
7166 });
7167
7168 if (this.unparenthesizedParent().type === 'ExpressionStatement') {
7169 // no rvalue needed for expression statement
7170 code.appendRight(this.end, ")");
7171 } else {
7172 // destructuring is part of an expression - need an rvalue
7173 code.appendRight(this.end, (", " + assign + ")"));
7174 }
7175 };
7176
7177 AssignmentExpression.prototype.transpileExponentiation = function transpileExponentiation (code) {
7178 var scope = this.findScope(false);
7179
7180 // first, the easy part – `**=` -> `=`
7181 var charIndex = this.left.end;
7182 while (code.original[charIndex] !== '*') { charIndex += 1; }
7183 code.remove(charIndex, charIndex + 2);
7184
7185 // how we do the next part depends on a number of factors – whether
7186 // this is a top-level statement, and whether we're updating a
7187 // simple or complex reference
7188 var base;
7189
7190 var left = this.left.unparenthesize();
7191
7192 if (left.type === 'Identifier') {
7193 base = scope.resolveName(left.name);
7194 } else if (left.type === 'MemberExpression') {
7195 var object;
7196 var needsObjectVar = false;
7197 var property;
7198 var needsPropertyVar = false;
7199
7200 var statement = this.findNearest(/(?:Statement|Declaration)$/);
7201 var i0 = statement.getIndentation();
7202
7203 if (left.property.type === 'Identifier') {
7204 property = left.computed
7205 ? scope.resolveName(left.property.name)
7206 : left.property.name;
7207 } else {
7208 property = scope.createDeclaration('property');
7209 needsPropertyVar = true;
7210 }
7211
7212 if (left.object.type === 'Identifier') {
7213 object = scope.resolveName(left.object.name);
7214 } else {
7215 object = scope.createDeclaration('object');
7216 needsObjectVar = true;
7217 }
7218
7219 if (left.start === statement.start) {
7220 if (needsObjectVar && needsPropertyVar) {
7221 code.prependRight(statement.start, (object + " = "));
7222 code.overwrite(
7223 left.object.end,
7224 left.property.start,
7225 (";\n" + i0 + property + " = ")
7226 );
7227 code.overwrite(
7228 left.property.end,
7229 left.end,
7230 (";\n" + i0 + object + "[" + property + "]")
7231 );
7232 } else if (needsObjectVar) {
7233 code.prependRight(statement.start, (object + " = "));
7234 code.appendLeft(left.object.end, (";\n" + i0));
7235 code.appendLeft(left.object.end, object);
7236 } else if (needsPropertyVar) {
7237 code.prependRight(left.property.start, (property + " = "));
7238 code.appendLeft(left.property.end, (";\n" + i0));
7239 code.move(left.property.start, left.property.end, this.start);
7240
7241 code.appendLeft(left.object.end, ("[" + property + "]"));
7242 code.remove(left.object.end, left.property.start);
7243 code.remove(left.property.end, left.end);
7244 }
7245 } else {
7246 if (needsObjectVar && needsPropertyVar) {
7247 code.prependRight(left.start, ("( " + object + " = "));
7248 code.overwrite(
7249 left.object.end,
7250 left.property.start,
7251 (", " + property + " = ")
7252 );
7253 code.overwrite(
7254 left.property.end,
7255 left.end,
7256 (", " + object + "[" + property + "]")
7257 );
7258 } else if (needsObjectVar) {
7259 code.prependRight(left.start, ("( " + object + " = "));
7260 code.appendLeft(left.object.end, (", " + object));
7261 } else if (needsPropertyVar) {
7262 code.prependRight(left.property.start, ("( " + property + " = "));
7263 code.appendLeft(left.property.end, ", ");
7264 code.move(left.property.start, left.property.end, left.start);
7265
7266 code.overwrite(left.object.end, left.property.start, ("[" + property + "]"));
7267 code.remove(left.property.end, left.end);
7268 }
7269
7270 if (needsPropertyVar) {
7271 code.appendLeft(this.end, " )");
7272 }
7273 }
7274
7275 base =
7276 object +
7277 (left.computed || needsPropertyVar ? ("[" + property + "]") : ("." + property));
7278 }
7279
7280 code.prependRight(this.right.start, ("Math.pow( " + base + ", "));
7281 code.appendLeft(this.right.end, " )");
7282 };
7283
7284 return AssignmentExpression;
7285}(Node$1));
7286
7287var BinaryExpression = (function (Node) {
7288 function BinaryExpression () {
7289 Node.apply(this, arguments);
7290 }
7291
7292 if ( Node ) BinaryExpression.__proto__ = Node;
7293 BinaryExpression.prototype = Object.create( Node && Node.prototype );
7294 BinaryExpression.prototype.constructor = BinaryExpression;
7295
7296 BinaryExpression.prototype.transpile = function transpile (code, transforms) {
7297 if (this.operator === '**' && transforms.exponentiation) {
7298 code.prependRight(this.start, "Math.pow( ");
7299 code.overwrite(this.left.end, this.right.start, ", ");
7300 code.appendLeft(this.end, " )");
7301 }
7302 Node.prototype.transpile.call(this, code, transforms);
7303 };
7304
7305 return BinaryExpression;
7306}(Node$1));
7307
7308var loopStatement = /(?:For(?:In|Of)?|While)Statement/;
7309
7310var BreakStatement = (function (Node) {
7311 function BreakStatement () {
7312 Node.apply(this, arguments);
7313 }
7314
7315 if ( Node ) BreakStatement.__proto__ = Node;
7316 BreakStatement.prototype = Object.create( Node && Node.prototype );
7317 BreakStatement.prototype.constructor = BreakStatement;
7318
7319 BreakStatement.prototype.initialise = function initialise () {
7320 var loop = this.findNearest(loopStatement);
7321 var switchCase = this.findNearest('SwitchCase');
7322
7323 if (loop && (!switchCase || loop.depth > switchCase.depth)) {
7324 loop.canBreak = true;
7325 this.loop = loop;
7326 }
7327 };
7328
7329 BreakStatement.prototype.transpile = function transpile (code) {
7330 if (this.loop && this.loop.shouldRewriteAsFunction) {
7331 if (this.label)
7332 { throw new CompileError(
7333 'Labels are not currently supported in a loop with locally-scoped variables',
7334 this
7335 ); }
7336 code.overwrite(this.start, this.start + 5, "return 'break'");
7337 }
7338 };
7339
7340 return BreakStatement;
7341}(Node$1));
7342
7343var CallExpression = (function (Node) {
7344 function CallExpression () {
7345 Node.apply(this, arguments);
7346 }
7347
7348 if ( Node ) CallExpression.__proto__ = Node;
7349 CallExpression.prototype = Object.create( Node && Node.prototype );
7350 CallExpression.prototype.constructor = CallExpression;
7351
7352 CallExpression.prototype.initialise = function initialise (transforms) {
7353 var this$1 = this;
7354
7355 if (transforms.spreadRest && this.arguments.length > 1) {
7356 var lexicalBoundary = this.findLexicalBoundary();
7357
7358 var i = this.arguments.length;
7359 while (i--) {
7360 var arg = this$1.arguments[i];
7361 if (arg.type === 'SpreadElement' && isArguments(arg.argument)) {
7362 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
7363 }
7364 }
7365 }
7366
7367 Node.prototype.initialise.call(this, transforms);
7368 };
7369
7370 CallExpression.prototype.transpile = function transpile (code, transforms) {
7371 if (transforms.spreadRest && this.arguments.length) {
7372 var hasSpreadElements = false;
7373 var context;
7374
7375 var firstArgument = this.arguments[0];
7376
7377 if (this.arguments.length === 1) {
7378 if (firstArgument.type === 'SpreadElement') {
7379 code.remove(firstArgument.start, firstArgument.argument.start);
7380 hasSpreadElements = true;
7381 }
7382 } else {
7383 hasSpreadElements = spread(
7384 code,
7385 this.arguments,
7386 firstArgument.start,
7387 this.argumentsArrayAlias
7388 );
7389 }
7390
7391 if (hasSpreadElements) {
7392 // we need to handle super() and super.method() differently
7393 // due to its instance
7394 var _super = null;
7395 if (this.callee.type === 'Super') {
7396 _super = this.callee;
7397 } else if (
7398 this.callee.type === 'MemberExpression' &&
7399 this.callee.object.type === 'Super'
7400 ) {
7401 _super = this.callee.object;
7402 }
7403
7404 if (!_super && this.callee.type === 'MemberExpression') {
7405 if (this.callee.object.type === 'Identifier') {
7406 context = this.callee.object.name;
7407 } else {
7408 context = this.findScope(true).createDeclaration('ref');
7409 var callExpression = this.callee.object;
7410 code.prependRight(callExpression.start, ("(" + context + " = "));
7411 code.appendLeft(callExpression.end, ")");
7412 }
7413 } else {
7414 context = 'void 0';
7415 }
7416
7417 code.appendLeft(this.callee.end, '.apply');
7418
7419 if (_super) {
7420 _super.noCall = true; // bit hacky...
7421
7422 if (this.arguments.length > 1) {
7423 if (firstArgument.type !== 'SpreadElement') {
7424 code.prependRight(firstArgument.start, "[ ");
7425 }
7426
7427 code.appendLeft(
7428 this.arguments[this.arguments.length - 1].end,
7429 ' )'
7430 );
7431 }
7432 } else if (this.arguments.length === 1) {
7433 code.prependRight(firstArgument.start, (context + ", "));
7434 } else {
7435 if (firstArgument.type === 'SpreadElement') {
7436 code.appendLeft(firstArgument.start, (context + ", "));
7437 } else {
7438 code.appendLeft(firstArgument.start, (context + ", [ "));
7439 }
7440
7441 code.appendLeft(this.arguments[this.arguments.length - 1].end, ' )');
7442 }
7443 }
7444 }
7445
7446 if (transforms.trailingFunctionCommas && this.arguments.length) {
7447 removeTrailingComma(code, this.arguments[this.arguments.length - 1].end);
7448 }
7449
7450 Node.prototype.transpile.call(this, code, transforms);
7451 };
7452
7453 return CallExpression;
7454}(Node$1));
7455
7456// TODO this code is pretty wild, tidy it up
7457var ClassBody = (function (Node) {
7458 function ClassBody () {
7459 Node.apply(this, arguments);
7460 }
7461
7462 if ( Node ) ClassBody.__proto__ = Node;
7463 ClassBody.prototype = Object.create( Node && Node.prototype );
7464 ClassBody.prototype.constructor = ClassBody;
7465
7466 ClassBody.prototype.transpile = function transpile (code, transforms, inFunctionExpression, superName) {
7467 var this$1 = this;
7468
7469 if (transforms.classes) {
7470 var name = this.parent.name;
7471
7472 var indentStr = code.getIndentString();
7473 var i0 =
7474 this.getIndentation() + (inFunctionExpression ? indentStr : '');
7475 var i1 = i0 + indentStr;
7476
7477 var constructorIndex = findIndex(
7478 this.body,
7479 function (node) { return node.kind === 'constructor'; }
7480 );
7481 var constructor = this.body[constructorIndex];
7482
7483 var introBlock = '';
7484 var outroBlock = '';
7485
7486 if (this.body.length) {
7487 code.remove(this.start, this.body[0].start);
7488 code.remove(this.body[this.body.length - 1].end, this.end);
7489 } else {
7490 code.remove(this.start, this.end);
7491 }
7492
7493 if (constructor) {
7494 constructor.value.body.isConstructorBody = true;
7495
7496 var previousMethod = this.body[constructorIndex - 1];
7497 var nextMethod = this.body[constructorIndex + 1];
7498
7499 // ensure constructor is first
7500 if (constructorIndex > 0) {
7501 code.remove(previousMethod.end, constructor.start);
7502 code.move(
7503 constructor.start,
7504 nextMethod ? nextMethod.start : this.end - 1,
7505 this.body[0].start
7506 );
7507 }
7508
7509 if (!inFunctionExpression) { code.appendLeft(constructor.end, ';'); }
7510 }
7511
7512 var namedFunctions =
7513 this.program.options.namedFunctionExpressions !== false;
7514 var namedConstructor =
7515 namedFunctions ||
7516 this.parent.superClass ||
7517 this.parent.type !== 'ClassDeclaration';
7518 if (this.parent.superClass) {
7519 var inheritanceBlock = "if ( " + superName + " ) " + name + ".__proto__ = " + superName + ";\n" + i0 + name + ".prototype = Object.create( " + superName + " && " + superName + ".prototype );\n" + i0 + name + ".prototype.constructor = " + name + ";";
7520
7521 if (constructor) {
7522 introBlock += "\n\n" + i0 + inheritanceBlock;
7523 } else {
7524 var fn =
7525 "function " + name + " () {" +
7526 (superName
7527 ? ("\n" + i1 + superName + ".apply(this, arguments);\n" + i0 + "}")
7528 : "}") +
7529 (inFunctionExpression ? '' : ';') +
7530 (this.body.length ? ("\n\n" + i0) : '');
7531
7532 inheritanceBlock = fn + inheritanceBlock;
7533 introBlock += inheritanceBlock + "\n\n" + i0;
7534 }
7535 } else if (!constructor) {
7536 var fn$1 = 'function ' + (namedConstructor ? name + ' ' : '') + '() {}';
7537 if (this.parent.type === 'ClassDeclaration') { fn$1 += ';'; }
7538 if (this.body.length) { fn$1 += "\n\n" + i0; }
7539
7540 introBlock += fn$1;
7541 }
7542
7543 var scope = this.findScope(false);
7544
7545 var prototypeGettersAndSetters = [];
7546 var staticGettersAndSetters = [];
7547 var prototypeAccessors;
7548 var staticAccessors;
7549
7550 this.body.forEach(function (method, i) {
7551 if (method.kind === 'constructor') {
7552 var constructorName = namedConstructor ? ' ' + name : '';
7553 code.overwrite(
7554 method.key.start,
7555 method.key.end,
7556 ("function" + constructorName)
7557 );
7558 return;
7559 }
7560
7561 if (method.static) {
7562 var len = code.original[method.start + 6] == ' ' ? 7 : 6;
7563 code.remove(method.start, method.start + len);
7564 }
7565
7566 var isAccessor = method.kind !== 'method';
7567 var lhs;
7568
7569 var methodName = method.key.name;
7570 if (
7571 reserved[methodName] ||
7572 method.value.body.scope.references[methodName]
7573 ) {
7574 methodName = scope.createIdentifier(methodName);
7575 }
7576
7577 // when method name is a string or a number let's pretend it's a computed method
7578
7579 var fake_computed = false;
7580 if (!method.computed && method.key.type === 'Literal') {
7581 fake_computed = true;
7582 method.computed = true;
7583 }
7584
7585 if (isAccessor) {
7586 if (method.computed) {
7587 throw new Error(
7588 'Computed accessor properties are not currently supported'
7589 );
7590 }
7591
7592 code.remove(method.start, method.key.start);
7593
7594 if (method.static) {
7595 if (!~staticGettersAndSetters.indexOf(method.key.name))
7596 { staticGettersAndSetters.push(method.key.name); }
7597 if (!staticAccessors)
7598 { staticAccessors = scope.createIdentifier('staticAccessors'); }
7599
7600 lhs = "" + staticAccessors;
7601 } else {
7602 if (!~prototypeGettersAndSetters.indexOf(method.key.name))
7603 { prototypeGettersAndSetters.push(method.key.name); }
7604 if (!prototypeAccessors)
7605 { prototypeAccessors = scope.createIdentifier('prototypeAccessors'); }
7606
7607 lhs = "" + prototypeAccessors;
7608 }
7609 } else {
7610 lhs = method.static ? ("" + name) : (name + ".prototype");
7611 }
7612
7613 if (!method.computed) { lhs += '.'; }
7614
7615 var insertNewlines =
7616 (constructorIndex > 0 && i === constructorIndex + 1) ||
7617 (i === 0 && constructorIndex === this$1.body.length - 1);
7618
7619 if (insertNewlines) { lhs = "\n\n" + i0 + lhs; }
7620
7621 var c = method.key.end;
7622 if (method.computed) {
7623 if (fake_computed) {
7624 code.prependRight(method.key.start, '[');
7625 code.appendLeft(method.key.end, ']');
7626 } else {
7627 while (code.original[c] !== ']') { c += 1; }
7628 c += 1;
7629 }
7630 }
7631
7632 var funcName =
7633 method.computed || isAccessor || !namedFunctions
7634 ? ''
7635 : (methodName + " ");
7636 var rhs =
7637 (isAccessor ? ("." + (method.kind)) : '') +
7638 " = function" +
7639 (method.value.generator ? '* ' : ' ') +
7640 funcName;
7641 code.remove(c, method.value.start);
7642 code.prependRight(method.value.start, rhs);
7643 code.appendLeft(method.end, ';');
7644
7645 if (method.value.generator) { code.remove(method.start, method.key.start); }
7646
7647 code.prependRight(method.start, lhs);
7648 });
7649
7650 if (prototypeGettersAndSetters.length || staticGettersAndSetters.length) {
7651 var intro = [];
7652 var outro = [];
7653
7654 if (prototypeGettersAndSetters.length) {
7655 intro.push(
7656 ("var " + prototypeAccessors + " = { " + (prototypeGettersAndSetters
7657 .map(function (name) { return (name + ": { configurable: true }"); })
7658 .join(',')) + " };")
7659 );
7660 outro.push(
7661 ("Object.defineProperties( " + name + ".prototype, " + prototypeAccessors + " );")
7662 );
7663 }
7664
7665 if (staticGettersAndSetters.length) {
7666 intro.push(
7667 ("var " + staticAccessors + " = { " + (staticGettersAndSetters
7668 .map(function (name) { return (name + ": { configurable: true }"); })
7669 .join(',')) + " };")
7670 );
7671 outro.push(("Object.defineProperties( " + name + ", " + staticAccessors + " );"));
7672 }
7673
7674 if (constructor) { introBlock += "\n\n" + i0; }
7675 introBlock += intro.join(("\n" + i0));
7676 if (!constructor) { introBlock += "\n\n" + i0; }
7677
7678 outroBlock += "\n\n" + i0 + outro.join(("\n" + i0));
7679 }
7680
7681 if (constructor) {
7682 code.appendLeft(constructor.end, introBlock);
7683 } else {
7684 code.prependRight(this.start, introBlock);
7685 }
7686
7687 code.appendLeft(this.end, outroBlock);
7688 }
7689
7690 Node.prototype.transpile.call(this, code, transforms);
7691 };
7692
7693 return ClassBody;
7694}(Node$1));
7695
7696// TODO this function is slightly flawed – it works on the original string,
7697// not its current edited state.
7698// That's not a problem for the way that it's currently used, but it could
7699// be in future...
7700function deindent(node, code) {
7701 var start = node.start;
7702 var end = node.end;
7703
7704 var indentStr = code.getIndentString();
7705 var indentStrLen = indentStr.length;
7706 var indentStart = start - indentStrLen;
7707
7708 if (
7709 !node.program.indentExclusions[indentStart] &&
7710 code.original.slice(indentStart, start) === indentStr
7711 ) {
7712 code.remove(indentStart, start);
7713 }
7714
7715 var pattern = new RegExp(indentStr + '\\S', 'g');
7716 var slice = code.original.slice(start, end);
7717 var match;
7718
7719 while ((match = pattern.exec(slice))) {
7720 var removeStart = start + match.index;
7721 if (!node.program.indentExclusions[removeStart]) {
7722 code.remove(removeStart, removeStart + indentStrLen);
7723 }
7724 }
7725}
7726
7727var ClassDeclaration = (function (Node) {
7728 function ClassDeclaration () {
7729 Node.apply(this, arguments);
7730 }
7731
7732 if ( Node ) ClassDeclaration.__proto__ = Node;
7733 ClassDeclaration.prototype = Object.create( Node && Node.prototype );
7734 ClassDeclaration.prototype.constructor = ClassDeclaration;
7735
7736 ClassDeclaration.prototype.initialise = function initialise (transforms) {
7737 if (this.id) {
7738 this.name = this.id.name;
7739 this.findScope(true).addDeclaration(this.id, 'class');
7740 } else {
7741 this.name = this.findScope(true).createIdentifier("defaultExport");
7742 }
7743
7744 Node.prototype.initialise.call(this, transforms);
7745 };
7746
7747 ClassDeclaration.prototype.transpile = function transpile (code, transforms) {
7748 if (transforms.classes) {
7749 if (!this.superClass) { deindent(this.body, code); }
7750
7751 var superName =
7752 this.superClass && (this.superClass.name || 'superclass');
7753
7754 var i0 = this.getIndentation();
7755 var i1 = i0 + code.getIndentString();
7756
7757 // if this is an export default statement, we have to move the export to
7758 // after the declaration, because `export default var Foo = ...` is illegal
7759 var isExportDefaultDeclaration = this.parent.type === 'ExportDefaultDeclaration';
7760
7761 if (isExportDefaultDeclaration) {
7762 code.remove(this.parent.start, this.start);
7763 }
7764
7765 var c = this.start;
7766 if (this.id) {
7767 code.overwrite(c, this.id.start, 'var ');
7768 c = this.id.end;
7769 } else {
7770 code.prependLeft(c, ("var " + (this.name)));
7771 }
7772
7773 if (this.superClass) {
7774 if (this.superClass.end === this.body.start) {
7775 code.remove(c, this.superClass.start);
7776 code.appendLeft(c, (" = (function (" + superName + ") {\n" + i1));
7777 } else {
7778 code.overwrite(c, this.superClass.start, ' = ');
7779 code.overwrite(
7780 this.superClass.end,
7781 this.body.start,
7782 ("(function (" + superName + ") {\n" + i1)
7783 );
7784 }
7785 } else {
7786 if (c === this.body.start) {
7787 code.appendLeft(c, ' = ');
7788 } else {
7789 code.overwrite(c, this.body.start, ' = ');
7790 }
7791 }
7792
7793 this.body.transpile(code, transforms, !!this.superClass, superName);
7794
7795 var syntheticDefaultExport =
7796 isExportDefaultDeclaration
7797 ? ("\n\n" + i0 + "export default " + (this.name) + ";")
7798 : '';
7799 if (this.superClass) {
7800 code.appendLeft(this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}("));
7801 code.move(this.superClass.start, this.superClass.end, this.end);
7802 code.prependRight(this.end, ("));" + syntheticDefaultExport));
7803 } else if (syntheticDefaultExport) {
7804 code.prependRight(this.end, syntheticDefaultExport);
7805 }
7806 } else {
7807 this.body.transpile(code, transforms, false, null);
7808 }
7809 };
7810
7811 return ClassDeclaration;
7812}(Node$1));
7813
7814var ClassExpression = (function (Node) {
7815 function ClassExpression () {
7816 Node.apply(this, arguments);
7817 }
7818
7819 if ( Node ) ClassExpression.__proto__ = Node;
7820 ClassExpression.prototype = Object.create( Node && Node.prototype );
7821 ClassExpression.prototype.constructor = ClassExpression;
7822
7823 ClassExpression.prototype.initialise = function initialise (transforms) {
7824 this.name = ( this.id
7825 ? this.id.name
7826 : this.parent.type === 'VariableDeclarator'
7827 ? this.parent.id.name
7828 : this.parent.type !== 'AssignmentExpression'
7829 ? null
7830 : this.parent.left.type === 'Identifier'
7831 ? this.parent.left.name
7832 : this.parent.left.type === 'MemberExpression'
7833 ? this.parent.left.property.name
7834 : null ) || this.findScope(true).createIdentifier('anonymous');
7835
7836 Node.prototype.initialise.call(this, transforms);
7837 };
7838
7839 ClassExpression.prototype.transpile = function transpile (code, transforms) {
7840 if (transforms.classes) {
7841 var superName =
7842 this.superClass && (this.superClass.name || 'superclass');
7843
7844 var i0 = this.getIndentation();
7845 var i1 = i0 + code.getIndentString();
7846
7847 if (this.superClass) {
7848 code.remove(this.start, this.superClass.start);
7849 code.remove(this.superClass.end, this.body.start);
7850 code.appendLeft(this.start, ("(function (" + superName + ") {\n" + i1));
7851 } else {
7852 code.overwrite(this.start, this.body.start, ("(function () {\n" + i1));
7853 }
7854
7855 this.body.transpile(code, transforms, true, superName);
7856
7857 var outro = "\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(";
7858
7859 if (this.superClass) {
7860 code.appendLeft(this.end, outro);
7861 code.move(this.superClass.start, this.superClass.end, this.end);
7862 code.prependRight(this.end, '))');
7863 } else {
7864 code.appendLeft(this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}())"));
7865 }
7866 } else {
7867 this.body.transpile(code, transforms, false);
7868 }
7869 };
7870
7871 return ClassExpression;
7872}(Node$1));
7873
7874var ContinueStatement = (function (Node) {
7875 function ContinueStatement () {
7876 Node.apply(this, arguments);
7877 }
7878
7879 if ( Node ) ContinueStatement.__proto__ = Node;
7880 ContinueStatement.prototype = Object.create( Node && Node.prototype );
7881 ContinueStatement.prototype.constructor = ContinueStatement;
7882
7883 ContinueStatement.prototype.transpile = function transpile (code) {
7884 var loop = this.findNearest(loopStatement);
7885 if (loop.shouldRewriteAsFunction) {
7886 if (this.label)
7887 { throw new CompileError(
7888 'Labels are not currently supported in a loop with locally-scoped variables',
7889 this
7890 ); }
7891 code.overwrite(this.start, this.start + 8, 'return');
7892 }
7893 };
7894
7895 return ContinueStatement;
7896}(Node$1));
7897
7898var ExportDefaultDeclaration = (function (Node) {
7899 function ExportDefaultDeclaration () {
7900 Node.apply(this, arguments);
7901 }
7902
7903 if ( Node ) ExportDefaultDeclaration.__proto__ = Node;
7904 ExportDefaultDeclaration.prototype = Object.create( Node && Node.prototype );
7905 ExportDefaultDeclaration.prototype.constructor = ExportDefaultDeclaration;
7906
7907 ExportDefaultDeclaration.prototype.initialise = function initialise (transforms) {
7908 if (transforms.moduleExport)
7909 { throw new CompileError('export is not supported', this); }
7910 Node.prototype.initialise.call(this, transforms);
7911 };
7912
7913 return ExportDefaultDeclaration;
7914}(Node$1));
7915
7916var ExportNamedDeclaration = (function (Node) {
7917 function ExportNamedDeclaration () {
7918 Node.apply(this, arguments);
7919 }
7920
7921 if ( Node ) ExportNamedDeclaration.__proto__ = Node;
7922 ExportNamedDeclaration.prototype = Object.create( Node && Node.prototype );
7923 ExportNamedDeclaration.prototype.constructor = ExportNamedDeclaration;
7924
7925 ExportNamedDeclaration.prototype.initialise = function initialise (transforms) {
7926 if (transforms.moduleExport)
7927 { throw new CompileError('export is not supported', this); }
7928 Node.prototype.initialise.call(this, transforms);
7929 };
7930
7931 return ExportNamedDeclaration;
7932}(Node$1));
7933
7934var LoopStatement = (function (Node) {
7935 function LoopStatement () {
7936 Node.apply(this, arguments);
7937 }
7938
7939 if ( Node ) LoopStatement.__proto__ = Node;
7940 LoopStatement.prototype = Object.create( Node && Node.prototype );
7941 LoopStatement.prototype.constructor = LoopStatement;
7942
7943 LoopStatement.prototype.findScope = function findScope (functionScope) {
7944 return functionScope || !this.createdScope
7945 ? this.parent.findScope(functionScope)
7946 : this.body.scope;
7947 };
7948
7949 LoopStatement.prototype.initialise = function initialise (transforms) {
7950 var this$1 = this;
7951
7952 this.body.createScope();
7953 this.createdScope = true;
7954
7955 // this is populated as and when reassignments occur
7956 this.reassigned = Object.create(null);
7957 this.aliases = Object.create(null);
7958
7959 Node.prototype.initialise.call(this, transforms);
7960
7961 if (transforms.letConst) {
7962 // see if any block-scoped declarations are referenced
7963 // inside function expressions
7964 var names = Object.keys(this.body.scope.declarations);
7965
7966 var i = names.length;
7967 while (i--) {
7968 var name = names[i];
7969 var declaration = this$1.body.scope.declarations[name];
7970
7971 var j = declaration.instances.length;
7972 while (j--) {
7973 var instance = declaration.instances[j];
7974 var nearestFunctionExpression = instance.findNearest(/Function/);
7975
7976 if (
7977 nearestFunctionExpression &&
7978 nearestFunctionExpression.depth > this$1.depth
7979 ) {
7980 this$1.shouldRewriteAsFunction = true;
7981 break;
7982 }
7983 }
7984
7985 if (this$1.shouldRewriteAsFunction) { break; }
7986 }
7987 }
7988 };
7989
7990 LoopStatement.prototype.transpile = function transpile (code, transforms) {
7991 var needsBlock =
7992 this.type != 'ForOfStatement' &&
7993 (this.body.type !== 'BlockStatement' ||
7994 (this.body.type === 'BlockStatement' && this.body.synthetic));
7995
7996 if (this.shouldRewriteAsFunction) {
7997 var i0 = this.getIndentation();
7998 var i1 = i0 + code.getIndentString();
7999
8000 var argString = this.args ? (" " + (this.args.join(', ')) + " ") : '';
8001 var paramString = this.params ? (" " + (this.params.join(', ')) + " ") : '';
8002
8003 var functionScope = this.findScope(true);
8004 var loop = functionScope.createIdentifier('loop');
8005
8006 var before =
8007 "var " + loop + " = function (" + paramString + ") " +
8008 (this.body.synthetic ? ("{\n" + i0 + (code.getIndentString())) : '');
8009 var after = (this.body.synthetic ? ("\n" + i0 + "}") : '') + ";\n\n" + i0;
8010
8011 code.prependRight(this.body.start, before);
8012 code.appendLeft(this.body.end, after);
8013 code.move(this.start, this.body.start, this.body.end);
8014
8015 if (this.canBreak || this.canReturn) {
8016 var returned = functionScope.createIdentifier('returned');
8017
8018 var insert = "{\n" + i1 + "var " + returned + " = " + loop + "(" + argString + ");\n";
8019 if (this.canBreak)
8020 { insert += "\n" + i1 + "if ( " + returned + " === 'break' ) break;"; }
8021 if (this.canReturn)
8022 { insert += "\n" + i1 + "if ( " + returned + " ) return " + returned + ".v;"; }
8023 insert += "\n" + i0 + "}";
8024
8025 code.prependRight(this.body.end, insert);
8026 } else {
8027 var callExpression = loop + "(" + argString + ");";
8028
8029 if (this.type === 'DoWhileStatement') {
8030 code.overwrite(
8031 this.start,
8032 this.body.start,
8033 ("do {\n" + i1 + callExpression + "\n" + i0 + "}")
8034 );
8035 } else {
8036 code.prependRight(this.body.end, callExpression);
8037 }
8038 }
8039 } else if (needsBlock) {
8040 code.appendLeft(this.body.start, '{ ');
8041 code.prependRight(this.body.end, ' }');
8042 }
8043
8044 Node.prototype.transpile.call(this, code, transforms);
8045 };
8046
8047 return LoopStatement;
8048}(Node$1));
8049
8050var ForStatement = (function (LoopStatement$$1) {
8051 function ForStatement () {
8052 LoopStatement$$1.apply(this, arguments);
8053 }
8054
8055 if ( LoopStatement$$1 ) ForStatement.__proto__ = LoopStatement$$1;
8056 ForStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
8057 ForStatement.prototype.constructor = ForStatement;
8058
8059 ForStatement.prototype.findScope = function findScope (functionScope) {
8060 return functionScope || !this.createdScope
8061 ? this.parent.findScope(functionScope)
8062 : this.body.scope;
8063 };
8064
8065 ForStatement.prototype.transpile = function transpile (code, transforms) {
8066 var this$1 = this;
8067
8068 var i1 = this.getIndentation() + code.getIndentString();
8069
8070 if (this.shouldRewriteAsFunction) {
8071 // which variables are declared in the init statement?
8072 var names =
8073 this.init.type === 'VariableDeclaration'
8074 ? [].concat.apply(
8075 [],
8076 this.init.declarations.map(function (declarator) { return extractNames(declarator.id); }
8077 )
8078 )
8079 : [];
8080
8081 var aliases = this.aliases;
8082
8083 this.args = names.map(
8084 function (name) { return (name in this$1.aliases ? this$1.aliases[name].outer : name); }
8085 );
8086 this.params = names.map(
8087 function (name) { return (name in this$1.aliases ? this$1.aliases[name].inner : name); }
8088 );
8089
8090 var updates = Object.keys(this.reassigned).map(
8091 function (name) { return ((aliases[name].outer) + " = " + (aliases[name].inner) + ";"); }
8092 );
8093
8094 if (updates.length) {
8095 if (this.body.synthetic) {
8096 code.appendLeft(this.body.body[0].end, ("; " + (updates.join(" "))));
8097 } else {
8098 var lastStatement = this.body.body[this.body.body.length - 1];
8099 code.appendLeft(
8100 lastStatement.end,
8101 ("\n\n" + i1 + (updates.join(("\n" + i1))))
8102 );
8103 }
8104 }
8105 }
8106
8107 LoopStatement$$1.prototype.transpile.call(this, code, transforms);
8108 };
8109
8110 return ForStatement;
8111}(LoopStatement));
8112
8113var ForInStatement = (function (LoopStatement$$1) {
8114 function ForInStatement () {
8115 LoopStatement$$1.apply(this, arguments);
8116 }
8117
8118 if ( LoopStatement$$1 ) ForInStatement.__proto__ = LoopStatement$$1;
8119 ForInStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
8120 ForInStatement.prototype.constructor = ForInStatement;
8121
8122 ForInStatement.prototype.findScope = function findScope (functionScope) {
8123 return functionScope || !this.createdScope
8124 ? this.parent.findScope(functionScope)
8125 : this.body.scope;
8126 };
8127
8128 ForInStatement.prototype.transpile = function transpile (code, transforms) {
8129 var this$1 = this;
8130
8131 var hasDeclaration = this.left.type === 'VariableDeclaration';
8132
8133 if (this.shouldRewriteAsFunction) {
8134 // which variables are declared in the init statement?
8135 var names =
8136 hasDeclaration
8137 ? [].concat.apply(
8138 [],
8139 this.left.declarations.map(function (declarator) { return extractNames(declarator.id); }
8140 )
8141 )
8142 : [];
8143
8144 this.args = names.map(
8145 function (name) { return (name in this$1.aliases ? this$1.aliases[name].outer : name); }
8146 );
8147 this.params = names.map(
8148 function (name) { return (name in this$1.aliases ? this$1.aliases[name].inner : name); }
8149 );
8150 }
8151
8152 LoopStatement$$1.prototype.transpile.call(this, code, transforms);
8153
8154 var maybePattern = hasDeclaration ? this.left.declarations[0].id : this.left;
8155 if (maybePattern.type !== 'Identifier') {
8156 this.destructurePattern(code, maybePattern, hasDeclaration);
8157 }
8158 };
8159
8160 ForInStatement.prototype.destructurePattern = function destructurePattern (code, pattern, isDeclaration) {
8161 var scope = this.findScope(true);
8162 var i0 = this.getIndentation();
8163 var i1 = i0 + code.getIndentString();
8164
8165 var ref = scope.createIdentifier('ref');
8166
8167 var bodyStart = this.body.body.length ? this.body.body[0].start : this.body.start + 1;
8168
8169 code.move(pattern.start, pattern.end, bodyStart);
8170
8171 code.prependRight(pattern.end, isDeclaration ? ref : ("var " + ref));
8172
8173 var statementGenerators = [];
8174 destructure(
8175 code,
8176 function (id) { return scope.createIdentifier(id); },
8177 function (ref) {
8178 var name = ref.name;
8179
8180 return scope.resolveName(name);
8181 },
8182 pattern,
8183 ref,
8184 false,
8185 statementGenerators
8186 );
8187
8188 var suffix = ";\n" + i1;
8189 statementGenerators.forEach(function (fn, i) {
8190 if (i === statementGenerators.length - 1) {
8191 suffix = ";\n\n" + i1;
8192 }
8193
8194 fn(bodyStart, '', suffix);
8195 });
8196 };
8197
8198 return ForInStatement;
8199}(LoopStatement));
8200
8201var ForOfStatement = (function (LoopStatement$$1) {
8202 function ForOfStatement () {
8203 LoopStatement$$1.apply(this, arguments);
8204 }
8205
8206 if ( LoopStatement$$1 ) ForOfStatement.__proto__ = LoopStatement$$1;
8207 ForOfStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
8208 ForOfStatement.prototype.constructor = ForOfStatement;
8209
8210 ForOfStatement.prototype.initialise = function initialise (transforms) {
8211 if (transforms.forOf && !transforms.dangerousForOf)
8212 { throw new CompileError(
8213 "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",
8214 this
8215 ); }
8216 LoopStatement$$1.prototype.initialise.call(this, transforms);
8217 };
8218
8219 ForOfStatement.prototype.transpile = function transpile (code, transforms) {
8220 LoopStatement$$1.prototype.transpile.call(this, code, transforms);
8221 if (!transforms.dangerousForOf) { return; }
8222
8223 // edge case (#80)
8224 if (!this.body.body[0]) {
8225 if (
8226 this.left.type === 'VariableDeclaration' &&
8227 this.left.kind === 'var'
8228 ) {
8229 code.remove(this.start, this.left.start);
8230 code.appendLeft(this.left.end, ';');
8231 code.remove(this.left.end, this.end);
8232 } else {
8233 code.remove(this.start, this.end);
8234 }
8235
8236 return;
8237 }
8238
8239 var scope = this.findScope(true);
8240 var i0 = this.getIndentation();
8241 var i1 = i0 + code.getIndentString();
8242
8243 var key = scope.createIdentifier('i');
8244 var list = scope.createIdentifier('list');
8245
8246 if (this.body.synthetic) {
8247 code.prependRight(this.left.start, ("{\n" + i1));
8248 code.appendLeft(this.body.body[0].end, ("\n" + i0 + "}"));
8249 }
8250
8251 var bodyStart = this.body.body[0].start;
8252
8253 code.remove(this.left.end, this.right.start);
8254 code.move(this.left.start, this.left.end, bodyStart);
8255
8256 code.prependRight(this.right.start, ("var " + key + " = 0, " + list + " = "));
8257 code.appendLeft(this.right.end, ("; " + key + " < " + list + ".length; " + key + " += 1"));
8258
8259 var isDeclaration = this.left.type === 'VariableDeclaration';
8260 var maybeDestructuring = isDeclaration ? this.left.declarations[0].id : this.left;
8261 if (maybeDestructuring.type !== 'Identifier') {
8262 var statementGenerators = [];
8263 var ref = scope.createIdentifier('ref');
8264 destructure(
8265 code,
8266 function (id) { return scope.createIdentifier(id); },
8267 function (ref) {
8268 var name = ref.name;
8269
8270 return scope.resolveName(name);
8271 },
8272 maybeDestructuring,
8273 ref,
8274 !isDeclaration,
8275 statementGenerators
8276 );
8277
8278 var suffix = ";\n" + i1;
8279 statementGenerators.forEach(function (fn, i) {
8280 if (i === statementGenerators.length - 1) {
8281 suffix = ";\n\n" + i1;
8282 }
8283
8284 fn(bodyStart, '', suffix);
8285 });
8286
8287 if (isDeclaration) {
8288 code.appendLeft(this.left.start + this.left.kind.length + 1, ref);
8289 code.appendLeft(this.left.end, (" = " + list + "[" + key + "];\n" + i1));
8290 } else {
8291 code.appendLeft(this.left.end, ("var " + ref + " = " + list + "[" + key + "];\n" + i1));
8292 }
8293 } else {
8294 code.appendLeft(this.left.end, (" = " + list + "[" + key + "];\n\n" + i1));
8295 }
8296 };
8297
8298 return ForOfStatement;
8299}(LoopStatement));
8300
8301var FunctionDeclaration = (function (Node) {
8302 function FunctionDeclaration () {
8303 Node.apply(this, arguments);
8304 }
8305
8306 if ( Node ) FunctionDeclaration.__proto__ = Node;
8307 FunctionDeclaration.prototype = Object.create( Node && Node.prototype );
8308 FunctionDeclaration.prototype.constructor = FunctionDeclaration;
8309
8310 FunctionDeclaration.prototype.initialise = function initialise (transforms) {
8311 if (this.generator && transforms.generator) {
8312 throw new CompileError('Generators are not supported', this);
8313 }
8314
8315 this.body.createScope();
8316
8317 if (this.id) {
8318 this.findScope(true).addDeclaration(this.id, 'function');
8319 }
8320 Node.prototype.initialise.call(this, transforms);
8321 };
8322
8323 FunctionDeclaration.prototype.transpile = function transpile (code, transforms) {
8324 Node.prototype.transpile.call(this, code, transforms);
8325 if (transforms.trailingFunctionCommas && this.params.length) {
8326 removeTrailingComma(code, this.params[this.params.length - 1].end);
8327 }
8328 };
8329
8330 return FunctionDeclaration;
8331}(Node$1));
8332
8333var FunctionExpression = (function (Node) {
8334 function FunctionExpression () {
8335 Node.apply(this, arguments);
8336 }
8337
8338 if ( Node ) FunctionExpression.__proto__ = Node;
8339 FunctionExpression.prototype = Object.create( Node && Node.prototype );
8340 FunctionExpression.prototype.constructor = FunctionExpression;
8341
8342 FunctionExpression.prototype.initialise = function initialise (transforms) {
8343 var this$1 = this;
8344
8345 if (this.generator && transforms.generator) {
8346 throw new CompileError('Generators are not supported', this);
8347 }
8348
8349 this.body.createScope();
8350
8351 if (this.id) {
8352 // function expression IDs belong to the child scope...
8353 this.body.scope.addDeclaration(this.id, 'function');
8354 }
8355
8356 Node.prototype.initialise.call(this, transforms);
8357
8358 var parent = this.parent;
8359 var methodName;
8360
8361 if (
8362 transforms.conciseMethodProperty &&
8363 parent.type === 'Property' &&
8364 parent.kind === 'init' &&
8365 parent.method &&
8366 parent.key.type === 'Identifier'
8367 ) {
8368 // object literal concise method
8369 methodName = parent.key.name;
8370 } else if (
8371 transforms.classes &&
8372 parent.type === 'MethodDefinition' &&
8373 parent.kind === 'method' &&
8374 parent.key.type === 'Identifier'
8375 ) {
8376 // method definition in a class
8377 methodName = parent.key.name;
8378 } else if (this.id && this.id.type === 'Identifier') {
8379 // naked function expression
8380 methodName = this.id.alias || this.id.name;
8381 }
8382
8383 if (methodName) {
8384 for (var i$1 = 0, list$1 = this$1.params; i$1 < list$1.length; i$1 += 1) {
8385 var param = list$1[i$1];
8386
8387 if (param.type === 'Identifier' && methodName === param.name) {
8388 // workaround for Safari 9/WebKit bug:
8389 // https://gitlab.com/Rich-Harris/buble/issues/154
8390 // change parameter name when same as method name
8391
8392 var scope = this$1.body.scope;
8393 var declaration = scope.declarations[methodName];
8394
8395 var alias = scope.createIdentifier(methodName);
8396 param.alias = alias;
8397
8398 for (var i = 0, list = declaration.instances; i < list.length; i += 1) {
8399 var identifier = list[i];
8400
8401 identifier.alias = alias;
8402 }
8403
8404 break;
8405 }
8406 }
8407 }
8408 };
8409
8410 FunctionExpression.prototype.transpile = function transpile (code, transforms) {
8411 Node.prototype.transpile.call(this, code, transforms);
8412 if (transforms.trailingFunctionCommas && this.params.length) {
8413 removeTrailingComma(code, this.params[this.params.length - 1].end);
8414 }
8415 };
8416
8417 return FunctionExpression;
8418}(Node$1));
8419
8420function isReference(node, parent) {
8421 if (node.type === 'MemberExpression') {
8422 return !node.computed && isReference(node.object, node);
8423 }
8424
8425 if (node.type === 'Identifier') {
8426 // the only time we could have an identifier node without a parent is
8427 // if it's the entire body of a function without a block statement –
8428 // i.e. an arrow function expression like `a => a`
8429 if (!parent) { return true; }
8430
8431 if (/(Function|Class)Expression/.test(parent.type)) { return false; }
8432
8433 if (parent.type === 'VariableDeclarator') { return node === parent.init; }
8434
8435 // TODO is this right?
8436 if (
8437 parent.type === 'MemberExpression' ||
8438 parent.type === 'MethodDefinition'
8439 ) {
8440 return parent.computed || node === parent.object;
8441 }
8442
8443 if (parent.type === 'ArrayPattern') { return false; }
8444
8445 // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
8446 if (parent.type === 'Property') {
8447 if (parent.parent.type === 'ObjectPattern') { return false; }
8448 return parent.computed || node === parent.value;
8449 }
8450
8451 // disregard the `bar` in `class Foo { bar () {...} }`
8452 if (parent.type === 'MethodDefinition') { return false; }
8453
8454 // disregard the `bar` in `export { foo as bar }`
8455 if (parent.type === 'ExportSpecifier' && node !== parent.local)
8456 { return false; }
8457
8458 return true;
8459 }
8460}
8461
8462var Identifier = (function (Node) {
8463 function Identifier () {
8464 Node.apply(this, arguments);
8465 }
8466
8467 if ( Node ) Identifier.__proto__ = Node;
8468 Identifier.prototype = Object.create( Node && Node.prototype );
8469 Identifier.prototype.constructor = Identifier;
8470
8471 Identifier.prototype.findScope = function findScope (functionScope) {
8472 if (this.parent.params && ~this.parent.params.indexOf(this)) {
8473 return this.parent.body.scope;
8474 }
8475
8476 if (this.parent.type === 'FunctionExpression' && this === this.parent.id) {
8477 return this.parent.body.scope;
8478 }
8479
8480 return this.parent.findScope(functionScope);
8481 };
8482
8483 Identifier.prototype.initialise = function initialise (transforms) {
8484 if (isReference(this, this.parent)) {
8485 if (
8486 transforms.arrow &&
8487 this.name === 'arguments' &&
8488 !this.findScope(false).contains(this.name)
8489 ) {
8490 var lexicalBoundary = this.findLexicalBoundary();
8491 var arrowFunction = this.findNearest('ArrowFunctionExpression');
8492 var loop = this.findNearest(loopStatement);
8493
8494 if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) {
8495 this.alias = lexicalBoundary.getArgumentsAlias();
8496 }
8497
8498 if (
8499 loop &&
8500 loop.body.contains(this) &&
8501 loop.depth > lexicalBoundary.depth
8502 ) {
8503 this.alias = lexicalBoundary.getArgumentsAlias();
8504 }
8505 }
8506
8507 this.findScope(false).addReference(this);
8508 }
8509 };
8510
8511 Identifier.prototype.transpile = function transpile (code) {
8512 if (this.alias) {
8513 code.overwrite(this.start, this.end, this.alias, {
8514 storeName: true,
8515 contentOnly: true
8516 });
8517 }
8518 };
8519
8520 return Identifier;
8521}(Node$1));
8522
8523var IfStatement = (function (Node) {
8524 function IfStatement () {
8525 Node.apply(this, arguments);
8526 }
8527
8528 if ( Node ) IfStatement.__proto__ = Node;
8529 IfStatement.prototype = Object.create( Node && Node.prototype );
8530 IfStatement.prototype.constructor = IfStatement;
8531
8532 IfStatement.prototype.initialise = function initialise (transforms) {
8533 Node.prototype.initialise.call(this, transforms);
8534 };
8535
8536 IfStatement.prototype.transpile = function transpile (code, transforms) {
8537 if (
8538 this.consequent.type !== 'BlockStatement' ||
8539 (this.consequent.type === 'BlockStatement' && this.consequent.synthetic)
8540 ) {
8541 code.appendLeft(this.consequent.start, '{ ');
8542 code.prependRight(this.consequent.end, ' }');
8543 }
8544
8545 if (
8546 this.alternate &&
8547 this.alternate.type !== 'IfStatement' &&
8548 (this.alternate.type !== 'BlockStatement' ||
8549 (this.alternate.type === 'BlockStatement' && this.alternate.synthetic))
8550 ) {
8551 code.appendLeft(this.alternate.start, '{ ');
8552 code.prependRight(this.alternate.end, ' }');
8553 }
8554
8555 Node.prototype.transpile.call(this, code, transforms);
8556 };
8557
8558 return IfStatement;
8559}(Node$1));
8560
8561var ImportDeclaration = (function (Node) {
8562 function ImportDeclaration () {
8563 Node.apply(this, arguments);
8564 }
8565
8566 if ( Node ) ImportDeclaration.__proto__ = Node;
8567 ImportDeclaration.prototype = Object.create( Node && Node.prototype );
8568 ImportDeclaration.prototype.constructor = ImportDeclaration;
8569
8570 ImportDeclaration.prototype.initialise = function initialise (transforms) {
8571 if (transforms.moduleImport)
8572 { throw new CompileError('import is not supported', this); }
8573 Node.prototype.initialise.call(this, transforms);
8574 };
8575
8576 return ImportDeclaration;
8577}(Node$1));
8578
8579var ImportDefaultSpecifier = (function (Node) {
8580 function ImportDefaultSpecifier () {
8581 Node.apply(this, arguments);
8582 }
8583
8584 if ( Node ) ImportDefaultSpecifier.__proto__ = Node;
8585 ImportDefaultSpecifier.prototype = Object.create( Node && Node.prototype );
8586 ImportDefaultSpecifier.prototype.constructor = ImportDefaultSpecifier;
8587
8588 ImportDefaultSpecifier.prototype.initialise = function initialise (transforms) {
8589 this.findScope(true).addDeclaration(this.local, 'import');
8590 Node.prototype.initialise.call(this, transforms);
8591 };
8592
8593 return ImportDefaultSpecifier;
8594}(Node$1));
8595
8596var ImportSpecifier = (function (Node) {
8597 function ImportSpecifier () {
8598 Node.apply(this, arguments);
8599 }
8600
8601 if ( Node ) ImportSpecifier.__proto__ = Node;
8602 ImportSpecifier.prototype = Object.create( Node && Node.prototype );
8603 ImportSpecifier.prototype.constructor = ImportSpecifier;
8604
8605 ImportSpecifier.prototype.initialise = function initialise (transforms) {
8606 this.findScope(true).addDeclaration(this.local, 'import');
8607 Node.prototype.initialise.call(this, transforms);
8608 };
8609
8610 return ImportSpecifier;
8611}(Node$1));
8612
8613var hasDashes = function (val) { return /-/.test(val); };
8614
8615var formatKey = function (key) { return (hasDashes(key) ? ("'" + key + "'") : key); };
8616
8617var formatVal = function (val) { return (val ? '' : 'true'); };
8618
8619var JSXAttribute = (function (Node) {
8620 function JSXAttribute () {
8621 Node.apply(this, arguments);
8622 }
8623
8624 if ( Node ) JSXAttribute.__proto__ = Node;
8625 JSXAttribute.prototype = Object.create( Node && Node.prototype );
8626 JSXAttribute.prototype.constructor = JSXAttribute;
8627
8628 JSXAttribute.prototype.transpile = function transpile (code, transforms) {
8629 var ref = this.name;
8630 var start = ref.start;
8631 var name = ref.name;
8632
8633 // Overwrite equals sign if value is present.
8634 var end = this.value ? this.value.start : this.name.end;
8635
8636 code.overwrite(start, end, ((formatKey(name)) + ": " + (formatVal(this.value))));
8637
8638 Node.prototype.transpile.call(this, code, transforms);
8639 };
8640
8641 return JSXAttribute;
8642}(Node$1));
8643
8644function containsNewLine(node) {
8645 return (
8646 node.type === 'JSXText' && !/\S/.test(node.value) && /\n/.test(node.value)
8647 );
8648}
8649
8650var JSXClosingElement = (function (Node) {
8651 function JSXClosingElement () {
8652 Node.apply(this, arguments);
8653 }
8654
8655 if ( Node ) JSXClosingElement.__proto__ = Node;
8656 JSXClosingElement.prototype = Object.create( Node && Node.prototype );
8657 JSXClosingElement.prototype.constructor = JSXClosingElement;
8658
8659 JSXClosingElement.prototype.transpile = function transpile (code) {
8660 var spaceBeforeParen = true;
8661
8662 var lastChild = this.parent.children[this.parent.children.length - 1];
8663
8664 // omit space before closing paren if
8665 // a) this is on a separate line, or
8666 // b) there are no children but there are attributes
8667 if (
8668 (lastChild && containsNewLine(lastChild)) ||
8669 this.parent.openingElement.attributes.length
8670 ) {
8671 spaceBeforeParen = false;
8672 }
8673
8674 code.overwrite(this.start, this.end, spaceBeforeParen ? ' )' : ')');
8675 };
8676
8677 return JSXClosingElement;
8678}(Node$1));
8679
8680function containsNewLine$1(node) {
8681 return (
8682 node.type === 'JSXText' && !/\S/.test(node.value) && /\n/.test(node.value)
8683 );
8684}
8685
8686var JSXClosingFragment = (function (Node) {
8687 function JSXClosingFragment () {
8688 Node.apply(this, arguments);
8689 }
8690
8691 if ( Node ) JSXClosingFragment.__proto__ = Node;
8692 JSXClosingFragment.prototype = Object.create( Node && Node.prototype );
8693 JSXClosingFragment.prototype.constructor = JSXClosingFragment;
8694
8695 JSXClosingFragment.prototype.transpile = function transpile (code) {
8696 var spaceBeforeParen = true;
8697
8698 var lastChild = this.parent.children[this.parent.children.length - 1];
8699
8700 // omit space before closing paren if this is on a separate line
8701 if (lastChild && containsNewLine$1(lastChild)) {
8702 spaceBeforeParen = false;
8703 }
8704
8705 code.overwrite(this.start, this.end, spaceBeforeParen ? ' )' : ')');
8706 };
8707
8708 return JSXClosingFragment;
8709}(Node$1));
8710
8711function normalise(str, removeTrailingWhitespace) {
8712
8713 str = str.replace(/\u00a0/g, '&nbsp;');
8714
8715 if (removeTrailingWhitespace && /\n/.test(str)) {
8716 str = str.replace(/\s+$/, '');
8717 }
8718
8719 str = str
8720 .replace(/^\n\r?\s+/, '') // remove leading newline + space
8721 .replace(/\s*\n\r?\s*/gm, ' '); // replace newlines with spaces
8722
8723 // TODO prefer single quotes?
8724 return JSON.stringify(str);
8725}
8726
8727var JSXElement = (function (Node) {
8728 function JSXElement () {
8729 Node.apply(this, arguments);
8730 }
8731
8732 if ( Node ) JSXElement.__proto__ = Node;
8733 JSXElement.prototype = Object.create( Node && Node.prototype );
8734 JSXElement.prototype.constructor = JSXElement;
8735
8736 JSXElement.prototype.transpile = function transpile (code, transforms) {
8737 Node.prototype.transpile.call(this, code, transforms);
8738
8739 var children = this.children.filter(function (child) {
8740 if (child.type !== 'JSXText') { return true; }
8741
8742 // remove whitespace-only literals, unless on a single line
8743 return /\S/.test(child.raw) || !/\n/.test(child.raw);
8744 });
8745
8746 if (children.length) {
8747 var c = this.openingElement.end;
8748
8749 var i;
8750 for (i = 0; i < children.length; i += 1) {
8751 var child = children[i];
8752
8753 if (
8754 child.type === 'JSXExpressionContainer' &&
8755 child.expression.type === 'JSXEmptyExpression'
8756 ) {
8757 // empty block is a no op
8758 } else {
8759 var tail =
8760 code.original[c] === '\n' && child.type !== 'JSXText' ? '' : ' ';
8761 code.appendLeft(c, ("," + tail));
8762 }
8763
8764 if (child.type === 'JSXText') {
8765 var str = normalise(child.value, i === children.length - 1);
8766 code.overwrite(child.start, child.end, str);
8767 }
8768
8769 c = child.end;
8770 }
8771 }
8772 };
8773
8774 return JSXElement;
8775}(Node$1));
8776
8777var JSXExpressionContainer = (function (Node) {
8778 function JSXExpressionContainer () {
8779 Node.apply(this, arguments);
8780 }
8781
8782 if ( Node ) JSXExpressionContainer.__proto__ = Node;
8783 JSXExpressionContainer.prototype = Object.create( Node && Node.prototype );
8784 JSXExpressionContainer.prototype.constructor = JSXExpressionContainer;
8785
8786 JSXExpressionContainer.prototype.transpile = function transpile (code, transforms) {
8787 code.remove(this.start, this.expression.start);
8788 code.remove(this.expression.end, this.end);
8789
8790 Node.prototype.transpile.call(this, code, transforms);
8791 };
8792
8793 return JSXExpressionContainer;
8794}(Node$1));
8795
8796var JSXFragment = (function (JSXElement$$1) {
8797 function JSXFragment () {
8798 JSXElement$$1.apply(this, arguments);
8799 }if ( JSXElement$$1 ) JSXFragment.__proto__ = JSXElement$$1;
8800 JSXFragment.prototype = Object.create( JSXElement$$1 && JSXElement$$1.prototype );
8801 JSXFragment.prototype.constructor = JSXFragment;
8802
8803
8804
8805 return JSXFragment;
8806}(JSXElement));
8807
8808var JSXOpeningElement = (function (Node) {
8809 function JSXOpeningElement () {
8810 Node.apply(this, arguments);
8811 }
8812
8813 if ( Node ) JSXOpeningElement.__proto__ = Node;
8814 JSXOpeningElement.prototype = Object.create( Node && Node.prototype );
8815 JSXOpeningElement.prototype.constructor = JSXOpeningElement;
8816
8817 JSXOpeningElement.prototype.transpile = function transpile (code, transforms) {
8818 var this$1 = this;
8819
8820 Node.prototype.transpile.call(this, code, transforms);
8821
8822 code.overwrite(this.start, this.name.start, ((this.program.jsx) + "( "));
8823
8824 var html =
8825 this.name.type === 'JSXIdentifier' &&
8826 this.name.name[0] === this.name.name[0].toLowerCase();
8827 if (html) { code.prependRight(this.name.start, "'"); }
8828
8829 var len = this.attributes.length;
8830 var c = this.name.end;
8831
8832 if (len) {
8833 var i;
8834
8835 var hasSpread = false;
8836 for (i = 0; i < len; i += 1) {
8837 if (this$1.attributes[i].type === 'JSXSpreadAttribute') {
8838 hasSpread = true;
8839 break;
8840 }
8841 }
8842
8843 c = this.attributes[0].end;
8844
8845 for (i = 0; i < len; i += 1) {
8846 var attr = this$1.attributes[i];
8847
8848 if (i > 0) {
8849 if (attr.start === c) { code.prependRight(c, ', '); }
8850 else { code.overwrite(c, attr.start, ', '); }
8851 }
8852
8853 if (hasSpread && attr.type !== 'JSXSpreadAttribute') {
8854 var lastAttr = this$1.attributes[i - 1];
8855 var nextAttr = this$1.attributes[i + 1];
8856
8857 if (!lastAttr || lastAttr.type === 'JSXSpreadAttribute') {
8858 code.prependRight(attr.start, '{ ');
8859 }
8860
8861 if (!nextAttr || nextAttr.type === 'JSXSpreadAttribute') {
8862 code.appendLeft(attr.end, ' }');
8863 }
8864 }
8865
8866 c = attr.end;
8867 }
8868
8869 var after;
8870 var before;
8871 if (hasSpread) {
8872 if (len === 1) {
8873 before = html ? "'," : ',';
8874 } else {
8875 if (!this.program.options.objectAssign) {
8876 throw new CompileError(
8877 "Mixed JSX attributes ending in spread requires specified objectAssign option with 'Object.assign' or polyfill helper.",
8878 this
8879 );
8880 }
8881 before = html
8882 ? ("', " + (this.program.options.objectAssign) + "({},")
8883 : (", " + (this.program.options.objectAssign) + "({},");
8884 after = ')';
8885 }
8886 } else {
8887 before = html ? "', {" : ', {';
8888 after = ' }';
8889 }
8890
8891 code.prependRight(this.name.end, before);
8892
8893 if (after) {
8894 code.appendLeft(this.attributes[len - 1].end, after);
8895 }
8896 } else {
8897 code.appendLeft(this.name.end, html ? "', null" : ", null");
8898 c = this.name.end;
8899 }
8900
8901 if (this.selfClosing) {
8902 code.overwrite(c, this.end, this.attributes.length ? ")" : " )");
8903 } else {
8904 code.remove(c, this.end);
8905 }
8906 };
8907
8908 return JSXOpeningElement;
8909}(Node$1));
8910
8911var JSXOpeningFragment = (function (Node) {
8912 function JSXOpeningFragment () {
8913 Node.apply(this, arguments);
8914 }
8915
8916 if ( Node ) JSXOpeningFragment.__proto__ = Node;
8917 JSXOpeningFragment.prototype = Object.create( Node && Node.prototype );
8918 JSXOpeningFragment.prototype.constructor = JSXOpeningFragment;
8919
8920 JSXOpeningFragment.prototype.transpile = function transpile (code, transforms) {
8921 code.overwrite(this.start, this.end, ((this.program.jsx) + "( React.Fragment, null"));
8922 };
8923
8924 return JSXOpeningFragment;
8925}(Node$1));
8926
8927var JSXSpreadAttribute = (function (Node) {
8928 function JSXSpreadAttribute () {
8929 Node.apply(this, arguments);
8930 }
8931
8932 if ( Node ) JSXSpreadAttribute.__proto__ = Node;
8933 JSXSpreadAttribute.prototype = Object.create( Node && Node.prototype );
8934 JSXSpreadAttribute.prototype.constructor = JSXSpreadAttribute;
8935
8936 JSXSpreadAttribute.prototype.transpile = function transpile (code, transforms) {
8937 code.remove(this.start, this.argument.start);
8938 code.remove(this.argument.end, this.end);
8939
8940 Node.prototype.transpile.call(this, code, transforms);
8941 };
8942
8943 return JSXSpreadAttribute;
8944}(Node$1));
8945
8946var regjsgen = createCommonjsModule(function (module, exports) {
8947/*!
8948 * regjsgen 0.3.0
8949 * Copyright 2014-2016 Benjamin Tan <https://demoneaux.github.io/>
8950 * Available under MIT license <https://github.com/demoneaux/regjsgen/blob/master/LICENSE>
8951 */
8952(function() {
8953 var objectTypes = {
8954 'function': true,
8955 'object': true
8956 };
8957
8958 // Used as a reference to the global object.
8959 var root = (objectTypes[typeof window] && window) || this;
8960
8961 // Detect free variable `exports`.
8962 var freeExports = objectTypes['object'] && exports;
8963
8964 // Detect free variable `module`.
8965 var freeModule = objectTypes['object'] && module && !module.nodeType && module;
8966
8967 // Detect free variable `global` from Node.js or Browserified code and use it as `root`.
8968 var freeGlobal = freeExports && freeModule && typeof commonjsGlobal == 'object' && commonjsGlobal;
8969 if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
8970 root = freeGlobal;
8971 }
8972
8973 // Used to check objects for own properties.
8974 var hasOwnProperty = Object.prototype.hasOwnProperty;
8975
8976 /*--------------------------------------------------------------------------*/
8977
8978 // Generates strings based on the given code points.
8979 // Based on https://mths.be/fromcodepoint v0.2.0 by @mathias.
8980 var stringFromCharCode = String.fromCharCode;
8981 var floor = Math.floor;
8982 function fromCodePoint() {
8983 var MAX_SIZE = 0x4000;
8984 var codeUnits = [];
8985 var highSurrogate;
8986 var lowSurrogate;
8987 var index = -1;
8988 var length = arguments.length;
8989 if (!length) {
8990 return '';
8991 }
8992 var result = '';
8993 while (++index < length) {
8994 var codePoint = Number(arguments[index]);
8995 if (
8996 !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
8997 codePoint < 0 || // not a valid Unicode code point
8998 codePoint > 0x10FFFF || // not a valid Unicode code point
8999 floor(codePoint) != codePoint // not an integer
9000 ) {
9001 throw RangeError('Invalid code point: ' + codePoint);
9002 }
9003 if (codePoint <= 0xFFFF) {
9004 // BMP code point
9005 codeUnits.push(codePoint);
9006 } else {
9007 // Astral code point; split in surrogate halves
9008 // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
9009 codePoint -= 0x10000;
9010 highSurrogate = (codePoint >> 10) + 0xD800;
9011 lowSurrogate = (codePoint % 0x400) + 0xDC00;
9012 codeUnits.push(highSurrogate, lowSurrogate);
9013 }
9014 if (index + 1 == length || codeUnits.length > MAX_SIZE) {
9015 result += stringFromCharCode.apply(null, codeUnits);
9016 codeUnits.length = 0;
9017 }
9018 }
9019 return result;
9020 }
9021
9022 /*--------------------------------------------------------------------------*/
9023
9024 // Ensures that nodes have the correct types.
9025 var assertTypeRegexMap = {};
9026 function assertType(type, expected) {
9027 if (expected.indexOf('|') == -1) {
9028 if (type == expected) {
9029 return;
9030 }
9031
9032 throw Error('Invalid node type: ' + type + '; expected type: ' + expected);
9033 }
9034
9035 expected = hasOwnProperty.call(assertTypeRegexMap, expected)
9036 ? assertTypeRegexMap[expected]
9037 : (assertTypeRegexMap[expected] = RegExp('^(?:' + expected + ')$'));
9038
9039 if (expected.test(type)) {
9040 return;
9041 }
9042
9043 throw Error('Invalid node type: ' + type + '; expected types: ' + expected);
9044 }
9045
9046 /*--------------------------------------------------------------------------*/
9047
9048 // Generates a regular expression string based on an AST.
9049 function generate(node) {
9050 var type = node.type;
9051
9052 if (hasOwnProperty.call(generators, type)) {
9053 return generators[type](node);
9054 }
9055
9056 throw Error('Invalid node type: ' + type);
9057 }
9058
9059 /*--------------------------------------------------------------------------*/
9060
9061 function generateAlternative(node) {
9062 assertType(node.type, 'alternative');
9063
9064 var terms = node.body,
9065 i = -1,
9066 length = terms.length,
9067 result = '';
9068
9069 while (++i < length) {
9070 result += generateTerm(terms[i]);
9071 }
9072
9073 return result;
9074 }
9075
9076 function generateAnchor(node) {
9077 assertType(node.type, 'anchor');
9078
9079 switch (node.kind) {
9080 case 'start':
9081 return '^';
9082 case 'end':
9083 return '$';
9084 case 'boundary':
9085 return '\\b';
9086 case 'not-boundary':
9087 return '\\B';
9088 default:
9089 throw Error('Invalid assertion');
9090 }
9091 }
9092
9093 function generateAtom(node) {
9094 assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
9095
9096 return generate(node);
9097 }
9098
9099 function generateCharacterClass(node) {
9100 assertType(node.type, 'characterClass');
9101
9102 var classRanges = node.body,
9103 i = -1,
9104 length = classRanges.length,
9105 result = '';
9106
9107 if (node.negative) {
9108 result += '^';
9109 }
9110
9111 while (++i < length) {
9112 result += generateClassAtom(classRanges[i]);
9113 }
9114
9115 return '[' + result + ']';
9116 }
9117
9118 function generateCharacterClassEscape(node) {
9119 assertType(node.type, 'characterClassEscape');
9120
9121 return '\\' + node.value;
9122 }
9123
9124 function generateUnicodePropertyEscape(node) {
9125 assertType(node.type, 'unicodePropertyEscape');
9126
9127 return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
9128 }
9129
9130 function generateCharacterClassRange(node) {
9131 assertType(node.type, 'characterClassRange');
9132
9133 var min = node.min,
9134 max = node.max;
9135
9136 if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
9137 throw Error('Invalid character class range');
9138 }
9139
9140 return generateClassAtom(min) + '-' + generateClassAtom(max);
9141 }
9142
9143 function generateClassAtom(node) {
9144 assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value');
9145
9146 return generate(node);
9147 }
9148
9149 function generateDisjunction(node) {
9150 assertType(node.type, 'disjunction');
9151
9152 var body = node.body,
9153 i = -1,
9154 length = body.length,
9155 result = '';
9156
9157 while (++i < length) {
9158 if (i != 0) {
9159 result += '|';
9160 }
9161 result += generate(body[i]);
9162 }
9163
9164 return result;
9165 }
9166
9167 function generateDot(node) {
9168 assertType(node.type, 'dot');
9169
9170 return '.';
9171 }
9172
9173 function generateGroup(node) {
9174 assertType(node.type, 'group');
9175
9176 var result = '';
9177
9178 switch (node.behavior) {
9179 case 'normal':
9180 break;
9181 case 'ignore':
9182 result += '?:';
9183 break;
9184 case 'lookahead':
9185 result += '?=';
9186 break;
9187 case 'negativeLookahead':
9188 result += '?!';
9189 break;
9190 default:
9191 throw Error('Invalid behaviour: ' + node.behaviour);
9192 }
9193
9194 var body = node.body,
9195 i = -1,
9196 length = body.length;
9197
9198 while (++i < length) {
9199 result += generate(body[i]);
9200 }
9201
9202 return '(' + result + ')';
9203 }
9204
9205 function generateQuantifier(node) {
9206 assertType(node.type, 'quantifier');
9207
9208 var quantifier = '',
9209 min = node.min,
9210 max = node.max;
9211
9212 if (max == null) {
9213 if (min == 0) {
9214 quantifier = '*';
9215 } else if (min == 1) {
9216 quantifier = '+';
9217 } else {
9218 quantifier = '{' + min + ',}';
9219 }
9220 } else if (min == max) {
9221 quantifier = '{' + min + '}';
9222 } else if (min == 0 && max == 1) {
9223 quantifier = '?';
9224 } else {
9225 quantifier = '{' + min + ',' + max + '}';
9226 }
9227
9228 if (!node.greedy) {
9229 quantifier += '?';
9230 }
9231
9232 return generateAtom(node.body[0]) + quantifier;
9233 }
9234
9235 function generateReference(node) {
9236 assertType(node.type, 'reference');
9237
9238 return '\\' + node.matchIndex;
9239 }
9240
9241 function generateTerm(node) {
9242 assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value');
9243
9244 return generate(node);
9245 }
9246
9247 function generateValue(node) {
9248 assertType(node.type, 'value');
9249
9250 var kind = node.kind,
9251 codePoint = node.codePoint;
9252
9253 switch (kind) {
9254 case 'controlLetter':
9255 return '\\c' + fromCodePoint(codePoint + 64);
9256 case 'hexadecimalEscape':
9257 return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
9258 case 'identifier':
9259 return '\\' + fromCodePoint(codePoint);
9260 case 'null':
9261 return '\\' + codePoint;
9262 case 'octal':
9263 return '\\' + codePoint.toString(8);
9264 case 'singleEscape':
9265 switch (codePoint) {
9266 case 0x0008:
9267 return '\\b';
9268 case 0x0009:
9269 return '\\t';
9270 case 0x000A:
9271 return '\\n';
9272 case 0x000B:
9273 return '\\v';
9274 case 0x000C:
9275 return '\\f';
9276 case 0x000D:
9277 return '\\r';
9278 default:
9279 throw Error('Invalid codepoint: ' + codePoint);
9280 }
9281 case 'symbol':
9282 return fromCodePoint(codePoint);
9283 case 'unicodeEscape':
9284 return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
9285 case 'unicodeCodePointEscape':
9286 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
9287 default:
9288 throw Error('Unsupported node kind: ' + kind);
9289 }
9290 }
9291
9292 /*--------------------------------------------------------------------------*/
9293
9294 // Used to generate strings for each node type.
9295 var generators = {
9296 'alternative': generateAlternative,
9297 'anchor': generateAnchor,
9298 'characterClass': generateCharacterClass,
9299 'characterClassEscape': generateCharacterClassEscape,
9300 'characterClassRange': generateCharacterClassRange,
9301 'unicodePropertyEscape': generateUnicodePropertyEscape,
9302 'disjunction': generateDisjunction,
9303 'dot': generateDot,
9304 'group': generateGroup,
9305 'quantifier': generateQuantifier,
9306 'reference': generateReference,
9307 'value': generateValue
9308 };
9309
9310 /*--------------------------------------------------------------------------*/
9311
9312 // Export regjsgen.
9313 // Some AMD build optimizers, like r.js, check for condition patterns like the following:
9314 if (typeof undefined == 'function' && typeof undefined.amd == 'object' && undefined.amd) {
9315 // Define as an anonymous module so it can be aliased through path mapping.
9316 undefined(function() {
9317 return {
9318 'generate': generate
9319 };
9320 });
9321 }
9322 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
9323 else if (freeExports && freeModule) {
9324 // Export for CommonJS support.
9325 freeExports.generate = generate;
9326 }
9327 else {
9328 // Export to the global object.
9329 root.regjsgen = {
9330 'generate': generate
9331 };
9332 }
9333}.call(commonjsGlobal));
9334});
9335
9336var parser = createCommonjsModule(function (module) {
9337// regjsparser
9338//
9339// ==================================================================
9340//
9341// See ECMA-262 Standard: 15.10.1
9342//
9343// NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the
9344// term "Anchor" is used.
9345//
9346// Pattern ::
9347// Disjunction
9348//
9349// Disjunction ::
9350// Alternative
9351// Alternative | Disjunction
9352//
9353// Alternative ::
9354// [empty]
9355// Alternative Term
9356//
9357// Term ::
9358// Anchor
9359// Atom
9360// Atom Quantifier
9361//
9362// Anchor ::
9363// ^
9364// $
9365// \ b
9366// \ B
9367// ( ? = Disjunction )
9368// ( ? ! Disjunction )
9369//
9370// Quantifier ::
9371// QuantifierPrefix
9372// QuantifierPrefix ?
9373//
9374// QuantifierPrefix ::
9375// *
9376// +
9377// ?
9378// { DecimalDigits }
9379// { DecimalDigits , }
9380// { DecimalDigits , DecimalDigits }
9381//
9382// Atom ::
9383// PatternCharacter
9384// .
9385// \ AtomEscape
9386// CharacterClass
9387// ( Disjunction )
9388// ( ? : Disjunction )
9389//
9390// PatternCharacter ::
9391// SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |
9392//
9393// AtomEscape ::
9394// DecimalEscape
9395// CharacterEscape
9396// CharacterClassEscape
9397//
9398// CharacterEscape[U] ::
9399// ControlEscape
9400// c ControlLetter
9401// HexEscapeSequence
9402// RegExpUnicodeEscapeSequence[?U] (ES6)
9403// IdentityEscape[?U]
9404//
9405// ControlEscape ::
9406// one of f n r t v
9407// ControlLetter ::
9408// one of
9409// 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
9410// 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
9411//
9412// IdentityEscape ::
9413// SourceCharacter but not IdentifierPart
9414// <ZWJ>
9415// <ZWNJ>
9416//
9417// DecimalEscape ::
9418// DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
9419//
9420// CharacterClassEscape ::
9421// one of d D s S w W
9422//
9423// CharacterClass ::
9424// [ [lookahead ∉ {^}] ClassRanges ]
9425// [ ^ ClassRanges ]
9426//
9427// ClassRanges ::
9428// [empty]
9429// NonemptyClassRanges
9430//
9431// NonemptyClassRanges ::
9432// ClassAtom
9433// ClassAtom NonemptyClassRangesNoDash
9434// ClassAtom - ClassAtom ClassRanges
9435//
9436// NonemptyClassRangesNoDash ::
9437// ClassAtom
9438// ClassAtomNoDash NonemptyClassRangesNoDash
9439// ClassAtomNoDash - ClassAtom ClassRanges
9440//
9441// ClassAtom ::
9442// -
9443// ClassAtomNoDash
9444//
9445// ClassAtomNoDash ::
9446// SourceCharacter but not one of \ or ] or -
9447// \ ClassEscape
9448//
9449// ClassEscape ::
9450// DecimalEscape
9451// b
9452// CharacterEscape
9453// CharacterClassEscape
9454
9455(function() {
9456
9457 function parse(str, flags, features) {
9458 if (!features) {
9459 features = {};
9460 }
9461 function addRaw(node) {
9462 node.raw = str.substring(node.range[0], node.range[1]);
9463 return node;
9464 }
9465
9466 function updateRawStart(node, start) {
9467 node.range[0] = start;
9468 return addRaw(node);
9469 }
9470
9471 function createAnchor(kind, rawLength) {
9472 return addRaw({
9473 type: 'anchor',
9474 kind: kind,
9475 range: [
9476 pos - rawLength,
9477 pos
9478 ]
9479 });
9480 }
9481
9482 function createValue(kind, codePoint, from, to) {
9483 return addRaw({
9484 type: 'value',
9485 kind: kind,
9486 codePoint: codePoint,
9487 range: [from, to]
9488 });
9489 }
9490
9491 function createEscaped(kind, codePoint, value, fromOffset) {
9492 fromOffset = fromOffset || 0;
9493 return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);
9494 }
9495
9496 function createCharacter(matches) {
9497 var _char = matches[0];
9498 var first = _char.charCodeAt(0);
9499 if (hasUnicodeFlag) {
9500 var second;
9501 if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
9502 second = lookahead().charCodeAt(0);
9503 if (second >= 0xDC00 && second <= 0xDFFF) {
9504 // Unicode surrogate pair
9505 pos++;
9506 return createValue(
9507 'symbol',
9508 (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,
9509 pos - 2, pos);
9510 }
9511 }
9512 }
9513 return createValue('symbol', first, pos - 1, pos);
9514 }
9515
9516 function createDisjunction(alternatives, from, to) {
9517 return addRaw({
9518 type: 'disjunction',
9519 body: alternatives,
9520 range: [
9521 from,
9522 to
9523 ]
9524 });
9525 }
9526
9527 function createDot() {
9528 return addRaw({
9529 type: 'dot',
9530 range: [
9531 pos - 1,
9532 pos
9533 ]
9534 });
9535 }
9536
9537 function createCharacterClassEscape(value) {
9538 return addRaw({
9539 type: 'characterClassEscape',
9540 value: value,
9541 range: [
9542 pos - 2,
9543 pos
9544 ]
9545 });
9546 }
9547
9548 function createReference(matchIndex) {
9549 return addRaw({
9550 type: 'reference',
9551 matchIndex: parseInt(matchIndex, 10),
9552 range: [
9553 pos - 1 - matchIndex.length,
9554 pos
9555 ]
9556 });
9557 }
9558
9559 function createGroup(behavior, disjunction, from, to) {
9560 return addRaw({
9561 type: 'group',
9562 behavior: behavior,
9563 body: disjunction,
9564 range: [
9565 from,
9566 to
9567 ]
9568 });
9569 }
9570
9571 function createQuantifier(min, max, from, to) {
9572 if (to == null) {
9573 from = pos - 1;
9574 to = pos;
9575 }
9576
9577 return addRaw({
9578 type: 'quantifier',
9579 min: min,
9580 max: max,
9581 greedy: true,
9582 body: null, // set later on
9583 range: [
9584 from,
9585 to
9586 ]
9587 });
9588 }
9589
9590 function createAlternative(terms, from, to) {
9591 return addRaw({
9592 type: 'alternative',
9593 body: terms,
9594 range: [
9595 from,
9596 to
9597 ]
9598 });
9599 }
9600
9601 function createCharacterClass(classRanges, negative, from, to) {
9602 return addRaw({
9603 type: 'characterClass',
9604 body: classRanges,
9605 negative: negative,
9606 range: [
9607 from,
9608 to
9609 ]
9610 });
9611 }
9612
9613 function createClassRange(min, max, from, to) {
9614 // See 15.10.2.15:
9615 if (min.codePoint > max.codePoint) {
9616 bail('invalid range in character class', min.raw + '-' + max.raw, from, to);
9617 }
9618
9619 return addRaw({
9620 type: 'characterClassRange',
9621 min: min,
9622 max: max,
9623 range: [
9624 from,
9625 to
9626 ]
9627 });
9628 }
9629
9630 function flattenBody(body) {
9631 if (body.type === 'alternative') {
9632 return body.body;
9633 } else {
9634 return [body];
9635 }
9636 }
9637
9638 function incr(amount) {
9639 amount = (amount || 1);
9640 var res = str.substring(pos, pos + amount);
9641 pos += (amount || 1);
9642 return res;
9643 }
9644
9645 function skip(value) {
9646 if (!match(value)) {
9647 bail('character', value);
9648 }
9649 }
9650
9651 function match(value) {
9652 if (str.indexOf(value, pos) === pos) {
9653 return incr(value.length);
9654 }
9655 }
9656
9657 function lookahead() {
9658 return str[pos];
9659 }
9660
9661 function current(value) {
9662 return str.indexOf(value, pos) === pos;
9663 }
9664
9665 function next(value) {
9666 return str[pos + 1] === value;
9667 }
9668
9669 function matchReg(regExp) {
9670 var subStr = str.substring(pos);
9671 var res = subStr.match(regExp);
9672 if (res) {
9673 res.range = [];
9674 res.range[0] = pos;
9675 incr(res[0].length);
9676 res.range[1] = pos;
9677 }
9678 return res;
9679 }
9680
9681 function parseDisjunction() {
9682 // Disjunction ::
9683 // Alternative
9684 // Alternative | Disjunction
9685 var res = [], from = pos;
9686 res.push(parseAlternative());
9687
9688 while (match('|')) {
9689 res.push(parseAlternative());
9690 }
9691
9692 if (res.length === 1) {
9693 return res[0];
9694 }
9695
9696 return createDisjunction(res, from, pos);
9697 }
9698
9699 function parseAlternative() {
9700 var res = [], from = pos;
9701 var term;
9702
9703 // Alternative ::
9704 // [empty]
9705 // Alternative Term
9706 while (term = parseTerm()) {
9707 res.push(term);
9708 }
9709
9710 if (res.length === 1) {
9711 return res[0];
9712 }
9713
9714 return createAlternative(res, from, pos);
9715 }
9716
9717 function parseTerm() {
9718 // Term ::
9719 // Anchor
9720 // Atom
9721 // Atom Quantifier
9722
9723 if (pos >= str.length || current('|') || current(')')) {
9724 return null; /* Means: The term is empty */
9725 }
9726
9727 var anchor = parseAnchor();
9728
9729 if (anchor) {
9730 return anchor;
9731 }
9732
9733 var atom = parseAtom();
9734 if (!atom) {
9735 bail('Expected atom');
9736 }
9737 var quantifier = parseQuantifier() || false;
9738 if (quantifier) {
9739 quantifier.body = flattenBody(atom);
9740 // The quantifier contains the atom. Therefore, the beginning of the
9741 // quantifier range is given by the beginning of the atom.
9742 updateRawStart(quantifier, atom.range[0]);
9743 return quantifier;
9744 }
9745 return atom;
9746 }
9747
9748 function parseGroup(matchA, typeA, matchB, typeB) {
9749 var type = null, from = pos;
9750
9751 if (match(matchA)) {
9752 type = typeA;
9753 } else if (match(matchB)) {
9754 type = typeB;
9755 } else {
9756 return false;
9757 }
9758
9759 var body = parseDisjunction();
9760 if (!body) {
9761 bail('Expected disjunction');
9762 }
9763 skip(')');
9764 var group = createGroup(type, flattenBody(body), from, pos);
9765
9766 if (type == 'normal') {
9767 // Keep track of the number of closed groups. This is required for
9768 // parseDecimalEscape(). In case the string is parsed a second time the
9769 // value already holds the total count and no incrementation is required.
9770 if (firstIteration) {
9771 closedCaptureCounter++;
9772 }
9773 }
9774 return group;
9775 }
9776
9777 function parseAnchor() {
9778 // Anchor ::
9779 // ^
9780 // $
9781 // \ b
9782 // \ B
9783 // ( ? = Disjunction )
9784 // ( ? ! Disjunction )
9785 if (match('^')) {
9786 return createAnchor('start', 1 /* rawLength */);
9787 } else if (match('$')) {
9788 return createAnchor('end', 1 /* rawLength */);
9789 } else if (match('\\b')) {
9790 return createAnchor('boundary', 2 /* rawLength */);
9791 } else if (match('\\B')) {
9792 return createAnchor('not-boundary', 2 /* rawLength */);
9793 } else {
9794 return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');
9795 }
9796 }
9797
9798 function parseQuantifier() {
9799 // Quantifier ::
9800 // QuantifierPrefix
9801 // QuantifierPrefix ?
9802 //
9803 // QuantifierPrefix ::
9804 // *
9805 // +
9806 // ?
9807 // { DecimalDigits }
9808 // { DecimalDigits , }
9809 // { DecimalDigits , DecimalDigits }
9810
9811 var res, from = pos;
9812 var quantifier;
9813 var min, max;
9814
9815 if (match('*')) {
9816 quantifier = createQuantifier(0);
9817 }
9818 else if (match('+')) {
9819 quantifier = createQuantifier(1);
9820 }
9821 else if (match('?')) {
9822 quantifier = createQuantifier(0, 1);
9823 }
9824 else if (res = matchReg(/^\{([0-9]+)\}/)) {
9825 min = parseInt(res[1], 10);
9826 quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
9827 }
9828 else if (res = matchReg(/^\{([0-9]+),\}/)) {
9829 min = parseInt(res[1], 10);
9830 quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
9831 }
9832 else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
9833 min = parseInt(res[1], 10);
9834 max = parseInt(res[2], 10);
9835 if (min > max) {
9836 bail('numbers out of order in {} quantifier', '', from, pos);
9837 }
9838 quantifier = createQuantifier(min, max, res.range[0], res.range[1]);
9839 }
9840
9841 if (quantifier) {
9842 if (match('?')) {
9843 quantifier.greedy = false;
9844 quantifier.range[1] += 1;
9845 }
9846 }
9847
9848 return quantifier;
9849 }
9850
9851 function parseAtom() {
9852 // Atom ::
9853 // PatternCharacter
9854 // .
9855 // \ AtomEscape
9856 // CharacterClass
9857 // ( Disjunction )
9858 // ( ? : Disjunction )
9859
9860 var res;
9861
9862 // jviereck: allow ']', '}' here as well to be compatible with browser's
9863 // implementations: ']'.match(/]/);
9864 // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) {
9865 if (res = matchReg(/^[^^$\\.*+?(){[|]/)) {
9866 // PatternCharacter
9867 return createCharacter(res);
9868 }
9869 else if (match('.')) {
9870 // .
9871 return createDot();
9872 }
9873 else if (match('\\')) {
9874 // \ AtomEscape
9875 res = parseAtomEscape();
9876 if (!res) {
9877 bail('atomEscape');
9878 }
9879 return res;
9880 }
9881 else if (res = parseCharacterClass()) {
9882 return res;
9883 }
9884 else {
9885 // ( Disjunction )
9886 // ( ? : Disjunction )
9887 return parseGroup('(?:', 'ignore', '(', 'normal');
9888 }
9889 }
9890
9891 function parseUnicodeSurrogatePairEscape(firstEscape) {
9892 if (hasUnicodeFlag) {
9893 var first, second;
9894 if (firstEscape.kind == 'unicodeEscape' &&
9895 (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&
9896 current('\\') && next('u') ) {
9897 var prevPos = pos;
9898 pos++;
9899 var secondEscape = parseClassEscape();
9900 if (secondEscape.kind == 'unicodeEscape' &&
9901 (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {
9902 // Unicode surrogate pair
9903 firstEscape.range[1] = secondEscape.range[1];
9904 firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
9905 firstEscape.type = 'value';
9906 firstEscape.kind = 'unicodeCodePointEscape';
9907 addRaw(firstEscape);
9908 }
9909 else {
9910 pos = prevPos;
9911 }
9912 }
9913 }
9914 return firstEscape;
9915 }
9916
9917 function parseClassEscape() {
9918 return parseAtomEscape(true);
9919 }
9920
9921 function parseAtomEscape(insideCharacterClass) {
9922 // AtomEscape ::
9923 // DecimalEscape
9924 // CharacterEscape
9925 // CharacterClassEscape
9926
9927 var res, from = pos;
9928
9929 res = parseDecimalEscape();
9930 if (res) {
9931 return res;
9932 }
9933
9934 // For ClassEscape
9935 if (insideCharacterClass) {
9936 if (match('b')) {
9937 // 15.10.2.19
9938 // The production ClassEscape :: b evaluates by returning the
9939 // CharSet containing the one character <BS> (Unicode value 0008).
9940 return createEscaped('singleEscape', 0x0008, '\\b');
9941 } else if (match('B')) {
9942 bail('\\B not possible inside of CharacterClass', '', from);
9943 }
9944 }
9945
9946 res = parseCharacterEscape();
9947
9948 return res;
9949 }
9950
9951
9952 function parseDecimalEscape() {
9953 // DecimalEscape ::
9954 // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
9955 // CharacterClassEscape :: one of d D s S w W
9956
9957 var res, match;
9958
9959 if (res = matchReg(/^(?!0)\d+/)) {
9960 match = res[0];
9961 var refIdx = parseInt(res[0], 10);
9962 if (refIdx <= closedCaptureCounter) {
9963 // If the number is smaller than the normal-groups found so
9964 // far, then it is a reference...
9965 return createReference(res[0]);
9966 } else {
9967 // ... otherwise it needs to be interpreted as a octal (if the
9968 // number is in an octal format). If it is NOT octal format,
9969 // then the slash is ignored and the number is matched later
9970 // as normal characters.
9971
9972 // Recall the negative decision to decide if the input must be parsed
9973 // a second time with the total normal-groups.
9974 backrefDenied.push(refIdx);
9975
9976 // Reset the position again, as maybe only parts of the previous
9977 // matched numbers are actual octal numbers. E.g. in '019' only
9978 // the '01' should be matched.
9979 incr(-res[0].length);
9980 if (res = matchReg(/^[0-7]{1,3}/)) {
9981 return createEscaped('octal', parseInt(res[0], 8), res[0], 1);
9982 } else {
9983 // If we end up here, we have a case like /\91/. Then the
9984 // first slash is to be ignored and the 9 & 1 to be treated
9985 // like ordinary characters. Create a character for the
9986 // first number only here - other number-characters
9987 // (if available) will be matched later.
9988 res = createCharacter(matchReg(/^[89]/));
9989 return updateRawStart(res, res.range[0] - 1);
9990 }
9991 }
9992 }
9993 // Only allow octal numbers in the following. All matched numbers start
9994 // with a zero (if the do not, the previous if-branch is executed).
9995 // If the number is not octal format and starts with zero (e.g. `091`)
9996 // then only the zeros `0` is treated here and the `91` are ordinary
9997 // characters.
9998 // Example:
9999 // /\091/.exec('\091')[0].length === 3
10000 else if (res = matchReg(/^[0-7]{1,3}/)) {
10001 match = res[0];
10002 if (/^0{1,3}$/.test(match)) {
10003 // If they are all zeros, then only take the first one.
10004 return createEscaped('null', 0x0000, '0', match.length + 1);
10005 } else {
10006 return createEscaped('octal', parseInt(match, 8), match, 1);
10007 }
10008 } else if (res = matchReg(/^[dDsSwW]/)) {
10009 return createCharacterClassEscape(res[0]);
10010 }
10011 return false;
10012 }
10013
10014 function parseCharacterEscape() {
10015 // CharacterEscape ::
10016 // ControlEscape
10017 // c ControlLetter
10018 // HexEscapeSequence
10019 // UnicodeEscapeSequence
10020 // IdentityEscape
10021
10022 var res;
10023 if (res = matchReg(/^[fnrtv]/)) {
10024 // ControlEscape
10025 var codePoint = 0;
10026 switch (res[0]) {
10027 case 't': codePoint = 0x009; break;
10028 case 'n': codePoint = 0x00A; break;
10029 case 'v': codePoint = 0x00B; break;
10030 case 'f': codePoint = 0x00C; break;
10031 case 'r': codePoint = 0x00D; break;
10032 }
10033 return createEscaped('singleEscape', codePoint, '\\' + res[0]);
10034 } else if (res = matchReg(/^c([a-zA-Z])/)) {
10035 // c ControlLetter
10036 return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);
10037 } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) {
10038 // HexEscapeSequence
10039 return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2);
10040 } else if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {
10041 // UnicodeEscapeSequence
10042 return parseUnicodeSurrogatePairEscape(
10043 createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2)
10044 );
10045 } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {
10046 // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)
10047 return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);
10048 } else if (features.unicodePropertyEscape && hasUnicodeFlag && (res = matchReg(/^([pP])\{([^\}]+)\}/))) {
10049 // https://github.com/jviereck/regjsparser/issues/77
10050 return addRaw({
10051 type: 'unicodePropertyEscape',
10052 negative: res[1] === 'P',
10053 value: res[2],
10054 range: [res.range[0] - 1, res.range[1]],
10055 raw: res[0]
10056 });
10057 } else {
10058 // IdentityEscape
10059 return parseIdentityEscape();
10060 }
10061 }
10062
10063 // Taken from the Esprima parser.
10064 function isIdentifierPart(ch) {
10065 // Generated by `tools/generate-identifier-regex.js`.
10066 var NonAsciiIdentifierPart = new RegExp('[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B2\u08E4-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\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\u135D-\u135F\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\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\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2D\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]');
10067
10068 return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
10069 (ch >= 65 && ch <= 90) || // A..Z
10070 (ch >= 97 && ch <= 122) || // a..z
10071 (ch >= 48 && ch <= 57) || // 0..9
10072 (ch === 92) || // \ (backslash)
10073 ((ch >= 0x80) && NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
10074 }
10075
10076 function parseIdentityEscape() {
10077 // IdentityEscape ::
10078 // SourceCharacter but not IdentifierPart
10079 // <ZWJ>
10080 // <ZWNJ>
10081
10082 var ZWJ = '\u200C';
10083 var ZWNJ = '\u200D';
10084
10085 var tmp;
10086
10087 if (!isIdentifierPart(lookahead())) {
10088 tmp = incr();
10089 return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1);
10090 }
10091
10092 if (match(ZWJ)) {
10093 // <ZWJ>
10094 return createEscaped('identifier', 0x200C, ZWJ);
10095 } else if (match(ZWNJ)) {
10096 // <ZWNJ>
10097 return createEscaped('identifier', 0x200D, ZWNJ);
10098 }
10099
10100 return null;
10101 }
10102
10103 function parseCharacterClass() {
10104 // CharacterClass ::
10105 // [ [lookahead ∉ {^}] ClassRanges ]
10106 // [ ^ ClassRanges ]
10107
10108 var res, from = pos;
10109 if (res = matchReg(/^\[\^/)) {
10110 res = parseClassRanges();
10111 skip(']');
10112 return createCharacterClass(res, true, from, pos);
10113 } else if (match('[')) {
10114 res = parseClassRanges();
10115 skip(']');
10116 return createCharacterClass(res, false, from, pos);
10117 }
10118
10119 return null;
10120 }
10121
10122 function parseClassRanges() {
10123 // ClassRanges ::
10124 // [empty]
10125 // NonemptyClassRanges
10126
10127 var res;
10128 if (current(']')) {
10129 // Empty array means nothing insinde of the ClassRange.
10130 return [];
10131 } else {
10132 res = parseNonemptyClassRanges();
10133 if (!res) {
10134 bail('nonEmptyClassRanges');
10135 }
10136 return res;
10137 }
10138 }
10139
10140 function parseHelperClassRanges(atom) {
10141 var from, to, res;
10142 if (current('-') && !next(']')) {
10143 // ClassAtom - ClassAtom ClassRanges
10144 skip('-');
10145
10146 res = parseClassAtom();
10147 if (!res) {
10148 bail('classAtom');
10149 }
10150 to = pos;
10151 var classRanges = parseClassRanges();
10152 if (!classRanges) {
10153 bail('classRanges');
10154 }
10155 from = atom.range[0];
10156 if (classRanges.type === 'empty') {
10157 return [createClassRange(atom, res, from, to)];
10158 }
10159 return [createClassRange(atom, res, from, to)].concat(classRanges);
10160 }
10161
10162 res = parseNonemptyClassRangesNoDash();
10163 if (!res) {
10164 bail('nonEmptyClassRangesNoDash');
10165 }
10166
10167 return [atom].concat(res);
10168 }
10169
10170 function parseNonemptyClassRanges() {
10171 // NonemptyClassRanges ::
10172 // ClassAtom
10173 // ClassAtom NonemptyClassRangesNoDash
10174 // ClassAtom - ClassAtom ClassRanges
10175
10176 var atom = parseClassAtom();
10177 if (!atom) {
10178 bail('classAtom');
10179 }
10180
10181 if (current(']')) {
10182 // ClassAtom
10183 return [atom];
10184 }
10185
10186 // ClassAtom NonemptyClassRangesNoDash
10187 // ClassAtom - ClassAtom ClassRanges
10188 return parseHelperClassRanges(atom);
10189 }
10190
10191 function parseNonemptyClassRangesNoDash() {
10192 // NonemptyClassRangesNoDash ::
10193 // ClassAtom
10194 // ClassAtomNoDash NonemptyClassRangesNoDash
10195 // ClassAtomNoDash - ClassAtom ClassRanges
10196
10197 var res = parseClassAtom();
10198 if (!res) {
10199 bail('classAtom');
10200 }
10201 if (current(']')) {
10202 // ClassAtom
10203 return res;
10204 }
10205
10206 // ClassAtomNoDash NonemptyClassRangesNoDash
10207 // ClassAtomNoDash - ClassAtom ClassRanges
10208 return parseHelperClassRanges(res);
10209 }
10210
10211 function parseClassAtom() {
10212 // ClassAtom ::
10213 // -
10214 // ClassAtomNoDash
10215 if (match('-')) {
10216 return createCharacter('-');
10217 } else {
10218 return parseClassAtomNoDash();
10219 }
10220 }
10221
10222 function parseClassAtomNoDash() {
10223 // ClassAtomNoDash ::
10224 // SourceCharacter but not one of \ or ] or -
10225 // \ ClassEscape
10226
10227 var res;
10228 if (res = matchReg(/^[^\\\]-]/)) {
10229 return createCharacter(res[0]);
10230 } else if (match('\\')) {
10231 res = parseClassEscape();
10232 if (!res) {
10233 bail('classEscape');
10234 }
10235
10236 return parseUnicodeSurrogatePairEscape(res);
10237 }
10238 }
10239
10240 function bail(message, details, from, to) {
10241 from = from == null ? pos : from;
10242 to = to == null ? from : to;
10243
10244 var contextStart = Math.max(0, from - 10);
10245 var contextEnd = Math.min(to + 10, str.length);
10246
10247 // Output a bit of context and a line pointing to where our error is.
10248 //
10249 // We are assuming that there are no actual newlines in the content as this is a regular expression.
10250 var context = ' ' + str.substring(contextStart, contextEnd);
10251 var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^';
10252
10253 throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer);
10254 }
10255
10256 var backrefDenied = [];
10257 var closedCaptureCounter = 0;
10258 var firstIteration = true;
10259 var hasUnicodeFlag = (flags || "").indexOf("u") !== -1;
10260 var pos = 0;
10261
10262 // Convert the input to a string and treat the empty string special.
10263 str = String(str);
10264 if (str === '') {
10265 str = '(?:)';
10266 }
10267
10268 var result = parseDisjunction();
10269
10270 if (result.range[1] !== str.length) {
10271 bail('Could not parse entire input - got stuck', '', result.range[1]);
10272 }
10273
10274 // The spec requires to interpret the `\2` in `/\2()()/` as backreference.
10275 // As the parser collects the number of capture groups as the string is
10276 // parsed it is impossible to make these decisions at the point when the
10277 // `\2` is handled. In case the local decision turns out to be wrong after
10278 // the parsing has finished, the input string is parsed a second time with
10279 // the total number of capture groups set.
10280 //
10281 // SEE: https://github.com/jviereck/regjsparser/issues/70
10282 for (var i = 0; i < backrefDenied.length; i++) {
10283 if (backrefDenied[i] <= closedCaptureCounter) {
10284 // Parse the input a second time.
10285 pos = 0;
10286 firstIteration = false;
10287 return parseDisjunction();
10288 }
10289 }
10290
10291 return result;
10292 }
10293
10294 var regjsparser = {
10295 parse: parse
10296 };
10297
10298 if ('object' !== 'undefined' && module.exports) {
10299 module.exports = regjsparser;
10300 } else {
10301 window.regjsparser = regjsparser;
10302 }
10303
10304}());
10305});
10306
10307var regenerate = createCommonjsModule(function (module, exports) {
10308/*! https://mths.be/regenerate v1.3.3 by @mathias | MIT license */
10309(function(root) {
10310
10311 // Detect free variables `exports`.
10312 var freeExports = 'object' == 'object' && exports;
10313
10314 // Detect free variable `module`.
10315 var freeModule = 'object' == 'object' && module &&
10316 module.exports == freeExports && module;
10317
10318 // Detect free variable `global`, from Node.js/io.js or Browserified code,
10319 // and use it as `root`.
10320 var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
10321 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
10322 root = freeGlobal;
10323 }
10324
10325 /*--------------------------------------------------------------------------*/
10326
10327 var ERRORS = {
10328 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
10329 'to the `start` value.',
10330 'codePointRange': 'Invalid code point value. Code points range from ' +
10331 'U+000000 to U+10FFFF.'
10332 };
10333
10334 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
10335 var HIGH_SURROGATE_MIN = 0xD800;
10336 var HIGH_SURROGATE_MAX = 0xDBFF;
10337 var LOW_SURROGATE_MIN = 0xDC00;
10338 var LOW_SURROGATE_MAX = 0xDFFF;
10339
10340 // In Regenerate output, `\0` is never preceded by `\` because we sort by
10341 // code point value, so let’s keep this regular expression simple.
10342 var regexNull = /\\x00([^0123456789]|$)/g;
10343
10344 var object = {};
10345 var hasOwnProperty = object.hasOwnProperty;
10346 var extend = function(destination, source) {
10347 var key;
10348 for (key in source) {
10349 if (hasOwnProperty.call(source, key)) {
10350 destination[key] = source[key];
10351 }
10352 }
10353 return destination;
10354 };
10355
10356 var forEach = function(array, callback) {
10357 var index = -1;
10358 var length = array.length;
10359 while (++index < length) {
10360 callback(array[index], index);
10361 }
10362 };
10363
10364 var toString = object.toString;
10365 var isArray = function(value) {
10366 return toString.call(value) == '[object Array]';
10367 };
10368 var isNumber = function(value) {
10369 return typeof value == 'number' ||
10370 toString.call(value) == '[object Number]';
10371 };
10372
10373 // This assumes that `number` is a positive integer that `toString()`s nicely
10374 // (which is the case for all code point values).
10375 var zeroes = '0000';
10376 var pad = function(number, totalCharacters) {
10377 var string = String(number);
10378 return string.length < totalCharacters
10379 ? (zeroes + string).slice(-totalCharacters)
10380 : string;
10381 };
10382
10383 var hex = function(number) {
10384 return Number(number).toString(16).toUpperCase();
10385 };
10386
10387 var slice = [].slice;
10388
10389 /*--------------------------------------------------------------------------*/
10390
10391 var dataFromCodePoints = function(codePoints) {
10392 var index = -1;
10393 var length = codePoints.length;
10394 var max = length - 1;
10395 var result = [];
10396 var isStart = true;
10397 var tmp;
10398 var previous = 0;
10399 while (++index < length) {
10400 tmp = codePoints[index];
10401 if (isStart) {
10402 result.push(tmp);
10403 previous = tmp;
10404 isStart = false;
10405 } else {
10406 if (tmp == previous + 1) {
10407 if (index != max) {
10408 previous = tmp;
10409 continue;
10410 } else {
10411 isStart = true;
10412 result.push(tmp + 1);
10413 }
10414 } else {
10415 // End the previous range and start a new one.
10416 result.push(previous + 1, tmp);
10417 previous = tmp;
10418 }
10419 }
10420 }
10421 if (!isStart) {
10422 result.push(tmp + 1);
10423 }
10424 return result;
10425 };
10426
10427 var dataRemove = function(data, codePoint) {
10428 // Iterate over the data per `(start, end)` pair.
10429 var index = 0;
10430 var start;
10431 var end;
10432 var length = data.length;
10433 while (index < length) {
10434 start = data[index];
10435 end = data[index + 1];
10436 if (codePoint >= start && codePoint < end) {
10437 // Modify this pair.
10438 if (codePoint == start) {
10439 if (end == start + 1) {
10440 // Just remove `start` and `end`.
10441 data.splice(index, 2);
10442 return data;
10443 } else {
10444 // Just replace `start` with a new value.
10445 data[index] = codePoint + 1;
10446 return data;
10447 }
10448 } else if (codePoint == end - 1) {
10449 // Just replace `end` with a new value.
10450 data[index + 1] = codePoint;
10451 return data;
10452 } else {
10453 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
10454 data.splice(index, 2, start, codePoint, codePoint + 1, end);
10455 return data;
10456 }
10457 }
10458 index += 2;
10459 }
10460 return data;
10461 };
10462
10463 var dataRemoveRange = function(data, rangeStart, rangeEnd) {
10464 if (rangeEnd < rangeStart) {
10465 throw Error(ERRORS.rangeOrder);
10466 }
10467 // Iterate over the data per `(start, end)` pair.
10468 var index = 0;
10469 var start;
10470 var end;
10471 while (index < data.length) {
10472 start = data[index];
10473 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
10474
10475 // Exit as soon as no more matching pairs can be found.
10476 if (start > rangeEnd) {
10477 return data;
10478 }
10479
10480 // Check if this range pair is equal to, or forms a subset of, the range
10481 // to be removed.
10482 // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
10483 // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
10484 if (rangeStart <= start && rangeEnd >= end) {
10485 // Remove this pair.
10486 data.splice(index, 2);
10487 continue;
10488 }
10489
10490 // Check if both `rangeStart` and `rangeEnd` are within the bounds of
10491 // this pair.
10492 // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
10493 if (rangeStart >= start && rangeEnd < end) {
10494 if (rangeStart == start) {
10495 // Replace `[start, end]` with `[startB, endB]`.
10496 data[index] = rangeEnd + 1;
10497 data[index + 1] = end + 1;
10498 return data;
10499 }
10500 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
10501 data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
10502 return data;
10503 }
10504
10505 // Check if only `rangeStart` is within the bounds of this pair.
10506 // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
10507 if (rangeStart >= start && rangeStart <= end) {
10508 // Replace `end` with `rangeStart`.
10509 data[index + 1] = rangeStart;
10510 // Note: we cannot `return` just yet, in case any following pairs still
10511 // contain matching code points.
10512 // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
10513 // → `[0, 4, 21, 31]`.
10514 }
10515
10516 // Check if only `rangeEnd` is within the bounds of this pair.
10517 // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
10518 else if (rangeEnd >= start && rangeEnd <= end) {
10519 // Just replace `start`.
10520 data[index] = rangeEnd + 1;
10521 return data;
10522 }
10523
10524 index += 2;
10525 }
10526 return data;
10527 };
10528
10529 var dataAdd = function(data, codePoint) {
10530 // Iterate over the data per `(start, end)` pair.
10531 var index = 0;
10532 var start;
10533 var end;
10534 var lastIndex = null;
10535 var length = data.length;
10536 if (codePoint < 0x0 || codePoint > 0x10FFFF) {
10537 throw RangeError(ERRORS.codePointRange);
10538 }
10539 while (index < length) {
10540 start = data[index];
10541 end = data[index + 1];
10542
10543 // Check if the code point is already in the set.
10544 if (codePoint >= start && codePoint < end) {
10545 return data;
10546 }
10547
10548 if (codePoint == start - 1) {
10549 // Just replace `start` with a new value.
10550 data[index] = codePoint;
10551 return data;
10552 }
10553
10554 // At this point, if `start` is `greater` than `codePoint`, insert a new
10555 // `[start, end]` pair before the current pair, or after the current pair
10556 // if there is a known `lastIndex`.
10557 if (start > codePoint) {
10558 data.splice(
10559 lastIndex != null ? lastIndex + 2 : 0,
10560 0,
10561 codePoint,
10562 codePoint + 1
10563 );
10564 return data;
10565 }
10566
10567 if (codePoint == end) {
10568 // Check if adding this code point causes two separate ranges to become
10569 // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
10570 if (codePoint + 1 == data[index + 2]) {
10571 data.splice(index, 4, start, data[index + 3]);
10572 return data;
10573 }
10574 // Else, just replace `end` with a new value.
10575 data[index + 1] = codePoint + 1;
10576 return data;
10577 }
10578 lastIndex = index;
10579 index += 2;
10580 }
10581 // The loop has finished; add the new pair to the end of the data set.
10582 data.push(codePoint, codePoint + 1);
10583 return data;
10584 };
10585
10586 var dataAddData = function(dataA, dataB) {
10587 // Iterate over the data per `(start, end)` pair.
10588 var index = 0;
10589 var start;
10590 var end;
10591 var data = dataA.slice();
10592 var length = dataB.length;
10593 while (index < length) {
10594 start = dataB[index];
10595 end = dataB[index + 1] - 1;
10596 if (start == end) {
10597 data = dataAdd(data, start);
10598 } else {
10599 data = dataAddRange(data, start, end);
10600 }
10601 index += 2;
10602 }
10603 return data;
10604 };
10605
10606 var dataRemoveData = function(dataA, dataB) {
10607 // Iterate over the data per `(start, end)` pair.
10608 var index = 0;
10609 var start;
10610 var end;
10611 var data = dataA.slice();
10612 var length = dataB.length;
10613 while (index < length) {
10614 start = dataB[index];
10615 end = dataB[index + 1] - 1;
10616 if (start == end) {
10617 data = dataRemove(data, start);
10618 } else {
10619 data = dataRemoveRange(data, start, end);
10620 }
10621 index += 2;
10622 }
10623 return data;
10624 };
10625
10626 var dataAddRange = function(data, rangeStart, rangeEnd) {
10627 if (rangeEnd < rangeStart) {
10628 throw Error(ERRORS.rangeOrder);
10629 }
10630 if (
10631 rangeStart < 0x0 || rangeStart > 0x10FFFF ||
10632 rangeEnd < 0x0 || rangeEnd > 0x10FFFF
10633 ) {
10634 throw RangeError(ERRORS.codePointRange);
10635 }
10636 // Iterate over the data per `(start, end)` pair.
10637 var index = 0;
10638 var start;
10639 var end;
10640 var added = false;
10641 var length = data.length;
10642 while (index < length) {
10643 start = data[index];
10644 end = data[index + 1];
10645
10646 if (added) {
10647 // The range has already been added to the set; at this point, we just
10648 // need to get rid of the following ranges in case they overlap.
10649
10650 // Check if this range can be combined with the previous range.
10651 if (start == rangeEnd + 1) {
10652 data.splice(index - 1, 2);
10653 return data;
10654 }
10655
10656 // Exit as soon as no more possibly overlapping pairs can be found.
10657 if (start > rangeEnd) {
10658 return data;
10659 }
10660
10661 // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
10662 // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
10663 // `0,16` range that was previously added.
10664 if (start >= rangeStart && start <= rangeEnd) {
10665 // `start` lies within the range that was previously added.
10666
10667 if (end > rangeStart && end - 1 <= rangeEnd) {
10668 // `end` lies within the range that was previously added as well,
10669 // so remove this pair.
10670 data.splice(index, 2);
10671 index -= 2;
10672 // Note: we cannot `return` just yet, as there may still be other
10673 // overlapping pairs.
10674 } else {
10675 // `start` lies within the range that was previously added, but
10676 // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
10677 // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
10678 // Remove the previously added `end` and the current `start`.
10679 data.splice(index - 1, 2);
10680 index -= 2;
10681 }
10682
10683 // Note: we cannot return yet.
10684 }
10685
10686 }
10687
10688 else if (start == rangeEnd + 1) {
10689 data[index] = rangeStart;
10690 return data;
10691 }
10692
10693 // Check if a new pair must be inserted *before* the current one.
10694 else if (start > rangeEnd) {
10695 data.splice(index, 0, rangeStart, rangeEnd + 1);
10696 return data;
10697 }
10698
10699 else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
10700 // The new range lies entirely within an existing range pair. No action
10701 // needed.
10702 return data;
10703 }
10704
10705 else if (
10706 // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
10707 (rangeStart >= start && rangeStart < end) ||
10708 // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
10709 end == rangeStart
10710 ) {
10711 // Replace `end` with the new value.
10712 data[index + 1] = rangeEnd + 1;
10713 // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
10714 // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
10715 added = true;
10716 // Note: we cannot `return` just yet.
10717 }
10718
10719 else if (rangeStart <= start && rangeEnd + 1 >= end) {
10720 // The new range is a superset of the old range.
10721 data[index] = rangeStart;
10722 data[index + 1] = rangeEnd + 1;
10723 added = true;
10724 }
10725
10726 index += 2;
10727 }
10728 // The loop has finished without doing anything; add the new pair to the end
10729 // of the data set.
10730 if (!added) {
10731 data.push(rangeStart, rangeEnd + 1);
10732 }
10733 return data;
10734 };
10735
10736 var dataContains = function(data, codePoint) {
10737 var index = 0;
10738 var length = data.length;
10739 // Exit early if `codePoint` is not within `data`’s overall range.
10740 var start = data[index];
10741 var end = data[length - 1];
10742 if (length >= 2) {
10743 if (codePoint < start || codePoint > end) {
10744 return false;
10745 }
10746 }
10747 // Iterate over the data per `(start, end)` pair.
10748 while (index < length) {
10749 start = data[index];
10750 end = data[index + 1];
10751 if (codePoint >= start && codePoint < end) {
10752 return true;
10753 }
10754 index += 2;
10755 }
10756 return false;
10757 };
10758
10759 var dataIntersection = function(data, codePoints) {
10760 var index = 0;
10761 var length = codePoints.length;
10762 var codePoint;
10763 var result = [];
10764 while (index < length) {
10765 codePoint = codePoints[index];
10766 if (dataContains(data, codePoint)) {
10767 result.push(codePoint);
10768 }
10769 ++index;
10770 }
10771 return dataFromCodePoints(result);
10772 };
10773
10774 var dataIsEmpty = function(data) {
10775 return !data.length;
10776 };
10777
10778 var dataIsSingleton = function(data) {
10779 // Check if the set only represents a single code point.
10780 return data.length == 2 && data[0] + 1 == data[1];
10781 };
10782
10783 var dataToArray = function(data) {
10784 // Iterate over the data per `(start, end)` pair.
10785 var index = 0;
10786 var start;
10787 var end;
10788 var result = [];
10789 var length = data.length;
10790 while (index < length) {
10791 start = data[index];
10792 end = data[index + 1];
10793 while (start < end) {
10794 result.push(start);
10795 ++start;
10796 }
10797 index += 2;
10798 }
10799 return result;
10800 };
10801
10802 /*--------------------------------------------------------------------------*/
10803
10804 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
10805 var floor = Math.floor;
10806 var highSurrogate = function(codePoint) {
10807 return parseInt(
10808 floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
10809 10
10810 );
10811 };
10812
10813 var lowSurrogate = function(codePoint) {
10814 return parseInt(
10815 (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
10816 10
10817 );
10818 };
10819
10820 var stringFromCharCode = String.fromCharCode;
10821 var codePointToString = function(codePoint) {
10822 var string;
10823 // https://mathiasbynens.be/notes/javascript-escapes#single
10824 // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
10825 // different meaning in regular expressions (word boundary), so it cannot
10826 // be used here.
10827 if (codePoint == 0x09) {
10828 string = '\\t';
10829 }
10830 // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
10831 // else if (codePoint == 0x0B) {
10832 // string = '\\v';
10833 // }
10834 else if (codePoint == 0x0A) {
10835 string = '\\n';
10836 }
10837 else if (codePoint == 0x0C) {
10838 string = '\\f';
10839 }
10840 else if (codePoint == 0x0D) {
10841 string = '\\r';
10842 }
10843 else if (codePoint == 0x5C) {
10844 string = '\\\\';
10845 }
10846 else if (
10847 codePoint == 0x24 ||
10848 (codePoint >= 0x28 && codePoint <= 0x2B) ||
10849 (codePoint >= 0x2D && codePoint <= 0x2F) ||
10850 codePoint == 0x3F ||
10851 (codePoint >= 0x5B && codePoint <= 0x5E) ||
10852 (codePoint >= 0x7B && codePoint <= 0x7D)
10853 ) {
10854 // The code point maps to an unsafe printable ASCII character;
10855 // backslash-escape it. Here’s the list of those symbols:
10856 //
10857 // $()*+-./?[\]^{|}
10858 //
10859 // See #7 for more info.
10860 string = '\\' + stringFromCharCode(codePoint);
10861 }
10862 else if (codePoint >= 0x20 && codePoint <= 0x7E) {
10863 // The code point maps to one of these printable ASCII symbols
10864 // (including the space character):
10865 //
10866 // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
10867 // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
10868 //
10869 // These can safely be used directly.
10870 string = stringFromCharCode(codePoint);
10871 }
10872 else if (codePoint <= 0xFF) {
10873 // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
10874 string = '\\x' + pad(hex(codePoint), 2);
10875 }
10876 else { // `codePoint <= 0xFFFF` holds true.
10877 // https://mathiasbynens.be/notes/javascript-escapes#unicode
10878 string = '\\u' + pad(hex(codePoint), 4);
10879 }
10880
10881 // There’s no need to account for astral symbols / surrogate pairs here,
10882 // since `codePointToString` is private and only used for BMP code points.
10883 // But if that’s what you need, just add an `else` block with this code:
10884 //
10885 // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
10886 // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
10887
10888 return string;
10889 };
10890
10891 var codePointToStringUnicode = function(codePoint) {
10892 if (codePoint <= 0xFFFF) {
10893 return codePointToString(codePoint);
10894 }
10895 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
10896 };
10897
10898 var symbolToCodePoint = function(symbol) {
10899 var length = symbol.length;
10900 var first = symbol.charCodeAt(0);
10901 var second;
10902 if (
10903 first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
10904 length > 1 // There is a next code unit.
10905 ) {
10906 // `first` is a high surrogate, and there is a next character. Assume
10907 // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
10908 second = symbol.charCodeAt(1);
10909 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
10910 return (first - HIGH_SURROGATE_MIN) * 0x400 +
10911 second - LOW_SURROGATE_MIN + 0x10000;
10912 }
10913 return first;
10914 };
10915
10916 var createBMPCharacterClasses = function(data) {
10917 // Iterate over the data per `(start, end)` pair.
10918 var result = '';
10919 var index = 0;
10920 var start;
10921 var end;
10922 var length = data.length;
10923 if (dataIsSingleton(data)) {
10924 return codePointToString(data[0]);
10925 }
10926 while (index < length) {
10927 start = data[index];
10928 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
10929 if (start == end) {
10930 result += codePointToString(start);
10931 } else if (start + 1 == end) {
10932 result += codePointToString(start) + codePointToString(end);
10933 } else {
10934 result += codePointToString(start) + '-' + codePointToString(end);
10935 }
10936 index += 2;
10937 }
10938 return '[' + result + ']';
10939 };
10940
10941 var createUnicodeCharacterClasses = function(data) {
10942 // Iterate over the data per `(start, end)` pair.
10943 var result = '';
10944 var index = 0;
10945 var start;
10946 var end;
10947 var length = data.length;
10948 if (dataIsSingleton(data)) {
10949 return codePointToStringUnicode(data[0]);
10950 }
10951 while (index < length) {
10952 start = data[index];
10953 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
10954 if (start == end) {
10955 result += codePointToStringUnicode(start);
10956 } else if (start + 1 == end) {
10957 result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
10958 } else {
10959 result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
10960 }
10961 index += 2;
10962 }
10963 return '[' + result + ']';
10964 };
10965
10966 var splitAtBMP = function(data) {
10967 // Iterate over the data per `(start, end)` pair.
10968 var loneHighSurrogates = [];
10969 var loneLowSurrogates = [];
10970 var bmp = [];
10971 var astral = [];
10972 var index = 0;
10973 var start;
10974 var end;
10975 var length = data.length;
10976 while (index < length) {
10977 start = data[index];
10978 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
10979
10980 if (start < HIGH_SURROGATE_MIN) {
10981
10982 // The range starts and ends before the high surrogate range.
10983 // E.g. (0, 0x10).
10984 if (end < HIGH_SURROGATE_MIN) {
10985 bmp.push(start, end + 1);
10986 }
10987
10988 // The range starts before the high surrogate range and ends within it.
10989 // E.g. (0, 0xD855).
10990 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
10991 bmp.push(start, HIGH_SURROGATE_MIN);
10992 loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
10993 }
10994
10995 // The range starts before the high surrogate range and ends in the low
10996 // surrogate range. E.g. (0, 0xDCFF).
10997 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
10998 bmp.push(start, HIGH_SURROGATE_MIN);
10999 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
11000 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
11001 }
11002
11003 // The range starts before the high surrogate range and ends after the
11004 // low surrogate range. E.g. (0, 0x10FFFF).
11005 if (end > LOW_SURROGATE_MAX) {
11006 bmp.push(start, HIGH_SURROGATE_MIN);
11007 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
11008 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
11009 if (end <= 0xFFFF) {
11010 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
11011 } else {
11012 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
11013 astral.push(0xFFFF + 1, end + 1);
11014 }
11015 }
11016
11017 } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
11018
11019 // The range starts and ends in the high surrogate range.
11020 // E.g. (0xD855, 0xD866).
11021 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
11022 loneHighSurrogates.push(start, end + 1);
11023 }
11024
11025 // The range starts in the high surrogate range and ends in the low
11026 // surrogate range. E.g. (0xD855, 0xDCFF).
11027 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
11028 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
11029 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
11030 }
11031
11032 // The range starts in the high surrogate range and ends after the low
11033 // surrogate range. E.g. (0xD855, 0x10FFFF).
11034 if (end > LOW_SURROGATE_MAX) {
11035 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
11036 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
11037 if (end <= 0xFFFF) {
11038 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
11039 } else {
11040 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
11041 astral.push(0xFFFF + 1, end + 1);
11042 }
11043 }
11044
11045 } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
11046
11047 // The range starts and ends in the low surrogate range.
11048 // E.g. (0xDCFF, 0xDDFF).
11049 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
11050 loneLowSurrogates.push(start, end + 1);
11051 }
11052
11053 // The range starts in the low surrogate range and ends after the low
11054 // surrogate range. E.g. (0xDCFF, 0x10FFFF).
11055 if (end > LOW_SURROGATE_MAX) {
11056 loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
11057 if (end <= 0xFFFF) {
11058 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
11059 } else {
11060 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
11061 astral.push(0xFFFF + 1, end + 1);
11062 }
11063 }
11064
11065 } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
11066
11067 // The range starts and ends after the low surrogate range.
11068 // E.g. (0xFFAA, 0x10FFFF).
11069 if (end <= 0xFFFF) {
11070 bmp.push(start, end + 1);
11071 } else {
11072 bmp.push(start, 0xFFFF + 1);
11073 astral.push(0xFFFF + 1, end + 1);
11074 }
11075
11076 } else {
11077
11078 // The range starts and ends in the astral range.
11079 astral.push(start, end + 1);
11080
11081 }
11082
11083 index += 2;
11084 }
11085 return {
11086 'loneHighSurrogates': loneHighSurrogates,
11087 'loneLowSurrogates': loneLowSurrogates,
11088 'bmp': bmp,
11089 'astral': astral
11090 };
11091 };
11092
11093 var optimizeSurrogateMappings = function(surrogateMappings) {
11094 var result = [];
11095 var tmpLow = [];
11096 var addLow = false;
11097 var mapping;
11098 var nextMapping;
11099 var highSurrogates;
11100 var lowSurrogates;
11101 var nextHighSurrogates;
11102 var nextLowSurrogates;
11103 var index = -1;
11104 var length = surrogateMappings.length;
11105 while (++index < length) {
11106 mapping = surrogateMappings[index];
11107 nextMapping = surrogateMappings[index + 1];
11108 if (!nextMapping) {
11109 result.push(mapping);
11110 continue;
11111 }
11112 highSurrogates = mapping[0];
11113 lowSurrogates = mapping[1];
11114 nextHighSurrogates = nextMapping[0];
11115 nextLowSurrogates = nextMapping[1];
11116
11117 // Check for identical high surrogate ranges.
11118 tmpLow = lowSurrogates;
11119 while (
11120 nextHighSurrogates &&
11121 highSurrogates[0] == nextHighSurrogates[0] &&
11122 highSurrogates[1] == nextHighSurrogates[1]
11123 ) {
11124 // Merge with the next item.
11125 if (dataIsSingleton(nextLowSurrogates)) {
11126 tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
11127 } else {
11128 tmpLow = dataAddRange(
11129 tmpLow,
11130 nextLowSurrogates[0],
11131 nextLowSurrogates[1] - 1
11132 );
11133 }
11134 ++index;
11135 mapping = surrogateMappings[index];
11136 highSurrogates = mapping[0];
11137 lowSurrogates = mapping[1];
11138 nextMapping = surrogateMappings[index + 1];
11139 nextHighSurrogates = nextMapping && nextMapping[0];
11140 nextLowSurrogates = nextMapping && nextMapping[1];
11141 addLow = true;
11142 }
11143 result.push([
11144 highSurrogates,
11145 addLow ? tmpLow : lowSurrogates
11146 ]);
11147 addLow = false;
11148 }
11149 return optimizeByLowSurrogates(result);
11150 };
11151
11152 var optimizeByLowSurrogates = function(surrogateMappings) {
11153 if (surrogateMappings.length == 1) {
11154 return surrogateMappings;
11155 }
11156 var index = -1;
11157 var innerIndex = -1;
11158 while (++index < surrogateMappings.length) {
11159 var mapping = surrogateMappings[index];
11160 var lowSurrogates = mapping[1];
11161 var lowSurrogateStart = lowSurrogates[0];
11162 var lowSurrogateEnd = lowSurrogates[1];
11163 innerIndex = index; // Note: the loop starts at the next index.
11164 while (++innerIndex < surrogateMappings.length) {
11165 var otherMapping = surrogateMappings[innerIndex];
11166 var otherLowSurrogates = otherMapping[1];
11167 var otherLowSurrogateStart = otherLowSurrogates[0];
11168 var otherLowSurrogateEnd = otherLowSurrogates[1];
11169 if (
11170 lowSurrogateStart == otherLowSurrogateStart &&
11171 lowSurrogateEnd == otherLowSurrogateEnd
11172 ) {
11173 // Add the code points in the other item to this one.
11174 if (dataIsSingleton(otherMapping[0])) {
11175 mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
11176 } else {
11177 mapping[0] = dataAddRange(
11178 mapping[0],
11179 otherMapping[0][0],
11180 otherMapping[0][1] - 1
11181 );
11182 }
11183 // Remove the other, now redundant, item.
11184 surrogateMappings.splice(innerIndex, 1);
11185 --innerIndex;
11186 }
11187 }
11188 }
11189 return surrogateMappings;
11190 };
11191
11192 var surrogateSet = function(data) {
11193 // Exit early if `data` is an empty set.
11194 if (!data.length) {
11195 return [];
11196 }
11197
11198 // Iterate over the data per `(start, end)` pair.
11199 var index = 0;
11200 var start;
11201 var end;
11202 var startHigh;
11203 var startLow;
11204 var endHigh;
11205 var endLow;
11206 var surrogateMappings = [];
11207 var length = data.length;
11208 while (index < length) {
11209 start = data[index];
11210 end = data[index + 1] - 1;
11211
11212 startHigh = highSurrogate(start);
11213 startLow = lowSurrogate(start);
11214 endHigh = highSurrogate(end);
11215 endLow = lowSurrogate(end);
11216
11217 var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
11218 var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
11219 var complete = false;
11220
11221 // Append the previous high-surrogate-to-low-surrogate mappings.
11222 // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
11223 if (
11224 startHigh == endHigh ||
11225 startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
11226 ) {
11227 surrogateMappings.push([
11228 [startHigh, endHigh + 1],
11229 [startLow, endLow + 1]
11230 ]);
11231 complete = true;
11232 } else {
11233 surrogateMappings.push([
11234 [startHigh, startHigh + 1],
11235 [startLow, LOW_SURROGATE_MAX + 1]
11236 ]);
11237 }
11238
11239 // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
11240 // `(endHigh - 1, LOW_SURROGATE_MAX)`.
11241 if (!complete && startHigh + 1 < endHigh) {
11242 if (endsWithHighestLowSurrogate) {
11243 // Combine step 2 and step 3.
11244 surrogateMappings.push([
11245 [startHigh + 1, endHigh + 1],
11246 [LOW_SURROGATE_MIN, endLow + 1]
11247 ]);
11248 complete = true;
11249 } else {
11250 surrogateMappings.push([
11251 [startHigh + 1, endHigh],
11252 [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
11253 ]);
11254 }
11255 }
11256
11257 // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
11258 if (!complete) {
11259 surrogateMappings.push([
11260 [endHigh, endHigh + 1],
11261 [LOW_SURROGATE_MIN, endLow + 1]
11262 ]);
11263 }
11264
11265 index += 2;
11266 }
11267
11268 // The format of `surrogateMappings` is as follows:
11269 //
11270 // [ surrogateMapping1, surrogateMapping2 ]
11271 //
11272 // i.e.:
11273 //
11274 // [
11275 // [ highSurrogates1, lowSurrogates1 ],
11276 // [ highSurrogates2, lowSurrogates2 ]
11277 // ]
11278 return optimizeSurrogateMappings(surrogateMappings);
11279 };
11280
11281 var createSurrogateCharacterClasses = function(surrogateMappings) {
11282 var result = [];
11283 forEach(surrogateMappings, function(surrogateMapping) {
11284 var highSurrogates = surrogateMapping[0];
11285 var lowSurrogates = surrogateMapping[1];
11286 result.push(
11287 createBMPCharacterClasses(highSurrogates) +
11288 createBMPCharacterClasses(lowSurrogates)
11289 );
11290 });
11291 return result.join('|');
11292 };
11293
11294 var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
11295 if (hasUnicodeFlag) {
11296 return createUnicodeCharacterClasses(data);
11297 }
11298 var result = [];
11299
11300 var parts = splitAtBMP(data);
11301 var loneHighSurrogates = parts.loneHighSurrogates;
11302 var loneLowSurrogates = parts.loneLowSurrogates;
11303 var bmp = parts.bmp;
11304 var astral = parts.astral;
11305 var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
11306 var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
11307
11308 var surrogateMappings = surrogateSet(astral);
11309
11310 if (bmpOnly) {
11311 bmp = dataAddData(bmp, loneHighSurrogates);
11312 hasLoneHighSurrogates = false;
11313 bmp = dataAddData(bmp, loneLowSurrogates);
11314 hasLoneLowSurrogates = false;
11315 }
11316
11317 if (!dataIsEmpty(bmp)) {
11318 // The data set contains BMP code points that are not high surrogates
11319 // needed for astral code points in the set.
11320 result.push(createBMPCharacterClasses(bmp));
11321 }
11322 if (surrogateMappings.length) {
11323 // The data set contains astral code points; append character classes
11324 // based on their surrogate pairs.
11325 result.push(createSurrogateCharacterClasses(surrogateMappings));
11326 }
11327 // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
11328 if (hasLoneHighSurrogates) {
11329 result.push(
11330 createBMPCharacterClasses(loneHighSurrogates) +
11331 // Make sure the high surrogates aren’t part of a surrogate pair.
11332 '(?![\\uDC00-\\uDFFF])'
11333 );
11334 }
11335 if (hasLoneLowSurrogates) {
11336 result.push(
11337 // It is not possible to accurately assert the low surrogates aren’t
11338 // part of a surrogate pair, since JavaScript regular expressions do
11339 // not support lookbehind.
11340 '(?:[^\\uD800-\\uDBFF]|^)' +
11341 createBMPCharacterClasses(loneLowSurrogates)
11342 );
11343 }
11344 return result.join('|');
11345 };
11346
11347 /*--------------------------------------------------------------------------*/
11348
11349 // `regenerate` can be used as a constructor (and new methods can be added to
11350 // its prototype) but also as a regular function, the latter of which is the
11351 // documented and most common usage. For that reason, it’s not capitalized.
11352 var regenerate = function(value) {
11353 if (arguments.length > 1) {
11354 value = slice.call(arguments);
11355 }
11356 if (this instanceof regenerate) {
11357 this.data = [];
11358 return value ? this.add(value) : this;
11359 }
11360 return (new regenerate).add(value);
11361 };
11362
11363 regenerate.version = '1.3.3';
11364
11365 var proto = regenerate.prototype;
11366 extend(proto, {
11367 'add': function(value) {
11368 var $this = this;
11369 if (value == null) {
11370 return $this;
11371 }
11372 if (value instanceof regenerate) {
11373 // Allow passing other Regenerate instances.
11374 $this.data = dataAddData($this.data, value.data);
11375 return $this;
11376 }
11377 if (arguments.length > 1) {
11378 value = slice.call(arguments);
11379 }
11380 if (isArray(value)) {
11381 forEach(value, function(item) {
11382 $this.add(item);
11383 });
11384 return $this;
11385 }
11386 $this.data = dataAdd(
11387 $this.data,
11388 isNumber(value) ? value : symbolToCodePoint(value)
11389 );
11390 return $this;
11391 },
11392 'remove': function(value) {
11393 var $this = this;
11394 if (value == null) {
11395 return $this;
11396 }
11397 if (value instanceof regenerate) {
11398 // Allow passing other Regenerate instances.
11399 $this.data = dataRemoveData($this.data, value.data);
11400 return $this;
11401 }
11402 if (arguments.length > 1) {
11403 value = slice.call(arguments);
11404 }
11405 if (isArray(value)) {
11406 forEach(value, function(item) {
11407 $this.remove(item);
11408 });
11409 return $this;
11410 }
11411 $this.data = dataRemove(
11412 $this.data,
11413 isNumber(value) ? value : symbolToCodePoint(value)
11414 );
11415 return $this;
11416 },
11417 'addRange': function(start, end) {
11418 var $this = this;
11419 $this.data = dataAddRange($this.data,
11420 isNumber(start) ? start : symbolToCodePoint(start),
11421 isNumber(end) ? end : symbolToCodePoint(end)
11422 );
11423 return $this;
11424 },
11425 'removeRange': function(start, end) {
11426 var $this = this;
11427 var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
11428 var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
11429 $this.data = dataRemoveRange(
11430 $this.data,
11431 startCodePoint,
11432 endCodePoint
11433 );
11434 return $this;
11435 },
11436 'intersection': function(argument) {
11437 var $this = this;
11438 // Allow passing other Regenerate instances.
11439 // TODO: Optimize this by writing and using `dataIntersectionData()`.
11440 var array = argument instanceof regenerate ?
11441 dataToArray(argument.data) :
11442 argument;
11443 $this.data = dataIntersection($this.data, array);
11444 return $this;
11445 },
11446 'contains': function(codePoint) {
11447 return dataContains(
11448 this.data,
11449 isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
11450 );
11451 },
11452 'clone': function() {
11453 var set = new regenerate;
11454 set.data = this.data.slice(0);
11455 return set;
11456 },
11457 'toString': function(options) {
11458 var result = createCharacterClassesFromData(
11459 this.data,
11460 options ? options.bmpOnly : false,
11461 options ? options.hasUnicodeFlag : false
11462 );
11463 if (!result) {
11464 // For an empty set, return something that can be inserted `/here/` to
11465 // form a valid regular expression. Avoid `(?:)` since that matches the
11466 // empty string.
11467 return '[]';
11468 }
11469 // Use `\0` instead of `\x00` where possible.
11470 return result.replace(regexNull, '\\0$1');
11471 },
11472 'toRegExp': function(flags) {
11473 var pattern = this.toString(
11474 flags && flags.indexOf('u') != -1 ?
11475 { 'hasUnicodeFlag': true } :
11476 null
11477 );
11478 return RegExp(pattern, flags || '');
11479 },
11480 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
11481 return dataToArray(this.data);
11482 }
11483 });
11484
11485 proto.toArray = proto.valueOf;
11486
11487 // Some AMD build optimizers, like r.js, check for specific condition patterns
11488 // like the following:
11489 if (
11490 typeof undefined == 'function' &&
11491 typeof undefined.amd == 'object' &&
11492 undefined.amd
11493 ) {
11494 undefined(function() {
11495 return regenerate;
11496 });
11497 } else if (freeExports && !freeExports.nodeType) {
11498 if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
11499 freeModule.exports = regenerate;
11500 } else { // in Narwhal or RingoJS v0.7.0-
11501 freeExports.regenerate = regenerate;
11502 }
11503 } else { // in Rhino or a web browser
11504 root.regenerate = regenerate;
11505 }
11506
11507}(commonjsGlobal));
11508});
11509
11510var unicodeCanonicalPropertyNamesEcmascript = new Set([
11511 // Non-binary properties:
11512 'General_Category',
11513 'Script',
11514 'Script_Extensions',
11515 // Binary properties:
11516 'Alphabetic',
11517 'Any',
11518 'ASCII',
11519 'ASCII_Hex_Digit',
11520 'Assigned',
11521 'Bidi_Control',
11522 'Bidi_Mirrored',
11523 'Case_Ignorable',
11524 'Cased',
11525 'Changes_When_Casefolded',
11526 'Changes_When_Casemapped',
11527 'Changes_When_Lowercased',
11528 'Changes_When_NFKC_Casefolded',
11529 'Changes_When_Titlecased',
11530 'Changes_When_Uppercased',
11531 'Dash',
11532 'Default_Ignorable_Code_Point',
11533 'Deprecated',
11534 'Diacritic',
11535 'Emoji',
11536 'Emoji_Component',
11537 'Emoji_Modifier',
11538 'Emoji_Modifier_Base',
11539 'Emoji_Presentation',
11540 'Extender',
11541 'Grapheme_Base',
11542 'Grapheme_Extend',
11543 'Hex_Digit',
11544 'ID_Continue',
11545 'ID_Start',
11546 'Ideographic',
11547 'IDS_Binary_Operator',
11548 'IDS_Trinary_Operator',
11549 'Join_Control',
11550 'Logical_Order_Exception',
11551 'Lowercase',
11552 'Math',
11553 'Noncharacter_Code_Point',
11554 'Pattern_Syntax',
11555 'Pattern_White_Space',
11556 'Quotation_Mark',
11557 'Radical',
11558 'Regional_Indicator',
11559 'Sentence_Terminal',
11560 'Soft_Dotted',
11561 'Terminal_Punctuation',
11562 'Unified_Ideograph',
11563 'Uppercase',
11564 'Variation_Selector',
11565 'White_Space',
11566 'XID_Continue',
11567 'XID_Start'
11568]);
11569
11570// Generated using `npm run build`. Do not edit!
11571var unicodePropertyAliasesEcmascript = new Map([
11572 ['scx', 'Script_Extensions'],
11573 ['sc', 'Script'],
11574 ['gc', 'General_Category'],
11575 ['AHex', 'ASCII_Hex_Digit'],
11576 ['Alpha', 'Alphabetic'],
11577 ['Bidi_C', 'Bidi_Control'],
11578 ['Bidi_M', 'Bidi_Mirrored'],
11579 ['Cased', 'Cased'],
11580 ['CI', 'Case_Ignorable'],
11581 ['CWCF', 'Changes_When_Casefolded'],
11582 ['CWCM', 'Changes_When_Casemapped'],
11583 ['CWKCF', 'Changes_When_NFKC_Casefolded'],
11584 ['CWL', 'Changes_When_Lowercased'],
11585 ['CWT', 'Changes_When_Titlecased'],
11586 ['CWU', 'Changes_When_Uppercased'],
11587 ['Dash', 'Dash'],
11588 ['Dep', 'Deprecated'],
11589 ['DI', 'Default_Ignorable_Code_Point'],
11590 ['Dia', 'Diacritic'],
11591 ['Ext', 'Extender'],
11592 ['Gr_Base', 'Grapheme_Base'],
11593 ['Gr_Ext', 'Grapheme_Extend'],
11594 ['Hex', 'Hex_Digit'],
11595 ['IDC', 'ID_Continue'],
11596 ['Ideo', 'Ideographic'],
11597 ['IDS', 'ID_Start'],
11598 ['IDSB', 'IDS_Binary_Operator'],
11599 ['IDST', 'IDS_Trinary_Operator'],
11600 ['Join_C', 'Join_Control'],
11601 ['LOE', 'Logical_Order_Exception'],
11602 ['Lower', 'Lowercase'],
11603 ['Math', 'Math'],
11604 ['NChar', 'Noncharacter_Code_Point'],
11605 ['Pat_Syn', 'Pattern_Syntax'],
11606 ['Pat_WS', 'Pattern_White_Space'],
11607 ['QMark', 'Quotation_Mark'],
11608 ['Radical', 'Radical'],
11609 ['RI', 'Regional_Indicator'],
11610 ['SD', 'Soft_Dotted'],
11611 ['STerm', 'Sentence_Terminal'],
11612 ['Term', 'Terminal_Punctuation'],
11613 ['UIdeo', 'Unified_Ideograph'],
11614 ['Upper', 'Uppercase'],
11615 ['VS', 'Variation_Selector'],
11616 ['WSpace', 'White_Space'],
11617 ['space', 'White_Space'],
11618 ['XIDC', 'XID_Continue'],
11619 ['XIDS', 'XID_Start']
11620]);
11621
11622var matchProperty = function(property) {
11623 if (unicodeCanonicalPropertyNamesEcmascript.has(property)) {
11624 return property;
11625 }
11626 if (unicodePropertyAliasesEcmascript.has(property)) {
11627 return unicodePropertyAliasesEcmascript.get(property);
11628 }
11629 throw new Error(("Unknown property: " + property));
11630};
11631
11632var unicodeMatchPropertyEcmascript = matchProperty;
11633
11634var mappings = new Map([
11635 ['General_Category', new Map([
11636 ['C', 'Other'],
11637 ['Cc', 'Control'],
11638 ['cntrl', 'Control'],
11639 ['Cf', 'Format'],
11640 ['Cn', 'Unassigned'],
11641 ['Co', 'Private_Use'],
11642 ['Cs', 'Surrogate'],
11643 ['L', 'Letter'],
11644 ['LC', 'Cased_Letter'],
11645 ['Ll', 'Lowercase_Letter'],
11646 ['Lm', 'Modifier_Letter'],
11647 ['Lo', 'Other_Letter'],
11648 ['Lt', 'Titlecase_Letter'],
11649 ['Lu', 'Uppercase_Letter'],
11650 ['M', 'Mark'],
11651 ['Combining_Mark', 'Mark'],
11652 ['Mc', 'Spacing_Mark'],
11653 ['Me', 'Enclosing_Mark'],
11654 ['Mn', 'Nonspacing_Mark'],
11655 ['N', 'Number'],
11656 ['Nd', 'Decimal_Number'],
11657 ['digit', 'Decimal_Number'],
11658 ['Nl', 'Letter_Number'],
11659 ['No', 'Other_Number'],
11660 ['P', 'Punctuation'],
11661 ['punct', 'Punctuation'],
11662 ['Pc', 'Connector_Punctuation'],
11663 ['Pd', 'Dash_Punctuation'],
11664 ['Pe', 'Close_Punctuation'],
11665 ['Pf', 'Final_Punctuation'],
11666 ['Pi', 'Initial_Punctuation'],
11667 ['Po', 'Other_Punctuation'],
11668 ['Ps', 'Open_Punctuation'],
11669 ['S', 'Symbol'],
11670 ['Sc', 'Currency_Symbol'],
11671 ['Sk', 'Modifier_Symbol'],
11672 ['Sm', 'Math_Symbol'],
11673 ['So', 'Other_Symbol'],
11674 ['Z', 'Separator'],
11675 ['Zl', 'Line_Separator'],
11676 ['Zp', 'Paragraph_Separator'],
11677 ['Zs', 'Space_Separator'],
11678 ['Other', 'Other'],
11679 ['Control', 'Control'],
11680 ['Format', 'Format'],
11681 ['Unassigned', 'Unassigned'],
11682 ['Private_Use', 'Private_Use'],
11683 ['Surrogate', 'Surrogate'],
11684 ['Letter', 'Letter'],
11685 ['Cased_Letter', 'Cased_Letter'],
11686 ['Lowercase_Letter', 'Lowercase_Letter'],
11687 ['Modifier_Letter', 'Modifier_Letter'],
11688 ['Other_Letter', 'Other_Letter'],
11689 ['Titlecase_Letter', 'Titlecase_Letter'],
11690 ['Uppercase_Letter', 'Uppercase_Letter'],
11691 ['Mark', 'Mark'],
11692 ['Spacing_Mark', 'Spacing_Mark'],
11693 ['Enclosing_Mark', 'Enclosing_Mark'],
11694 ['Nonspacing_Mark', 'Nonspacing_Mark'],
11695 ['Number', 'Number'],
11696 ['Decimal_Number', 'Decimal_Number'],
11697 ['Letter_Number', 'Letter_Number'],
11698 ['Other_Number', 'Other_Number'],
11699 ['Punctuation', 'Punctuation'],
11700 ['Connector_Punctuation', 'Connector_Punctuation'],
11701 ['Dash_Punctuation', 'Dash_Punctuation'],
11702 ['Close_Punctuation', 'Close_Punctuation'],
11703 ['Final_Punctuation', 'Final_Punctuation'],
11704 ['Initial_Punctuation', 'Initial_Punctuation'],
11705 ['Other_Punctuation', 'Other_Punctuation'],
11706 ['Open_Punctuation', 'Open_Punctuation'],
11707 ['Symbol', 'Symbol'],
11708 ['Currency_Symbol', 'Currency_Symbol'],
11709 ['Modifier_Symbol', 'Modifier_Symbol'],
11710 ['Math_Symbol', 'Math_Symbol'],
11711 ['Other_Symbol', 'Other_Symbol'],
11712 ['Separator', 'Separator'],
11713 ['Line_Separator', 'Line_Separator'],
11714 ['Paragraph_Separator', 'Paragraph_Separator'],
11715 ['Space_Separator', 'Space_Separator']
11716 ])],
11717 ['Script', new Map([
11718 ['Adlm', 'Adlam'],
11719 ['Aghb', 'Caucasian_Albanian'],
11720 ['Ahom', 'Ahom'],
11721 ['Arab', 'Arabic'],
11722 ['Armi', 'Imperial_Aramaic'],
11723 ['Armn', 'Armenian'],
11724 ['Avst', 'Avestan'],
11725 ['Bali', 'Balinese'],
11726 ['Bamu', 'Bamum'],
11727 ['Bass', 'Bassa_Vah'],
11728 ['Batk', 'Batak'],
11729 ['Beng', 'Bengali'],
11730 ['Bhks', 'Bhaiksuki'],
11731 ['Bopo', 'Bopomofo'],
11732 ['Brah', 'Brahmi'],
11733 ['Brai', 'Braille'],
11734 ['Bugi', 'Buginese'],
11735 ['Buhd', 'Buhid'],
11736 ['Cakm', 'Chakma'],
11737 ['Cans', 'Canadian_Aboriginal'],
11738 ['Cari', 'Carian'],
11739 ['Cham', 'Cham'],
11740 ['Cher', 'Cherokee'],
11741 ['Copt', 'Coptic'],
11742 ['Qaac', 'Coptic'],
11743 ['Cprt', 'Cypriot'],
11744 ['Cyrl', 'Cyrillic'],
11745 ['Deva', 'Devanagari'],
11746 ['Dsrt', 'Deseret'],
11747 ['Dupl', 'Duployan'],
11748 ['Egyp', 'Egyptian_Hieroglyphs'],
11749 ['Elba', 'Elbasan'],
11750 ['Ethi', 'Ethiopic'],
11751 ['Geor', 'Georgian'],
11752 ['Glag', 'Glagolitic'],
11753 ['Gonm', 'Masaram_Gondi'],
11754 ['Goth', 'Gothic'],
11755 ['Gran', 'Grantha'],
11756 ['Grek', 'Greek'],
11757 ['Gujr', 'Gujarati'],
11758 ['Guru', 'Gurmukhi'],
11759 ['Hang', 'Hangul'],
11760 ['Hani', 'Han'],
11761 ['Hano', 'Hanunoo'],
11762 ['Hatr', 'Hatran'],
11763 ['Hebr', 'Hebrew'],
11764 ['Hira', 'Hiragana'],
11765 ['Hluw', 'Anatolian_Hieroglyphs'],
11766 ['Hmng', 'Pahawh_Hmong'],
11767 ['Hrkt', 'Katakana_Or_Hiragana'],
11768 ['Hung', 'Old_Hungarian'],
11769 ['Ital', 'Old_Italic'],
11770 ['Java', 'Javanese'],
11771 ['Kali', 'Kayah_Li'],
11772 ['Kana', 'Katakana'],
11773 ['Khar', 'Kharoshthi'],
11774 ['Khmr', 'Khmer'],
11775 ['Khoj', 'Khojki'],
11776 ['Knda', 'Kannada'],
11777 ['Kthi', 'Kaithi'],
11778 ['Lana', 'Tai_Tham'],
11779 ['Laoo', 'Lao'],
11780 ['Latn', 'Latin'],
11781 ['Lepc', 'Lepcha'],
11782 ['Limb', 'Limbu'],
11783 ['Lina', 'Linear_A'],
11784 ['Linb', 'Linear_B'],
11785 ['Lisu', 'Lisu'],
11786 ['Lyci', 'Lycian'],
11787 ['Lydi', 'Lydian'],
11788 ['Mahj', 'Mahajani'],
11789 ['Mand', 'Mandaic'],
11790 ['Mani', 'Manichaean'],
11791 ['Marc', 'Marchen'],
11792 ['Mend', 'Mende_Kikakui'],
11793 ['Merc', 'Meroitic_Cursive'],
11794 ['Mero', 'Meroitic_Hieroglyphs'],
11795 ['Mlym', 'Malayalam'],
11796 ['Modi', 'Modi'],
11797 ['Mong', 'Mongolian'],
11798 ['Mroo', 'Mro'],
11799 ['Mtei', 'Meetei_Mayek'],
11800 ['Mult', 'Multani'],
11801 ['Mymr', 'Myanmar'],
11802 ['Narb', 'Old_North_Arabian'],
11803 ['Nbat', 'Nabataean'],
11804 ['Newa', 'Newa'],
11805 ['Nkoo', 'Nko'],
11806 ['Nshu', 'Nushu'],
11807 ['Ogam', 'Ogham'],
11808 ['Olck', 'Ol_Chiki'],
11809 ['Orkh', 'Old_Turkic'],
11810 ['Orya', 'Oriya'],
11811 ['Osge', 'Osage'],
11812 ['Osma', 'Osmanya'],
11813 ['Palm', 'Palmyrene'],
11814 ['Pauc', 'Pau_Cin_Hau'],
11815 ['Perm', 'Old_Permic'],
11816 ['Phag', 'Phags_Pa'],
11817 ['Phli', 'Inscriptional_Pahlavi'],
11818 ['Phlp', 'Psalter_Pahlavi'],
11819 ['Phnx', 'Phoenician'],
11820 ['Plrd', 'Miao'],
11821 ['Prti', 'Inscriptional_Parthian'],
11822 ['Rjng', 'Rejang'],
11823 ['Runr', 'Runic'],
11824 ['Samr', 'Samaritan'],
11825 ['Sarb', 'Old_South_Arabian'],
11826 ['Saur', 'Saurashtra'],
11827 ['Sgnw', 'SignWriting'],
11828 ['Shaw', 'Shavian'],
11829 ['Shrd', 'Sharada'],
11830 ['Sidd', 'Siddham'],
11831 ['Sind', 'Khudawadi'],
11832 ['Sinh', 'Sinhala'],
11833 ['Sora', 'Sora_Sompeng'],
11834 ['Soyo', 'Soyombo'],
11835 ['Sund', 'Sundanese'],
11836 ['Sylo', 'Syloti_Nagri'],
11837 ['Syrc', 'Syriac'],
11838 ['Tagb', 'Tagbanwa'],
11839 ['Takr', 'Takri'],
11840 ['Tale', 'Tai_Le'],
11841 ['Talu', 'New_Tai_Lue'],
11842 ['Taml', 'Tamil'],
11843 ['Tang', 'Tangut'],
11844 ['Tavt', 'Tai_Viet'],
11845 ['Telu', 'Telugu'],
11846 ['Tfng', 'Tifinagh'],
11847 ['Tglg', 'Tagalog'],
11848 ['Thaa', 'Thaana'],
11849 ['Thai', 'Thai'],
11850 ['Tibt', 'Tibetan'],
11851 ['Tirh', 'Tirhuta'],
11852 ['Ugar', 'Ugaritic'],
11853 ['Vaii', 'Vai'],
11854 ['Wara', 'Warang_Citi'],
11855 ['Xpeo', 'Old_Persian'],
11856 ['Xsux', 'Cuneiform'],
11857 ['Yiii', 'Yi'],
11858 ['Zanb', 'Zanabazar_Square'],
11859 ['Zinh', 'Inherited'],
11860 ['Qaai', 'Inherited'],
11861 ['Zyyy', 'Common'],
11862 ['Zzzz', 'Unknown'],
11863 ['Adlam', 'Adlam'],
11864 ['Caucasian_Albanian', 'Caucasian_Albanian'],
11865 ['Arabic', 'Arabic'],
11866 ['Imperial_Aramaic', 'Imperial_Aramaic'],
11867 ['Armenian', 'Armenian'],
11868 ['Avestan', 'Avestan'],
11869 ['Balinese', 'Balinese'],
11870 ['Bamum', 'Bamum'],
11871 ['Bassa_Vah', 'Bassa_Vah'],
11872 ['Batak', 'Batak'],
11873 ['Bengali', 'Bengali'],
11874 ['Bhaiksuki', 'Bhaiksuki'],
11875 ['Bopomofo', 'Bopomofo'],
11876 ['Brahmi', 'Brahmi'],
11877 ['Braille', 'Braille'],
11878 ['Buginese', 'Buginese'],
11879 ['Buhid', 'Buhid'],
11880 ['Chakma', 'Chakma'],
11881 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
11882 ['Carian', 'Carian'],
11883 ['Cherokee', 'Cherokee'],
11884 ['Coptic', 'Coptic'],
11885 ['Cypriot', 'Cypriot'],
11886 ['Cyrillic', 'Cyrillic'],
11887 ['Devanagari', 'Devanagari'],
11888 ['Deseret', 'Deseret'],
11889 ['Duployan', 'Duployan'],
11890 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
11891 ['Elbasan', 'Elbasan'],
11892 ['Ethiopic', 'Ethiopic'],
11893 ['Georgian', 'Georgian'],
11894 ['Glagolitic', 'Glagolitic'],
11895 ['Masaram_Gondi', 'Masaram_Gondi'],
11896 ['Gothic', 'Gothic'],
11897 ['Grantha', 'Grantha'],
11898 ['Greek', 'Greek'],
11899 ['Gujarati', 'Gujarati'],
11900 ['Gurmukhi', 'Gurmukhi'],
11901 ['Hangul', 'Hangul'],
11902 ['Han', 'Han'],
11903 ['Hanunoo', 'Hanunoo'],
11904 ['Hatran', 'Hatran'],
11905 ['Hebrew', 'Hebrew'],
11906 ['Hiragana', 'Hiragana'],
11907 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
11908 ['Pahawh_Hmong', 'Pahawh_Hmong'],
11909 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
11910 ['Old_Hungarian', 'Old_Hungarian'],
11911 ['Old_Italic', 'Old_Italic'],
11912 ['Javanese', 'Javanese'],
11913 ['Kayah_Li', 'Kayah_Li'],
11914 ['Katakana', 'Katakana'],
11915 ['Kharoshthi', 'Kharoshthi'],
11916 ['Khmer', 'Khmer'],
11917 ['Khojki', 'Khojki'],
11918 ['Kannada', 'Kannada'],
11919 ['Kaithi', 'Kaithi'],
11920 ['Tai_Tham', 'Tai_Tham'],
11921 ['Lao', 'Lao'],
11922 ['Latin', 'Latin'],
11923 ['Lepcha', 'Lepcha'],
11924 ['Limbu', 'Limbu'],
11925 ['Linear_A', 'Linear_A'],
11926 ['Linear_B', 'Linear_B'],
11927 ['Lycian', 'Lycian'],
11928 ['Lydian', 'Lydian'],
11929 ['Mahajani', 'Mahajani'],
11930 ['Mandaic', 'Mandaic'],
11931 ['Manichaean', 'Manichaean'],
11932 ['Marchen', 'Marchen'],
11933 ['Mende_Kikakui', 'Mende_Kikakui'],
11934 ['Meroitic_Cursive', 'Meroitic_Cursive'],
11935 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
11936 ['Malayalam', 'Malayalam'],
11937 ['Mongolian', 'Mongolian'],
11938 ['Mro', 'Mro'],
11939 ['Meetei_Mayek', 'Meetei_Mayek'],
11940 ['Multani', 'Multani'],
11941 ['Myanmar', 'Myanmar'],
11942 ['Old_North_Arabian', 'Old_North_Arabian'],
11943 ['Nabataean', 'Nabataean'],
11944 ['Nko', 'Nko'],
11945 ['Nushu', 'Nushu'],
11946 ['Ogham', 'Ogham'],
11947 ['Ol_Chiki', 'Ol_Chiki'],
11948 ['Old_Turkic', 'Old_Turkic'],
11949 ['Oriya', 'Oriya'],
11950 ['Osage', 'Osage'],
11951 ['Osmanya', 'Osmanya'],
11952 ['Palmyrene', 'Palmyrene'],
11953 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
11954 ['Old_Permic', 'Old_Permic'],
11955 ['Phags_Pa', 'Phags_Pa'],
11956 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
11957 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
11958 ['Phoenician', 'Phoenician'],
11959 ['Miao', 'Miao'],
11960 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
11961 ['Rejang', 'Rejang'],
11962 ['Runic', 'Runic'],
11963 ['Samaritan', 'Samaritan'],
11964 ['Old_South_Arabian', 'Old_South_Arabian'],
11965 ['Saurashtra', 'Saurashtra'],
11966 ['SignWriting', 'SignWriting'],
11967 ['Shavian', 'Shavian'],
11968 ['Sharada', 'Sharada'],
11969 ['Siddham', 'Siddham'],
11970 ['Khudawadi', 'Khudawadi'],
11971 ['Sinhala', 'Sinhala'],
11972 ['Sora_Sompeng', 'Sora_Sompeng'],
11973 ['Soyombo', 'Soyombo'],
11974 ['Sundanese', 'Sundanese'],
11975 ['Syloti_Nagri', 'Syloti_Nagri'],
11976 ['Syriac', 'Syriac'],
11977 ['Tagbanwa', 'Tagbanwa'],
11978 ['Takri', 'Takri'],
11979 ['Tai_Le', 'Tai_Le'],
11980 ['New_Tai_Lue', 'New_Tai_Lue'],
11981 ['Tamil', 'Tamil'],
11982 ['Tangut', 'Tangut'],
11983 ['Tai_Viet', 'Tai_Viet'],
11984 ['Telugu', 'Telugu'],
11985 ['Tifinagh', 'Tifinagh'],
11986 ['Tagalog', 'Tagalog'],
11987 ['Thaana', 'Thaana'],
11988 ['Tibetan', 'Tibetan'],
11989 ['Tirhuta', 'Tirhuta'],
11990 ['Ugaritic', 'Ugaritic'],
11991 ['Vai', 'Vai'],
11992 ['Warang_Citi', 'Warang_Citi'],
11993 ['Old_Persian', 'Old_Persian'],
11994 ['Cuneiform', 'Cuneiform'],
11995 ['Yi', 'Yi'],
11996 ['Zanabazar_Square', 'Zanabazar_Square'],
11997 ['Inherited', 'Inherited'],
11998 ['Common', 'Common'],
11999 ['Unknown', 'Unknown']
12000 ])],
12001 ['Script_Extensions', new Map([
12002 ['Adlm', 'Adlam'],
12003 ['Aghb', 'Caucasian_Albanian'],
12004 ['Ahom', 'Ahom'],
12005 ['Arab', 'Arabic'],
12006 ['Armi', 'Imperial_Aramaic'],
12007 ['Armn', 'Armenian'],
12008 ['Avst', 'Avestan'],
12009 ['Bali', 'Balinese'],
12010 ['Bamu', 'Bamum'],
12011 ['Bass', 'Bassa_Vah'],
12012 ['Batk', 'Batak'],
12013 ['Beng', 'Bengali'],
12014 ['Bhks', 'Bhaiksuki'],
12015 ['Bopo', 'Bopomofo'],
12016 ['Brah', 'Brahmi'],
12017 ['Brai', 'Braille'],
12018 ['Bugi', 'Buginese'],
12019 ['Buhd', 'Buhid'],
12020 ['Cakm', 'Chakma'],
12021 ['Cans', 'Canadian_Aboriginal'],
12022 ['Cari', 'Carian'],
12023 ['Cham', 'Cham'],
12024 ['Cher', 'Cherokee'],
12025 ['Copt', 'Coptic'],
12026 ['Qaac', 'Coptic'],
12027 ['Cprt', 'Cypriot'],
12028 ['Cyrl', 'Cyrillic'],
12029 ['Deva', 'Devanagari'],
12030 ['Dsrt', 'Deseret'],
12031 ['Dupl', 'Duployan'],
12032 ['Egyp', 'Egyptian_Hieroglyphs'],
12033 ['Elba', 'Elbasan'],
12034 ['Ethi', 'Ethiopic'],
12035 ['Geor', 'Georgian'],
12036 ['Glag', 'Glagolitic'],
12037 ['Gonm', 'Masaram_Gondi'],
12038 ['Goth', 'Gothic'],
12039 ['Gran', 'Grantha'],
12040 ['Grek', 'Greek'],
12041 ['Gujr', 'Gujarati'],
12042 ['Guru', 'Gurmukhi'],
12043 ['Hang', 'Hangul'],
12044 ['Hani', 'Han'],
12045 ['Hano', 'Hanunoo'],
12046 ['Hatr', 'Hatran'],
12047 ['Hebr', 'Hebrew'],
12048 ['Hira', 'Hiragana'],
12049 ['Hluw', 'Anatolian_Hieroglyphs'],
12050 ['Hmng', 'Pahawh_Hmong'],
12051 ['Hrkt', 'Katakana_Or_Hiragana'],
12052 ['Hung', 'Old_Hungarian'],
12053 ['Ital', 'Old_Italic'],
12054 ['Java', 'Javanese'],
12055 ['Kali', 'Kayah_Li'],
12056 ['Kana', 'Katakana'],
12057 ['Khar', 'Kharoshthi'],
12058 ['Khmr', 'Khmer'],
12059 ['Khoj', 'Khojki'],
12060 ['Knda', 'Kannada'],
12061 ['Kthi', 'Kaithi'],
12062 ['Lana', 'Tai_Tham'],
12063 ['Laoo', 'Lao'],
12064 ['Latn', 'Latin'],
12065 ['Lepc', 'Lepcha'],
12066 ['Limb', 'Limbu'],
12067 ['Lina', 'Linear_A'],
12068 ['Linb', 'Linear_B'],
12069 ['Lisu', 'Lisu'],
12070 ['Lyci', 'Lycian'],
12071 ['Lydi', 'Lydian'],
12072 ['Mahj', 'Mahajani'],
12073 ['Mand', 'Mandaic'],
12074 ['Mani', 'Manichaean'],
12075 ['Marc', 'Marchen'],
12076 ['Mend', 'Mende_Kikakui'],
12077 ['Merc', 'Meroitic_Cursive'],
12078 ['Mero', 'Meroitic_Hieroglyphs'],
12079 ['Mlym', 'Malayalam'],
12080 ['Modi', 'Modi'],
12081 ['Mong', 'Mongolian'],
12082 ['Mroo', 'Mro'],
12083 ['Mtei', 'Meetei_Mayek'],
12084 ['Mult', 'Multani'],
12085 ['Mymr', 'Myanmar'],
12086 ['Narb', 'Old_North_Arabian'],
12087 ['Nbat', 'Nabataean'],
12088 ['Newa', 'Newa'],
12089 ['Nkoo', 'Nko'],
12090 ['Nshu', 'Nushu'],
12091 ['Ogam', 'Ogham'],
12092 ['Olck', 'Ol_Chiki'],
12093 ['Orkh', 'Old_Turkic'],
12094 ['Orya', 'Oriya'],
12095 ['Osge', 'Osage'],
12096 ['Osma', 'Osmanya'],
12097 ['Palm', 'Palmyrene'],
12098 ['Pauc', 'Pau_Cin_Hau'],
12099 ['Perm', 'Old_Permic'],
12100 ['Phag', 'Phags_Pa'],
12101 ['Phli', 'Inscriptional_Pahlavi'],
12102 ['Phlp', 'Psalter_Pahlavi'],
12103 ['Phnx', 'Phoenician'],
12104 ['Plrd', 'Miao'],
12105 ['Prti', 'Inscriptional_Parthian'],
12106 ['Rjng', 'Rejang'],
12107 ['Runr', 'Runic'],
12108 ['Samr', 'Samaritan'],
12109 ['Sarb', 'Old_South_Arabian'],
12110 ['Saur', 'Saurashtra'],
12111 ['Sgnw', 'SignWriting'],
12112 ['Shaw', 'Shavian'],
12113 ['Shrd', 'Sharada'],
12114 ['Sidd', 'Siddham'],
12115 ['Sind', 'Khudawadi'],
12116 ['Sinh', 'Sinhala'],
12117 ['Sora', 'Sora_Sompeng'],
12118 ['Soyo', 'Soyombo'],
12119 ['Sund', 'Sundanese'],
12120 ['Sylo', 'Syloti_Nagri'],
12121 ['Syrc', 'Syriac'],
12122 ['Tagb', 'Tagbanwa'],
12123 ['Takr', 'Takri'],
12124 ['Tale', 'Tai_Le'],
12125 ['Talu', 'New_Tai_Lue'],
12126 ['Taml', 'Tamil'],
12127 ['Tang', 'Tangut'],
12128 ['Tavt', 'Tai_Viet'],
12129 ['Telu', 'Telugu'],
12130 ['Tfng', 'Tifinagh'],
12131 ['Tglg', 'Tagalog'],
12132 ['Thaa', 'Thaana'],
12133 ['Thai', 'Thai'],
12134 ['Tibt', 'Tibetan'],
12135 ['Tirh', 'Tirhuta'],
12136 ['Ugar', 'Ugaritic'],
12137 ['Vaii', 'Vai'],
12138 ['Wara', 'Warang_Citi'],
12139 ['Xpeo', 'Old_Persian'],
12140 ['Xsux', 'Cuneiform'],
12141 ['Yiii', 'Yi'],
12142 ['Zanb', 'Zanabazar_Square'],
12143 ['Zinh', 'Inherited'],
12144 ['Qaai', 'Inherited'],
12145 ['Zyyy', 'Common'],
12146 ['Zzzz', 'Unknown'],
12147 ['Adlam', 'Adlam'],
12148 ['Caucasian_Albanian', 'Caucasian_Albanian'],
12149 ['Arabic', 'Arabic'],
12150 ['Imperial_Aramaic', 'Imperial_Aramaic'],
12151 ['Armenian', 'Armenian'],
12152 ['Avestan', 'Avestan'],
12153 ['Balinese', 'Balinese'],
12154 ['Bamum', 'Bamum'],
12155 ['Bassa_Vah', 'Bassa_Vah'],
12156 ['Batak', 'Batak'],
12157 ['Bengali', 'Bengali'],
12158 ['Bhaiksuki', 'Bhaiksuki'],
12159 ['Bopomofo', 'Bopomofo'],
12160 ['Brahmi', 'Brahmi'],
12161 ['Braille', 'Braille'],
12162 ['Buginese', 'Buginese'],
12163 ['Buhid', 'Buhid'],
12164 ['Chakma', 'Chakma'],
12165 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
12166 ['Carian', 'Carian'],
12167 ['Cherokee', 'Cherokee'],
12168 ['Coptic', 'Coptic'],
12169 ['Cypriot', 'Cypriot'],
12170 ['Cyrillic', 'Cyrillic'],
12171 ['Devanagari', 'Devanagari'],
12172 ['Deseret', 'Deseret'],
12173 ['Duployan', 'Duployan'],
12174 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
12175 ['Elbasan', 'Elbasan'],
12176 ['Ethiopic', 'Ethiopic'],
12177 ['Georgian', 'Georgian'],
12178 ['Glagolitic', 'Glagolitic'],
12179 ['Masaram_Gondi', 'Masaram_Gondi'],
12180 ['Gothic', 'Gothic'],
12181 ['Grantha', 'Grantha'],
12182 ['Greek', 'Greek'],
12183 ['Gujarati', 'Gujarati'],
12184 ['Gurmukhi', 'Gurmukhi'],
12185 ['Hangul', 'Hangul'],
12186 ['Han', 'Han'],
12187 ['Hanunoo', 'Hanunoo'],
12188 ['Hatran', 'Hatran'],
12189 ['Hebrew', 'Hebrew'],
12190 ['Hiragana', 'Hiragana'],
12191 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
12192 ['Pahawh_Hmong', 'Pahawh_Hmong'],
12193 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
12194 ['Old_Hungarian', 'Old_Hungarian'],
12195 ['Old_Italic', 'Old_Italic'],
12196 ['Javanese', 'Javanese'],
12197 ['Kayah_Li', 'Kayah_Li'],
12198 ['Katakana', 'Katakana'],
12199 ['Kharoshthi', 'Kharoshthi'],
12200 ['Khmer', 'Khmer'],
12201 ['Khojki', 'Khojki'],
12202 ['Kannada', 'Kannada'],
12203 ['Kaithi', 'Kaithi'],
12204 ['Tai_Tham', 'Tai_Tham'],
12205 ['Lao', 'Lao'],
12206 ['Latin', 'Latin'],
12207 ['Lepcha', 'Lepcha'],
12208 ['Limbu', 'Limbu'],
12209 ['Linear_A', 'Linear_A'],
12210 ['Linear_B', 'Linear_B'],
12211 ['Lycian', 'Lycian'],
12212 ['Lydian', 'Lydian'],
12213 ['Mahajani', 'Mahajani'],
12214 ['Mandaic', 'Mandaic'],
12215 ['Manichaean', 'Manichaean'],
12216 ['Marchen', 'Marchen'],
12217 ['Mende_Kikakui', 'Mende_Kikakui'],
12218 ['Meroitic_Cursive', 'Meroitic_Cursive'],
12219 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
12220 ['Malayalam', 'Malayalam'],
12221 ['Mongolian', 'Mongolian'],
12222 ['Mro', 'Mro'],
12223 ['Meetei_Mayek', 'Meetei_Mayek'],
12224 ['Multani', 'Multani'],
12225 ['Myanmar', 'Myanmar'],
12226 ['Old_North_Arabian', 'Old_North_Arabian'],
12227 ['Nabataean', 'Nabataean'],
12228 ['Nko', 'Nko'],
12229 ['Nushu', 'Nushu'],
12230 ['Ogham', 'Ogham'],
12231 ['Ol_Chiki', 'Ol_Chiki'],
12232 ['Old_Turkic', 'Old_Turkic'],
12233 ['Oriya', 'Oriya'],
12234 ['Osage', 'Osage'],
12235 ['Osmanya', 'Osmanya'],
12236 ['Palmyrene', 'Palmyrene'],
12237 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
12238 ['Old_Permic', 'Old_Permic'],
12239 ['Phags_Pa', 'Phags_Pa'],
12240 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
12241 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
12242 ['Phoenician', 'Phoenician'],
12243 ['Miao', 'Miao'],
12244 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
12245 ['Rejang', 'Rejang'],
12246 ['Runic', 'Runic'],
12247 ['Samaritan', 'Samaritan'],
12248 ['Old_South_Arabian', 'Old_South_Arabian'],
12249 ['Saurashtra', 'Saurashtra'],
12250 ['SignWriting', 'SignWriting'],
12251 ['Shavian', 'Shavian'],
12252 ['Sharada', 'Sharada'],
12253 ['Siddham', 'Siddham'],
12254 ['Khudawadi', 'Khudawadi'],
12255 ['Sinhala', 'Sinhala'],
12256 ['Sora_Sompeng', 'Sora_Sompeng'],
12257 ['Soyombo', 'Soyombo'],
12258 ['Sundanese', 'Sundanese'],
12259 ['Syloti_Nagri', 'Syloti_Nagri'],
12260 ['Syriac', 'Syriac'],
12261 ['Tagbanwa', 'Tagbanwa'],
12262 ['Takri', 'Takri'],
12263 ['Tai_Le', 'Tai_Le'],
12264 ['New_Tai_Lue', 'New_Tai_Lue'],
12265 ['Tamil', 'Tamil'],
12266 ['Tangut', 'Tangut'],
12267 ['Tai_Viet', 'Tai_Viet'],
12268 ['Telugu', 'Telugu'],
12269 ['Tifinagh', 'Tifinagh'],
12270 ['Tagalog', 'Tagalog'],
12271 ['Thaana', 'Thaana'],
12272 ['Tibetan', 'Tibetan'],
12273 ['Tirhuta', 'Tirhuta'],
12274 ['Ugaritic', 'Ugaritic'],
12275 ['Vai', 'Vai'],
12276 ['Warang_Citi', 'Warang_Citi'],
12277 ['Old_Persian', 'Old_Persian'],
12278 ['Cuneiform', 'Cuneiform'],
12279 ['Yi', 'Yi'],
12280 ['Zanabazar_Square', 'Zanabazar_Square'],
12281 ['Inherited', 'Inherited'],
12282 ['Common', 'Common'],
12283 ['Unknown', 'Unknown']
12284 ])]
12285]);
12286
12287var matchPropertyValue = function(property, value) {
12288 var aliasToValue = mappings.get(property);
12289 if (!aliasToValue) {
12290 throw new Error(("Unknown property `" + property + "`."));
12291 }
12292 var canonicalValue = aliasToValue.get(value);
12293 if (canonicalValue) {
12294 return canonicalValue;
12295 }
12296 throw new Error(
12297 ("Unknown value `" + value + "` for property `" + property + "`.")
12298 );
12299};
12300
12301var unicodeMatchPropertyValueEcmascript = matchPropertyValue;
12302
12303var iuMappings = new Map([
12304 [0x4B, 0x212A],
12305 [0x53, 0x17F],
12306 [0x6B, 0x212A],
12307 [0x73, 0x17F],
12308 [0xB5, 0x39C],
12309 [0xC5, 0x212B],
12310 [0xDF, 0x1E9E],
12311 [0xE5, 0x212B],
12312 [0x17F, 0x53],
12313 [0x1C4, 0x1C5],
12314 [0x1C5, 0x1C4],
12315 [0x1C7, 0x1C8],
12316 [0x1C8, 0x1C7],
12317 [0x1CA, 0x1CB],
12318 [0x1CB, 0x1CA],
12319 [0x1F1, 0x1F2],
12320 [0x1F2, 0x1F1],
12321 [0x26A, 0xA7AE],
12322 [0x29D, 0xA7B2],
12323 [0x345, 0x1FBE],
12324 [0x392, 0x3D0],
12325 [0x395, 0x3F5],
12326 [0x398, 0x3F4],
12327 [0x399, 0x1FBE],
12328 [0x39A, 0x3F0],
12329 [0x39C, 0xB5],
12330 [0x3A0, 0x3D6],
12331 [0x3A1, 0x3F1],
12332 [0x3A3, 0x3C2],
12333 [0x3A6, 0x3D5],
12334 [0x3A9, 0x2126],
12335 [0x3B8, 0x3F4],
12336 [0x3C2, 0x3A3],
12337 [0x3C9, 0x2126],
12338 [0x3D0, 0x392],
12339 [0x3D1, 0x3F4],
12340 [0x3D5, 0x3A6],
12341 [0x3D6, 0x3A0],
12342 [0x3F0, 0x39A],
12343 [0x3F1, 0x3A1],
12344 [0x3F4, [
12345 0x398,
12346 0x3D1,
12347 0x3B8
12348 ]],
12349 [0x3F5, 0x395],
12350 [0x412, 0x1C80],
12351 [0x414, 0x1C81],
12352 [0x41E, 0x1C82],
12353 [0x421, 0x1C83],
12354 [0x422, 0x1C85],
12355 [0x42A, 0x1C86],
12356 [0x432, 0x1C80],
12357 [0x434, 0x1C81],
12358 [0x43E, 0x1C82],
12359 [0x441, 0x1C83],
12360 [0x442, [
12361 0x1C84,
12362 0x1C85
12363 ]],
12364 [0x44A, 0x1C86],
12365 [0x462, 0x1C87],
12366 [0x463, 0x1C87],
12367 [0x13A0, 0xAB70],
12368 [0x13A1, 0xAB71],
12369 [0x13A2, 0xAB72],
12370 [0x13A3, 0xAB73],
12371 [0x13A4, 0xAB74],
12372 [0x13A5, 0xAB75],
12373 [0x13A6, 0xAB76],
12374 [0x13A7, 0xAB77],
12375 [0x13A8, 0xAB78],
12376 [0x13A9, 0xAB79],
12377 [0x13AA, 0xAB7A],
12378 [0x13AB, 0xAB7B],
12379 [0x13AC, 0xAB7C],
12380 [0x13AD, 0xAB7D],
12381 [0x13AE, 0xAB7E],
12382 [0x13AF, 0xAB7F],
12383 [0x13B0, 0xAB80],
12384 [0x13B1, 0xAB81],
12385 [0x13B2, 0xAB82],
12386 [0x13B3, 0xAB83],
12387 [0x13B4, 0xAB84],
12388 [0x13B5, 0xAB85],
12389 [0x13B6, 0xAB86],
12390 [0x13B7, 0xAB87],
12391 [0x13B8, 0xAB88],
12392 [0x13B9, 0xAB89],
12393 [0x13BA, 0xAB8A],
12394 [0x13BB, 0xAB8B],
12395 [0x13BC, 0xAB8C],
12396 [0x13BD, 0xAB8D],
12397 [0x13BE, 0xAB8E],
12398 [0x13BF, 0xAB8F],
12399 [0x13C0, 0xAB90],
12400 [0x13C1, 0xAB91],
12401 [0x13C2, 0xAB92],
12402 [0x13C3, 0xAB93],
12403 [0x13C4, 0xAB94],
12404 [0x13C5, 0xAB95],
12405 [0x13C6, 0xAB96],
12406 [0x13C7, 0xAB97],
12407 [0x13C8, 0xAB98],
12408 [0x13C9, 0xAB99],
12409 [0x13CA, 0xAB9A],
12410 [0x13CB, 0xAB9B],
12411 [0x13CC, 0xAB9C],
12412 [0x13CD, 0xAB9D],
12413 [0x13CE, 0xAB9E],
12414 [0x13CF, 0xAB9F],
12415 [0x13D0, 0xABA0],
12416 [0x13D1, 0xABA1],
12417 [0x13D2, 0xABA2],
12418 [0x13D3, 0xABA3],
12419 [0x13D4, 0xABA4],
12420 [0x13D5, 0xABA5],
12421 [0x13D6, 0xABA6],
12422 [0x13D7, 0xABA7],
12423 [0x13D8, 0xABA8],
12424 [0x13D9, 0xABA9],
12425 [0x13DA, 0xABAA],
12426 [0x13DB, 0xABAB],
12427 [0x13DC, 0xABAC],
12428 [0x13DD, 0xABAD],
12429 [0x13DE, 0xABAE],
12430 [0x13DF, 0xABAF],
12431 [0x13E0, 0xABB0],
12432 [0x13E1, 0xABB1],
12433 [0x13E2, 0xABB2],
12434 [0x13E3, 0xABB3],
12435 [0x13E4, 0xABB4],
12436 [0x13E5, 0xABB5],
12437 [0x13E6, 0xABB6],
12438 [0x13E7, 0xABB7],
12439 [0x13E8, 0xABB8],
12440 [0x13E9, 0xABB9],
12441 [0x13EA, 0xABBA],
12442 [0x13EB, 0xABBB],
12443 [0x13EC, 0xABBC],
12444 [0x13ED, 0xABBD],
12445 [0x13EE, 0xABBE],
12446 [0x13EF, 0xABBF],
12447 [0x13F0, 0x13F8],
12448 [0x13F1, 0x13F9],
12449 [0x13F2, 0x13FA],
12450 [0x13F3, 0x13FB],
12451 [0x13F4, 0x13FC],
12452 [0x13F5, 0x13FD],
12453 [0x13F8, 0x13F0],
12454 [0x13F9, 0x13F1],
12455 [0x13FA, 0x13F2],
12456 [0x13FB, 0x13F3],
12457 [0x13FC, 0x13F4],
12458 [0x13FD, 0x13F5],
12459 [0x1C80, [
12460 0x412,
12461 0x432
12462 ]],
12463 [0x1C81, [
12464 0x414,
12465 0x434
12466 ]],
12467 [0x1C82, [
12468 0x41E,
12469 0x43E
12470 ]],
12471 [0x1C83, [
12472 0x421,
12473 0x441
12474 ]],
12475 [0x1C84, [
12476 0x1C85,
12477 0x442
12478 ]],
12479 [0x1C85, [
12480 0x422,
12481 0x1C84,
12482 0x442
12483 ]],
12484 [0x1C86, [
12485 0x42A,
12486 0x44A
12487 ]],
12488 [0x1C87, [
12489 0x462,
12490 0x463
12491 ]],
12492 [0x1C88, [
12493 0xA64A,
12494 0xA64B
12495 ]],
12496 [0x1E60, 0x1E9B],
12497 [0x1E9B, 0x1E60],
12498 [0x1E9E, 0xDF],
12499 [0x1F80, 0x1F88],
12500 [0x1F81, 0x1F89],
12501 [0x1F82, 0x1F8A],
12502 [0x1F83, 0x1F8B],
12503 [0x1F84, 0x1F8C],
12504 [0x1F85, 0x1F8D],
12505 [0x1F86, 0x1F8E],
12506 [0x1F87, 0x1F8F],
12507 [0x1F88, 0x1F80],
12508 [0x1F89, 0x1F81],
12509 [0x1F8A, 0x1F82],
12510 [0x1F8B, 0x1F83],
12511 [0x1F8C, 0x1F84],
12512 [0x1F8D, 0x1F85],
12513 [0x1F8E, 0x1F86],
12514 [0x1F8F, 0x1F87],
12515 [0x1F90, 0x1F98],
12516 [0x1F91, 0x1F99],
12517 [0x1F92, 0x1F9A],
12518 [0x1F93, 0x1F9B],
12519 [0x1F94, 0x1F9C],
12520 [0x1F95, 0x1F9D],
12521 [0x1F96, 0x1F9E],
12522 [0x1F97, 0x1F9F],
12523 [0x1F98, 0x1F90],
12524 [0x1F99, 0x1F91],
12525 [0x1F9A, 0x1F92],
12526 [0x1F9B, 0x1F93],
12527 [0x1F9C, 0x1F94],
12528 [0x1F9D, 0x1F95],
12529 [0x1F9E, 0x1F96],
12530 [0x1F9F, 0x1F97],
12531 [0x1FA0, 0x1FA8],
12532 [0x1FA1, 0x1FA9],
12533 [0x1FA2, 0x1FAA],
12534 [0x1FA3, 0x1FAB],
12535 [0x1FA4, 0x1FAC],
12536 [0x1FA5, 0x1FAD],
12537 [0x1FA6, 0x1FAE],
12538 [0x1FA7, 0x1FAF],
12539 [0x1FA8, 0x1FA0],
12540 [0x1FA9, 0x1FA1],
12541 [0x1FAA, 0x1FA2],
12542 [0x1FAB, 0x1FA3],
12543 [0x1FAC, 0x1FA4],
12544 [0x1FAD, 0x1FA5],
12545 [0x1FAE, 0x1FA6],
12546 [0x1FAF, 0x1FA7],
12547 [0x1FB3, 0x1FBC],
12548 [0x1FBC, 0x1FB3],
12549 [0x1FBE, [
12550 0x345,
12551 0x399
12552 ]],
12553 [0x1FC3, 0x1FCC],
12554 [0x1FCC, 0x1FC3],
12555 [0x1FF3, 0x1FFC],
12556 [0x1FFC, 0x1FF3],
12557 [0x2126, [
12558 0x3A9,
12559 0x3C9
12560 ]],
12561 [0x212A, 0x4B],
12562 [0x212B, [
12563 0xC5,
12564 0xE5
12565 ]],
12566 [0xA64A, 0x1C88],
12567 [0xA64B, 0x1C88],
12568 [0xA7AE, 0x26A],
12569 [0xA7B2, 0x29D],
12570 [0xA7B3, 0xAB53],
12571 [0xA7B4, 0xA7B5],
12572 [0xA7B5, 0xA7B4],
12573 [0xA7B6, 0xA7B7],
12574 [0xA7B7, 0xA7B6],
12575 [0xAB53, 0xA7B3],
12576 [0xAB70, 0x13A0],
12577 [0xAB71, 0x13A1],
12578 [0xAB72, 0x13A2],
12579 [0xAB73, 0x13A3],
12580 [0xAB74, 0x13A4],
12581 [0xAB75, 0x13A5],
12582 [0xAB76, 0x13A6],
12583 [0xAB77, 0x13A7],
12584 [0xAB78, 0x13A8],
12585 [0xAB79, 0x13A9],
12586 [0xAB7A, 0x13AA],
12587 [0xAB7B, 0x13AB],
12588 [0xAB7C, 0x13AC],
12589 [0xAB7D, 0x13AD],
12590 [0xAB7E, 0x13AE],
12591 [0xAB7F, 0x13AF],
12592 [0xAB80, 0x13B0],
12593 [0xAB81, 0x13B1],
12594 [0xAB82, 0x13B2],
12595 [0xAB83, 0x13B3],
12596 [0xAB84, 0x13B4],
12597 [0xAB85, 0x13B5],
12598 [0xAB86, 0x13B6],
12599 [0xAB87, 0x13B7],
12600 [0xAB88, 0x13B8],
12601 [0xAB89, 0x13B9],
12602 [0xAB8A, 0x13BA],
12603 [0xAB8B, 0x13BB],
12604 [0xAB8C, 0x13BC],
12605 [0xAB8D, 0x13BD],
12606 [0xAB8E, 0x13BE],
12607 [0xAB8F, 0x13BF],
12608 [0xAB90, 0x13C0],
12609 [0xAB91, 0x13C1],
12610 [0xAB92, 0x13C2],
12611 [0xAB93, 0x13C3],
12612 [0xAB94, 0x13C4],
12613 [0xAB95, 0x13C5],
12614 [0xAB96, 0x13C6],
12615 [0xAB97, 0x13C7],
12616 [0xAB98, 0x13C8],
12617 [0xAB99, 0x13C9],
12618 [0xAB9A, 0x13CA],
12619 [0xAB9B, 0x13CB],
12620 [0xAB9C, 0x13CC],
12621 [0xAB9D, 0x13CD],
12622 [0xAB9E, 0x13CE],
12623 [0xAB9F, 0x13CF],
12624 [0xABA0, 0x13D0],
12625 [0xABA1, 0x13D1],
12626 [0xABA2, 0x13D2],
12627 [0xABA3, 0x13D3],
12628 [0xABA4, 0x13D4],
12629 [0xABA5, 0x13D5],
12630 [0xABA6, 0x13D6],
12631 [0xABA7, 0x13D7],
12632 [0xABA8, 0x13D8],
12633 [0xABA9, 0x13D9],
12634 [0xABAA, 0x13DA],
12635 [0xABAB, 0x13DB],
12636 [0xABAC, 0x13DC],
12637 [0xABAD, 0x13DD],
12638 [0xABAE, 0x13DE],
12639 [0xABAF, 0x13DF],
12640 [0xABB0, 0x13E0],
12641 [0xABB1, 0x13E1],
12642 [0xABB2, 0x13E2],
12643 [0xABB3, 0x13E3],
12644 [0xABB4, 0x13E4],
12645 [0xABB5, 0x13E5],
12646 [0xABB6, 0x13E6],
12647 [0xABB7, 0x13E7],
12648 [0xABB8, 0x13E8],
12649 [0xABB9, 0x13E9],
12650 [0xABBA, 0x13EA],
12651 [0xABBB, 0x13EB],
12652 [0xABBC, 0x13EC],
12653 [0xABBD, 0x13ED],
12654 [0xABBE, 0x13EE],
12655 [0xABBF, 0x13EF],
12656 [0x10400, 0x10428],
12657 [0x10401, 0x10429],
12658 [0x10402, 0x1042A],
12659 [0x10403, 0x1042B],
12660 [0x10404, 0x1042C],
12661 [0x10405, 0x1042D],
12662 [0x10406, 0x1042E],
12663 [0x10407, 0x1042F],
12664 [0x10408, 0x10430],
12665 [0x10409, 0x10431],
12666 [0x1040A, 0x10432],
12667 [0x1040B, 0x10433],
12668 [0x1040C, 0x10434],
12669 [0x1040D, 0x10435],
12670 [0x1040E, 0x10436],
12671 [0x1040F, 0x10437],
12672 [0x10410, 0x10438],
12673 [0x10411, 0x10439],
12674 [0x10412, 0x1043A],
12675 [0x10413, 0x1043B],
12676 [0x10414, 0x1043C],
12677 [0x10415, 0x1043D],
12678 [0x10416, 0x1043E],
12679 [0x10417, 0x1043F],
12680 [0x10418, 0x10440],
12681 [0x10419, 0x10441],
12682 [0x1041A, 0x10442],
12683 [0x1041B, 0x10443],
12684 [0x1041C, 0x10444],
12685 [0x1041D, 0x10445],
12686 [0x1041E, 0x10446],
12687 [0x1041F, 0x10447],
12688 [0x10420, 0x10448],
12689 [0x10421, 0x10449],
12690 [0x10422, 0x1044A],
12691 [0x10423, 0x1044B],
12692 [0x10424, 0x1044C],
12693 [0x10425, 0x1044D],
12694 [0x10426, 0x1044E],
12695 [0x10427, 0x1044F],
12696 [0x10428, 0x10400],
12697 [0x10429, 0x10401],
12698 [0x1042A, 0x10402],
12699 [0x1042B, 0x10403],
12700 [0x1042C, 0x10404],
12701 [0x1042D, 0x10405],
12702 [0x1042E, 0x10406],
12703 [0x1042F, 0x10407],
12704 [0x10430, 0x10408],
12705 [0x10431, 0x10409],
12706 [0x10432, 0x1040A],
12707 [0x10433, 0x1040B],
12708 [0x10434, 0x1040C],
12709 [0x10435, 0x1040D],
12710 [0x10436, 0x1040E],
12711 [0x10437, 0x1040F],
12712 [0x10438, 0x10410],
12713 [0x10439, 0x10411],
12714 [0x1043A, 0x10412],
12715 [0x1043B, 0x10413],
12716 [0x1043C, 0x10414],
12717 [0x1043D, 0x10415],
12718 [0x1043E, 0x10416],
12719 [0x1043F, 0x10417],
12720 [0x10440, 0x10418],
12721 [0x10441, 0x10419],
12722 [0x10442, 0x1041A],
12723 [0x10443, 0x1041B],
12724 [0x10444, 0x1041C],
12725 [0x10445, 0x1041D],
12726 [0x10446, 0x1041E],
12727 [0x10447, 0x1041F],
12728 [0x10448, 0x10420],
12729 [0x10449, 0x10421],
12730 [0x1044A, 0x10422],
12731 [0x1044B, 0x10423],
12732 [0x1044C, 0x10424],
12733 [0x1044D, 0x10425],
12734 [0x1044E, 0x10426],
12735 [0x1044F, 0x10427],
12736 [0x104B0, 0x104D8],
12737 [0x104B1, 0x104D9],
12738 [0x104B2, 0x104DA],
12739 [0x104B3, 0x104DB],
12740 [0x104B4, 0x104DC],
12741 [0x104B5, 0x104DD],
12742 [0x104B6, 0x104DE],
12743 [0x104B7, 0x104DF],
12744 [0x104B8, 0x104E0],
12745 [0x104B9, 0x104E1],
12746 [0x104BA, 0x104E2],
12747 [0x104BB, 0x104E3],
12748 [0x104BC, 0x104E4],
12749 [0x104BD, 0x104E5],
12750 [0x104BE, 0x104E6],
12751 [0x104BF, 0x104E7],
12752 [0x104C0, 0x104E8],
12753 [0x104C1, 0x104E9],
12754 [0x104C2, 0x104EA],
12755 [0x104C3, 0x104EB],
12756 [0x104C4, 0x104EC],
12757 [0x104C5, 0x104ED],
12758 [0x104C6, 0x104EE],
12759 [0x104C7, 0x104EF],
12760 [0x104C8, 0x104F0],
12761 [0x104C9, 0x104F1],
12762 [0x104CA, 0x104F2],
12763 [0x104CB, 0x104F3],
12764 [0x104CC, 0x104F4],
12765 [0x104CD, 0x104F5],
12766 [0x104CE, 0x104F6],
12767 [0x104CF, 0x104F7],
12768 [0x104D0, 0x104F8],
12769 [0x104D1, 0x104F9],
12770 [0x104D2, 0x104FA],
12771 [0x104D3, 0x104FB],
12772 [0x104D8, 0x104B0],
12773 [0x104D9, 0x104B1],
12774 [0x104DA, 0x104B2],
12775 [0x104DB, 0x104B3],
12776 [0x104DC, 0x104B4],
12777 [0x104DD, 0x104B5],
12778 [0x104DE, 0x104B6],
12779 [0x104DF, 0x104B7],
12780 [0x104E0, 0x104B8],
12781 [0x104E1, 0x104B9],
12782 [0x104E2, 0x104BA],
12783 [0x104E3, 0x104BB],
12784 [0x104E4, 0x104BC],
12785 [0x104E5, 0x104BD],
12786 [0x104E6, 0x104BE],
12787 [0x104E7, 0x104BF],
12788 [0x104E8, 0x104C0],
12789 [0x104E9, 0x104C1],
12790 [0x104EA, 0x104C2],
12791 [0x104EB, 0x104C3],
12792 [0x104EC, 0x104C4],
12793 [0x104ED, 0x104C5],
12794 [0x104EE, 0x104C6],
12795 [0x104EF, 0x104C7],
12796 [0x104F0, 0x104C8],
12797 [0x104F1, 0x104C9],
12798 [0x104F2, 0x104CA],
12799 [0x104F3, 0x104CB],
12800 [0x104F4, 0x104CC],
12801 [0x104F5, 0x104CD],
12802 [0x104F6, 0x104CE],
12803 [0x104F7, 0x104CF],
12804 [0x104F8, 0x104D0],
12805 [0x104F9, 0x104D1],
12806 [0x104FA, 0x104D2],
12807 [0x104FB, 0x104D3],
12808 [0x10C80, 0x10CC0],
12809 [0x10C81, 0x10CC1],
12810 [0x10C82, 0x10CC2],
12811 [0x10C83, 0x10CC3],
12812 [0x10C84, 0x10CC4],
12813 [0x10C85, 0x10CC5],
12814 [0x10C86, 0x10CC6],
12815 [0x10C87, 0x10CC7],
12816 [0x10C88, 0x10CC8],
12817 [0x10C89, 0x10CC9],
12818 [0x10C8A, 0x10CCA],
12819 [0x10C8B, 0x10CCB],
12820 [0x10C8C, 0x10CCC],
12821 [0x10C8D, 0x10CCD],
12822 [0x10C8E, 0x10CCE],
12823 [0x10C8F, 0x10CCF],
12824 [0x10C90, 0x10CD0],
12825 [0x10C91, 0x10CD1],
12826 [0x10C92, 0x10CD2],
12827 [0x10C93, 0x10CD3],
12828 [0x10C94, 0x10CD4],
12829 [0x10C95, 0x10CD5],
12830 [0x10C96, 0x10CD6],
12831 [0x10C97, 0x10CD7],
12832 [0x10C98, 0x10CD8],
12833 [0x10C99, 0x10CD9],
12834 [0x10C9A, 0x10CDA],
12835 [0x10C9B, 0x10CDB],
12836 [0x10C9C, 0x10CDC],
12837 [0x10C9D, 0x10CDD],
12838 [0x10C9E, 0x10CDE],
12839 [0x10C9F, 0x10CDF],
12840 [0x10CA0, 0x10CE0],
12841 [0x10CA1, 0x10CE1],
12842 [0x10CA2, 0x10CE2],
12843 [0x10CA3, 0x10CE3],
12844 [0x10CA4, 0x10CE4],
12845 [0x10CA5, 0x10CE5],
12846 [0x10CA6, 0x10CE6],
12847 [0x10CA7, 0x10CE7],
12848 [0x10CA8, 0x10CE8],
12849 [0x10CA9, 0x10CE9],
12850 [0x10CAA, 0x10CEA],
12851 [0x10CAB, 0x10CEB],
12852 [0x10CAC, 0x10CEC],
12853 [0x10CAD, 0x10CED],
12854 [0x10CAE, 0x10CEE],
12855 [0x10CAF, 0x10CEF],
12856 [0x10CB0, 0x10CF0],
12857 [0x10CB1, 0x10CF1],
12858 [0x10CB2, 0x10CF2],
12859 [0x10CC0, 0x10C80],
12860 [0x10CC1, 0x10C81],
12861 [0x10CC2, 0x10C82],
12862 [0x10CC3, 0x10C83],
12863 [0x10CC4, 0x10C84],
12864 [0x10CC5, 0x10C85],
12865 [0x10CC6, 0x10C86],
12866 [0x10CC7, 0x10C87],
12867 [0x10CC8, 0x10C88],
12868 [0x10CC9, 0x10C89],
12869 [0x10CCA, 0x10C8A],
12870 [0x10CCB, 0x10C8B],
12871 [0x10CCC, 0x10C8C],
12872 [0x10CCD, 0x10C8D],
12873 [0x10CCE, 0x10C8E],
12874 [0x10CCF, 0x10C8F],
12875 [0x10CD0, 0x10C90],
12876 [0x10CD1, 0x10C91],
12877 [0x10CD2, 0x10C92],
12878 [0x10CD3, 0x10C93],
12879 [0x10CD4, 0x10C94],
12880 [0x10CD5, 0x10C95],
12881 [0x10CD6, 0x10C96],
12882 [0x10CD7, 0x10C97],
12883 [0x10CD8, 0x10C98],
12884 [0x10CD9, 0x10C99],
12885 [0x10CDA, 0x10C9A],
12886 [0x10CDB, 0x10C9B],
12887 [0x10CDC, 0x10C9C],
12888 [0x10CDD, 0x10C9D],
12889 [0x10CDE, 0x10C9E],
12890 [0x10CDF, 0x10C9F],
12891 [0x10CE0, 0x10CA0],
12892 [0x10CE1, 0x10CA1],
12893 [0x10CE2, 0x10CA2],
12894 [0x10CE3, 0x10CA3],
12895 [0x10CE4, 0x10CA4],
12896 [0x10CE5, 0x10CA5],
12897 [0x10CE6, 0x10CA6],
12898 [0x10CE7, 0x10CA7],
12899 [0x10CE8, 0x10CA8],
12900 [0x10CE9, 0x10CA9],
12901 [0x10CEA, 0x10CAA],
12902 [0x10CEB, 0x10CAB],
12903 [0x10CEC, 0x10CAC],
12904 [0x10CED, 0x10CAD],
12905 [0x10CEE, 0x10CAE],
12906 [0x10CEF, 0x10CAF],
12907 [0x10CF0, 0x10CB0],
12908 [0x10CF1, 0x10CB1],
12909 [0x10CF2, 0x10CB2],
12910 [0x118A0, 0x118C0],
12911 [0x118A1, 0x118C1],
12912 [0x118A2, 0x118C2],
12913 [0x118A3, 0x118C3],
12914 [0x118A4, 0x118C4],
12915 [0x118A5, 0x118C5],
12916 [0x118A6, 0x118C6],
12917 [0x118A7, 0x118C7],
12918 [0x118A8, 0x118C8],
12919 [0x118A9, 0x118C9],
12920 [0x118AA, 0x118CA],
12921 [0x118AB, 0x118CB],
12922 [0x118AC, 0x118CC],
12923 [0x118AD, 0x118CD],
12924 [0x118AE, 0x118CE],
12925 [0x118AF, 0x118CF],
12926 [0x118B0, 0x118D0],
12927 [0x118B1, 0x118D1],
12928 [0x118B2, 0x118D2],
12929 [0x118B3, 0x118D3],
12930 [0x118B4, 0x118D4],
12931 [0x118B5, 0x118D5],
12932 [0x118B6, 0x118D6],
12933 [0x118B7, 0x118D7],
12934 [0x118B8, 0x118D8],
12935 [0x118B9, 0x118D9],
12936 [0x118BA, 0x118DA],
12937 [0x118BB, 0x118DB],
12938 [0x118BC, 0x118DC],
12939 [0x118BD, 0x118DD],
12940 [0x118BE, 0x118DE],
12941 [0x118BF, 0x118DF],
12942 [0x118C0, 0x118A0],
12943 [0x118C1, 0x118A1],
12944 [0x118C2, 0x118A2],
12945 [0x118C3, 0x118A3],
12946 [0x118C4, 0x118A4],
12947 [0x118C5, 0x118A5],
12948 [0x118C6, 0x118A6],
12949 [0x118C7, 0x118A7],
12950 [0x118C8, 0x118A8],
12951 [0x118C9, 0x118A9],
12952 [0x118CA, 0x118AA],
12953 [0x118CB, 0x118AB],
12954 [0x118CC, 0x118AC],
12955 [0x118CD, 0x118AD],
12956 [0x118CE, 0x118AE],
12957 [0x118CF, 0x118AF],
12958 [0x118D0, 0x118B0],
12959 [0x118D1, 0x118B1],
12960 [0x118D2, 0x118B2],
12961 [0x118D3, 0x118B3],
12962 [0x118D4, 0x118B4],
12963 [0x118D5, 0x118B5],
12964 [0x118D6, 0x118B6],
12965 [0x118D7, 0x118B7],
12966 [0x118D8, 0x118B8],
12967 [0x118D9, 0x118B9],
12968 [0x118DA, 0x118BA],
12969 [0x118DB, 0x118BB],
12970 [0x118DC, 0x118BC],
12971 [0x118DD, 0x118BD],
12972 [0x118DE, 0x118BE],
12973 [0x118DF, 0x118BF],
12974 [0x1E900, 0x1E922],
12975 [0x1E901, 0x1E923],
12976 [0x1E902, 0x1E924],
12977 [0x1E903, 0x1E925],
12978 [0x1E904, 0x1E926],
12979 [0x1E905, 0x1E927],
12980 [0x1E906, 0x1E928],
12981 [0x1E907, 0x1E929],
12982 [0x1E908, 0x1E92A],
12983 [0x1E909, 0x1E92B],
12984 [0x1E90A, 0x1E92C],
12985 [0x1E90B, 0x1E92D],
12986 [0x1E90C, 0x1E92E],
12987 [0x1E90D, 0x1E92F],
12988 [0x1E90E, 0x1E930],
12989 [0x1E90F, 0x1E931],
12990 [0x1E910, 0x1E932],
12991 [0x1E911, 0x1E933],
12992 [0x1E912, 0x1E934],
12993 [0x1E913, 0x1E935],
12994 [0x1E914, 0x1E936],
12995 [0x1E915, 0x1E937],
12996 [0x1E916, 0x1E938],
12997 [0x1E917, 0x1E939],
12998 [0x1E918, 0x1E93A],
12999 [0x1E919, 0x1E93B],
13000 [0x1E91A, 0x1E93C],
13001 [0x1E91B, 0x1E93D],
13002 [0x1E91C, 0x1E93E],
13003 [0x1E91D, 0x1E93F],
13004 [0x1E91E, 0x1E940],
13005 [0x1E91F, 0x1E941],
13006 [0x1E920, 0x1E942],
13007 [0x1E921, 0x1E943],
13008 [0x1E922, 0x1E900],
13009 [0x1E923, 0x1E901],
13010 [0x1E924, 0x1E902],
13011 [0x1E925, 0x1E903],
13012 [0x1E926, 0x1E904],
13013 [0x1E927, 0x1E905],
13014 [0x1E928, 0x1E906],
13015 [0x1E929, 0x1E907],
13016 [0x1E92A, 0x1E908],
13017 [0x1E92B, 0x1E909],
13018 [0x1E92C, 0x1E90A],
13019 [0x1E92D, 0x1E90B],
13020 [0x1E92E, 0x1E90C],
13021 [0x1E92F, 0x1E90D],
13022 [0x1E930, 0x1E90E],
13023 [0x1E931, 0x1E90F],
13024 [0x1E932, 0x1E910],
13025 [0x1E933, 0x1E911],
13026 [0x1E934, 0x1E912],
13027 [0x1E935, 0x1E913],
13028 [0x1E936, 0x1E914],
13029 [0x1E937, 0x1E915],
13030 [0x1E938, 0x1E916],
13031 [0x1E939, 0x1E917],
13032 [0x1E93A, 0x1E918],
13033 [0x1E93B, 0x1E919],
13034 [0x1E93C, 0x1E91A],
13035 [0x1E93D, 0x1E91B],
13036 [0x1E93E, 0x1E91C],
13037 [0x1E93F, 0x1E91D],
13038 [0x1E940, 0x1E91E],
13039 [0x1E941, 0x1E91F],
13040 [0x1E942, 0x1E920],
13041 [0x1E943, 0x1E921]
13042]);
13043
13044var REGULAR = new Map([
13045 ['d', regenerate()
13046 .addRange(0x30, 0x39)],
13047 ['D', regenerate()
13048 .addRange(0x0, 0x2F)
13049 .addRange(0x3A, 0xFFFF)],
13050 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
13051 .addRange(0x9, 0xD)
13052 .addRange(0x2000, 0x200A)
13053 .addRange(0x2028, 0x2029)],
13054 ['S', regenerate()
13055 .addRange(0x0, 0x8)
13056 .addRange(0xE, 0x1F)
13057 .addRange(0x21, 0x9F)
13058 .addRange(0xA1, 0x167F)
13059 .addRange(0x1681, 0x1FFF)
13060 .addRange(0x200B, 0x2027)
13061 .addRange(0x202A, 0x202E)
13062 .addRange(0x2030, 0x205E)
13063 .addRange(0x2060, 0x2FFF)
13064 .addRange(0x3001, 0xFEFE)
13065 .addRange(0xFF00, 0xFFFF)],
13066 ['w', regenerate(0x5F)
13067 .addRange(0x30, 0x39)
13068 .addRange(0x41, 0x5A)
13069 .addRange(0x61, 0x7A)],
13070 ['W', regenerate(0x60)
13071 .addRange(0x0, 0x2F)
13072 .addRange(0x3A, 0x40)
13073 .addRange(0x5B, 0x5E)
13074 .addRange(0x7B, 0xFFFF)]
13075]);
13076
13077var UNICODE = new Map([
13078 ['d', regenerate()
13079 .addRange(0x30, 0x39)],
13080 ['D', regenerate()
13081 .addRange(0x0, 0x2F)
13082 .addRange(0x3A, 0x10FFFF)],
13083 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
13084 .addRange(0x9, 0xD)
13085 .addRange(0x2000, 0x200A)
13086 .addRange(0x2028, 0x2029)],
13087 ['S', regenerate()
13088 .addRange(0x0, 0x8)
13089 .addRange(0xE, 0x1F)
13090 .addRange(0x21, 0x9F)
13091 .addRange(0xA1, 0x167F)
13092 .addRange(0x1681, 0x1FFF)
13093 .addRange(0x200B, 0x2027)
13094 .addRange(0x202A, 0x202E)
13095 .addRange(0x2030, 0x205E)
13096 .addRange(0x2060, 0x2FFF)
13097 .addRange(0x3001, 0xFEFE)
13098 .addRange(0xFF00, 0x10FFFF)],
13099 ['w', regenerate(0x5F)
13100 .addRange(0x30, 0x39)
13101 .addRange(0x41, 0x5A)
13102 .addRange(0x61, 0x7A)],
13103 ['W', regenerate(0x60)
13104 .addRange(0x0, 0x2F)
13105 .addRange(0x3A, 0x40)
13106 .addRange(0x5B, 0x5E)
13107 .addRange(0x7B, 0x10FFFF)]
13108]);
13109
13110var UNICODE_IGNORE_CASE = new Map([
13111 ['d', regenerate()
13112 .addRange(0x30, 0x39)],
13113 ['D', regenerate()
13114 .addRange(0x0, 0x2F)
13115 .addRange(0x3A, 0x10FFFF)],
13116 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
13117 .addRange(0x9, 0xD)
13118 .addRange(0x2000, 0x200A)
13119 .addRange(0x2028, 0x2029)],
13120 ['S', regenerate()
13121 .addRange(0x0, 0x8)
13122 .addRange(0xE, 0x1F)
13123 .addRange(0x21, 0x9F)
13124 .addRange(0xA1, 0x167F)
13125 .addRange(0x1681, 0x1FFF)
13126 .addRange(0x200B, 0x2027)
13127 .addRange(0x202A, 0x202E)
13128 .addRange(0x2030, 0x205E)
13129 .addRange(0x2060, 0x2FFF)
13130 .addRange(0x3001, 0xFEFE)
13131 .addRange(0xFF00, 0x10FFFF)],
13132 ['w', regenerate(0x5F, 0x17F, 0x212A)
13133 .addRange(0x30, 0x39)
13134 .addRange(0x41, 0x5A)
13135 .addRange(0x61, 0x7A)],
13136 ['W', regenerate(0x60)
13137 .addRange(0x0, 0x2F)
13138 .addRange(0x3A, 0x40)
13139 .addRange(0x5B, 0x5E)
13140 .addRange(0x7B, 0x17E)
13141 .addRange(0x180, 0x2129)
13142 .addRange(0x212B, 0x10FFFF)]
13143]);
13144
13145var characterClassEscapeSets = {
13146 REGULAR: REGULAR,
13147 UNICODE: UNICODE,
13148 UNICODE_IGNORE_CASE: UNICODE_IGNORE_CASE
13149};
13150
13151var rewritePattern_1 = createCommonjsModule(function (module) {
13152var generate = regjsgen.generate;
13153var parse = parser.parse;
13154
13155
13156
13157
13158
13159
13160// Prepare a Regenerate set containing all code points, used for negative
13161// character classes (if any).
13162var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
13163// Without the `u` flag, the range stops at 0xFFFF.
13164// https://mths.be/es6#sec-pattern-semantics
13165var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
13166
13167// Prepare a Regenerate set containing all code points that are supposed to be
13168// matched by `/./u`. https://mths.be/es6#sec-atom
13169var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
13170 .remove(
13171 // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
13172 0x000A, // Line Feed <LF>
13173 0x000D, // Carriage Return <CR>
13174 0x2028, // Line Separator <LS>
13175 0x2029 // Paragraph Separator <PS>
13176 );
13177// Prepare a Regenerate set containing all code points that are supposed to be
13178// matched by `/./` (only BMP code points).
13179var DOT_SET = DOT_SET_UNICODE.clone()
13180 .intersection(BMP_SET);
13181
13182var getCharacterClassEscapeSet = function (character, unicode, ignoreCase) {
13183 if (unicode) {
13184 if (ignoreCase) {
13185 return characterClassEscapeSets.UNICODE_IGNORE_CASE.get(character);
13186 }
13187 return characterClassEscapeSets.UNICODE.get(character);
13188 }
13189 return characterClassEscapeSets.REGULAR.get(character);
13190};
13191
13192var getDotSet = function (unicode, dotAll) {
13193 if (dotAll) {
13194 return unicode ? UNICODE_SET : BMP_SET;
13195 }
13196 return unicode ? DOT_SET_UNICODE : DOT_SET;
13197};
13198
13199var getUnicodePropertyValueSet = function (property, value) {
13200 var path = value ?
13201 (property + "/" + value) :
13202 ("Binary_Property/" + property);
13203 try {
13204 return commonjsRequire(("regenerate-unicode-properties/" + path + ".js"));
13205 } catch (exception) {
13206 throw new Error(
13207 "Failed to recognize value `" + value + "` for property " +
13208 "`" + property + "`."
13209 );
13210 }
13211};
13212
13213var handleLoneUnicodePropertyNameOrValue = function (value) {
13214 // It could be a `General_Category` value or a binary property.
13215 // Note: `unicodeMatchPropertyValue` throws on invalid values.
13216 try {
13217 var property$1 = 'General_Category';
13218 var category = unicodeMatchPropertyValueEcmascript(property$1, value);
13219 return getUnicodePropertyValueSet(property$1, category);
13220 } catch (exception) {}
13221 // It’s not a `General_Category` value, so check if it’s a binary
13222 // property. Note: `unicodeMatchProperty` throws on invalid properties.
13223 var property = unicodeMatchPropertyEcmascript(value);
13224 return getUnicodePropertyValueSet(property);
13225};
13226
13227var getUnicodePropertyEscapeSet = function (value, isNegative) {
13228 var parts = value.split('=');
13229 var firstPart = parts[0];
13230 var set;
13231 if (parts.length == 1) {
13232 set = handleLoneUnicodePropertyNameOrValue(firstPart);
13233 } else {
13234 // The pattern consists of two parts, i.e. `Property=Value`.
13235 var property = unicodeMatchPropertyEcmascript(firstPart);
13236 var value$1 = unicodeMatchPropertyValueEcmascript(property, parts[1]);
13237 set = getUnicodePropertyValueSet(property, value$1);
13238 }
13239 if (isNegative) {
13240 return UNICODE_SET.clone().remove(set);
13241 }
13242 return set.clone();
13243};
13244
13245// Given a range of code points, add any case-folded code points in that range
13246// to a set.
13247regenerate.prototype.iuAddRange = function(min, max) {
13248 var $this = this;
13249 do {
13250 var folded = caseFold(min);
13251 if (folded) {
13252 $this.add(folded);
13253 }
13254 } while (++min <= max);
13255 return $this;
13256};
13257
13258var update = function (item, pattern) {
13259 var tree = parse(pattern, config.useUnicodeFlag ? 'u' : '');
13260 switch (tree.type) {
13261 case 'characterClass':
13262 case 'group':
13263 case 'value':
13264 // No wrapping needed.
13265 break;
13266 default:
13267 // Wrap the pattern in a non-capturing group.
13268 tree = wrap(tree, pattern);
13269 }
13270 Object.assign(item, tree);
13271};
13272
13273var wrap = function (tree, pattern) {
13274 // Wrap the pattern in a non-capturing group.
13275 return {
13276 'type': 'group',
13277 'behavior': 'ignore',
13278 'body': [tree],
13279 'raw': ("(?:" + pattern + ")")
13280 };
13281};
13282
13283var caseFold = function (codePoint) {
13284 return iuMappings.get(codePoint) || false;
13285};
13286
13287var processCharacterClass = function (characterClassItem, regenerateOptions) {
13288 var set = regenerate();
13289 for (var i = 0, list = characterClassItem.body; i < list.length; i += 1) {
13290 var item = list[i];
13291
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
13334var processTerm = function (item, regenerateOptions) {
13335 switch (item.type) {
13336 case 'dot':
13337 update(
13338 item,
13339 getDotSet(config.unicode, config.dotAll).toString(regenerateOptions)
13340 );
13341 break;
13342 case 'characterClass':
13343 item = processCharacterClass(item, regenerateOptions);
13344 break;
13345 case 'unicodePropertyEscape':
13346 update(
13347 item,
13348 getUnicodePropertyEscapeSet(item.value, item.negative)
13349 .toString(regenerateOptions)
13350 );
13351 break;
13352 case 'characterClassEscape':
13353 update(
13354 item,
13355 getCharacterClassEscapeSet(
13356 item.value,
13357 config.unicode,
13358 config.ignoreCase
13359 ).toString(regenerateOptions)
13360 );
13361 break;
13362 case 'alternative':
13363 case 'disjunction':
13364 case 'group':
13365 case 'quantifier':
13366 item.body = item.body.map(function (term) {
13367 return processTerm(term, regenerateOptions);
13368 });
13369 break;
13370 case 'value':
13371 var codePoint = item.codePoint;
13372 var set = regenerate(codePoint);
13373 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
13374 var folded = caseFold(codePoint);
13375 if (folded) {
13376 set.add(folded);
13377 }
13378 }
13379 update(item, set.toString(regenerateOptions));
13380 break;
13381 case 'anchor':
13382 case 'empty':
13383 case 'group':
13384 case 'reference':
13385 // Nothing to do here.
13386 break;
13387 // The `default` clause is only here as a safeguard; it should never be
13388 // reached. Code coverage tools should ignore it.
13389 /* istanbul ignore next */
13390 default:
13391 throw new Error(("Unknown term type: " + (item.type)));
13392 }
13393 return item;
13394};
13395
13396var config = {
13397 'ignoreCase': false,
13398 'unicode': false,
13399 'dotAll': false,
13400 'useUnicodeFlag': false
13401};
13402var rewritePattern = function (pattern, flags, options) {
13403 var regjsparserFeatures = {
13404 'unicodePropertyEscape': options && options.unicodePropertyEscape
13405 };
13406 config.ignoreCase = flags && flags.includes('i');
13407 config.unicode = flags && flags.includes('u');
13408 var supportDotAllFlag = options && options.dotAllFlag;
13409 config.dotAll = supportDotAllFlag && flags && flags.includes('s');
13410 config.useUnicodeFlag = options && options.useUnicodeFlag;
13411 var regenerateOptions = {
13412 'hasUnicodeFlag': config.useUnicodeFlag,
13413 'bmpOnly': !config.unicode
13414 };
13415 var tree = parse(pattern, flags, regjsparserFeatures);
13416 // Note: `processTerm` mutates `tree`.
13417 processTerm(tree, regenerateOptions);
13418 return generate(tree);
13419};
13420
13421module.exports = rewritePattern;
13422});
13423
13424var Literal = (function (Node) {
13425 function Literal () {
13426 Node.apply(this, arguments);
13427 }
13428
13429 if ( Node ) Literal.__proto__ = Node;
13430 Literal.prototype = Object.create( Node && Node.prototype );
13431 Literal.prototype.constructor = Literal;
13432
13433 Literal.prototype.initialise = function initialise () {
13434 if (typeof this.value === 'string') {
13435 this.program.indentExclusionElements.push(this);
13436 }
13437 };
13438
13439 Literal.prototype.transpile = function transpile (code, transforms) {
13440 if (transforms.numericLiteral) {
13441 var leading = this.raw.slice(0, 2);
13442 if (leading === '0b' || leading === '0o') {
13443 code.overwrite(this.start, this.end, String(this.value), {
13444 storeName: true,
13445 contentOnly: true
13446 });
13447 }
13448 }
13449
13450 if (this.regex) {
13451 var ref = this.regex;
13452 var pattern = ref.pattern;
13453 var flags = ref.flags;
13454
13455 if (transforms.stickyRegExp && /y/.test(flags))
13456 { throw new CompileError(
13457 'Regular expression sticky flag is not supported',
13458 this
13459 ); }
13460 if (transforms.unicodeRegExp && /u/.test(flags)) {
13461 code.overwrite(
13462 this.start,
13463 this.end,
13464 ("/" + (rewritePattern_1(pattern, flags)) + "/" + (flags.replace('u', ''))),
13465 {
13466 contentOnly: true
13467 }
13468 );
13469 }
13470 }
13471 };
13472
13473 return Literal;
13474}(Node$1));
13475
13476var MemberExpression = (function (Node) {
13477 function MemberExpression () {
13478 Node.apply(this, arguments);
13479 }
13480
13481 if ( Node ) MemberExpression.__proto__ = Node;
13482 MemberExpression.prototype = Object.create( Node && Node.prototype );
13483 MemberExpression.prototype.constructor = MemberExpression;
13484
13485 MemberExpression.prototype.transpile = function transpile (code, transforms) {
13486 if (transforms.reservedProperties && reserved[this.property.name]) {
13487 code.overwrite(this.object.end, this.property.start, "['");
13488 code.appendLeft(this.property.end, "']");
13489 }
13490
13491 Node.prototype.transpile.call(this, code, transforms);
13492 };
13493
13494 return MemberExpression;
13495}(Node$1));
13496
13497var NewExpression = (function (Node) {
13498 function NewExpression () {
13499 Node.apply(this, arguments);
13500 }
13501
13502 if ( Node ) NewExpression.__proto__ = Node;
13503 NewExpression.prototype = Object.create( Node && Node.prototype );
13504 NewExpression.prototype.constructor = NewExpression;
13505
13506 NewExpression.prototype.initialise = function initialise (transforms) {
13507 var this$1 = this;
13508
13509 if (transforms.spreadRest && this.arguments.length) {
13510 var lexicalBoundary = this.findLexicalBoundary();
13511
13512 var i = this.arguments.length;
13513 while (i--) {
13514 var arg = this$1.arguments[i];
13515 if (arg.type === 'SpreadElement' && isArguments(arg.argument)) {
13516 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
13517 break;
13518 }
13519 }
13520 }
13521
13522 Node.prototype.initialise.call(this, transforms);
13523 };
13524
13525 NewExpression.prototype.transpile = function transpile (code, transforms) {
13526 Node.prototype.transpile.call(this, code, transforms);
13527
13528 if (transforms.spreadRest && this.arguments.length) {
13529 var firstArgument = this.arguments[0];
13530 var isNew = true;
13531 var hasSpreadElements = spread(
13532 code,
13533 this.arguments,
13534 firstArgument.start,
13535 this.argumentsArrayAlias,
13536 isNew
13537 );
13538
13539 if (hasSpreadElements) {
13540 code.prependRight(
13541 this.start + 'new'.length,
13542 ' (Function.prototype.bind.apply('
13543 );
13544 code.overwrite(
13545 this.callee.end,
13546 firstArgument.start,
13547 ', [ null ].concat( '
13548 );
13549 code.appendLeft(this.end, ' ))');
13550 }
13551 }
13552
13553 if (this.arguments.length) {
13554 removeTrailingComma(code, this.arguments[this.arguments.length - 1].end);
13555 }
13556 };
13557
13558 return NewExpression;
13559}(Node$1));
13560
13561var ObjectExpression = (function (Node) {
13562 function ObjectExpression () {
13563 Node.apply(this, arguments);
13564 }
13565
13566 if ( Node ) ObjectExpression.__proto__ = Node;
13567 ObjectExpression.prototype = Object.create( Node && Node.prototype );
13568 ObjectExpression.prototype.constructor = ObjectExpression;
13569
13570 ObjectExpression.prototype.transpile = function transpile (code, transforms) {
13571 var this$1 = this;
13572
13573 Node.prototype.transpile.call(this, code, transforms);
13574
13575 var firstPropertyStart = this.start + 1;
13576 var regularPropertyCount = 0;
13577 var spreadPropertyCount = 0;
13578 var computedPropertyCount = 0;
13579 var firstSpreadProperty = null;
13580 var firstComputedProperty = null;
13581
13582 for (var i = 0; i < this.properties.length; ++i) {
13583 var prop = this$1.properties[i];
13584 if (prop.type === 'SpreadElement') {
13585 spreadPropertyCount += 1;
13586 if (firstSpreadProperty === null) { firstSpreadProperty = i; }
13587 } else if (prop.computed) {
13588 computedPropertyCount += 1;
13589 if (firstComputedProperty === null) { firstComputedProperty = i; }
13590 } else if (prop.type === 'Property') {
13591 regularPropertyCount += 1;
13592 }
13593 }
13594
13595 if (spreadPropertyCount) {
13596 if (!this.program.options.objectAssign) {
13597 throw new CompileError(
13598 "Object spread operator requires specified objectAssign option with 'Object.assign' or polyfill helper.",
13599 this
13600 );
13601 }
13602 // enclose run of non-spread properties in curlies
13603 var i$1 = this.properties.length;
13604 if (regularPropertyCount && !computedPropertyCount) {
13605 while (i$1--) {
13606 var prop$1 = this$1.properties[i$1];
13607
13608 if (prop$1.type === 'Property' && !prop$1.computed) {
13609 var lastProp = this$1.properties[i$1 - 1];
13610 var nextProp = this$1.properties[i$1 + 1];
13611
13612 if (
13613 !lastProp ||
13614 lastProp.type !== 'Property' ||
13615 lastProp.computed
13616 ) {
13617 code.prependRight(prop$1.start, '{');
13618 }
13619
13620 if (
13621 !nextProp ||
13622 nextProp.type !== 'Property' ||
13623 nextProp.computed
13624 ) {
13625 code.appendLeft(prop$1.end, '}');
13626 }
13627 }
13628 }
13629 }
13630
13631 // wrap the whole thing in Object.assign
13632 firstPropertyStart = this.properties[0].start;
13633 if (!computedPropertyCount) {
13634 code.overwrite(
13635 this.start,
13636 firstPropertyStart,
13637 ((this.program.options.objectAssign) + "({}, ")
13638 );
13639 code.overwrite(
13640 this.properties[this.properties.length - 1].end,
13641 this.end,
13642 ')'
13643 );
13644 } else if (this.properties[0].type === 'SpreadElement') {
13645 code.overwrite(
13646 this.start,
13647 firstPropertyStart,
13648 ((this.program.options.objectAssign) + "({}, ")
13649 );
13650 code.remove(this.end - 1, this.end);
13651 code.appendRight(this.end, ')');
13652 } else {
13653 code.prependLeft(this.start, ((this.program.options.objectAssign) + "("));
13654 code.appendRight(this.end, ')');
13655 }
13656 }
13657
13658 if (computedPropertyCount && transforms.computedProperty) {
13659 var i0 = this.getIndentation();
13660
13661 var isSimpleAssignment;
13662 var name;
13663
13664 if (
13665 this.parent.type === 'VariableDeclarator' &&
13666 this.parent.parent.declarations.length === 1 &&
13667 this.parent.id.type === 'Identifier'
13668 ) {
13669 isSimpleAssignment = true;
13670 name = this.parent.id.alias || this.parent.id.name; // TODO is this right?
13671 } else if (
13672 this.parent.type === 'AssignmentExpression' &&
13673 this.parent.parent.type === 'ExpressionStatement' &&
13674 this.parent.left.type === 'Identifier'
13675 ) {
13676 isSimpleAssignment = true;
13677 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
13678 } else if (
13679 this.parent.type === 'AssignmentPattern' &&
13680 this.parent.left.type === 'Identifier'
13681 ) {
13682 isSimpleAssignment = true;
13683 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
13684 }
13685
13686 if (spreadPropertyCount) { isSimpleAssignment = false; }
13687
13688 // handle block scoping
13689 name = this.findScope(false).resolveName(name);
13690
13691 var start = firstPropertyStart;
13692 var end = this.end;
13693
13694 if (isSimpleAssignment) {
13695 // ???
13696 } else {
13697 if (
13698 firstSpreadProperty === null ||
13699 firstComputedProperty < firstSpreadProperty
13700 ) {
13701 name = this.findScope(true).createDeclaration('obj');
13702
13703 code.prependRight(this.start, ("( " + name + " = "));
13704 } else { name = null; } // We don't actually need this variable
13705 }
13706
13707 var len = this.properties.length;
13708 var lastComputedProp;
13709 var sawNonComputedProperty = false;
13710 var isFirst = true;
13711
13712 for (var i$2 = 0; i$2 < len; i$2 += 1) {
13713 var prop$2 = this$1.properties[i$2];
13714 var moveStart = i$2 > 0 ? this$1.properties[i$2 - 1].end : start;
13715
13716 if (
13717 prop$2.type === 'Property' &&
13718 (prop$2.computed || (lastComputedProp && !spreadPropertyCount))
13719 ) {
13720 if (i$2 === 0) { moveStart = this$1.start + 1; } // Trim leading whitespace
13721 lastComputedProp = prop$2;
13722
13723 if (!name) {
13724 name = this$1.findScope(true).createDeclaration('obj');
13725
13726 var propId = name + (prop$2.computed ? '' : '.');
13727 code.appendRight(prop$2.start, ("( " + name + " = {}, " + propId));
13728 } else {
13729 var propId$1 =
13730 (isSimpleAssignment ? (";\n" + i0 + name) : (", " + name)) +
13731 (prop$2.key.type === 'Literal' || prop$2.computed ? '' : '.');
13732
13733 if (moveStart < prop$2.start) {
13734 code.overwrite(moveStart, prop$2.start, propId$1);
13735 } else {
13736 code.prependRight(prop$2.start, propId$1);
13737 }
13738 }
13739
13740 var c = prop$2.key.end;
13741 if (prop$2.computed) {
13742 while (code.original[c] !== ']') { c += 1; }
13743 c += 1;
13744 }
13745 if (prop$2.key.type === 'Literal' && !prop$2.computed) {
13746 code.overwrite(
13747 prop$2.start,
13748 prop$2.key.end + 1,
13749 '[' + code.slice(prop$2.start, prop$2.key.end) + '] = '
13750 );
13751 } else if (prop$2.shorthand || (prop$2.method && !prop$2.computed && transforms.conciseMethodProperty)) {
13752 // Replace : with = if Property::transpile inserted the :
13753 code.overwrite(
13754 prop$2.key.start,
13755 prop$2.key.end,
13756 code.slice(prop$2.key.start, prop$2.key.end).replace(/:/, ' =')
13757 );
13758 } else {
13759 if (prop$2.value.start > c) { code.remove(c, prop$2.value.start); }
13760 code.prependLeft(c, ' = ');
13761 }
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$1.properties[i$2 - 1];
13773 }
13774 code.appendLeft(lastComputedProp.end, (", " + name + " )"));
13775
13776 lastComputedProp = null;
13777 name = null;
13778 }
13779 } else {
13780 if (!isFirst && spreadPropertyCount) {
13781 // We are in an Object.assign context, so we need to wrap regular properties
13782 code.prependRight(prop$2.start, '{');
13783 code.appendLeft(prop$2.end, '}');
13784 }
13785 sawNonComputedProperty = true;
13786 }
13787 if (isFirst && (prop$2.type === 'SpreadElement' || prop$2.computed)) {
13788 var beginEnd = sawNonComputedProperty
13789 ? this$1.properties[this$1.properties.length - 1].end
13790 : this$1.end - 1;
13791 // Trim trailing comma because it can easily become a leading comma which is illegal
13792 if (code.original[beginEnd] == ',') { ++beginEnd; }
13793 var closing = code.slice(beginEnd, end);
13794 code.prependLeft(moveStart, closing);
13795 code.remove(beginEnd, end);
13796 isFirst = false;
13797 }
13798
13799 // Clean up some extranous whitespace
13800 var c$1 = prop$2.end;
13801 if (i$2 < len - 1 && !sawNonComputedProperty) {
13802 while (code.original[c$1] !== ',') { c$1 += 1; }
13803 } else if (i$2 == len - 1) { c$1 = this$1.end; }
13804 code.remove(prop$2.end, c$1);
13805 }
13806
13807 // special case
13808 if (computedPropertyCount === len) {
13809 code.remove(this.properties[len - 1].end, this.end - 1);
13810 }
13811
13812 if (!isSimpleAssignment && name) {
13813 code.appendLeft(lastComputedProp.end, (", " + name + " )"));
13814 }
13815 }
13816 };
13817
13818 return ObjectExpression;
13819}(Node$1));
13820
13821var Property = (function (Node) {
13822 function Property () {
13823 Node.apply(this, arguments);
13824 }
13825
13826 if ( Node ) Property.__proto__ = Node;
13827 Property.prototype = Object.create( Node && Node.prototype );
13828 Property.prototype.constructor = Property;
13829
13830 Property.prototype.transpile = function transpile (code, transforms) {
13831 Node.prototype.transpile.call(this, code, transforms);
13832
13833 if (
13834 transforms.conciseMethodProperty &&
13835 !this.computed &&
13836 this.parent.type !== 'ObjectPattern'
13837 ) {
13838 if (this.shorthand) {
13839 code.prependRight(this.start, ((this.key.name) + ": "));
13840 } else if (this.method) {
13841 var name = '';
13842 if (this.program.options.namedFunctionExpressions !== false) {
13843 if (
13844 this.key.type === 'Literal' &&
13845 typeof this.key.value === 'number'
13846 ) {
13847 name = '';
13848 } else if (this.key.type === 'Identifier') {
13849 if (
13850 reserved[this.key.name] ||
13851 !/^[a-z_$][a-z0-9_$]*$/i.test(this.key.name) ||
13852 this.value.body.scope.references[this.key.name]
13853 ) {
13854 name = this.findScope(true).createIdentifier(this.key.name);
13855 } else {
13856 name = this.key.name;
13857 }
13858 } else {
13859 name = this.findScope(true).createIdentifier(this.key.value);
13860 }
13861 name = ' ' + name;
13862 }
13863
13864 if (this.value.generator) { code.remove(this.start, this.key.start); }
13865 code.appendLeft(
13866 this.key.end,
13867 (": function" + (this.value.generator ? '*' : '') + name)
13868 );
13869 }
13870 }
13871
13872 if (transforms.reservedProperties && reserved[this.key.name]) {
13873 code.prependRight(this.key.start, "'");
13874 code.appendLeft(this.key.end, "'");
13875 }
13876 };
13877
13878 return Property;
13879}(Node$1));
13880
13881var ReturnStatement = (function (Node) {
13882 function ReturnStatement () {
13883 Node.apply(this, arguments);
13884 }
13885
13886 if ( Node ) ReturnStatement.__proto__ = Node;
13887 ReturnStatement.prototype = Object.create( Node && Node.prototype );
13888 ReturnStatement.prototype.constructor = ReturnStatement;
13889
13890 ReturnStatement.prototype.initialise = function initialise (transforms) {
13891 this.loop = this.findNearest(loopStatement);
13892 this.nearestFunction = this.findNearest(/Function/);
13893
13894 if (
13895 this.loop &&
13896 (!this.nearestFunction || this.loop.depth > this.nearestFunction.depth)
13897 ) {
13898 this.loop.canReturn = true;
13899 this.shouldWrap = true;
13900 }
13901
13902 if (this.argument) { this.argument.initialise(transforms); }
13903 };
13904
13905 ReturnStatement.prototype.transpile = function transpile (code, transforms) {
13906 var shouldWrap =
13907 this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;
13908
13909 if (this.argument) {
13910 if (shouldWrap) { code.prependRight(this.argument.start, "{ v: "); }
13911 this.argument.transpile(code, transforms);
13912 if (shouldWrap) { code.appendLeft(this.argument.end, " }"); }
13913 } else if (shouldWrap) {
13914 code.appendLeft(this.start + 6, ' {}');
13915 }
13916 };
13917
13918 return ReturnStatement;
13919}(Node$1));
13920
13921var SpreadElement = (function (Node) {
13922 function SpreadElement () {
13923 Node.apply(this, arguments);
13924 }
13925
13926 if ( Node ) SpreadElement.__proto__ = Node;
13927 SpreadElement.prototype = Object.create( Node && Node.prototype );
13928 SpreadElement.prototype.constructor = SpreadElement;
13929
13930 SpreadElement.prototype.transpile = function transpile (code, transforms) {
13931 if (this.parent.type == 'ObjectExpression') {
13932 code.remove(this.start, this.argument.start);
13933 code.remove(this.argument.end, this.end);
13934 }
13935
13936 Node.prototype.transpile.call(this, code, transforms);
13937 };
13938
13939 return SpreadElement;
13940}(Node$1));
13941
13942var Super = (function (Node) {
13943 function Super () {
13944 Node.apply(this, arguments);
13945 }
13946
13947 if ( Node ) Super.__proto__ = Node;
13948 Super.prototype = Object.create( Node && Node.prototype );
13949 Super.prototype.constructor = Super;
13950
13951 Super.prototype.initialise = function initialise (transforms) {
13952 if (transforms.classes) {
13953 this.method = this.findNearest('MethodDefinition');
13954 if (!this.method)
13955 { throw new CompileError('use of super outside class method', this); }
13956
13957 var parentClass = this.findNearest('ClassBody').parent;
13958 this.superClassName =
13959 parentClass.superClass && (parentClass.superClass.name || 'superclass');
13960
13961 if (!this.superClassName)
13962 { throw new CompileError('super used in base class', this); }
13963
13964 this.isCalled =
13965 this.parent.type === 'CallExpression' && this === this.parent.callee;
13966
13967 if (this.method.kind !== 'constructor' && this.isCalled) {
13968 throw new CompileError(
13969 'super() not allowed outside class constructor',
13970 this
13971 );
13972 }
13973
13974 this.isMember = this.parent.type === 'MemberExpression';
13975
13976 if (!this.isCalled && !this.isMember) {
13977 throw new CompileError(
13978 'Unexpected use of `super` (expected `super(...)` or `super.*`)',
13979 this
13980 );
13981 }
13982 }
13983
13984 if (transforms.arrow) {
13985 var lexicalBoundary = this.findLexicalBoundary();
13986 var arrowFunction = this.findNearest('ArrowFunctionExpression');
13987 var loop = this.findNearest(loopStatement);
13988
13989 if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) {
13990 this.thisAlias = lexicalBoundary.getThisAlias();
13991 }
13992
13993 if (
13994 loop &&
13995 loop.body.contains(this) &&
13996 loop.depth > lexicalBoundary.depth
13997 ) {
13998 this.thisAlias = lexicalBoundary.getThisAlias();
13999 }
14000 }
14001 };
14002
14003 Super.prototype.transpile = function transpile (code, transforms) {
14004 if (transforms.classes) {
14005 var expression =
14006 this.isCalled || this.method.static
14007 ? this.superClassName
14008 : ((this.superClassName) + ".prototype");
14009
14010 code.overwrite(this.start, this.end, expression, {
14011 storeName: true,
14012 contentOnly: true
14013 });
14014
14015 var callExpression = this.isCalled ? this.parent : this.parent.parent;
14016
14017 if (callExpression && callExpression.type === 'CallExpression') {
14018 if (!this.noCall) {
14019 // special case – `super( ...args )`
14020 code.appendLeft(callExpression.callee.end, '.call');
14021 }
14022
14023 var thisAlias = this.thisAlias || 'this';
14024
14025 if (callExpression.arguments.length) {
14026 code.appendLeft(callExpression.arguments[0].start, (thisAlias + ", "));
14027 } else {
14028 code.appendLeft(callExpression.end - 1, ("" + thisAlias));
14029 }
14030 }
14031 }
14032 };
14033
14034 return Super;
14035}(Node$1));
14036
14037var TaggedTemplateExpression = (function (Node) {
14038 function TaggedTemplateExpression () {
14039 Node.apply(this, arguments);
14040 }
14041
14042 if ( Node ) TaggedTemplateExpression.__proto__ = Node;
14043 TaggedTemplateExpression.prototype = Object.create( Node && Node.prototype );
14044 TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
14045
14046 TaggedTemplateExpression.prototype.initialise = function initialise (transforms) {
14047 if (
14048 transforms.templateString &&
14049 !transforms.dangerousTaggedTemplateString
14050 ) {
14051 throw new CompileError(
14052 "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",
14053 this
14054 );
14055 }
14056
14057 Node.prototype.initialise.call(this, transforms);
14058 };
14059
14060 TaggedTemplateExpression.prototype.transpile = function transpile (code, transforms) {
14061 if (transforms.templateString && transforms.dangerousTaggedTemplateString) {
14062 var ordered = this.quasi.expressions
14063 .concat(this.quasi.quasis)
14064 .sort(function (a, b) { return a.start - b.start; });
14065
14066 var program = this.program;
14067 var rootScope = program.body.scope;
14068
14069 // insert strings at start
14070 var templateStrings = this.quasi.quasis.map(function (quasi) { return JSON.stringify(quasi.value.cooked); }
14071 ).join(', ');
14072
14073 var templateObject = this.program.templateLiteralQuasis[templateStrings];
14074 if (!templateObject) {
14075 templateObject = rootScope.createIdentifier('templateObject');
14076 code.prependRight(this.program.prependAt, ("var " + templateObject + " = Object.freeze([" + templateStrings + "]);\n"));
14077
14078 this.program.templateLiteralQuasis[templateStrings] = templateObject;
14079 }
14080
14081 code.overwrite(
14082 this.tag.end,
14083 ordered[0].start,
14084 ("(" + templateObject)
14085 );
14086
14087 var lastIndex = ordered[0].start;
14088 ordered.forEach(function (node) {
14089 if (node.type === 'TemplateElement') {
14090 code.remove(lastIndex, node.end);
14091 } else {
14092 code.overwrite(lastIndex, node.start, ', ');
14093 }
14094
14095 lastIndex = node.end;
14096 });
14097
14098 code.overwrite(lastIndex, this.end, ')');
14099 }
14100
14101 Node.prototype.transpile.call(this, code, transforms);
14102 };
14103
14104 return TaggedTemplateExpression;
14105}(Node$1));
14106
14107var TemplateElement = (function (Node) {
14108 function TemplateElement () {
14109 Node.apply(this, arguments);
14110 }
14111
14112 if ( Node ) TemplateElement.__proto__ = Node;
14113 TemplateElement.prototype = Object.create( Node && Node.prototype );
14114 TemplateElement.prototype.constructor = TemplateElement;
14115
14116 TemplateElement.prototype.initialise = function initialise () {
14117 this.program.indentExclusionElements.push(this);
14118 };
14119
14120 return TemplateElement;
14121}(Node$1));
14122
14123var TemplateLiteral = (function (Node) {
14124 function TemplateLiteral () {
14125 Node.apply(this, arguments);
14126 }
14127
14128 if ( Node ) TemplateLiteral.__proto__ = Node;
14129 TemplateLiteral.prototype = Object.create( Node && Node.prototype );
14130 TemplateLiteral.prototype.constructor = TemplateLiteral;
14131
14132 TemplateLiteral.prototype.transpile = function transpile (code, transforms) {
14133 Node.prototype.transpile.call(this, code, transforms);
14134
14135 if (
14136 transforms.templateString &&
14137 this.parent.type !== 'TaggedTemplateExpression'
14138 ) {
14139 var ordered = this.expressions
14140 .concat(this.quasis)
14141 .sort(function (a, b) { return a.start - b.start || a.end - b.end; })
14142 .filter(function (node, i) {
14143 // include all expressions
14144 if (node.type !== 'TemplateElement') { return true; }
14145
14146 // include all non-empty strings
14147 if (node.value.raw) { return true; }
14148
14149 // exclude all empty strings not at the head
14150 return !i;
14151 });
14152
14153 // special case – we may be able to skip the first element,
14154 // if it's the empty string, but only if the second and
14155 // third elements aren't both expressions (since they maybe
14156 // be numeric, and `1 + 2 + '3' === '33'`)
14157 if (ordered.length >= 3) {
14158 var first = ordered[0];
14159 var third = ordered[2];
14160 if (
14161 first.type === 'TemplateElement' &&
14162 first.value.raw === '' &&
14163 third.type === 'TemplateElement'
14164 ) {
14165 ordered.shift();
14166 }
14167 }
14168
14169 var parenthesise =
14170 (this.quasis.length !== 1 || this.expressions.length !== 0) &&
14171 this.parent.type !== 'TemplateLiteral' &&
14172 this.parent.type !== 'AssignmentExpression' &&
14173 this.parent.type !== 'AssignmentPattern' &&
14174 this.parent.type !== 'VariableDeclarator' &&
14175 (this.parent.type !== 'BinaryExpression' ||
14176 this.parent.operator !== '+');
14177
14178 if (parenthesise) { code.appendRight(this.start, '('); }
14179
14180 var lastIndex = this.start;
14181
14182 ordered.forEach(function (node, i) {
14183 var prefix = i === 0 ? (parenthesise ? '(' : '') : ' + ';
14184
14185 if (node.type === 'TemplateElement') {
14186 code.overwrite(
14187 lastIndex,
14188 node.end,
14189 prefix + JSON.stringify(node.value.cooked)
14190 );
14191 } else {
14192 var parenthesise$1 = node.type !== 'Identifier'; // TODO other cases where it's safe
14193
14194 if (parenthesise$1) { prefix += '('; }
14195
14196 code.remove(lastIndex, node.start);
14197
14198 if (prefix) { code.prependRight(node.start, prefix); }
14199 if (parenthesise$1) { code.appendLeft(node.end, ')'); }
14200 }
14201
14202 lastIndex = node.end;
14203 });
14204
14205 if (parenthesise) { code.appendLeft(lastIndex, ')'); }
14206 code.overwrite(lastIndex, this.end, "", { contentOnly: true } );
14207 }
14208 };
14209
14210 return TemplateLiteral;
14211}(Node$1));
14212
14213var ThisExpression = (function (Node) {
14214 function ThisExpression () {
14215 Node.apply(this, arguments);
14216 }
14217
14218 if ( Node ) ThisExpression.__proto__ = Node;
14219 ThisExpression.prototype = Object.create( Node && Node.prototype );
14220 ThisExpression.prototype.constructor = ThisExpression;
14221
14222 ThisExpression.prototype.initialise = function initialise (transforms) {
14223 if (transforms.arrow) {
14224 var lexicalBoundary = this.findLexicalBoundary();
14225 var arrowFunction = this.findNearest('ArrowFunctionExpression');
14226 var loop = this.findNearest(loopStatement);
14227
14228 if (
14229 (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) ||
14230 (loop &&
14231 loop.body.contains(this) &&
14232 loop.depth > lexicalBoundary.depth) ||
14233 (loop && loop.right && loop.right.contains(this))
14234 ) {
14235 this.alias = lexicalBoundary.getThisAlias();
14236 }
14237 }
14238 };
14239
14240 ThisExpression.prototype.transpile = function transpile (code) {
14241 if (this.alias) {
14242 code.overwrite(this.start, this.end, this.alias, {
14243 storeName: true,
14244 contentOnly: true
14245 });
14246 }
14247 };
14248
14249 return ThisExpression;
14250}(Node$1));
14251
14252var UpdateExpression = (function (Node) {
14253 function UpdateExpression () {
14254 Node.apply(this, arguments);
14255 }
14256
14257 if ( Node ) UpdateExpression.__proto__ = Node;
14258 UpdateExpression.prototype = Object.create( Node && Node.prototype );
14259 UpdateExpression.prototype.constructor = UpdateExpression;
14260
14261 UpdateExpression.prototype.initialise = function initialise (transforms) {
14262 if (this.argument.type === 'Identifier') {
14263 var declaration = this.findScope(false).findDeclaration(
14264 this.argument.name
14265 );
14266 // special case – https://gitlab.com/Rich-Harris/buble/issues/150
14267 var statement = declaration && declaration.node.ancestor(3);
14268 if (
14269 statement &&
14270 statement.type === 'ForStatement' &&
14271 statement.body.contains(this)
14272 ) {
14273 statement.reassigned[this.argument.name] = true;
14274 }
14275 }
14276
14277 Node.prototype.initialise.call(this, transforms);
14278 };
14279
14280 UpdateExpression.prototype.transpile = function transpile (code, transforms) {
14281 if (this.argument.type === 'Identifier') {
14282 // Do this check after everything has been initialized to find
14283 // shadowing declarations after this expression
14284 checkConst(this.argument, this.findScope(false));
14285 }
14286 Node.prototype.transpile.call(this, code, transforms);
14287 };
14288
14289 return UpdateExpression;
14290}(Node$1));
14291
14292var VariableDeclaration = (function (Node) {
14293 function VariableDeclaration () {
14294 Node.apply(this, arguments);
14295 }
14296
14297 if ( Node ) VariableDeclaration.__proto__ = Node;
14298 VariableDeclaration.prototype = Object.create( Node && Node.prototype );
14299 VariableDeclaration.prototype.constructor = VariableDeclaration;
14300
14301 VariableDeclaration.prototype.initialise = function initialise (transforms) {
14302 this.scope = this.findScope(this.kind === 'var');
14303 this.declarations.forEach(function (declarator) { return declarator.initialise(transforms); });
14304 };
14305
14306 VariableDeclaration.prototype.transpile = function transpile (code, transforms) {
14307 var this$1 = this;
14308
14309 var i0 = this.getIndentation();
14310 var kind = this.kind;
14311
14312 if (transforms.letConst && kind !== 'var') {
14313 kind = 'var';
14314 code.overwrite(this.start, this.start + this.kind.length, kind, {
14315 storeName: true
14316 });
14317 }
14318
14319 if (transforms.destructuring && this.parent.type !== 'ForOfStatement' && this.parent.type !== 'ForInStatement') {
14320 var c = this.start;
14321 var lastDeclaratorIsPattern;
14322
14323 this.declarations.forEach(function (declarator, i) {
14324 declarator.transpile(code, transforms);
14325
14326 if (declarator.id.type === 'Identifier') {
14327 if (i > 0 && this$1.declarations[i - 1].id.type !== 'Identifier') {
14328 code.overwrite(c, declarator.id.start, "var ");
14329 }
14330 } else {
14331 var inline = loopStatement.test(this$1.parent.type);
14332
14333 if (i === 0) {
14334 code.remove(c, declarator.id.start);
14335 } else {
14336 code.overwrite(c, declarator.id.start, (";\n" + i0));
14337 }
14338
14339 var simple =
14340 declarator.init.type === 'Identifier' && !declarator.init.rewritten;
14341
14342 var name = simple
14343 ? (declarator.init.alias || declarator.init.name)
14344 : declarator.findScope(true).createIdentifier('ref');
14345
14346 c = declarator.start;
14347
14348 var statementGenerators = [];
14349
14350 if (simple) {
14351 code.remove(declarator.id.end, declarator.end);
14352 } else {
14353 statementGenerators.push(function (start, prefix, suffix) {
14354 code.prependRight(declarator.id.end, ("var " + name));
14355 code.appendLeft(declarator.init.end, ("" + suffix));
14356 code.move(declarator.id.end, declarator.end, start);
14357 });
14358 }
14359
14360 var scope = declarator.findScope(false);
14361 destructure(
14362 code,
14363 function (id) { return scope.createIdentifier(id); },
14364 function (ref) {
14365 var name = ref.name;
14366
14367 return scope.resolveName(name);
14368 },
14369 declarator.id,
14370 name,
14371 inline,
14372 statementGenerators
14373 );
14374
14375 var prefix = inline ? 'var ' : '';
14376 var suffix = inline ? ", " : (";\n" + i0);
14377 statementGenerators.forEach(function (fn, j) {
14378 if (
14379 i === this$1.declarations.length - 1 &&
14380 j === statementGenerators.length - 1
14381 ) {
14382 suffix = inline ? '' : ';';
14383 }
14384
14385 fn(declarator.start, j === 0 ? prefix : '', suffix);
14386 });
14387 }
14388
14389 c = declarator.end;
14390 lastDeclaratorIsPattern = declarator.id.type !== 'Identifier';
14391 });
14392
14393 if (lastDeclaratorIsPattern && this.end > c) {
14394 code.overwrite(c, this.end, '', { contentOnly: true });
14395 }
14396 } else {
14397 this.declarations.forEach(function (declarator) {
14398 declarator.transpile(code, transforms);
14399 });
14400 }
14401 };
14402
14403 return VariableDeclaration;
14404}(Node$1));
14405
14406var VariableDeclarator = (function (Node) {
14407 function VariableDeclarator () {
14408 Node.apply(this, arguments);
14409 }
14410
14411 if ( Node ) VariableDeclarator.__proto__ = Node;
14412 VariableDeclarator.prototype = Object.create( Node && Node.prototype );
14413 VariableDeclarator.prototype.constructor = VariableDeclarator;
14414
14415 VariableDeclarator.prototype.initialise = function initialise (transforms) {
14416 var kind = this.parent.kind;
14417 if (kind === 'let' && this.parent.parent.type === 'ForStatement') {
14418 kind = 'for.let'; // special case...
14419 }
14420
14421 this.parent.scope.addDeclaration(this.id, kind);
14422 Node.prototype.initialise.call(this, transforms);
14423 };
14424
14425 VariableDeclarator.prototype.transpile = function transpile (code, transforms) {
14426 if (!this.init && transforms.letConst && this.parent.kind !== 'var') {
14427 var inLoop = this.findNearest(
14428 /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/
14429 );
14430 if (
14431 inLoop &&
14432 !/Function/.test(inLoop.type) &&
14433 !this.isLeftDeclaratorOfLoop()
14434 ) {
14435 code.appendLeft(this.id.end, ' = (void 0)');
14436 }
14437 }
14438
14439 if (this.id) { this.id.transpile(code, transforms); }
14440 if (this.init) { this.init.transpile(code, transforms); }
14441 };
14442
14443 VariableDeclarator.prototype.isLeftDeclaratorOfLoop = function isLeftDeclaratorOfLoop () {
14444 return (
14445 this.parent &&
14446 this.parent.type === 'VariableDeclaration' &&
14447 this.parent.parent &&
14448 (this.parent.parent.type === 'ForInStatement' ||
14449 this.parent.parent.type === 'ForOfStatement') &&
14450 this.parent.parent.left &&
14451 this.parent.parent.left.declarations[0] === this
14452 );
14453 };
14454
14455 return VariableDeclarator;
14456}(Node$1));
14457
14458var types$2 = {
14459 ArrayExpression: ArrayExpression,
14460 ArrowFunctionExpression: ArrowFunctionExpression,
14461 AssignmentExpression: AssignmentExpression,
14462 BinaryExpression: BinaryExpression,
14463 BreakStatement: BreakStatement,
14464 CallExpression: CallExpression,
14465 ClassBody: ClassBody,
14466 ClassDeclaration: ClassDeclaration,
14467 ClassExpression: ClassExpression,
14468 ContinueStatement: ContinueStatement,
14469 DoWhileStatement: LoopStatement,
14470 ExportNamedDeclaration: ExportNamedDeclaration,
14471 ExportDefaultDeclaration: ExportDefaultDeclaration,
14472 ForStatement: ForStatement,
14473 ForInStatement: ForInStatement,
14474 ForOfStatement: ForOfStatement,
14475 FunctionDeclaration: FunctionDeclaration,
14476 FunctionExpression: FunctionExpression,
14477 Identifier: Identifier,
14478 IfStatement: IfStatement,
14479 ImportDeclaration: ImportDeclaration,
14480 ImportDefaultSpecifier: ImportDefaultSpecifier,
14481 ImportSpecifier: ImportSpecifier,
14482 JSXAttribute: JSXAttribute,
14483 JSXClosingElement: JSXClosingElement,
14484 JSXClosingFragment: JSXClosingFragment,
14485 JSXElement: JSXElement,
14486 JSXExpressionContainer: JSXExpressionContainer,
14487 JSXFragment: JSXFragment,
14488 JSXOpeningElement: JSXOpeningElement,
14489 JSXOpeningFragment: JSXOpeningFragment,
14490 JSXSpreadAttribute: JSXSpreadAttribute,
14491 Literal: Literal,
14492 MemberExpression: MemberExpression,
14493 NewExpression: NewExpression,
14494 ObjectExpression: ObjectExpression,
14495 Property: Property,
14496 ReturnStatement: ReturnStatement,
14497 SpreadElement: SpreadElement,
14498 Super: Super,
14499 TaggedTemplateExpression: TaggedTemplateExpression,
14500 TemplateElement: TemplateElement,
14501 TemplateLiteral: TemplateLiteral,
14502 ThisExpression: ThisExpression,
14503 UpdateExpression: UpdateExpression,
14504 VariableDeclaration: VariableDeclaration,
14505 VariableDeclarator: VariableDeclarator,
14506 WhileStatement: LoopStatement
14507};
14508
14509var keys = {
14510 Program: ['body'],
14511 Literal: []
14512};
14513
14514var statementsWithBlocks = {
14515 IfStatement: 'consequent',
14516 ForStatement: 'body',
14517 ForInStatement: 'body',
14518 ForOfStatement: 'body',
14519 WhileStatement: 'body',
14520 DoWhileStatement: 'body',
14521 ArrowFunctionExpression: 'body'
14522};
14523
14524function wrap(raw, parent) {
14525 if (!raw) { return; }
14526
14527 if ('length' in raw) {
14528 var i = raw.length;
14529 while (i--) { wrap(raw[i], parent); }
14530 return;
14531 }
14532
14533 // with e.g. shorthand properties, key and value are
14534 // the same node. We don't want to wrap an object twice
14535 if (raw.__wrapped) { return; }
14536 raw.__wrapped = true;
14537
14538 if (!keys[raw.type]) {
14539 keys[raw.type] = Object.keys(raw).filter(
14540 function (key) { return typeof raw[key] === 'object'; }
14541 );
14542 }
14543
14544 // special case – body-less if/for/while statements. TODO others?
14545 var bodyType = statementsWithBlocks[raw.type];
14546 if (bodyType && raw[bodyType].type !== 'BlockStatement') {
14547 var expression = raw[bodyType];
14548
14549 // create a synthetic block statement, otherwise all hell
14550 // breaks loose when it comes to block scoping
14551 raw[bodyType] = {
14552 start: expression.start,
14553 end: expression.end,
14554 type: 'BlockStatement',
14555 body: [expression],
14556 synthetic: true
14557 };
14558 }
14559
14560 raw.parent = parent;
14561 raw.program = parent.program || parent;
14562 raw.depth = parent.depth + 1;
14563 raw.keys = keys[raw.type];
14564 raw.indentation = undefined;
14565
14566 for (var i$1 = 0, list = keys[raw.type]; i$1 < list.length; i$1 += 1) {
14567 var key = list[i$1];
14568
14569 wrap(raw[key], raw);
14570 }
14571
14572 raw.program.magicString.addSourcemapLocation(raw.start);
14573 raw.program.magicString.addSourcemapLocation(raw.end);
14574
14575 var type =
14576 (raw.type === 'BlockStatement' ? BlockStatement : types$2[raw.type]) || Node$1;
14577 raw.__proto__ = type.prototype;
14578}
14579
14580function Program(source, ast, transforms, options) {
14581 var this$1 = this;
14582
14583 this.type = 'Root';
14584
14585 // options
14586 this.jsx = options.jsx || 'React.createElement';
14587 this.options = options;
14588
14589 this.source = source;
14590 this.magicString = new MagicString$1(source);
14591
14592 this.ast = ast;
14593 this.depth = 0;
14594
14595 wrap((this.body = ast), this);
14596 this.body.__proto__ = BlockStatement.prototype;
14597
14598 this.templateLiteralQuasis = Object.create(null);
14599 for (var i = 0; i < this.body.body.length; ++i) {
14600 if (!this$1.body.body[i].directive) {
14601 this$1.prependAt = this$1.body.body[i].start;
14602 break;
14603 }
14604 }
14605 this.objectWithoutPropertiesHelper = null;
14606
14607 this.indentExclusionElements = [];
14608 this.body.initialise(transforms);
14609
14610 this.indentExclusions = Object.create(null);
14611 for (var i$2 = 0, list = this$1.indentExclusionElements; i$2 < list.length; i$2 += 1) {
14612 var node = list[i$2];
14613
14614 for (var i$1 = node.start; i$1 < node.end; i$1 += 1) {
14615 this$1.indentExclusions[i$1] = true;
14616 }
14617 }
14618
14619 this.body.transpile(this.magicString, transforms);
14620}
14621
14622Program.prototype = {
14623 export: function export$1(options) {
14624 if ( options === void 0 ) options = {};
14625
14626 return {
14627 code: this.magicString.toString(),
14628 map: this.magicString.generateMap({
14629 file: options.file,
14630 source: options.source,
14631 includeContent: options.includeContent !== false
14632 })
14633 };
14634 },
14635
14636 findNearest: function findNearest() {
14637 return null;
14638 },
14639
14640 findScope: function findScope() {
14641 return null;
14642 },
14643
14644 getObjectWithoutPropertiesHelper: function getObjectWithoutPropertiesHelper(code) {
14645 if (!this.objectWithoutPropertiesHelper) {
14646 this.objectWithoutPropertiesHelper = this.body.scope.createIdentifier('objectWithoutProperties');
14647 code.prependLeft(this.prependAt, "function " + (this.objectWithoutPropertiesHelper) + " (obj, exclude) { " +
14648 "var target = {}; for (var k in obj) " +
14649 "if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) " +
14650 "target[k] = obj[k]; return target; }\n"
14651 );
14652 }
14653 return this.objectWithoutPropertiesHelper;
14654 }
14655};
14656
14657var matrix = {
14658 chrome: {
14659 48: 305357,
14660 49: 326143,
14661 50: 391679,
14662 51: 391679,
14663 52: 522751,
14664 53: 522751,
14665 54: 522751,
14666 55: 522751,
14667 56: 522751,
14668 57: 522751,
14669 58: 1047039,
14670 59: 1047039,
14671 60: 1047039,
14672 61: 1047039,
14673 62: 1047039,
14674 63: 1047039
14675 },
14676 firefox: {
14677 43: 325853,
14678 44: 326109,
14679 45: 326111,
14680 46: 391647,
14681 47: 391679,
14682 48: 391679,
14683 49: 387583,
14684 50: 387583,
14685 51: 387583,
14686 52: 1047039,
14687 53: 1047039,
14688 54: 1047039,
14689 55: 1047039,
14690 56: 1047039,
14691 57: 1047039,
14692 58: 1047039
14693 },
14694 safari: {
14695 8: 262148,
14696 9: 301166,
14697 10: 915967,
14698 '10.1': 1047039,
14699 11: 1047039
14700 },
14701 ie: {
14702 8: 0,
14703 9: 262144,
14704 10: 262144,
14705 11: 262400
14706 },
14707 edge: {
14708 12: 305485,
14709 13: 387535,
14710 14: 1042943,
14711 15: 1042943,
14712 16: 1042943
14713 },
14714 node: {
14715 '0.10': 262144,
14716 '0.12': 262208,
14717 4: 297167,
14718 5: 297167,
14719 6: 391679,
14720 8: 1047039,
14721 '8.3': 1047039,
14722 '8.7': 1047039
14723 }
14724};
14725
14726var features = [
14727 'arrow',
14728 'classes',
14729 'computedProperty',
14730 'conciseMethodProperty',
14731 'defaultParameter',
14732 'destructuring',
14733 'forOf',
14734 'generator',
14735 'letConst',
14736 'moduleExport',
14737 'moduleImport',
14738 'numericLiteral',
14739 'parameterDestructuring',
14740 'spreadRest',
14741 'stickyRegExp',
14742 'templateString',
14743 'unicodeRegExp',
14744
14745 // ES2016
14746 'exponentiation',
14747
14748 // additional transforms, not from
14749 // https://featuretests.io
14750 'reservedProperties',
14751
14752 'trailingFunctionCommas'
14753];
14754
14755var version$1 = "0.19.3";
14756
14757var ref$1 = [inject, acornDynamicImport].reduce(
14758 function (final, plugin) { return plugin(final); },
14759 acorn
14760);
14761var parse$1 = ref$1.parse;
14762
14763var dangerousTransforms = ['dangerousTaggedTemplateString', 'dangerousForOf'];
14764
14765function target(target) {
14766 var targets = Object.keys(target);
14767 var bitmask = targets.length
14768 ? 1048575
14769 : 262144;
14770
14771 Object.keys(target).forEach(function (environment) {
14772 var versions = matrix[environment];
14773 if (!versions)
14774 { throw new Error(
14775 ("Unknown environment '" + environment + "'. Please raise an issue at https://github.com/Rich-Harris/buble/issues")
14776 ); }
14777
14778 var targetVersion = target[environment];
14779 if (!(targetVersion in versions))
14780 { throw new Error(
14781 ("Support data exists for the following versions of " + environment + ": " + (Object.keys(
14782 versions
14783 ).join(
14784 ', '
14785 )) + ". Please raise an issue at https://github.com/Rich-Harris/buble/issues")
14786 ); }
14787 var support = versions[targetVersion];
14788
14789 bitmask &= support;
14790 });
14791
14792 var transforms = Object.create(null);
14793 features.forEach(function (name, i) {
14794 transforms[name] = !(bitmask & (1 << i));
14795 });
14796
14797 dangerousTransforms.forEach(function (name) {
14798 transforms[name] = false;
14799 });
14800
14801 return transforms;
14802}
14803
14804function transform(source, options) {
14805 if ( options === void 0 ) options = {};
14806
14807 var ast;
14808 var jsx = null;
14809
14810 try {
14811 ast = parse$1(source, {
14812 ecmaVersion: 9,
14813 preserveParens: true,
14814 sourceType: 'module',
14815 onComment: function (block, text) {
14816 if (!jsx) {
14817 var match = /@jsx\s+([^\s]+)/.exec(text);
14818 if (match) { jsx = match[1]; }
14819 }
14820 },
14821 plugins: {
14822 jsx: true,
14823 dynamicImport: true
14824 }
14825 });
14826 options.jsx = jsx || options.jsx;
14827 } catch (err) {
14828 err.snippet = getSnippet(source, err.loc);
14829 err.toString = function () { return ((err.name) + ": " + (err.message) + "\n" + (err.snippet)); };
14830 throw err;
14831 }
14832
14833 var transforms = target(options.target || {});
14834 Object.keys(options.transforms || {}).forEach(function (name) {
14835 if (name === 'modules') {
14836 if (!('moduleImport' in options.transforms))
14837 { transforms.moduleImport = options.transforms.modules; }
14838 if (!('moduleExport' in options.transforms))
14839 { transforms.moduleExport = options.transforms.modules; }
14840 return;
14841 }
14842
14843 if (!(name in transforms)) { throw new Error(("Unknown transform '" + name + "'")); }
14844 transforms[name] = options.transforms[name];
14845 });
14846
14847 return new Program(source, ast, transforms, options).export(options);
14848}
14849
14850exports.target = target;
14851exports.transform = transform;
14852exports.VERSION = version$1;
14853
14854Object.defineProperty(exports, '__esModule', { value: true });
14855
14856})));
14857//# sourceMappingURL=buble-browser-deps.umd.js.map