UNPKG

430 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
26// ## Character categories
27
28// Big ugly regular expressions that match characters in the
29// whitespace, identifier, and identifier-start categories. These
30// are only applied when a character is found to actually have a
31// code point above 128.
32// Generated by `bin/generate-identifier-regex.js`.
33
34var 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";
35var 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";
36
37var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
38var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
39
40nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
41
42// These are a run-length and offset encoded representation of the
43// >0xffff code points that are a valid part of identifiers. The
44// offset starts at 0x10000, and each pair of numbers represents an
45// offset to the next range, and then a size of the range. They were
46// generated by bin/generate-identifier-regex.js
47
48// eslint-disable-next-line comma-spacing
49var 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];
50
51// eslint-disable-next-line comma-spacing
52var 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];
53
54// This has a complexity linear to the value of the code. The
55// assumption is that looking up astral identifier characters is
56// rare.
57function isInAstralSet(code, set) {
58 var pos = 0x10000;
59 for (var i = 0; i < set.length; i += 2) {
60 pos += set[i];
61 if (pos > code) { return false }
62 pos += set[i + 1];
63 if (pos >= code) { return true }
64 }
65}
66
67// Test whether a given character code starts an identifier.
68
69function isIdentifierStart(code, astral) {
70 if (code < 65) { return code === 36 }
71 if (code < 91) { return true }
72 if (code < 97) { return code === 95 }
73 if (code < 123) { return true }
74 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
75 if (astral === false) { return false }
76 return isInAstralSet(code, astralIdentifierStartCodes)
77}
78
79// Test whether a given character is part of an identifier.
80
81function isIdentifierChar(code, astral) {
82 if (code < 48) { return code === 36 }
83 if (code < 58) { return true }
84 if (code < 65) { return false }
85 if (code < 91) { return true }
86 if (code < 97) { return code === 95 }
87 if (code < 123) { return true }
88 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
89 if (astral === false) { return false }
90 return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
91}
92
93// ## Token types
94
95// The assignment of fine-grained, information-carrying type objects
96// allows the tokenizer to store the information it has about a
97// token in a way that is very cheap for the parser to look up.
98
99// All token type variables start with an underscore, to make them
100// easy to recognize.
101
102// The `beforeExpr` property is used to disambiguate between regular
103// expressions and divisions. It is set on all token types that can
104// be followed by an expression (thus, a slash after them would be a
105// regular expression).
106//
107// The `startsExpr` property is used to check if the token ends a
108// `yield` expression. It is set on all token types that either can
109// directly start an expression (like a quotation mark) or can
110// continue an expression (like the body of a string).
111//
112// `isLoop` marks a keyword as starting a loop, which is important
113// to know when parsing a label, in order to allow or disallow
114// continue jumps to that label.
115
116var TokenType = function TokenType(label, conf) {
117 if ( conf === void 0 ) conf = {};
118
119 this.label = label;
120 this.keyword = conf.keyword;
121 this.beforeExpr = !!conf.beforeExpr;
122 this.startsExpr = !!conf.startsExpr;
123 this.isLoop = !!conf.isLoop;
124 this.isAssign = !!conf.isAssign;
125 this.prefix = !!conf.prefix;
126 this.postfix = !!conf.postfix;
127 this.binop = conf.binop || null;
128 this.updateContext = null;
129};
130
131function binop(name, prec) {
132 return new TokenType(name, {beforeExpr: true, binop: prec})
133}
134var beforeExpr = {beforeExpr: true};
135var startsExpr = {startsExpr: true};
136
137// Map keyword names to token types.
138
139var keywords$1 = {};
140
141// Succinct definitions of keyword token types
142function kw(name, options) {
143 if ( options === void 0 ) options = {};
144
145 options.keyword = name;
146 return keywords$1[name] = new TokenType(name, options)
147}
148
149var types = {
150 num: new TokenType("num", startsExpr),
151 regexp: new TokenType("regexp", startsExpr),
152 string: new TokenType("string", startsExpr),
153 name: new TokenType("name", startsExpr),
154 eof: new TokenType("eof"),
155
156 // Punctuation token types.
157 bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
158 bracketR: new TokenType("]"),
159 braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
160 braceR: new TokenType("}"),
161 parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
162 parenR: new TokenType(")"),
163 comma: new TokenType(",", beforeExpr),
164 semi: new TokenType(";", beforeExpr),
165 colon: new TokenType(":", beforeExpr),
166 dot: new TokenType("."),
167 question: new TokenType("?", beforeExpr),
168 arrow: new TokenType("=>", beforeExpr),
169 template: new TokenType("template"),
170 invalidTemplate: new TokenType("invalidTemplate"),
171 ellipsis: new TokenType("...", beforeExpr),
172 backQuote: new TokenType("`", startsExpr),
173 dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
174
175 // Operators. These carry several kinds of properties to help the
176 // parser use them properly (the presence of these properties is
177 // what categorizes them as operators).
178 //
179 // `binop`, when present, specifies that this operator is a binary
180 // operator, and will refer to its precedence.
181 //
182 // `prefix` and `postfix` mark the operator as a prefix or postfix
183 // unary operator.
184 //
185 // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
186 // binary operators with a very low precedence, that should result
187 // in AssignmentExpression nodes.
188
189 eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
190 assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
191 incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
192 prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
193 logicalOR: binop("||", 1),
194 logicalAND: binop("&&", 2),
195 bitwiseOR: binop("|", 3),
196 bitwiseXOR: binop("^", 4),
197 bitwiseAND: binop("&", 5),
198 equality: binop("==/!=/===/!==", 6),
199 relational: binop("</>/<=/>=", 7),
200 bitShift: binop("<</>>/>>>", 8),
201 plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
202 modulo: binop("%", 10),
203 star: binop("*", 10),
204 slash: binop("/", 10),
205 starstar: new TokenType("**", {beforeExpr: true}),
206
207 // Keyword token types.
208 _break: kw("break"),
209 _case: kw("case", beforeExpr),
210 _catch: kw("catch"),
211 _continue: kw("continue"),
212 _debugger: kw("debugger"),
213 _default: kw("default", beforeExpr),
214 _do: kw("do", {isLoop: true, beforeExpr: true}),
215 _else: kw("else", beforeExpr),
216 _finally: kw("finally"),
217 _for: kw("for", {isLoop: true}),
218 _function: kw("function", startsExpr),
219 _if: kw("if"),
220 _return: kw("return", beforeExpr),
221 _switch: kw("switch"),
222 _throw: kw("throw", beforeExpr),
223 _try: kw("try"),
224 _var: kw("var"),
225 _const: kw("const"),
226 _while: kw("while", {isLoop: true}),
227 _with: kw("with"),
228 _new: kw("new", {beforeExpr: true, startsExpr: true}),
229 _this: kw("this", startsExpr),
230 _super: kw("super", startsExpr),
231 _class: kw("class", startsExpr),
232 _extends: kw("extends", beforeExpr),
233 _export: kw("export"),
234 _import: kw("import"),
235 _null: kw("null", startsExpr),
236 _true: kw("true", startsExpr),
237 _false: kw("false", startsExpr),
238 _in: kw("in", {beforeExpr: true, binop: 7}),
239 _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
240 _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
241 _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
242 _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
243};
244
245// Matches a whole line break (where CRLF is considered a single
246// line break). Used to count lines.
247
248var lineBreak = /\r\n?|\n|\u2028|\u2029/;
249var lineBreakG = new RegExp(lineBreak.source, "g");
250
251function isNewLine(code) {
252 return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
253}
254
255var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
256
257var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
258
259var ref$1 = Object.prototype;
260var hasOwnProperty = ref$1.hasOwnProperty;
261var toString = ref$1.toString;
262
263// Checks if an object has a property.
264
265function has(obj, propName) {
266 return hasOwnProperty.call(obj, propName)
267}
268
269var isArray = Array.isArray || (function (obj) { return (
270 toString.call(obj) === "[object Array]"
271); });
272
273// These are used when `options.locations` is on, for the
274// `startLoc` and `endLoc` properties.
275
276var Position = function Position(line, col) {
277 this.line = line;
278 this.column = col;
279};
280
281Position.prototype.offset = function offset (n) {
282 return new Position(this.line, this.column + n)
283};
284
285var SourceLocation = function SourceLocation(p, start, end) {
286 this.start = start;
287 this.end = end;
288 if (p.sourceFile !== null) { this.source = p.sourceFile; }
289};
290
291// The `getLineInfo` function is mostly useful when the
292// `locations` option is off (for performance reasons) and you
293// want to find the line/column position for a given character
294// offset. `input` should be the code string that the offset refers
295// into.
296
297function getLineInfo(input, offset) {
298 for (var line = 1, cur = 0;;) {
299 lineBreakG.lastIndex = cur;
300 var match = lineBreakG.exec(input);
301 if (match && match.index < offset) {
302 ++line;
303 cur = match.index + match[0].length;
304 } else {
305 return new Position(line, offset - cur)
306 }
307 }
308}
309
310// A second optional argument can be given to further configure
311// the parser process. These options are recognized:
312
313var defaultOptions = {
314 // `ecmaVersion` indicates the ECMAScript version to parse. Must
315 // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
316 // for strict mode, the set of reserved words, and support for
317 // new syntax features. The default is 7.
318 ecmaVersion: 7,
319 // `sourceType` indicates the mode the code should be parsed in.
320 // Can be either `"script"` or `"module"`. This influences global
321 // strict mode and parsing of `import` and `export` declarations.
322 sourceType: "script",
323 // `onInsertedSemicolon` can be a callback that will be called
324 // when a semicolon is automatically inserted. It will be passed
325 // th position of the comma as an offset, and if `locations` is
326 // enabled, it is given the location as a `{line, column}` object
327 // as second argument.
328 onInsertedSemicolon: null,
329 // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
330 // trailing commas.
331 onTrailingComma: null,
332 // By default, reserved words are only enforced if ecmaVersion >= 5.
333 // Set `allowReserved` to a boolean value to explicitly turn this on
334 // an off. When this option has the value "never", reserved words
335 // and keywords can also not be used as property names.
336 allowReserved: null,
337 // When enabled, a return at the top level is not considered an
338 // error.
339 allowReturnOutsideFunction: false,
340 // When enabled, import/export statements are not constrained to
341 // appearing at the top of the program.
342 allowImportExportEverywhere: false,
343 // When enabled, hashbang directive in the beginning of file
344 // is allowed and treated as a line comment.
345 allowHashBang: false,
346 // When `locations` is on, `loc` properties holding objects with
347 // `start` and `end` properties in `{line, column}` form (with
348 // line being 1-based and column 0-based) will be attached to the
349 // nodes.
350 locations: false,
351 // A function can be passed as `onToken` option, which will
352 // cause Acorn to call that function with object in the same
353 // format as tokens returned from `tokenizer().getToken()`. Note
354 // that you are not allowed to call the parser from the
355 // callback—that will corrupt its internal state.
356 onToken: null,
357 // A function can be passed as `onComment` option, which will
358 // cause Acorn to call that function with `(block, text, start,
359 // end)` parameters whenever a comment is skipped. `block` is a
360 // boolean indicating whether this is a block (`/* */`) comment,
361 // `text` is the content of the comment, and `start` and `end` are
362 // character offsets that denote the start and end of the comment.
363 // When the `locations` option is on, two more parameters are
364 // passed, the full `{line, column}` locations of the start and
365 // end of the comments. Note that you are not allowed to call the
366 // parser from the callback—that will corrupt its internal state.
367 onComment: null,
368 // Nodes have their start and end characters offsets recorded in
369 // `start` and `end` properties (directly on the node, rather than
370 // the `loc` object, which holds line/column data. To also add a
371 // [semi-standardized][range] `range` property holding a `[start,
372 // end]` array with the same numbers, set the `ranges` option to
373 // `true`.
374 //
375 // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
376 ranges: false,
377 // It is possible to parse multiple files into a single AST by
378 // passing the tree produced by parsing the first file as
379 // `program` option in subsequent parses. This will add the
380 // toplevel forms of the parsed file to the `Program` (top) node
381 // of an existing parse tree.
382 program: null,
383 // When `locations` is on, you can pass this to record the source
384 // file in every node's `loc` object.
385 sourceFile: null,
386 // This value, if given, is stored in every node, whether
387 // `locations` is on or off.
388 directSourceFile: null,
389 // When enabled, parenthesized expressions are represented by
390 // (non-standard) ParenthesizedExpression nodes
391 preserveParens: false,
392 plugins: {}
393};
394
395// Interpret and default an options object
396
397function getOptions(opts) {
398 var options = {};
399
400 for (var opt in defaultOptions)
401 { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
402
403 if (options.ecmaVersion >= 2015)
404 { options.ecmaVersion -= 2009; }
405
406 if (options.allowReserved == null)
407 { options.allowReserved = options.ecmaVersion < 5; }
408
409 if (isArray(options.onToken)) {
410 var tokens = options.onToken;
411 options.onToken = function (token) { return tokens.push(token); };
412 }
413 if (isArray(options.onComment))
414 { options.onComment = pushComment(options, options.onComment); }
415
416 return options
417}
418
419function pushComment(options, array) {
420 return function(block, text, start, end, startLoc, endLoc) {
421 var comment = {
422 type: block ? "Block" : "Line",
423 value: text,
424 start: start,
425 end: end
426 };
427 if (options.locations)
428 { comment.loc = new SourceLocation(this, startLoc, endLoc); }
429 if (options.ranges)
430 { comment.range = [start, end]; }
431 array.push(comment);
432 }
433}
434
435// Registered plugins
436var plugins = {};
437
438function keywordRegexp(words) {
439 return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
440}
441
442var Parser = function Parser(options, input, startPos) {
443 this.options = options = getOptions(options);
444 this.sourceFile = options.sourceFile;
445 this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
446 var reserved = "";
447 if (!options.allowReserved) {
448 for (var v = options.ecmaVersion;; v--)
449 { if (reserved = reservedWords[v]) { break } }
450 if (options.sourceType == "module") { reserved += " await"; }
451 }
452 this.reservedWords = keywordRegexp(reserved);
453 var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
454 this.reservedWordsStrict = keywordRegexp(reservedStrict);
455 this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
456 this.input = String(input);
457
458 // Used to signal to callers of `readWord1` whether the word
459 // contained any escape sequences. This is needed because words with
460 // escape sequences must not be interpreted as keywords.
461 this.containsEsc = false;
462
463 // Load plugins
464 this.loadPlugins(options.plugins);
465
466 // Set up token state
467
468 // The current position of the tokenizer in the input.
469 if (startPos) {
470 this.pos = startPos;
471 this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
472 this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
473 } else {
474 this.pos = this.lineStart = 0;
475 this.curLine = 1;
476 }
477
478 // Properties of the current token:
479 // Its type
480 this.type = types.eof;
481 // For tokens that include more information than their type, the value
482 this.value = null;
483 // Its start and end offset
484 this.start = this.end = this.pos;
485 // And, if locations are used, the {line, column} object
486 // corresponding to those offsets
487 this.startLoc = this.endLoc = this.curPosition();
488
489 // Position information for the previous token
490 this.lastTokEndLoc = this.lastTokStartLoc = null;
491 this.lastTokStart = this.lastTokEnd = this.pos;
492
493 // The context stack is used to superficially track syntactic
494 // context to predict whether a regular expression is allowed in a
495 // given position.
496 this.context = this.initialContext();
497 this.exprAllowed = true;
498
499 // Figure out if it's a module code.
500 this.inModule = options.sourceType === "module";
501 this.strict = this.inModule || this.strictDirective(this.pos);
502
503 // Used to signify the start of a potential arrow function
504 this.potentialArrowAt = -1;
505
506 // Flags to track whether we are in a function, a generator, an async function.
507 this.inFunction = this.inGenerator = this.inAsync = false;
508 // Positions to delayed-check that yield/await does not exist in default parameters.
509 this.yieldPos = this.awaitPos = 0;
510 // Labels in scope.
511 this.labels = [];
512
513 // If enabled, skip leading hashbang line.
514 if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
515 { this.skipLineComment(2); }
516
517 // Scope tracking for duplicate variable names (see scope.js)
518 this.scopeStack = [];
519 this.enterFunctionScope();
520};
521
522// DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
523Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
524Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
525
526Parser.prototype.extend = function extend (name, f) {
527 this[name] = f(this[name]);
528};
529
530Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
531 var this$1 = this;
532
533 for (var name in pluginConfigs) {
534 var plugin = plugins[name];
535 if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
536 plugin(this$1, pluginConfigs[name]);
537 }
538};
539
540Parser.prototype.parse = function parse () {
541 var node = this.options.program || this.startNode();
542 this.nextToken();
543 return this.parseTopLevel(node)
544};
545
546var pp = Parser.prototype;
547
548// ## Parser utilities
549
550var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
551pp.strictDirective = function(start) {
552 var this$1 = this;
553
554 for (;;) {
555 skipWhiteSpace.lastIndex = start;
556 start += skipWhiteSpace.exec(this$1.input)[0].length;
557 var match = literal.exec(this$1.input.slice(start));
558 if (!match) { return false }
559 if ((match[1] || match[2]) == "use strict") { return true }
560 start += match[0].length;
561 }
562};
563
564// Predicate that tests whether the next token is of the given
565// type, and if yes, consumes it as a side effect.
566
567pp.eat = function(type) {
568 if (this.type === type) {
569 this.next();
570 return true
571 } else {
572 return false
573 }
574};
575
576// Tests whether parsed token is a contextual keyword.
577
578pp.isContextual = function(name) {
579 return this.type === types.name && this.value === name
580};
581
582// Consumes contextual keyword if possible.
583
584pp.eatContextual = function(name) {
585 return this.value === name && this.eat(types.name)
586};
587
588// Asserts that following token is given contextual keyword.
589
590pp.expectContextual = function(name) {
591 if (!this.eatContextual(name)) { this.unexpected(); }
592};
593
594// Test whether a semicolon can be inserted at the current position.
595
596pp.canInsertSemicolon = function() {
597 return this.type === types.eof ||
598 this.type === types.braceR ||
599 lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
600};
601
602pp.insertSemicolon = function() {
603 if (this.canInsertSemicolon()) {
604 if (this.options.onInsertedSemicolon)
605 { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
606 return true
607 }
608};
609
610// Consume a semicolon, or, failing that, see if we are allowed to
611// pretend that there is a semicolon at this position.
612
613pp.semicolon = function() {
614 if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
615};
616
617pp.afterTrailingComma = function(tokType, notNext) {
618 if (this.type == tokType) {
619 if (this.options.onTrailingComma)
620 { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
621 if (!notNext)
622 { this.next(); }
623 return true
624 }
625};
626
627// Expect a token of a given type. If found, consume it, otherwise,
628// raise an unexpected token error.
629
630pp.expect = function(type) {
631 this.eat(type) || this.unexpected();
632};
633
634// Raise an unexpected token error.
635
636pp.unexpected = function(pos) {
637 this.raise(pos != null ? pos : this.start, "Unexpected token");
638};
639
640function DestructuringErrors() {
641 this.shorthandAssign =
642 this.trailingComma =
643 this.parenthesizedAssign =
644 this.parenthesizedBind =
645 -1;
646}
647
648pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
649 if (!refDestructuringErrors) { return }
650 if (refDestructuringErrors.trailingComma > -1)
651 { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
652 var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
653 if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
654};
655
656pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
657 var pos = refDestructuringErrors ? refDestructuringErrors.shorthandAssign : -1;
658 if (!andThrow) { return pos >= 0 }
659 if (pos > -1) { this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns"); }
660};
661
662pp.checkYieldAwaitInDefaultParams = function() {
663 if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
664 { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
665 if (this.awaitPos)
666 { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
667};
668
669pp.isSimpleAssignTarget = function(expr) {
670 if (expr.type === "ParenthesizedExpression")
671 { return this.isSimpleAssignTarget(expr.expression) }
672 return expr.type === "Identifier" || expr.type === "MemberExpression"
673};
674
675var pp$1 = Parser.prototype;
676
677// ### Statement parsing
678
679// Parse a program. Initializes the parser, reads any number of
680// statements, and wraps them in a Program node. Optionally takes a
681// `program` argument. If present, the statements will be appended
682// to its body instead of creating a new node.
683
684pp$1.parseTopLevel = function(node) {
685 var this$1 = this;
686
687 var exports = {};
688 if (!node.body) { node.body = []; }
689 while (this.type !== types.eof) {
690 var stmt = this$1.parseStatement(true, true, exports);
691 node.body.push(stmt);
692 }
693 this.next();
694 if (this.options.ecmaVersion >= 6) {
695 node.sourceType = this.options.sourceType;
696 }
697 return this.finishNode(node, "Program")
698};
699
700var loopLabel = {kind: "loop"};
701var switchLabel = {kind: "switch"};
702
703pp$1.isLet = function() {
704 if (this.type !== types.name || this.options.ecmaVersion < 6 || this.value != "let") { return false }
705 skipWhiteSpace.lastIndex = this.pos;
706 var skip = skipWhiteSpace.exec(this.input);
707 var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
708 if (nextCh === 91 || nextCh == 123) { return true } // '{' and '['
709 if (isIdentifierStart(nextCh, true)) {
710 var pos = next + 1;
711 while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
712 var ident = this.input.slice(next, pos);
713 if (!this.isKeyword(ident)) { return true }
714 }
715 return false
716};
717
718// check 'async [no LineTerminator here] function'
719// - 'async /*foo*/ function' is OK.
720// - 'async /*\n*/ function' is invalid.
721pp$1.isAsyncFunction = function() {
722 if (this.type !== types.name || this.options.ecmaVersion < 8 || this.value != "async")
723 { return false }
724
725 skipWhiteSpace.lastIndex = this.pos;
726 var skip = skipWhiteSpace.exec(this.input);
727 var next = this.pos + skip[0].length;
728 return !lineBreak.test(this.input.slice(this.pos, next)) &&
729 this.input.slice(next, next + 8) === "function" &&
730 (next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
731};
732
733// Parse a single statement.
734//
735// If expecting a statement and finding a slash operator, parse a
736// regular expression literal. This is to handle cases like
737// `if (foo) /blah/.exec(foo)`, where looking at the previous token
738// does not help.
739
740pp$1.parseStatement = function(declaration, topLevel, exports) {
741 var starttype = this.type, node = this.startNode(), kind;
742
743 if (this.isLet()) {
744 starttype = types._var;
745 kind = "let";
746 }
747
748 // Most types of statements are recognized by the keyword they
749 // start with. Many are trivial to parse, some require a bit of
750 // complexity.
751
752 switch (starttype) {
753 case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
754 case types._debugger: return this.parseDebuggerStatement(node)
755 case types._do: return this.parseDoStatement(node)
756 case types._for: return this.parseForStatement(node)
757 case types._function:
758 if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
759 return this.parseFunctionStatement(node, false)
760 case types._class:
761 if (!declaration) { this.unexpected(); }
762 return this.parseClass(node, true)
763 case types._if: return this.parseIfStatement(node)
764 case types._return: return this.parseReturnStatement(node)
765 case types._switch: return this.parseSwitchStatement(node)
766 case types._throw: return this.parseThrowStatement(node)
767 case types._try: return this.parseTryStatement(node)
768 case types._const: case types._var:
769 kind = kind || this.value;
770 if (!declaration && kind != "var") { this.unexpected(); }
771 return this.parseVarStatement(node, kind)
772 case types._while: return this.parseWhileStatement(node)
773 case types._with: return this.parseWithStatement(node)
774 case types.braceL: return this.parseBlock()
775 case types.semi: return this.parseEmptyStatement(node)
776 case types._export:
777 case types._import:
778 if (!this.options.allowImportExportEverywhere) {
779 if (!topLevel)
780 { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
781 if (!this.inModule)
782 { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
783 }
784 return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
785
786 // If the statement does not start with a statement keyword or a
787 // brace, it's an ExpressionStatement or LabeledStatement. We
788 // simply start parsing an expression, and afterwards, if the
789 // next token is a colon and the expression was a simple
790 // Identifier node, we switch to interpreting it as a label.
791 default:
792 if (this.isAsyncFunction() && declaration) {
793 this.next();
794 return this.parseFunctionStatement(node, true)
795 }
796
797 var maybeName = this.value, expr = this.parseExpression();
798 if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
799 { return this.parseLabeledStatement(node, maybeName, expr) }
800 else { return this.parseExpressionStatement(node, expr) }
801 }
802};
803
804pp$1.parseBreakContinueStatement = function(node, keyword) {
805 var this$1 = this;
806
807 var isBreak = keyword == "break";
808 this.next();
809 if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
810 else if (this.type !== types.name) { this.unexpected(); }
811 else {
812 node.label = this.parseIdent();
813 this.semicolon();
814 }
815
816 // Verify that there is an actual destination to break or
817 // continue to.
818 var i = 0;
819 for (; i < this.labels.length; ++i) {
820 var lab = this$1.labels[i];
821 if (node.label == null || lab.name === node.label.name) {
822 if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
823 if (node.label && isBreak) { break }
824 }
825 }
826 if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
827 return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
828};
829
830pp$1.parseDebuggerStatement = function(node) {
831 this.next();
832 this.semicolon();
833 return this.finishNode(node, "DebuggerStatement")
834};
835
836pp$1.parseDoStatement = function(node) {
837 this.next();
838 this.labels.push(loopLabel);
839 node.body = this.parseStatement(false);
840 this.labels.pop();
841 this.expect(types._while);
842 node.test = this.parseParenExpression();
843 if (this.options.ecmaVersion >= 6)
844 { this.eat(types.semi); }
845 else
846 { this.semicolon(); }
847 return this.finishNode(node, "DoWhileStatement")
848};
849
850// Disambiguating between a `for` and a `for`/`in` or `for`/`of`
851// loop is non-trivial. Basically, we have to parse the init `var`
852// statement or expression, disallowing the `in` operator (see
853// the second parameter to `parseExpression`), and then check
854// whether the next token is `in` or `of`. When there is no init
855// part (semicolon immediately after the opening parenthesis), it
856// is a regular `for` loop.
857
858pp$1.parseForStatement = function(node) {
859 this.next();
860 this.labels.push(loopLabel);
861 this.enterLexicalScope();
862 this.expect(types.parenL);
863 if (this.type === types.semi) { return this.parseFor(node, null) }
864 var isLet = this.isLet();
865 if (this.type === types._var || this.type === types._const || isLet) {
866 var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
867 this.next();
868 this.parseVar(init$1, true, kind);
869 this.finishNode(init$1, "VariableDeclaration");
870 if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
871 !(kind !== "var" && init$1.declarations[0].init))
872 { return this.parseForIn(node, init$1) }
873 return this.parseFor(node, init$1)
874 }
875 var refDestructuringErrors = new DestructuringErrors;
876 var init = this.parseExpression(true, refDestructuringErrors);
877 if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
878 this.toAssignable(init);
879 this.checkLVal(init);
880 this.checkPatternErrors(refDestructuringErrors, true);
881 return this.parseForIn(node, init)
882 } else {
883 this.checkExpressionErrors(refDestructuringErrors, true);
884 }
885 return this.parseFor(node, init)
886};
887
888pp$1.parseFunctionStatement = function(node, isAsync) {
889 this.next();
890 return this.parseFunction(node, true, false, isAsync)
891};
892
893pp$1.isFunction = function() {
894 return this.type === types._function || this.isAsyncFunction()
895};
896
897pp$1.parseIfStatement = function(node) {
898 this.next();
899 node.test = this.parseParenExpression();
900 // allow function declarations in branches, but only in non-strict mode
901 node.consequent = this.parseStatement(!this.strict && this.isFunction());
902 node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.isFunction()) : null;
903 return this.finishNode(node, "IfStatement")
904};
905
906pp$1.parseReturnStatement = function(node) {
907 if (!this.inFunction && !this.options.allowReturnOutsideFunction)
908 { this.raise(this.start, "'return' outside of function"); }
909 this.next();
910
911 // In `return` (and `break`/`continue`), the keywords with
912 // optional arguments, we eagerly look for a semicolon or the
913 // possibility to insert one.
914
915 if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
916 else { node.argument = this.parseExpression(); this.semicolon(); }
917 return this.finishNode(node, "ReturnStatement")
918};
919
920pp$1.parseSwitchStatement = function(node) {
921 var this$1 = this;
922
923 this.next();
924 node.discriminant = this.parseParenExpression();
925 node.cases = [];
926 this.expect(types.braceL);
927 this.labels.push(switchLabel);
928 this.enterLexicalScope();
929
930 // Statements under must be grouped (by label) in SwitchCase
931 // nodes. `cur` is used to keep the node that we are currently
932 // adding statements to.
933
934 var cur;
935 for (var sawDefault = false; this.type != types.braceR;) {
936 if (this$1.type === types._case || this$1.type === types._default) {
937 var isCase = this$1.type === types._case;
938 if (cur) { this$1.finishNode(cur, "SwitchCase"); }
939 node.cases.push(cur = this$1.startNode());
940 cur.consequent = [];
941 this$1.next();
942 if (isCase) {
943 cur.test = this$1.parseExpression();
944 } else {
945 if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
946 sawDefault = true;
947 cur.test = null;
948 }
949 this$1.expect(types.colon);
950 } else {
951 if (!cur) { this$1.unexpected(); }
952 cur.consequent.push(this$1.parseStatement(true));
953 }
954 }
955 this.exitLexicalScope();
956 if (cur) { this.finishNode(cur, "SwitchCase"); }
957 this.next(); // Closing brace
958 this.labels.pop();
959 return this.finishNode(node, "SwitchStatement")
960};
961
962pp$1.parseThrowStatement = function(node) {
963 this.next();
964 if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
965 { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
966 node.argument = this.parseExpression();
967 this.semicolon();
968 return this.finishNode(node, "ThrowStatement")
969};
970
971// Reused empty array added for node fields that are always empty.
972
973var empty = [];
974
975pp$1.parseTryStatement = function(node) {
976 this.next();
977 node.block = this.parseBlock();
978 node.handler = null;
979 if (this.type === types._catch) {
980 var clause = this.startNode();
981 this.next();
982 this.expect(types.parenL);
983 clause.param = this.parseBindingAtom();
984 this.enterLexicalScope();
985 this.checkLVal(clause.param, "let");
986 this.expect(types.parenR);
987 clause.body = this.parseBlock(false);
988 this.exitLexicalScope();
989 node.handler = this.finishNode(clause, "CatchClause");
990 }
991 node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
992 if (!node.handler && !node.finalizer)
993 { this.raise(node.start, "Missing catch or finally clause"); }
994 return this.finishNode(node, "TryStatement")
995};
996
997pp$1.parseVarStatement = function(node, kind) {
998 this.next();
999 this.parseVar(node, false, kind);
1000 this.semicolon();
1001 return this.finishNode(node, "VariableDeclaration")
1002};
1003
1004pp$1.parseWhileStatement = function(node) {
1005 this.next();
1006 node.test = this.parseParenExpression();
1007 this.labels.push(loopLabel);
1008 node.body = this.parseStatement(false);
1009 this.labels.pop();
1010 return this.finishNode(node, "WhileStatement")
1011};
1012
1013pp$1.parseWithStatement = function(node) {
1014 if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
1015 this.next();
1016 node.object = this.parseParenExpression();
1017 node.body = this.parseStatement(false);
1018 return this.finishNode(node, "WithStatement")
1019};
1020
1021pp$1.parseEmptyStatement = function(node) {
1022 this.next();
1023 return this.finishNode(node, "EmptyStatement")
1024};
1025
1026pp$1.parseLabeledStatement = function(node, maybeName, expr) {
1027 var this$1 = this;
1028
1029 for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
1030 {
1031 var label = list[i$1];
1032
1033 if (label.name === maybeName)
1034 { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
1035 } }
1036 var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
1037 for (var i = this.labels.length - 1; i >= 0; i--) {
1038 var label$1 = this$1.labels[i];
1039 if (label$1.statementStart == node.start) {
1040 label$1.statementStart = this$1.start;
1041 label$1.kind = kind;
1042 } else { break }
1043 }
1044 this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
1045 node.body = this.parseStatement(true);
1046 if (node.body.type == "ClassDeclaration" ||
1047 node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
1048 node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator))
1049 { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
1050 this.labels.pop();
1051 node.label = expr;
1052 return this.finishNode(node, "LabeledStatement")
1053};
1054
1055pp$1.parseExpressionStatement = function(node, expr) {
1056 node.expression = expr;
1057 this.semicolon();
1058 return this.finishNode(node, "ExpressionStatement")
1059};
1060
1061// Parse a semicolon-enclosed block of statements, handling `"use
1062// strict"` declarations when `allowStrict` is true (used for
1063// function bodies).
1064
1065pp$1.parseBlock = function(createNewLexicalScope) {
1066 var this$1 = this;
1067 if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
1068
1069 var node = this.startNode();
1070 node.body = [];
1071 this.expect(types.braceL);
1072 if (createNewLexicalScope) {
1073 this.enterLexicalScope();
1074 }
1075 while (!this.eat(types.braceR)) {
1076 var stmt = this$1.parseStatement(true);
1077 node.body.push(stmt);
1078 }
1079 if (createNewLexicalScope) {
1080 this.exitLexicalScope();
1081 }
1082 return this.finishNode(node, "BlockStatement")
1083};
1084
1085// Parse a regular `for` loop. The disambiguation code in
1086// `parseStatement` will already have parsed the init statement or
1087// expression.
1088
1089pp$1.parseFor = function(node, init) {
1090 node.init = init;
1091 this.expect(types.semi);
1092 node.test = this.type === types.semi ? null : this.parseExpression();
1093 this.expect(types.semi);
1094 node.update = this.type === types.parenR ? null : this.parseExpression();
1095 this.expect(types.parenR);
1096 this.exitLexicalScope();
1097 node.body = this.parseStatement(false);
1098 this.labels.pop();
1099 return this.finishNode(node, "ForStatement")
1100};
1101
1102// Parse a `for`/`in` and `for`/`of` loop, which are almost
1103// same from parser's perspective.
1104
1105pp$1.parseForIn = function(node, init) {
1106 var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
1107 this.next();
1108 node.left = init;
1109 node.right = this.parseExpression();
1110 this.expect(types.parenR);
1111 this.exitLexicalScope();
1112 node.body = this.parseStatement(false);
1113 this.labels.pop();
1114 return this.finishNode(node, type)
1115};
1116
1117// Parse a list of variable declarations.
1118
1119pp$1.parseVar = function(node, isFor, kind) {
1120 var this$1 = this;
1121
1122 node.declarations = [];
1123 node.kind = kind;
1124 for (;;) {
1125 var decl = this$1.startNode();
1126 this$1.parseVarId(decl, kind);
1127 if (this$1.eat(types.eq)) {
1128 decl.init = this$1.parseMaybeAssign(isFor);
1129 } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
1130 this$1.unexpected();
1131 } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
1132 this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
1133 } else {
1134 decl.init = null;
1135 }
1136 node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
1137 if (!this$1.eat(types.comma)) { break }
1138 }
1139 return node
1140};
1141
1142pp$1.parseVarId = function(decl, kind) {
1143 decl.id = this.parseBindingAtom(kind);
1144 this.checkLVal(decl.id, kind, false);
1145};
1146
1147// Parse a function declaration or literal (depending on the
1148// `isStatement` parameter).
1149
1150pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
1151 this.initFunction(node);
1152 if (this.options.ecmaVersion >= 6 && !isAsync)
1153 { node.generator = this.eat(types.star); }
1154 if (this.options.ecmaVersion >= 8)
1155 { node.async = !!isAsync; }
1156
1157 if (isStatement) {
1158 node.id = isStatement === "nullableID" && this.type != types.name ? null : this.parseIdent();
1159 if (node.id) {
1160 this.checkLVal(node.id, "var");
1161 }
1162 }
1163
1164 var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
1165 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
1166 this.inGenerator = node.generator;
1167 this.inAsync = node.async;
1168 this.yieldPos = 0;
1169 this.awaitPos = 0;
1170 this.inFunction = true;
1171 this.enterFunctionScope();
1172
1173 if (!isStatement)
1174 { node.id = this.type == types.name ? this.parseIdent() : null; }
1175
1176 this.parseFunctionParams(node);
1177 this.parseFunctionBody(node, allowExpressionBody);
1178
1179 this.inGenerator = oldInGen;
1180 this.inAsync = oldInAsync;
1181 this.yieldPos = oldYieldPos;
1182 this.awaitPos = oldAwaitPos;
1183 this.inFunction = oldInFunc;
1184 return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
1185};
1186
1187pp$1.parseFunctionParams = function(node) {
1188 this.expect(types.parenL);
1189 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
1190 this.checkYieldAwaitInDefaultParams();
1191};
1192
1193// Parse a class declaration or literal (depending on the
1194// `isStatement` parameter).
1195
1196pp$1.parseClass = function(node, isStatement) {
1197 var this$1 = this;
1198
1199 this.next();
1200
1201 this.parseClassId(node, isStatement);
1202 this.parseClassSuper(node);
1203 var classBody = this.startNode();
1204 var hadConstructor = false;
1205 classBody.body = [];
1206 this.expect(types.braceL);
1207 while (!this.eat(types.braceR)) {
1208 if (this$1.eat(types.semi)) { continue }
1209 var method = this$1.startNode();
1210 var isGenerator = this$1.eat(types.star);
1211 var isAsync = false;
1212 var isMaybeStatic = this$1.type === types.name && this$1.value === "static";
1213 this$1.parsePropertyName(method);
1214 method.static = isMaybeStatic && this$1.type !== types.parenL;
1215 if (method.static) {
1216 if (isGenerator) { this$1.unexpected(); }
1217 isGenerator = this$1.eat(types.star);
1218 this$1.parsePropertyName(method);
1219 }
1220 if (this$1.options.ecmaVersion >= 8 && !isGenerator && !method.computed &&
1221 method.key.type === "Identifier" && method.key.name === "async" && this$1.type !== types.parenL &&
1222 !this$1.canInsertSemicolon()) {
1223 isAsync = true;
1224 this$1.parsePropertyName(method);
1225 }
1226 method.kind = "method";
1227 var isGetSet = false;
1228 if (!method.computed) {
1229 var key = method.key;
1230 if (!isGenerator && !isAsync && key.type === "Identifier" && this$1.type !== types.parenL && (key.name === "get" || key.name === "set")) {
1231 isGetSet = true;
1232 method.kind = key.name;
1233 key = this$1.parsePropertyName(method);
1234 }
1235 if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
1236 key.type === "Literal" && key.value === "constructor")) {
1237 if (hadConstructor) { this$1.raise(key.start, "Duplicate constructor in the same class"); }
1238 if (isGetSet) { this$1.raise(key.start, "Constructor can't have get/set modifier"); }
1239 if (isGenerator) { this$1.raise(key.start, "Constructor can't be a generator"); }
1240 if (isAsync) { this$1.raise(key.start, "Constructor can't be an async method"); }
1241 method.kind = "constructor";
1242 hadConstructor = true;
1243 }
1244 }
1245 this$1.parseClassMethod(classBody, method, isGenerator, isAsync);
1246 if (isGetSet) {
1247 var paramCount = method.kind === "get" ? 0 : 1;
1248 if (method.value.params.length !== paramCount) {
1249 var start = method.value.start;
1250 if (method.kind === "get")
1251 { this$1.raiseRecoverable(start, "getter should have no params"); }
1252 else
1253 { this$1.raiseRecoverable(start, "setter should have exactly one param"); }
1254 } else {
1255 if (method.kind === "set" && method.value.params[0].type === "RestElement")
1256 { this$1.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
1257 }
1258 }
1259 }
1260 node.body = this.finishNode(classBody, "ClassBody");
1261 return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
1262};
1263
1264pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
1265 method.value = this.parseMethod(isGenerator, isAsync);
1266 classBody.body.push(this.finishNode(method, "MethodDefinition"));
1267};
1268
1269pp$1.parseClassId = function(node, isStatement) {
1270 node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
1271};
1272
1273pp$1.parseClassSuper = function(node) {
1274 node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
1275};
1276
1277// Parses module export declaration.
1278
1279pp$1.parseExport = function(node, exports) {
1280 var this$1 = this;
1281
1282 this.next();
1283 // export * from '...'
1284 if (this.eat(types.star)) {
1285 this.expectContextual("from");
1286 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1287 this.semicolon();
1288 return this.finishNode(node, "ExportAllDeclaration")
1289 }
1290 if (this.eat(types._default)) { // export default ...
1291 this.checkExport(exports, "default", this.lastTokStart);
1292 var isAsync;
1293 if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
1294 var fNode = this.startNode();
1295 this.next();
1296 if (isAsync) { this.next(); }
1297 node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
1298 } else if (this.type === types._class) {
1299 var cNode = this.startNode();
1300 node.declaration = this.parseClass(cNode, "nullableID");
1301 } else {
1302 node.declaration = this.parseMaybeAssign();
1303 this.semicolon();
1304 }
1305 return this.finishNode(node, "ExportDefaultDeclaration")
1306 }
1307 // export var|const|let|function|class ...
1308 if (this.shouldParseExportStatement()) {
1309 node.declaration = this.parseStatement(true);
1310 if (node.declaration.type === "VariableDeclaration")
1311 { this.checkVariableExport(exports, node.declaration.declarations); }
1312 else
1313 { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
1314 node.specifiers = [];
1315 node.source = null;
1316 } else { // export { x, y as z } [from '...']
1317 node.declaration = null;
1318 node.specifiers = this.parseExportSpecifiers(exports);
1319 if (this.eatContextual("from")) {
1320 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1321 } else {
1322 // check for keywords used as local names
1323 for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
1324 var spec = list[i];
1325
1326 this$1.checkUnreserved(spec.local);
1327 }
1328
1329 node.source = null;
1330 }
1331 this.semicolon();
1332 }
1333 return this.finishNode(node, "ExportNamedDeclaration")
1334};
1335
1336pp$1.checkExport = function(exports, name, pos) {
1337 if (!exports) { return }
1338 if (has(exports, name))
1339 { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
1340 exports[name] = true;
1341};
1342
1343pp$1.checkPatternExport = function(exports, pat) {
1344 var this$1 = this;
1345
1346 var type = pat.type;
1347 if (type == "Identifier")
1348 { this.checkExport(exports, pat.name, pat.start); }
1349 else if (type == "ObjectPattern")
1350 { for (var i = 0, list = pat.properties; i < list.length; i += 1)
1351 {
1352 var prop = list[i];
1353
1354 this$1.checkPatternExport(exports, prop.value);
1355 } }
1356 else if (type == "ArrayPattern")
1357 { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
1358 var elt = list$1[i$1];
1359
1360 if (elt) { this$1.checkPatternExport(exports, elt); }
1361 } }
1362 else if (type == "AssignmentPattern")
1363 { this.checkPatternExport(exports, pat.left); }
1364 else if (type == "ParenthesizedExpression")
1365 { this.checkPatternExport(exports, pat.expression); }
1366};
1367
1368pp$1.checkVariableExport = function(exports, decls) {
1369 var this$1 = this;
1370
1371 if (!exports) { return }
1372 for (var i = 0, list = decls; i < list.length; i += 1)
1373 {
1374 var decl = list[i];
1375
1376 this$1.checkPatternExport(exports, decl.id);
1377 }
1378};
1379
1380pp$1.shouldParseExportStatement = function() {
1381 return this.type.keyword === "var" ||
1382 this.type.keyword === "const" ||
1383 this.type.keyword === "class" ||
1384 this.type.keyword === "function" ||
1385 this.isLet() ||
1386 this.isAsyncFunction()
1387};
1388
1389// Parses a comma-separated list of module exports.
1390
1391pp$1.parseExportSpecifiers = function(exports) {
1392 var this$1 = this;
1393
1394 var nodes = [], first = true;
1395 // export { x, y as z } [from '...']
1396 this.expect(types.braceL);
1397 while (!this.eat(types.braceR)) {
1398 if (!first) {
1399 this$1.expect(types.comma);
1400 if (this$1.afterTrailingComma(types.braceR)) { break }
1401 } else { first = false; }
1402
1403 var node = this$1.startNode();
1404 node.local = this$1.parseIdent(true);
1405 node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
1406 this$1.checkExport(exports, node.exported.name, node.exported.start);
1407 nodes.push(this$1.finishNode(node, "ExportSpecifier"));
1408 }
1409 return nodes
1410};
1411
1412// Parses import declaration.
1413
1414pp$1.parseImport = function(node) {
1415 this.next();
1416 // import '...'
1417 if (this.type === types.string) {
1418 node.specifiers = empty;
1419 node.source = this.parseExprAtom();
1420 } else {
1421 node.specifiers = this.parseImportSpecifiers();
1422 this.expectContextual("from");
1423 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1424 }
1425 this.semicolon();
1426 return this.finishNode(node, "ImportDeclaration")
1427};
1428
1429// Parses a comma-separated list of module imports.
1430
1431pp$1.parseImportSpecifiers = function() {
1432 var this$1 = this;
1433
1434 var nodes = [], first = true;
1435 if (this.type === types.name) {
1436 // import defaultObj, { x, y as z } from '...'
1437 var node = this.startNode();
1438 node.local = this.parseIdent();
1439 this.checkLVal(node.local, "let");
1440 nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
1441 if (!this.eat(types.comma)) { return nodes }
1442 }
1443 if (this.type === types.star) {
1444 var node$1 = this.startNode();
1445 this.next();
1446 this.expectContextual("as");
1447 node$1.local = this.parseIdent();
1448 this.checkLVal(node$1.local, "let");
1449 nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
1450 return nodes
1451 }
1452 this.expect(types.braceL);
1453 while (!this.eat(types.braceR)) {
1454 if (!first) {
1455 this$1.expect(types.comma);
1456 if (this$1.afterTrailingComma(types.braceR)) { break }
1457 } else { first = false; }
1458
1459 var node$2 = this$1.startNode();
1460 node$2.imported = this$1.parseIdent(true);
1461 if (this$1.eatContextual("as")) {
1462 node$2.local = this$1.parseIdent();
1463 } else {
1464 this$1.checkUnreserved(node$2.imported);
1465 node$2.local = node$2.imported;
1466 }
1467 this$1.checkLVal(node$2.local, "let");
1468 nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
1469 }
1470 return nodes
1471};
1472
1473var pp$2 = Parser.prototype;
1474
1475// Convert existing expression atom to assignable pattern
1476// if possible.
1477
1478pp$2.toAssignable = function(node, isBinding) {
1479 var this$1 = this;
1480
1481 if (this.options.ecmaVersion >= 6 && node) {
1482 switch (node.type) {
1483 case "Identifier":
1484 if (this.inAsync && node.name === "await")
1485 { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
1486 break
1487
1488 case "ObjectPattern":
1489 case "ArrayPattern":
1490 break
1491
1492 case "ObjectExpression":
1493 node.type = "ObjectPattern";
1494 for (var i = 0, list = node.properties; i < list.length; i += 1) {
1495 var prop = list[i];
1496
1497 if (prop.kind !== "init") { this$1.raise(prop.key.start, "Object pattern can't contain getter or setter"); }
1498 this$1.toAssignable(prop.value, isBinding);
1499 }
1500 break
1501
1502 case "ArrayExpression":
1503 node.type = "ArrayPattern";
1504 this.toAssignableList(node.elements, isBinding);
1505 break
1506
1507 case "AssignmentExpression":
1508 if (node.operator === "=") {
1509 node.type = "AssignmentPattern";
1510 delete node.operator;
1511 this.toAssignable(node.left, isBinding);
1512 // falls through to AssignmentPattern
1513 } else {
1514 this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
1515 break
1516 }
1517
1518 case "AssignmentPattern":
1519 break
1520
1521 case "ParenthesizedExpression":
1522 this.toAssignable(node.expression, isBinding);
1523 break
1524
1525 case "MemberExpression":
1526 if (!isBinding) { break }
1527
1528 default:
1529 this.raise(node.start, "Assigning to rvalue");
1530 }
1531 }
1532 return node
1533};
1534
1535// Convert list of expression atoms to binding list.
1536
1537pp$2.toAssignableList = function(exprList, isBinding) {
1538 var this$1 = this;
1539
1540 var end = exprList.length;
1541 if (end) {
1542 var last = exprList[end - 1];
1543 if (last && last.type == "RestElement") {
1544 --end;
1545 } else if (last && last.type == "SpreadElement") {
1546 last.type = "RestElement";
1547 var arg = last.argument;
1548 this.toAssignable(arg, isBinding);
1549 --end;
1550 }
1551
1552 if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
1553 { this.unexpected(last.argument.start); }
1554 }
1555 for (var i = 0; i < end; i++) {
1556 var elt = exprList[i];
1557 if (elt) { this$1.toAssignable(elt, isBinding); }
1558 }
1559 return exprList
1560};
1561
1562// Parses spread element.
1563
1564pp$2.parseSpread = function(refDestructuringErrors) {
1565 var node = this.startNode();
1566 this.next();
1567 node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
1568 return this.finishNode(node, "SpreadElement")
1569};
1570
1571pp$2.parseRestBinding = function() {
1572 var node = this.startNode();
1573 this.next();
1574
1575 // RestElement inside of a function parameter must be an identifier
1576 if (this.options.ecmaVersion === 6 && this.type !== types.name)
1577 { this.unexpected(); }
1578
1579 node.argument = this.parseBindingAtom();
1580
1581 return this.finishNode(node, "RestElement")
1582};
1583
1584// Parses lvalue (assignable) atom.
1585
1586pp$2.parseBindingAtom = function() {
1587 if (this.options.ecmaVersion < 6) { return this.parseIdent() }
1588 switch (this.type) {
1589 case types.name:
1590 return this.parseIdent()
1591
1592 case types.bracketL:
1593 var node = this.startNode();
1594 this.next();
1595 node.elements = this.parseBindingList(types.bracketR, true, true);
1596 return this.finishNode(node, "ArrayPattern")
1597
1598 case types.braceL:
1599 return this.parseObj(true)
1600
1601 default:
1602 this.unexpected();
1603 }
1604};
1605
1606pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
1607 var this$1 = this;
1608
1609 var elts = [], first = true;
1610 while (!this.eat(close)) {
1611 if (first) { first = false; }
1612 else { this$1.expect(types.comma); }
1613 if (allowEmpty && this$1.type === types.comma) {
1614 elts.push(null);
1615 } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
1616 break
1617 } else if (this$1.type === types.ellipsis) {
1618 var rest = this$1.parseRestBinding();
1619 this$1.parseBindingListItem(rest);
1620 elts.push(rest);
1621 if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
1622 this$1.expect(close);
1623 break
1624 } else {
1625 var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
1626 this$1.parseBindingListItem(elem);
1627 elts.push(elem);
1628 }
1629 }
1630 return elts
1631};
1632
1633pp$2.parseBindingListItem = function(param) {
1634 return param
1635};
1636
1637// Parses assignment pattern around given atom if possible.
1638
1639pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
1640 left = left || this.parseBindingAtom();
1641 if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
1642 var node = this.startNodeAt(startPos, startLoc);
1643 node.left = left;
1644 node.right = this.parseMaybeAssign();
1645 return this.finishNode(node, "AssignmentPattern")
1646};
1647
1648// Verify that a node is an lval — something that can be assigned
1649// to.
1650// bindingType can be either:
1651// 'var' indicating that the lval creates a 'var' binding
1652// 'let' indicating that the lval creates a lexical ('let' or 'const') binding
1653// 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
1654
1655pp$2.checkLVal = function(expr, bindingType, checkClashes) {
1656 var this$1 = this;
1657
1658 switch (expr.type) {
1659 case "Identifier":
1660 if (this.strict && this.reservedWordsStrictBind.test(expr.name))
1661 { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
1662 if (checkClashes) {
1663 if (has(checkClashes, expr.name))
1664 { this.raiseRecoverable(expr.start, "Argument name clash"); }
1665 checkClashes[expr.name] = true;
1666 }
1667 if (bindingType && bindingType !== "none") {
1668 if (
1669 bindingType === "var" && !this.canDeclareVarName(expr.name) ||
1670 bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
1671 ) {
1672 this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
1673 }
1674 if (bindingType === "var") {
1675 this.declareVarName(expr.name);
1676 } else {
1677 this.declareLexicalName(expr.name);
1678 }
1679 }
1680 break
1681
1682 case "MemberExpression":
1683 if (bindingType) { this.raiseRecoverable(expr.start, (bindingType ? "Binding" : "Assigning to") + " member expression"); }
1684 break
1685
1686 case "ObjectPattern":
1687 for (var i = 0, list = expr.properties; i < list.length; i += 1)
1688 {
1689 var prop = list[i];
1690
1691 this$1.checkLVal(prop.value, bindingType, checkClashes);
1692 }
1693 break
1694
1695 case "ArrayPattern":
1696 for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
1697 var elem = list$1[i$1];
1698
1699 if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
1700 }
1701 break
1702
1703 case "AssignmentPattern":
1704 this.checkLVal(expr.left, bindingType, checkClashes);
1705 break
1706
1707 case "RestElement":
1708 this.checkLVal(expr.argument, bindingType, checkClashes);
1709 break
1710
1711 case "ParenthesizedExpression":
1712 this.checkLVal(expr.expression, bindingType, checkClashes);
1713 break
1714
1715 default:
1716 this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
1717 }
1718};
1719
1720// A recursive descent parser operates by defining functions for all
1721// syntactic elements, and recursively calling those, each function
1722// advancing the input stream and returning an AST node. Precedence
1723// of constructs (for example, the fact that `!x[1]` means `!(x[1])`
1724// instead of `(!x)[1]` is handled by the fact that the parser
1725// function that parses unary prefix operators is called first, and
1726// in turn calls the function that parses `[]` subscripts — that
1727// way, it'll receive the node for `x[1]` already parsed, and wraps
1728// *that* in the unary operator node.
1729//
1730// Acorn uses an [operator precedence parser][opp] to handle binary
1731// operator precedence, because it is much more compact than using
1732// the technique outlined above, which uses different, nesting
1733// functions to specify precedence, for all of the ten binary
1734// precedence levels that JavaScript defines.
1735//
1736// [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
1737
1738var pp$3 = Parser.prototype;
1739
1740// Check if property name clashes with already added.
1741// Object/class getters and setters are not allowed to clash —
1742// either with each other or with an init property — and in
1743// strict mode, init properties are also not allowed to be repeated.
1744
1745pp$3.checkPropClash = function(prop, propHash) {
1746 if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
1747 { return }
1748 var key = prop.key;
1749 var name;
1750 switch (key.type) {
1751 case "Identifier": name = key.name; break
1752 case "Literal": name = String(key.value); break
1753 default: return
1754 }
1755 var kind = prop.kind;
1756 if (this.options.ecmaVersion >= 6) {
1757 if (name === "__proto__" && kind === "init") {
1758 if (propHash.proto) { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
1759 propHash.proto = true;
1760 }
1761 return
1762 }
1763 name = "$" + name;
1764 var other = propHash[name];
1765 if (other) {
1766 var redefinition;
1767 if (kind === "init") {
1768 redefinition = this.strict && other.init || other.get || other.set;
1769 } else {
1770 redefinition = other.init || other[kind];
1771 }
1772 if (redefinition)
1773 { this.raiseRecoverable(key.start, "Redefinition of property"); }
1774 } else {
1775 other = propHash[name] = {
1776 init: false,
1777 get: false,
1778 set: false
1779 };
1780 }
1781 other[kind] = true;
1782};
1783
1784// ### Expression parsing
1785
1786// These nest, from the most general expression type at the top to
1787// 'atomic', nondivisible expression types at the bottom. Most of
1788// the functions will simply let the function(s) below them parse,
1789// and, *if* the syntactic construct they handle is present, wrap
1790// the AST node that the inner parser gave them in another node.
1791
1792// Parse a full expression. The optional arguments are used to
1793// forbid the `in` operator (in for loops initalization expressions)
1794// and provide reference for storing '=' operator inside shorthand
1795// property assignment in contexts where both object expression
1796// and object pattern might appear (so it's possible to raise
1797// delayed syntax error at correct position).
1798
1799pp$3.parseExpression = function(noIn, refDestructuringErrors) {
1800 var this$1 = this;
1801
1802 var startPos = this.start, startLoc = this.startLoc;
1803 var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
1804 if (this.type === types.comma) {
1805 var node = this.startNodeAt(startPos, startLoc);
1806 node.expressions = [expr];
1807 while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
1808 return this.finishNode(node, "SequenceExpression")
1809 }
1810 return expr
1811};
1812
1813// Parse an assignment expression. This includes applications of
1814// operators like `+=`.
1815
1816pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
1817 if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
1818
1819 var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
1820 if (refDestructuringErrors) {
1821 oldParenAssign = refDestructuringErrors.parenthesizedAssign;
1822 oldTrailingComma = refDestructuringErrors.trailingComma;
1823 refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
1824 } else {
1825 refDestructuringErrors = new DestructuringErrors;
1826 ownDestructuringErrors = true;
1827 }
1828
1829 var startPos = this.start, startLoc = this.startLoc;
1830 if (this.type == types.parenL || this.type == types.name)
1831 { this.potentialArrowAt = this.start; }
1832 var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
1833 if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
1834 if (this.type.isAssign) {
1835 this.checkPatternErrors(refDestructuringErrors, true);
1836 if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
1837 var node = this.startNodeAt(startPos, startLoc);
1838 node.operator = this.value;
1839 node.left = this.type === types.eq ? this.toAssignable(left) : left;
1840 refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
1841 this.checkLVal(left);
1842 this.next();
1843 node.right = this.parseMaybeAssign(noIn);
1844 return this.finishNode(node, "AssignmentExpression")
1845 } else {
1846 if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
1847 }
1848 if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
1849 if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
1850 return left
1851};
1852
1853// Parse a ternary conditional (`?:`) operator.
1854
1855pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
1856 var startPos = this.start, startLoc = this.startLoc;
1857 var expr = this.parseExprOps(noIn, refDestructuringErrors);
1858 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1859 if (this.eat(types.question)) {
1860 var node = this.startNodeAt(startPos, startLoc);
1861 node.test = expr;
1862 node.consequent = this.parseMaybeAssign();
1863 this.expect(types.colon);
1864 node.alternate = this.parseMaybeAssign(noIn);
1865 return this.finishNode(node, "ConditionalExpression")
1866 }
1867 return expr
1868};
1869
1870// Start the precedence parser.
1871
1872pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
1873 var startPos = this.start, startLoc = this.startLoc;
1874 var expr = this.parseMaybeUnary(refDestructuringErrors, false);
1875 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1876 return expr.start == startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
1877};
1878
1879// Parse binary operators with the operator precedence parsing
1880// algorithm. `left` is the left-hand side of the operator.
1881// `minPrec` provides context that allows the function to stop and
1882// defer further parser to one of its callers when it encounters an
1883// operator that has a lower precedence than the set it is parsing.
1884
1885pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
1886 var prec = this.type.binop;
1887 if (prec != null && (!noIn || this.type !== types._in)) {
1888 if (prec > minPrec) {
1889 var logical = this.type === types.logicalOR || this.type === types.logicalAND;
1890 var op = this.value;
1891 this.next();
1892 var startPos = this.start, startLoc = this.startLoc;
1893 var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
1894 var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
1895 return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
1896 }
1897 }
1898 return left
1899};
1900
1901pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
1902 var node = this.startNodeAt(startPos, startLoc);
1903 node.left = left;
1904 node.operator = op;
1905 node.right = right;
1906 return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
1907};
1908
1909// Parse unary operators, both prefix and postfix.
1910
1911pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
1912 var this$1 = this;
1913
1914 var startPos = this.start, startLoc = this.startLoc, expr;
1915 if (this.inAsync && this.isContextual("await")) {
1916 expr = this.parseAwait(refDestructuringErrors);
1917 sawUnary = true;
1918 } else if (this.type.prefix) {
1919 var node = this.startNode(), update = this.type === types.incDec;
1920 node.operator = this.value;
1921 node.prefix = true;
1922 this.next();
1923 node.argument = this.parseMaybeUnary(null, true);
1924 this.checkExpressionErrors(refDestructuringErrors, true);
1925 if (update) { this.checkLVal(node.argument); }
1926 else if (this.strict && node.operator === "delete" &&
1927 node.argument.type === "Identifier")
1928 { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
1929 else { sawUnary = true; }
1930 expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
1931 } else {
1932 expr = this.parseExprSubscripts(refDestructuringErrors);
1933 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1934 while (this.type.postfix && !this.canInsertSemicolon()) {
1935 var node$1 = this$1.startNodeAt(startPos, startLoc);
1936 node$1.operator = this$1.value;
1937 node$1.prefix = false;
1938 node$1.argument = expr;
1939 this$1.checkLVal(expr);
1940 this$1.next();
1941 expr = this$1.finishNode(node$1, "UpdateExpression");
1942 }
1943 }
1944
1945 if (!sawUnary && this.eat(types.starstar))
1946 { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
1947 else
1948 { return expr }
1949};
1950
1951// Parse call, dot, and `[]`-subscript expressions.
1952
1953pp$3.parseExprSubscripts = function(refDestructuringErrors) {
1954 var startPos = this.start, startLoc = this.startLoc;
1955 var expr = this.parseExprAtom(refDestructuringErrors);
1956 var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
1957 if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
1958 var result = this.parseSubscripts(expr, startPos, startLoc);
1959 if (refDestructuringErrors && result.type === "MemberExpression") {
1960 if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
1961 if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
1962 }
1963 return result
1964};
1965
1966pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
1967 var this$1 = this;
1968
1969 var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
1970 this.lastTokEnd == base.end && !this.canInsertSemicolon();
1971 for (var computed = (void 0);;) {
1972 if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
1973 var node = this$1.startNodeAt(startPos, startLoc);
1974 node.object = base;
1975 node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
1976 node.computed = !!computed;
1977 if (computed) { this$1.expect(types.bracketR); }
1978 base = this$1.finishNode(node, "MemberExpression");
1979 } else if (!noCalls && this$1.eat(types.parenL)) {
1980 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
1981 this$1.yieldPos = 0;
1982 this$1.awaitPos = 0;
1983 var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
1984 if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
1985 this$1.checkPatternErrors(refDestructuringErrors, false);
1986 this$1.checkYieldAwaitInDefaultParams();
1987 this$1.yieldPos = oldYieldPos;
1988 this$1.awaitPos = oldAwaitPos;
1989 return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
1990 }
1991 this$1.checkExpressionErrors(refDestructuringErrors, true);
1992 this$1.yieldPos = oldYieldPos || this$1.yieldPos;
1993 this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
1994 var node$1 = this$1.startNodeAt(startPos, startLoc);
1995 node$1.callee = base;
1996 node$1.arguments = exprList;
1997 base = this$1.finishNode(node$1, "CallExpression");
1998 } else if (this$1.type === types.backQuote) {
1999 var node$2 = this$1.startNodeAt(startPos, startLoc);
2000 node$2.tag = base;
2001 node$2.quasi = this$1.parseTemplate({isTagged: true});
2002 base = this$1.finishNode(node$2, "TaggedTemplateExpression");
2003 } else {
2004 return base
2005 }
2006 }
2007};
2008
2009// Parse an atomic expression — either a single token that is an
2010// expression, an expression started by a keyword like `function` or
2011// `new`, or an expression wrapped in punctuation like `()`, `[]`,
2012// or `{}`.
2013
2014pp$3.parseExprAtom = function(refDestructuringErrors) {
2015 var node, canBeArrow = this.potentialArrowAt == this.start;
2016 switch (this.type) {
2017 case types._super:
2018 if (!this.inFunction)
2019 { this.raise(this.start, "'super' outside of function or class"); }
2020
2021 case types._this:
2022 var type = this.type === types._this ? "ThisExpression" : "Super";
2023 node = this.startNode();
2024 this.next();
2025 return this.finishNode(node, type)
2026
2027 case types.name:
2028 var startPos = this.start, startLoc = this.startLoc;
2029 var id = this.parseIdent(this.type !== types.name);
2030 if (this.options.ecmaVersion >= 8 && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
2031 { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
2032 if (canBeArrow && !this.canInsertSemicolon()) {
2033 if (this.eat(types.arrow))
2034 { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
2035 if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name) {
2036 id = this.parseIdent();
2037 if (this.canInsertSemicolon() || !this.eat(types.arrow))
2038 { this.unexpected(); }
2039 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
2040 }
2041 }
2042 return id
2043
2044 case types.regexp:
2045 var value = this.value;
2046 node = this.parseLiteral(value.value);
2047 node.regex = {pattern: value.pattern, flags: value.flags};
2048 return node
2049
2050 case types.num: case types.string:
2051 return this.parseLiteral(this.value)
2052
2053 case types._null: case types._true: case types._false:
2054 node = this.startNode();
2055 node.value = this.type === types._null ? null : this.type === types._true;
2056 node.raw = this.type.keyword;
2057 this.next();
2058 return this.finishNode(node, "Literal")
2059
2060 case types.parenL:
2061 var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
2062 if (refDestructuringErrors) {
2063 if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
2064 { refDestructuringErrors.parenthesizedAssign = start; }
2065 if (refDestructuringErrors.parenthesizedBind < 0)
2066 { refDestructuringErrors.parenthesizedBind = start; }
2067 }
2068 return expr
2069
2070 case types.bracketL:
2071 node = this.startNode();
2072 this.next();
2073 node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
2074 return this.finishNode(node, "ArrayExpression")
2075
2076 case types.braceL:
2077 return this.parseObj(false, refDestructuringErrors)
2078
2079 case types._function:
2080 node = this.startNode();
2081 this.next();
2082 return this.parseFunction(node, false)
2083
2084 case types._class:
2085 return this.parseClass(this.startNode(), false)
2086
2087 case types._new:
2088 return this.parseNew()
2089
2090 case types.backQuote:
2091 return this.parseTemplate()
2092
2093 default:
2094 this.unexpected();
2095 }
2096};
2097
2098pp$3.parseLiteral = function(value) {
2099 var node = this.startNode();
2100 node.value = value;
2101 node.raw = this.input.slice(this.start, this.end);
2102 this.next();
2103 return this.finishNode(node, "Literal")
2104};
2105
2106pp$3.parseParenExpression = function() {
2107 this.expect(types.parenL);
2108 var val = this.parseExpression();
2109 this.expect(types.parenR);
2110 return val
2111};
2112
2113pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
2114 var this$1 = this;
2115
2116 var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
2117 if (this.options.ecmaVersion >= 6) {
2118 this.next();
2119
2120 var innerStartPos = this.start, innerStartLoc = this.startLoc;
2121 var exprList = [], first = true, lastIsComma = false;
2122 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart, innerParenStart;
2123 this.yieldPos = 0;
2124 this.awaitPos = 0;
2125 while (this.type !== types.parenR) {
2126 first ? first = false : this$1.expect(types.comma);
2127 if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
2128 lastIsComma = true;
2129 break
2130 } else if (this$1.type === types.ellipsis) {
2131 spreadStart = this$1.start;
2132 exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
2133 if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
2134 break
2135 } else {
2136 if (this$1.type === types.parenL && !innerParenStart) {
2137 innerParenStart = this$1.start;
2138 }
2139 exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
2140 }
2141 }
2142 var innerEndPos = this.start, innerEndLoc = this.startLoc;
2143 this.expect(types.parenR);
2144
2145 if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2146 this.checkPatternErrors(refDestructuringErrors, false);
2147 this.checkYieldAwaitInDefaultParams();
2148 if (innerParenStart) { this.unexpected(innerParenStart); }
2149 this.yieldPos = oldYieldPos;
2150 this.awaitPos = oldAwaitPos;
2151 return this.parseParenArrowList(startPos, startLoc, exprList)
2152 }
2153
2154 if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
2155 if (spreadStart) { this.unexpected(spreadStart); }
2156 this.checkExpressionErrors(refDestructuringErrors, true);
2157 this.yieldPos = oldYieldPos || this.yieldPos;
2158 this.awaitPos = oldAwaitPos || this.awaitPos;
2159
2160 if (exprList.length > 1) {
2161 val = this.startNodeAt(innerStartPos, innerStartLoc);
2162 val.expressions = exprList;
2163 this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
2164 } else {
2165 val = exprList[0];
2166 }
2167 } else {
2168 val = this.parseParenExpression();
2169 }
2170
2171 if (this.options.preserveParens) {
2172 var par = this.startNodeAt(startPos, startLoc);
2173 par.expression = val;
2174 return this.finishNode(par, "ParenthesizedExpression")
2175 } else {
2176 return val
2177 }
2178};
2179
2180pp$3.parseParenItem = function(item) {
2181 return item
2182};
2183
2184pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
2185 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
2186};
2187
2188// New's precedence is slightly tricky. It must allow its argument to
2189// be a `[]` or dot subscript expression, but not a call — at least,
2190// not without wrapping it in parentheses. Thus, it uses the noCalls
2191// argument to parseSubscripts to prevent it from consuming the
2192// argument list.
2193
2194var empty$1 = [];
2195
2196pp$3.parseNew = function() {
2197 var node = this.startNode();
2198 var meta = this.parseIdent(true);
2199 if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
2200 node.meta = meta;
2201 node.property = this.parseIdent(true);
2202 if (node.property.name !== "target")
2203 { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
2204 if (!this.inFunction)
2205 { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
2206 return this.finishNode(node, "MetaProperty")
2207 }
2208 var startPos = this.start, startLoc = this.startLoc;
2209 node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
2210 if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
2211 else { node.arguments = empty$1; }
2212 return this.finishNode(node, "NewExpression")
2213};
2214
2215// Parse template expression.
2216
2217pp$3.parseTemplateElement = function(ref) {
2218 var isTagged = ref.isTagged;
2219
2220 var elem = this.startNode();
2221 if (this.type === types.invalidTemplate) {
2222 if (!isTagged) {
2223 this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
2224 }
2225 elem.value = {
2226 raw: this.value,
2227 cooked: null
2228 };
2229 } else {
2230 elem.value = {
2231 raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
2232 cooked: this.value
2233 };
2234 }
2235 this.next();
2236 elem.tail = this.type === types.backQuote;
2237 return this.finishNode(elem, "TemplateElement")
2238};
2239
2240pp$3.parseTemplate = function(ref) {
2241 var this$1 = this;
2242 if ( ref === void 0 ) ref = {};
2243 var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
2244
2245 var node = this.startNode();
2246 this.next();
2247 node.expressions = [];
2248 var curElt = this.parseTemplateElement({isTagged: isTagged});
2249 node.quasis = [curElt];
2250 while (!curElt.tail) {
2251 this$1.expect(types.dollarBraceL);
2252 node.expressions.push(this$1.parseExpression());
2253 this$1.expect(types.braceR);
2254 node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
2255 }
2256 this.next();
2257 return this.finishNode(node, "TemplateLiteral")
2258};
2259
2260// Parse an object literal or binding pattern.
2261
2262pp$3.isAsyncProp = function(prop) {
2263 return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
2264 (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword) &&
2265 !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
2266};
2267
2268pp$3.parseObj = function(isPattern, refDestructuringErrors) {
2269 var this$1 = this;
2270
2271 var node = this.startNode(), first = true, propHash = {};
2272 node.properties = [];
2273 this.next();
2274 while (!this.eat(types.braceR)) {
2275 if (!first) {
2276 this$1.expect(types.comma);
2277 if (this$1.afterTrailingComma(types.braceR)) { break }
2278 } else { first = false; }
2279
2280 var prop = this$1.startNode(), isGenerator = (void 0), isAsync = (void 0), startPos = (void 0), startLoc = (void 0);
2281 if (this$1.options.ecmaVersion >= 6) {
2282 prop.method = false;
2283 prop.shorthand = false;
2284 if (isPattern || refDestructuringErrors) {
2285 startPos = this$1.start;
2286 startLoc = this$1.startLoc;
2287 }
2288 if (!isPattern)
2289 { isGenerator = this$1.eat(types.star); }
2290 }
2291 this$1.parsePropertyName(prop);
2292 if (!isPattern && this$1.options.ecmaVersion >= 8 && !isGenerator && this$1.isAsyncProp(prop)) {
2293 isAsync = true;
2294 this$1.parsePropertyName(prop, refDestructuringErrors);
2295 } else {
2296 isAsync = false;
2297 }
2298 this$1.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
2299 this$1.checkPropClash(prop, propHash);
2300 node.properties.push(this$1.finishNode(prop, "Property"));
2301 }
2302 return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
2303};
2304
2305pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) {
2306 if ((isGenerator || isAsync) && this.type === types.colon)
2307 { this.unexpected(); }
2308
2309 if (this.eat(types.colon)) {
2310 prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
2311 prop.kind = "init";
2312 } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
2313 if (isPattern) { this.unexpected(); }
2314 prop.kind = "init";
2315 prop.method = true;
2316 prop.value = this.parseMethod(isGenerator, isAsync);
2317 } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
2318 (prop.key.name === "get" || prop.key.name === "set") &&
2319 (this.type != types.comma && this.type != types.braceR)) {
2320 if (isGenerator || isAsync || isPattern) { this.unexpected(); }
2321 prop.kind = prop.key.name;
2322 this.parsePropertyName(prop);
2323 prop.value = this.parseMethod(false);
2324 var paramCount = prop.kind === "get" ? 0 : 1;
2325 if (prop.value.params.length !== paramCount) {
2326 var start = prop.value.start;
2327 if (prop.kind === "get")
2328 { this.raiseRecoverable(start, "getter should have no params"); }
2329 else
2330 { this.raiseRecoverable(start, "setter should have exactly one param"); }
2331 } else {
2332 if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
2333 { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
2334 }
2335 } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
2336 this.checkUnreserved(prop.key);
2337 prop.kind = "init";
2338 if (isPattern) {
2339 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2340 } else if (this.type === types.eq && refDestructuringErrors) {
2341 if (refDestructuringErrors.shorthandAssign < 0)
2342 { refDestructuringErrors.shorthandAssign = this.start; }
2343 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2344 } else {
2345 prop.value = prop.key;
2346 }
2347 prop.shorthand = true;
2348 } else { this.unexpected(); }
2349};
2350
2351pp$3.parsePropertyName = function(prop) {
2352 if (this.options.ecmaVersion >= 6) {
2353 if (this.eat(types.bracketL)) {
2354 prop.computed = true;
2355 prop.key = this.parseMaybeAssign();
2356 this.expect(types.bracketR);
2357 return prop.key
2358 } else {
2359 prop.computed = false;
2360 }
2361 }
2362 return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
2363};
2364
2365// Initialize empty function node.
2366
2367pp$3.initFunction = function(node) {
2368 node.id = null;
2369 if (this.options.ecmaVersion >= 6) {
2370 node.generator = false;
2371 node.expression = false;
2372 }
2373 if (this.options.ecmaVersion >= 8)
2374 { node.async = false; }
2375};
2376
2377// Parse object or class method.
2378
2379pp$3.parseMethod = function(isGenerator, isAsync) {
2380 var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
2381 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
2382
2383 this.initFunction(node);
2384 if (this.options.ecmaVersion >= 6)
2385 { node.generator = isGenerator; }
2386 if (this.options.ecmaVersion >= 8)
2387 { node.async = !!isAsync; }
2388
2389 this.inGenerator = node.generator;
2390 this.inAsync = node.async;
2391 this.yieldPos = 0;
2392 this.awaitPos = 0;
2393 this.inFunction = true;
2394 this.enterFunctionScope();
2395
2396 this.expect(types.parenL);
2397 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
2398 this.checkYieldAwaitInDefaultParams();
2399 this.parseFunctionBody(node, false);
2400
2401 this.inGenerator = oldInGen;
2402 this.inAsync = oldInAsync;
2403 this.yieldPos = oldYieldPos;
2404 this.awaitPos = oldAwaitPos;
2405 this.inFunction = oldInFunc;
2406 return this.finishNode(node, "FunctionExpression")
2407};
2408
2409// Parse arrow function expression with given parameters.
2410
2411pp$3.parseArrowExpression = function(node, params, isAsync) {
2412 var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
2413 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
2414
2415 this.enterFunctionScope();
2416 this.initFunction(node);
2417 if (this.options.ecmaVersion >= 8)
2418 { node.async = !!isAsync; }
2419
2420 this.inGenerator = false;
2421 this.inAsync = node.async;
2422 this.yieldPos = 0;
2423 this.awaitPos = 0;
2424 this.inFunction = true;
2425
2426 node.params = this.toAssignableList(params, true);
2427 this.parseFunctionBody(node, true);
2428
2429 this.inGenerator = oldInGen;
2430 this.inAsync = oldInAsync;
2431 this.yieldPos = oldYieldPos;
2432 this.awaitPos = oldAwaitPos;
2433 this.inFunction = oldInFunc;
2434 return this.finishNode(node, "ArrowFunctionExpression")
2435};
2436
2437// Parse function body and check parameters.
2438
2439pp$3.parseFunctionBody = function(node, isArrowFunction) {
2440 var isExpression = isArrowFunction && this.type !== types.braceL;
2441 var oldStrict = this.strict, useStrict = false;
2442
2443 if (isExpression) {
2444 node.body = this.parseMaybeAssign();
2445 node.expression = true;
2446 this.checkParams(node, false);
2447 } else {
2448 var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
2449 if (!oldStrict || nonSimple) {
2450 useStrict = this.strictDirective(this.end);
2451 // If this is a strict mode function, verify that argument names
2452 // are not repeated, and it does not try to bind the words `eval`
2453 // or `arguments`.
2454 if (useStrict && nonSimple)
2455 { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
2456 }
2457 // Start a new scope with regard to labels and the `inFunction`
2458 // flag (restore them to their old value afterwards).
2459 var oldLabels = this.labels;
2460 this.labels = [];
2461 if (useStrict) { this.strict = true; }
2462
2463 // Add the params to varDeclaredNames to ensure that an error is thrown
2464 // if a let/const declaration in the function clashes with one of the params.
2465 this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
2466 node.body = this.parseBlock(false);
2467 node.expression = false;
2468 this.labels = oldLabels;
2469 }
2470 this.exitFunctionScope();
2471
2472 if (this.strict && node.id) {
2473 // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
2474 this.checkLVal(node.id, "none");
2475 }
2476 this.strict = oldStrict;
2477};
2478
2479pp$3.isSimpleParamList = function(params) {
2480 for (var i = 0, list = params; i < list.length; i += 1)
2481 {
2482 var param = list[i];
2483
2484 if (param.type !== "Identifier") { return false
2485 } }
2486 return true
2487};
2488
2489// Checks function params for various disallowed patterns such as using "eval"
2490// or "arguments" and duplicate parameters.
2491
2492pp$3.checkParams = function(node, allowDuplicates) {
2493 var this$1 = this;
2494
2495 var nameHash = {};
2496 for (var i = 0, list = node.params; i < list.length; i += 1)
2497 {
2498 var param = list[i];
2499
2500 this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
2501 }
2502};
2503
2504// Parses a comma-separated list of expressions, and returns them as
2505// an array. `close` is the token type that ends the list, and
2506// `allowEmpty` can be turned on to allow subsequent commas with
2507// nothing in between them to be parsed as `null` (which is needed
2508// for array literals).
2509
2510pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
2511 var this$1 = this;
2512
2513 var elts = [], first = true;
2514 while (!this.eat(close)) {
2515 if (!first) {
2516 this$1.expect(types.comma);
2517 if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
2518 } else { first = false; }
2519
2520 var elt = (void 0);
2521 if (allowEmpty && this$1.type === types.comma)
2522 { elt = null; }
2523 else if (this$1.type === types.ellipsis) {
2524 elt = this$1.parseSpread(refDestructuringErrors);
2525 if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
2526 { refDestructuringErrors.trailingComma = this$1.start; }
2527 } else {
2528 elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
2529 }
2530 elts.push(elt);
2531 }
2532 return elts
2533};
2534
2535// Parse the next token as an identifier. If `liberal` is true (used
2536// when parsing properties), it will also convert keywords into
2537// identifiers.
2538
2539pp$3.checkUnreserved = function(ref) {
2540 var start = ref.start;
2541 var end = ref.end;
2542 var name = ref.name;
2543
2544 if (this.inGenerator && name === "yield")
2545 { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
2546 if (this.inAsync && name === "await")
2547 { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
2548 if (this.isKeyword(name))
2549 { this.raise(start, ("Unexpected keyword '" + name + "'")); }
2550 if (this.options.ecmaVersion < 6 &&
2551 this.input.slice(start, end).indexOf("\\") != -1) { return }
2552 var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
2553 if (re.test(name))
2554 { this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved")); }
2555};
2556
2557pp$3.parseIdent = function(liberal, isBinding) {
2558 var node = this.startNode();
2559 if (liberal && this.options.allowReserved == "never") { liberal = false; }
2560 if (this.type === types.name) {
2561 node.name = this.value;
2562 } else if (this.type.keyword) {
2563 node.name = this.type.keyword;
2564 } else {
2565 this.unexpected();
2566 }
2567 this.next();
2568 this.finishNode(node, "Identifier");
2569 if (!liberal) { this.checkUnreserved(node); }
2570 return node
2571};
2572
2573// Parses yield expression inside generator.
2574
2575pp$3.parseYield = function() {
2576 if (!this.yieldPos) { this.yieldPos = this.start; }
2577
2578 var node = this.startNode();
2579 this.next();
2580 if (this.type == types.semi || this.canInsertSemicolon() || (this.type != types.star && !this.type.startsExpr)) {
2581 node.delegate = false;
2582 node.argument = null;
2583 } else {
2584 node.delegate = this.eat(types.star);
2585 node.argument = this.parseMaybeAssign();
2586 }
2587 return this.finishNode(node, "YieldExpression")
2588};
2589
2590pp$3.parseAwait = function() {
2591 if (!this.awaitPos) { this.awaitPos = this.start; }
2592
2593 var node = this.startNode();
2594 this.next();
2595 node.argument = this.parseMaybeUnary(null, true);
2596 return this.finishNode(node, "AwaitExpression")
2597};
2598
2599var pp$4 = Parser.prototype;
2600
2601// This function is used to raise exceptions on parse errors. It
2602// takes an offset integer (into the current `input`) to indicate
2603// the location of the error, attaches the position to the end
2604// of the error message, and then raises a `SyntaxError` with that
2605// message.
2606
2607pp$4.raise = function(pos, message) {
2608 var loc = getLineInfo(this.input, pos);
2609 message += " (" + loc.line + ":" + loc.column + ")";
2610 var err = new SyntaxError(message);
2611 err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
2612 throw err
2613};
2614
2615pp$4.raiseRecoverable = pp$4.raise;
2616
2617pp$4.curPosition = function() {
2618 if (this.options.locations) {
2619 return new Position(this.curLine, this.pos - this.lineStart)
2620 }
2621};
2622
2623var pp$5 = Parser.prototype;
2624
2625// Object.assign polyfill
2626var assign = Object.assign || function(target) {
2627 var sources = [], len = arguments.length - 1;
2628 while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
2629
2630 for (var i = 0, list = sources; i < list.length; i += 1) {
2631 var source = list[i];
2632
2633 for (var key in source) {
2634 if (has(source, key)) {
2635 target[key] = source[key];
2636 }
2637 }
2638 }
2639 return target
2640};
2641
2642// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
2643
2644pp$5.enterFunctionScope = function() {
2645 // var: a hash of var-declared names in the current lexical scope
2646 // lexical: a hash of lexically-declared names in the current lexical scope
2647 // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
2648 // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
2649 this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
2650};
2651
2652pp$5.exitFunctionScope = function() {
2653 this.scopeStack.pop();
2654};
2655
2656pp$5.enterLexicalScope = function() {
2657 var parentScope = this.scopeStack[this.scopeStack.length - 1];
2658 var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
2659
2660 this.scopeStack.push(childScope);
2661 assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
2662};
2663
2664pp$5.exitLexicalScope = function() {
2665 var childScope = this.scopeStack.pop();
2666 var parentScope = this.scopeStack[this.scopeStack.length - 1];
2667
2668 assign(parentScope.childVar, childScope.var, childScope.childVar);
2669};
2670
2671/**
2672 * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
2673 * in the current lexical scope or any of the parent lexical scopes in this function.
2674 */
2675pp$5.canDeclareVarName = function(name) {
2676 var currentScope = this.scopeStack[this.scopeStack.length - 1];
2677
2678 return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
2679};
2680
2681/**
2682 * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
2683 * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
2684 * any child lexical scopes in this function.
2685 */
2686pp$5.canDeclareLexicalName = function(name) {
2687 var currentScope = this.scopeStack[this.scopeStack.length - 1];
2688
2689 return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
2690};
2691
2692pp$5.declareVarName = function(name) {
2693 this.scopeStack[this.scopeStack.length - 1].var[name] = true;
2694};
2695
2696pp$5.declareLexicalName = function(name) {
2697 this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
2698};
2699
2700var Node = function Node(parser, pos, loc) {
2701 this.type = "";
2702 this.start = pos;
2703 this.end = 0;
2704 if (parser.options.locations)
2705 { this.loc = new SourceLocation(parser, loc); }
2706 if (parser.options.directSourceFile)
2707 { this.sourceFile = parser.options.directSourceFile; }
2708 if (parser.options.ranges)
2709 { this.range = [pos, 0]; }
2710};
2711
2712// Start an AST node, attaching a start offset.
2713
2714var pp$6 = Parser.prototype;
2715
2716pp$6.startNode = function() {
2717 return new Node(this, this.start, this.startLoc)
2718};
2719
2720pp$6.startNodeAt = function(pos, loc) {
2721 return new Node(this, pos, loc)
2722};
2723
2724// Finish an AST node, adding `type` and `end` properties.
2725
2726function finishNodeAt(node, type, pos, loc) {
2727 node.type = type;
2728 node.end = pos;
2729 if (this.options.locations)
2730 { node.loc.end = loc; }
2731 if (this.options.ranges)
2732 { node.range[1] = pos; }
2733 return node
2734}
2735
2736pp$6.finishNode = function(node, type) {
2737 return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
2738};
2739
2740// Finish node at given position
2741
2742pp$6.finishNodeAt = function(node, type, pos, loc) {
2743 return finishNodeAt.call(this, node, type, pos, loc)
2744};
2745
2746// The algorithm used to determine whether a regexp can appear at a
2747// given point in the program is loosely based on sweet.js' approach.
2748// See https://github.com/mozilla/sweet.js/wiki/design
2749
2750var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
2751 this.token = token;
2752 this.isExpr = !!isExpr;
2753 this.preserveSpace = !!preserveSpace;
2754 this.override = override;
2755 this.generator = !!generator;
2756};
2757
2758var types$1 = {
2759 b_stat: new TokContext("{", false),
2760 b_expr: new TokContext("{", true),
2761 b_tmpl: new TokContext("${", false),
2762 p_stat: new TokContext("(", false),
2763 p_expr: new TokContext("(", true),
2764 q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
2765 f_stat: new TokContext("function", false),
2766 f_expr: new TokContext("function", true),
2767 f_expr_gen: new TokContext("function", true, false, null, true),
2768 f_gen: new TokContext("function", false, false, null, true)
2769};
2770
2771var pp$7 = Parser.prototype;
2772
2773pp$7.initialContext = function() {
2774 return [types$1.b_stat]
2775};
2776
2777pp$7.braceIsBlock = function(prevType) {
2778 var parent = this.curContext();
2779 if (parent === types$1.f_expr || parent === types$1.f_stat)
2780 { return true }
2781 if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
2782 { return !parent.isExpr }
2783
2784 // The check for `tt.name && exprAllowed` detects whether we are
2785 // after a `yield` or `of` construct. See the `updateContext` for
2786 // `tt.name`.
2787 if (prevType === types._return || prevType == types.name && this.exprAllowed)
2788 { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
2789 if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType == types.arrow)
2790 { return true }
2791 if (prevType == types.braceL)
2792 { return parent === types$1.b_stat }
2793 if (prevType == types._var || prevType == types.name)
2794 { return false }
2795 return !this.exprAllowed
2796};
2797
2798pp$7.inGeneratorContext = function() {
2799 var this$1 = this;
2800
2801 for (var i = this.context.length - 1; i >= 1; i--) {
2802 var context = this$1.context[i];
2803 if (context.token === "function")
2804 { return context.generator }
2805 }
2806 return false
2807};
2808
2809pp$7.updateContext = function(prevType) {
2810 var update, type = this.type;
2811 if (type.keyword && prevType == types.dot)
2812 { this.exprAllowed = false; }
2813 else if (update = type.updateContext)
2814 { update.call(this, prevType); }
2815 else
2816 { this.exprAllowed = type.beforeExpr; }
2817};
2818
2819// Token-specific context update code
2820
2821types.parenR.updateContext = types.braceR.updateContext = function() {
2822 if (this.context.length == 1) {
2823 this.exprAllowed = true;
2824 return
2825 }
2826 var out = this.context.pop();
2827 if (out === types$1.b_stat && this.curContext().token === "function") {
2828 out = this.context.pop();
2829 }
2830 this.exprAllowed = !out.isExpr;
2831};
2832
2833types.braceL.updateContext = function(prevType) {
2834 this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
2835 this.exprAllowed = true;
2836};
2837
2838types.dollarBraceL.updateContext = function() {
2839 this.context.push(types$1.b_tmpl);
2840 this.exprAllowed = true;
2841};
2842
2843types.parenL.updateContext = function(prevType) {
2844 var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
2845 this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
2846 this.exprAllowed = true;
2847};
2848
2849types.incDec.updateContext = function() {
2850 // tokExprAllowed stays unchanged
2851};
2852
2853types._function.updateContext = types._class.updateContext = function(prevType) {
2854 if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
2855 !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
2856 { this.context.push(types$1.f_expr); }
2857 else
2858 { this.context.push(types$1.f_stat); }
2859 this.exprAllowed = false;
2860};
2861
2862types.backQuote.updateContext = function() {
2863 if (this.curContext() === types$1.q_tmpl)
2864 { this.context.pop(); }
2865 else
2866 { this.context.push(types$1.q_tmpl); }
2867 this.exprAllowed = false;
2868};
2869
2870types.star.updateContext = function(prevType) {
2871 if (prevType == types._function) {
2872 var index = this.context.length - 1;
2873 if (this.context[index] === types$1.f_expr)
2874 { this.context[index] = types$1.f_expr_gen; }
2875 else
2876 { this.context[index] = types$1.f_gen; }
2877 }
2878 this.exprAllowed = true;
2879};
2880
2881types.name.updateContext = function(prevType) {
2882 var allowed = false;
2883 if (this.options.ecmaVersion >= 6) {
2884 if (this.value == "of" && !this.exprAllowed ||
2885 this.value == "yield" && this.inGeneratorContext())
2886 { allowed = true; }
2887 }
2888 this.exprAllowed = allowed;
2889};
2890
2891// Object type used to represent tokens. Note that normally, tokens
2892// simply exist as properties on the parser object. This is only
2893// used for the onToken callback and the external tokenizer.
2894
2895var Token = function Token(p) {
2896 this.type = p.type;
2897 this.value = p.value;
2898 this.start = p.start;
2899 this.end = p.end;
2900 if (p.options.locations)
2901 { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
2902 if (p.options.ranges)
2903 { this.range = [p.start, p.end]; }
2904};
2905
2906// ## Tokenizer
2907
2908var pp$8 = Parser.prototype;
2909
2910// Are we running under Rhino?
2911var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
2912
2913// Move to the next token
2914
2915pp$8.next = function() {
2916 if (this.options.onToken)
2917 { this.options.onToken(new Token(this)); }
2918
2919 this.lastTokEnd = this.end;
2920 this.lastTokStart = this.start;
2921 this.lastTokEndLoc = this.endLoc;
2922 this.lastTokStartLoc = this.startLoc;
2923 this.nextToken();
2924};
2925
2926pp$8.getToken = function() {
2927 this.next();
2928 return new Token(this)
2929};
2930
2931// If we're in an ES6 environment, make parsers iterable
2932if (typeof Symbol !== "undefined")
2933 { pp$8[Symbol.iterator] = function() {
2934 var this$1 = this;
2935
2936 return {
2937 next: function () {
2938 var token = this$1.getToken();
2939 return {
2940 done: token.type === types.eof,
2941 value: token
2942 }
2943 }
2944 }
2945 }; }
2946
2947// Toggle strict mode. Re-reads the next number or string to please
2948// pedantic tests (`"use strict"; 010;` should fail).
2949
2950pp$8.curContext = function() {
2951 return this.context[this.context.length - 1]
2952};
2953
2954// Read a single token, updating the parser object's token-related
2955// properties.
2956
2957pp$8.nextToken = function() {
2958 var curContext = this.curContext();
2959 if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
2960
2961 this.start = this.pos;
2962 if (this.options.locations) { this.startLoc = this.curPosition(); }
2963 if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
2964
2965 if (curContext.override) { return curContext.override(this) }
2966 else { this.readToken(this.fullCharCodeAtPos()); }
2967};
2968
2969pp$8.readToken = function(code) {
2970 // Identifier or keyword. '\uXXXX' sequences are allowed in
2971 // identifiers, so '\' also dispatches to that.
2972 if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
2973 { return this.readWord() }
2974
2975 return this.getTokenFromCode(code)
2976};
2977
2978pp$8.fullCharCodeAtPos = function() {
2979 var code = this.input.charCodeAt(this.pos);
2980 if (code <= 0xd7ff || code >= 0xe000) { return code }
2981 var next = this.input.charCodeAt(this.pos + 1);
2982 return (code << 10) + next - 0x35fdc00
2983};
2984
2985pp$8.skipBlockComment = function() {
2986 var this$1 = this;
2987
2988 var startLoc = this.options.onComment && this.curPosition();
2989 var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
2990 if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
2991 this.pos = end + 2;
2992 if (this.options.locations) {
2993 lineBreakG.lastIndex = start;
2994 var match;
2995 while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
2996 ++this$1.curLine;
2997 this$1.lineStart = match.index + match[0].length;
2998 }
2999 }
3000 if (this.options.onComment)
3001 { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
3002 startLoc, this.curPosition()); }
3003};
3004
3005pp$8.skipLineComment = function(startSkip) {
3006 var this$1 = this;
3007
3008 var start = this.pos;
3009 var startLoc = this.options.onComment && this.curPosition();
3010 var ch = this.input.charCodeAt(this.pos += startSkip);
3011 while (this.pos < this.input.length && !isNewLine(ch)) {
3012 ch = this$1.input.charCodeAt(++this$1.pos);
3013 }
3014 if (this.options.onComment)
3015 { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
3016 startLoc, this.curPosition()); }
3017};
3018
3019// Called at the start of the parse and after every token. Skips
3020// whitespace and comments, and.
3021
3022pp$8.skipSpace = function() {
3023 var this$1 = this;
3024
3025 loop: while (this.pos < this.input.length) {
3026 var ch = this$1.input.charCodeAt(this$1.pos);
3027 switch (ch) {
3028 case 32: case 160: // ' '
3029 ++this$1.pos;
3030 break
3031 case 13:
3032 if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
3033 ++this$1.pos;
3034 }
3035 case 10: case 8232: case 8233:
3036 ++this$1.pos;
3037 if (this$1.options.locations) {
3038 ++this$1.curLine;
3039 this$1.lineStart = this$1.pos;
3040 }
3041 break
3042 case 47: // '/'
3043 switch (this$1.input.charCodeAt(this$1.pos + 1)) {
3044 case 42: // '*'
3045 this$1.skipBlockComment();
3046 break
3047 case 47:
3048 this$1.skipLineComment(2);
3049 break
3050 default:
3051 break loop
3052 }
3053 break
3054 default:
3055 if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
3056 ++this$1.pos;
3057 } else {
3058 break loop
3059 }
3060 }
3061 }
3062};
3063
3064// Called at the end of every token. Sets `end`, `val`, and
3065// maintains `context` and `exprAllowed`, and skips the space after
3066// the token, so that the next one's `start` will point at the
3067// right position.
3068
3069pp$8.finishToken = function(type, val) {
3070 this.end = this.pos;
3071 if (this.options.locations) { this.endLoc = this.curPosition(); }
3072 var prevType = this.type;
3073 this.type = type;
3074 this.value = val;
3075
3076 this.updateContext(prevType);
3077};
3078
3079// ### Token reading
3080
3081// This is the function that is called to fetch the next token. It
3082// is somewhat obscure, because it works in character codes rather
3083// than characters, and because operator parsing has been inlined
3084// into it.
3085//
3086// All in the name of speed.
3087//
3088pp$8.readToken_dot = function() {
3089 var next = this.input.charCodeAt(this.pos + 1);
3090 if (next >= 48 && next <= 57) { return this.readNumber(true) }
3091 var next2 = this.input.charCodeAt(this.pos + 2);
3092 if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
3093 this.pos += 3;
3094 return this.finishToken(types.ellipsis)
3095 } else {
3096 ++this.pos;
3097 return this.finishToken(types.dot)
3098 }
3099};
3100
3101pp$8.readToken_slash = function() { // '/'
3102 var next = this.input.charCodeAt(this.pos + 1);
3103 if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
3104 if (next === 61) { return this.finishOp(types.assign, 2) }
3105 return this.finishOp(types.slash, 1)
3106};
3107
3108pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
3109 var next = this.input.charCodeAt(this.pos + 1);
3110 var size = 1;
3111 var tokentype = code === 42 ? types.star : types.modulo;
3112
3113 // exponentiation operator ** and **=
3114 if (this.options.ecmaVersion >= 7 && next === 42) {
3115 ++size;
3116 tokentype = types.starstar;
3117 next = this.input.charCodeAt(this.pos + 2);
3118 }
3119
3120 if (next === 61) { return this.finishOp(types.assign, size + 1) }
3121 return this.finishOp(tokentype, size)
3122};
3123
3124pp$8.readToken_pipe_amp = function(code) { // '|&'
3125 var next = this.input.charCodeAt(this.pos + 1);
3126 if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
3127 if (next === 61) { return this.finishOp(types.assign, 2) }
3128 return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
3129};
3130
3131pp$8.readToken_caret = function() { // '^'
3132 var next = this.input.charCodeAt(this.pos + 1);
3133 if (next === 61) { return this.finishOp(types.assign, 2) }
3134 return this.finishOp(types.bitwiseXOR, 1)
3135};
3136
3137pp$8.readToken_plus_min = function(code) { // '+-'
3138 var next = this.input.charCodeAt(this.pos + 1);
3139 if (next === code) {
3140 if (next == 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 62 &&
3141 (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
3142 // A `-->` line comment
3143 this.skipLineComment(3);
3144 this.skipSpace();
3145 return this.nextToken()
3146 }
3147 return this.finishOp(types.incDec, 2)
3148 }
3149 if (next === 61) { return this.finishOp(types.assign, 2) }
3150 return this.finishOp(types.plusMin, 1)
3151};
3152
3153pp$8.readToken_lt_gt = function(code) { // '<>'
3154 var next = this.input.charCodeAt(this.pos + 1);
3155 var size = 1;
3156 if (next === code) {
3157 size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
3158 if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
3159 return this.finishOp(types.bitShift, size)
3160 }
3161 if (next == 33 && code == 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 45 &&
3162 this.input.charCodeAt(this.pos + 3) == 45) {
3163 // `<!--`, an XML-style comment that should be interpreted as a line comment
3164 this.skipLineComment(4);
3165 this.skipSpace();
3166 return this.nextToken()
3167 }
3168 if (next === 61) { size = 2; }
3169 return this.finishOp(types.relational, size)
3170};
3171
3172pp$8.readToken_eq_excl = function(code) { // '=!'
3173 var next = this.input.charCodeAt(this.pos + 1);
3174 if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
3175 if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
3176 this.pos += 2;
3177 return this.finishToken(types.arrow)
3178 }
3179 return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
3180};
3181
3182pp$8.getTokenFromCode = function(code) {
3183 switch (code) {
3184 // The interpretation of a dot depends on whether it is followed
3185 // by a digit or another two dots.
3186 case 46: // '.'
3187 return this.readToken_dot()
3188
3189 // Punctuation tokens.
3190 case 40: ++this.pos; return this.finishToken(types.parenL)
3191 case 41: ++this.pos; return this.finishToken(types.parenR)
3192 case 59: ++this.pos; return this.finishToken(types.semi)
3193 case 44: ++this.pos; return this.finishToken(types.comma)
3194 case 91: ++this.pos; return this.finishToken(types.bracketL)
3195 case 93: ++this.pos; return this.finishToken(types.bracketR)
3196 case 123: ++this.pos; return this.finishToken(types.braceL)
3197 case 125: ++this.pos; return this.finishToken(types.braceR)
3198 case 58: ++this.pos; return this.finishToken(types.colon)
3199 case 63: ++this.pos; return this.finishToken(types.question)
3200
3201 case 96: // '`'
3202 if (this.options.ecmaVersion < 6) { break }
3203 ++this.pos;
3204 return this.finishToken(types.backQuote)
3205
3206 case 48: // '0'
3207 var next = this.input.charCodeAt(this.pos + 1);
3208 if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
3209 if (this.options.ecmaVersion >= 6) {
3210 if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
3211 if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
3212 }
3213 // Anything else beginning with a digit is an integer, octal
3214 // number, or float.
3215 case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
3216 return this.readNumber(false)
3217
3218 // Quotes produce strings.
3219 case 34: case 39: // '"', "'"
3220 return this.readString(code)
3221
3222 // Operators are parsed inline in tiny state machines. '=' (61) is
3223 // often referred to. `finishOp` simply skips the amount of
3224 // characters it is given as second argument, and returns a token
3225 // of the type given by its first argument.
3226
3227 case 47: // '/'
3228 return this.readToken_slash()
3229
3230 case 37: case 42: // '%*'
3231 return this.readToken_mult_modulo_exp(code)
3232
3233 case 124: case 38: // '|&'
3234 return this.readToken_pipe_amp(code)
3235
3236 case 94: // '^'
3237 return this.readToken_caret()
3238
3239 case 43: case 45: // '+-'
3240 return this.readToken_plus_min(code)
3241
3242 case 60: case 62: // '<>'
3243 return this.readToken_lt_gt(code)
3244
3245 case 61: case 33: // '=!'
3246 return this.readToken_eq_excl(code)
3247
3248 case 126: // '~'
3249 return this.finishOp(types.prefix, 1)
3250 }
3251
3252 this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
3253};
3254
3255pp$8.finishOp = function(type, size) {
3256 var str = this.input.slice(this.pos, this.pos + size);
3257 this.pos += size;
3258 return this.finishToken(type, str)
3259};
3260
3261// Parse a regular expression. Some context-awareness is necessary,
3262// since a '/' inside a '[]' set does not end the expression.
3263
3264function tryCreateRegexp(src, flags, throwErrorAt, parser) {
3265 try {
3266 return new RegExp(src, flags)
3267 } catch (e) {
3268 if (throwErrorAt !== undefined) {
3269 if (e instanceof SyntaxError) { parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message); }
3270 throw e
3271 }
3272 }
3273}
3274
3275var regexpUnicodeSupport = !!tryCreateRegexp("\uffff", "u");
3276
3277pp$8.readRegexp = function() {
3278 var this$1 = this;
3279
3280 var escaped, inClass, start = this.pos;
3281 for (;;) {
3282 if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
3283 var ch = this$1.input.charAt(this$1.pos);
3284 if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
3285 if (!escaped) {
3286 if (ch === "[") { inClass = true; }
3287 else if (ch === "]" && inClass) { inClass = false; }
3288 else if (ch === "/" && !inClass) { break }
3289 escaped = ch === "\\";
3290 } else { escaped = false; }
3291 ++this$1.pos;
3292 }
3293 var content = this.input.slice(start, this.pos);
3294 ++this.pos;
3295 // Need to use `readWord1` because '\uXXXX' sequences are allowed
3296 // here (don't ask).
3297 var mods = this.readWord1();
3298 var tmp = content, tmpFlags = "";
3299 if (mods) {
3300 var validFlags = /^[gim]*$/;
3301 if (this.options.ecmaVersion >= 6) { validFlags = /^[gimuy]*$/; }
3302 if (!validFlags.test(mods)) { this.raise(start, "Invalid regular expression flag"); }
3303 if (mods.indexOf("u") >= 0) {
3304 if (regexpUnicodeSupport) {
3305 tmpFlags = "u";
3306 } else {
3307 // Replace each astral symbol and every Unicode escape sequence that
3308 // possibly represents an astral symbol or a paired surrogate with a
3309 // single ASCII symbol to avoid throwing on regular expressions that
3310 // are only valid in combination with the `/u` flag.
3311 // Note: replacing with the ASCII symbol `x` might cause false
3312 // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
3313 // perfectly valid pattern that is equivalent to `[a-b]`, but it would
3314 // be replaced by `[x-b]` which throws an error.
3315 tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
3316 code = Number("0x" + code);
3317 if (code > 0x10FFFF) { this$1.raise(start + offset + 3, "Code point out of bounds"); }
3318 return "x"
3319 });
3320 tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
3321 tmpFlags = tmpFlags.replace("u", "");
3322 }
3323 }
3324 }
3325 // Detect invalid regular expressions.
3326 var value = null;
3327 // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
3328 // so don't do detection if we are running under Rhino
3329 if (!isRhino) {
3330 tryCreateRegexp(tmp, tmpFlags, start, this);
3331 // Get a regular expression object for this pattern-flag pair, or `null` in
3332 // case the current environment doesn't support the flags it uses.
3333 value = tryCreateRegexp(content, mods);
3334 }
3335 return this.finishToken(types.regexp, {pattern: content, flags: mods, value: value})
3336};
3337
3338// Read an integer in the given radix. Return null if zero digits
3339// were read, the integer value otherwise. When `len` is given, this
3340// will return `null` unless the integer has exactly `len` digits.
3341
3342pp$8.readInt = function(radix, len) {
3343 var this$1 = this;
3344
3345 var start = this.pos, total = 0;
3346 for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
3347 var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
3348 if (code >= 97) { val = code - 97 + 10; } // a
3349 else if (code >= 65) { val = code - 65 + 10; } // A
3350 else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
3351 else { val = Infinity; }
3352 if (val >= radix) { break }
3353 ++this$1.pos;
3354 total = total * radix + val;
3355 }
3356 if (this.pos === start || len != null && this.pos - start !== len) { return null }
3357
3358 return total
3359};
3360
3361pp$8.readRadixNumber = function(radix) {
3362 this.pos += 2; // 0x
3363 var val = this.readInt(radix);
3364 if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
3365 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
3366 return this.finishToken(types.num, val)
3367};
3368
3369// Read an integer, octal integer, or floating-point number.
3370
3371pp$8.readNumber = function(startsWithDot) {
3372 var start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48;
3373 if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
3374 if (octal && this.pos == start + 1) { octal = false; }
3375 var next = this.input.charCodeAt(this.pos);
3376 if (next === 46 && !octal) { // '.'
3377 ++this.pos;
3378 this.readInt(10);
3379 isFloat = true;
3380 next = this.input.charCodeAt(this.pos);
3381 }
3382 if ((next === 69 || next === 101) && !octal) { // 'eE'
3383 next = this.input.charCodeAt(++this.pos);
3384 if (next === 43 || next === 45) { ++this.pos; } // '+-'
3385 if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
3386 isFloat = true;
3387 }
3388 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
3389
3390 var str = this.input.slice(start, this.pos), val;
3391 if (isFloat) { val = parseFloat(str); }
3392 else if (!octal || str.length === 1) { val = parseInt(str, 10); }
3393 else if (this.strict) { this.raise(start, "Invalid number"); }
3394 else if (/[89]/.test(str)) { val = parseInt(str, 10); }
3395 else { val = parseInt(str, 8); }
3396 return this.finishToken(types.num, val)
3397};
3398
3399// Read a string value, interpreting backslash-escapes.
3400
3401pp$8.readCodePoint = function() {
3402 var ch = this.input.charCodeAt(this.pos), code;
3403
3404 if (ch === 123) { // '{'
3405 if (this.options.ecmaVersion < 6) { this.unexpected(); }
3406 var codePos = ++this.pos;
3407 code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
3408 ++this.pos;
3409 if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
3410 } else {
3411 code = this.readHexChar(4);
3412 }
3413 return code
3414};
3415
3416function codePointToString(code) {
3417 // UTF-16 Decoding
3418 if (code <= 0xFFFF) { return String.fromCharCode(code) }
3419 code -= 0x10000;
3420 return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
3421}
3422
3423pp$8.readString = function(quote) {
3424 var this$1 = this;
3425
3426 var out = "", chunkStart = ++this.pos;
3427 for (;;) {
3428 if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
3429 var ch = this$1.input.charCodeAt(this$1.pos);
3430 if (ch === quote) { break }
3431 if (ch === 92) { // '\'
3432 out += this$1.input.slice(chunkStart, this$1.pos);
3433 out += this$1.readEscapedChar(false);
3434 chunkStart = this$1.pos;
3435 } else {
3436 if (isNewLine(ch)) { this$1.raise(this$1.start, "Unterminated string constant"); }
3437 ++this$1.pos;
3438 }
3439 }
3440 out += this.input.slice(chunkStart, this.pos++);
3441 return this.finishToken(types.string, out)
3442};
3443
3444// Reads template string tokens.
3445
3446var INVALID_TEMPLATE_ESCAPE_ERROR = {};
3447
3448pp$8.tryReadTemplateToken = function() {
3449 this.inTemplateElement = true;
3450 try {
3451 this.readTmplToken();
3452 } catch (err) {
3453 if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
3454 this.readInvalidTemplateToken();
3455 } else {
3456 throw err
3457 }
3458 }
3459
3460 this.inTemplateElement = false;
3461};
3462
3463pp$8.invalidStringToken = function(position, message) {
3464 if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
3465 throw INVALID_TEMPLATE_ESCAPE_ERROR
3466 } else {
3467 this.raise(position, message);
3468 }
3469};
3470
3471pp$8.readTmplToken = function() {
3472 var this$1 = this;
3473
3474 var out = "", chunkStart = this.pos;
3475 for (;;) {
3476 if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
3477 var ch = this$1.input.charCodeAt(this$1.pos);
3478 if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
3479 if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
3480 if (ch === 36) {
3481 this$1.pos += 2;
3482 return this$1.finishToken(types.dollarBraceL)
3483 } else {
3484 ++this$1.pos;
3485 return this$1.finishToken(types.backQuote)
3486 }
3487 }
3488 out += this$1.input.slice(chunkStart, this$1.pos);
3489 return this$1.finishToken(types.template, out)
3490 }
3491 if (ch === 92) { // '\'
3492 out += this$1.input.slice(chunkStart, this$1.pos);
3493 out += this$1.readEscapedChar(true);
3494 chunkStart = this$1.pos;
3495 } else if (isNewLine(ch)) {
3496 out += this$1.input.slice(chunkStart, this$1.pos);
3497 ++this$1.pos;
3498 switch (ch) {
3499 case 13:
3500 if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
3501 case 10:
3502 out += "\n";
3503 break
3504 default:
3505 out += String.fromCharCode(ch);
3506 break
3507 }
3508 if (this$1.options.locations) {
3509 ++this$1.curLine;
3510 this$1.lineStart = this$1.pos;
3511 }
3512 chunkStart = this$1.pos;
3513 } else {
3514 ++this$1.pos;
3515 }
3516 }
3517};
3518
3519// Reads a template token to search for the end, without validating any escape sequences
3520pp$8.readInvalidTemplateToken = function() {
3521 var this$1 = this;
3522
3523 for (; this.pos < this.input.length; this.pos++) {
3524 switch (this$1.input[this$1.pos]) {
3525 case "\\":
3526 ++this$1.pos;
3527 break
3528
3529 case "$":
3530 if (this$1.input[this$1.pos + 1] !== "{") {
3531 break
3532 }
3533 // falls through
3534
3535 case "`":
3536 return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
3537
3538 // no default
3539 }
3540 }
3541 this.raise(this.start, "Unterminated template");
3542};
3543
3544// Used to read escaped characters
3545
3546pp$8.readEscapedChar = function(inTemplate) {
3547 var ch = this.input.charCodeAt(++this.pos);
3548 ++this.pos;
3549 switch (ch) {
3550 case 110: return "\n" // 'n' -> '\n'
3551 case 114: return "\r" // 'r' -> '\r'
3552 case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
3553 case 117: return codePointToString(this.readCodePoint()) // 'u'
3554 case 116: return "\t" // 't' -> '\t'
3555 case 98: return "\b" // 'b' -> '\b'
3556 case 118: return "\u000b" // 'v' -> '\u000b'
3557 case 102: return "\f" // 'f' -> '\f'
3558 case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
3559 case 10: // ' \n'
3560 if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
3561 return ""
3562 default:
3563 if (ch >= 48 && ch <= 55) {
3564 var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
3565 var octal = parseInt(octalStr, 8);
3566 if (octal > 255) {
3567 octalStr = octalStr.slice(0, -1);
3568 octal = parseInt(octalStr, 8);
3569 }
3570 if (octalStr !== "0" && (this.strict || inTemplate)) {
3571 this.invalidStringToken(this.pos - 2, "Octal literal in strict mode");
3572 }
3573 this.pos += octalStr.length - 1;
3574 return String.fromCharCode(octal)
3575 }
3576 return String.fromCharCode(ch)
3577 }
3578};
3579
3580// Used to read character escape sequences ('\x', '\u', '\U').
3581
3582pp$8.readHexChar = function(len) {
3583 var codePos = this.pos;
3584 var n = this.readInt(16, len);
3585 if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
3586 return n
3587};
3588
3589// Read an identifier, and return it as a string. Sets `this.containsEsc`
3590// to whether the word contained a '\u' escape.
3591//
3592// Incrementally adds only escaped chars, adding other chunks as-is
3593// as a micro-optimization.
3594
3595pp$8.readWord1 = function() {
3596 var this$1 = this;
3597
3598 this.containsEsc = false;
3599 var word = "", first = true, chunkStart = this.pos;
3600 var astral = this.options.ecmaVersion >= 6;
3601 while (this.pos < this.input.length) {
3602 var ch = this$1.fullCharCodeAtPos();
3603 if (isIdentifierChar(ch, astral)) {
3604 this$1.pos += ch <= 0xffff ? 1 : 2;
3605 } else if (ch === 92) { // "\"
3606 this$1.containsEsc = true;
3607 word += this$1.input.slice(chunkStart, this$1.pos);
3608 var escStart = this$1.pos;
3609 if (this$1.input.charCodeAt(++this$1.pos) != 117) // "u"
3610 { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
3611 ++this$1.pos;
3612 var esc = this$1.readCodePoint();
3613 if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
3614 { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
3615 word += codePointToString(esc);
3616 chunkStart = this$1.pos;
3617 } else {
3618 break
3619 }
3620 first = false;
3621 }
3622 return word + this.input.slice(chunkStart, this.pos)
3623};
3624
3625// Read an identifier or keyword token. Will check for reserved
3626// words when necessary.
3627
3628pp$8.readWord = function() {
3629 var word = this.readWord1();
3630 var type = types.name;
3631 if (this.keywords.test(word)) {
3632 if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
3633 type = keywords$1[word];
3634 }
3635 return this.finishToken(type, word)
3636};
3637
3638// Acorn is a tiny, fast JavaScript parser written in JavaScript.
3639//
3640// Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
3641// various contributors and released under an MIT license.
3642//
3643// Git repositories for Acorn are available at
3644//
3645// http://marijnhaverbeke.nl/git/acorn
3646// https://github.com/ternjs/acorn.git
3647//
3648// Please use the [github bug tracker][ghbt] to report issues.
3649//
3650// [ghbt]: https://github.com/ternjs/acorn/issues
3651//
3652// This file defines the main parser interface. The library also comes
3653// with a [error-tolerant parser][dammit] and an
3654// [abstract syntax tree walker][walk], defined in other files.
3655//
3656// [dammit]: acorn_loose.js
3657// [walk]: util/walk.js
3658
3659var version = "5.1.2";
3660
3661// The main exported interface (under `self.acorn` when in the
3662// browser) is a `parse` function that takes a code string and
3663// returns an abstract syntax tree as specified by [Mozilla parser
3664// API][api].
3665//
3666// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
3667
3668function parse$1(input, options) {
3669 return new Parser(options, input).parse()
3670}
3671
3672// This function tries to parse a single expression at a given
3673// offset in a string. Useful for parsing mixed-language formats
3674// that embed JavaScript expressions.
3675
3676function parseExpressionAt(input, pos, options) {
3677 var p = new Parser(options, input, pos);
3678 p.nextToken();
3679 return p.parseExpression()
3680}
3681
3682// Acorn is organized as a tokenizer and a recursive-descent parser.
3683// The `tokenizer` export provides an interface to the tokenizer.
3684
3685function tokenizer(input, options) {
3686 return new Parser(options, input)
3687}
3688
3689// This is a terrible kludge to support the existing, pre-ES6
3690// interface where the loose parser module retroactively adds exports
3691// to this module.
3692var parse_dammit;
3693var LooseParser;
3694var pluginsLoose; // eslint-disable-line camelcase
3695function addLooseExports(parse, Parser$$1, plugins$$1) {
3696 parse_dammit = parse; // eslint-disable-line camelcase
3697 LooseParser = Parser$$1;
3698 pluginsLoose = plugins$$1;
3699}
3700
3701
3702
3703
3704var acorn = Object.freeze({
3705 version: version,
3706 parse: parse$1,
3707 parseExpressionAt: parseExpressionAt,
3708 tokenizer: tokenizer,
3709 get parse_dammit () { return parse_dammit; },
3710 get LooseParser () { return LooseParser; },
3711 get pluginsLoose () { return pluginsLoose; },
3712 addLooseExports: addLooseExports,
3713 Parser: Parser,
3714 plugins: plugins,
3715 defaultOptions: defaultOptions,
3716 Position: Position,
3717 SourceLocation: SourceLocation,
3718 getLineInfo: getLineInfo,
3719 Node: Node,
3720 TokenType: TokenType,
3721 tokTypes: types,
3722 keywordTypes: keywords$1,
3723 TokContext: TokContext,
3724 tokContexts: types$1,
3725 isIdentifierChar: isIdentifierChar,
3726 isIdentifierStart: isIdentifierStart,
3727 Token: Token,
3728 isNewLine: isNewLine,
3729 lineBreak: lineBreak,
3730 lineBreakG: lineBreakG,
3731 nonASCIIwhitespace: nonASCIIwhitespace
3732});
3733
3734var xhtml = {
3735 quot: '\u0022',
3736 amp: '&',
3737 apos: '\u0027',
3738 lt: '<',
3739 gt: '>',
3740 nbsp: '\u00A0',
3741 iexcl: '\u00A1',
3742 cent: '\u00A2',
3743 pound: '\u00A3',
3744 curren: '\u00A4',
3745 yen: '\u00A5',
3746 brvbar: '\u00A6',
3747 sect: '\u00A7',
3748 uml: '\u00A8',
3749 copy: '\u00A9',
3750 ordf: '\u00AA',
3751 laquo: '\u00AB',
3752 not: '\u00AC',
3753 shy: '\u00AD',
3754 reg: '\u00AE',
3755 macr: '\u00AF',
3756 deg: '\u00B0',
3757 plusmn: '\u00B1',
3758 sup2: '\u00B2',
3759 sup3: '\u00B3',
3760 acute: '\u00B4',
3761 micro: '\u00B5',
3762 para: '\u00B6',
3763 middot: '\u00B7',
3764 cedil: '\u00B8',
3765 sup1: '\u00B9',
3766 ordm: '\u00BA',
3767 raquo: '\u00BB',
3768 frac14: '\u00BC',
3769 frac12: '\u00BD',
3770 frac34: '\u00BE',
3771 iquest: '\u00BF',
3772 Agrave: '\u00C0',
3773 Aacute: '\u00C1',
3774 Acirc: '\u00C2',
3775 Atilde: '\u00C3',
3776 Auml: '\u00C4',
3777 Aring: '\u00C5',
3778 AElig: '\u00C6',
3779 Ccedil: '\u00C7',
3780 Egrave: '\u00C8',
3781 Eacute: '\u00C9',
3782 Ecirc: '\u00CA',
3783 Euml: '\u00CB',
3784 Igrave: '\u00CC',
3785 Iacute: '\u00CD',
3786 Icirc: '\u00CE',
3787 Iuml: '\u00CF',
3788 ETH: '\u00D0',
3789 Ntilde: '\u00D1',
3790 Ograve: '\u00D2',
3791 Oacute: '\u00D3',
3792 Ocirc: '\u00D4',
3793 Otilde: '\u00D5',
3794 Ouml: '\u00D6',
3795 times: '\u00D7',
3796 Oslash: '\u00D8',
3797 Ugrave: '\u00D9',
3798 Uacute: '\u00DA',
3799 Ucirc: '\u00DB',
3800 Uuml: '\u00DC',
3801 Yacute: '\u00DD',
3802 THORN: '\u00DE',
3803 szlig: '\u00DF',
3804 agrave: '\u00E0',
3805 aacute: '\u00E1',
3806 acirc: '\u00E2',
3807 atilde: '\u00E3',
3808 auml: '\u00E4',
3809 aring: '\u00E5',
3810 aelig: '\u00E6',
3811 ccedil: '\u00E7',
3812 egrave: '\u00E8',
3813 eacute: '\u00E9',
3814 ecirc: '\u00EA',
3815 euml: '\u00EB',
3816 igrave: '\u00EC',
3817 iacute: '\u00ED',
3818 icirc: '\u00EE',
3819 iuml: '\u00EF',
3820 eth: '\u00F0',
3821 ntilde: '\u00F1',
3822 ograve: '\u00F2',
3823 oacute: '\u00F3',
3824 ocirc: '\u00F4',
3825 otilde: '\u00F5',
3826 ouml: '\u00F6',
3827 divide: '\u00F7',
3828 oslash: '\u00F8',
3829 ugrave: '\u00F9',
3830 uacute: '\u00FA',
3831 ucirc: '\u00FB',
3832 uuml: '\u00FC',
3833 yacute: '\u00FD',
3834 thorn: '\u00FE',
3835 yuml: '\u00FF',
3836 OElig: '\u0152',
3837 oelig: '\u0153',
3838 Scaron: '\u0160',
3839 scaron: '\u0161',
3840 Yuml: '\u0178',
3841 fnof: '\u0192',
3842 circ: '\u02C6',
3843 tilde: '\u02DC',
3844 Alpha: '\u0391',
3845 Beta: '\u0392',
3846 Gamma: '\u0393',
3847 Delta: '\u0394',
3848 Epsilon: '\u0395',
3849 Zeta: '\u0396',
3850 Eta: '\u0397',
3851 Theta: '\u0398',
3852 Iota: '\u0399',
3853 Kappa: '\u039A',
3854 Lambda: '\u039B',
3855 Mu: '\u039C',
3856 Nu: '\u039D',
3857 Xi: '\u039E',
3858 Omicron: '\u039F',
3859 Pi: '\u03A0',
3860 Rho: '\u03A1',
3861 Sigma: '\u03A3',
3862 Tau: '\u03A4',
3863 Upsilon: '\u03A5',
3864 Phi: '\u03A6',
3865 Chi: '\u03A7',
3866 Psi: '\u03A8',
3867 Omega: '\u03A9',
3868 alpha: '\u03B1',
3869 beta: '\u03B2',
3870 gamma: '\u03B3',
3871 delta: '\u03B4',
3872 epsilon: '\u03B5',
3873 zeta: '\u03B6',
3874 eta: '\u03B7',
3875 theta: '\u03B8',
3876 iota: '\u03B9',
3877 kappa: '\u03BA',
3878 lambda: '\u03BB',
3879 mu: '\u03BC',
3880 nu: '\u03BD',
3881 xi: '\u03BE',
3882 omicron: '\u03BF',
3883 pi: '\u03C0',
3884 rho: '\u03C1',
3885 sigmaf: '\u03C2',
3886 sigma: '\u03C3',
3887 tau: '\u03C4',
3888 upsilon: '\u03C5',
3889 phi: '\u03C6',
3890 chi: '\u03C7',
3891 psi: '\u03C8',
3892 omega: '\u03C9',
3893 thetasym: '\u03D1',
3894 upsih: '\u03D2',
3895 piv: '\u03D6',
3896 ensp: '\u2002',
3897 emsp: '\u2003',
3898 thinsp: '\u2009',
3899 zwnj: '\u200C',
3900 zwj: '\u200D',
3901 lrm: '\u200E',
3902 rlm: '\u200F',
3903 ndash: '\u2013',
3904 mdash: '\u2014',
3905 lsquo: '\u2018',
3906 rsquo: '\u2019',
3907 sbquo: '\u201A',
3908 ldquo: '\u201C',
3909 rdquo: '\u201D',
3910 bdquo: '\u201E',
3911 dagger: '\u2020',
3912 Dagger: '\u2021',
3913 bull: '\u2022',
3914 hellip: '\u2026',
3915 permil: '\u2030',
3916 prime: '\u2032',
3917 Prime: '\u2033',
3918 lsaquo: '\u2039',
3919 rsaquo: '\u203A',
3920 oline: '\u203E',
3921 frasl: '\u2044',
3922 euro: '\u20AC',
3923 image: '\u2111',
3924 weierp: '\u2118',
3925 real: '\u211C',
3926 trade: '\u2122',
3927 alefsym: '\u2135',
3928 larr: '\u2190',
3929 uarr: '\u2191',
3930 rarr: '\u2192',
3931 darr: '\u2193',
3932 harr: '\u2194',
3933 crarr: '\u21B5',
3934 lArr: '\u21D0',
3935 uArr: '\u21D1',
3936 rArr: '\u21D2',
3937 dArr: '\u21D3',
3938 hArr: '\u21D4',
3939 forall: '\u2200',
3940 part: '\u2202',
3941 exist: '\u2203',
3942 empty: '\u2205',
3943 nabla: '\u2207',
3944 isin: '\u2208',
3945 notin: '\u2209',
3946 ni: '\u220B',
3947 prod: '\u220F',
3948 sum: '\u2211',
3949 minus: '\u2212',
3950 lowast: '\u2217',
3951 radic: '\u221A',
3952 prop: '\u221D',
3953 infin: '\u221E',
3954 ang: '\u2220',
3955 and: '\u2227',
3956 or: '\u2228',
3957 cap: '\u2229',
3958 cup: '\u222A',
3959 'int': '\u222B',
3960 there4: '\u2234',
3961 sim: '\u223C',
3962 cong: '\u2245',
3963 asymp: '\u2248',
3964 ne: '\u2260',
3965 equiv: '\u2261',
3966 le: '\u2264',
3967 ge: '\u2265',
3968 sub: '\u2282',
3969 sup: '\u2283',
3970 nsub: '\u2284',
3971 sube: '\u2286',
3972 supe: '\u2287',
3973 oplus: '\u2295',
3974 otimes: '\u2297',
3975 perp: '\u22A5',
3976 sdot: '\u22C5',
3977 lceil: '\u2308',
3978 rceil: '\u2309',
3979 lfloor: '\u230A',
3980 rfloor: '\u230B',
3981 lang: '\u2329',
3982 rang: '\u232A',
3983 loz: '\u25CA',
3984 spades: '\u2660',
3985 clubs: '\u2663',
3986 hearts: '\u2665',
3987 diams: '\u2666'
3988};
3989
3990'use strict';
3991
3992
3993
3994var hexNumber = /^[\da-fA-F]+$/;
3995var decimalNumber = /^\d+$/;
3996
3997var inject = function(acorn) {
3998 var tt = acorn.tokTypes;
3999 var tc = acorn.tokContexts;
4000
4001 tc.j_oTag = new acorn.TokContext('<tag', false);
4002 tc.j_cTag = new acorn.TokContext('</tag', false);
4003 tc.j_expr = new acorn.TokContext('<tag>...</tag>', true, true);
4004
4005 tt.jsxName = new acorn.TokenType('jsxName');
4006 tt.jsxText = new acorn.TokenType('jsxText', {beforeExpr: true});
4007 tt.jsxTagStart = new acorn.TokenType('jsxTagStart');
4008 tt.jsxTagEnd = new acorn.TokenType('jsxTagEnd');
4009
4010 tt.jsxTagStart.updateContext = function() {
4011 this.context.push(tc.j_expr); // treat as beginning of JSX expression
4012 this.context.push(tc.j_oTag); // start opening tag context
4013 this.exprAllowed = false;
4014 };
4015 tt.jsxTagEnd.updateContext = function(prevType) {
4016 var out = this.context.pop();
4017 if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) {
4018 this.context.pop();
4019 this.exprAllowed = this.curContext() === tc.j_expr;
4020 } else {
4021 this.exprAllowed = true;
4022 }
4023 };
4024
4025 var pp = acorn.Parser.prototype;
4026
4027 // Reads inline JSX contents token.
4028
4029 pp.jsx_readToken = function() {
4030 var out = '', chunkStart = this.pos;
4031 for (;;) {
4032 if (this.pos >= this.input.length)
4033 this.raise(this.start, 'Unterminated JSX contents');
4034 var ch = this.input.charCodeAt(this.pos);
4035
4036 switch (ch) {
4037 case 60: // '<'
4038 case 123: // '{'
4039 if (this.pos === this.start) {
4040 if (ch === 60 && this.exprAllowed) {
4041 ++this.pos;
4042 return this.finishToken(tt.jsxTagStart);
4043 }
4044 return this.getTokenFromCode(ch);
4045 }
4046 out += this.input.slice(chunkStart, this.pos);
4047 return this.finishToken(tt.jsxText, out);
4048
4049 case 38: // '&'
4050 out += this.input.slice(chunkStart, this.pos);
4051 out += this.jsx_readEntity();
4052 chunkStart = this.pos;
4053 break;
4054
4055 default:
4056 if (acorn.isNewLine(ch)) {
4057 out += this.input.slice(chunkStart, this.pos);
4058 out += this.jsx_readNewLine(true);
4059 chunkStart = this.pos;
4060 } else {
4061 ++this.pos;
4062 }
4063 }
4064 }
4065 };
4066
4067 pp.jsx_readNewLine = function(normalizeCRLF) {
4068 var ch = this.input.charCodeAt(this.pos);
4069 var out;
4070 ++this.pos;
4071 if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
4072 ++this.pos;
4073 out = normalizeCRLF ? '\n' : '\r\n';
4074 } else {
4075 out = String.fromCharCode(ch);
4076 }
4077 if (this.options.locations) {
4078 ++this.curLine;
4079 this.lineStart = this.pos;
4080 }
4081
4082 return out;
4083 };
4084
4085 pp.jsx_readString = function(quote) {
4086 var out = '', chunkStart = ++this.pos;
4087 for (;;) {
4088 if (this.pos >= this.input.length)
4089 this.raise(this.start, 'Unterminated string constant');
4090 var ch = this.input.charCodeAt(this.pos);
4091 if (ch === quote) break;
4092 if (ch === 38) { // '&'
4093 out += this.input.slice(chunkStart, this.pos);
4094 out += this.jsx_readEntity();
4095 chunkStart = this.pos;
4096 } else if (acorn.isNewLine(ch)) {
4097 out += this.input.slice(chunkStart, this.pos);
4098 out += this.jsx_readNewLine(false);
4099 chunkStart = this.pos;
4100 } else {
4101 ++this.pos;
4102 }
4103 }
4104 out += this.input.slice(chunkStart, this.pos++);
4105 return this.finishToken(tt.string, out);
4106 };
4107
4108 pp.jsx_readEntity = function() {
4109 var str = '', count = 0, entity;
4110 var ch = this.input[this.pos];
4111 if (ch !== '&')
4112 this.raise(this.pos, 'Entity must start with an ampersand');
4113 var startPos = ++this.pos;
4114 while (this.pos < this.input.length && count++ < 10) {
4115 ch = this.input[this.pos++];
4116 if (ch === ';') {
4117 if (str[0] === '#') {
4118 if (str[1] === 'x') {
4119 str = str.substr(2);
4120 if (hexNumber.test(str))
4121 entity = String.fromCharCode(parseInt(str, 16));
4122 } else {
4123 str = str.substr(1);
4124 if (decimalNumber.test(str))
4125 entity = String.fromCharCode(parseInt(str, 10));
4126 }
4127 } else {
4128 entity = xhtml[str];
4129 }
4130 break;
4131 }
4132 str += ch;
4133 }
4134 if (!entity) {
4135 this.pos = startPos;
4136 return '&';
4137 }
4138 return entity;
4139 };
4140
4141
4142 // Read a JSX identifier (valid tag or attribute name).
4143 //
4144 // Optimized version since JSX identifiers can't contain
4145 // escape characters and so can be read as single slice.
4146 // Also assumes that first character was already checked
4147 // by isIdentifierStart in readToken.
4148
4149 pp.jsx_readWord = function() {
4150 var ch, start = this.pos;
4151 do {
4152 ch = this.input.charCodeAt(++this.pos);
4153 } while (acorn.isIdentifierChar(ch) || ch === 45); // '-'
4154 return this.finishToken(tt.jsxName, this.input.slice(start, this.pos));
4155 };
4156
4157 // Transforms JSX element name to string.
4158
4159 function getQualifiedJSXName(object) {
4160 if (object.type === 'JSXIdentifier')
4161 return object.name;
4162
4163 if (object.type === 'JSXNamespacedName')
4164 return object.namespace.name + ':' + object.name.name;
4165
4166 if (object.type === 'JSXMemberExpression')
4167 return getQualifiedJSXName(object.object) + '.' +
4168 getQualifiedJSXName(object.property);
4169 }
4170
4171 // Parse next token as JSX identifier
4172
4173 pp.jsx_parseIdentifier = function() {
4174 var node = this.startNode();
4175 if (this.type === tt.jsxName)
4176 node.name = this.value;
4177 else if (this.type.keyword)
4178 node.name = this.type.keyword;
4179 else
4180 this.unexpected();
4181 this.next();
4182 return this.finishNode(node, 'JSXIdentifier');
4183 };
4184
4185 // Parse namespaced identifier.
4186
4187 pp.jsx_parseNamespacedName = function() {
4188 var startPos = this.start, startLoc = this.startLoc;
4189 var name = this.jsx_parseIdentifier();
4190 if (!this.options.plugins.jsx.allowNamespaces || !this.eat(tt.colon)) return name;
4191 var node = this.startNodeAt(startPos, startLoc);
4192 node.namespace = name;
4193 node.name = this.jsx_parseIdentifier();
4194 return this.finishNode(node, 'JSXNamespacedName');
4195 };
4196
4197 // Parses element name in any form - namespaced, member
4198 // or single identifier.
4199
4200 pp.jsx_parseElementName = function() {
4201 var startPos = this.start, startLoc = this.startLoc;
4202 var node = this.jsx_parseNamespacedName();
4203 if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !this.options.plugins.jsx.allowNamespacedObjects) {
4204 this.unexpected();
4205 }
4206 while (this.eat(tt.dot)) {
4207 var newNode = this.startNodeAt(startPos, startLoc);
4208 newNode.object = node;
4209 newNode.property = this.jsx_parseIdentifier();
4210 node = this.finishNode(newNode, 'JSXMemberExpression');
4211 }
4212 return node;
4213 };
4214
4215 // Parses any type of JSX attribute value.
4216
4217 pp.jsx_parseAttributeValue = function() {
4218 switch (this.type) {
4219 case tt.braceL:
4220 var node = this.jsx_parseExpressionContainer();
4221 if (node.expression.type === 'JSXEmptyExpression')
4222 this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression');
4223 return node;
4224
4225 case tt.jsxTagStart:
4226 case tt.string:
4227 return this.parseExprAtom();
4228
4229 default:
4230 this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
4231 }
4232 };
4233
4234 // JSXEmptyExpression is unique type since it doesn't actually parse anything,
4235 // and so it should start at the end of last read token (left brace) and finish
4236 // at the beginning of the next one (right brace).
4237
4238 pp.jsx_parseEmptyExpression = function() {
4239 var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
4240 return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
4241 };
4242
4243 // Parses JSX expression enclosed into curly brackets.
4244
4245
4246 pp.jsx_parseExpressionContainer = function() {
4247 var node = this.startNode();
4248 this.next();
4249 node.expression = this.type === tt.braceR
4250 ? this.jsx_parseEmptyExpression()
4251 : this.parseExpression();
4252 this.expect(tt.braceR);
4253 return this.finishNode(node, 'JSXExpressionContainer');
4254 };
4255
4256 // Parses following JSX attribute name-value pair.
4257
4258 pp.jsx_parseAttribute = function() {
4259 var node = this.startNode();
4260 if (this.eat(tt.braceL)) {
4261 this.expect(tt.ellipsis);
4262 node.argument = this.parseMaybeAssign();
4263 this.expect(tt.braceR);
4264 return this.finishNode(node, 'JSXSpreadAttribute');
4265 }
4266 node.name = this.jsx_parseNamespacedName();
4267 node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
4268 return this.finishNode(node, 'JSXAttribute');
4269 };
4270
4271 // Parses JSX opening tag starting after '<'.
4272
4273 pp.jsx_parseOpeningElementAt = function(startPos, startLoc) {
4274 var node = this.startNodeAt(startPos, startLoc);
4275 node.attributes = [];
4276 node.name = this.jsx_parseElementName();
4277 while (this.type !== tt.slash && this.type !== tt.jsxTagEnd)
4278 node.attributes.push(this.jsx_parseAttribute());
4279 node.selfClosing = this.eat(tt.slash);
4280 this.expect(tt.jsxTagEnd);
4281 return this.finishNode(node, 'JSXOpeningElement');
4282 };
4283
4284 // Parses JSX closing tag starting after '</'.
4285
4286 pp.jsx_parseClosingElementAt = function(startPos, startLoc) {
4287 var node = this.startNodeAt(startPos, startLoc);
4288 node.name = this.jsx_parseElementName();
4289 this.expect(tt.jsxTagEnd);
4290 return this.finishNode(node, 'JSXClosingElement');
4291 };
4292
4293 // Parses entire JSX element, including it's opening tag
4294 // (starting after '<'), attributes, contents and closing tag.
4295
4296 pp.jsx_parseElementAt = function(startPos, startLoc) {
4297 var node = this.startNodeAt(startPos, startLoc);
4298 var children = [];
4299 var openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
4300 var closingElement = null;
4301
4302 if (!openingElement.selfClosing) {
4303 contents: for (;;) {
4304 switch (this.type) {
4305 case tt.jsxTagStart:
4306 startPos = this.start; startLoc = this.startLoc;
4307 this.next();
4308 if (this.eat(tt.slash)) {
4309 closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
4310 break contents;
4311 }
4312 children.push(this.jsx_parseElementAt(startPos, startLoc));
4313 break;
4314
4315 case tt.jsxText:
4316 children.push(this.parseExprAtom());
4317 break;
4318
4319 case tt.braceL:
4320 children.push(this.jsx_parseExpressionContainer());
4321 break;
4322
4323 default:
4324 this.unexpected();
4325 }
4326 }
4327 if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
4328 this.raise(
4329 closingElement.start,
4330 'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
4331 }
4332 }
4333
4334 node.openingElement = openingElement;
4335 node.closingElement = closingElement;
4336 node.children = children;
4337 if (this.type === tt.relational && this.value === "<") {
4338 this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
4339 }
4340 return this.finishNode(node, 'JSXElement');
4341 };
4342
4343 // Parses entire JSX element from current position.
4344
4345 pp.jsx_parseElement = function() {
4346 var startPos = this.start, startLoc = this.startLoc;
4347 this.next();
4348 return this.jsx_parseElementAt(startPos, startLoc);
4349 };
4350
4351 acorn.plugins.jsx = function(instance, opts) {
4352 if (!opts) {
4353 return;
4354 }
4355
4356 if (typeof opts !== 'object') {
4357 opts = {};
4358 }
4359
4360 instance.options.plugins.jsx = {
4361 allowNamespaces: opts.allowNamespaces !== false,
4362 allowNamespacedObjects: !!opts.allowNamespacedObjects
4363 };
4364
4365 instance.extend('parseExprAtom', function(inner) {
4366 return function(refShortHandDefaultPos) {
4367 if (this.type === tt.jsxText)
4368 return this.parseLiteral(this.value);
4369 else if (this.type === tt.jsxTagStart)
4370 return this.jsx_parseElement();
4371 else
4372 return inner.call(this, refShortHandDefaultPos);
4373 };
4374 });
4375
4376 instance.extend('readToken', function(inner) {
4377 return function(code) {
4378 var context = this.curContext();
4379
4380 if (context === tc.j_expr) return this.jsx_readToken();
4381
4382 if (context === tc.j_oTag || context === tc.j_cTag) {
4383 if (acorn.isIdentifierStart(code)) return this.jsx_readWord();
4384
4385 if (code == 62) {
4386 ++this.pos;
4387 return this.finishToken(tt.jsxTagEnd);
4388 }
4389
4390 if ((code === 34 || code === 39) && context == tc.j_oTag)
4391 return this.jsx_readString(code);
4392 }
4393
4394 if (code === 60 && this.exprAllowed) {
4395 ++this.pos;
4396 return this.finishToken(tt.jsxTagStart);
4397 }
4398 return inner.call(this, code);
4399 };
4400 });
4401
4402 instance.extend('updateContext', function(inner) {
4403 return function(prevType) {
4404 if (this.type == tt.braceL) {
4405 var curContext = this.curContext();
4406 if (curContext == tc.j_oTag) this.context.push(tc.b_expr);
4407 else if (curContext == tc.j_expr) this.context.push(tc.b_tmpl);
4408 else inner.call(this, prevType);
4409 this.exprAllowed = true;
4410 } else if (this.type === tt.slash && prevType === tt.jsxTagStart) {
4411 this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
4412 this.context.push(tc.j_cTag); // reconsider as closing tag context
4413 this.exprAllowed = false;
4414 } else {
4415 return inner.call(this, prevType);
4416 }
4417 };
4418 });
4419 };
4420
4421 return acorn;
4422};
4423
4424'use strict';
4425
4426var inject$1 = function(acorn) {
4427 if (acorn.version.substr(0, 1) !== "5") {
4428 throw new Error("Unsupported acorn version " + acorn.version + ", please use acorn 5");
4429 }
4430 var tt = acorn.tokTypes;
4431 var pp = acorn.Parser.prototype;
4432
4433 // this is the same parseObj that acorn has with...
4434 function parseObj(isPattern, refDestructuringErrors) {
4435 let node = this.startNode(), first = true, propHash = {};
4436 node.properties = [];
4437 this.next();
4438 while (!this.eat(tt.braceR)) {
4439 if (!first) {
4440 this.expect(tt.comma);
4441 if (this.afterTrailingComma(tt.braceR)) break
4442 } else first = false;
4443
4444 let prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
4445 if (this.options.ecmaVersion >= 6) {
4446 // ...the spread logic borrowed from babylon :)
4447 if (this.type === tt.ellipsis) {
4448 prop = isPattern ? this.parseRestBinding() : this.parseSpread(refDestructuringErrors);
4449 node.properties.push(prop);
4450 if (this.type === tt.comma) {
4451 if (isPattern) {
4452 this.raise(this.start, "Comma is not permitted after the rest element");
4453 } else if (refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
4454 refDestructuringErrors.trailingComma = this.start;
4455 }
4456 }
4457 continue
4458 }
4459
4460 prop.method = false;
4461 prop.shorthand = false;
4462 if (isPattern || refDestructuringErrors) {
4463 startPos = this.start;
4464 startLoc = this.startLoc;
4465 }
4466 if (!isPattern)
4467 isGenerator = this.eat(tt.star);
4468 }
4469 this.parsePropertyName(prop);
4470 if (!isPattern && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
4471 isAsync = true;
4472 this.parsePropertyName(prop, refDestructuringErrors);
4473 } else {
4474 isAsync = false;
4475 }
4476 this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
4477 if (!isPattern) this.checkPropClash(prop, propHash);
4478 node.properties.push(this.finishNode(prop, "Property"));
4479 }
4480 return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
4481 }
4482
4483 const getCheckLVal = origCheckLVal => function (expr, bindingType, checkClashes) {
4484 if (expr.type == "ObjectPattern") {
4485 for (let prop of expr.properties)
4486 this.checkLVal(prop, bindingType, checkClashes);
4487 return
4488 } else if (expr.type === "Property") {
4489 // AssignmentProperty has type == "Property"
4490 return this.checkLVal(expr.value, bindingType, checkClashes)
4491 }
4492 return origCheckLVal.apply(this, arguments)
4493 };
4494
4495 acorn.plugins.objectSpread = function objectSpreadPlugin(instance) {
4496 pp.parseObj = parseObj;
4497 instance.extend("checkLVal", getCheckLVal);
4498 instance.extend("toAssignable", nextMethod => function(node, isBinding) {
4499 if (this.options.ecmaVersion >= 6 && node) {
4500 if (node.type == "ObjectExpression") {
4501 node.type = "ObjectPattern";
4502 for (let prop of node.properties)
4503 this.toAssignable(prop, isBinding);
4504 return node
4505 } else if (node.type === "Property") {
4506 // AssignmentProperty has type == "Property"
4507 if (node.kind !== "init") this.raise(node.key.start, "Object pattern can't contain getter or setter");
4508 return this.toAssignable(node.value, isBinding)
4509 } else if (node.type === "SpreadElement") {
4510 node.type = "RestElement";
4511 return this.toAssignable(node.argument, isBinding)
4512 }
4513 }
4514 return nextMethod.apply(this, arguments)
4515 });
4516 instance.extend("checkPatternExport", nextMethod => function(exports, pat) {
4517 if (pat.type == "ObjectPattern") {
4518 for (let prop of pat.properties)
4519 this.checkPatternExport(exports, prop);
4520 return
4521 } else if (pat.type === "Property") {
4522 return this.checkPatternExport(exports, pat.value)
4523 } else if (pat.type === "RestElement") {
4524 return this.checkPatternExport(exports, pat.argument)
4525 }
4526 nextMethod.apply(this, arguments);
4527 });
4528 };
4529
4530 return acorn;
4531};
4532
4533var integerToChar = {};
4534
4535'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
4536 integerToChar[ i ] = char;
4537});
4538
4539
4540
4541function encode ( value ) {
4542 var result;
4543
4544 if ( typeof value === 'number' ) {
4545 result = encodeInteger( value );
4546 } else {
4547 result = '';
4548 for ( var i = 0; i < value.length; i += 1 ) {
4549 result += encodeInteger( value[i] );
4550 }
4551 }
4552
4553 return result;
4554}
4555
4556function encodeInteger ( num ) {
4557 var result = '';
4558
4559 if ( num < 0 ) {
4560 num = ( -num << 1 ) | 1;
4561 } else {
4562 num <<= 1;
4563 }
4564
4565 do {
4566 var clamped = num & 31;
4567 num >>= 5;
4568
4569 if ( num > 0 ) {
4570 clamped |= 32;
4571 }
4572
4573 result += integerToChar[ clamped ];
4574 } while ( num > 0 );
4575
4576 return result;
4577}
4578
4579function Chunk ( start, end, content ) {
4580 this.start = start;
4581 this.end = end;
4582 this.original = content;
4583
4584 this.intro = '';
4585 this.outro = '';
4586
4587 this.content = content;
4588 this.storeName = false;
4589 this.edited = false;
4590
4591 // we make these non-enumerable, for sanity while debugging
4592 Object.defineProperties( this, {
4593 previous: { writable: true, value: null },
4594 next: { writable: true, value: null }
4595 });
4596}
4597
4598Chunk.prototype = {
4599 appendLeft: function appendLeft ( content ) {
4600 this.outro += content;
4601 },
4602
4603 appendRight: function appendRight ( content ) {
4604 this.intro = this.intro + content;
4605 },
4606
4607 clone: function clone () {
4608 var chunk = new Chunk( this.start, this.end, this.original );
4609
4610 chunk.intro = this.intro;
4611 chunk.outro = this.outro;
4612 chunk.content = this.content;
4613 chunk.storeName = this.storeName;
4614 chunk.edited = this.edited;
4615
4616 return chunk;
4617 },
4618
4619 contains: function contains ( index ) {
4620 return this.start < index && index < this.end;
4621 },
4622
4623 eachNext: function eachNext ( fn ) {
4624 var chunk = this;
4625 while ( chunk ) {
4626 fn( chunk );
4627 chunk = chunk.next;
4628 }
4629 },
4630
4631 eachPrevious: function eachPrevious ( fn ) {
4632 var chunk = this;
4633 while ( chunk ) {
4634 fn( chunk );
4635 chunk = chunk.previous;
4636 }
4637 },
4638
4639 edit: function edit ( content, storeName, contentOnly ) {
4640 this.content = content;
4641 if ( !contentOnly ) {
4642 this.intro = '';
4643 this.outro = '';
4644 }
4645 this.storeName = storeName;
4646
4647 this.edited = true;
4648
4649 return this;
4650 },
4651
4652 prependLeft: function prependLeft ( content ) {
4653 this.outro = content + this.outro;
4654 },
4655
4656 prependRight: function prependRight ( content ) {
4657 this.intro = content + this.intro;
4658 },
4659
4660 split: function split ( index ) {
4661 var sliceIndex = index - this.start;
4662
4663 var originalBefore = this.original.slice( 0, sliceIndex );
4664 var originalAfter = this.original.slice( sliceIndex );
4665
4666 this.original = originalBefore;
4667
4668 var newChunk = new Chunk( index, this.end, originalAfter );
4669 newChunk.outro = this.outro;
4670 this.outro = '';
4671
4672 this.end = index;
4673
4674 if ( this.edited ) {
4675 // TODO is this block necessary?...
4676 newChunk.edit( '', false );
4677 this.content = '';
4678 } else {
4679 this.content = originalBefore;
4680 }
4681
4682 newChunk.next = this.next;
4683 if ( newChunk.next ) { newChunk.next.previous = newChunk; }
4684 newChunk.previous = this;
4685 this.next = newChunk;
4686
4687 return newChunk;
4688 },
4689
4690 toString: function toString () {
4691 return this.intro + this.content + this.outro;
4692 },
4693
4694 trimEnd: function trimEnd ( rx ) {
4695 this.outro = this.outro.replace( rx, '' );
4696 if ( this.outro.length ) { return true; }
4697
4698 var trimmed = this.content.replace( rx, '' );
4699
4700 if ( trimmed.length ) {
4701 if ( trimmed !== this.content ) {
4702 this.split( this.start + trimmed.length ).edit( '', false );
4703 }
4704
4705 return true;
4706 } else {
4707 this.edit( '', false );
4708
4709 this.intro = this.intro.replace( rx, '' );
4710 if ( this.intro.length ) { return true; }
4711 }
4712 },
4713
4714 trimStart: function trimStart ( rx ) {
4715 this.intro = this.intro.replace( rx, '' );
4716 if ( this.intro.length ) { return true; }
4717
4718 var trimmed = this.content.replace( rx, '' );
4719
4720 if ( trimmed.length ) {
4721 if ( trimmed !== this.content ) {
4722 this.split( this.end - trimmed.length );
4723 this.edit( '', false );
4724 }
4725
4726 return true;
4727 } else {
4728 this.edit( '', false );
4729
4730 this.outro = this.outro.replace( rx, '' );
4731 if ( this.outro.length ) { return true; }
4732 }
4733 }
4734};
4735
4736var _btoa;
4737
4738if ( typeof window !== 'undefined' && typeof window.btoa === 'function' ) {
4739 _btoa = window.btoa;
4740} else if ( typeof Buffer === 'function' ) {
4741 _btoa = function (str) { return new Buffer( str ).toString( 'base64' ); };
4742} else {
4743 _btoa = function () {
4744 throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
4745 };
4746}
4747
4748var btoa = _btoa;
4749
4750function SourceMap ( properties ) {
4751 this.version = 3;
4752
4753 this.file = properties.file;
4754 this.sources = properties.sources;
4755 this.sourcesContent = properties.sourcesContent;
4756 this.names = properties.names;
4757 this.mappings = properties.mappings;
4758}
4759
4760SourceMap.prototype = {
4761 toString: function toString () {
4762 return JSON.stringify( this );
4763 },
4764
4765 toUrl: function toUrl () {
4766 return 'data:application/json;charset=utf-8;base64,' + btoa( this.toString() );
4767 }
4768};
4769
4770function guessIndent ( code ) {
4771 var lines = code.split( '\n' );
4772
4773 var tabbed = lines.filter( function (line) { return /^\t+/.test( line ); } );
4774 var spaced = lines.filter( function (line) { return /^ {2,}/.test( line ); } );
4775
4776 if ( tabbed.length === 0 && spaced.length === 0 ) {
4777 return null;
4778 }
4779
4780 // More lines tabbed than spaced? Assume tabs, and
4781 // default to tabs in the case of a tie (or nothing
4782 // to go on)
4783 if ( tabbed.length >= spaced.length ) {
4784 return '\t';
4785 }
4786
4787 // Otherwise, we need to guess the multiple
4788 var min = spaced.reduce( function ( previous, current ) {
4789 var numSpaces = /^ +/.exec( current )[0].length;
4790 return Math.min( numSpaces, previous );
4791 }, Infinity );
4792
4793 return new Array( min + 1 ).join( ' ' );
4794}
4795
4796function getRelativePath ( from, to ) {
4797 var fromParts = from.split( /[\/\\]/ );
4798 var toParts = to.split( /[\/\\]/ );
4799
4800 fromParts.pop(); // get dirname
4801
4802 while ( fromParts[0] === toParts[0] ) {
4803 fromParts.shift();
4804 toParts.shift();
4805 }
4806
4807 if ( fromParts.length ) {
4808 var i = fromParts.length;
4809 while ( i-- ) { fromParts[i] = '..'; }
4810 }
4811
4812 return fromParts.concat( toParts ).join( '/' );
4813}
4814
4815var toString$1 = Object.prototype.toString;
4816
4817function isObject ( thing ) {
4818 return toString$1.call( thing ) === '[object Object]';
4819}
4820
4821function getLocator ( source ) {
4822 var originalLines = source.split( '\n' );
4823
4824 var start = 0;
4825 var lineRanges = originalLines.map( function ( line, i ) {
4826 var end = start + line.length + 1;
4827 var range = { start: start, end: end, line: i };
4828
4829 start = end;
4830 return range;
4831 });
4832
4833 var i = 0;
4834
4835 function rangeContains ( range, index ) {
4836 return range.start <= index && index < range.end;
4837 }
4838
4839 function getLocation ( range, index ) {
4840 return { line: range.line, column: index - range.start };
4841 }
4842
4843 return function locate ( index ) {
4844 var range = lineRanges[i];
4845
4846 var d = index >= range.end ? 1 : -1;
4847
4848 while ( range ) {
4849 if ( rangeContains( range, index ) ) { return getLocation( range, index ); }
4850
4851 i += d;
4852 range = lineRanges[i];
4853 }
4854 };
4855}
4856
4857function Mappings ( hires ) {
4858 var this$1 = this;
4859
4860 var offsets = {
4861 generatedCodeColumn: 0,
4862 sourceIndex: 0,
4863 sourceCodeLine: 0,
4864 sourceCodeColumn: 0,
4865 sourceCodeName: 0
4866 };
4867
4868 var generatedCodeLine = 0;
4869 var generatedCodeColumn = 0;
4870
4871 this.raw = [];
4872 var rawSegments = this.raw[ generatedCodeLine ] = [];
4873
4874 var pending = null;
4875
4876 this.addEdit = function ( sourceIndex, content, original, loc, nameIndex ) {
4877 if ( content.length ) {
4878 rawSegments.push([
4879 generatedCodeColumn,
4880 sourceIndex,
4881 loc.line,
4882 loc.column,
4883 nameIndex ]);
4884 } else if ( pending ) {
4885 rawSegments.push( pending );
4886 }
4887
4888 this$1.advance( content );
4889 pending = null;
4890 };
4891
4892 this.addUneditedChunk = function ( sourceIndex, chunk, original, loc, sourcemapLocations ) {
4893 var originalCharIndex = chunk.start;
4894 var first = true;
4895
4896 while ( originalCharIndex < chunk.end ) {
4897 if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {
4898 rawSegments.push([
4899 generatedCodeColumn,
4900 sourceIndex,
4901 loc.line,
4902 loc.column,
4903 -1
4904 ]);
4905 }
4906
4907 if ( original[ originalCharIndex ] === '\n' ) {
4908 loc.line += 1;
4909 loc.column = 0;
4910 generatedCodeLine += 1;
4911 this$1.raw[ generatedCodeLine ] = rawSegments = [];
4912 generatedCodeColumn = 0;
4913 } else {
4914 loc.column += 1;
4915 generatedCodeColumn += 1;
4916 }
4917
4918 originalCharIndex += 1;
4919 first = false;
4920 }
4921
4922 pending = [
4923 generatedCodeColumn,
4924 sourceIndex,
4925 loc.line,
4926 loc.column,
4927 -1 ];
4928 };
4929
4930 this.advance = function (str) {
4931 if ( !str ) { return; }
4932
4933 var lines = str.split( '\n' );
4934 var lastLine = lines.pop();
4935
4936 if ( lines.length ) {
4937 generatedCodeLine += lines.length;
4938 this$1.raw[ generatedCodeLine ] = rawSegments = [];
4939 generatedCodeColumn = lastLine.length;
4940 } else {
4941 generatedCodeColumn += lastLine.length;
4942 }
4943 };
4944
4945 this.encode = function () {
4946 return this$1.raw.map( function (segments) {
4947 var generatedCodeColumn = 0;
4948
4949 return segments.map( function (segment) {
4950 var arr = [
4951 segment[0] - generatedCodeColumn,
4952 segment[1] - offsets.sourceIndex,
4953 segment[2] - offsets.sourceCodeLine,
4954 segment[3] - offsets.sourceCodeColumn
4955 ];
4956
4957 generatedCodeColumn = segment[0];
4958 offsets.sourceIndex = segment[1];
4959 offsets.sourceCodeLine = segment[2];
4960 offsets.sourceCodeColumn = segment[3];
4961
4962 if ( ~segment[4] ) {
4963 arr.push( segment[4] - offsets.sourceCodeName );
4964 offsets.sourceCodeName = segment[4];
4965 }
4966
4967 return encode( arr );
4968 }).join( ',' );
4969 }).join( ';' );
4970 };
4971}
4972
4973var Stats = function Stats () {
4974 Object.defineProperties( this, {
4975 startTimes: { value: {} }
4976 });
4977};
4978
4979Stats.prototype.time = function time ( label ) {
4980 this.startTimes[ label ] = process.hrtime();
4981};
4982
4983Stats.prototype.timeEnd = function timeEnd ( label ) {
4984 var elapsed = process.hrtime( this.startTimes[ label ] );
4985
4986 if ( !this[ label ] ) { this[ label ] = 0; }
4987 this[ label ] += elapsed[0] * 1e3 + elapsed[1] * 1e-6;
4988};
4989
4990var warned = {
4991 insertLeft: false,
4992 insertRight: false,
4993 storeName: false
4994};
4995
4996function MagicString$1 ( string, options ) {
4997 if ( options === void 0 ) options = {};
4998
4999 var chunk = new Chunk( 0, string.length, string );
5000
5001 Object.defineProperties( this, {
5002 original: { writable: true, value: string },
5003 outro: { writable: true, value: '' },
5004 intro: { writable: true, value: '' },
5005 firstChunk: { writable: true, value: chunk },
5006 lastChunk: { writable: true, value: chunk },
5007 lastSearchedChunk: { writable: true, value: chunk },
5008 byStart: { writable: true, value: {} },
5009 byEnd: { writable: true, value: {} },
5010 filename: { writable: true, value: options.filename },
5011 indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
5012 sourcemapLocations: { writable: true, value: {} },
5013 storedNames: { writable: true, value: {} },
5014 indentStr: { writable: true, value: guessIndent( string ) }
5015 });
5016
5017 this.byStart[ 0 ] = chunk;
5018 this.byEnd[ string.length ] = chunk;
5019}
5020
5021MagicString$1.prototype = {
5022 addSourcemapLocation: function addSourcemapLocation ( char ) {
5023 this.sourcemapLocations[ char ] = true;
5024 },
5025
5026 append: function append ( content ) {
5027 if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
5028
5029 this.outro += content;
5030 return this;
5031 },
5032
5033 appendLeft: function appendLeft ( index, content ) {
5034 if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
5035
5036 this._split( index );
5037
5038 var chunk = this.byEnd[ index ];
5039
5040 if ( chunk ) {
5041 chunk.appendLeft( content );
5042 } else {
5043 this.intro += content;
5044 }
5045
5046 return this;
5047 },
5048
5049 appendRight: function appendRight ( index, content ) {
5050 if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
5051
5052 this._split( index );
5053
5054 var chunk = this.byStart[ index ];
5055
5056 if ( chunk ) {
5057 chunk.appendRight( content );
5058 } else {
5059 this.outro += content;
5060 }
5061
5062 return this;
5063 },
5064
5065 clone: function clone () {
5066 var cloned = new MagicString$1( this.original, { filename: this.filename });
5067
5068 var originalChunk = this.firstChunk;
5069 var clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
5070
5071 while ( originalChunk ) {
5072 cloned.byStart[ clonedChunk.start ] = clonedChunk;
5073 cloned.byEnd[ clonedChunk.end ] = clonedChunk;
5074
5075 var nextOriginalChunk = originalChunk.next;
5076 var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
5077
5078 if ( nextClonedChunk ) {
5079 clonedChunk.next = nextClonedChunk;
5080 nextClonedChunk.previous = clonedChunk;
5081
5082 clonedChunk = nextClonedChunk;
5083 }
5084
5085 originalChunk = nextOriginalChunk;
5086 }
5087
5088 cloned.lastChunk = clonedChunk;
5089
5090 if ( this.indentExclusionRanges ) {
5091 cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
5092 }
5093
5094 Object.keys( this.sourcemapLocations ).forEach( function (loc) {
5095 cloned.sourcemapLocations[ loc ] = true;
5096 });
5097
5098 return cloned;
5099 },
5100
5101 generateMap: function generateMap ( options ) {
5102 var this$1 = this;
5103
5104 options = options || {};
5105
5106 var sourceIndex = 0;
5107 var names = Object.keys( this.storedNames );
5108 var mappings = new Mappings( options.hires );
5109
5110 var locate = getLocator( this.original );
5111
5112 if ( this.intro ) {
5113 mappings.advance( this.intro );
5114 }
5115
5116 this.firstChunk.eachNext( function (chunk) {
5117 var loc = locate( chunk.start );
5118
5119 if ( chunk.intro.length ) { mappings.advance( chunk.intro ); }
5120
5121 if ( chunk.edited ) {
5122 mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
5123 } else {
5124 mappings.addUneditedChunk( sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations );
5125 }
5126
5127 if ( chunk.outro.length ) { mappings.advance( chunk.outro ); }
5128 });
5129
5130 var map = new SourceMap({
5131 file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
5132 sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],
5133 sourcesContent: options.includeContent ? [ this.original ] : [ null ],
5134 names: names,
5135 mappings: mappings.encode()
5136 });
5137 return map;
5138 },
5139
5140 getIndentString: function getIndentString () {
5141 return this.indentStr === null ? '\t' : this.indentStr;
5142 },
5143
5144 indent: function indent ( indentStr, options ) {
5145 var this$1 = this;
5146
5147 var pattern = /^[^\r\n]/gm;
5148
5149 if ( isObject( indentStr ) ) {
5150 options = indentStr;
5151 indentStr = undefined;
5152 }
5153
5154 indentStr = indentStr !== undefined ? indentStr : ( this.indentStr || '\t' );
5155
5156 if ( indentStr === '' ) { return this; } // noop
5157
5158 options = options || {};
5159
5160 // Process exclusion ranges
5161 var isExcluded = {};
5162
5163 if ( options.exclude ) {
5164 var exclusions = typeof options.exclude[0] === 'number' ? [ options.exclude ] : options.exclude;
5165 exclusions.forEach( function (exclusion) {
5166 for ( var i = exclusion[0]; i < exclusion[1]; i += 1 ) {
5167 isExcluded[i] = true;
5168 }
5169 });
5170 }
5171
5172 var shouldIndentNextCharacter = options.indentStart !== false;
5173 var replacer = function (match) {
5174 if ( shouldIndentNextCharacter ) { return ("" + indentStr + match); }
5175 shouldIndentNextCharacter = true;
5176 return match;
5177 };
5178
5179 this.intro = this.intro.replace( pattern, replacer );
5180
5181 var charIndex = 0;
5182
5183 var chunk = this.firstChunk;
5184
5185 while ( chunk ) {
5186 var end = chunk.end;
5187
5188 if ( chunk.edited ) {
5189 if ( !isExcluded[ charIndex ] ) {
5190 chunk.content = chunk.content.replace( pattern, replacer );
5191
5192 if ( chunk.content.length ) {
5193 shouldIndentNextCharacter = chunk.content[ chunk.content.length - 1 ] === '\n';
5194 }
5195 }
5196 } else {
5197 charIndex = chunk.start;
5198
5199 while ( charIndex < end ) {
5200 if ( !isExcluded[ charIndex ] ) {
5201 var char = this$1.original[ charIndex ];
5202
5203 if ( char === '\n' ) {
5204 shouldIndentNextCharacter = true;
5205 } else if ( char !== '\r' && shouldIndentNextCharacter ) {
5206 shouldIndentNextCharacter = false;
5207
5208 if ( charIndex === chunk.start ) {
5209 chunk.prependRight( indentStr );
5210 } else {
5211 this$1._splitChunk( chunk, charIndex );
5212 chunk = chunk.next;
5213 chunk.prependRight( indentStr );
5214 }
5215 }
5216 }
5217
5218 charIndex += 1;
5219 }
5220 }
5221
5222 charIndex = chunk.end;
5223 chunk = chunk.next;
5224 }
5225
5226 this.outro = this.outro.replace( pattern, replacer );
5227
5228 return this;
5229 },
5230
5231 insert: function insert () {
5232 throw new Error( 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)' );
5233 },
5234
5235 insertLeft: function insertLeft ( index, content ) {
5236 if ( !warned.insertLeft ) {
5237 console.warn( 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead' ); // eslint-disable-line no-console
5238 warned.insertLeft = true;
5239 }
5240
5241 return this.appendLeft( index, content );
5242 },
5243
5244 insertRight: function insertRight ( index, content ) {
5245 if ( !warned.insertRight ) {
5246 console.warn( 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead' ); // eslint-disable-line no-console
5247 warned.insertRight = true;
5248 }
5249
5250 return this.prependRight( index, content );
5251 },
5252
5253 move: function move ( start, end, index ) {
5254 if ( index >= start && index <= end ) { throw new Error( 'Cannot move a selection inside itself' ); }
5255
5256 this._split( start );
5257 this._split( end );
5258 this._split( index );
5259
5260 var first = this.byStart[ start ];
5261 var last = this.byEnd[ end ];
5262
5263 var oldLeft = first.previous;
5264 var oldRight = last.next;
5265
5266 var newRight = this.byStart[ index ];
5267 if ( !newRight && last === this.lastChunk ) { return this; }
5268 var newLeft = newRight ? newRight.previous : this.lastChunk;
5269
5270 if ( oldLeft ) { oldLeft.next = oldRight; }
5271 if ( oldRight ) { oldRight.previous = oldLeft; }
5272
5273 if ( newLeft ) { newLeft.next = first; }
5274 if ( newRight ) { newRight.previous = last; }
5275
5276 if ( !first.previous ) { this.firstChunk = last.next; }
5277 if ( !last.next ) {
5278 this.lastChunk = first.previous;
5279 this.lastChunk.next = null;
5280 }
5281
5282 first.previous = newLeft;
5283 last.next = newRight || null;
5284
5285 if ( !newLeft ) { this.firstChunk = first; }
5286 if ( !newRight ) { this.lastChunk = last; }
5287
5288 return this;
5289 },
5290
5291 overwrite: function overwrite ( start, end, content, options ) {
5292 var this$1 = this;
5293
5294 if ( typeof content !== 'string' ) { throw new TypeError( 'replacement content must be a string' ); }
5295
5296 while ( start < 0 ) { start += this$1.original.length; }
5297 while ( end < 0 ) { end += this$1.original.length; }
5298
5299 if ( end > this.original.length ) { throw new Error( 'end is out of bounds' ); }
5300 if ( start === end ) { throw new Error( 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead' ); }
5301
5302 this._split( start );
5303 this._split( end );
5304
5305 if ( options === true ) {
5306 if ( !warned.storeName ) {
5307 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
5308 warned.storeName = true;
5309 }
5310
5311 options = { storeName: true };
5312 }
5313 var storeName = options !== undefined ? options.storeName : false;
5314 var contentOnly = options !== undefined ? options.contentOnly : false;
5315
5316 if ( storeName ) {
5317 var original = this.original.slice( start, end );
5318 this.storedNames[ original ] = true;
5319 }
5320
5321 var first = this.byStart[ start ];
5322 var last = this.byEnd[ end ];
5323
5324 if ( first ) {
5325 if ( end > first.end && first.next !== this.byStart[ first.end ] ) {
5326 throw new Error( 'Cannot overwrite across a split point' );
5327 }
5328
5329 first.edit( content, storeName, contentOnly );
5330
5331 if ( first !== last ) {
5332 var chunk = first.next;
5333 while ( chunk !== last ) {
5334 chunk.edit( '', false );
5335 chunk = chunk.next;
5336 }
5337
5338 chunk.edit( '', false );
5339 }
5340 }
5341
5342 else {
5343 // must be inserting at the end
5344 var newChunk = new Chunk( start, end, '' ).edit( content, storeName );
5345
5346 // TODO last chunk in the array may not be the last chunk, if it's moved...
5347 last.next = newChunk;
5348 newChunk.previous = last;
5349 }
5350
5351 return this;
5352 },
5353
5354 prepend: function prepend ( content ) {
5355 if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
5356
5357 this.intro = content + this.intro;
5358 return this;
5359 },
5360
5361 prependLeft: function prependLeft ( index, content ) {
5362 if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
5363
5364 this._split( index );
5365
5366 var chunk = this.byEnd[ index ];
5367
5368 if ( chunk ) {
5369 chunk.prependLeft( content );
5370 } else {
5371 this.intro = content + this.intro;
5372 }
5373
5374 return this;
5375 },
5376
5377 prependRight: function prependRight ( index, content ) {
5378 if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
5379
5380 this._split( index );
5381
5382 var chunk = this.byStart[ index ];
5383
5384 if ( chunk ) {
5385 chunk.prependRight( content );
5386 } else {
5387 this.outro = content + this.outro;
5388 }
5389
5390 return this;
5391 },
5392
5393 remove: function remove ( start, end ) {
5394 var this$1 = this;
5395
5396 while ( start < 0 ) { start += this$1.original.length; }
5397 while ( end < 0 ) { end += this$1.original.length; }
5398
5399 if ( start === end ) { return this; }
5400
5401 if ( start < 0 || end > this.original.length ) { throw new Error( 'Character is out of bounds' ); }
5402 if ( start > end ) { throw new Error( 'end must be greater than start' ); }
5403
5404 this._split( start );
5405 this._split( end );
5406
5407 var chunk = this.byStart[ start ];
5408
5409 while ( chunk ) {
5410 chunk.intro = '';
5411 chunk.outro = '';
5412 chunk.edit( '' );
5413
5414 chunk = end > chunk.end ? this$1.byStart[ chunk.end ] : null;
5415 }
5416
5417 return this;
5418 },
5419
5420 slice: function slice ( start, end ) {
5421 var this$1 = this;
5422 if ( start === void 0 ) start = 0;
5423 if ( end === void 0 ) end = this.original.length;
5424
5425 while ( start < 0 ) { start += this$1.original.length; }
5426 while ( end < 0 ) { end += this$1.original.length; }
5427
5428 var result = '';
5429
5430 // find start chunk
5431 var chunk = this.firstChunk;
5432 while ( chunk && ( chunk.start > start || chunk.end <= start ) ) {
5433
5434 // found end chunk before start
5435 if ( chunk.start < end && chunk.end >= end ) {
5436 return result;
5437 }
5438
5439 chunk = chunk.next;
5440 }
5441
5442 if ( chunk && chunk.edited && chunk.start !== start ) { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
5443
5444 var startChunk = chunk;
5445 while ( chunk ) {
5446 if ( chunk.intro && ( startChunk !== chunk || chunk.start === start ) ) {
5447 result += chunk.intro;
5448 }
5449
5450 var containsEnd = chunk.start < end && chunk.end >= end;
5451 if ( containsEnd && chunk.edited && chunk.end !== end ) { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
5452
5453 var sliceStart = startChunk === chunk ? start - chunk.start : 0;
5454 var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
5455
5456 result += chunk.content.slice( sliceStart, sliceEnd );
5457
5458 if ( chunk.outro && ( !containsEnd || chunk.end === end ) ) {
5459 result += chunk.outro;
5460 }
5461
5462 if ( containsEnd ) {
5463 break;
5464 }
5465
5466 chunk = chunk.next;
5467 }
5468
5469 return result;
5470 },
5471
5472 // TODO deprecate this? not really very useful
5473 snip: function snip ( start, end ) {
5474 var clone = this.clone();
5475 clone.remove( 0, start );
5476 clone.remove( end, clone.original.length );
5477
5478 return clone;
5479 },
5480
5481 _split: function _split ( index ) {
5482 var this$1 = this;
5483
5484 if ( this.byStart[ index ] || this.byEnd[ index ] ) { return; }
5485
5486 var chunk = this.lastSearchedChunk;
5487 var searchForward = index > chunk.end;
5488
5489 while ( true ) {
5490 if ( chunk.contains( index ) ) { return this$1._splitChunk( chunk, index ); }
5491
5492 chunk = searchForward ?
5493 this$1.byStart[ chunk.end ] :
5494 this$1.byEnd[ chunk.start ];
5495 }
5496 },
5497
5498 _splitChunk: function _splitChunk ( chunk, index ) {
5499 if ( chunk.edited && chunk.content.length ) { // zero-length edited chunks are a special case (overlapping replacements)
5500 var loc = getLocator( this.original )( index );
5501 throw new Error( ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")") );
5502 }
5503
5504 var newChunk = chunk.split( index );
5505
5506 this.byEnd[ index ] = chunk;
5507 this.byStart[ index ] = newChunk;
5508 this.byEnd[ newChunk.end ] = newChunk;
5509
5510 if ( chunk === this.lastChunk ) { this.lastChunk = newChunk; }
5511
5512 this.lastSearchedChunk = chunk;
5513 return true;
5514 },
5515
5516 toString: function toString () {
5517 var str = this.intro;
5518
5519 var chunk = this.firstChunk;
5520 while ( chunk ) {
5521 str += chunk.toString();
5522 chunk = chunk.next;
5523 }
5524
5525 return str + this.outro;
5526 },
5527
5528 trimLines: function trimLines () {
5529 return this.trim('[\\r\\n]');
5530 },
5531
5532 trim: function trim ( charType ) {
5533 return this.trimStart( charType ).trimEnd( charType );
5534 },
5535
5536 trimEnd: function trimEnd ( charType ) {
5537 var this$1 = this;
5538
5539 var rx = new RegExp( ( charType || '\\s' ) + '+$' );
5540
5541 this.outro = this.outro.replace( rx, '' );
5542 if ( this.outro.length ) { return this; }
5543
5544 var chunk = this.lastChunk;
5545
5546 do {
5547 var end = chunk.end;
5548 var aborted = chunk.trimEnd( rx );
5549
5550 // if chunk was trimmed, we have a new lastChunk
5551 if ( chunk.end !== end ) {
5552 if ( this$1.lastChunk === chunk ) {
5553 this$1.lastChunk = chunk.next;
5554 }
5555
5556 this$1.byEnd[ chunk.end ] = chunk;
5557 this$1.byStart[ chunk.next.start ] = chunk.next;
5558 this$1.byEnd[ chunk.next.end ] = chunk.next;
5559 }
5560
5561 if ( aborted ) { return this$1; }
5562 chunk = chunk.previous;
5563 } while ( chunk );
5564
5565 return this;
5566 },
5567
5568 trimStart: function trimStart ( charType ) {
5569 var this$1 = this;
5570
5571 var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
5572
5573 this.intro = this.intro.replace( rx, '' );
5574 if ( this.intro.length ) { return this; }
5575
5576 var chunk = this.firstChunk;
5577
5578 do {
5579 var end = chunk.end;
5580 var aborted = chunk.trimStart( rx );
5581
5582 if ( chunk.end !== end ) {
5583 // special case...
5584 if ( chunk === this$1.lastChunk ) { this$1.lastChunk = chunk.next; }
5585
5586 this$1.byEnd[ chunk.end ] = chunk;
5587 this$1.byStart[ chunk.next.start ] = chunk.next;
5588 this$1.byEnd[ chunk.next.end ] = chunk.next;
5589 }
5590
5591 if ( aborted ) { return this$1; }
5592 chunk = chunk.next;
5593 } while ( chunk );
5594
5595 return this;
5596 }
5597};
5598
5599var keys = {
5600 Program: [ 'body' ],
5601 Literal: []
5602};
5603
5604// used for debugging, without the noise created by
5605// circular references
5606function toJSON ( node ) {
5607 var obj = {};
5608
5609 Object.keys( node ).forEach( function ( key ) {
5610 if ( key === 'parent' || key === 'program' || key === 'keys' || key === '__wrapped' ) return;
5611
5612 if ( Array.isArray( node[ key ] ) ) {
5613 obj[ key ] = node[ key ].map( toJSON );
5614 } else if ( node[ key ] && node[ key ].toJSON ) {
5615 obj[ key ] = node[ key ].toJSON();
5616 } else {
5617 obj[ key ] = node[ key ];
5618 }
5619 });
5620
5621 return obj;
5622}
5623
5624var Node$1 = function Node ( raw, parent ) {
5625 raw.parent = parent;
5626 raw.program = parent.program || parent;
5627 raw.depth = parent.depth + 1;
5628 raw.keys = keys[ raw.type ];
5629 raw.indentation = undefined;
5630
5631 for ( var i = 0, list = keys[ raw.type ]; i < list.length; i += 1 ) {
5632 var key = list[i];
5633
5634 wrap( raw[ key ], raw );
5635 }
5636
5637 raw.program.magicString.addSourcemapLocation( raw.start );
5638 raw.program.magicString.addSourcemapLocation( raw.end );
5639};
5640
5641Node$1.prototype.ancestor = function ancestor ( level ) {
5642 var node = this;
5643 while ( level-- ) {
5644 node = node.parent;
5645 if ( !node ) return null;
5646 }
5647
5648 return node;
5649};
5650
5651Node$1.prototype.contains = function contains ( node ) {
5652 var this$1 = this;
5653
5654 while ( node ) {
5655 if ( node === this$1 ) return true;
5656 node = node.parent;
5657 }
5658
5659 return false;
5660};
5661
5662Node$1.prototype.findLexicalBoundary = function findLexicalBoundary () {
5663 return this.parent.findLexicalBoundary();
5664};
5665
5666Node$1.prototype.findNearest = function findNearest ( type ) {
5667 if ( typeof type === 'string' ) type = new RegExp( ("^" + type + "$") );
5668 if ( type.test( this.type ) ) return this;
5669 return this.parent.findNearest( type );
5670};
5671
5672Node$1.prototype.unparenthesizedParent = function unparenthesizedParent () {
5673 var node = this.parent;
5674 while ( node && node.type === 'ParenthesizedExpression' ) {
5675 node = node.parent;
5676 }
5677 return node;
5678};
5679
5680Node$1.prototype.unparenthesize = function unparenthesize () {
5681 var node = this;
5682 while ( node.type === 'ParenthesizedExpression' ) {
5683 node = node.expression;
5684 }
5685 return node;
5686};
5687
5688Node$1.prototype.findScope = function findScope ( functionScope ) {
5689 return this.parent.findScope( functionScope );
5690};
5691
5692Node$1.prototype.getIndentation = function getIndentation () {
5693 return this.parent.getIndentation();
5694};
5695
5696Node$1.prototype.initialise = function initialise ( transforms ) {
5697 for ( var i = 0, list = this.keys; i < list.length; i += 1 ) {
5698 var key = list[i];
5699
5700 var value = this[ key ];
5701
5702 if ( Array.isArray( value ) ) {
5703 value.forEach( function ( node ) { return node && node.initialise( transforms ); } );
5704 } else if ( value && typeof value === 'object' ) {
5705 value.initialise( transforms );
5706 }
5707 }
5708};
5709
5710Node$1.prototype.toJSON = function toJSON$1 () {
5711 return toJSON( this );
5712};
5713
5714Node$1.prototype.toString = function toString () {
5715 return this.program.magicString.original.slice( this.start, this.end );
5716};
5717
5718Node$1.prototype.transpile = function transpile ( code, transforms ) {
5719 for ( var i = 0, list = this.keys; i < list.length; i += 1 ) {
5720 var key = list[i];
5721
5722 var value = this[ key ];
5723
5724 if ( Array.isArray( value ) ) {
5725 value.forEach( function ( node ) { return node && node.transpile( code, transforms ); } );
5726 } else if ( value && typeof value === 'object' ) {
5727 value.transpile( code, transforms );
5728 }
5729 }
5730};
5731
5732function isArguments ( node ) {
5733 return node.type === 'Identifier' && node.name === 'arguments';
5734}
5735
5736function spread ( code, elements, start, argumentsArrayAlias, isNew ) {
5737 var i = elements.length;
5738 var firstSpreadIndex = -1;
5739
5740 while ( i-- ) {
5741 var element$1 = elements[i];
5742 if ( element$1 && element$1.type === 'SpreadElement' ) {
5743 if ( isArguments( element$1.argument ) ) {
5744 code.overwrite( element$1.argument.start, element$1.argument.end, argumentsArrayAlias );
5745 }
5746
5747 firstSpreadIndex = i;
5748 }
5749 }
5750
5751 if ( firstSpreadIndex === -1 ) return false; // false indicates no spread elements
5752
5753 if (isNew) {
5754 for ( i = 0; i < elements.length; i += 1 ) {
5755 var element$2 = elements[i];
5756 if ( element$2.type === 'SpreadElement' ) {
5757 code.remove( element$2.start, element$2.argument.start );
5758 } else {
5759 code.prependRight( element$2.start, '[' );
5760 code.prependRight( element$2.end, ']' );
5761 }
5762 }
5763
5764 return true; // true indicates some spread elements
5765 }
5766
5767 var element = elements[ firstSpreadIndex ];
5768 var previousElement = elements[ firstSpreadIndex - 1 ];
5769
5770 if ( !previousElement ) {
5771 code.remove( start, element.start );
5772 code.overwrite( element.end, elements[1].start, '.concat( ' );
5773 } else {
5774 code.overwrite( previousElement.end, element.start, ' ].concat( ' );
5775 }
5776
5777 for ( i = firstSpreadIndex; i < elements.length; i += 1 ) {
5778 element = elements[i];
5779
5780 if ( element ) {
5781 if ( element.type === 'SpreadElement' ) {
5782 code.remove( element.start, element.argument.start );
5783 } else {
5784 code.appendLeft( element.start, '[' );
5785 code.appendLeft( element.end, ']' );
5786 }
5787 }
5788 }
5789
5790 return true; // true indicates some spread elements
5791}
5792
5793var ArrayExpression = (function (Node) {
5794 function ArrayExpression () {
5795 Node.apply(this, arguments);
5796 }
5797
5798 if ( Node ) ArrayExpression.__proto__ = Node;
5799 ArrayExpression.prototype = Object.create( Node && Node.prototype );
5800 ArrayExpression.prototype.constructor = ArrayExpression;
5801
5802 ArrayExpression.prototype.initialise = function initialise ( transforms ) {
5803 var this$1 = this;
5804
5805 if ( transforms.spreadRest && this.elements.length ) {
5806 var lexicalBoundary = this.findLexicalBoundary();
5807
5808 var i = this.elements.length;
5809 while ( i-- ) {
5810 var element = this$1.elements[i];
5811 if ( element && element.type === 'SpreadElement' && isArguments( element.argument ) ) {
5812 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
5813 }
5814 }
5815 }
5816
5817 Node.prototype.initialise.call( this, transforms );
5818 };
5819
5820 ArrayExpression.prototype.transpile = function transpile ( code, transforms ) {
5821 if ( transforms.spreadRest ) {
5822 // erase trailing comma after last array element if not an array hole
5823 if ( this.elements.length ) {
5824 var lastElement = this.elements[ this.elements.length - 1 ];
5825 if ( lastElement && /\s*,/.test( code.original.slice( lastElement.end, this.end ) ) ) {
5826 code.overwrite( lastElement.end, this.end - 1, ' ' );
5827 }
5828 }
5829
5830 if ( this.elements.length === 1 ) {
5831 var element = this.elements[0];
5832
5833 if ( element && element.type === 'SpreadElement' ) {
5834 // special case – [ ...arguments ]
5835 if ( isArguments( element.argument ) ) {
5836 code.overwrite( this.start, this.end, ("[].concat( " + (this.argumentsArrayAlias) + " )") ); // TODO if this is the only use of argsArray, don't bother concating
5837 } else {
5838 code.overwrite( this.start, element.argument.start, '[].concat( ' );
5839 code.overwrite( element.end, this.end, ' )' );
5840 }
5841 }
5842 }
5843 else {
5844 var hasSpreadElements = spread( code, this.elements, this.start, this.argumentsArrayAlias );
5845
5846 if ( hasSpreadElements ) {
5847 code.overwrite( this.end - 1, this.end, ')' );
5848 }
5849 }
5850 }
5851
5852 Node.prototype.transpile.call( this, code, transforms );
5853 };
5854
5855 return ArrayExpression;
5856}(Node$1));
5857
5858var ArrowFunctionExpression = (function (Node) {
5859 function ArrowFunctionExpression () {
5860 Node.apply(this, arguments);
5861 }
5862
5863 if ( Node ) ArrowFunctionExpression.__proto__ = Node;
5864 ArrowFunctionExpression.prototype = Object.create( Node && Node.prototype );
5865 ArrowFunctionExpression.prototype.constructor = ArrowFunctionExpression;
5866
5867 ArrowFunctionExpression.prototype.initialise = function initialise ( transforms ) {
5868 this.body.createScope();
5869 Node.prototype.initialise.call( this, transforms );
5870 };
5871
5872 ArrowFunctionExpression.prototype.transpile = function transpile ( code, transforms ) {
5873 if ( transforms.arrow || this.needsArguments(transforms) ) {
5874 // remove arrow
5875 var charIndex = this.body.start;
5876 while ( code.original[ charIndex ] !== '=' ) {
5877 charIndex -= 1;
5878 }
5879 code.remove( charIndex, this.body.start );
5880
5881 Node.prototype.transpile.call( this, code, transforms );
5882
5883 // wrap naked parameter
5884 if ( this.params.length === 1 && this.start === this.params[0].start ) {
5885 code.prependRight( this.params[0].start, '(' );
5886 code.appendLeft( this.params[0].end, ')' );
5887 }
5888
5889 // add function
5890 if ( this.parent && this.parent.type === 'ExpressionStatement' ) {
5891 // standalone expression statement
5892 code.prependRight( this.start, '!function' );
5893 } else {
5894 code.prependRight( this.start, 'function ' );
5895 }
5896 }
5897
5898 else {
5899 Node.prototype.transpile.call( this, code, transforms );
5900 }
5901 };
5902
5903 // Returns whether any transforms that will happen use `arguments`
5904 ArrowFunctionExpression.prototype.needsArguments = function needsArguments(transforms) {
5905 return transforms.spreadRest && this.params.filter( function ( param ) { return param.type === 'RestElement'; } ).length > 0
5906 };
5907
5908 return ArrowFunctionExpression;
5909}(Node$1));
5910
5911function locate ( source, index ) {
5912 var lines = source.split( '\n' );
5913 var len = lines.length;
5914
5915 var lineStart = 0;
5916 var i;
5917
5918 for ( i = 0; i < len; i += 1 ) {
5919 var line = lines[i];
5920 var lineEnd = lineStart + line.length + 1; // +1 for newline
5921
5922 if ( lineEnd > index ) {
5923 return { line: i + 1, column: index - lineStart, char: i };
5924 }
5925
5926 lineStart = lineEnd;
5927 }
5928
5929 throw new Error( 'Could not determine location of character' );
5930}
5931
5932function pad ( num, len ) {
5933 var result = String( num );
5934 return result + repeat( ' ', len - result.length );
5935}
5936
5937function repeat ( str, times ) {
5938 var result = '';
5939 while ( times-- ) result += str;
5940 return result;
5941}
5942
5943function getSnippet ( source, loc, length ) {
5944 if ( length === void 0 ) length = 1;
5945
5946 var first = Math.max( loc.line - 5, 0 );
5947 var last = loc.line;
5948
5949 var numDigits = String( last ).length;
5950
5951 var lines = source.split( '\n' ).slice( first, last );
5952
5953 var lastLine = lines[ lines.length - 1 ];
5954 var offset = lastLine.slice( 0, loc.column ).replace( /\t/g, ' ' ).length;
5955
5956 var snippet = lines
5957 .map( function ( line, i ) { return ((pad( i + first + 1, numDigits )) + " : " + (line.replace( /\t/g, ' '))); } )
5958 .join( '\n' );
5959
5960 snippet += '\n' + repeat( ' ', numDigits + 3 + offset ) + repeat( '^', length );
5961
5962 return snippet;
5963}
5964
5965var CompileError$1 = (function (Error) {
5966 function CompileError ( message, node ) {
5967 Error.call( this, message );
5968
5969 this.name = 'CompileError';
5970 if ( !node ) { return; }
5971
5972 var source = node.program.magicString.original;
5973 var loc = locate( source, node.start );
5974
5975 this.message = message + " (" + (loc.line) + ":" + (loc.column) + ")";
5976
5977 this.stack = new Error().stack.replace( new RegExp( (".+new " + (this.name) + ".+\\n"), 'm' ), '' );
5978
5979 this.loc = loc;
5980 this.snippet = getSnippet( source, loc, node.end - node.start );
5981 }
5982
5983 if ( Error ) CompileError.__proto__ = Error;
5984 CompileError.prototype = Object.create( Error && Error.prototype );
5985 CompileError.prototype.constructor = CompileError;
5986
5987 CompileError.prototype.toString = function toString () {
5988 return ((this.name) + ": " + (this.message) + "\n" + (this.snippet));
5989 };
5990
5991 return CompileError;
5992}(Error));
5993
5994var AssignmentExpression = (function (Node) {
5995 function AssignmentExpression () {
5996 Node.apply(this, arguments);
5997 }
5998
5999 if ( Node ) AssignmentExpression.__proto__ = Node;
6000 AssignmentExpression.prototype = Object.create( Node && Node.prototype );
6001 AssignmentExpression.prototype.constructor = AssignmentExpression;
6002
6003 AssignmentExpression.prototype.initialise = function initialise ( transforms ) {
6004 if ( this.left.type === 'Identifier' ) {
6005 var declaration = this.findScope( false ).findDeclaration( this.left.name );
6006 if ( declaration && declaration.kind === 'const' ) {
6007 throw new CompileError$1( ((this.left.name) + " is read-only"), this.left );
6008 }
6009
6010 // special case – https://gitlab.com/Rich-Harris/buble/issues/11
6011 var statement = declaration && declaration.node.ancestor( 3 );
6012 if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
6013 statement.reassigned[ this.left.name ] = true;
6014 }
6015 }
6016
6017 Node.prototype.initialise.call( this, transforms );
6018 };
6019
6020 AssignmentExpression.prototype.transpile = function transpile ( code, transforms ) {
6021 if ( this.operator === '**=' && transforms.exponentiation ) {
6022 this.transpileExponentiation( code, transforms );
6023 }
6024
6025 else if ( /Pattern/.test( this.left.type ) && transforms.destructuring ) {
6026 this.transpileDestructuring( code, transforms );
6027 }
6028
6029 Node.prototype.transpile.call( this, code, transforms );
6030 };
6031
6032 AssignmentExpression.prototype.transpileDestructuring = function transpileDestructuring ( code ) {
6033 var scope = this.findScope( true );
6034 var assign = scope.createIdentifier( 'assign' );
6035 var temporaries = [ assign ];
6036
6037 var start = this.start;
6038
6039 // We need to pick out some elements from the original code,
6040 // interleaved with generated code. These helpers are used to
6041 // easily do that while keeping the order of the output
6042 // predictable.
6043 var text = '';
6044 function use ( node ) {
6045 code.prependRight( node.start, text );
6046 code.move( node.start, node.end, start );
6047 text = '';
6048 }
6049 function write ( string ) {
6050 text += string;
6051 }
6052
6053 write( ("(" + assign + " = ") );
6054 use( this.right );
6055
6056 // Walk `pattern`, generating code that assigns the value in
6057 // `ref` to it. When `mayDuplicate` is false, the function
6058 // must take care to only output `ref` once.
6059 function destructure ( pattern, ref, mayDuplicate ) {
6060 if ( pattern.type === 'Identifier' || pattern.type === 'MemberExpression' ) {
6061 write( ', ' );
6062 use( pattern );
6063 write( (" = " + ref) );
6064 }
6065
6066 else if ( pattern.type === 'AssignmentPattern' ) {
6067 if ( pattern.left.type === 'Identifier' ) {
6068 code.remove( pattern.start, pattern.right.start );
6069
6070 var target = pattern.left.name;
6071 var source = ref;
6072 if ( !mayDuplicate ) {
6073 write( (", " + target + " = " + ref) );
6074 source = target;
6075 }
6076 write( (", " + target + " = " + source + " === void 0 ? ") );
6077 use( pattern.right );
6078 write( (" : " + source) );
6079 } else {
6080 code.remove( pattern.left.end, pattern.right.start );
6081
6082 var target$1 = scope.createIdentifier( 'temp' );
6083 var source$1 = ref;
6084 temporaries.push( target$1 );
6085 if ( !mayDuplicate ) {
6086 write( (", " + target$1 + " = " + ref) );
6087 source$1 = target$1;
6088 }
6089 write( (", " + target$1 + " = " + source$1 + " === void 0 ? ") );
6090 use( pattern.right );
6091 write( (" : " + source$1) );
6092 destructure( pattern.left, target$1, true );
6093 }
6094 }
6095
6096 else if ( pattern.type === 'ArrayPattern' ) {
6097 var elements = pattern.elements;
6098 if ( elements.length === 1 ) {
6099 code.remove( pattern.start, elements[0].start );
6100 destructure( elements[0], (ref + "[0]"), false );
6101 code.remove( elements[0].end, pattern.end );
6102 }
6103 else {
6104 if ( !mayDuplicate ) {
6105 var temp = scope.createIdentifier( 'array' );
6106 temporaries.push( temp );
6107 write( (", " + temp + " = " + ref) );
6108 ref = temp;
6109 }
6110
6111 var c = pattern.start;
6112 elements.forEach( function ( element, i ) {
6113 if (!element) return;
6114
6115 code.remove(c, element.start);
6116 c = element.end;
6117
6118 if ( element.type === 'RestElement' ) {
6119 code.remove( element.start, element.argument.start );
6120 destructure( element.argument, (ref + ".slice(" + i + ")"), false );
6121 } else {
6122 destructure( element, (ref + "[" + i + "]"), false );
6123 }
6124 });
6125
6126 code.remove(c, pattern.end);
6127 }
6128 }
6129
6130 else if ( pattern.type === 'ObjectPattern' ) {
6131 var props = pattern.properties;
6132 if ( props.length == 1 ) {
6133 var prop = props[0];
6134 var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
6135
6136 code.remove( pattern.start, prop.value.start );
6137 destructure( prop.value, value, false );
6138 code.remove( prop.end, pattern.end );
6139 }
6140 else {
6141 if ( !mayDuplicate ) {
6142 var temp$1 = scope.createIdentifier( 'obj' );
6143 temporaries.push( temp$1 );
6144 write( (", " + temp$1 + " = " + ref) );
6145 ref = temp$1;
6146 }
6147
6148 var c$1 = pattern.start;
6149
6150 props.forEach( function ( prop ) {
6151 var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
6152
6153 code.remove(c$1, prop.value.start);
6154 c$1 = prop.end;
6155
6156 destructure( prop.value, value, false );
6157 });
6158
6159 code.remove(c$1, pattern.end);
6160 }
6161 }
6162
6163 else {
6164 throw new Error( ("Unexpected node type in destructuring assignment (" + (pattern.type) + ")") );
6165 }
6166 }
6167
6168 destructure( this.left, assign, true );
6169 code.remove( this.left.end, this.right.start );
6170
6171 if ( this.unparenthesizedParent().type === 'ExpressionStatement' ) {
6172 // no rvalue needed for expression statement
6173 code.prependRight( start, (text + ")") );
6174 } else {
6175 // destructuring is part of an expression - need an rvalue
6176 code.prependRight( start, (text + ", " + assign + ")") );
6177 }
6178
6179 var statement = this.findNearest( /(?:Statement|Declaration)$/ );
6180 code.appendLeft( statement.start, ("var " + (temporaries.join( ', ' )) + ";\n" + (statement.getIndentation())) );
6181 };
6182
6183 AssignmentExpression.prototype.transpileExponentiation = function transpileExponentiation ( code ) {
6184 var scope = this.findScope( false );
6185 var getAlias = function ( name ) {
6186 var declaration = scope.findDeclaration( name );
6187 return declaration ? declaration.name : name;
6188 };
6189
6190 // first, the easy part – `**=` -> `=`
6191 var charIndex = this.left.end;
6192 while ( code.original[ charIndex ] !== '*' ) charIndex += 1;
6193 code.remove( charIndex, charIndex + 2 );
6194
6195 // how we do the next part depends on a number of factors – whether
6196 // this is a top-level statement, and whether we're updating a
6197 // simple or complex reference
6198 var base;
6199
6200 var left = this.left.unparenthesize();
6201
6202 if ( left.type === 'Identifier' ) {
6203 base = getAlias( left.name );
6204 } else if ( left.type === 'MemberExpression' ) {
6205 var object;
6206 var needsObjectVar = false;
6207 var property;
6208 var needsPropertyVar = false;
6209
6210 var statement = this.findNearest( /(?:Statement|Declaration)$/ );
6211 var i0 = statement.getIndentation();
6212
6213 if ( left.property.type === 'Identifier' ) {
6214 property = left.computed ? getAlias( left.property.name ) : left.property.name;
6215 } else {
6216 property = scope.createIdentifier( 'property' );
6217 needsPropertyVar = true;
6218 }
6219
6220 if ( left.object.type === 'Identifier' ) {
6221 object = getAlias( left.object.name );
6222 } else {
6223 object = scope.createIdentifier( 'object' );
6224 needsObjectVar = true;
6225 }
6226
6227 if ( left.start === statement.start ) {
6228 if ( needsObjectVar && needsPropertyVar ) {
6229 code.prependRight( statement.start, ("var " + object + " = ") );
6230 code.overwrite( left.object.end, left.property.start, (";\n" + i0 + "var " + property + " = ") );
6231 code.overwrite( left.property.end, left.end, (";\n" + i0 + object + "[" + property + "]") );
6232 }
6233
6234 else if ( needsObjectVar ) {
6235 code.prependRight( statement.start, ("var " + object + " = ") );
6236 code.appendLeft( left.object.end, (";\n" + i0) );
6237 code.appendLeft( left.object.end, object );
6238 }
6239
6240 else if ( needsPropertyVar ) {
6241 code.prependRight( left.property.start, ("var " + property + " = ") );
6242 code.appendLeft( left.property.end, (";\n" + i0) );
6243 code.move( left.property.start, left.property.end, this.start );
6244
6245 code.appendLeft( left.object.end, ("[" + property + "]") );
6246 code.remove( left.object.end, left.property.start );
6247 code.remove( left.property.end, left.end );
6248 }
6249 }
6250
6251 else {
6252 var declarators = [];
6253 if ( needsObjectVar ) declarators.push( object );
6254 if ( needsPropertyVar ) declarators.push( property );
6255
6256 if ( declarators.length ) {
6257 code.prependRight( statement.start, ("var " + (declarators.join( ', ' )) + ";\n" + i0) );
6258 }
6259
6260 if ( needsObjectVar && needsPropertyVar ) {
6261 code.prependRight( left.start, ("( " + object + " = ") );
6262 code.overwrite( left.object.end, left.property.start, (", " + property + " = ") );
6263 code.overwrite( left.property.end, left.end, (", " + object + "[" + property + "]") );
6264 }
6265
6266 else if ( needsObjectVar ) {
6267 code.prependRight( left.start, ("( " + object + " = ") );
6268 code.appendLeft( left.object.end, (", " + object) );
6269 }
6270
6271 else if ( needsPropertyVar ) {
6272 code.prependRight( left.property.start, ("( " + property + " = ") );
6273 code.appendLeft( left.property.end, ", " );
6274 code.move( left.property.start, left.property.end, left.start );
6275
6276 code.overwrite( left.object.end, left.property.start, ("[" + property + "]") );
6277 code.remove( left.property.end, left.end );
6278 }
6279
6280 if ( needsPropertyVar ) {
6281 code.appendLeft( this.end, " )" );
6282 }
6283 }
6284
6285 base = object + ( left.computed || needsPropertyVar ? ("[" + property + "]") : ("." + property) );
6286 }
6287
6288 code.prependRight( this.right.start, ("Math.pow( " + base + ", ") );
6289 code.appendLeft( this.right.end, " )" );
6290 };
6291
6292 return AssignmentExpression;
6293}(Node$1));
6294
6295var BinaryExpression = (function (Node) {
6296 function BinaryExpression () {
6297 Node.apply(this, arguments);
6298 }
6299
6300 if ( Node ) BinaryExpression.__proto__ = Node;
6301 BinaryExpression.prototype = Object.create( Node && Node.prototype );
6302 BinaryExpression.prototype.constructor = BinaryExpression;
6303
6304 BinaryExpression.prototype.transpile = function transpile ( code, transforms ) {
6305 if ( this.operator === '**' && transforms.exponentiation ) {
6306 code.prependRight( this.start, "Math.pow( " );
6307 code.overwrite( this.left.end, this.right.start, ", " );
6308 code.appendLeft( this.end, " )" );
6309 }
6310 Node.prototype.transpile.call( this, code, transforms );
6311 };
6312
6313 return BinaryExpression;
6314}(Node$1));
6315
6316var loopStatement = /(?:For(?:In|Of)?|While)Statement/;
6317
6318var BreakStatement = (function (Node) {
6319 function BreakStatement () {
6320 Node.apply(this, arguments);
6321 }
6322
6323 if ( Node ) BreakStatement.__proto__ = Node;
6324 BreakStatement.prototype = Object.create( Node && Node.prototype );
6325 BreakStatement.prototype.constructor = BreakStatement;
6326
6327 BreakStatement.prototype.initialise = function initialise () {
6328 var loop = this.findNearest( loopStatement );
6329 var switchCase = this.findNearest( 'SwitchCase' );
6330
6331 if ( loop && ( !switchCase || loop.depth > switchCase.depth ) ) {
6332 loop.canBreak = true;
6333 this.loop = loop;
6334 }
6335 };
6336
6337 BreakStatement.prototype.transpile = function transpile ( code ) {
6338 if ( this.loop && this.loop.shouldRewriteAsFunction ) {
6339 if ( this.label ) throw new CompileError$1( 'Labels are not currently supported in a loop with locally-scoped variables', this );
6340 code.overwrite( this.start, this.start + 5, "return 'break'" );
6341 }
6342 };
6343
6344 return BreakStatement;
6345}(Node$1));
6346
6347var CallExpression = (function (Node) {
6348 function CallExpression () {
6349 Node.apply(this, arguments);
6350 }
6351
6352 if ( Node ) CallExpression.__proto__ = Node;
6353 CallExpression.prototype = Object.create( Node && Node.prototype );
6354 CallExpression.prototype.constructor = CallExpression;
6355
6356 CallExpression.prototype.initialise = function initialise ( transforms ) {
6357 var this$1 = this;
6358
6359 if ( transforms.spreadRest && this.arguments.length > 1 ) {
6360 var lexicalBoundary = this.findLexicalBoundary();
6361
6362 var i = this.arguments.length;
6363 while ( i-- ) {
6364 var arg = this$1.arguments[i];
6365 if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
6366 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
6367 }
6368 }
6369 }
6370
6371 Node.prototype.initialise.call( this, transforms );
6372 };
6373
6374 CallExpression.prototype.transpile = function transpile ( code, transforms ) {
6375 if ( transforms.spreadRest && this.arguments.length ) {
6376 var hasSpreadElements = false;
6377 var context;
6378
6379 var firstArgument = this.arguments[0];
6380
6381 if ( this.arguments.length === 1 ) {
6382 if ( firstArgument.type === 'SpreadElement' ) {
6383 code.remove( firstArgument.start, firstArgument.argument.start );
6384 hasSpreadElements = true;
6385 }
6386 } else {
6387 hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias );
6388 }
6389
6390 if ( hasSpreadElements ) {
6391
6392 // we need to handle super() and super.method() differently
6393 // due to its instance
6394 var _super = null;
6395 if ( this.callee.type === 'Super' ) {
6396 _super = this.callee;
6397 }
6398 else if ( this.callee.type === 'MemberExpression' && this.callee.object.type === 'Super' ) {
6399 _super = this.callee.object;
6400 }
6401
6402 if ( !_super && this.callee.type === 'MemberExpression' ) {
6403 if ( this.callee.object.type === 'Identifier' ) {
6404 context = this.callee.object.name;
6405 } else {
6406 context = this.findScope( true ).createIdentifier( 'ref' );
6407 var callExpression = this.callee.object;
6408 var enclosure = callExpression.findNearest( /Function/ );
6409 var block = enclosure ? enclosure.body.body
6410 : callExpression.findNearest( /^Program$/ ).body;
6411 var lastStatementInBlock = block[ block.length - 1 ];
6412 var i0 = lastStatementInBlock.getIndentation();
6413 code.prependRight( callExpression.start, ("(" + context + " = ") );
6414 code.appendLeft( callExpression.end, ")" );
6415 code.appendLeft( lastStatementInBlock.end, ("\n" + i0 + "var " + context + ";") );
6416 }
6417 } else {
6418 context = 'void 0';
6419 }
6420
6421 code.appendLeft( this.callee.end, '.apply' );
6422
6423 if ( _super ) {
6424 _super.noCall = true; // bit hacky...
6425
6426 if ( this.arguments.length > 1 ) {
6427 if ( firstArgument.type !== 'SpreadElement' ) {
6428 code.prependRight( firstArgument.start, "[ " );
6429 }
6430
6431 code.appendLeft( this.arguments[ this.arguments.length - 1 ].end, ' )' );
6432 }
6433 }
6434
6435 else if ( this.arguments.length === 1 ) {
6436 code.prependRight( firstArgument.start, (context + ", ") );
6437 } else {
6438 if ( firstArgument.type === 'SpreadElement' ) {
6439 code.appendLeft( firstArgument.start, (context + ", ") );
6440 } else {
6441 code.appendLeft( firstArgument.start, (context + ", [ ") );
6442 }
6443
6444 code.appendLeft( this.arguments[ this.arguments.length - 1 ].end, ' )' );
6445 }
6446 }
6447 }
6448
6449 Node.prototype.transpile.call( this, code, transforms );
6450 };
6451
6452 return CallExpression;
6453}(Node$1));
6454
6455function findIndex ( array, fn ) {
6456 for ( var i = 0; i < array.length; i += 1 ) {
6457 if ( fn( array[i], i ) ) return i;
6458 }
6459
6460 return -1;
6461}
6462
6463var reserved = Object.create( null );
6464'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'.split( ' ' )
6465 .forEach( function ( word ) { return reserved[ word ] = true; } );
6466
6467// TODO this code is pretty wild, tidy it up
6468var ClassBody = (function (Node) {
6469 function ClassBody () {
6470 Node.apply(this, arguments);
6471 }
6472
6473 if ( Node ) ClassBody.__proto__ = Node;
6474 ClassBody.prototype = Object.create( Node && Node.prototype );
6475 ClassBody.prototype.constructor = ClassBody;
6476
6477 ClassBody.prototype.transpile = function transpile ( code, transforms, inFunctionExpression, superName ) {
6478 var this$1 = this;
6479
6480 if ( transforms.classes ) {
6481 var name = this.parent.name;
6482
6483 var indentStr = code.getIndentString();
6484 var i0 = this.getIndentation() + ( inFunctionExpression ? indentStr : '' );
6485 var i1 = i0 + indentStr;
6486
6487 var constructorIndex = findIndex( this.body, function ( node ) { return node.kind === 'constructor'; } );
6488 var constructor = this.body[ constructorIndex ];
6489
6490 var introBlock = '';
6491 var outroBlock = '';
6492
6493 if ( this.body.length ) {
6494 code.remove( this.start, this.body[0].start );
6495 code.remove( this.body[ this.body.length - 1 ].end, this.end );
6496 } else {
6497 code.remove( this.start, this.end );
6498 }
6499
6500 if ( constructor ) {
6501 constructor.value.body.isConstructorBody = true;
6502
6503 var previousMethod = this.body[ constructorIndex - 1 ];
6504 var nextMethod = this.body[ constructorIndex + 1 ];
6505
6506 // ensure constructor is first
6507 if ( constructorIndex > 0 ) {
6508 code.remove( previousMethod.end, constructor.start );
6509 code.move( constructor.start, nextMethod ? nextMethod.start : this.end - 1, this.body[0].start );
6510 }
6511
6512 if ( !inFunctionExpression ) code.appendLeft( constructor.end, ';' );
6513 }
6514
6515 var namedFunctions = this.program.options.namedFunctionExpressions !== false;
6516 var namedConstructor = namedFunctions || this.parent.superClass || this.parent.type !== 'ClassDeclaration';
6517 if ( this.parent.superClass ) {
6518 var inheritanceBlock = "if ( " + superName + " ) " + name + ".__proto__ = " + superName + ";\n" + i0 + name + ".prototype = Object.create( " + superName + " && " + superName + ".prototype );\n" + i0 + name + ".prototype.constructor = " + name + ";";
6519
6520 if ( constructor ) {
6521 introBlock += "\n\n" + i0 + inheritanceBlock;
6522 } else {
6523 var fn = "function " + name + " () {" + ( superName ?
6524 ("\n" + i1 + superName + ".apply(this, arguments);\n" + i0 + "}") :
6525 "}" ) + ( inFunctionExpression ? '' : ';' ) + ( this.body.length ? ("\n\n" + i0) : '' );
6526
6527 inheritanceBlock = fn + inheritanceBlock;
6528 introBlock += inheritanceBlock + "\n\n" + i0;
6529 }
6530 } else if ( !constructor ) {
6531 var fn$1 = 'function ' + (namedConstructor ? name + ' ' : '') + '() {}';
6532 if ( this.parent.type === 'ClassDeclaration' ) fn$1 += ';';
6533 if ( this.body.length ) fn$1 += "\n\n" + i0;
6534
6535 introBlock += fn$1;
6536 }
6537
6538 var scope = this.findScope( false );
6539
6540 var prototypeGettersAndSetters = [];
6541 var staticGettersAndSetters = [];
6542 var prototypeAccessors;
6543 var staticAccessors;
6544
6545 this.body.forEach( function ( method, i ) {
6546 if ( method.kind === 'constructor' ) {
6547 var constructorName = namedConstructor ? ' ' + name : '';
6548 code.overwrite( method.key.start, method.key.end, ("function" + constructorName) );
6549 return;
6550 }
6551
6552 if ( method.static ) {
6553 var len = code.original[ method.start + 6 ] == ' ' ? 7 : 6;
6554 code.remove( method.start, method.start + len );
6555 }
6556
6557 var isAccessor = method.kind !== 'method';
6558 var lhs;
6559
6560 var methodName = method.key.name;
6561 if ( reserved[ methodName ] || method.value.body.scope.references[methodName] ) {
6562 methodName = scope.createIdentifier( methodName );
6563 }
6564
6565 // when method name is a string or a number let's pretend it's a computed method
6566
6567 var fake_computed = false;
6568 if ( ! method.computed && method.key.type === 'Literal' ) {
6569 fake_computed = true;
6570 method.computed = true;
6571 }
6572
6573 if ( isAccessor ) {
6574 if ( method.computed ) {
6575 throw new Error( 'Computed accessor properties are not currently supported' );
6576 }
6577
6578 code.remove( method.start, method.key.start );
6579
6580 if ( method.static ) {
6581 if ( !~staticGettersAndSetters.indexOf( method.key.name ) ) staticGettersAndSetters.push( method.key.name );
6582 if ( !staticAccessors ) staticAccessors = scope.createIdentifier( 'staticAccessors' );
6583
6584 lhs = "" + staticAccessors;
6585 } else {
6586 if ( !~prototypeGettersAndSetters.indexOf( method.key.name ) ) prototypeGettersAndSetters.push( method.key.name );
6587 if ( !prototypeAccessors ) prototypeAccessors = scope.createIdentifier( 'prototypeAccessors' );
6588
6589 lhs = "" + prototypeAccessors;
6590 }
6591 } else {
6592 lhs = method.static ?
6593 ("" + name) :
6594 (name + ".prototype");
6595 }
6596
6597 if ( !method.computed ) lhs += '.';
6598
6599 var insertNewlines = ( constructorIndex > 0 && i === constructorIndex + 1 ) ||
6600 ( i === 0 && constructorIndex === this$1.body.length - 1 );
6601
6602 if ( insertNewlines ) lhs = "\n\n" + i0 + lhs;
6603
6604 var c = method.key.end;
6605 if ( method.computed ) {
6606 if ( fake_computed ) {
6607 code.prependRight( method.key.start, '[' );
6608 code.appendLeft( method.key.end, ']' );
6609 } else {
6610 while ( code.original[c] !== ']' ) c += 1;
6611 c += 1;
6612 }
6613 }
6614
6615 var funcName = method.computed || isAccessor || !namedFunctions ? '' : (methodName + " ");
6616 var rhs = ( isAccessor ? ("." + (method.kind)) : '' ) + " = function" + ( method.value.generator ? '* ' : ' ' ) + funcName;
6617 code.remove( c, method.value.start );
6618 code.prependRight( method.value.start, rhs );
6619 code.appendLeft( method.end, ';' );
6620
6621 if ( method.value.generator ) code.remove( method.start, method.key.start );
6622
6623 code.prependRight( method.start, lhs );
6624 });
6625
6626 if ( prototypeGettersAndSetters.length || staticGettersAndSetters.length ) {
6627 var intro = [];
6628 var outro = [];
6629
6630 if ( prototypeGettersAndSetters.length ) {
6631 intro.push( ("var " + prototypeAccessors + " = { " + (prototypeGettersAndSetters.map( function ( name ) { return (name + ": { configurable: true }"); } ).join( ',' )) + " };") );
6632 outro.push( ("Object.defineProperties( " + name + ".prototype, " + prototypeAccessors + " );") );
6633 }
6634
6635 if ( staticGettersAndSetters.length ) {
6636 intro.push( ("var " + staticAccessors + " = { " + (staticGettersAndSetters.map( function ( name ) { return (name + ": { configurable: true }"); } ).join( ',' )) + " };") );
6637 outro.push( ("Object.defineProperties( " + name + ", " + staticAccessors + " );") );
6638 }
6639
6640 if ( constructor ) introBlock += "\n\n" + i0;
6641 introBlock += intro.join( ("\n" + i0) );
6642 if ( !constructor ) introBlock += "\n\n" + i0;
6643
6644 outroBlock += "\n\n" + i0 + outro.join( ("\n" + i0) );
6645 }
6646
6647 if ( constructor ) {
6648 code.appendLeft( constructor.end, introBlock );
6649 } else {
6650 code.prependRight( this.start, introBlock );
6651 }
6652
6653 code.appendLeft( this.end, outroBlock );
6654 }
6655
6656 Node.prototype.transpile.call( this, code, transforms );
6657 };
6658
6659 return ClassBody;
6660}(Node$1));
6661
6662// TODO this function is slightly flawed – it works on the original string,
6663// not its current edited state.
6664// That's not a problem for the way that it's currently used, but it could
6665// be in future...
6666function deindent ( node, code ) {
6667 var start = node.start;
6668 var end = node.end;
6669
6670 var indentStr = code.getIndentString();
6671 var indentStrLen = indentStr.length;
6672 var indentStart = start - indentStrLen;
6673
6674 if ( !node.program.indentExclusions[ indentStart ]
6675 && code.original.slice( indentStart, start ) === indentStr ) {
6676 code.remove( indentStart, start );
6677 }
6678
6679 var pattern = new RegExp( indentStr + '\\S', 'g' );
6680 var slice = code.original.slice( start, end );
6681 var match;
6682
6683 while ( match = pattern.exec( slice ) ) {
6684 var removeStart = start + match.index;
6685 if ( !node.program.indentExclusions[ removeStart ] ) {
6686 code.remove( removeStart, removeStart + indentStrLen );
6687 }
6688 }
6689}
6690
6691var ClassDeclaration = (function (Node) {
6692 function ClassDeclaration () {
6693 Node.apply(this, arguments);
6694 }
6695
6696 if ( Node ) ClassDeclaration.__proto__ = Node;
6697 ClassDeclaration.prototype = Object.create( Node && Node.prototype );
6698 ClassDeclaration.prototype.constructor = ClassDeclaration;
6699
6700 ClassDeclaration.prototype.initialise = function initialise ( transforms ) {
6701 this.name = this.id.name;
6702 this.findScope( true ).addDeclaration( this.id, 'class' );
6703
6704 Node.prototype.initialise.call( this, transforms );
6705 };
6706
6707 ClassDeclaration.prototype.transpile = function transpile ( code, transforms ) {
6708 if ( transforms.classes ) {
6709 if ( !this.superClass ) deindent( this.body, code );
6710
6711 var superName = this.superClass && ( this.superClass.name || 'superclass' );
6712
6713 var i0 = this.getIndentation();
6714 var i1 = i0 + code.getIndentString();
6715
6716 // if this is an export default statement, we have to move the export to
6717 // after the declaration, because `export default var Foo = ...` is illegal
6718 var syntheticDefaultExport = this.parent.type === 'ExportDefaultDeclaration' ?
6719 ("\n\n" + i0 + "export default " + (this.id.name) + ";") :
6720 '';
6721
6722 if ( syntheticDefaultExport ) code.remove( this.parent.start, this.start );
6723
6724 code.overwrite( this.start, this.id.start, 'var ' );
6725
6726 if ( this.superClass ) {
6727 if ( this.superClass.end === this.body.start ) {
6728 code.remove( this.id.end, this.superClass.start );
6729 code.appendLeft( this.id.end, (" = (function (" + superName + ") {\n" + i1) );
6730 } else {
6731 code.overwrite( this.id.end, this.superClass.start, ' = ' );
6732 code.overwrite( this.superClass.end, this.body.start, ("(function (" + superName + ") {\n" + i1) );
6733 }
6734 } else {
6735 if ( this.id.end === this.body.start ) {
6736 code.appendLeft( this.id.end, ' = ' );
6737 } else {
6738 code.overwrite( this.id.end, this.body.start, ' = ' );
6739 }
6740 }
6741
6742 this.body.transpile( code, transforms, !!this.superClass, superName );
6743
6744 if ( this.superClass ) {
6745 code.appendLeft( this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(") );
6746 code.move( this.superClass.start, this.superClass.end, this.end );
6747 code.prependRight( this.end, ("));" + syntheticDefaultExport) );
6748 } else if ( syntheticDefaultExport ) {
6749 code.prependRight( this.end, syntheticDefaultExport );
6750 }
6751 }
6752
6753 else {
6754 this.body.transpile( code, transforms, false, null );
6755 }
6756 };
6757
6758 return ClassDeclaration;
6759}(Node$1));
6760
6761var ClassExpression = (function (Node) {
6762 function ClassExpression () {
6763 Node.apply(this, arguments);
6764 }
6765
6766 if ( Node ) ClassExpression.__proto__ = Node;
6767 ClassExpression.prototype = Object.create( Node && Node.prototype );
6768 ClassExpression.prototype.constructor = ClassExpression;
6769
6770 ClassExpression.prototype.initialise = function initialise ( transforms ) {
6771 this.name = this.id ? this.id.name :
6772 this.parent.type === 'VariableDeclarator' ? this.parent.id.name :
6773 this.parent.type === 'AssignmentExpression' ? this.parent.left.name :
6774 this.findScope( true ).createIdentifier( 'anonymous' );
6775
6776 Node.prototype.initialise.call( this, transforms );
6777 };
6778
6779 ClassExpression.prototype.transpile = function transpile ( code, transforms ) {
6780 if ( transforms.classes ) {
6781 var superName = this.superClass && ( this.superClass.name || 'superclass' );
6782
6783 var i0 = this.getIndentation();
6784 var i1 = i0 + code.getIndentString();
6785
6786 if ( this.superClass ) {
6787 code.remove( this.start, this.superClass.start );
6788 code.remove( this.superClass.end, this.body.start );
6789 code.appendLeft( this.start, ("(function (" + superName + ") {\n" + i1) );
6790 } else {
6791 code.overwrite( this.start, this.body.start, ("(function () {\n" + i1) );
6792 }
6793
6794 this.body.transpile( code, transforms, true, superName );
6795
6796 var outro = "\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(";
6797
6798 if ( this.superClass ) {
6799 code.appendLeft( this.end, outro );
6800 code.move( this.superClass.start, this.superClass.end, this.end );
6801 code.prependRight( this.end, '))' );
6802 } else {
6803 code.appendLeft( this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}())") );
6804 }
6805 }
6806
6807 else {
6808 this.body.transpile( code, transforms, false );
6809 }
6810 };
6811
6812 return ClassExpression;
6813}(Node$1));
6814
6815var ContinueStatement = (function (Node) {
6816 function ContinueStatement () {
6817 Node.apply(this, arguments);
6818 }
6819
6820 if ( Node ) ContinueStatement.__proto__ = Node;
6821 ContinueStatement.prototype = Object.create( Node && Node.prototype );
6822 ContinueStatement.prototype.constructor = ContinueStatement;
6823
6824 ContinueStatement.prototype.transpile = function transpile ( code ) {
6825 var loop = this.findNearest( loopStatement );
6826 if ( loop.shouldRewriteAsFunction ) {
6827 if ( this.label ) throw new CompileError$1( 'Labels are not currently supported in a loop with locally-scoped variables', this );
6828 code.overwrite( this.start, this.start + 8, 'return' );
6829 }
6830 };
6831
6832 return ContinueStatement;
6833}(Node$1));
6834
6835var ExportDefaultDeclaration = (function (Node) {
6836 function ExportDefaultDeclaration () {
6837 Node.apply(this, arguments);
6838 }
6839
6840 if ( Node ) ExportDefaultDeclaration.__proto__ = Node;
6841 ExportDefaultDeclaration.prototype = Object.create( Node && Node.prototype );
6842 ExportDefaultDeclaration.prototype.constructor = ExportDefaultDeclaration;
6843
6844 ExportDefaultDeclaration.prototype.initialise = function initialise ( transforms ) {
6845 if ( transforms.moduleExport ) throw new CompileError$1( 'export is not supported', this );
6846 Node.prototype.initialise.call( this, transforms );
6847 };
6848
6849 return ExportDefaultDeclaration;
6850}(Node$1));
6851
6852var ExportNamedDeclaration = (function (Node) {
6853 function ExportNamedDeclaration () {
6854 Node.apply(this, arguments);
6855 }
6856
6857 if ( Node ) ExportNamedDeclaration.__proto__ = Node;
6858 ExportNamedDeclaration.prototype = Object.create( Node && Node.prototype );
6859 ExportNamedDeclaration.prototype.constructor = ExportNamedDeclaration;
6860
6861 ExportNamedDeclaration.prototype.initialise = function initialise ( transforms ) {
6862 if ( transforms.moduleExport ) throw new CompileError$1( 'export is not supported', this );
6863 Node.prototype.initialise.call( this, transforms );
6864 };
6865
6866 return ExportNamedDeclaration;
6867}(Node$1));
6868
6869var LoopStatement = (function (Node) {
6870 function LoopStatement () {
6871 Node.apply(this, arguments);
6872 }
6873
6874 if ( Node ) LoopStatement.__proto__ = Node;
6875 LoopStatement.prototype = Object.create( Node && Node.prototype );
6876 LoopStatement.prototype.constructor = LoopStatement;
6877
6878 LoopStatement.prototype.findScope = function findScope ( functionScope ) {
6879 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
6880 };
6881
6882 LoopStatement.prototype.initialise = function initialise ( transforms ) {
6883 var this$1 = this;
6884
6885 this.body.createScope();
6886 this.createdScope = true;
6887
6888 // this is populated as and when reassignments occur
6889 this.reassigned = Object.create( null );
6890 this.aliases = Object.create( null );
6891
6892 Node.prototype.initialise.call( this, transforms );
6893
6894 if ( transforms.letConst ) {
6895 // see if any block-scoped declarations are referenced
6896 // inside function expressions
6897 var names = Object.keys( this.body.scope.declarations );
6898
6899 var i = names.length;
6900 while ( i-- ) {
6901 var name = names[i];
6902 var declaration = this$1.body.scope.declarations[ name ];
6903
6904 var j = declaration.instances.length;
6905 while ( j-- ) {
6906 var instance = declaration.instances[j];
6907 var nearestFunctionExpression = instance.findNearest( /Function/ );
6908
6909 if ( nearestFunctionExpression && nearestFunctionExpression.depth > this$1.depth ) {
6910 this$1.shouldRewriteAsFunction = true;
6911 break;
6912 }
6913 }
6914
6915 if ( this$1.shouldRewriteAsFunction ) break;
6916 }
6917 }
6918 };
6919
6920 LoopStatement.prototype.transpile = function transpile ( code, transforms ) {
6921 var needsBlock = this.type != 'ForOfStatement' && (
6922 this.body.type !== 'BlockStatement'
6923 || this.body.type === 'BlockStatement' && this.body.synthetic );
6924
6925 if ( this.shouldRewriteAsFunction ) {
6926 var i0 = this.getIndentation();
6927 var i1 = i0 + code.getIndentString();
6928
6929 var argString = this.args ? (" " + (this.args.join( ', ' )) + " ") : '';
6930 var paramString = this.params ? (" " + (this.params.join( ', ' )) + " ") : '';
6931
6932 var functionScope = this.findScope( true );
6933 var loop = functionScope.createIdentifier( 'loop' );
6934
6935 var before = "var " + loop + " = function (" + paramString + ") " + ( this.body.synthetic ? ("{\n" + i0 + (code.getIndentString())) : '' );
6936 var after = ( this.body.synthetic ? ("\n" + i0 + "}") : '' ) + ";\n\n" + i0;
6937
6938 code.prependRight( this.body.start, before );
6939 code.appendLeft( this.body.end, after );
6940 code.move( this.start, this.body.start, this.body.end );
6941
6942 if ( this.canBreak || this.canReturn ) {
6943 var returned = functionScope.createIdentifier( 'returned' );
6944
6945 var insert = "{\n" + i1 + "var " + returned + " = " + loop + "(" + argString + ");\n";
6946 if ( this.canBreak ) insert += "\n" + i1 + "if ( " + returned + " === 'break' ) break;";
6947 if ( this.canReturn ) insert += "\n" + i1 + "if ( " + returned + " ) return " + returned + ".v;";
6948 insert += "\n" + i0 + "}";
6949
6950 code.prependRight( this.body.end, insert );
6951 } else {
6952 var callExpression = loop + "(" + argString + ");";
6953
6954 if ( this.type === 'DoWhileStatement' ) {
6955 code.overwrite( this.start, this.body.start, ("do {\n" + i1 + callExpression + "\n" + i0 + "}") );
6956 } else {
6957 code.prependRight( this.body.end, callExpression );
6958 }
6959 }
6960 } else if ( needsBlock ) {
6961 code.appendLeft( this.body.start, '{ ' );
6962 code.prependRight( this.body.end, ' }' );
6963 }
6964
6965 Node.prototype.transpile.call( this, code, transforms );
6966 };
6967
6968 return LoopStatement;
6969}(Node$1));
6970
6971function extractNames ( node ) {
6972 var names = [];
6973 extractors[ node.type ]( names, node );
6974 return names;
6975}
6976
6977var extractors = {
6978 Identifier: function Identifier ( names, node ) {
6979 names.push( node );
6980 },
6981
6982 ObjectPattern: function ObjectPattern ( names, node ) {
6983 for ( var i = 0, list = node.properties; i < list.length; i += 1 ) {
6984 var prop = list[i];
6985
6986 extractors[ prop.type ]( names, prop );
6987 }
6988 },
6989
6990 Property: function Property ( names, node ) {
6991 extractors[ node.value.type ]( names, node.value );
6992 },
6993
6994 RestElement: function RestElement ( names, node ) {
6995 extractors[ node.argument.type ]( names, node.argument );
6996 },
6997
6998 ArrayPattern: function ArrayPattern ( names, node ) {
6999 for ( var i = 0, list = node.elements; i < list.length; i += 1 ) {
7000 var element = list[i];
7001
7002 if ( element ) extractors[ element.type ]( names, element );
7003 }
7004 },
7005
7006 RestElement: function RestElement$1 ( names, node ) {
7007 extractors[ node.argument.type ]( names, node.argument );
7008 },
7009
7010 AssignmentPattern: function AssignmentPattern ( names, node ) {
7011 extractors[ node.left.type ]( names, node.left );
7012 }
7013};
7014
7015var ForStatement = (function (LoopStatement$$1) {
7016 function ForStatement () {
7017 LoopStatement$$1.apply(this, arguments);
7018 }
7019
7020 if ( LoopStatement$$1 ) ForStatement.__proto__ = LoopStatement$$1;
7021 ForStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
7022 ForStatement.prototype.constructor = ForStatement;
7023
7024 ForStatement.prototype.findScope = function findScope ( functionScope ) {
7025 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
7026 };
7027
7028 ForStatement.prototype.transpile = function transpile ( code, transforms ) {
7029 var this$1 = this;
7030
7031 var i1 = this.getIndentation() + code.getIndentString();
7032
7033 if ( this.shouldRewriteAsFunction ) {
7034 // which variables are declared in the init statement?
7035 var names = this.init.type === 'VariableDeclaration' ?
7036 [].concat.apply( [], this.init.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
7037 [];
7038
7039 var aliases = this.aliases;
7040
7041 this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
7042 this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
7043
7044 var updates = Object.keys( this.reassigned )
7045 .map( function ( name ) { return ((aliases[ name ].outer) + " = " + (aliases[ name ].inner) + ";"); } );
7046
7047 if ( updates.length ) {
7048 if ( this.body.synthetic ) {
7049 code.appendLeft( this.body.body[0].end, ("; " + (updates.join(" "))) );
7050 } else {
7051 var lastStatement = this.body.body[ this.body.body.length - 1 ];
7052 code.appendLeft( lastStatement.end, ("\n\n" + i1 + (updates.join(("\n" + i1)))) );
7053 }
7054 }
7055 }
7056
7057 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
7058 };
7059
7060 return ForStatement;
7061}(LoopStatement));
7062
7063var ForInStatement = (function (LoopStatement$$1) {
7064 function ForInStatement () {
7065 LoopStatement$$1.apply(this, arguments);
7066 }
7067
7068 if ( LoopStatement$$1 ) ForInStatement.__proto__ = LoopStatement$$1;
7069 ForInStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
7070 ForInStatement.prototype.constructor = ForInStatement;
7071
7072 ForInStatement.prototype.findScope = function findScope ( functionScope ) {
7073 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
7074 };
7075
7076 ForInStatement.prototype.transpile = function transpile ( code, transforms ) {
7077 var this$1 = this;
7078
7079 if ( this.shouldRewriteAsFunction ) {
7080 // which variables are declared in the init statement?
7081 var names = this.left.type === 'VariableDeclaration' ?
7082 [].concat.apply( [], this.left.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
7083 [];
7084
7085 this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
7086 this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
7087 }
7088
7089 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
7090 };
7091
7092 return ForInStatement;
7093}(LoopStatement));
7094
7095var handlers = {
7096 Identifier: destructureIdentifier,
7097 AssignmentPattern: destructureAssignmentPattern,
7098 ArrayPattern: destructureArrayPattern,
7099 ObjectPattern: destructureObjectPattern
7100};
7101
7102function destructure ( code, scope, node, ref, inline, statementGenerators ) {
7103 handlers[ node.type ]( code, scope, node, ref, inline, statementGenerators );
7104}
7105
7106function destructureIdentifier ( code, scope, node, ref, inline, statementGenerators ) {
7107 statementGenerators.push( function ( start, prefix, suffix ) {
7108 code.prependRight( node.start, inline ? prefix : (prefix + "var ") );
7109 code.appendLeft( node.end, (" = " + ref + suffix) );
7110 code.move( node.start, node.end, start );
7111 });
7112}
7113
7114function destructureAssignmentPattern ( code, scope, node, ref, inline, statementGenerators ) {
7115 var isIdentifier = node.left.type === 'Identifier';
7116 var name = isIdentifier ? node.left.name : ref;
7117
7118 if ( !inline ) {
7119 statementGenerators.push( function ( start, prefix, suffix ) {
7120 code.prependRight( node.left.end, (prefix + "if ( " + name + " === void 0 ) " + name) );
7121 code.move( node.left.end, node.right.end, start );
7122 code.appendLeft( node.right.end, suffix );
7123 });
7124 }
7125
7126 if ( !isIdentifier ) {
7127 destructure( code, scope, node.left, ref, inline, statementGenerators );
7128 }
7129}
7130
7131function destructureArrayPattern ( code, scope, node, ref, inline, statementGenerators ) {
7132 var c = node.start;
7133
7134 node.elements.forEach( function ( element, i ) {
7135 if ( !element ) return;
7136
7137 if ( element.type === 'RestElement' ) {
7138 handleProperty( code, scope, c, element.argument, (ref + ".slice(" + i + ")"), inline, statementGenerators );
7139 } else {
7140 handleProperty( code, scope, c, element, (ref + "[" + i + "]"), inline, statementGenerators );
7141 }
7142 c = element.end;
7143 });
7144
7145 code.remove( c, node.end );
7146}
7147
7148function destructureObjectPattern ( code, scope, node, ref, inline, statementGenerators ) {
7149 var this$1 = this;
7150
7151 var c = node.start;
7152
7153 var nonRestKeys = [];
7154 node.properties.forEach( function ( prop ) {
7155 var value;
7156 var content;
7157 if (prop.type === "Property") {
7158 var isComputedKey = prop.computed || prop.key.type !== 'Identifier';
7159 var key = isComputedKey ? code.slice(prop.key.start, prop.key.end) : prop.key.name;
7160 value = isComputedKey ? (ref + "[" + key + "]") : (ref + "." + key);
7161 content = prop.value;
7162 nonRestKeys.push(isComputedKey ? key : '"' + key + '"');
7163 } else if (prop.type === "RestElement") {
7164 content = prop.argument;
7165 value = scope.createIdentifier( 'rest' );
7166 var n = scope.createIdentifier( 'n' );
7167 statementGenerators.push( function ( start, prefix, suffix ) {
7168 code.overwrite(prop.start, c = prop.argument.start, (prefix + "var " + value + " = {}; for (var " + n + " in " + ref + ") if([" + (nonRestKeys.join(", ")) + "].indexOf(" + n + ") === -1) " + value + "[" + n + "] = " + ref + "[" + n + "]" + suffix));
7169 code.move(prop.start, c, start);
7170 } );
7171 } else {
7172 throw new CompileError( this$1, ("Unexpected node of type " + (prop.type) + " in object pattern"))
7173 }
7174 handleProperty( code, scope, c, content, value, inline, statementGenerators );
7175 c = prop.end;
7176 });
7177
7178 code.remove( c, node.end );
7179}
7180
7181function handleProperty ( code, scope, c, node, value, inline, statementGenerators ) {
7182 switch ( node.type ) {
7183 case 'Identifier': {
7184 code.remove( c, node.start );
7185 destructureIdentifier( code, scope, node, value, inline, statementGenerators );
7186 break;
7187 }
7188
7189 case 'AssignmentPattern': {
7190 var name;
7191
7192 var isIdentifier = node.left.type === 'Identifier';
7193
7194 if ( isIdentifier ) {
7195 name = node.left.name;
7196 var declaration = scope.findDeclaration( name );
7197 if ( declaration ) name = declaration.name;
7198 } else {
7199 name = scope.createIdentifier( value );
7200 }
7201
7202 statementGenerators.push( function ( start, prefix, suffix ) {
7203 if ( inline ) {
7204 code.prependRight( node.right.start, (name + " = " + value + " === undefined ? ") );
7205 code.appendLeft( node.right.end, (" : " + value) );
7206 } else {
7207 code.prependRight( node.right.start, (prefix + "var " + name + " = " + value + "; if ( " + name + " === void 0 ) " + name + " = ") );
7208 code.appendLeft( node.right.end, suffix );
7209 }
7210
7211 code.move( node.right.start, node.right.end, start );
7212 });
7213
7214 if ( isIdentifier ) {
7215 code.remove( c, node.right.start );
7216 } else {
7217 code.remove( c, node.left.start );
7218 code.remove( node.left.end, node.right.start );
7219 handleProperty( code, scope, c, node.left, name, inline, statementGenerators );
7220 }
7221
7222 break;
7223 }
7224
7225 case 'ObjectPattern': {
7226 code.remove( c, c = node.start );
7227
7228 var ref = value;
7229 if ( node.properties.length > 1 ) {
7230 ref = scope.createIdentifier( value );
7231
7232 statementGenerators.push( function ( start, prefix, suffix ) {
7233 // this feels a tiny bit hacky, but we can't do a
7234 // straightforward appendLeft and keep correct order...
7235 code.prependRight( node.start, (prefix + "var " + ref + " = ") );
7236 code.overwrite( node.start, c = node.start + 1, value );
7237 code.appendLeft( c, suffix );
7238
7239 code.overwrite( node.start, c = node.start + 1, (prefix + "var " + ref + " = " + value + suffix) );
7240 code.move( node.start, c, start );
7241 });
7242 }
7243
7244 destructureObjectPattern( code, scope, node, ref, inline, statementGenerators );
7245
7246 break;
7247 }
7248
7249 case 'ArrayPattern': {
7250 code.remove( c, c = node.start );
7251
7252 if ( node.elements.filter( Boolean ).length > 1 ) {
7253 var ref$1 = scope.createIdentifier( value );
7254
7255 statementGenerators.push( function ( start, prefix, suffix ) {
7256 code.prependRight( node.start, (prefix + "var " + ref$1 + " = ") );
7257 code.overwrite( node.start, c = node.start + 1, value, { contentOnly: true });
7258 code.appendLeft( c, suffix );
7259
7260 code.move( node.start, c, start );
7261 });
7262
7263 node.elements.forEach( function ( element, i ) {
7264 if ( !element ) return;
7265
7266 if ( element.type === 'RestElement' ) {
7267 handleProperty( code, scope, c, element.argument, (ref$1 + ".slice(" + i + ")"), inline, statementGenerators );
7268 } else {
7269 handleProperty( code, scope, c, element, (ref$1 + "[" + i + "]"), inline, statementGenerators );
7270 }
7271 c = element.end;
7272 });
7273 } else {
7274 var index = findIndex( node.elements, Boolean );
7275 var element = node.elements[ index ];
7276 if ( element.type === 'RestElement' ) {
7277 handleProperty( code, scope, c, element.argument, (value + ".slice(" + index + ")"), inline, statementGenerators );
7278 } else {
7279 handleProperty( code, scope, c, element, (value + "[" + index + "]"), inline, statementGenerators );
7280 }
7281 c = element.end;
7282 }
7283
7284 code.remove( c, node.end );
7285 break;
7286 }
7287
7288 default: {
7289 throw new Error( ("Unexpected node type in destructuring (" + (node.type) + ")") );
7290 }
7291 }
7292}
7293
7294var ForOfStatement = (function (LoopStatement$$1) {
7295 function ForOfStatement () {
7296 LoopStatement$$1.apply(this, arguments);
7297 }
7298
7299 if ( LoopStatement$$1 ) ForOfStatement.__proto__ = LoopStatement$$1;
7300 ForOfStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
7301 ForOfStatement.prototype.constructor = ForOfStatement;
7302
7303 ForOfStatement.prototype.initialise = function initialise ( transforms ) {
7304 if ( transforms.forOf && !transforms.dangerousForOf ) throw new CompileError$1( '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', this );
7305 LoopStatement$$1.prototype.initialise.call( this, transforms );
7306 };
7307
7308 ForOfStatement.prototype.transpile = function transpile ( code, transforms ) {
7309 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
7310 if ( !transforms.dangerousForOf ) return;
7311
7312 // edge case (#80)
7313 if ( !this.body.body[0] ) {
7314 if ( this.left.type === 'VariableDeclaration' && this.left.kind === 'var' ) {
7315 code.remove( this.start, this.left.start );
7316 code.appendLeft( this.left.end, ';' );
7317 code.remove( this.left.end, this.end );
7318 } else {
7319 code.remove( this.start, this.end );
7320 }
7321
7322 return;
7323 }
7324
7325 var scope = this.findScope( true );
7326 var i0 = this.getIndentation();
7327 var i1 = i0 + code.getIndentString();
7328
7329 var key = scope.createIdentifier( 'i' );
7330 var list = scope.createIdentifier( 'list' );
7331
7332 if ( this.body.synthetic ) {
7333 code.prependRight( this.left.start, ("{\n" + i1) );
7334 code.appendLeft( this.body.body[0].end, ("\n" + i0 + "}") );
7335 }
7336
7337 var bodyStart = this.body.body[0].start;
7338
7339 code.remove( this.left.end, this.right.start );
7340 code.move( this.left.start, this.left.end, bodyStart );
7341
7342
7343 code.prependRight( this.right.start, ("var " + key + " = 0, " + list + " = ") );
7344 code.appendLeft( this.right.end, ("; " + key + " < " + list + ".length; " + key + " += 1") );
7345
7346 // destructuring. TODO non declaration destructuring
7347 var declarator = this.left.type === 'VariableDeclaration' && this.left.declarations[0];
7348 if ( declarator && declarator.id.type !== 'Identifier' ) {
7349 var statementGenerators = [];
7350 var ref = scope.createIdentifier( 'ref' );
7351 destructure( code, scope, declarator.id, ref, false, statementGenerators );
7352
7353 var suffix = ";\n" + i1;
7354 statementGenerators.forEach( function ( fn, i ) {
7355 if ( i === statementGenerators.length - 1 ) {
7356 suffix = ";\n\n" + i1;
7357 }
7358
7359 fn( bodyStart, '', suffix );
7360 });
7361
7362 code.appendLeft( this.left.start + this.left.kind.length + 1, ref );
7363 code.appendLeft( this.left.end, (" = " + list + "[" + key + "];\n" + i1) );
7364 } else {
7365 code.appendLeft( this.left.end, (" = " + list + "[" + key + "];\n\n" + i1) );
7366 }
7367 };
7368
7369 return ForOfStatement;
7370}(LoopStatement));
7371
7372var FunctionDeclaration = (function (Node) {
7373 function FunctionDeclaration () {
7374 Node.apply(this, arguments);
7375 }
7376
7377 if ( Node ) FunctionDeclaration.__proto__ = Node;
7378 FunctionDeclaration.prototype = Object.create( Node && Node.prototype );
7379 FunctionDeclaration.prototype.constructor = FunctionDeclaration;
7380
7381 FunctionDeclaration.prototype.initialise = function initialise ( transforms ) {
7382 if ( this.generator && transforms.generator ) {
7383 throw new CompileError$1( 'Generators are not supported', this );
7384 }
7385
7386 this.body.createScope();
7387
7388 this.findScope( true ).addDeclaration( this.id, 'function' );
7389 Node.prototype.initialise.call( this, transforms );
7390 };
7391
7392 return FunctionDeclaration;
7393}(Node$1));
7394
7395var FunctionExpression = (function (Node) {
7396 function FunctionExpression () {
7397 Node.apply(this, arguments);
7398 }
7399
7400 if ( Node ) FunctionExpression.__proto__ = Node;
7401 FunctionExpression.prototype = Object.create( Node && Node.prototype );
7402 FunctionExpression.prototype.constructor = FunctionExpression;
7403
7404 FunctionExpression.prototype.initialise = function initialise ( transforms ) {
7405 if ( this.generator && transforms.generator ) {
7406 throw new CompileError$1( 'Generators are not supported', this );
7407 }
7408
7409 this.body.createScope();
7410
7411 if ( this.id ) {
7412 // function expression IDs belong to the child scope...
7413 this.body.scope.addDeclaration( this.id, 'function' );
7414 }
7415
7416 Node.prototype.initialise.call( this, transforms );
7417
7418 var parent = this.parent;
7419 var methodName;
7420
7421 if ( transforms.conciseMethodProperty
7422 && parent.type === 'Property'
7423 && parent.kind === 'init'
7424 && parent.method
7425 && parent.key.type === 'Identifier' ) {
7426 // object literal concise method
7427 methodName = parent.key.name;
7428 }
7429 else if ( transforms.classes
7430 && parent.type === 'MethodDefinition'
7431 && parent.kind === 'method'
7432 && parent.key.type === 'Identifier' ) {
7433 // method definition in a class
7434 methodName = parent.key.name;
7435 }
7436 else if ( this.id && this.id.type === 'Identifier' ) {
7437 // naked function expression
7438 methodName = this.id.alias || this.id.name;
7439 }
7440
7441 if ( methodName ) {
7442 for ( var i = 0, list = this.params; i < list.length; i += 1 ) {
7443 var param = list[i];
7444
7445 if ( param.type === 'Identifier' && methodName === param.name ) {
7446 // workaround for Safari 9/WebKit bug:
7447 // https://gitlab.com/Rich-Harris/buble/issues/154
7448 // change parameter name when same as method name
7449
7450 var scope = this.body.scope;
7451 var declaration = scope.declarations[ methodName ];
7452
7453 var alias = scope.createIdentifier( methodName );
7454 param.alias = alias;
7455
7456 for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
7457 var identifier = list$1[i$1];
7458
7459 identifier.alias = alias;
7460 }
7461
7462 break;
7463 }
7464 }
7465 }
7466 };
7467
7468 return FunctionExpression;
7469}(Node$1));
7470
7471function isReference ( node, parent ) {
7472 if ( node.type === 'MemberExpression' ) {
7473 return !node.computed && isReference( node.object, node );
7474 }
7475
7476 if ( node.type === 'Identifier' ) {
7477 // the only time we could have an identifier node without a parent is
7478 // if it's the entire body of a function without a block statement –
7479 // i.e. an arrow function expression like `a => a`
7480 if ( !parent ) return true;
7481
7482 if ( /(Function|Class)Expression/.test( parent.type ) ) return false;
7483
7484 if ( parent.type === 'VariableDeclarator' ) return node === parent.init;
7485
7486 // TODO is this right?
7487 if ( parent.type === 'MemberExpression' || parent.type === 'MethodDefinition' ) {
7488 return parent.computed || node === parent.object;
7489 }
7490
7491 if ( parent.type === 'ArrayPattern' ) return false;
7492
7493 // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
7494 if ( parent.type === 'Property' ) {
7495 if ( parent.parent.type === 'ObjectPattern' ) return false;
7496 return parent.computed || node === parent.value;
7497 }
7498
7499 // disregard the `bar` in `class Foo { bar () {...} }`
7500 if ( parent.type === 'MethodDefinition' ) return false;
7501
7502 // disregard the `bar` in `export { foo as bar }`
7503 if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return false;
7504
7505 return true;
7506 }
7507}
7508
7509var Identifier = (function (Node) {
7510 function Identifier () {
7511 Node.apply(this, arguments);
7512 }
7513
7514 if ( Node ) Identifier.__proto__ = Node;
7515 Identifier.prototype = Object.create( Node && Node.prototype );
7516 Identifier.prototype.constructor = Identifier;
7517
7518 Identifier.prototype.findScope = function findScope ( functionScope ) {
7519 if ( this.parent.params && ~this.parent.params.indexOf( this ) ) {
7520 return this.parent.body.scope;
7521 }
7522
7523 if ( this.parent.type === 'FunctionExpression' && this === this.parent.id ) {
7524 return this.parent.body.scope;
7525 }
7526
7527 return this.parent.findScope( functionScope );
7528 };
7529
7530 Identifier.prototype.initialise = function initialise ( transforms ) {
7531 if ( transforms.arrow && isReference( this, this.parent ) ) {
7532 if ( this.name === 'arguments' && !this.findScope( false ).contains( this.name ) ) {
7533 var lexicalBoundary = this.findLexicalBoundary();
7534 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
7535 var loop = this.findNearest( loopStatement );
7536
7537 if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
7538 this.alias = lexicalBoundary.getArgumentsAlias();
7539 }
7540
7541 if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
7542 this.alias = lexicalBoundary.getArgumentsAlias();
7543 }
7544 }
7545
7546 this.findScope( false ).addReference( this );
7547 }
7548 };
7549
7550 Identifier.prototype.transpile = function transpile ( code ) {
7551 if ( this.alias ) {
7552 code.overwrite( this.start, this.end, this.alias, { storeName: true, contentOnly: true });
7553 }
7554 };
7555
7556 return Identifier;
7557}(Node$1));
7558
7559var IfStatement = (function (Node) {
7560 function IfStatement () {
7561 Node.apply(this, arguments);
7562 }
7563
7564 if ( Node ) IfStatement.__proto__ = Node;
7565 IfStatement.prototype = Object.create( Node && Node.prototype );
7566 IfStatement.prototype.constructor = IfStatement;
7567
7568 IfStatement.prototype.initialise = function initialise ( transforms ) {
7569 Node.prototype.initialise.call( this, transforms );
7570 };
7571
7572 IfStatement.prototype.transpile = function transpile ( code, transforms ) {
7573 if ( this.consequent.type !== 'BlockStatement'
7574 || this.consequent.type === 'BlockStatement' && this.consequent.synthetic ) {
7575 code.appendLeft( this.consequent.start, '{ ' );
7576 code.prependRight( this.consequent.end, ' }' );
7577 }
7578
7579 if ( this.alternate && this.alternate.type !== 'IfStatement' && (
7580 this.alternate.type !== 'BlockStatement'
7581 || this.alternate.type === 'BlockStatement' && this.alternate.synthetic ) ) {
7582 code.appendLeft( this.alternate.start, '{ ' );
7583 code.prependRight( this.alternate.end, ' }' );
7584 }
7585
7586 Node.prototype.transpile.call( this, code, transforms );
7587 };
7588
7589 return IfStatement;
7590}(Node$1));
7591
7592var ImportDeclaration = (function (Node) {
7593 function ImportDeclaration () {
7594 Node.apply(this, arguments);
7595 }
7596
7597 if ( Node ) ImportDeclaration.__proto__ = Node;
7598 ImportDeclaration.prototype = Object.create( Node && Node.prototype );
7599 ImportDeclaration.prototype.constructor = ImportDeclaration;
7600
7601 ImportDeclaration.prototype.initialise = function initialise ( transforms ) {
7602 if ( transforms.moduleImport ) throw new CompileError$1( 'import is not supported', this );
7603 Node.prototype.initialise.call( this, transforms );
7604 };
7605
7606 return ImportDeclaration;
7607}(Node$1));
7608
7609var ImportDefaultSpecifier = (function (Node) {
7610 function ImportDefaultSpecifier () {
7611 Node.apply(this, arguments);
7612 }
7613
7614 if ( Node ) ImportDefaultSpecifier.__proto__ = Node;
7615 ImportDefaultSpecifier.prototype = Object.create( Node && Node.prototype );
7616 ImportDefaultSpecifier.prototype.constructor = ImportDefaultSpecifier;
7617
7618 ImportDefaultSpecifier.prototype.initialise = function initialise ( transforms ) {
7619 this.findScope( true ).addDeclaration( this.local, 'import' );
7620 Node.prototype.initialise.call( this, transforms );
7621 };
7622
7623 return ImportDefaultSpecifier;
7624}(Node$1));
7625
7626var ImportSpecifier = (function (Node) {
7627 function ImportSpecifier () {
7628 Node.apply(this, arguments);
7629 }
7630
7631 if ( Node ) ImportSpecifier.__proto__ = Node;
7632 ImportSpecifier.prototype = Object.create( Node && Node.prototype );
7633 ImportSpecifier.prototype.constructor = ImportSpecifier;
7634
7635 ImportSpecifier.prototype.initialise = function initialise ( transforms ) {
7636 this.findScope( true ).addDeclaration( this.local, 'import' );
7637 Node.prototype.initialise.call( this, transforms );
7638 };
7639
7640 return ImportSpecifier;
7641}(Node$1));
7642
7643var hasDashes = function ( val ) { return /-/.test(val); };
7644
7645var formatKey = function ( key ) { return hasDashes(key) ? ("'" + key + "'") : key; };
7646
7647var formatVal = function ( val ) { return val ? '' : 'true'; };
7648
7649var JSXAttribute = (function (Node) {
7650 function JSXAttribute () {
7651 Node.apply(this, arguments);
7652 }
7653
7654 if ( Node ) JSXAttribute.__proto__ = Node;
7655 JSXAttribute.prototype = Object.create( Node && Node.prototype );
7656 JSXAttribute.prototype.constructor = JSXAttribute;
7657
7658 JSXAttribute.prototype.transpile = function transpile ( code, transforms ) {
7659 var ref = this.name;
7660 var start = ref.start;
7661 var name = ref.name;
7662
7663 // Overwrite equals sign if value is present.
7664 var end = this.value ? this.value.start : this.name.end;
7665
7666 code.overwrite( start, end, ((formatKey(name)) + ": " + (formatVal(this.value))) );
7667
7668 Node.prototype.transpile.call( this, code, transforms );
7669 };
7670
7671 return JSXAttribute;
7672}(Node$1));
7673
7674function containsNewLine ( node ) {
7675 return node.type === 'Literal' && !/\S/.test( node.value ) && /\n/.test( node.value );
7676}
7677
7678var JSXClosingElement = (function (Node) {
7679 function JSXClosingElement () {
7680 Node.apply(this, arguments);
7681 }
7682
7683 if ( Node ) JSXClosingElement.__proto__ = Node;
7684 JSXClosingElement.prototype = Object.create( Node && Node.prototype );
7685 JSXClosingElement.prototype.constructor = JSXClosingElement;
7686
7687 JSXClosingElement.prototype.transpile = function transpile ( code ) {
7688 var spaceBeforeParen = true;
7689
7690 var lastChild = this.parent.children[ this.parent.children.length - 1 ];
7691
7692 // omit space before closing paren if
7693 // a) this is on a separate line, or
7694 // b) there are no children but there are attributes
7695 if ( ( lastChild && containsNewLine( lastChild ) ) || ( this.parent.openingElement.attributes.length ) ) {
7696 spaceBeforeParen = false;
7697 }
7698
7699 code.overwrite( this.start, this.end, spaceBeforeParen ? ' )' : ')' );
7700 };
7701
7702 return JSXClosingElement;
7703}(Node$1));
7704
7705function normalise ( str, removeTrailingWhitespace ) {
7706 if ( removeTrailingWhitespace && /\n/.test( str ) ) {
7707 str = str.replace( /\s+$/, '' );
7708 }
7709
7710 str = str
7711 .replace( /^\n\r?\s+/, '' ) // remove leading newline + space
7712 .replace( /\s*\n\r?\s*/gm, ' ' ); // replace newlines with spaces
7713
7714 // TODO prefer single quotes?
7715 return JSON.stringify( str );
7716}
7717
7718var JSXElement = (function (Node) {
7719 function JSXElement () {
7720 Node.apply(this, arguments);
7721 }
7722
7723 if ( Node ) JSXElement.__proto__ = Node;
7724 JSXElement.prototype = Object.create( Node && Node.prototype );
7725 JSXElement.prototype.constructor = JSXElement;
7726
7727 JSXElement.prototype.transpile = function transpile ( code, transforms ) {
7728 Node.prototype.transpile.call( this, code, transforms );
7729
7730 var children = this.children.filter( function ( child ) {
7731 if ( child.type !== 'Literal' ) return true;
7732
7733 // remove whitespace-only literals, unless on a single line
7734 return /\S/.test( child.value ) || !/\n/.test( child.value );
7735 });
7736
7737 if ( children.length ) {
7738 var c = this.openingElement.end;
7739
7740 var i;
7741 for ( i = 0; i < children.length; i += 1 ) {
7742 var child = children[i];
7743
7744 if ( child.type === 'JSXExpressionContainer' && child.expression.type === 'JSXEmptyExpression' ) {
7745 // empty block is a no op
7746 } else {
7747 var tail = code.original[ c ] === '\n' && child.type !== 'Literal' ? '' : ' ';
7748 code.appendLeft( c, ("," + tail) );
7749 }
7750
7751 if ( child.type === 'Literal' ) {
7752 var str = normalise( child.value, i === children.length - 1 );
7753 code.overwrite( child.start, child.end, str );
7754 }
7755
7756 c = child.end;
7757 }
7758 }
7759 };
7760
7761 return JSXElement;
7762}(Node$1));
7763
7764var JSXExpressionContainer = (function (Node) {
7765 function JSXExpressionContainer () {
7766 Node.apply(this, arguments);
7767 }
7768
7769 if ( Node ) JSXExpressionContainer.__proto__ = Node;
7770 JSXExpressionContainer.prototype = Object.create( Node && Node.prototype );
7771 JSXExpressionContainer.prototype.constructor = JSXExpressionContainer;
7772
7773 JSXExpressionContainer.prototype.transpile = function transpile ( code, transforms ) {
7774 code.remove( this.start, this.expression.start );
7775 code.remove( this.expression.end, this.end );
7776
7777 Node.prototype.transpile.call( this, code, transforms );
7778 };
7779
7780 return JSXExpressionContainer;
7781}(Node$1));
7782
7783var JSXOpeningElement = (function (Node) {
7784 function JSXOpeningElement () {
7785 Node.apply(this, arguments);
7786 }
7787
7788 if ( Node ) JSXOpeningElement.__proto__ = Node;
7789 JSXOpeningElement.prototype = Object.create( Node && Node.prototype );
7790 JSXOpeningElement.prototype.constructor = JSXOpeningElement;
7791
7792 JSXOpeningElement.prototype.transpile = function transpile ( code, transforms ) {
7793 var this$1 = this;
7794
7795 Node.prototype.transpile.call( this, code, transforms );
7796
7797 code.overwrite( this.start, this.name.start, ((this.program.jsx) + "( ") );
7798
7799 var html = this.name.type === 'JSXIdentifier' && this.name.name[0] === this.name.name[0].toLowerCase();
7800 if ( html ) code.prependRight( this.name.start, "'" );
7801
7802 var len = this.attributes.length;
7803 var c = this.name.end;
7804
7805 if ( len ) {
7806 var i;
7807
7808 var hasSpread = false;
7809 for ( i = 0; i < len; i += 1 ) {
7810 if ( this$1.attributes[i].type === 'JSXSpreadAttribute' ) {
7811 hasSpread = true;
7812 break;
7813 }
7814 }
7815
7816 c = this.attributes[0].end;
7817
7818 for ( i = 0; i < len; i += 1 ) {
7819 var attr = this$1.attributes[i];
7820
7821 if ( i > 0 ) {
7822 if ( attr.start === c )
7823 code.prependRight( c, ', ' );
7824 else
7825 code.overwrite( c, attr.start, ', ' );
7826 }
7827
7828 if ( hasSpread && attr.type !== 'JSXSpreadAttribute' ) {
7829 var lastAttr = this$1.attributes[ i - 1 ];
7830 var nextAttr = this$1.attributes[ i + 1 ];
7831
7832 if ( !lastAttr || lastAttr.type === 'JSXSpreadAttribute' ) {
7833 code.prependRight( attr.start, '{ ' );
7834 }
7835
7836 if ( !nextAttr || nextAttr.type === 'JSXSpreadAttribute' ) {
7837 code.appendLeft( attr.end, ' }' );
7838 }
7839 }
7840
7841 c = attr.end;
7842 }
7843
7844 var after;
7845 var before;
7846 if ( hasSpread ) {
7847 if ( len === 1 ) {
7848 before = html ? "'," : ',';
7849 } else {
7850 if (!this.program.options.objectAssign) {
7851 throw new CompileError$1( 'Mixed JSX attributes ending in spread requires specified objectAssign option with \'Object.assign\' or polyfill helper.', this );
7852 }
7853 before = html ? ("', " + (this.program.options.objectAssign) + "({},") : (", " + (this.program.options.objectAssign) + "({},");
7854 after = ')';
7855 }
7856 } else {
7857 before = html ? "', {" : ', {';
7858 after = ' }';
7859 }
7860
7861 code.prependRight( this.name.end, before );
7862
7863 if ( after ) {
7864 code.appendLeft( this.attributes[ len - 1 ].end, after );
7865 }
7866 } else {
7867 code.appendLeft( this.name.end, html ? "', null" : ", null" );
7868 c = this.name.end;
7869 }
7870
7871 if ( this.selfClosing ) {
7872 code.overwrite( c, this.end, this.attributes.length ? ")" : " )" );
7873 } else {
7874 code.remove( c, this.end );
7875 }
7876 };
7877
7878 return JSXOpeningElement;
7879}(Node$1));
7880
7881var JSXSpreadAttribute = (function (Node) {
7882 function JSXSpreadAttribute () {
7883 Node.apply(this, arguments);
7884 }
7885
7886 if ( Node ) JSXSpreadAttribute.__proto__ = Node;
7887 JSXSpreadAttribute.prototype = Object.create( Node && Node.prototype );
7888 JSXSpreadAttribute.prototype.constructor = JSXSpreadAttribute;
7889
7890 JSXSpreadAttribute.prototype.transpile = function transpile ( code, transforms ) {
7891 code.remove( this.start, this.argument.start );
7892 code.remove( this.argument.end, this.end );
7893
7894 Node.prototype.transpile.call( this, code, transforms );
7895 };
7896
7897 return JSXSpreadAttribute;
7898}(Node$1));
7899
7900var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
7901
7902function commonjsRequire () {
7903 throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
7904}
7905
7906
7907
7908function createCommonjsModule(fn, module) {
7909 return module = { exports: {} }, fn(module, module.exports), module.exports;
7910}
7911
7912var regjsgen = createCommonjsModule(function (module, exports) {
7913/*!
7914 * regjsgen 0.3.0
7915 * Copyright 2014-2016 Benjamin Tan <https://demoneaux.github.io/>
7916 * Available under MIT license <https://github.com/demoneaux/regjsgen/blob/master/LICENSE>
7917 */
7918(function() {
7919 'use strict';
7920
7921 // Used to determine if values are of the language type `Object`.
7922 var objectTypes = {
7923 'function': true,
7924 'object': true
7925 };
7926
7927 // Used as a reference to the global object.
7928 var root = (objectTypes[typeof window] && window) || this;
7929
7930 // Detect free variable `exports`.
7931 var freeExports = objectTypes['object'] && exports;
7932
7933 // Detect free variable `module`.
7934 var freeModule = objectTypes['object'] && module && !module.nodeType && module;
7935
7936 // Detect free variable `global` from Node.js or Browserified code and use it as `root`.
7937 var freeGlobal = freeExports && freeModule && typeof commonjsGlobal == 'object' && commonjsGlobal;
7938 if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
7939 root = freeGlobal;
7940 }
7941
7942 // Used to check objects for own properties.
7943 var hasOwnProperty = Object.prototype.hasOwnProperty;
7944
7945 /*--------------------------------------------------------------------------*/
7946
7947 // Generates strings based on the given code points.
7948 // Based on https://mths.be/fromcodepoint v0.2.0 by @mathias.
7949 var stringFromCharCode = String.fromCharCode;
7950 var floor = Math.floor;
7951 function fromCodePoint() {
7952 var MAX_SIZE = 0x4000;
7953 var codeUnits = [];
7954 var highSurrogate;
7955 var lowSurrogate;
7956 var index = -1;
7957 var length = arguments.length;
7958 if (!length) {
7959 return '';
7960 }
7961 var result = '';
7962 while (++index < length) {
7963 var codePoint = Number(arguments[index]);
7964 if (
7965 !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
7966 codePoint < 0 || // not a valid Unicode code point
7967 codePoint > 0x10FFFF || // not a valid Unicode code point
7968 floor(codePoint) != codePoint // not an integer
7969 ) {
7970 throw RangeError('Invalid code point: ' + codePoint);
7971 }
7972 if (codePoint <= 0xFFFF) {
7973 // BMP code point
7974 codeUnits.push(codePoint);
7975 } else {
7976 // Astral code point; split in surrogate halves
7977 // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
7978 codePoint -= 0x10000;
7979 highSurrogate = (codePoint >> 10) + 0xD800;
7980 lowSurrogate = (codePoint % 0x400) + 0xDC00;
7981 codeUnits.push(highSurrogate, lowSurrogate);
7982 }
7983 if (index + 1 == length || codeUnits.length > MAX_SIZE) {
7984 result += stringFromCharCode.apply(null, codeUnits);
7985 codeUnits.length = 0;
7986 }
7987 }
7988 return result;
7989 }
7990
7991 /*--------------------------------------------------------------------------*/
7992
7993 // Ensures that nodes have the correct types.
7994 var assertTypeRegexMap = {};
7995 function assertType(type, expected) {
7996 if (expected.indexOf('|') == -1) {
7997 if (type == expected) {
7998 return;
7999 }
8000
8001 throw Error('Invalid node type: ' + type + '; expected type: ' + expected);
8002 }
8003
8004 expected = hasOwnProperty.call(assertTypeRegexMap, expected)
8005 ? assertTypeRegexMap[expected]
8006 : (assertTypeRegexMap[expected] = RegExp('^(?:' + expected + ')$'));
8007
8008 if (expected.test(type)) {
8009 return;
8010 }
8011
8012 throw Error('Invalid node type: ' + type + '; expected types: ' + expected);
8013 }
8014
8015 /*--------------------------------------------------------------------------*/
8016
8017 // Generates a regular expression string based on an AST.
8018 function generate(node) {
8019 var type = node.type;
8020
8021 if (hasOwnProperty.call(generators, type)) {
8022 return generators[type](node);
8023 }
8024
8025 throw Error('Invalid node type: ' + type);
8026 }
8027
8028 /*--------------------------------------------------------------------------*/
8029
8030 function generateAlternative(node) {
8031 assertType(node.type, 'alternative');
8032
8033 var terms = node.body,
8034 i = -1,
8035 length = terms.length,
8036 result = '';
8037
8038 while (++i < length) {
8039 result += generateTerm(terms[i]);
8040 }
8041
8042 return result;
8043 }
8044
8045 function generateAnchor(node) {
8046 assertType(node.type, 'anchor');
8047
8048 switch (node.kind) {
8049 case 'start':
8050 return '^';
8051 case 'end':
8052 return '$';
8053 case 'boundary':
8054 return '\\b';
8055 case 'not-boundary':
8056 return '\\B';
8057 default:
8058 throw Error('Invalid assertion');
8059 }
8060 }
8061
8062 function generateAtom(node) {
8063 assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
8064
8065 return generate(node);
8066 }
8067
8068 function generateCharacterClass(node) {
8069 assertType(node.type, 'characterClass');
8070
8071 var classRanges = node.body,
8072 i = -1,
8073 length = classRanges.length,
8074 result = '';
8075
8076 if (node.negative) {
8077 result += '^';
8078 }
8079
8080 while (++i < length) {
8081 result += generateClassAtom(classRanges[i]);
8082 }
8083
8084 return '[' + result + ']';
8085 }
8086
8087 function generateCharacterClassEscape(node) {
8088 assertType(node.type, 'characterClassEscape');
8089
8090 return '\\' + node.value;
8091 }
8092
8093 function generateUnicodePropertyEscape(node) {
8094 assertType(node.type, 'unicodePropertyEscape');
8095
8096 return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
8097 }
8098
8099 function generateCharacterClassRange(node) {
8100 assertType(node.type, 'characterClassRange');
8101
8102 var min = node.min,
8103 max = node.max;
8104
8105 if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
8106 throw Error('Invalid character class range');
8107 }
8108
8109 return generateClassAtom(min) + '-' + generateClassAtom(max);
8110 }
8111
8112 function generateClassAtom(node) {
8113 assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value');
8114
8115 return generate(node);
8116 }
8117
8118 function generateDisjunction(node) {
8119 assertType(node.type, 'disjunction');
8120
8121 var body = node.body,
8122 i = -1,
8123 length = body.length,
8124 result = '';
8125
8126 while (++i < length) {
8127 if (i != 0) {
8128 result += '|';
8129 }
8130 result += generate(body[i]);
8131 }
8132
8133 return result;
8134 }
8135
8136 function generateDot(node) {
8137 assertType(node.type, 'dot');
8138
8139 return '.';
8140 }
8141
8142 function generateGroup(node) {
8143 assertType(node.type, 'group');
8144
8145 var result = '';
8146
8147 switch (node.behavior) {
8148 case 'normal':
8149 break;
8150 case 'ignore':
8151 result += '?:';
8152 break;
8153 case 'lookahead':
8154 result += '?=';
8155 break;
8156 case 'negativeLookahead':
8157 result += '?!';
8158 break;
8159 default:
8160 throw Error('Invalid behaviour: ' + node.behaviour);
8161 }
8162
8163 var body = node.body,
8164 i = -1,
8165 length = body.length;
8166
8167 while (++i < length) {
8168 result += generate(body[i]);
8169 }
8170
8171 return '(' + result + ')';
8172 }
8173
8174 function generateQuantifier(node) {
8175 assertType(node.type, 'quantifier');
8176
8177 var quantifier = '',
8178 min = node.min,
8179 max = node.max;
8180
8181 if (max == null) {
8182 if (min == 0) {
8183 quantifier = '*';
8184 } else if (min == 1) {
8185 quantifier = '+';
8186 } else {
8187 quantifier = '{' + min + ',}';
8188 }
8189 } else if (min == max) {
8190 quantifier = '{' + min + '}';
8191 } else if (min == 0 && max == 1) {
8192 quantifier = '?';
8193 } else {
8194 quantifier = '{' + min + ',' + max + '}';
8195 }
8196
8197 if (!node.greedy) {
8198 quantifier += '?';
8199 }
8200
8201 return generateAtom(node.body[0]) + quantifier;
8202 }
8203
8204 function generateReference(node) {
8205 assertType(node.type, 'reference');
8206
8207 return '\\' + node.matchIndex;
8208 }
8209
8210 function generateTerm(node) {
8211 assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value');
8212
8213 return generate(node);
8214 }
8215
8216 function generateValue(node) {
8217 assertType(node.type, 'value');
8218
8219 var kind = node.kind,
8220 codePoint = node.codePoint;
8221
8222 switch (kind) {
8223 case 'controlLetter':
8224 return '\\c' + fromCodePoint(codePoint + 64);
8225 case 'hexadecimalEscape':
8226 return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
8227 case 'identifier':
8228 return '\\' + fromCodePoint(codePoint);
8229 case 'null':
8230 return '\\' + codePoint;
8231 case 'octal':
8232 return '\\' + codePoint.toString(8);
8233 case 'singleEscape':
8234 switch (codePoint) {
8235 case 0x0008:
8236 return '\\b';
8237 case 0x0009:
8238 return '\\t';
8239 case 0x000A:
8240 return '\\n';
8241 case 0x000B:
8242 return '\\v';
8243 case 0x000C:
8244 return '\\f';
8245 case 0x000D:
8246 return '\\r';
8247 default:
8248 throw Error('Invalid codepoint: ' + codePoint);
8249 }
8250 case 'symbol':
8251 return fromCodePoint(codePoint);
8252 case 'unicodeEscape':
8253 return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
8254 case 'unicodeCodePointEscape':
8255 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
8256 default:
8257 throw Error('Unsupported node kind: ' + kind);
8258 }
8259 }
8260
8261 /*--------------------------------------------------------------------------*/
8262
8263 // Used to generate strings for each node type.
8264 var generators = {
8265 'alternative': generateAlternative,
8266 'anchor': generateAnchor,
8267 'characterClass': generateCharacterClass,
8268 'characterClassEscape': generateCharacterClassEscape,
8269 'characterClassRange': generateCharacterClassRange,
8270 'unicodePropertyEscape': generateUnicodePropertyEscape,
8271 'disjunction': generateDisjunction,
8272 'dot': generateDot,
8273 'group': generateGroup,
8274 'quantifier': generateQuantifier,
8275 'reference': generateReference,
8276 'value': generateValue
8277 };
8278
8279 /*--------------------------------------------------------------------------*/
8280
8281 // Export regjsgen.
8282 // Some AMD build optimizers, like r.js, check for condition patterns like the following:
8283 if (typeof undefined == 'function' && typeof undefined.amd == 'object' && undefined.amd) {
8284 // Define as an anonymous module so it can be aliased through path mapping.
8285 undefined(function() {
8286 return {
8287 'generate': generate
8288 };
8289 });
8290 }
8291 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
8292 else if (freeExports && freeModule) {
8293 // Export for CommonJS support.
8294 freeExports.generate = generate;
8295 }
8296 else {
8297 // Export to the global object.
8298 root.regjsgen = {
8299 'generate': generate
8300 };
8301 }
8302}.call(commonjsGlobal));
8303});
8304
8305var parser = createCommonjsModule(function (module) {
8306// regjsparser
8307//
8308// ==================================================================
8309//
8310// See ECMA-262 Standard: 15.10.1
8311//
8312// NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the
8313// term "Anchor" is used.
8314//
8315// Pattern ::
8316// Disjunction
8317//
8318// Disjunction ::
8319// Alternative
8320// Alternative | Disjunction
8321//
8322// Alternative ::
8323// [empty]
8324// Alternative Term
8325//
8326// Term ::
8327// Anchor
8328// Atom
8329// Atom Quantifier
8330//
8331// Anchor ::
8332// ^
8333// $
8334// \ b
8335// \ B
8336// ( ? = Disjunction )
8337// ( ? ! Disjunction )
8338//
8339// Quantifier ::
8340// QuantifierPrefix
8341// QuantifierPrefix ?
8342//
8343// QuantifierPrefix ::
8344// *
8345// +
8346// ?
8347// { DecimalDigits }
8348// { DecimalDigits , }
8349// { DecimalDigits , DecimalDigits }
8350//
8351// Atom ::
8352// PatternCharacter
8353// .
8354// \ AtomEscape
8355// CharacterClass
8356// ( Disjunction )
8357// ( ? : Disjunction )
8358//
8359// PatternCharacter ::
8360// SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |
8361//
8362// AtomEscape ::
8363// DecimalEscape
8364// CharacterEscape
8365// CharacterClassEscape
8366//
8367// CharacterEscape[U] ::
8368// ControlEscape
8369// c ControlLetter
8370// HexEscapeSequence
8371// RegExpUnicodeEscapeSequence[?U] (ES6)
8372// IdentityEscape[?U]
8373//
8374// ControlEscape ::
8375// one of f n r t v
8376// ControlLetter ::
8377// one of
8378// 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
8379// 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
8380//
8381// IdentityEscape ::
8382// SourceCharacter but not IdentifierPart
8383// <ZWJ>
8384// <ZWNJ>
8385//
8386// DecimalEscape ::
8387// DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
8388//
8389// CharacterClassEscape ::
8390// one of d D s S w W
8391//
8392// CharacterClass ::
8393// [ [lookahead ∉ {^}] ClassRanges ]
8394// [ ^ ClassRanges ]
8395//
8396// ClassRanges ::
8397// [empty]
8398// NonemptyClassRanges
8399//
8400// NonemptyClassRanges ::
8401// ClassAtom
8402// ClassAtom NonemptyClassRangesNoDash
8403// ClassAtom - ClassAtom ClassRanges
8404//
8405// NonemptyClassRangesNoDash ::
8406// ClassAtom
8407// ClassAtomNoDash NonemptyClassRangesNoDash
8408// ClassAtomNoDash - ClassAtom ClassRanges
8409//
8410// ClassAtom ::
8411// -
8412// ClassAtomNoDash
8413//
8414// ClassAtomNoDash ::
8415// SourceCharacter but not one of \ or ] or -
8416// \ ClassEscape
8417//
8418// ClassEscape ::
8419// DecimalEscape
8420// b
8421// CharacterEscape
8422// CharacterClassEscape
8423
8424(function() {
8425
8426 function parse(str, flags, features) {
8427 if (!features) {
8428 features = {};
8429 }
8430 function addRaw(node) {
8431 node.raw = str.substring(node.range[0], node.range[1]);
8432 return node;
8433 }
8434
8435 function updateRawStart(node, start) {
8436 node.range[0] = start;
8437 return addRaw(node);
8438 }
8439
8440 function createAnchor(kind, rawLength) {
8441 return addRaw({
8442 type: 'anchor',
8443 kind: kind,
8444 range: [
8445 pos - rawLength,
8446 pos
8447 ]
8448 });
8449 }
8450
8451 function createValue(kind, codePoint, from, to) {
8452 return addRaw({
8453 type: 'value',
8454 kind: kind,
8455 codePoint: codePoint,
8456 range: [from, to]
8457 });
8458 }
8459
8460 function createEscaped(kind, codePoint, value, fromOffset) {
8461 fromOffset = fromOffset || 0;
8462 return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);
8463 }
8464
8465 function createCharacter(matches) {
8466 var _char = matches[0];
8467 var first = _char.charCodeAt(0);
8468 if (hasUnicodeFlag) {
8469 var second;
8470 if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
8471 second = lookahead().charCodeAt(0);
8472 if (second >= 0xDC00 && second <= 0xDFFF) {
8473 // Unicode surrogate pair
8474 pos++;
8475 return createValue(
8476 'symbol',
8477 (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,
8478 pos - 2, pos);
8479 }
8480 }
8481 }
8482 return createValue('symbol', first, pos - 1, pos);
8483 }
8484
8485 function createDisjunction(alternatives, from, to) {
8486 return addRaw({
8487 type: 'disjunction',
8488 body: alternatives,
8489 range: [
8490 from,
8491 to
8492 ]
8493 });
8494 }
8495
8496 function createDot() {
8497 return addRaw({
8498 type: 'dot',
8499 range: [
8500 pos - 1,
8501 pos
8502 ]
8503 });
8504 }
8505
8506 function createCharacterClassEscape(value) {
8507 return addRaw({
8508 type: 'characterClassEscape',
8509 value: value,
8510 range: [
8511 pos - 2,
8512 pos
8513 ]
8514 });
8515 }
8516
8517 function createReference(matchIndex) {
8518 return addRaw({
8519 type: 'reference',
8520 matchIndex: parseInt(matchIndex, 10),
8521 range: [
8522 pos - 1 - matchIndex.length,
8523 pos
8524 ]
8525 });
8526 }
8527
8528 function createGroup(behavior, disjunction, from, to) {
8529 return addRaw({
8530 type: 'group',
8531 behavior: behavior,
8532 body: disjunction,
8533 range: [
8534 from,
8535 to
8536 ]
8537 });
8538 }
8539
8540 function createQuantifier(min, max, from, to) {
8541 if (to == null) {
8542 from = pos - 1;
8543 to = pos;
8544 }
8545
8546 return addRaw({
8547 type: 'quantifier',
8548 min: min,
8549 max: max,
8550 greedy: true,
8551 body: null, // set later on
8552 range: [
8553 from,
8554 to
8555 ]
8556 });
8557 }
8558
8559 function createAlternative(terms, from, to) {
8560 return addRaw({
8561 type: 'alternative',
8562 body: terms,
8563 range: [
8564 from,
8565 to
8566 ]
8567 });
8568 }
8569
8570 function createCharacterClass(classRanges, negative, from, to) {
8571 return addRaw({
8572 type: 'characterClass',
8573 body: classRanges,
8574 negative: negative,
8575 range: [
8576 from,
8577 to
8578 ]
8579 });
8580 }
8581
8582 function createClassRange(min, max, from, to) {
8583 // See 15.10.2.15:
8584 if (min.codePoint > max.codePoint) {
8585 bail('invalid range in character class', min.raw + '-' + max.raw, from, to);
8586 }
8587
8588 return addRaw({
8589 type: 'characterClassRange',
8590 min: min,
8591 max: max,
8592 range: [
8593 from,
8594 to
8595 ]
8596 });
8597 }
8598
8599 function flattenBody(body) {
8600 if (body.type === 'alternative') {
8601 return body.body;
8602 } else {
8603 return [body];
8604 }
8605 }
8606
8607 function incr(amount) {
8608 amount = (amount || 1);
8609 var res = str.substring(pos, pos + amount);
8610 pos += (amount || 1);
8611 return res;
8612 }
8613
8614 function skip(value) {
8615 if (!match(value)) {
8616 bail('character', value);
8617 }
8618 }
8619
8620 function match(value) {
8621 if (str.indexOf(value, pos) === pos) {
8622 return incr(value.length);
8623 }
8624 }
8625
8626 function lookahead() {
8627 return str[pos];
8628 }
8629
8630 function current(value) {
8631 return str.indexOf(value, pos) === pos;
8632 }
8633
8634 function next(value) {
8635 return str[pos + 1] === value;
8636 }
8637
8638 function matchReg(regExp) {
8639 var subStr = str.substring(pos);
8640 var res = subStr.match(regExp);
8641 if (res) {
8642 res.range = [];
8643 res.range[0] = pos;
8644 incr(res[0].length);
8645 res.range[1] = pos;
8646 }
8647 return res;
8648 }
8649
8650 function parseDisjunction() {
8651 // Disjunction ::
8652 // Alternative
8653 // Alternative | Disjunction
8654 var res = [], from = pos;
8655 res.push(parseAlternative());
8656
8657 while (match('|')) {
8658 res.push(parseAlternative());
8659 }
8660
8661 if (res.length === 1) {
8662 return res[0];
8663 }
8664
8665 return createDisjunction(res, from, pos);
8666 }
8667
8668 function parseAlternative() {
8669 var res = [], from = pos;
8670 var term;
8671
8672 // Alternative ::
8673 // [empty]
8674 // Alternative Term
8675 while (term = parseTerm()) {
8676 res.push(term);
8677 }
8678
8679 if (res.length === 1) {
8680 return res[0];
8681 }
8682
8683 return createAlternative(res, from, pos);
8684 }
8685
8686 function parseTerm() {
8687 // Term ::
8688 // Anchor
8689 // Atom
8690 // Atom Quantifier
8691
8692 if (pos >= str.length || current('|') || current(')')) {
8693 return null; /* Means: The term is empty */
8694 }
8695
8696 var anchor = parseAnchor();
8697
8698 if (anchor) {
8699 return anchor;
8700 }
8701
8702 var atom = parseAtom();
8703 if (!atom) {
8704 bail('Expected atom');
8705 }
8706 var quantifier = parseQuantifier() || false;
8707 if (quantifier) {
8708 quantifier.body = flattenBody(atom);
8709 // The quantifier contains the atom. Therefore, the beginning of the
8710 // quantifier range is given by the beginning of the atom.
8711 updateRawStart(quantifier, atom.range[0]);
8712 return quantifier;
8713 }
8714 return atom;
8715 }
8716
8717 function parseGroup(matchA, typeA, matchB, typeB) {
8718 var type = null, from = pos;
8719
8720 if (match(matchA)) {
8721 type = typeA;
8722 } else if (match(matchB)) {
8723 type = typeB;
8724 } else {
8725 return false;
8726 }
8727
8728 var body = parseDisjunction();
8729 if (!body) {
8730 bail('Expected disjunction');
8731 }
8732 skip(')');
8733 var group = createGroup(type, flattenBody(body), from, pos);
8734
8735 if (type == 'normal') {
8736 // Keep track of the number of closed groups. This is required for
8737 // parseDecimalEscape(). In case the string is parsed a second time the
8738 // value already holds the total count and no incrementation is required.
8739 if (firstIteration) {
8740 closedCaptureCounter++;
8741 }
8742 }
8743 return group;
8744 }
8745
8746 function parseAnchor() {
8747 // Anchor ::
8748 // ^
8749 // $
8750 // \ b
8751 // \ B
8752 // ( ? = Disjunction )
8753 // ( ? ! Disjunction )
8754 if (match('^')) {
8755 return createAnchor('start', 1 /* rawLength */);
8756 } else if (match('$')) {
8757 return createAnchor('end', 1 /* rawLength */);
8758 } else if (match('\\b')) {
8759 return createAnchor('boundary', 2 /* rawLength */);
8760 } else if (match('\\B')) {
8761 return createAnchor('not-boundary', 2 /* rawLength */);
8762 } else {
8763 return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');
8764 }
8765 }
8766
8767 function parseQuantifier() {
8768 // Quantifier ::
8769 // QuantifierPrefix
8770 // QuantifierPrefix ?
8771 //
8772 // QuantifierPrefix ::
8773 // *
8774 // +
8775 // ?
8776 // { DecimalDigits }
8777 // { DecimalDigits , }
8778 // { DecimalDigits , DecimalDigits }
8779
8780 var res, from = pos;
8781 var quantifier;
8782 var min, max;
8783
8784 if (match('*')) {
8785 quantifier = createQuantifier(0);
8786 }
8787 else if (match('+')) {
8788 quantifier = createQuantifier(1);
8789 }
8790 else if (match('?')) {
8791 quantifier = createQuantifier(0, 1);
8792 }
8793 else if (res = matchReg(/^\{([0-9]+)\}/)) {
8794 min = parseInt(res[1], 10);
8795 quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
8796 }
8797 else if (res = matchReg(/^\{([0-9]+),\}/)) {
8798 min = parseInt(res[1], 10);
8799 quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
8800 }
8801 else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
8802 min = parseInt(res[1], 10);
8803 max = parseInt(res[2], 10);
8804 if (min > max) {
8805 bail('numbers out of order in {} quantifier', '', from, pos);
8806 }
8807 quantifier = createQuantifier(min, max, res.range[0], res.range[1]);
8808 }
8809
8810 if (quantifier) {
8811 if (match('?')) {
8812 quantifier.greedy = false;
8813 quantifier.range[1] += 1;
8814 }
8815 }
8816
8817 return quantifier;
8818 }
8819
8820 function parseAtom() {
8821 // Atom ::
8822 // PatternCharacter
8823 // .
8824 // \ AtomEscape
8825 // CharacterClass
8826 // ( Disjunction )
8827 // ( ? : Disjunction )
8828
8829 var res;
8830
8831 // jviereck: allow ']', '}' here as well to be compatible with browser's
8832 // implementations: ']'.match(/]/);
8833 // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) {
8834 if (res = matchReg(/^[^^$\\.*+?(){[|]/)) {
8835 // PatternCharacter
8836 return createCharacter(res);
8837 }
8838 else if (match('.')) {
8839 // .
8840 return createDot();
8841 }
8842 else if (match('\\')) {
8843 // \ AtomEscape
8844 res = parseAtomEscape();
8845 if (!res) {
8846 bail('atomEscape');
8847 }
8848 return res;
8849 }
8850 else if (res = parseCharacterClass()) {
8851 return res;
8852 }
8853 else {
8854 // ( Disjunction )
8855 // ( ? : Disjunction )
8856 return parseGroup('(?:', 'ignore', '(', 'normal');
8857 }
8858 }
8859
8860 function parseUnicodeSurrogatePairEscape(firstEscape) {
8861 if (hasUnicodeFlag) {
8862 var first, second;
8863 if (firstEscape.kind == 'unicodeEscape' &&
8864 (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&
8865 current('\\') && next('u') ) {
8866 var prevPos = pos;
8867 pos++;
8868 var secondEscape = parseClassEscape();
8869 if (secondEscape.kind == 'unicodeEscape' &&
8870 (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {
8871 // Unicode surrogate pair
8872 firstEscape.range[1] = secondEscape.range[1];
8873 firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
8874 firstEscape.type = 'value';
8875 firstEscape.kind = 'unicodeCodePointEscape';
8876 addRaw(firstEscape);
8877 }
8878 else {
8879 pos = prevPos;
8880 }
8881 }
8882 }
8883 return firstEscape;
8884 }
8885
8886 function parseClassEscape() {
8887 return parseAtomEscape(true);
8888 }
8889
8890 function parseAtomEscape(insideCharacterClass) {
8891 // AtomEscape ::
8892 // DecimalEscape
8893 // CharacterEscape
8894 // CharacterClassEscape
8895
8896 var res, from = pos;
8897
8898 res = parseDecimalEscape();
8899 if (res) {
8900 return res;
8901 }
8902
8903 // For ClassEscape
8904 if (insideCharacterClass) {
8905 if (match('b')) {
8906 // 15.10.2.19
8907 // The production ClassEscape :: b evaluates by returning the
8908 // CharSet containing the one character <BS> (Unicode value 0008).
8909 return createEscaped('singleEscape', 0x0008, '\\b');
8910 } else if (match('B')) {
8911 bail('\\B not possible inside of CharacterClass', '', from);
8912 }
8913 }
8914
8915 res = parseCharacterEscape();
8916
8917 return res;
8918 }
8919
8920
8921 function parseDecimalEscape() {
8922 // DecimalEscape ::
8923 // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
8924 // CharacterClassEscape :: one of d D s S w W
8925
8926 var res, match;
8927
8928 if (res = matchReg(/^(?!0)\d+/)) {
8929 match = res[0];
8930 var refIdx = parseInt(res[0], 10);
8931 if (refIdx <= closedCaptureCounter) {
8932 // If the number is smaller than the normal-groups found so
8933 // far, then it is a reference...
8934 return createReference(res[0]);
8935 } else {
8936 // ... otherwise it needs to be interpreted as a octal (if the
8937 // number is in an octal format). If it is NOT octal format,
8938 // then the slash is ignored and the number is matched later
8939 // as normal characters.
8940
8941 // Recall the negative decision to decide if the input must be parsed
8942 // a second time with the total normal-groups.
8943 backrefDenied.push(refIdx);
8944
8945 // Reset the position again, as maybe only parts of the previous
8946 // matched numbers are actual octal numbers. E.g. in '019' only
8947 // the '01' should be matched.
8948 incr(-res[0].length);
8949 if (res = matchReg(/^[0-7]{1,3}/)) {
8950 return createEscaped('octal', parseInt(res[0], 8), res[0], 1);
8951 } else {
8952 // If we end up here, we have a case like /\91/. Then the
8953 // first slash is to be ignored and the 9 & 1 to be treated
8954 // like ordinary characters. Create a character for the
8955 // first number only here - other number-characters
8956 // (if available) will be matched later.
8957 res = createCharacter(matchReg(/^[89]/));
8958 return updateRawStart(res, res.range[0] - 1);
8959 }
8960 }
8961 }
8962 // Only allow octal numbers in the following. All matched numbers start
8963 // with a zero (if the do not, the previous if-branch is executed).
8964 // If the number is not octal format and starts with zero (e.g. `091`)
8965 // then only the zeros `0` is treated here and the `91` are ordinary
8966 // characters.
8967 // Example:
8968 // /\091/.exec('\091')[0].length === 3
8969 else if (res = matchReg(/^[0-7]{1,3}/)) {
8970 match = res[0];
8971 if (/^0{1,3}$/.test(match)) {
8972 // If they are all zeros, then only take the first one.
8973 return createEscaped('null', 0x0000, '0', match.length + 1);
8974 } else {
8975 return createEscaped('octal', parseInt(match, 8), match, 1);
8976 }
8977 } else if (res = matchReg(/^[dDsSwW]/)) {
8978 return createCharacterClassEscape(res[0]);
8979 }
8980 return false;
8981 }
8982
8983 function parseCharacterEscape() {
8984 // CharacterEscape ::
8985 // ControlEscape
8986 // c ControlLetter
8987 // HexEscapeSequence
8988 // UnicodeEscapeSequence
8989 // IdentityEscape
8990
8991 var res;
8992 if (res = matchReg(/^[fnrtv]/)) {
8993 // ControlEscape
8994 var codePoint = 0;
8995 switch (res[0]) {
8996 case 't': codePoint = 0x009; break;
8997 case 'n': codePoint = 0x00A; break;
8998 case 'v': codePoint = 0x00B; break;
8999 case 'f': codePoint = 0x00C; break;
9000 case 'r': codePoint = 0x00D; break;
9001 }
9002 return createEscaped('singleEscape', codePoint, '\\' + res[0]);
9003 } else if (res = matchReg(/^c([a-zA-Z])/)) {
9004 // c ControlLetter
9005 return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);
9006 } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) {
9007 // HexEscapeSequence
9008 return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2);
9009 } else if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {
9010 // UnicodeEscapeSequence
9011 return parseUnicodeSurrogatePairEscape(
9012 createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2)
9013 );
9014 } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {
9015 // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)
9016 return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);
9017 } else if (features.unicodePropertyEscape && hasUnicodeFlag && (res = matchReg(/^([pP])\{([^\}]+)\}/))) {
9018 // https://github.com/jviereck/regjsparser/issues/77
9019 return addRaw({
9020 type: 'unicodePropertyEscape',
9021 negative: res[1] === 'P',
9022 value: res[2],
9023 range: [res.range[0] - 1, res.range[1]],
9024 raw: res[0]
9025 });
9026 } else {
9027 // IdentityEscape
9028 return parseIdentityEscape();
9029 }
9030 }
9031
9032 // Taken from the Esprima parser.
9033 function isIdentifierPart(ch) {
9034 // Generated by `tools/generate-identifier-regex.js`.
9035 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]');
9036
9037 return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
9038 (ch >= 65 && ch <= 90) || // A..Z
9039 (ch >= 97 && ch <= 122) || // a..z
9040 (ch >= 48 && ch <= 57) || // 0..9
9041 (ch === 92) || // \ (backslash)
9042 ((ch >= 0x80) && NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
9043 }
9044
9045 function parseIdentityEscape() {
9046 // IdentityEscape ::
9047 // SourceCharacter but not IdentifierPart
9048 // <ZWJ>
9049 // <ZWNJ>
9050
9051 var ZWJ = '\u200C';
9052 var ZWNJ = '\u200D';
9053
9054 var tmp;
9055
9056 if (!isIdentifierPart(lookahead())) {
9057 tmp = incr();
9058 return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1);
9059 }
9060
9061 if (match(ZWJ)) {
9062 // <ZWJ>
9063 return createEscaped('identifier', 0x200C, ZWJ);
9064 } else if (match(ZWNJ)) {
9065 // <ZWNJ>
9066 return createEscaped('identifier', 0x200D, ZWNJ);
9067 }
9068
9069 return null;
9070 }
9071
9072 function parseCharacterClass() {
9073 // CharacterClass ::
9074 // [ [lookahead ∉ {^}] ClassRanges ]
9075 // [ ^ ClassRanges ]
9076
9077 var res, from = pos;
9078 if (res = matchReg(/^\[\^/)) {
9079 res = parseClassRanges();
9080 skip(']');
9081 return createCharacterClass(res, true, from, pos);
9082 } else if (match('[')) {
9083 res = parseClassRanges();
9084 skip(']');
9085 return createCharacterClass(res, false, from, pos);
9086 }
9087
9088 return null;
9089 }
9090
9091 function parseClassRanges() {
9092 // ClassRanges ::
9093 // [empty]
9094 // NonemptyClassRanges
9095
9096 var res;
9097 if (current(']')) {
9098 // Empty array means nothing insinde of the ClassRange.
9099 return [];
9100 } else {
9101 res = parseNonemptyClassRanges();
9102 if (!res) {
9103 bail('nonEmptyClassRanges');
9104 }
9105 return res;
9106 }
9107 }
9108
9109 function parseHelperClassRanges(atom) {
9110 var from, to, res;
9111 if (current('-') && !next(']')) {
9112 // ClassAtom - ClassAtom ClassRanges
9113 skip('-');
9114
9115 res = parseClassAtom();
9116 if (!res) {
9117 bail('classAtom');
9118 }
9119 to = pos;
9120 var classRanges = parseClassRanges();
9121 if (!classRanges) {
9122 bail('classRanges');
9123 }
9124 from = atom.range[0];
9125 if (classRanges.type === 'empty') {
9126 return [createClassRange(atom, res, from, to)];
9127 }
9128 return [createClassRange(atom, res, from, to)].concat(classRanges);
9129 }
9130
9131 res = parseNonemptyClassRangesNoDash();
9132 if (!res) {
9133 bail('nonEmptyClassRangesNoDash');
9134 }
9135
9136 return [atom].concat(res);
9137 }
9138
9139 function parseNonemptyClassRanges() {
9140 // NonemptyClassRanges ::
9141 // ClassAtom
9142 // ClassAtom NonemptyClassRangesNoDash
9143 // ClassAtom - ClassAtom ClassRanges
9144
9145 var atom = parseClassAtom();
9146 if (!atom) {
9147 bail('classAtom');
9148 }
9149
9150 if (current(']')) {
9151 // ClassAtom
9152 return [atom];
9153 }
9154
9155 // ClassAtom NonemptyClassRangesNoDash
9156 // ClassAtom - ClassAtom ClassRanges
9157 return parseHelperClassRanges(atom);
9158 }
9159
9160 function parseNonemptyClassRangesNoDash() {
9161 // NonemptyClassRangesNoDash ::
9162 // ClassAtom
9163 // ClassAtomNoDash NonemptyClassRangesNoDash
9164 // ClassAtomNoDash - ClassAtom ClassRanges
9165
9166 var res = parseClassAtom();
9167 if (!res) {
9168 bail('classAtom');
9169 }
9170 if (current(']')) {
9171 // ClassAtom
9172 return res;
9173 }
9174
9175 // ClassAtomNoDash NonemptyClassRangesNoDash
9176 // ClassAtomNoDash - ClassAtom ClassRanges
9177 return parseHelperClassRanges(res);
9178 }
9179
9180 function parseClassAtom() {
9181 // ClassAtom ::
9182 // -
9183 // ClassAtomNoDash
9184 if (match('-')) {
9185 return createCharacter('-');
9186 } else {
9187 return parseClassAtomNoDash();
9188 }
9189 }
9190
9191 function parseClassAtomNoDash() {
9192 // ClassAtomNoDash ::
9193 // SourceCharacter but not one of \ or ] or -
9194 // \ ClassEscape
9195
9196 var res;
9197 if (res = matchReg(/^[^\\\]-]/)) {
9198 return createCharacter(res[0]);
9199 } else if (match('\\')) {
9200 res = parseClassEscape();
9201 if (!res) {
9202 bail('classEscape');
9203 }
9204
9205 return parseUnicodeSurrogatePairEscape(res);
9206 }
9207 }
9208
9209 function bail(message, details, from, to) {
9210 from = from == null ? pos : from;
9211 to = to == null ? from : to;
9212
9213 var contextStart = Math.max(0, from - 10);
9214 var contextEnd = Math.min(to + 10, str.length);
9215
9216 // Output a bit of context and a line pointing to where our error is.
9217 //
9218 // We are assuming that there are no actual newlines in the content as this is a regular expression.
9219 var context = ' ' + str.substring(contextStart, contextEnd);
9220 var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^';
9221
9222 throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer);
9223 }
9224
9225 var backrefDenied = [];
9226 var closedCaptureCounter = 0;
9227 var firstIteration = true;
9228 var hasUnicodeFlag = (flags || "").indexOf("u") !== -1;
9229 var pos = 0;
9230
9231 // Convert the input to a string and treat the empty string special.
9232 str = String(str);
9233 if (str === '') {
9234 str = '(?:)';
9235 }
9236
9237 var result = parseDisjunction();
9238
9239 if (result.range[1] !== str.length) {
9240 bail('Could not parse entire input - got stuck', '', result.range[1]);
9241 }
9242
9243 // The spec requires to interpret the `\2` in `/\2()()/` as backreference.
9244 // As the parser collects the number of capture groups as the string is
9245 // parsed it is impossible to make these decisions at the point when the
9246 // `\2` is handled. In case the local decision turns out to be wrong after
9247 // the parsing has finished, the input string is parsed a second time with
9248 // the total number of capture groups set.
9249 //
9250 // SEE: https://github.com/jviereck/regjsparser/issues/70
9251 for (var i = 0; i < backrefDenied.length; i++) {
9252 if (backrefDenied[i] <= closedCaptureCounter) {
9253 // Parse the input a second time.
9254 pos = 0;
9255 firstIteration = false;
9256 return parseDisjunction();
9257 }
9258 }
9259
9260 return result;
9261 }
9262
9263 var regjsparser = {
9264 parse: parse
9265 };
9266
9267 if ('object' !== 'undefined' && module.exports) {
9268 module.exports = regjsparser;
9269 } else {
9270 window.regjsparser = regjsparser;
9271 }
9272
9273}());
9274});
9275
9276var regenerate = createCommonjsModule(function (module, exports) {
9277/*! https://mths.be/regenerate v1.3.3 by @mathias | MIT license */
9278(function(root) {
9279
9280 // Detect free variables `exports`.
9281 var freeExports = 'object' == 'object' && exports;
9282
9283 // Detect free variable `module`.
9284 var freeModule = 'object' == 'object' && module &&
9285 module.exports == freeExports && module;
9286
9287 // Detect free variable `global`, from Node.js/io.js or Browserified code,
9288 // and use it as `root`.
9289 var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
9290 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
9291 root = freeGlobal;
9292 }
9293
9294 /*--------------------------------------------------------------------------*/
9295
9296 var ERRORS = {
9297 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
9298 'to the `start` value.',
9299 'codePointRange': 'Invalid code point value. Code points range from ' +
9300 'U+000000 to U+10FFFF.'
9301 };
9302
9303 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
9304 var HIGH_SURROGATE_MIN = 0xD800;
9305 var HIGH_SURROGATE_MAX = 0xDBFF;
9306 var LOW_SURROGATE_MIN = 0xDC00;
9307 var LOW_SURROGATE_MAX = 0xDFFF;
9308
9309 // In Regenerate output, `\0` is never preceded by `\` because we sort by
9310 // code point value, so let’s keep this regular expression simple.
9311 var regexNull = /\\x00([^0123456789]|$)/g;
9312
9313 var object = {};
9314 var hasOwnProperty = object.hasOwnProperty;
9315 var extend = function(destination, source) {
9316 var key;
9317 for (key in source) {
9318 if (hasOwnProperty.call(source, key)) {
9319 destination[key] = source[key];
9320 }
9321 }
9322 return destination;
9323 };
9324
9325 var forEach = function(array, callback) {
9326 var index = -1;
9327 var length = array.length;
9328 while (++index < length) {
9329 callback(array[index], index);
9330 }
9331 };
9332
9333 var toString = object.toString;
9334 var isArray = function(value) {
9335 return toString.call(value) == '[object Array]';
9336 };
9337 var isNumber = function(value) {
9338 return typeof value == 'number' ||
9339 toString.call(value) == '[object Number]';
9340 };
9341
9342 // This assumes that `number` is a positive integer that `toString()`s nicely
9343 // (which is the case for all code point values).
9344 var zeroes = '0000';
9345 var pad = function(number, totalCharacters) {
9346 var string = String(number);
9347 return string.length < totalCharacters
9348 ? (zeroes + string).slice(-totalCharacters)
9349 : string;
9350 };
9351
9352 var hex = function(number) {
9353 return Number(number).toString(16).toUpperCase();
9354 };
9355
9356 var slice = [].slice;
9357
9358 /*--------------------------------------------------------------------------*/
9359
9360 var dataFromCodePoints = function(codePoints) {
9361 var index = -1;
9362 var length = codePoints.length;
9363 var max = length - 1;
9364 var result = [];
9365 var isStart = true;
9366 var tmp;
9367 var previous = 0;
9368 while (++index < length) {
9369 tmp = codePoints[index];
9370 if (isStart) {
9371 result.push(tmp);
9372 previous = tmp;
9373 isStart = false;
9374 } else {
9375 if (tmp == previous + 1) {
9376 if (index != max) {
9377 previous = tmp;
9378 continue;
9379 } else {
9380 isStart = true;
9381 result.push(tmp + 1);
9382 }
9383 } else {
9384 // End the previous range and start a new one.
9385 result.push(previous + 1, tmp);
9386 previous = tmp;
9387 }
9388 }
9389 }
9390 if (!isStart) {
9391 result.push(tmp + 1);
9392 }
9393 return result;
9394 };
9395
9396 var dataRemove = function(data, codePoint) {
9397 // Iterate over the data per `(start, end)` pair.
9398 var index = 0;
9399 var start;
9400 var end;
9401 var length = data.length;
9402 while (index < length) {
9403 start = data[index];
9404 end = data[index + 1];
9405 if (codePoint >= start && codePoint < end) {
9406 // Modify this pair.
9407 if (codePoint == start) {
9408 if (end == start + 1) {
9409 // Just remove `start` and `end`.
9410 data.splice(index, 2);
9411 return data;
9412 } else {
9413 // Just replace `start` with a new value.
9414 data[index] = codePoint + 1;
9415 return data;
9416 }
9417 } else if (codePoint == end - 1) {
9418 // Just replace `end` with a new value.
9419 data[index + 1] = codePoint;
9420 return data;
9421 } else {
9422 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
9423 data.splice(index, 2, start, codePoint, codePoint + 1, end);
9424 return data;
9425 }
9426 }
9427 index += 2;
9428 }
9429 return data;
9430 };
9431
9432 var dataRemoveRange = function(data, rangeStart, rangeEnd) {
9433 if (rangeEnd < rangeStart) {
9434 throw Error(ERRORS.rangeOrder);
9435 }
9436 // Iterate over the data per `(start, end)` pair.
9437 var index = 0;
9438 var start;
9439 var end;
9440 while (index < data.length) {
9441 start = data[index];
9442 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
9443
9444 // Exit as soon as no more matching pairs can be found.
9445 if (start > rangeEnd) {
9446 return data;
9447 }
9448
9449 // Check if this range pair is equal to, or forms a subset of, the range
9450 // to be removed.
9451 // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
9452 // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
9453 if (rangeStart <= start && rangeEnd >= end) {
9454 // Remove this pair.
9455 data.splice(index, 2);
9456 continue;
9457 }
9458
9459 // Check if both `rangeStart` and `rangeEnd` are within the bounds of
9460 // this pair.
9461 // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
9462 if (rangeStart >= start && rangeEnd < end) {
9463 if (rangeStart == start) {
9464 // Replace `[start, end]` with `[startB, endB]`.
9465 data[index] = rangeEnd + 1;
9466 data[index + 1] = end + 1;
9467 return data;
9468 }
9469 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
9470 data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
9471 return data;
9472 }
9473
9474 // Check if only `rangeStart` is within the bounds of this pair.
9475 // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
9476 if (rangeStart >= start && rangeStart <= end) {
9477 // Replace `end` with `rangeStart`.
9478 data[index + 1] = rangeStart;
9479 // Note: we cannot `return` just yet, in case any following pairs still
9480 // contain matching code points.
9481 // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
9482 // → `[0, 4, 21, 31]`.
9483 }
9484
9485 // Check if only `rangeEnd` is within the bounds of this pair.
9486 // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
9487 else if (rangeEnd >= start && rangeEnd <= end) {
9488 // Just replace `start`.
9489 data[index] = rangeEnd + 1;
9490 return data;
9491 }
9492
9493 index += 2;
9494 }
9495 return data;
9496 };
9497
9498 var dataAdd = function(data, codePoint) {
9499 // Iterate over the data per `(start, end)` pair.
9500 var index = 0;
9501 var start;
9502 var end;
9503 var lastIndex = null;
9504 var length = data.length;
9505 if (codePoint < 0x0 || codePoint > 0x10FFFF) {
9506 throw RangeError(ERRORS.codePointRange);
9507 }
9508 while (index < length) {
9509 start = data[index];
9510 end = data[index + 1];
9511
9512 // Check if the code point is already in the set.
9513 if (codePoint >= start && codePoint < end) {
9514 return data;
9515 }
9516
9517 if (codePoint == start - 1) {
9518 // Just replace `start` with a new value.
9519 data[index] = codePoint;
9520 return data;
9521 }
9522
9523 // At this point, if `start` is `greater` than `codePoint`, insert a new
9524 // `[start, end]` pair before the current pair, or after the current pair
9525 // if there is a known `lastIndex`.
9526 if (start > codePoint) {
9527 data.splice(
9528 lastIndex != null ? lastIndex + 2 : 0,
9529 0,
9530 codePoint,
9531 codePoint + 1
9532 );
9533 return data;
9534 }
9535
9536 if (codePoint == end) {
9537 // Check if adding this code point causes two separate ranges to become
9538 // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
9539 if (codePoint + 1 == data[index + 2]) {
9540 data.splice(index, 4, start, data[index + 3]);
9541 return data;
9542 }
9543 // Else, just replace `end` with a new value.
9544 data[index + 1] = codePoint + 1;
9545 return data;
9546 }
9547 lastIndex = index;
9548 index += 2;
9549 }
9550 // The loop has finished; add the new pair to the end of the data set.
9551 data.push(codePoint, codePoint + 1);
9552 return data;
9553 };
9554
9555 var dataAddData = function(dataA, dataB) {
9556 // Iterate over the data per `(start, end)` pair.
9557 var index = 0;
9558 var start;
9559 var end;
9560 var data = dataA.slice();
9561 var length = dataB.length;
9562 while (index < length) {
9563 start = dataB[index];
9564 end = dataB[index + 1] - 1;
9565 if (start == end) {
9566 data = dataAdd(data, start);
9567 } else {
9568 data = dataAddRange(data, start, end);
9569 }
9570 index += 2;
9571 }
9572 return data;
9573 };
9574
9575 var dataRemoveData = function(dataA, dataB) {
9576 // Iterate over the data per `(start, end)` pair.
9577 var index = 0;
9578 var start;
9579 var end;
9580 var data = dataA.slice();
9581 var length = dataB.length;
9582 while (index < length) {
9583 start = dataB[index];
9584 end = dataB[index + 1] - 1;
9585 if (start == end) {
9586 data = dataRemove(data, start);
9587 } else {
9588 data = dataRemoveRange(data, start, end);
9589 }
9590 index += 2;
9591 }
9592 return data;
9593 };
9594
9595 var dataAddRange = function(data, rangeStart, rangeEnd) {
9596 if (rangeEnd < rangeStart) {
9597 throw Error(ERRORS.rangeOrder);
9598 }
9599 if (
9600 rangeStart < 0x0 || rangeStart > 0x10FFFF ||
9601 rangeEnd < 0x0 || rangeEnd > 0x10FFFF
9602 ) {
9603 throw RangeError(ERRORS.codePointRange);
9604 }
9605 // Iterate over the data per `(start, end)` pair.
9606 var index = 0;
9607 var start;
9608 var end;
9609 var added = false;
9610 var length = data.length;
9611 while (index < length) {
9612 start = data[index];
9613 end = data[index + 1];
9614
9615 if (added) {
9616 // The range has already been added to the set; at this point, we just
9617 // need to get rid of the following ranges in case they overlap.
9618
9619 // Check if this range can be combined with the previous range.
9620 if (start == rangeEnd + 1) {
9621 data.splice(index - 1, 2);
9622 return data;
9623 }
9624
9625 // Exit as soon as no more possibly overlapping pairs can be found.
9626 if (start > rangeEnd) {
9627 return data;
9628 }
9629
9630 // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
9631 // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
9632 // `0,16` range that was previously added.
9633 if (start >= rangeStart && start <= rangeEnd) {
9634 // `start` lies within the range that was previously added.
9635
9636 if (end > rangeStart && end - 1 <= rangeEnd) {
9637 // `end` lies within the range that was previously added as well,
9638 // so remove this pair.
9639 data.splice(index, 2);
9640 index -= 2;
9641 // Note: we cannot `return` just yet, as there may still be other
9642 // overlapping pairs.
9643 } else {
9644 // `start` lies within the range that was previously added, but
9645 // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
9646 // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
9647 // Remove the previously added `end` and the current `start`.
9648 data.splice(index - 1, 2);
9649 index -= 2;
9650 }
9651
9652 // Note: we cannot return yet.
9653 }
9654
9655 }
9656
9657 else if (start == rangeEnd + 1) {
9658 data[index] = rangeStart;
9659 return data;
9660 }
9661
9662 // Check if a new pair must be inserted *before* the current one.
9663 else if (start > rangeEnd) {
9664 data.splice(index, 0, rangeStart, rangeEnd + 1);
9665 return data;
9666 }
9667
9668 else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
9669 // The new range lies entirely within an existing range pair. No action
9670 // needed.
9671 return data;
9672 }
9673
9674 else if (
9675 // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
9676 (rangeStart >= start && rangeStart < end) ||
9677 // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
9678 end == rangeStart
9679 ) {
9680 // Replace `end` with the new value.
9681 data[index + 1] = rangeEnd + 1;
9682 // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
9683 // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
9684 added = true;
9685 // Note: we cannot `return` just yet.
9686 }
9687
9688 else if (rangeStart <= start && rangeEnd + 1 >= end) {
9689 // The new range is a superset of the old range.
9690 data[index] = rangeStart;
9691 data[index + 1] = rangeEnd + 1;
9692 added = true;
9693 }
9694
9695 index += 2;
9696 }
9697 // The loop has finished without doing anything; add the new pair to the end
9698 // of the data set.
9699 if (!added) {
9700 data.push(rangeStart, rangeEnd + 1);
9701 }
9702 return data;
9703 };
9704
9705 var dataContains = function(data, codePoint) {
9706 var index = 0;
9707 var length = data.length;
9708 // Exit early if `codePoint` is not within `data`’s overall range.
9709 var start = data[index];
9710 var end = data[length - 1];
9711 if (length >= 2) {
9712 if (codePoint < start || codePoint > end) {
9713 return false;
9714 }
9715 }
9716 // Iterate over the data per `(start, end)` pair.
9717 while (index < length) {
9718 start = data[index];
9719 end = data[index + 1];
9720 if (codePoint >= start && codePoint < end) {
9721 return true;
9722 }
9723 index += 2;
9724 }
9725 return false;
9726 };
9727
9728 var dataIntersection = function(data, codePoints) {
9729 var index = 0;
9730 var length = codePoints.length;
9731 var codePoint;
9732 var result = [];
9733 while (index < length) {
9734 codePoint = codePoints[index];
9735 if (dataContains(data, codePoint)) {
9736 result.push(codePoint);
9737 }
9738 ++index;
9739 }
9740 return dataFromCodePoints(result);
9741 };
9742
9743 var dataIsEmpty = function(data) {
9744 return !data.length;
9745 };
9746
9747 var dataIsSingleton = function(data) {
9748 // Check if the set only represents a single code point.
9749 return data.length == 2 && data[0] + 1 == data[1];
9750 };
9751
9752 var dataToArray = function(data) {
9753 // Iterate over the data per `(start, end)` pair.
9754 var index = 0;
9755 var start;
9756 var end;
9757 var result = [];
9758 var length = data.length;
9759 while (index < length) {
9760 start = data[index];
9761 end = data[index + 1];
9762 while (start < end) {
9763 result.push(start);
9764 ++start;
9765 }
9766 index += 2;
9767 }
9768 return result;
9769 };
9770
9771 /*--------------------------------------------------------------------------*/
9772
9773 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
9774 var floor = Math.floor;
9775 var highSurrogate = function(codePoint) {
9776 return parseInt(
9777 floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
9778 10
9779 );
9780 };
9781
9782 var lowSurrogate = function(codePoint) {
9783 return parseInt(
9784 (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
9785 10
9786 );
9787 };
9788
9789 var stringFromCharCode = String.fromCharCode;
9790 var codePointToString = function(codePoint) {
9791 var string;
9792 // https://mathiasbynens.be/notes/javascript-escapes#single
9793 // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
9794 // different meaning in regular expressions (word boundary), so it cannot
9795 // be used here.
9796 if (codePoint == 0x09) {
9797 string = '\\t';
9798 }
9799 // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
9800 // else if (codePoint == 0x0B) {
9801 // string = '\\v';
9802 // }
9803 else if (codePoint == 0x0A) {
9804 string = '\\n';
9805 }
9806 else if (codePoint == 0x0C) {
9807 string = '\\f';
9808 }
9809 else if (codePoint == 0x0D) {
9810 string = '\\r';
9811 }
9812 else if (codePoint == 0x5C) {
9813 string = '\\\\';
9814 }
9815 else if (
9816 codePoint == 0x24 ||
9817 (codePoint >= 0x28 && codePoint <= 0x2B) ||
9818 (codePoint >= 0x2D && codePoint <= 0x2F) ||
9819 codePoint == 0x3F ||
9820 (codePoint >= 0x5B && codePoint <= 0x5E) ||
9821 (codePoint >= 0x7B && codePoint <= 0x7D)
9822 ) {
9823 // The code point maps to an unsafe printable ASCII character;
9824 // backslash-escape it. Here’s the list of those symbols:
9825 //
9826 // $()*+-./?[\]^{|}
9827 //
9828 // See #7 for more info.
9829 string = '\\' + stringFromCharCode(codePoint);
9830 }
9831 else if (codePoint >= 0x20 && codePoint <= 0x7E) {
9832 // The code point maps to one of these printable ASCII symbols
9833 // (including the space character):
9834 //
9835 // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
9836 // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
9837 //
9838 // These can safely be used directly.
9839 string = stringFromCharCode(codePoint);
9840 }
9841 else if (codePoint <= 0xFF) {
9842 // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
9843 string = '\\x' + pad(hex(codePoint), 2);
9844 }
9845 else { // `codePoint <= 0xFFFF` holds true.
9846 // https://mathiasbynens.be/notes/javascript-escapes#unicode
9847 string = '\\u' + pad(hex(codePoint), 4);
9848 }
9849
9850 // There’s no need to account for astral symbols / surrogate pairs here,
9851 // since `codePointToString` is private and only used for BMP code points.
9852 // But if that’s what you need, just add an `else` block with this code:
9853 //
9854 // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
9855 // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
9856
9857 return string;
9858 };
9859
9860 var codePointToStringUnicode = function(codePoint) {
9861 if (codePoint <= 0xFFFF) {
9862 return codePointToString(codePoint);
9863 }
9864 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
9865 };
9866
9867 var symbolToCodePoint = function(symbol) {
9868 var length = symbol.length;
9869 var first = symbol.charCodeAt(0);
9870 var second;
9871 if (
9872 first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
9873 length > 1 // There is a next code unit.
9874 ) {
9875 // `first` is a high surrogate, and there is a next character. Assume
9876 // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
9877 second = symbol.charCodeAt(1);
9878 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
9879 return (first - HIGH_SURROGATE_MIN) * 0x400 +
9880 second - LOW_SURROGATE_MIN + 0x10000;
9881 }
9882 return first;
9883 };
9884
9885 var createBMPCharacterClasses = function(data) {
9886 // Iterate over the data per `(start, end)` pair.
9887 var result = '';
9888 var index = 0;
9889 var start;
9890 var end;
9891 var length = data.length;
9892 if (dataIsSingleton(data)) {
9893 return codePointToString(data[0]);
9894 }
9895 while (index < length) {
9896 start = data[index];
9897 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
9898 if (start == end) {
9899 result += codePointToString(start);
9900 } else if (start + 1 == end) {
9901 result += codePointToString(start) + codePointToString(end);
9902 } else {
9903 result += codePointToString(start) + '-' + codePointToString(end);
9904 }
9905 index += 2;
9906 }
9907 return '[' + result + ']';
9908 };
9909
9910 var createUnicodeCharacterClasses = function(data) {
9911 // Iterate over the data per `(start, end)` pair.
9912 var result = '';
9913 var index = 0;
9914 var start;
9915 var end;
9916 var length = data.length;
9917 if (dataIsSingleton(data)) {
9918 return codePointToStringUnicode(data[0]);
9919 }
9920 while (index < length) {
9921 start = data[index];
9922 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
9923 if (start == end) {
9924 result += codePointToStringUnicode(start);
9925 } else if (start + 1 == end) {
9926 result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
9927 } else {
9928 result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
9929 }
9930 index += 2;
9931 }
9932 return '[' + result + ']';
9933 };
9934
9935 var splitAtBMP = function(data) {
9936 // Iterate over the data per `(start, end)` pair.
9937 var loneHighSurrogates = [];
9938 var loneLowSurrogates = [];
9939 var bmp = [];
9940 var astral = [];
9941 var index = 0;
9942 var start;
9943 var end;
9944 var length = data.length;
9945 while (index < length) {
9946 start = data[index];
9947 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
9948
9949 if (start < HIGH_SURROGATE_MIN) {
9950
9951 // The range starts and ends before the high surrogate range.
9952 // E.g. (0, 0x10).
9953 if (end < HIGH_SURROGATE_MIN) {
9954 bmp.push(start, end + 1);
9955 }
9956
9957 // The range starts before the high surrogate range and ends within it.
9958 // E.g. (0, 0xD855).
9959 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
9960 bmp.push(start, HIGH_SURROGATE_MIN);
9961 loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
9962 }
9963
9964 // The range starts before the high surrogate range and ends in the low
9965 // surrogate range. E.g. (0, 0xDCFF).
9966 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
9967 bmp.push(start, HIGH_SURROGATE_MIN);
9968 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
9969 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
9970 }
9971
9972 // The range starts before the high surrogate range and ends after the
9973 // low surrogate range. E.g. (0, 0x10FFFF).
9974 if (end > LOW_SURROGATE_MAX) {
9975 bmp.push(start, HIGH_SURROGATE_MIN);
9976 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
9977 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
9978 if (end <= 0xFFFF) {
9979 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
9980 } else {
9981 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
9982 astral.push(0xFFFF + 1, end + 1);
9983 }
9984 }
9985
9986 } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
9987
9988 // The range starts and ends in the high surrogate range.
9989 // E.g. (0xD855, 0xD866).
9990 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
9991 loneHighSurrogates.push(start, end + 1);
9992 }
9993
9994 // The range starts in the high surrogate range and ends in the low
9995 // surrogate range. E.g. (0xD855, 0xDCFF).
9996 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
9997 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
9998 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
9999 }
10000
10001 // The range starts in the high surrogate range and ends after the low
10002 // surrogate range. E.g. (0xD855, 0x10FFFF).
10003 if (end > LOW_SURROGATE_MAX) {
10004 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
10005 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
10006 if (end <= 0xFFFF) {
10007 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
10008 } else {
10009 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
10010 astral.push(0xFFFF + 1, end + 1);
10011 }
10012 }
10013
10014 } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
10015
10016 // The range starts and ends in the low surrogate range.
10017 // E.g. (0xDCFF, 0xDDFF).
10018 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
10019 loneLowSurrogates.push(start, end + 1);
10020 }
10021
10022 // The range starts in the low surrogate range and ends after the low
10023 // surrogate range. E.g. (0xDCFF, 0x10FFFF).
10024 if (end > LOW_SURROGATE_MAX) {
10025 loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
10026 if (end <= 0xFFFF) {
10027 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
10028 } else {
10029 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
10030 astral.push(0xFFFF + 1, end + 1);
10031 }
10032 }
10033
10034 } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
10035
10036 // The range starts and ends after the low surrogate range.
10037 // E.g. (0xFFAA, 0x10FFFF).
10038 if (end <= 0xFFFF) {
10039 bmp.push(start, end + 1);
10040 } else {
10041 bmp.push(start, 0xFFFF + 1);
10042 astral.push(0xFFFF + 1, end + 1);
10043 }
10044
10045 } else {
10046
10047 // The range starts and ends in the astral range.
10048 astral.push(start, end + 1);
10049
10050 }
10051
10052 index += 2;
10053 }
10054 return {
10055 'loneHighSurrogates': loneHighSurrogates,
10056 'loneLowSurrogates': loneLowSurrogates,
10057 'bmp': bmp,
10058 'astral': astral
10059 };
10060 };
10061
10062 var optimizeSurrogateMappings = function(surrogateMappings) {
10063 var result = [];
10064 var tmpLow = [];
10065 var addLow = false;
10066 var mapping;
10067 var nextMapping;
10068 var highSurrogates;
10069 var lowSurrogates;
10070 var nextHighSurrogates;
10071 var nextLowSurrogates;
10072 var index = -1;
10073 var length = surrogateMappings.length;
10074 while (++index < length) {
10075 mapping = surrogateMappings[index];
10076 nextMapping = surrogateMappings[index + 1];
10077 if (!nextMapping) {
10078 result.push(mapping);
10079 continue;
10080 }
10081 highSurrogates = mapping[0];
10082 lowSurrogates = mapping[1];
10083 nextHighSurrogates = nextMapping[0];
10084 nextLowSurrogates = nextMapping[1];
10085
10086 // Check for identical high surrogate ranges.
10087 tmpLow = lowSurrogates;
10088 while (
10089 nextHighSurrogates &&
10090 highSurrogates[0] == nextHighSurrogates[0] &&
10091 highSurrogates[1] == nextHighSurrogates[1]
10092 ) {
10093 // Merge with the next item.
10094 if (dataIsSingleton(nextLowSurrogates)) {
10095 tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
10096 } else {
10097 tmpLow = dataAddRange(
10098 tmpLow,
10099 nextLowSurrogates[0],
10100 nextLowSurrogates[1] - 1
10101 );
10102 }
10103 ++index;
10104 mapping = surrogateMappings[index];
10105 highSurrogates = mapping[0];
10106 lowSurrogates = mapping[1];
10107 nextMapping = surrogateMappings[index + 1];
10108 nextHighSurrogates = nextMapping && nextMapping[0];
10109 nextLowSurrogates = nextMapping && nextMapping[1];
10110 addLow = true;
10111 }
10112 result.push([
10113 highSurrogates,
10114 addLow ? tmpLow : lowSurrogates
10115 ]);
10116 addLow = false;
10117 }
10118 return optimizeByLowSurrogates(result);
10119 };
10120
10121 var optimizeByLowSurrogates = function(surrogateMappings) {
10122 if (surrogateMappings.length == 1) {
10123 return surrogateMappings;
10124 }
10125 var index = -1;
10126 var innerIndex = -1;
10127 while (++index < surrogateMappings.length) {
10128 var mapping = surrogateMappings[index];
10129 var lowSurrogates = mapping[1];
10130 var lowSurrogateStart = lowSurrogates[0];
10131 var lowSurrogateEnd = lowSurrogates[1];
10132 innerIndex = index; // Note: the loop starts at the next index.
10133 while (++innerIndex < surrogateMappings.length) {
10134 var otherMapping = surrogateMappings[innerIndex];
10135 var otherLowSurrogates = otherMapping[1];
10136 var otherLowSurrogateStart = otherLowSurrogates[0];
10137 var otherLowSurrogateEnd = otherLowSurrogates[1];
10138 if (
10139 lowSurrogateStart == otherLowSurrogateStart &&
10140 lowSurrogateEnd == otherLowSurrogateEnd
10141 ) {
10142 // Add the code points in the other item to this one.
10143 if (dataIsSingleton(otherMapping[0])) {
10144 mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
10145 } else {
10146 mapping[0] = dataAddRange(
10147 mapping[0],
10148 otherMapping[0][0],
10149 otherMapping[0][1] - 1
10150 );
10151 }
10152 // Remove the other, now redundant, item.
10153 surrogateMappings.splice(innerIndex, 1);
10154 --innerIndex;
10155 }
10156 }
10157 }
10158 return surrogateMappings;
10159 };
10160
10161 var surrogateSet = function(data) {
10162 // Exit early if `data` is an empty set.
10163 if (!data.length) {
10164 return [];
10165 }
10166
10167 // Iterate over the data per `(start, end)` pair.
10168 var index = 0;
10169 var start;
10170 var end;
10171 var startHigh;
10172 var startLow;
10173 var endHigh;
10174 var endLow;
10175 var surrogateMappings = [];
10176 var length = data.length;
10177 while (index < length) {
10178 start = data[index];
10179 end = data[index + 1] - 1;
10180
10181 startHigh = highSurrogate(start);
10182 startLow = lowSurrogate(start);
10183 endHigh = highSurrogate(end);
10184 endLow = lowSurrogate(end);
10185
10186 var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
10187 var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
10188 var complete = false;
10189
10190 // Append the previous high-surrogate-to-low-surrogate mappings.
10191 // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
10192 if (
10193 startHigh == endHigh ||
10194 startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
10195 ) {
10196 surrogateMappings.push([
10197 [startHigh, endHigh + 1],
10198 [startLow, endLow + 1]
10199 ]);
10200 complete = true;
10201 } else {
10202 surrogateMappings.push([
10203 [startHigh, startHigh + 1],
10204 [startLow, LOW_SURROGATE_MAX + 1]
10205 ]);
10206 }
10207
10208 // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
10209 // `(endHigh - 1, LOW_SURROGATE_MAX)`.
10210 if (!complete && startHigh + 1 < endHigh) {
10211 if (endsWithHighestLowSurrogate) {
10212 // Combine step 2 and step 3.
10213 surrogateMappings.push([
10214 [startHigh + 1, endHigh + 1],
10215 [LOW_SURROGATE_MIN, endLow + 1]
10216 ]);
10217 complete = true;
10218 } else {
10219 surrogateMappings.push([
10220 [startHigh + 1, endHigh],
10221 [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
10222 ]);
10223 }
10224 }
10225
10226 // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
10227 if (!complete) {
10228 surrogateMappings.push([
10229 [endHigh, endHigh + 1],
10230 [LOW_SURROGATE_MIN, endLow + 1]
10231 ]);
10232 }
10233
10234 index += 2;
10235 }
10236
10237 // The format of `surrogateMappings` is as follows:
10238 //
10239 // [ surrogateMapping1, surrogateMapping2 ]
10240 //
10241 // i.e.:
10242 //
10243 // [
10244 // [ highSurrogates1, lowSurrogates1 ],
10245 // [ highSurrogates2, lowSurrogates2 ]
10246 // ]
10247 return optimizeSurrogateMappings(surrogateMappings);
10248 };
10249
10250 var createSurrogateCharacterClasses = function(surrogateMappings) {
10251 var result = [];
10252 forEach(surrogateMappings, function(surrogateMapping) {
10253 var highSurrogates = surrogateMapping[0];
10254 var lowSurrogates = surrogateMapping[1];
10255 result.push(
10256 createBMPCharacterClasses(highSurrogates) +
10257 createBMPCharacterClasses(lowSurrogates)
10258 );
10259 });
10260 return result.join('|');
10261 };
10262
10263 var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
10264 if (hasUnicodeFlag) {
10265 return createUnicodeCharacterClasses(data);
10266 }
10267 var result = [];
10268
10269 var parts = splitAtBMP(data);
10270 var loneHighSurrogates = parts.loneHighSurrogates;
10271 var loneLowSurrogates = parts.loneLowSurrogates;
10272 var bmp = parts.bmp;
10273 var astral = parts.astral;
10274 var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
10275 var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
10276
10277 var surrogateMappings = surrogateSet(astral);
10278
10279 if (bmpOnly) {
10280 bmp = dataAddData(bmp, loneHighSurrogates);
10281 hasLoneHighSurrogates = false;
10282 bmp = dataAddData(bmp, loneLowSurrogates);
10283 hasLoneLowSurrogates = false;
10284 }
10285
10286 if (!dataIsEmpty(bmp)) {
10287 // The data set contains BMP code points that are not high surrogates
10288 // needed for astral code points in the set.
10289 result.push(createBMPCharacterClasses(bmp));
10290 }
10291 if (surrogateMappings.length) {
10292 // The data set contains astral code points; append character classes
10293 // based on their surrogate pairs.
10294 result.push(createSurrogateCharacterClasses(surrogateMappings));
10295 }
10296 // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
10297 if (hasLoneHighSurrogates) {
10298 result.push(
10299 createBMPCharacterClasses(loneHighSurrogates) +
10300 // Make sure the high surrogates aren’t part of a surrogate pair.
10301 '(?![\\uDC00-\\uDFFF])'
10302 );
10303 }
10304 if (hasLoneLowSurrogates) {
10305 result.push(
10306 // It is not possible to accurately assert the low surrogates aren’t
10307 // part of a surrogate pair, since JavaScript regular expressions do
10308 // not support lookbehind.
10309 '(?:[^\\uD800-\\uDBFF]|^)' +
10310 createBMPCharacterClasses(loneLowSurrogates)
10311 );
10312 }
10313 return result.join('|');
10314 };
10315
10316 /*--------------------------------------------------------------------------*/
10317
10318 // `regenerate` can be used as a constructor (and new methods can be added to
10319 // its prototype) but also as a regular function, the latter of which is the
10320 // documented and most common usage. For that reason, it’s not capitalized.
10321 var regenerate = function(value) {
10322 if (arguments.length > 1) {
10323 value = slice.call(arguments);
10324 }
10325 if (this instanceof regenerate) {
10326 this.data = [];
10327 return value ? this.add(value) : this;
10328 }
10329 return (new regenerate).add(value);
10330 };
10331
10332 regenerate.version = '1.3.3';
10333
10334 var proto = regenerate.prototype;
10335 extend(proto, {
10336 'add': function(value) {
10337 var $this = this;
10338 if (value == null) {
10339 return $this;
10340 }
10341 if (value instanceof regenerate) {
10342 // Allow passing other Regenerate instances.
10343 $this.data = dataAddData($this.data, value.data);
10344 return $this;
10345 }
10346 if (arguments.length > 1) {
10347 value = slice.call(arguments);
10348 }
10349 if (isArray(value)) {
10350 forEach(value, function(item) {
10351 $this.add(item);
10352 });
10353 return $this;
10354 }
10355 $this.data = dataAdd(
10356 $this.data,
10357 isNumber(value) ? value : symbolToCodePoint(value)
10358 );
10359 return $this;
10360 },
10361 'remove': function(value) {
10362 var $this = this;
10363 if (value == null) {
10364 return $this;
10365 }
10366 if (value instanceof regenerate) {
10367 // Allow passing other Regenerate instances.
10368 $this.data = dataRemoveData($this.data, value.data);
10369 return $this;
10370 }
10371 if (arguments.length > 1) {
10372 value = slice.call(arguments);
10373 }
10374 if (isArray(value)) {
10375 forEach(value, function(item) {
10376 $this.remove(item);
10377 });
10378 return $this;
10379 }
10380 $this.data = dataRemove(
10381 $this.data,
10382 isNumber(value) ? value : symbolToCodePoint(value)
10383 );
10384 return $this;
10385 },
10386 'addRange': function(start, end) {
10387 var $this = this;
10388 $this.data = dataAddRange($this.data,
10389 isNumber(start) ? start : symbolToCodePoint(start),
10390 isNumber(end) ? end : symbolToCodePoint(end)
10391 );
10392 return $this;
10393 },
10394 'removeRange': function(start, end) {
10395 var $this = this;
10396 var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
10397 var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
10398 $this.data = dataRemoveRange(
10399 $this.data,
10400 startCodePoint,
10401 endCodePoint
10402 );
10403 return $this;
10404 },
10405 'intersection': function(argument) {
10406 var $this = this;
10407 // Allow passing other Regenerate instances.
10408 // TODO: Optimize this by writing and using `dataIntersectionData()`.
10409 var array = argument instanceof regenerate ?
10410 dataToArray(argument.data) :
10411 argument;
10412 $this.data = dataIntersection($this.data, array);
10413 return $this;
10414 },
10415 'contains': function(codePoint) {
10416 return dataContains(
10417 this.data,
10418 isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
10419 );
10420 },
10421 'clone': function() {
10422 var set = new regenerate;
10423 set.data = this.data.slice(0);
10424 return set;
10425 },
10426 'toString': function(options) {
10427 var result = createCharacterClassesFromData(
10428 this.data,
10429 options ? options.bmpOnly : false,
10430 options ? options.hasUnicodeFlag : false
10431 );
10432 if (!result) {
10433 // For an empty set, return something that can be inserted `/here/` to
10434 // form a valid regular expression. Avoid `(?:)` since that matches the
10435 // empty string.
10436 return '[]';
10437 }
10438 // Use `\0` instead of `\x00` where possible.
10439 return result.replace(regexNull, '\\0$1');
10440 },
10441 'toRegExp': function(flags) {
10442 var pattern = this.toString(
10443 flags && flags.indexOf('u') != -1 ?
10444 { 'hasUnicodeFlag': true } :
10445 null
10446 );
10447 return RegExp(pattern, flags || '');
10448 },
10449 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
10450 return dataToArray(this.data);
10451 }
10452 });
10453
10454 proto.toArray = proto.valueOf;
10455
10456 // Some AMD build optimizers, like r.js, check for specific condition patterns
10457 // like the following:
10458 if (
10459 typeof undefined == 'function' &&
10460 typeof undefined.amd == 'object' &&
10461 undefined.amd
10462 ) {
10463 undefined(function() {
10464 return regenerate;
10465 });
10466 } else if (freeExports && !freeExports.nodeType) {
10467 if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
10468 freeModule.exports = regenerate;
10469 } else { // in Narwhal or RingoJS v0.7.0-
10470 freeExports.regenerate = regenerate;
10471 }
10472 } else { // in Rhino or a web browser
10473 root.regenerate = regenerate;
10474 }
10475
10476}(commonjsGlobal));
10477});
10478
10479var unicodeCanonicalPropertyNamesEcmascript = new Set([
10480 // Non-binary properties:
10481 'General_Category',
10482 'Script',
10483 'Script_Extensions',
10484 // Binary properties:
10485 'Alphabetic',
10486 'Any',
10487 'ASCII',
10488 'ASCII_Hex_Digit',
10489 'Assigned',
10490 'Bidi_Control',
10491 'Bidi_Mirrored',
10492 'Case_Ignorable',
10493 'Cased',
10494 'Changes_When_Casefolded',
10495 'Changes_When_Casemapped',
10496 'Changes_When_Lowercased',
10497 'Changes_When_NFKC_Casefolded',
10498 'Changes_When_Titlecased',
10499 'Changes_When_Uppercased',
10500 'Dash',
10501 'Default_Ignorable_Code_Point',
10502 'Deprecated',
10503 'Diacritic',
10504 'Emoji',
10505 'Emoji_Component',
10506 'Emoji_Modifier',
10507 'Emoji_Modifier_Base',
10508 'Emoji_Presentation',
10509 'Extended_Pictographic',
10510 'Extender',
10511 'Grapheme_Base',
10512 'Grapheme_Extend',
10513 'Hex_Digit',
10514 'ID_Continue',
10515 'ID_Start',
10516 'Ideographic',
10517 'IDS_Binary_Operator',
10518 'IDS_Trinary_Operator',
10519 'Join_Control',
10520 'Logical_Order_Exception',
10521 'Lowercase',
10522 'Math',
10523 'Noncharacter_Code_Point',
10524 'Pattern_Syntax',
10525 'Pattern_White_Space',
10526 'Quotation_Mark',
10527 'Radical',
10528 'Regional_Indicator',
10529 'Sentence_Terminal',
10530 'Soft_Dotted',
10531 'Terminal_Punctuation',
10532 'Unified_Ideograph',
10533 'Uppercase',
10534 'Variation_Selector',
10535 'White_Space',
10536 'XID_Continue',
10537 'XID_Start'
10538]);
10539
10540// Generated using `npm run build`. Do not edit!
10541var unicodePropertyAliasesEcmascript = new Map([
10542 ['scx', 'Script_Extensions'],
10543 ['sc', 'Script'],
10544 ['gc', 'General_Category'],
10545 ['AHex', 'ASCII_Hex_Digit'],
10546 ['Alpha', 'Alphabetic'],
10547 ['Bidi_C', 'Bidi_Control'],
10548 ['Bidi_M', 'Bidi_Mirrored'],
10549 ['Cased', 'Cased'],
10550 ['CI', 'Case_Ignorable'],
10551 ['CWCF', 'Changes_When_Casefolded'],
10552 ['CWCM', 'Changes_When_Casemapped'],
10553 ['CWKCF', 'Changes_When_NFKC_Casefolded'],
10554 ['CWL', 'Changes_When_Lowercased'],
10555 ['CWT', 'Changes_When_Titlecased'],
10556 ['CWU', 'Changes_When_Uppercased'],
10557 ['Dash', 'Dash'],
10558 ['Dep', 'Deprecated'],
10559 ['DI', 'Default_Ignorable_Code_Point'],
10560 ['Dia', 'Diacritic'],
10561 ['Ext', 'Extender'],
10562 ['Gr_Base', 'Grapheme_Base'],
10563 ['Gr_Ext', 'Grapheme_Extend'],
10564 ['Hex', 'Hex_Digit'],
10565 ['IDC', 'ID_Continue'],
10566 ['Ideo', 'Ideographic'],
10567 ['IDS', 'ID_Start'],
10568 ['IDSB', 'IDS_Binary_Operator'],
10569 ['IDST', 'IDS_Trinary_Operator'],
10570 ['Join_C', 'Join_Control'],
10571 ['LOE', 'Logical_Order_Exception'],
10572 ['Lower', 'Lowercase'],
10573 ['Math', 'Math'],
10574 ['NChar', 'Noncharacter_Code_Point'],
10575 ['Pat_Syn', 'Pattern_Syntax'],
10576 ['Pat_WS', 'Pattern_White_Space'],
10577 ['QMark', 'Quotation_Mark'],
10578 ['Radical', 'Radical'],
10579 ['RI', 'Regional_Indicator'],
10580 ['SD', 'Soft_Dotted'],
10581 ['STerm', 'Sentence_Terminal'],
10582 ['Term', 'Terminal_Punctuation'],
10583 ['UIdeo', 'Unified_Ideograph'],
10584 ['Upper', 'Uppercase'],
10585 ['VS', 'Variation_Selector'],
10586 ['WSpace', 'White_Space'],
10587 ['space', 'White_Space'],
10588 ['XIDC', 'XID_Continue'],
10589 ['XIDS', 'XID_Start']
10590]);
10591
10592'use strict';
10593
10594
10595
10596
10597const matchProperty = function(property) {
10598 if (unicodeCanonicalPropertyNamesEcmascript.has(property)) {
10599 return property;
10600 }
10601 if (unicodePropertyAliasesEcmascript.has(property)) {
10602 return unicodePropertyAliasesEcmascript.get(property);
10603 }
10604 throw new Error(`Unknown property: ${ property }`);
10605};
10606
10607var unicodeMatchPropertyEcmascript = matchProperty;
10608
10609var mappings = new Map([
10610 ['General_Category', new Map([
10611 ['C', 'Other'],
10612 ['Cc', 'Control'],
10613 ['cntrl', 'Control'],
10614 ['Cf', 'Format'],
10615 ['Cn', 'Unassigned'],
10616 ['Co', 'Private_Use'],
10617 ['Cs', 'Surrogate'],
10618 ['L', 'Letter'],
10619 ['LC', 'Cased_Letter'],
10620 ['Ll', 'Lowercase_Letter'],
10621 ['Lm', 'Modifier_Letter'],
10622 ['Lo', 'Other_Letter'],
10623 ['Lt', 'Titlecase_Letter'],
10624 ['Lu', 'Uppercase_Letter'],
10625 ['M', 'Mark'],
10626 ['Combining_Mark', 'Mark'],
10627 ['Mc', 'Spacing_Mark'],
10628 ['Me', 'Enclosing_Mark'],
10629 ['Mn', 'Nonspacing_Mark'],
10630 ['N', 'Number'],
10631 ['Nd', 'Decimal_Number'],
10632 ['digit', 'Decimal_Number'],
10633 ['Nl', 'Letter_Number'],
10634 ['No', 'Other_Number'],
10635 ['P', 'Punctuation'],
10636 ['punct', 'Punctuation'],
10637 ['Pc', 'Connector_Punctuation'],
10638 ['Pd', 'Dash_Punctuation'],
10639 ['Pe', 'Close_Punctuation'],
10640 ['Pf', 'Final_Punctuation'],
10641 ['Pi', 'Initial_Punctuation'],
10642 ['Po', 'Other_Punctuation'],
10643 ['Ps', 'Open_Punctuation'],
10644 ['S', 'Symbol'],
10645 ['Sc', 'Currency_Symbol'],
10646 ['Sk', 'Modifier_Symbol'],
10647 ['Sm', 'Math_Symbol'],
10648 ['So', 'Other_Symbol'],
10649 ['Z', 'Separator'],
10650 ['Zl', 'Line_Separator'],
10651 ['Zp', 'Paragraph_Separator'],
10652 ['Zs', 'Space_Separator'],
10653 ['Other', 'Other'],
10654 ['Control', 'Control'],
10655 ['Format', 'Format'],
10656 ['Unassigned', 'Unassigned'],
10657 ['Private_Use', 'Private_Use'],
10658 ['Surrogate', 'Surrogate'],
10659 ['Letter', 'Letter'],
10660 ['Cased_Letter', 'Cased_Letter'],
10661 ['Lowercase_Letter', 'Lowercase_Letter'],
10662 ['Modifier_Letter', 'Modifier_Letter'],
10663 ['Other_Letter', 'Other_Letter'],
10664 ['Titlecase_Letter', 'Titlecase_Letter'],
10665 ['Uppercase_Letter', 'Uppercase_Letter'],
10666 ['Mark', 'Mark'],
10667 ['Spacing_Mark', 'Spacing_Mark'],
10668 ['Enclosing_Mark', 'Enclosing_Mark'],
10669 ['Nonspacing_Mark', 'Nonspacing_Mark'],
10670 ['Number', 'Number'],
10671 ['Decimal_Number', 'Decimal_Number'],
10672 ['Letter_Number', 'Letter_Number'],
10673 ['Other_Number', 'Other_Number'],
10674 ['Punctuation', 'Punctuation'],
10675 ['Connector_Punctuation', 'Connector_Punctuation'],
10676 ['Dash_Punctuation', 'Dash_Punctuation'],
10677 ['Close_Punctuation', 'Close_Punctuation'],
10678 ['Final_Punctuation', 'Final_Punctuation'],
10679 ['Initial_Punctuation', 'Initial_Punctuation'],
10680 ['Other_Punctuation', 'Other_Punctuation'],
10681 ['Open_Punctuation', 'Open_Punctuation'],
10682 ['Symbol', 'Symbol'],
10683 ['Currency_Symbol', 'Currency_Symbol'],
10684 ['Modifier_Symbol', 'Modifier_Symbol'],
10685 ['Math_Symbol', 'Math_Symbol'],
10686 ['Other_Symbol', 'Other_Symbol'],
10687 ['Separator', 'Separator'],
10688 ['Line_Separator', 'Line_Separator'],
10689 ['Paragraph_Separator', 'Paragraph_Separator'],
10690 ['Space_Separator', 'Space_Separator']
10691 ])],
10692 ['Script', new Map([
10693 ['Adlm', 'Adlam'],
10694 ['Aghb', 'Caucasian_Albanian'],
10695 ['Ahom', 'Ahom'],
10696 ['Arab', 'Arabic'],
10697 ['Armi', 'Imperial_Aramaic'],
10698 ['Armn', 'Armenian'],
10699 ['Avst', 'Avestan'],
10700 ['Bali', 'Balinese'],
10701 ['Bamu', 'Bamum'],
10702 ['Bass', 'Bassa_Vah'],
10703 ['Batk', 'Batak'],
10704 ['Beng', 'Bengali'],
10705 ['Bhks', 'Bhaiksuki'],
10706 ['Bopo', 'Bopomofo'],
10707 ['Brah', 'Brahmi'],
10708 ['Brai', 'Braille'],
10709 ['Bugi', 'Buginese'],
10710 ['Buhd', 'Buhid'],
10711 ['Cakm', 'Chakma'],
10712 ['Cans', 'Canadian_Aboriginal'],
10713 ['Cari', 'Carian'],
10714 ['Cham', 'Cham'],
10715 ['Cher', 'Cherokee'],
10716 ['Copt', 'Coptic'],
10717 ['Qaac', 'Coptic'],
10718 ['Cprt', 'Cypriot'],
10719 ['Cyrl', 'Cyrillic'],
10720 ['Deva', 'Devanagari'],
10721 ['Dsrt', 'Deseret'],
10722 ['Dupl', 'Duployan'],
10723 ['Egyp', 'Egyptian_Hieroglyphs'],
10724 ['Elba', 'Elbasan'],
10725 ['Ethi', 'Ethiopic'],
10726 ['Geor', 'Georgian'],
10727 ['Glag', 'Glagolitic'],
10728 ['Gonm', 'Masaram_Gondi'],
10729 ['Goth', 'Gothic'],
10730 ['Gran', 'Grantha'],
10731 ['Grek', 'Greek'],
10732 ['Gujr', 'Gujarati'],
10733 ['Guru', 'Gurmukhi'],
10734 ['Hang', 'Hangul'],
10735 ['Hani', 'Han'],
10736 ['Hano', 'Hanunoo'],
10737 ['Hatr', 'Hatran'],
10738 ['Hebr', 'Hebrew'],
10739 ['Hira', 'Hiragana'],
10740 ['Hluw', 'Anatolian_Hieroglyphs'],
10741 ['Hmng', 'Pahawh_Hmong'],
10742 ['Hrkt', 'Katakana_Or_Hiragana'],
10743 ['Hung', 'Old_Hungarian'],
10744 ['Ital', 'Old_Italic'],
10745 ['Java', 'Javanese'],
10746 ['Kali', 'Kayah_Li'],
10747 ['Kana', 'Katakana'],
10748 ['Khar', 'Kharoshthi'],
10749 ['Khmr', 'Khmer'],
10750 ['Khoj', 'Khojki'],
10751 ['Knda', 'Kannada'],
10752 ['Kthi', 'Kaithi'],
10753 ['Lana', 'Tai_Tham'],
10754 ['Laoo', 'Lao'],
10755 ['Latn', 'Latin'],
10756 ['Lepc', 'Lepcha'],
10757 ['Limb', 'Limbu'],
10758 ['Lina', 'Linear_A'],
10759 ['Linb', 'Linear_B'],
10760 ['Lisu', 'Lisu'],
10761 ['Lyci', 'Lycian'],
10762 ['Lydi', 'Lydian'],
10763 ['Mahj', 'Mahajani'],
10764 ['Mand', 'Mandaic'],
10765 ['Mani', 'Manichaean'],
10766 ['Marc', 'Marchen'],
10767 ['Mend', 'Mende_Kikakui'],
10768 ['Merc', 'Meroitic_Cursive'],
10769 ['Mero', 'Meroitic_Hieroglyphs'],
10770 ['Mlym', 'Malayalam'],
10771 ['Modi', 'Modi'],
10772 ['Mong', 'Mongolian'],
10773 ['Mroo', 'Mro'],
10774 ['Mtei', 'Meetei_Mayek'],
10775 ['Mult', 'Multani'],
10776 ['Mymr', 'Myanmar'],
10777 ['Narb', 'Old_North_Arabian'],
10778 ['Nbat', 'Nabataean'],
10779 ['Newa', 'Newa'],
10780 ['Nkoo', 'Nko'],
10781 ['Nshu', 'Nushu'],
10782 ['Ogam', 'Ogham'],
10783 ['Olck', 'Ol_Chiki'],
10784 ['Orkh', 'Old_Turkic'],
10785 ['Orya', 'Oriya'],
10786 ['Osge', 'Osage'],
10787 ['Osma', 'Osmanya'],
10788 ['Palm', 'Palmyrene'],
10789 ['Pauc', 'Pau_Cin_Hau'],
10790 ['Perm', 'Old_Permic'],
10791 ['Phag', 'Phags_Pa'],
10792 ['Phli', 'Inscriptional_Pahlavi'],
10793 ['Phlp', 'Psalter_Pahlavi'],
10794 ['Phnx', 'Phoenician'],
10795 ['Plrd', 'Miao'],
10796 ['Prti', 'Inscriptional_Parthian'],
10797 ['Rjng', 'Rejang'],
10798 ['Runr', 'Runic'],
10799 ['Samr', 'Samaritan'],
10800 ['Sarb', 'Old_South_Arabian'],
10801 ['Saur', 'Saurashtra'],
10802 ['Sgnw', 'SignWriting'],
10803 ['Shaw', 'Shavian'],
10804 ['Shrd', 'Sharada'],
10805 ['Sidd', 'Siddham'],
10806 ['Sind', 'Khudawadi'],
10807 ['Sinh', 'Sinhala'],
10808 ['Sora', 'Sora_Sompeng'],
10809 ['Soyo', 'Soyombo'],
10810 ['Sund', 'Sundanese'],
10811 ['Sylo', 'Syloti_Nagri'],
10812 ['Syrc', 'Syriac'],
10813 ['Tagb', 'Tagbanwa'],
10814 ['Takr', 'Takri'],
10815 ['Tale', 'Tai_Le'],
10816 ['Talu', 'New_Tai_Lue'],
10817 ['Taml', 'Tamil'],
10818 ['Tang', 'Tangut'],
10819 ['Tavt', 'Tai_Viet'],
10820 ['Telu', 'Telugu'],
10821 ['Tfng', 'Tifinagh'],
10822 ['Tglg', 'Tagalog'],
10823 ['Thaa', 'Thaana'],
10824 ['Thai', 'Thai'],
10825 ['Tibt', 'Tibetan'],
10826 ['Tirh', 'Tirhuta'],
10827 ['Ugar', 'Ugaritic'],
10828 ['Vaii', 'Vai'],
10829 ['Wara', 'Warang_Citi'],
10830 ['Xpeo', 'Old_Persian'],
10831 ['Xsux', 'Cuneiform'],
10832 ['Yiii', 'Yi'],
10833 ['Zanb', 'Zanabazar_Square'],
10834 ['Zinh', 'Inherited'],
10835 ['Qaai', 'Inherited'],
10836 ['Zyyy', 'Common'],
10837 ['Zzzz', 'Unknown'],
10838 ['Adlam', 'Adlam'],
10839 ['Caucasian_Albanian', 'Caucasian_Albanian'],
10840 ['Arabic', 'Arabic'],
10841 ['Imperial_Aramaic', 'Imperial_Aramaic'],
10842 ['Armenian', 'Armenian'],
10843 ['Avestan', 'Avestan'],
10844 ['Balinese', 'Balinese'],
10845 ['Bamum', 'Bamum'],
10846 ['Bassa_Vah', 'Bassa_Vah'],
10847 ['Batak', 'Batak'],
10848 ['Bengali', 'Bengali'],
10849 ['Bhaiksuki', 'Bhaiksuki'],
10850 ['Bopomofo', 'Bopomofo'],
10851 ['Brahmi', 'Brahmi'],
10852 ['Braille', 'Braille'],
10853 ['Buginese', 'Buginese'],
10854 ['Buhid', 'Buhid'],
10855 ['Chakma', 'Chakma'],
10856 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
10857 ['Carian', 'Carian'],
10858 ['Cherokee', 'Cherokee'],
10859 ['Coptic', 'Coptic'],
10860 ['Cypriot', 'Cypriot'],
10861 ['Cyrillic', 'Cyrillic'],
10862 ['Devanagari', 'Devanagari'],
10863 ['Deseret', 'Deseret'],
10864 ['Duployan', 'Duployan'],
10865 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
10866 ['Elbasan', 'Elbasan'],
10867 ['Ethiopic', 'Ethiopic'],
10868 ['Georgian', 'Georgian'],
10869 ['Glagolitic', 'Glagolitic'],
10870 ['Masaram_Gondi', 'Masaram_Gondi'],
10871 ['Gothic', 'Gothic'],
10872 ['Grantha', 'Grantha'],
10873 ['Greek', 'Greek'],
10874 ['Gujarati', 'Gujarati'],
10875 ['Gurmukhi', 'Gurmukhi'],
10876 ['Hangul', 'Hangul'],
10877 ['Han', 'Han'],
10878 ['Hanunoo', 'Hanunoo'],
10879 ['Hatran', 'Hatran'],
10880 ['Hebrew', 'Hebrew'],
10881 ['Hiragana', 'Hiragana'],
10882 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
10883 ['Pahawh_Hmong', 'Pahawh_Hmong'],
10884 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
10885 ['Old_Hungarian', 'Old_Hungarian'],
10886 ['Old_Italic', 'Old_Italic'],
10887 ['Javanese', 'Javanese'],
10888 ['Kayah_Li', 'Kayah_Li'],
10889 ['Katakana', 'Katakana'],
10890 ['Kharoshthi', 'Kharoshthi'],
10891 ['Khmer', 'Khmer'],
10892 ['Khojki', 'Khojki'],
10893 ['Kannada', 'Kannada'],
10894 ['Kaithi', 'Kaithi'],
10895 ['Tai_Tham', 'Tai_Tham'],
10896 ['Lao', 'Lao'],
10897 ['Latin', 'Latin'],
10898 ['Lepcha', 'Lepcha'],
10899 ['Limbu', 'Limbu'],
10900 ['Linear_A', 'Linear_A'],
10901 ['Linear_B', 'Linear_B'],
10902 ['Lycian', 'Lycian'],
10903 ['Lydian', 'Lydian'],
10904 ['Mahajani', 'Mahajani'],
10905 ['Mandaic', 'Mandaic'],
10906 ['Manichaean', 'Manichaean'],
10907 ['Marchen', 'Marchen'],
10908 ['Mende_Kikakui', 'Mende_Kikakui'],
10909 ['Meroitic_Cursive', 'Meroitic_Cursive'],
10910 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
10911 ['Malayalam', 'Malayalam'],
10912 ['Mongolian', 'Mongolian'],
10913 ['Mro', 'Mro'],
10914 ['Meetei_Mayek', 'Meetei_Mayek'],
10915 ['Multani', 'Multani'],
10916 ['Myanmar', 'Myanmar'],
10917 ['Old_North_Arabian', 'Old_North_Arabian'],
10918 ['Nabataean', 'Nabataean'],
10919 ['Nko', 'Nko'],
10920 ['Nushu', 'Nushu'],
10921 ['Ogham', 'Ogham'],
10922 ['Ol_Chiki', 'Ol_Chiki'],
10923 ['Old_Turkic', 'Old_Turkic'],
10924 ['Oriya', 'Oriya'],
10925 ['Osage', 'Osage'],
10926 ['Osmanya', 'Osmanya'],
10927 ['Palmyrene', 'Palmyrene'],
10928 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
10929 ['Old_Permic', 'Old_Permic'],
10930 ['Phags_Pa', 'Phags_Pa'],
10931 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
10932 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
10933 ['Phoenician', 'Phoenician'],
10934 ['Miao', 'Miao'],
10935 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
10936 ['Rejang', 'Rejang'],
10937 ['Runic', 'Runic'],
10938 ['Samaritan', 'Samaritan'],
10939 ['Old_South_Arabian', 'Old_South_Arabian'],
10940 ['Saurashtra', 'Saurashtra'],
10941 ['SignWriting', 'SignWriting'],
10942 ['Shavian', 'Shavian'],
10943 ['Sharada', 'Sharada'],
10944 ['Siddham', 'Siddham'],
10945 ['Khudawadi', 'Khudawadi'],
10946 ['Sinhala', 'Sinhala'],
10947 ['Sora_Sompeng', 'Sora_Sompeng'],
10948 ['Soyombo', 'Soyombo'],
10949 ['Sundanese', 'Sundanese'],
10950 ['Syloti_Nagri', 'Syloti_Nagri'],
10951 ['Syriac', 'Syriac'],
10952 ['Tagbanwa', 'Tagbanwa'],
10953 ['Takri', 'Takri'],
10954 ['Tai_Le', 'Tai_Le'],
10955 ['New_Tai_Lue', 'New_Tai_Lue'],
10956 ['Tamil', 'Tamil'],
10957 ['Tangut', 'Tangut'],
10958 ['Tai_Viet', 'Tai_Viet'],
10959 ['Telugu', 'Telugu'],
10960 ['Tifinagh', 'Tifinagh'],
10961 ['Tagalog', 'Tagalog'],
10962 ['Thaana', 'Thaana'],
10963 ['Tibetan', 'Tibetan'],
10964 ['Tirhuta', 'Tirhuta'],
10965 ['Ugaritic', 'Ugaritic'],
10966 ['Vai', 'Vai'],
10967 ['Warang_Citi', 'Warang_Citi'],
10968 ['Old_Persian', 'Old_Persian'],
10969 ['Cuneiform', 'Cuneiform'],
10970 ['Yi', 'Yi'],
10971 ['Zanabazar_Square', 'Zanabazar_Square'],
10972 ['Inherited', 'Inherited'],
10973 ['Common', 'Common'],
10974 ['Unknown', 'Unknown']
10975 ])],
10976 ['Script_Extensions', new Map([
10977 ['Adlm', 'Adlam'],
10978 ['Aghb', 'Caucasian_Albanian'],
10979 ['Ahom', 'Ahom'],
10980 ['Arab', 'Arabic'],
10981 ['Armi', 'Imperial_Aramaic'],
10982 ['Armn', 'Armenian'],
10983 ['Avst', 'Avestan'],
10984 ['Bali', 'Balinese'],
10985 ['Bamu', 'Bamum'],
10986 ['Bass', 'Bassa_Vah'],
10987 ['Batk', 'Batak'],
10988 ['Beng', 'Bengali'],
10989 ['Bhks', 'Bhaiksuki'],
10990 ['Bopo', 'Bopomofo'],
10991 ['Brah', 'Brahmi'],
10992 ['Brai', 'Braille'],
10993 ['Bugi', 'Buginese'],
10994 ['Buhd', 'Buhid'],
10995 ['Cakm', 'Chakma'],
10996 ['Cans', 'Canadian_Aboriginal'],
10997 ['Cari', 'Carian'],
10998 ['Cham', 'Cham'],
10999 ['Cher', 'Cherokee'],
11000 ['Copt', 'Coptic'],
11001 ['Qaac', 'Coptic'],
11002 ['Cprt', 'Cypriot'],
11003 ['Cyrl', 'Cyrillic'],
11004 ['Deva', 'Devanagari'],
11005 ['Dsrt', 'Deseret'],
11006 ['Dupl', 'Duployan'],
11007 ['Egyp', 'Egyptian_Hieroglyphs'],
11008 ['Elba', 'Elbasan'],
11009 ['Ethi', 'Ethiopic'],
11010 ['Geor', 'Georgian'],
11011 ['Glag', 'Glagolitic'],
11012 ['Gonm', 'Masaram_Gondi'],
11013 ['Goth', 'Gothic'],
11014 ['Gran', 'Grantha'],
11015 ['Grek', 'Greek'],
11016 ['Gujr', 'Gujarati'],
11017 ['Guru', 'Gurmukhi'],
11018 ['Hang', 'Hangul'],
11019 ['Hani', 'Han'],
11020 ['Hano', 'Hanunoo'],
11021 ['Hatr', 'Hatran'],
11022 ['Hebr', 'Hebrew'],
11023 ['Hira', 'Hiragana'],
11024 ['Hluw', 'Anatolian_Hieroglyphs'],
11025 ['Hmng', 'Pahawh_Hmong'],
11026 ['Hrkt', 'Katakana_Or_Hiragana'],
11027 ['Hung', 'Old_Hungarian'],
11028 ['Ital', 'Old_Italic'],
11029 ['Java', 'Javanese'],
11030 ['Kali', 'Kayah_Li'],
11031 ['Kana', 'Katakana'],
11032 ['Khar', 'Kharoshthi'],
11033 ['Khmr', 'Khmer'],
11034 ['Khoj', 'Khojki'],
11035 ['Knda', 'Kannada'],
11036 ['Kthi', 'Kaithi'],
11037 ['Lana', 'Tai_Tham'],
11038 ['Laoo', 'Lao'],
11039 ['Latn', 'Latin'],
11040 ['Lepc', 'Lepcha'],
11041 ['Limb', 'Limbu'],
11042 ['Lina', 'Linear_A'],
11043 ['Linb', 'Linear_B'],
11044 ['Lisu', 'Lisu'],
11045 ['Lyci', 'Lycian'],
11046 ['Lydi', 'Lydian'],
11047 ['Mahj', 'Mahajani'],
11048 ['Mand', 'Mandaic'],
11049 ['Mani', 'Manichaean'],
11050 ['Marc', 'Marchen'],
11051 ['Mend', 'Mende_Kikakui'],
11052 ['Merc', 'Meroitic_Cursive'],
11053 ['Mero', 'Meroitic_Hieroglyphs'],
11054 ['Mlym', 'Malayalam'],
11055 ['Modi', 'Modi'],
11056 ['Mong', 'Mongolian'],
11057 ['Mroo', 'Mro'],
11058 ['Mtei', 'Meetei_Mayek'],
11059 ['Mult', 'Multani'],
11060 ['Mymr', 'Myanmar'],
11061 ['Narb', 'Old_North_Arabian'],
11062 ['Nbat', 'Nabataean'],
11063 ['Newa', 'Newa'],
11064 ['Nkoo', 'Nko'],
11065 ['Nshu', 'Nushu'],
11066 ['Ogam', 'Ogham'],
11067 ['Olck', 'Ol_Chiki'],
11068 ['Orkh', 'Old_Turkic'],
11069 ['Orya', 'Oriya'],
11070 ['Osge', 'Osage'],
11071 ['Osma', 'Osmanya'],
11072 ['Palm', 'Palmyrene'],
11073 ['Pauc', 'Pau_Cin_Hau'],
11074 ['Perm', 'Old_Permic'],
11075 ['Phag', 'Phags_Pa'],
11076 ['Phli', 'Inscriptional_Pahlavi'],
11077 ['Phlp', 'Psalter_Pahlavi'],
11078 ['Phnx', 'Phoenician'],
11079 ['Plrd', 'Miao'],
11080 ['Prti', 'Inscriptional_Parthian'],
11081 ['Rjng', 'Rejang'],
11082 ['Runr', 'Runic'],
11083 ['Samr', 'Samaritan'],
11084 ['Sarb', 'Old_South_Arabian'],
11085 ['Saur', 'Saurashtra'],
11086 ['Sgnw', 'SignWriting'],
11087 ['Shaw', 'Shavian'],
11088 ['Shrd', 'Sharada'],
11089 ['Sidd', 'Siddham'],
11090 ['Sind', 'Khudawadi'],
11091 ['Sinh', 'Sinhala'],
11092 ['Sora', 'Sora_Sompeng'],
11093 ['Soyo', 'Soyombo'],
11094 ['Sund', 'Sundanese'],
11095 ['Sylo', 'Syloti_Nagri'],
11096 ['Syrc', 'Syriac'],
11097 ['Tagb', 'Tagbanwa'],
11098 ['Takr', 'Takri'],
11099 ['Tale', 'Tai_Le'],
11100 ['Talu', 'New_Tai_Lue'],
11101 ['Taml', 'Tamil'],
11102 ['Tang', 'Tangut'],
11103 ['Tavt', 'Tai_Viet'],
11104 ['Telu', 'Telugu'],
11105 ['Tfng', 'Tifinagh'],
11106 ['Tglg', 'Tagalog'],
11107 ['Thaa', 'Thaana'],
11108 ['Thai', 'Thai'],
11109 ['Tibt', 'Tibetan'],
11110 ['Tirh', 'Tirhuta'],
11111 ['Ugar', 'Ugaritic'],
11112 ['Vaii', 'Vai'],
11113 ['Wara', 'Warang_Citi'],
11114 ['Xpeo', 'Old_Persian'],
11115 ['Xsux', 'Cuneiform'],
11116 ['Yiii', 'Yi'],
11117 ['Zanb', 'Zanabazar_Square'],
11118 ['Zinh', 'Inherited'],
11119 ['Qaai', 'Inherited'],
11120 ['Zyyy', 'Common'],
11121 ['Zzzz', 'Unknown'],
11122 ['Adlam', 'Adlam'],
11123 ['Caucasian_Albanian', 'Caucasian_Albanian'],
11124 ['Arabic', 'Arabic'],
11125 ['Imperial_Aramaic', 'Imperial_Aramaic'],
11126 ['Armenian', 'Armenian'],
11127 ['Avestan', 'Avestan'],
11128 ['Balinese', 'Balinese'],
11129 ['Bamum', 'Bamum'],
11130 ['Bassa_Vah', 'Bassa_Vah'],
11131 ['Batak', 'Batak'],
11132 ['Bengali', 'Bengali'],
11133 ['Bhaiksuki', 'Bhaiksuki'],
11134 ['Bopomofo', 'Bopomofo'],
11135 ['Brahmi', 'Brahmi'],
11136 ['Braille', 'Braille'],
11137 ['Buginese', 'Buginese'],
11138 ['Buhid', 'Buhid'],
11139 ['Chakma', 'Chakma'],
11140 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
11141 ['Carian', 'Carian'],
11142 ['Cherokee', 'Cherokee'],
11143 ['Coptic', 'Coptic'],
11144 ['Cypriot', 'Cypriot'],
11145 ['Cyrillic', 'Cyrillic'],
11146 ['Devanagari', 'Devanagari'],
11147 ['Deseret', 'Deseret'],
11148 ['Duployan', 'Duployan'],
11149 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
11150 ['Elbasan', 'Elbasan'],
11151 ['Ethiopic', 'Ethiopic'],
11152 ['Georgian', 'Georgian'],
11153 ['Glagolitic', 'Glagolitic'],
11154 ['Masaram_Gondi', 'Masaram_Gondi'],
11155 ['Gothic', 'Gothic'],
11156 ['Grantha', 'Grantha'],
11157 ['Greek', 'Greek'],
11158 ['Gujarati', 'Gujarati'],
11159 ['Gurmukhi', 'Gurmukhi'],
11160 ['Hangul', 'Hangul'],
11161 ['Han', 'Han'],
11162 ['Hanunoo', 'Hanunoo'],
11163 ['Hatran', 'Hatran'],
11164 ['Hebrew', 'Hebrew'],
11165 ['Hiragana', 'Hiragana'],
11166 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
11167 ['Pahawh_Hmong', 'Pahawh_Hmong'],
11168 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
11169 ['Old_Hungarian', 'Old_Hungarian'],
11170 ['Old_Italic', 'Old_Italic'],
11171 ['Javanese', 'Javanese'],
11172 ['Kayah_Li', 'Kayah_Li'],
11173 ['Katakana', 'Katakana'],
11174 ['Kharoshthi', 'Kharoshthi'],
11175 ['Khmer', 'Khmer'],
11176 ['Khojki', 'Khojki'],
11177 ['Kannada', 'Kannada'],
11178 ['Kaithi', 'Kaithi'],
11179 ['Tai_Tham', 'Tai_Tham'],
11180 ['Lao', 'Lao'],
11181 ['Latin', 'Latin'],
11182 ['Lepcha', 'Lepcha'],
11183 ['Limbu', 'Limbu'],
11184 ['Linear_A', 'Linear_A'],
11185 ['Linear_B', 'Linear_B'],
11186 ['Lycian', 'Lycian'],
11187 ['Lydian', 'Lydian'],
11188 ['Mahajani', 'Mahajani'],
11189 ['Mandaic', 'Mandaic'],
11190 ['Manichaean', 'Manichaean'],
11191 ['Marchen', 'Marchen'],
11192 ['Mende_Kikakui', 'Mende_Kikakui'],
11193 ['Meroitic_Cursive', 'Meroitic_Cursive'],
11194 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
11195 ['Malayalam', 'Malayalam'],
11196 ['Mongolian', 'Mongolian'],
11197 ['Mro', 'Mro'],
11198 ['Meetei_Mayek', 'Meetei_Mayek'],
11199 ['Multani', 'Multani'],
11200 ['Myanmar', 'Myanmar'],
11201 ['Old_North_Arabian', 'Old_North_Arabian'],
11202 ['Nabataean', 'Nabataean'],
11203 ['Nko', 'Nko'],
11204 ['Nushu', 'Nushu'],
11205 ['Ogham', 'Ogham'],
11206 ['Ol_Chiki', 'Ol_Chiki'],
11207 ['Old_Turkic', 'Old_Turkic'],
11208 ['Oriya', 'Oriya'],
11209 ['Osage', 'Osage'],
11210 ['Osmanya', 'Osmanya'],
11211 ['Palmyrene', 'Palmyrene'],
11212 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
11213 ['Old_Permic', 'Old_Permic'],
11214 ['Phags_Pa', 'Phags_Pa'],
11215 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
11216 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
11217 ['Phoenician', 'Phoenician'],
11218 ['Miao', 'Miao'],
11219 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
11220 ['Rejang', 'Rejang'],
11221 ['Runic', 'Runic'],
11222 ['Samaritan', 'Samaritan'],
11223 ['Old_South_Arabian', 'Old_South_Arabian'],
11224 ['Saurashtra', 'Saurashtra'],
11225 ['SignWriting', 'SignWriting'],
11226 ['Shavian', 'Shavian'],
11227 ['Sharada', 'Sharada'],
11228 ['Siddham', 'Siddham'],
11229 ['Khudawadi', 'Khudawadi'],
11230 ['Sinhala', 'Sinhala'],
11231 ['Sora_Sompeng', 'Sora_Sompeng'],
11232 ['Soyombo', 'Soyombo'],
11233 ['Sundanese', 'Sundanese'],
11234 ['Syloti_Nagri', 'Syloti_Nagri'],
11235 ['Syriac', 'Syriac'],
11236 ['Tagbanwa', 'Tagbanwa'],
11237 ['Takri', 'Takri'],
11238 ['Tai_Le', 'Tai_Le'],
11239 ['New_Tai_Lue', 'New_Tai_Lue'],
11240 ['Tamil', 'Tamil'],
11241 ['Tangut', 'Tangut'],
11242 ['Tai_Viet', 'Tai_Viet'],
11243 ['Telugu', 'Telugu'],
11244 ['Tifinagh', 'Tifinagh'],
11245 ['Tagalog', 'Tagalog'],
11246 ['Thaana', 'Thaana'],
11247 ['Tibetan', 'Tibetan'],
11248 ['Tirhuta', 'Tirhuta'],
11249 ['Ugaritic', 'Ugaritic'],
11250 ['Vai', 'Vai'],
11251 ['Warang_Citi', 'Warang_Citi'],
11252 ['Old_Persian', 'Old_Persian'],
11253 ['Cuneiform', 'Cuneiform'],
11254 ['Yi', 'Yi'],
11255 ['Zanabazar_Square', 'Zanabazar_Square'],
11256 ['Inherited', 'Inherited'],
11257 ['Common', 'Common'],
11258 ['Unknown', 'Unknown']
11259 ])]
11260]);
11261
11262'use strict';
11263
11264
11265
11266const matchPropertyValue = function(property, value) {
11267 const aliasToValue = mappings.get(property);
11268 if (!aliasToValue) {
11269 throw new Error(`Unknown property \`${ property }\`.`);
11270 }
11271 const canonicalValue = aliasToValue.get(value);
11272 if (canonicalValue) {
11273 return canonicalValue;
11274 }
11275 throw new Error(
11276 `Unknown value \`${ value }\` for property \`${ property }\`.`
11277 );
11278};
11279
11280var unicodeMatchPropertyValueEcmascript = matchPropertyValue;
11281
11282var iuMappings = new Map([
11283 [0x4B, 0x212A],
11284 [0x53, 0x17F],
11285 [0x6B, 0x212A],
11286 [0x73, 0x17F],
11287 [0xB5, 0x39C],
11288 [0xC5, 0x212B],
11289 [0xDF, 0x1E9E],
11290 [0xE5, 0x212B],
11291 [0x17F, 0x53],
11292 [0x1C4, 0x1C5],
11293 [0x1C5, 0x1C4],
11294 [0x1C7, 0x1C8],
11295 [0x1C8, 0x1C7],
11296 [0x1CA, 0x1CB],
11297 [0x1CB, 0x1CA],
11298 [0x1F1, 0x1F2],
11299 [0x1F2, 0x1F1],
11300 [0x26A, 0xA7AE],
11301 [0x29D, 0xA7B2],
11302 [0x345, 0x1FBE],
11303 [0x392, 0x3D0],
11304 [0x395, 0x3F5],
11305 [0x398, 0x3F4],
11306 [0x399, 0x1FBE],
11307 [0x39A, 0x3F0],
11308 [0x39C, 0xB5],
11309 [0x3A0, 0x3D6],
11310 [0x3A1, 0x3F1],
11311 [0x3A3, 0x3C2],
11312 [0x3A6, 0x3D5],
11313 [0x3A9, 0x2126],
11314 [0x3B8, 0x3F4],
11315 [0x3C2, 0x3A3],
11316 [0x3C9, 0x2126],
11317 [0x3D0, 0x392],
11318 [0x3D1, 0x3F4],
11319 [0x3D5, 0x3A6],
11320 [0x3D6, 0x3A0],
11321 [0x3F0, 0x39A],
11322 [0x3F1, 0x3A1],
11323 [0x3F4, [
11324 0x398,
11325 0x3D1,
11326 0x3B8
11327 ]],
11328 [0x3F5, 0x395],
11329 [0x412, 0x1C80],
11330 [0x414, 0x1C81],
11331 [0x41E, 0x1C82],
11332 [0x421, 0x1C83],
11333 [0x422, 0x1C85],
11334 [0x42A, 0x1C86],
11335 [0x432, 0x1C80],
11336 [0x434, 0x1C81],
11337 [0x43E, 0x1C82],
11338 [0x441, 0x1C83],
11339 [0x442, [
11340 0x1C84,
11341 0x1C85
11342 ]],
11343 [0x44A, 0x1C86],
11344 [0x462, 0x1C87],
11345 [0x463, 0x1C87],
11346 [0x13A0, 0xAB70],
11347 [0x13A1, 0xAB71],
11348 [0x13A2, 0xAB72],
11349 [0x13A3, 0xAB73],
11350 [0x13A4, 0xAB74],
11351 [0x13A5, 0xAB75],
11352 [0x13A6, 0xAB76],
11353 [0x13A7, 0xAB77],
11354 [0x13A8, 0xAB78],
11355 [0x13A9, 0xAB79],
11356 [0x13AA, 0xAB7A],
11357 [0x13AB, 0xAB7B],
11358 [0x13AC, 0xAB7C],
11359 [0x13AD, 0xAB7D],
11360 [0x13AE, 0xAB7E],
11361 [0x13AF, 0xAB7F],
11362 [0x13B0, 0xAB80],
11363 [0x13B1, 0xAB81],
11364 [0x13B2, 0xAB82],
11365 [0x13B3, 0xAB83],
11366 [0x13B4, 0xAB84],
11367 [0x13B5, 0xAB85],
11368 [0x13B6, 0xAB86],
11369 [0x13B7, 0xAB87],
11370 [0x13B8, 0xAB88],
11371 [0x13B9, 0xAB89],
11372 [0x13BA, 0xAB8A],
11373 [0x13BB, 0xAB8B],
11374 [0x13BC, 0xAB8C],
11375 [0x13BD, 0xAB8D],
11376 [0x13BE, 0xAB8E],
11377 [0x13BF, 0xAB8F],
11378 [0x13C0, 0xAB90],
11379 [0x13C1, 0xAB91],
11380 [0x13C2, 0xAB92],
11381 [0x13C3, 0xAB93],
11382 [0x13C4, 0xAB94],
11383 [0x13C5, 0xAB95],
11384 [0x13C6, 0xAB96],
11385 [0x13C7, 0xAB97],
11386 [0x13C8, 0xAB98],
11387 [0x13C9, 0xAB99],
11388 [0x13CA, 0xAB9A],
11389 [0x13CB, 0xAB9B],
11390 [0x13CC, 0xAB9C],
11391 [0x13CD, 0xAB9D],
11392 [0x13CE, 0xAB9E],
11393 [0x13CF, 0xAB9F],
11394 [0x13D0, 0xABA0],
11395 [0x13D1, 0xABA1],
11396 [0x13D2, 0xABA2],
11397 [0x13D3, 0xABA3],
11398 [0x13D4, 0xABA4],
11399 [0x13D5, 0xABA5],
11400 [0x13D6, 0xABA6],
11401 [0x13D7, 0xABA7],
11402 [0x13D8, 0xABA8],
11403 [0x13D9, 0xABA9],
11404 [0x13DA, 0xABAA],
11405 [0x13DB, 0xABAB],
11406 [0x13DC, 0xABAC],
11407 [0x13DD, 0xABAD],
11408 [0x13DE, 0xABAE],
11409 [0x13DF, 0xABAF],
11410 [0x13E0, 0xABB0],
11411 [0x13E1, 0xABB1],
11412 [0x13E2, 0xABB2],
11413 [0x13E3, 0xABB3],
11414 [0x13E4, 0xABB4],
11415 [0x13E5, 0xABB5],
11416 [0x13E6, 0xABB6],
11417 [0x13E7, 0xABB7],
11418 [0x13E8, 0xABB8],
11419 [0x13E9, 0xABB9],
11420 [0x13EA, 0xABBA],
11421 [0x13EB, 0xABBB],
11422 [0x13EC, 0xABBC],
11423 [0x13ED, 0xABBD],
11424 [0x13EE, 0xABBE],
11425 [0x13EF, 0xABBF],
11426 [0x13F0, 0x13F8],
11427 [0x13F1, 0x13F9],
11428 [0x13F2, 0x13FA],
11429 [0x13F3, 0x13FB],
11430 [0x13F4, 0x13FC],
11431 [0x13F5, 0x13FD],
11432 [0x13F8, 0x13F0],
11433 [0x13F9, 0x13F1],
11434 [0x13FA, 0x13F2],
11435 [0x13FB, 0x13F3],
11436 [0x13FC, 0x13F4],
11437 [0x13FD, 0x13F5],
11438 [0x1C80, [
11439 0x412,
11440 0x432
11441 ]],
11442 [0x1C81, [
11443 0x414,
11444 0x434
11445 ]],
11446 [0x1C82, [
11447 0x41E,
11448 0x43E
11449 ]],
11450 [0x1C83, [
11451 0x421,
11452 0x441
11453 ]],
11454 [0x1C84, [
11455 0x1C85,
11456 0x442
11457 ]],
11458 [0x1C85, [
11459 0x422,
11460 0x1C84,
11461 0x442
11462 ]],
11463 [0x1C86, [
11464 0x42A,
11465 0x44A
11466 ]],
11467 [0x1C87, [
11468 0x462,
11469 0x463
11470 ]],
11471 [0x1C88, [
11472 0xA64A,
11473 0xA64B
11474 ]],
11475 [0x1E60, 0x1E9B],
11476 [0x1E9B, 0x1E60],
11477 [0x1E9E, 0xDF],
11478 [0x1F80, 0x1F88],
11479 [0x1F81, 0x1F89],
11480 [0x1F82, 0x1F8A],
11481 [0x1F83, 0x1F8B],
11482 [0x1F84, 0x1F8C],
11483 [0x1F85, 0x1F8D],
11484 [0x1F86, 0x1F8E],
11485 [0x1F87, 0x1F8F],
11486 [0x1F88, 0x1F80],
11487 [0x1F89, 0x1F81],
11488 [0x1F8A, 0x1F82],
11489 [0x1F8B, 0x1F83],
11490 [0x1F8C, 0x1F84],
11491 [0x1F8D, 0x1F85],
11492 [0x1F8E, 0x1F86],
11493 [0x1F8F, 0x1F87],
11494 [0x1F90, 0x1F98],
11495 [0x1F91, 0x1F99],
11496 [0x1F92, 0x1F9A],
11497 [0x1F93, 0x1F9B],
11498 [0x1F94, 0x1F9C],
11499 [0x1F95, 0x1F9D],
11500 [0x1F96, 0x1F9E],
11501 [0x1F97, 0x1F9F],
11502 [0x1F98, 0x1F90],
11503 [0x1F99, 0x1F91],
11504 [0x1F9A, 0x1F92],
11505 [0x1F9B, 0x1F93],
11506 [0x1F9C, 0x1F94],
11507 [0x1F9D, 0x1F95],
11508 [0x1F9E, 0x1F96],
11509 [0x1F9F, 0x1F97],
11510 [0x1FA0, 0x1FA8],
11511 [0x1FA1, 0x1FA9],
11512 [0x1FA2, 0x1FAA],
11513 [0x1FA3, 0x1FAB],
11514 [0x1FA4, 0x1FAC],
11515 [0x1FA5, 0x1FAD],
11516 [0x1FA6, 0x1FAE],
11517 [0x1FA7, 0x1FAF],
11518 [0x1FA8, 0x1FA0],
11519 [0x1FA9, 0x1FA1],
11520 [0x1FAA, 0x1FA2],
11521 [0x1FAB, 0x1FA3],
11522 [0x1FAC, 0x1FA4],
11523 [0x1FAD, 0x1FA5],
11524 [0x1FAE, 0x1FA6],
11525 [0x1FAF, 0x1FA7],
11526 [0x1FB3, 0x1FBC],
11527 [0x1FBC, 0x1FB3],
11528 [0x1FBE, [
11529 0x345,
11530 0x399
11531 ]],
11532 [0x1FC3, 0x1FCC],
11533 [0x1FCC, 0x1FC3],
11534 [0x1FF3, 0x1FFC],
11535 [0x1FFC, 0x1FF3],
11536 [0x2126, [
11537 0x3A9,
11538 0x3C9
11539 ]],
11540 [0x212A, 0x4B],
11541 [0x212B, [
11542 0xC5,
11543 0xE5
11544 ]],
11545 [0xA64A, 0x1C88],
11546 [0xA64B, 0x1C88],
11547 [0xA7AE, 0x26A],
11548 [0xA7B2, 0x29D],
11549 [0xA7B3, 0xAB53],
11550 [0xA7B4, 0xA7B5],
11551 [0xA7B5, 0xA7B4],
11552 [0xA7B6, 0xA7B7],
11553 [0xA7B7, 0xA7B6],
11554 [0xAB53, 0xA7B3],
11555 [0xAB70, 0x13A0],
11556 [0xAB71, 0x13A1],
11557 [0xAB72, 0x13A2],
11558 [0xAB73, 0x13A3],
11559 [0xAB74, 0x13A4],
11560 [0xAB75, 0x13A5],
11561 [0xAB76, 0x13A6],
11562 [0xAB77, 0x13A7],
11563 [0xAB78, 0x13A8],
11564 [0xAB79, 0x13A9],
11565 [0xAB7A, 0x13AA],
11566 [0xAB7B, 0x13AB],
11567 [0xAB7C, 0x13AC],
11568 [0xAB7D, 0x13AD],
11569 [0xAB7E, 0x13AE],
11570 [0xAB7F, 0x13AF],
11571 [0xAB80, 0x13B0],
11572 [0xAB81, 0x13B1],
11573 [0xAB82, 0x13B2],
11574 [0xAB83, 0x13B3],
11575 [0xAB84, 0x13B4],
11576 [0xAB85, 0x13B5],
11577 [0xAB86, 0x13B6],
11578 [0xAB87, 0x13B7],
11579 [0xAB88, 0x13B8],
11580 [0xAB89, 0x13B9],
11581 [0xAB8A, 0x13BA],
11582 [0xAB8B, 0x13BB],
11583 [0xAB8C, 0x13BC],
11584 [0xAB8D, 0x13BD],
11585 [0xAB8E, 0x13BE],
11586 [0xAB8F, 0x13BF],
11587 [0xAB90, 0x13C0],
11588 [0xAB91, 0x13C1],
11589 [0xAB92, 0x13C2],
11590 [0xAB93, 0x13C3],
11591 [0xAB94, 0x13C4],
11592 [0xAB95, 0x13C5],
11593 [0xAB96, 0x13C6],
11594 [0xAB97, 0x13C7],
11595 [0xAB98, 0x13C8],
11596 [0xAB99, 0x13C9],
11597 [0xAB9A, 0x13CA],
11598 [0xAB9B, 0x13CB],
11599 [0xAB9C, 0x13CC],
11600 [0xAB9D, 0x13CD],
11601 [0xAB9E, 0x13CE],
11602 [0xAB9F, 0x13CF],
11603 [0xABA0, 0x13D0],
11604 [0xABA1, 0x13D1],
11605 [0xABA2, 0x13D2],
11606 [0xABA3, 0x13D3],
11607 [0xABA4, 0x13D4],
11608 [0xABA5, 0x13D5],
11609 [0xABA6, 0x13D6],
11610 [0xABA7, 0x13D7],
11611 [0xABA8, 0x13D8],
11612 [0xABA9, 0x13D9],
11613 [0xABAA, 0x13DA],
11614 [0xABAB, 0x13DB],
11615 [0xABAC, 0x13DC],
11616 [0xABAD, 0x13DD],
11617 [0xABAE, 0x13DE],
11618 [0xABAF, 0x13DF],
11619 [0xABB0, 0x13E0],
11620 [0xABB1, 0x13E1],
11621 [0xABB2, 0x13E2],
11622 [0xABB3, 0x13E3],
11623 [0xABB4, 0x13E4],
11624 [0xABB5, 0x13E5],
11625 [0xABB6, 0x13E6],
11626 [0xABB7, 0x13E7],
11627 [0xABB8, 0x13E8],
11628 [0xABB9, 0x13E9],
11629 [0xABBA, 0x13EA],
11630 [0xABBB, 0x13EB],
11631 [0xABBC, 0x13EC],
11632 [0xABBD, 0x13ED],
11633 [0xABBE, 0x13EE],
11634 [0xABBF, 0x13EF],
11635 [0x10400, 0x10428],
11636 [0x10401, 0x10429],
11637 [0x10402, 0x1042A],
11638 [0x10403, 0x1042B],
11639 [0x10404, 0x1042C],
11640 [0x10405, 0x1042D],
11641 [0x10406, 0x1042E],
11642 [0x10407, 0x1042F],
11643 [0x10408, 0x10430],
11644 [0x10409, 0x10431],
11645 [0x1040A, 0x10432],
11646 [0x1040B, 0x10433],
11647 [0x1040C, 0x10434],
11648 [0x1040D, 0x10435],
11649 [0x1040E, 0x10436],
11650 [0x1040F, 0x10437],
11651 [0x10410, 0x10438],
11652 [0x10411, 0x10439],
11653 [0x10412, 0x1043A],
11654 [0x10413, 0x1043B],
11655 [0x10414, 0x1043C],
11656 [0x10415, 0x1043D],
11657 [0x10416, 0x1043E],
11658 [0x10417, 0x1043F],
11659 [0x10418, 0x10440],
11660 [0x10419, 0x10441],
11661 [0x1041A, 0x10442],
11662 [0x1041B, 0x10443],
11663 [0x1041C, 0x10444],
11664 [0x1041D, 0x10445],
11665 [0x1041E, 0x10446],
11666 [0x1041F, 0x10447],
11667 [0x10420, 0x10448],
11668 [0x10421, 0x10449],
11669 [0x10422, 0x1044A],
11670 [0x10423, 0x1044B],
11671 [0x10424, 0x1044C],
11672 [0x10425, 0x1044D],
11673 [0x10426, 0x1044E],
11674 [0x10427, 0x1044F],
11675 [0x10428, 0x10400],
11676 [0x10429, 0x10401],
11677 [0x1042A, 0x10402],
11678 [0x1042B, 0x10403],
11679 [0x1042C, 0x10404],
11680 [0x1042D, 0x10405],
11681 [0x1042E, 0x10406],
11682 [0x1042F, 0x10407],
11683 [0x10430, 0x10408],
11684 [0x10431, 0x10409],
11685 [0x10432, 0x1040A],
11686 [0x10433, 0x1040B],
11687 [0x10434, 0x1040C],
11688 [0x10435, 0x1040D],
11689 [0x10436, 0x1040E],
11690 [0x10437, 0x1040F],
11691 [0x10438, 0x10410],
11692 [0x10439, 0x10411],
11693 [0x1043A, 0x10412],
11694 [0x1043B, 0x10413],
11695 [0x1043C, 0x10414],
11696 [0x1043D, 0x10415],
11697 [0x1043E, 0x10416],
11698 [0x1043F, 0x10417],
11699 [0x10440, 0x10418],
11700 [0x10441, 0x10419],
11701 [0x10442, 0x1041A],
11702 [0x10443, 0x1041B],
11703 [0x10444, 0x1041C],
11704 [0x10445, 0x1041D],
11705 [0x10446, 0x1041E],
11706 [0x10447, 0x1041F],
11707 [0x10448, 0x10420],
11708 [0x10449, 0x10421],
11709 [0x1044A, 0x10422],
11710 [0x1044B, 0x10423],
11711 [0x1044C, 0x10424],
11712 [0x1044D, 0x10425],
11713 [0x1044E, 0x10426],
11714 [0x1044F, 0x10427],
11715 [0x104B0, 0x104D8],
11716 [0x104B1, 0x104D9],
11717 [0x104B2, 0x104DA],
11718 [0x104B3, 0x104DB],
11719 [0x104B4, 0x104DC],
11720 [0x104B5, 0x104DD],
11721 [0x104B6, 0x104DE],
11722 [0x104B7, 0x104DF],
11723 [0x104B8, 0x104E0],
11724 [0x104B9, 0x104E1],
11725 [0x104BA, 0x104E2],
11726 [0x104BB, 0x104E3],
11727 [0x104BC, 0x104E4],
11728 [0x104BD, 0x104E5],
11729 [0x104BE, 0x104E6],
11730 [0x104BF, 0x104E7],
11731 [0x104C0, 0x104E8],
11732 [0x104C1, 0x104E9],
11733 [0x104C2, 0x104EA],
11734 [0x104C3, 0x104EB],
11735 [0x104C4, 0x104EC],
11736 [0x104C5, 0x104ED],
11737 [0x104C6, 0x104EE],
11738 [0x104C7, 0x104EF],
11739 [0x104C8, 0x104F0],
11740 [0x104C9, 0x104F1],
11741 [0x104CA, 0x104F2],
11742 [0x104CB, 0x104F3],
11743 [0x104CC, 0x104F4],
11744 [0x104CD, 0x104F5],
11745 [0x104CE, 0x104F6],
11746 [0x104CF, 0x104F7],
11747 [0x104D0, 0x104F8],
11748 [0x104D1, 0x104F9],
11749 [0x104D2, 0x104FA],
11750 [0x104D3, 0x104FB],
11751 [0x104D8, 0x104B0],
11752 [0x104D9, 0x104B1],
11753 [0x104DA, 0x104B2],
11754 [0x104DB, 0x104B3],
11755 [0x104DC, 0x104B4],
11756 [0x104DD, 0x104B5],
11757 [0x104DE, 0x104B6],
11758 [0x104DF, 0x104B7],
11759 [0x104E0, 0x104B8],
11760 [0x104E1, 0x104B9],
11761 [0x104E2, 0x104BA],
11762 [0x104E3, 0x104BB],
11763 [0x104E4, 0x104BC],
11764 [0x104E5, 0x104BD],
11765 [0x104E6, 0x104BE],
11766 [0x104E7, 0x104BF],
11767 [0x104E8, 0x104C0],
11768 [0x104E9, 0x104C1],
11769 [0x104EA, 0x104C2],
11770 [0x104EB, 0x104C3],
11771 [0x104EC, 0x104C4],
11772 [0x104ED, 0x104C5],
11773 [0x104EE, 0x104C6],
11774 [0x104EF, 0x104C7],
11775 [0x104F0, 0x104C8],
11776 [0x104F1, 0x104C9],
11777 [0x104F2, 0x104CA],
11778 [0x104F3, 0x104CB],
11779 [0x104F4, 0x104CC],
11780 [0x104F5, 0x104CD],
11781 [0x104F6, 0x104CE],
11782 [0x104F7, 0x104CF],
11783 [0x104F8, 0x104D0],
11784 [0x104F9, 0x104D1],
11785 [0x104FA, 0x104D2],
11786 [0x104FB, 0x104D3],
11787 [0x10C80, 0x10CC0],
11788 [0x10C81, 0x10CC1],
11789 [0x10C82, 0x10CC2],
11790 [0x10C83, 0x10CC3],
11791 [0x10C84, 0x10CC4],
11792 [0x10C85, 0x10CC5],
11793 [0x10C86, 0x10CC6],
11794 [0x10C87, 0x10CC7],
11795 [0x10C88, 0x10CC8],
11796 [0x10C89, 0x10CC9],
11797 [0x10C8A, 0x10CCA],
11798 [0x10C8B, 0x10CCB],
11799 [0x10C8C, 0x10CCC],
11800 [0x10C8D, 0x10CCD],
11801 [0x10C8E, 0x10CCE],
11802 [0x10C8F, 0x10CCF],
11803 [0x10C90, 0x10CD0],
11804 [0x10C91, 0x10CD1],
11805 [0x10C92, 0x10CD2],
11806 [0x10C93, 0x10CD3],
11807 [0x10C94, 0x10CD4],
11808 [0x10C95, 0x10CD5],
11809 [0x10C96, 0x10CD6],
11810 [0x10C97, 0x10CD7],
11811 [0x10C98, 0x10CD8],
11812 [0x10C99, 0x10CD9],
11813 [0x10C9A, 0x10CDA],
11814 [0x10C9B, 0x10CDB],
11815 [0x10C9C, 0x10CDC],
11816 [0x10C9D, 0x10CDD],
11817 [0x10C9E, 0x10CDE],
11818 [0x10C9F, 0x10CDF],
11819 [0x10CA0, 0x10CE0],
11820 [0x10CA1, 0x10CE1],
11821 [0x10CA2, 0x10CE2],
11822 [0x10CA3, 0x10CE3],
11823 [0x10CA4, 0x10CE4],
11824 [0x10CA5, 0x10CE5],
11825 [0x10CA6, 0x10CE6],
11826 [0x10CA7, 0x10CE7],
11827 [0x10CA8, 0x10CE8],
11828 [0x10CA9, 0x10CE9],
11829 [0x10CAA, 0x10CEA],
11830 [0x10CAB, 0x10CEB],
11831 [0x10CAC, 0x10CEC],
11832 [0x10CAD, 0x10CED],
11833 [0x10CAE, 0x10CEE],
11834 [0x10CAF, 0x10CEF],
11835 [0x10CB0, 0x10CF0],
11836 [0x10CB1, 0x10CF1],
11837 [0x10CB2, 0x10CF2],
11838 [0x10CC0, 0x10C80],
11839 [0x10CC1, 0x10C81],
11840 [0x10CC2, 0x10C82],
11841 [0x10CC3, 0x10C83],
11842 [0x10CC4, 0x10C84],
11843 [0x10CC5, 0x10C85],
11844 [0x10CC6, 0x10C86],
11845 [0x10CC7, 0x10C87],
11846 [0x10CC8, 0x10C88],
11847 [0x10CC9, 0x10C89],
11848 [0x10CCA, 0x10C8A],
11849 [0x10CCB, 0x10C8B],
11850 [0x10CCC, 0x10C8C],
11851 [0x10CCD, 0x10C8D],
11852 [0x10CCE, 0x10C8E],
11853 [0x10CCF, 0x10C8F],
11854 [0x10CD0, 0x10C90],
11855 [0x10CD1, 0x10C91],
11856 [0x10CD2, 0x10C92],
11857 [0x10CD3, 0x10C93],
11858 [0x10CD4, 0x10C94],
11859 [0x10CD5, 0x10C95],
11860 [0x10CD6, 0x10C96],
11861 [0x10CD7, 0x10C97],
11862 [0x10CD8, 0x10C98],
11863 [0x10CD9, 0x10C99],
11864 [0x10CDA, 0x10C9A],
11865 [0x10CDB, 0x10C9B],
11866 [0x10CDC, 0x10C9C],
11867 [0x10CDD, 0x10C9D],
11868 [0x10CDE, 0x10C9E],
11869 [0x10CDF, 0x10C9F],
11870 [0x10CE0, 0x10CA0],
11871 [0x10CE1, 0x10CA1],
11872 [0x10CE2, 0x10CA2],
11873 [0x10CE3, 0x10CA3],
11874 [0x10CE4, 0x10CA4],
11875 [0x10CE5, 0x10CA5],
11876 [0x10CE6, 0x10CA6],
11877 [0x10CE7, 0x10CA7],
11878 [0x10CE8, 0x10CA8],
11879 [0x10CE9, 0x10CA9],
11880 [0x10CEA, 0x10CAA],
11881 [0x10CEB, 0x10CAB],
11882 [0x10CEC, 0x10CAC],
11883 [0x10CED, 0x10CAD],
11884 [0x10CEE, 0x10CAE],
11885 [0x10CEF, 0x10CAF],
11886 [0x10CF0, 0x10CB0],
11887 [0x10CF1, 0x10CB1],
11888 [0x10CF2, 0x10CB2],
11889 [0x118A0, 0x118C0],
11890 [0x118A1, 0x118C1],
11891 [0x118A2, 0x118C2],
11892 [0x118A3, 0x118C3],
11893 [0x118A4, 0x118C4],
11894 [0x118A5, 0x118C5],
11895 [0x118A6, 0x118C6],
11896 [0x118A7, 0x118C7],
11897 [0x118A8, 0x118C8],
11898 [0x118A9, 0x118C9],
11899 [0x118AA, 0x118CA],
11900 [0x118AB, 0x118CB],
11901 [0x118AC, 0x118CC],
11902 [0x118AD, 0x118CD],
11903 [0x118AE, 0x118CE],
11904 [0x118AF, 0x118CF],
11905 [0x118B0, 0x118D0],
11906 [0x118B1, 0x118D1],
11907 [0x118B2, 0x118D2],
11908 [0x118B3, 0x118D3],
11909 [0x118B4, 0x118D4],
11910 [0x118B5, 0x118D5],
11911 [0x118B6, 0x118D6],
11912 [0x118B7, 0x118D7],
11913 [0x118B8, 0x118D8],
11914 [0x118B9, 0x118D9],
11915 [0x118BA, 0x118DA],
11916 [0x118BB, 0x118DB],
11917 [0x118BC, 0x118DC],
11918 [0x118BD, 0x118DD],
11919 [0x118BE, 0x118DE],
11920 [0x118BF, 0x118DF],
11921 [0x118C0, 0x118A0],
11922 [0x118C1, 0x118A1],
11923 [0x118C2, 0x118A2],
11924 [0x118C3, 0x118A3],
11925 [0x118C4, 0x118A4],
11926 [0x118C5, 0x118A5],
11927 [0x118C6, 0x118A6],
11928 [0x118C7, 0x118A7],
11929 [0x118C8, 0x118A8],
11930 [0x118C9, 0x118A9],
11931 [0x118CA, 0x118AA],
11932 [0x118CB, 0x118AB],
11933 [0x118CC, 0x118AC],
11934 [0x118CD, 0x118AD],
11935 [0x118CE, 0x118AE],
11936 [0x118CF, 0x118AF],
11937 [0x118D0, 0x118B0],
11938 [0x118D1, 0x118B1],
11939 [0x118D2, 0x118B2],
11940 [0x118D3, 0x118B3],
11941 [0x118D4, 0x118B4],
11942 [0x118D5, 0x118B5],
11943 [0x118D6, 0x118B6],
11944 [0x118D7, 0x118B7],
11945 [0x118D8, 0x118B8],
11946 [0x118D9, 0x118B9],
11947 [0x118DA, 0x118BA],
11948 [0x118DB, 0x118BB],
11949 [0x118DC, 0x118BC],
11950 [0x118DD, 0x118BD],
11951 [0x118DE, 0x118BE],
11952 [0x118DF, 0x118BF],
11953 [0x1E900, 0x1E922],
11954 [0x1E901, 0x1E923],
11955 [0x1E902, 0x1E924],
11956 [0x1E903, 0x1E925],
11957 [0x1E904, 0x1E926],
11958 [0x1E905, 0x1E927],
11959 [0x1E906, 0x1E928],
11960 [0x1E907, 0x1E929],
11961 [0x1E908, 0x1E92A],
11962 [0x1E909, 0x1E92B],
11963 [0x1E90A, 0x1E92C],
11964 [0x1E90B, 0x1E92D],
11965 [0x1E90C, 0x1E92E],
11966 [0x1E90D, 0x1E92F],
11967 [0x1E90E, 0x1E930],
11968 [0x1E90F, 0x1E931],
11969 [0x1E910, 0x1E932],
11970 [0x1E911, 0x1E933],
11971 [0x1E912, 0x1E934],
11972 [0x1E913, 0x1E935],
11973 [0x1E914, 0x1E936],
11974 [0x1E915, 0x1E937],
11975 [0x1E916, 0x1E938],
11976 [0x1E917, 0x1E939],
11977 [0x1E918, 0x1E93A],
11978 [0x1E919, 0x1E93B],
11979 [0x1E91A, 0x1E93C],
11980 [0x1E91B, 0x1E93D],
11981 [0x1E91C, 0x1E93E],
11982 [0x1E91D, 0x1E93F],
11983 [0x1E91E, 0x1E940],
11984 [0x1E91F, 0x1E941],
11985 [0x1E920, 0x1E942],
11986 [0x1E921, 0x1E943],
11987 [0x1E922, 0x1E900],
11988 [0x1E923, 0x1E901],
11989 [0x1E924, 0x1E902],
11990 [0x1E925, 0x1E903],
11991 [0x1E926, 0x1E904],
11992 [0x1E927, 0x1E905],
11993 [0x1E928, 0x1E906],
11994 [0x1E929, 0x1E907],
11995 [0x1E92A, 0x1E908],
11996 [0x1E92B, 0x1E909],
11997 [0x1E92C, 0x1E90A],
11998 [0x1E92D, 0x1E90B],
11999 [0x1E92E, 0x1E90C],
12000 [0x1E92F, 0x1E90D],
12001 [0x1E930, 0x1E90E],
12002 [0x1E931, 0x1E90F],
12003 [0x1E932, 0x1E910],
12004 [0x1E933, 0x1E911],
12005 [0x1E934, 0x1E912],
12006 [0x1E935, 0x1E913],
12007 [0x1E936, 0x1E914],
12008 [0x1E937, 0x1E915],
12009 [0x1E938, 0x1E916],
12010 [0x1E939, 0x1E917],
12011 [0x1E93A, 0x1E918],
12012 [0x1E93B, 0x1E919],
12013 [0x1E93C, 0x1E91A],
12014 [0x1E93D, 0x1E91B],
12015 [0x1E93E, 0x1E91C],
12016 [0x1E93F, 0x1E91D],
12017 [0x1E940, 0x1E91E],
12018 [0x1E941, 0x1E91F],
12019 [0x1E942, 0x1E920],
12020 [0x1E943, 0x1E921]
12021]);
12022
12023// Generated using `npm run build`. Do not edit.
12024'use strict';
12025
12026
12027
12028var REGULAR = new Map([
12029 ['d', regenerate()
12030 .addRange(0x30, 0x39)],
12031 ['D', regenerate()
12032 .addRange(0x0, 0x2F)
12033 .addRange(0x3A, 0xFFFF)],
12034 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
12035 .addRange(0x9, 0xD)
12036 .addRange(0x2000, 0x200A)
12037 .addRange(0x2028, 0x2029)],
12038 ['S', regenerate()
12039 .addRange(0x0, 0x8)
12040 .addRange(0xE, 0x1F)
12041 .addRange(0x21, 0x9F)
12042 .addRange(0xA1, 0x167F)
12043 .addRange(0x1681, 0x1FFF)
12044 .addRange(0x200B, 0x2027)
12045 .addRange(0x202A, 0x202E)
12046 .addRange(0x2030, 0x205E)
12047 .addRange(0x2060, 0x2FFF)
12048 .addRange(0x3001, 0xFEFE)
12049 .addRange(0xFF00, 0xFFFF)],
12050 ['w', regenerate(0x5F)
12051 .addRange(0x30, 0x39)
12052 .addRange(0x41, 0x5A)
12053 .addRange(0x61, 0x7A)],
12054 ['W', regenerate(0x60)
12055 .addRange(0x0, 0x2F)
12056 .addRange(0x3A, 0x40)
12057 .addRange(0x5B, 0x5E)
12058 .addRange(0x7B, 0xFFFF)]
12059]);
12060
12061var UNICODE = new Map([
12062 ['d', regenerate()
12063 .addRange(0x30, 0x39)],
12064 ['D', regenerate()
12065 .addRange(0x0, 0x2F)
12066 .addRange(0x3A, 0x10FFFF)],
12067 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
12068 .addRange(0x9, 0xD)
12069 .addRange(0x2000, 0x200A)
12070 .addRange(0x2028, 0x2029)],
12071 ['S', regenerate()
12072 .addRange(0x0, 0x8)
12073 .addRange(0xE, 0x1F)
12074 .addRange(0x21, 0x9F)
12075 .addRange(0xA1, 0x167F)
12076 .addRange(0x1681, 0x1FFF)
12077 .addRange(0x200B, 0x2027)
12078 .addRange(0x202A, 0x202E)
12079 .addRange(0x2030, 0x205E)
12080 .addRange(0x2060, 0x2FFF)
12081 .addRange(0x3001, 0xFEFE)
12082 .addRange(0xFF00, 0x10FFFF)],
12083 ['w', regenerate(0x5F)
12084 .addRange(0x30, 0x39)
12085 .addRange(0x41, 0x5A)
12086 .addRange(0x61, 0x7A)],
12087 ['W', regenerate(0x60)
12088 .addRange(0x0, 0x2F)
12089 .addRange(0x3A, 0x40)
12090 .addRange(0x5B, 0x5E)
12091 .addRange(0x7B, 0x10FFFF)]
12092]);
12093
12094var UNICODE_IGNORE_CASE = new Map([
12095 ['d', regenerate()
12096 .addRange(0x30, 0x39)],
12097 ['D', regenerate()
12098 .addRange(0x0, 0x2F)
12099 .addRange(0x3A, 0x10FFFF)],
12100 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
12101 .addRange(0x9, 0xD)
12102 .addRange(0x2000, 0x200A)
12103 .addRange(0x2028, 0x2029)],
12104 ['S', regenerate()
12105 .addRange(0x0, 0x8)
12106 .addRange(0xE, 0x1F)
12107 .addRange(0x21, 0x9F)
12108 .addRange(0xA1, 0x167F)
12109 .addRange(0x1681, 0x1FFF)
12110 .addRange(0x200B, 0x2027)
12111 .addRange(0x202A, 0x202E)
12112 .addRange(0x2030, 0x205E)
12113 .addRange(0x2060, 0x2FFF)
12114 .addRange(0x3001, 0xFEFE)
12115 .addRange(0xFF00, 0x10FFFF)],
12116 ['w', regenerate(0x5F, 0x17F, 0x212A)
12117 .addRange(0x30, 0x39)
12118 .addRange(0x41, 0x5A)
12119 .addRange(0x61, 0x7A)],
12120 ['W', regenerate(0x60)
12121 .addRange(0x0, 0x2F)
12122 .addRange(0x3A, 0x40)
12123 .addRange(0x5B, 0x5E)
12124 .addRange(0x7B, 0x17E)
12125 .addRange(0x180, 0x2129)
12126 .addRange(0x212B, 0x10FFFF)]
12127]);
12128
12129var characterClassEscapeSets = {
12130 REGULAR: REGULAR,
12131 UNICODE: UNICODE,
12132 UNICODE_IGNORE_CASE: UNICODE_IGNORE_CASE
12133};
12134
12135var rewritePattern_1 = createCommonjsModule(function (module) {
12136'use strict';
12137
12138var generate = regjsgen.generate;
12139var parse = parser.parse;
12140
12141
12142
12143
12144
12145
12146// Prepare a Regenerate set containing all code points, used for negative
12147// character classes (if any).
12148var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
12149// Without the `u` flag, the range stops at 0xFFFF.
12150// https://mths.be/es6#sec-pattern-semantics
12151var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
12152
12153// Prepare a Regenerate set containing all code points that are supposed to be
12154// matched by `/./u`. https://mths.be/es6#sec-atom
12155var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
12156 .remove(
12157 // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
12158 0x000A, // Line Feed <LF>
12159 0x000D, // Carriage Return <CR>
12160 0x2028, // Line Separator <LS>
12161 0x2029 // Paragraph Separator <PS>
12162 );
12163// Prepare a Regenerate set containing all code points that are supposed to be
12164// matched by `/./` (only BMP code points).
12165var DOT_SET = DOT_SET_UNICODE.clone()
12166 .intersection(BMP_SET);
12167
12168var getCharacterClassEscapeSet = function (character, unicode, ignoreCase) {
12169 if (unicode) {
12170 if (ignoreCase) {
12171 return characterClassEscapeSets.UNICODE_IGNORE_CASE.get(character);
12172 }
12173 return characterClassEscapeSets.UNICODE.get(character);
12174 }
12175 return characterClassEscapeSets.REGULAR.get(character);
12176};
12177
12178var getDotSet = function (unicode, dotAll) {
12179 if (dotAll) {
12180 return unicode ? UNICODE_SET : BMP_SET;
12181 }
12182 return unicode ? DOT_SET_UNICODE : DOT_SET;
12183};
12184
12185var getUnicodePropertyValueSet = function (property, value) {
12186 var path = value ?
12187 (property + "/" + value) :
12188 ("Binary_Property/" + property);
12189 try {
12190 return commonjsRequire(("regenerate-unicode-properties/" + path + ".js"));
12191 } catch (exception) {
12192 throw new Error(
12193 "Failed to recognize value `" + value + "` for property " +
12194 "`" + property + "`."
12195 );
12196 }
12197};
12198
12199var handleLoneUnicodePropertyNameOrValue = function (value) {
12200 // It could be a `General_Category` value or a binary property.
12201 // Note: `unicodeMatchPropertyValue` throws on invalid values.
12202 try {
12203 var property$1 = 'General_Category';
12204 var category = unicodeMatchPropertyValueEcmascript(property$1, value);
12205 return getUnicodePropertyValueSet(property$1, category);
12206 } catch (exception) {}
12207 // It’s not a `General_Category` value, so check if it’s a binary
12208 // property. Note: `unicodeMatchProperty` throws on invalid properties.
12209 var property = unicodeMatchPropertyEcmascript(value);
12210 return getUnicodePropertyValueSet(property);
12211};
12212
12213var getUnicodePropertyEscapeSet = function (value, isNegative) {
12214 var parts = value.split('=');
12215 var firstPart = parts[0];
12216 var set;
12217 if (parts.length == 1) {
12218 set = handleLoneUnicodePropertyNameOrValue(firstPart);
12219 } else {
12220 // The pattern consists of two parts, i.e. `Property=Value`.
12221 var property = unicodeMatchPropertyEcmascript(firstPart);
12222 var value$1 = unicodeMatchPropertyValueEcmascript(property, parts[1]);
12223 set = getUnicodePropertyValueSet(property, value$1);
12224 }
12225 if (isNegative) {
12226 return UNICODE_SET.clone().remove(set);
12227 }
12228 return set.clone();
12229};
12230
12231// Given a range of code points, add any case-folded code points in that range
12232// to a set.
12233regenerate.prototype.iuAddRange = function(min, max) {
12234 var $this = this;
12235 do {
12236 var folded = caseFold(min);
12237 if (folded) {
12238 $this.add(folded);
12239 }
12240 } while (++min <= max);
12241 return $this;
12242};
12243
12244var update = function (item, pattern) {
12245 var tree = parse(pattern, config.useUnicodeFlag ? 'u' : '');
12246 switch (tree.type) {
12247 case 'characterClass':
12248 case 'group':
12249 case 'value':
12250 // No wrapping needed.
12251 break;
12252 default:
12253 // Wrap the pattern in a non-capturing group.
12254 tree = wrap(tree, pattern);
12255 }
12256 Object.assign(item, tree);
12257};
12258
12259var wrap = function (tree, pattern) {
12260 // Wrap the pattern in a non-capturing group.
12261 return {
12262 'type': 'group',
12263 'behavior': 'ignore',
12264 'body': [tree],
12265 'raw': ("(?:" + pattern + ")")
12266 };
12267};
12268
12269var caseFold = function (codePoint) {
12270 return iuMappings.get(codePoint) || false;
12271};
12272
12273var processCharacterClass = function (characterClassItem, regenerateOptions) {
12274 var set = regenerate();
12275 for (var i = 0, list = characterClassItem.body; i < list.length; i += 1) {
12276 var item = list[i];
12277
12278 switch (item.type) {
12279 case 'value':
12280 set.add(item.codePoint);
12281 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
12282 var folded = caseFold(item.codePoint);
12283 if (folded) {
12284 set.add(folded);
12285 }
12286 }
12287 break;
12288 case 'characterClassRange':
12289 var min = item.min.codePoint;
12290 var max = item.max.codePoint;
12291 set.addRange(min, max);
12292 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
12293 set.iuAddRange(min, max);
12294 }
12295 break;
12296 case 'characterClassEscape':
12297 set.add(getCharacterClassEscapeSet(
12298 item.value,
12299 config.unicode,
12300 config.ignoreCase
12301 ));
12302 break;
12303 case 'unicodePropertyEscape':
12304 set.add(getUnicodePropertyEscapeSet(item.value, item.negative));
12305 break;
12306 // The `default` clause is only here as a safeguard; it should never be
12307 // reached. Code coverage tools should ignore it.
12308 /* istanbul ignore next */
12309 default:
12310 throw new Error(("Unknown term type: " + (item.type)));
12311 }
12312 }
12313 if (characterClassItem.negative) {
12314 set = (config.unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
12315 }
12316 update(characterClassItem, set.toString(regenerateOptions));
12317 return characterClassItem;
12318};
12319
12320var processTerm = function (item, regenerateOptions) {
12321 switch (item.type) {
12322 case 'dot':
12323 update(
12324 item,
12325 getDotSet(config.unicode, config.dotAll).toString(regenerateOptions)
12326 );
12327 break;
12328 case 'characterClass':
12329 item = processCharacterClass(item, regenerateOptions);
12330 break;
12331 case 'unicodePropertyEscape':
12332 update(
12333 item,
12334 getUnicodePropertyEscapeSet(item.value, item.negative)
12335 .toString(regenerateOptions)
12336 );
12337 break;
12338 case 'characterClassEscape':
12339 update(
12340 item,
12341 getCharacterClassEscapeSet(
12342 item.value,
12343 config.unicode,
12344 config.ignoreCase
12345 ).toString(regenerateOptions)
12346 );
12347 break;
12348 case 'alternative':
12349 case 'disjunction':
12350 case 'group':
12351 case 'quantifier':
12352 item.body = item.body.map(function ( term ) {
12353 return processTerm(term, regenerateOptions);
12354 });
12355 break;
12356 case 'value':
12357 var codePoint = item.codePoint;
12358 var set = regenerate(codePoint);
12359 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
12360 var folded = caseFold(codePoint);
12361 if (folded) {
12362 set.add(folded);
12363 }
12364 }
12365 update(item, set.toString(regenerateOptions));
12366 break;
12367 case 'anchor':
12368 case 'empty':
12369 case 'group':
12370 case 'reference':
12371 // Nothing to do here.
12372 break;
12373 // The `default` clause is only here as a safeguard; it should never be
12374 // reached. Code coverage tools should ignore it.
12375 /* istanbul ignore next */
12376 default:
12377 throw new Error(("Unknown term type: " + (item.type)));
12378 }
12379 return item;
12380};
12381
12382var config = {
12383 'ignoreCase': false,
12384 'unicode': false,
12385 'dotAll': false,
12386 'useUnicodeFlag': false
12387};
12388var rewritePattern = function (pattern, flags, options) {
12389 var regjsparserFeatures = {
12390 'unicodePropertyEscape': options && options.unicodePropertyEscape
12391 };
12392 config.ignoreCase = flags && flags.includes('i');
12393 config.unicode = flags && flags.includes('u');
12394 var supportDotAllFlag = options && options.dotAllFlag;
12395 config.dotAll = supportDotAllFlag && flags && flags.includes('s');
12396 config.useUnicodeFlag = options && options.useUnicodeFlag;
12397 var regenerateOptions = {
12398 'hasUnicodeFlag': config.useUnicodeFlag,
12399 'bmpOnly': !config.unicode
12400 };
12401 var tree = parse(pattern, flags, regjsparserFeatures);
12402 // Note: `processTerm` mutates `tree`.
12403 processTerm(tree, regenerateOptions);
12404 return generate(tree);
12405};
12406
12407module.exports = rewritePattern;
12408});
12409
12410var Literal = (function (Node) {
12411 function Literal () {
12412 Node.apply(this, arguments);
12413 }
12414
12415 if ( Node ) Literal.__proto__ = Node;
12416 Literal.prototype = Object.create( Node && Node.prototype );
12417 Literal.prototype.constructor = Literal;
12418
12419 Literal.prototype.initialise = function initialise () {
12420 if ( typeof this.value === 'string' ) {
12421 this.program.indentExclusionElements.push( this );
12422 }
12423 };
12424
12425 Literal.prototype.transpile = function transpile ( code, transforms ) {
12426 if ( transforms.numericLiteral ) {
12427 var leading = this.raw.slice( 0, 2 );
12428 if ( leading === '0b' || leading === '0o' ) {
12429 code.overwrite( this.start, this.end, String( this.value ), {
12430 storeName: true,
12431 contentOnly: true
12432 });
12433 }
12434 }
12435
12436 if ( this.regex ) {
12437 var ref = this.regex;
12438 var pattern = ref.pattern;
12439 var flags = ref.flags;
12440
12441 if ( transforms.stickyRegExp && /y/.test( flags ) ) throw new CompileError$1( 'Regular expression sticky flag is not supported', this );
12442 if ( transforms.unicodeRegExp && /u/.test( flags ) ) {
12443 code.overwrite( this.start, this.end, ("/" + (rewritePattern_1( pattern, flags )) + "/" + (flags.replace( 'u', '' ))), {
12444 contentOnly: true
12445 });
12446 }
12447 }
12448 };
12449
12450 return Literal;
12451}(Node$1));
12452
12453var MemberExpression = (function (Node) {
12454 function MemberExpression () {
12455 Node.apply(this, arguments);
12456 }
12457
12458 if ( Node ) MemberExpression.__proto__ = Node;
12459 MemberExpression.prototype = Object.create( Node && Node.prototype );
12460 MemberExpression.prototype.constructor = MemberExpression;
12461
12462 MemberExpression.prototype.transpile = function transpile ( code, transforms ) {
12463 if ( transforms.reservedProperties && reserved[ this.property.name ] ) {
12464 code.overwrite( this.object.end, this.property.start, "['" );
12465 code.appendLeft( this.property.end, "']" );
12466 }
12467
12468 Node.prototype.transpile.call( this, code, transforms );
12469 };
12470
12471 return MemberExpression;
12472}(Node$1));
12473
12474var NewExpression = (function (Node) {
12475 function NewExpression () {
12476 Node.apply(this, arguments);
12477 }
12478
12479 if ( Node ) NewExpression.__proto__ = Node;
12480 NewExpression.prototype = Object.create( Node && Node.prototype );
12481 NewExpression.prototype.constructor = NewExpression;
12482
12483 NewExpression.prototype.initialise = function initialise ( transforms ) {
12484 var this$1 = this;
12485
12486 if ( transforms.spreadRest && this.arguments.length ) {
12487 var lexicalBoundary = this.findLexicalBoundary();
12488
12489 var i = this.arguments.length;
12490 while ( i-- ) {
12491 var arg = this$1.arguments[i];
12492 if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
12493 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
12494 break;
12495 }
12496 }
12497 }
12498
12499 Node.prototype.initialise.call( this, transforms );
12500 };
12501
12502 NewExpression.prototype.transpile = function transpile ( code, transforms ) {
12503 if ( transforms.spreadRest && this.arguments.length ) {
12504 var firstArgument = this.arguments[0];
12505 var isNew = true;
12506 var hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias, isNew );
12507
12508 if ( hasSpreadElements ) {
12509 code.prependRight( this.start + 'new'.length, ' (Function.prototype.bind.apply(' );
12510 code.overwrite( this.callee.end, firstArgument.start, ', [ null ].concat( ' );
12511 code.appendLeft( this.end, ' ))' );
12512 }
12513 }
12514
12515 Node.prototype.transpile.call( this, code, transforms );
12516 };
12517
12518 return NewExpression;
12519}(Node$1));
12520
12521var ObjectExpression = (function (Node) {
12522 function ObjectExpression () {
12523 Node.apply(this, arguments);
12524 }
12525
12526 if ( Node ) ObjectExpression.__proto__ = Node;
12527 ObjectExpression.prototype = Object.create( Node && Node.prototype );
12528 ObjectExpression.prototype.constructor = ObjectExpression;
12529
12530 ObjectExpression.prototype.transpile = function transpile ( code, transforms ) {
12531 var this$1 = this;
12532
12533 Node.prototype.transpile.call( this, code, transforms );
12534
12535 var firstPropertyStart = this.start + 1;
12536 var regularPropertyCount = 0;
12537 var spreadPropertyCount = 0;
12538 var computedPropertyCount = 0;
12539
12540 for ( var i$2 = 0, list = this.properties; i$2 < list.length; i$2 += 1 ) {
12541 var prop = list[i$2];
12542
12543 if ( prop.type === 'SpreadElement' ) {
12544 spreadPropertyCount += 1;
12545 } else if ( prop.computed ) {
12546 computedPropertyCount += 1;
12547 } else if ( prop.type === 'Property' ) {
12548 regularPropertyCount += 1;
12549 }
12550 }
12551
12552 if ( spreadPropertyCount ) {
12553 if ( !this.program.options.objectAssign ) {
12554 throw new CompileError$1( 'Object spread operator requires specified objectAssign option with \'Object.assign\' or polyfill helper.', this );
12555 }
12556 // enclose run of non-spread properties in curlies
12557 var i = this.properties.length;
12558 if ( regularPropertyCount ) {
12559 while ( i-- ) {
12560 var prop$1 = this$1.properties[i];
12561
12562 if ( prop$1.type === 'Property' && !prop$1.computed ) {
12563 var lastProp = this$1.properties[ i - 1 ];
12564 var nextProp = this$1.properties[ i + 1 ];
12565
12566 if ( !lastProp || lastProp.type !== 'Property' || lastProp.computed ) {
12567 code.prependRight( prop$1.start, '{' );
12568 }
12569
12570 if ( !nextProp || nextProp.type !== 'Property' || nextProp.computed ) {
12571 code.appendLeft( prop$1.end, '}' );
12572 }
12573 }
12574 }
12575 }
12576
12577 // wrap the whole thing in Object.assign
12578 firstPropertyStart = this.properties[0].start;
12579 code.overwrite( this.start, firstPropertyStart, ((this.program.options.objectAssign) + "({}, "));
12580 code.overwrite( this.properties[ this.properties.length - 1 ].end, this.end, ')' );
12581 }
12582
12583 if ( computedPropertyCount && transforms.computedProperty ) {
12584 var i0 = this.getIndentation();
12585
12586 var isSimpleAssignment;
12587 var name;
12588
12589 if ( this.parent.type === 'VariableDeclarator' && this.parent.parent.declarations.length === 1 ) {
12590 isSimpleAssignment = true;
12591 name = this.parent.id.alias || this.parent.id.name; // TODO is this right?
12592 } else if ( this.parent.type === 'AssignmentExpression' && this.parent.parent.type === 'ExpressionStatement' && this.parent.left.type === 'Identifier' ) {
12593 isSimpleAssignment = true;
12594 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
12595 } else if ( this.parent.type === 'AssignmentPattern' && this.parent.left.type === 'Identifier' ) {
12596 isSimpleAssignment = true;
12597 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
12598 }
12599
12600 // handle block scoping
12601 var declaration = this.findScope( false ).findDeclaration( name );
12602 if ( declaration ) name = declaration.name;
12603
12604 var start = firstPropertyStart;
12605 var end = this.end;
12606
12607 if ( isSimpleAssignment ) {
12608 // ???
12609 } else {
12610 name = this.findScope( true ).createIdentifier( 'obj' );
12611
12612 var statement = this.findNearest( /(?:Statement|Declaration)$/ );
12613 code.appendLeft( statement.end, ("\n" + i0 + "var " + name + ";") );
12614
12615 code.prependRight( this.start, ("( " + name + " = ") );
12616 }
12617
12618 var len = this.properties.length;
12619 var lastComputedProp;
12620 var sawNonComputedProperty = false;
12621
12622 for ( var i$1 = 0; i$1 < len; i$1 += 1 ) {
12623 var prop$2 = this$1.properties[i$1];
12624
12625 if ( prop$2.computed ) {
12626 lastComputedProp = prop$2;
12627 var moveStart = i$1 > 0 ? this$1.properties[ i$1 - 1 ].end : start;
12628
12629 var propId = isSimpleAssignment ? (";\n" + i0 + name) : (", " + name);
12630
12631 if (moveStart < prop$2.start) {
12632 code.overwrite( moveStart, prop$2.start, propId );
12633 } else {
12634 code.prependRight( prop$2.start, propId );
12635 }
12636
12637 var c = prop$2.key.end;
12638 while ( code.original[c] !== ']' ) c += 1;
12639 c += 1;
12640
12641 if ( prop$2.value.start > c ) code.remove( c, prop$2.value.start );
12642 code.appendLeft( c, ' = ' );
12643 code.move( moveStart, prop$2.end, end );
12644
12645 if ( i$1 < len - 1 && ! sawNonComputedProperty ) {
12646 // remove trailing comma
12647 c = prop$2.end;
12648 while ( code.original[c] !== ',' ) c += 1;
12649
12650 code.remove( prop$2.end, c + 1 );
12651 }
12652
12653 if ( prop$2.method && transforms.conciseMethodProperty ) {
12654 code.prependRight( prop$2.value.start, 'function ' );
12655 }
12656 } else {
12657 sawNonComputedProperty = true;
12658 }
12659 }
12660
12661 // special case
12662 if ( computedPropertyCount === len ) {
12663 code.remove( this.properties[ len - 1 ].end, this.end - 1 );
12664 }
12665
12666 if ( !isSimpleAssignment ) {
12667 code.appendLeft( lastComputedProp.end, (", " + name + " )") );
12668 }
12669 }
12670 };
12671
12672 return ObjectExpression;
12673}(Node$1));
12674
12675var Property = (function (Node) {
12676 function Property () {
12677 Node.apply(this, arguments);
12678 }
12679
12680 if ( Node ) Property.__proto__ = Node;
12681 Property.prototype = Object.create( Node && Node.prototype );
12682 Property.prototype.constructor = Property;
12683
12684 Property.prototype.transpile = function transpile ( code, transforms ) {
12685 Node.prototype.transpile.call( this, code, transforms );
12686
12687 if ( transforms.conciseMethodProperty && !this.computed && this.parent.type !== 'ObjectPattern' ) {
12688 if ( this.shorthand ) {
12689 code.prependRight( this.start, ((this.key.name) + ": ") );
12690 } else if ( this.method ) {
12691 var name = '';
12692 if ( this.program.options.namedFunctionExpressions !== false ) {
12693 if ( this.key.type === 'Literal' && typeof this.key.value === 'number' ) {
12694 name = "";
12695 } else if ( this.key.type === 'Identifier' ) {
12696 if ( reserved[ this.key.name ] ||
12697 ! /^[a-z_$][a-z0-9_$]*$/i.test( this.key.name ) ||
12698 this.value.body.scope.references[this.key.name] ) {
12699 name = this.findScope( true ).createIdentifier( this.key.name );
12700 } else {
12701 name = this.key.name;
12702 }
12703 } else {
12704 name = this.findScope( true ).createIdentifier( this.key.value );
12705 }
12706 name = ' ' + name;
12707 }
12708
12709 if ( this.value.generator ) code.remove( this.start, this.key.start );
12710 code.appendLeft( this.key.end, (": function" + (this.value.generator ? '*' : '') + name) );
12711 }
12712 }
12713
12714 if ( transforms.reservedProperties && reserved[ this.key.name ] ) {
12715 code.prependRight( this.key.start, "'" );
12716 code.appendLeft( this.key.end, "'" );
12717 }
12718 };
12719
12720 return Property;
12721}(Node$1));
12722
12723var ReturnStatement = (function (Node) {
12724 function ReturnStatement () {
12725 Node.apply(this, arguments);
12726 }
12727
12728 if ( Node ) ReturnStatement.__proto__ = Node;
12729 ReturnStatement.prototype = Object.create( Node && Node.prototype );
12730 ReturnStatement.prototype.constructor = ReturnStatement;
12731
12732 ReturnStatement.prototype.initialise = function initialise ( transforms ) {
12733 this.loop = this.findNearest( loopStatement );
12734 this.nearestFunction = this.findNearest( /Function/ );
12735
12736 if ( this.loop && ( !this.nearestFunction || this.loop.depth > this.nearestFunction.depth ) ) {
12737 this.loop.canReturn = true;
12738 this.shouldWrap = true;
12739 }
12740
12741 if ( this.argument ) this.argument.initialise( transforms );
12742 };
12743
12744 ReturnStatement.prototype.transpile = function transpile ( code, transforms ) {
12745 var shouldWrap = this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;
12746
12747 if ( this.argument ) {
12748 if ( shouldWrap ) code.prependRight( this.argument.start, "{ v: " );
12749 this.argument.transpile( code, transforms );
12750 if ( shouldWrap ) code.appendLeft( this.argument.end, " }" );
12751 } else if ( shouldWrap ) {
12752 code.appendLeft( this.start + 6, ' {}' );
12753 }
12754 };
12755
12756 return ReturnStatement;
12757}(Node$1));
12758
12759var SpreadElement = (function (Node) {
12760 function SpreadElement () {
12761 Node.apply(this, arguments);
12762 }
12763
12764 if ( Node ) SpreadElement.__proto__ = Node;
12765 SpreadElement.prototype = Object.create( Node && Node.prototype );
12766 SpreadElement.prototype.constructor = SpreadElement;
12767
12768 SpreadElement.prototype.transpile = function transpile ( code, transforms ) {
12769 if (this.parent.type == "ObjectExpression") {
12770 code.remove( this.start, this.argument.start );
12771 code.remove( this.argument.end, this.end );
12772 }
12773
12774 Node.prototype.transpile.call( this, code, transforms );
12775 };
12776
12777 return SpreadElement;
12778}(Node$1));
12779
12780var Super = (function (Node) {
12781 function Super () {
12782 Node.apply(this, arguments);
12783 }
12784
12785 if ( Node ) Super.__proto__ = Node;
12786 Super.prototype = Object.create( Node && Node.prototype );
12787 Super.prototype.constructor = Super;
12788
12789 Super.prototype.initialise = function initialise ( transforms ) {
12790 if ( transforms.classes ) {
12791 this.method = this.findNearest( 'MethodDefinition' );
12792 if ( !this.method ) throw new CompileError$1( this, 'use of super outside class method' );
12793
12794 var parentClass = this.findNearest( 'ClassBody' ).parent;
12795 this.superClassName = parentClass.superClass && (parentClass.superClass.name || 'superclass');
12796
12797 if ( !this.superClassName ) throw new CompileError$1( 'super used in base class', this );
12798
12799 this.isCalled = this.parent.type === 'CallExpression' && this === this.parent.callee;
12800
12801 if ( this.method.kind !== 'constructor' && this.isCalled ) {
12802 throw new CompileError$1( 'super() not allowed outside class constructor', this );
12803 }
12804
12805 this.isMember = this.parent.type === 'MemberExpression';
12806
12807 if ( !this.isCalled && !this.isMember ) {
12808 throw new CompileError$1( 'Unexpected use of `super` (expected `super(...)` or `super.*`)', this );
12809 }
12810 }
12811
12812 if ( transforms.arrow ) {
12813 var lexicalBoundary = this.findLexicalBoundary();
12814 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
12815 var loop = this.findNearest( loopStatement );
12816
12817 if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
12818 this.thisAlias = lexicalBoundary.getThisAlias();
12819 }
12820
12821 if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
12822 this.thisAlias = lexicalBoundary.getThisAlias();
12823 }
12824 }
12825 };
12826
12827 Super.prototype.transpile = function transpile ( code, transforms ) {
12828 if ( transforms.classes ) {
12829 var expression = ( this.isCalled || this.method.static ) ?
12830 this.superClassName :
12831 ((this.superClassName) + ".prototype");
12832
12833 code.overwrite( this.start, this.end, expression, { storeName: true, contentOnly: true });
12834
12835 var callExpression = this.isCalled ? this.parent : this.parent.parent;
12836
12837 if ( callExpression && callExpression.type === 'CallExpression' ) {
12838 if ( !this.noCall ) { // special case – `super( ...args )`
12839 code.appendLeft( callExpression.callee.end, '.call' );
12840 }
12841
12842 var thisAlias = this.thisAlias || 'this';
12843
12844 if ( callExpression.arguments.length ) {
12845 code.appendLeft( callExpression.arguments[0].start, (thisAlias + ", ") );
12846 } else {
12847 code.appendLeft( callExpression.end - 1, ("" + thisAlias) );
12848 }
12849 }
12850 }
12851 };
12852
12853 return Super;
12854}(Node$1));
12855
12856var TaggedTemplateExpression = (function (Node) {
12857 function TaggedTemplateExpression () {
12858 Node.apply(this, arguments);
12859 }
12860
12861 if ( Node ) TaggedTemplateExpression.__proto__ = Node;
12862 TaggedTemplateExpression.prototype = Object.create( Node && Node.prototype );
12863 TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
12864
12865 TaggedTemplateExpression.prototype.initialise = function initialise ( transforms ) {
12866 if ( transforms.templateString && !transforms.dangerousTaggedTemplateString ) {
12867 throw new CompileError$1( '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', this );
12868 }
12869
12870 Node.prototype.initialise.call( this, transforms );
12871 };
12872
12873 TaggedTemplateExpression.prototype.transpile = function transpile ( code, transforms ) {
12874 if ( transforms.templateString && transforms.dangerousTaggedTemplateString ) {
12875 var ordered = this.quasi.expressions.concat( this.quasi.quasis ).sort( function ( a, b ) { return a.start - b.start; } );
12876
12877 // insert strings at start
12878 var templateStrings = this.quasi.quasis.map( function ( quasi ) { return JSON.stringify( quasi.value.cooked ); } );
12879 code.overwrite( this.tag.end, ordered[0].start, ("([" + (templateStrings.join(', ')) + "]") );
12880
12881 var lastIndex = ordered[0].start;
12882 ordered.forEach( function ( node ) {
12883 if ( node.type === 'TemplateElement' ) {
12884 code.remove( lastIndex, node.end );
12885 } else {
12886 code.overwrite( lastIndex, node.start, ', ' );
12887 }
12888
12889 lastIndex = node.end;
12890 });
12891
12892 code.overwrite( lastIndex, this.end, ')' );
12893 }
12894
12895 Node.prototype.transpile.call( this, code, transforms );
12896 };
12897
12898 return TaggedTemplateExpression;
12899}(Node$1));
12900
12901var TemplateElement = (function (Node) {
12902 function TemplateElement () {
12903 Node.apply(this, arguments);
12904 }
12905
12906 if ( Node ) TemplateElement.__proto__ = Node;
12907 TemplateElement.prototype = Object.create( Node && Node.prototype );
12908 TemplateElement.prototype.constructor = TemplateElement;
12909
12910 TemplateElement.prototype.initialise = function initialise () {
12911 this.program.indentExclusionElements.push( this );
12912 };
12913
12914 return TemplateElement;
12915}(Node$1));
12916
12917var TemplateLiteral = (function (Node) {
12918 function TemplateLiteral () {
12919 Node.apply(this, arguments);
12920 }
12921
12922 if ( Node ) TemplateLiteral.__proto__ = Node;
12923 TemplateLiteral.prototype = Object.create( Node && Node.prototype );
12924 TemplateLiteral.prototype.constructor = TemplateLiteral;
12925
12926 TemplateLiteral.prototype.transpile = function transpile ( code, transforms ) {
12927 if ( transforms.templateString && this.parent.type !== 'TaggedTemplateExpression' ) {
12928 var ordered = this.expressions.concat( this.quasis )
12929 .sort( function ( a, b ) { return a.start - b.start || a.end - b.end; } )
12930 .filter( function ( node, i ) {
12931 // include all expressions
12932 if ( node.type !== 'TemplateElement' ) return true;
12933
12934 // include all non-empty strings
12935 if ( node.value.raw ) return true;
12936
12937 // exclude all empty strings not at the head
12938 return !i;
12939 });
12940
12941 // special case – we may be able to skip the first element,
12942 // if it's the empty string, but only if the second and
12943 // third elements aren't both expressions (since they maybe
12944 // be numeric, and `1 + 2 + '3' === '33'`)
12945 if ( ordered.length >= 3 ) {
12946 var first = ordered[0];
12947 var third = ordered[2];
12948 if ( first.type === 'TemplateElement' && first.value.raw === '' && third.type === 'TemplateElement' ) {
12949 ordered.shift();
12950 }
12951 }
12952
12953 var parenthesise = ( this.quasis.length !== 1 || this.expressions.length !== 0 ) &&
12954 this.parent.type !== 'AssignmentExpression' &&
12955 this.parent.type !== 'AssignmentPattern' &&
12956 this.parent.type !== 'VariableDeclarator' &&
12957 ( this.parent.type !== 'BinaryExpression' || this.parent.operator !== '+' );
12958
12959 if ( parenthesise ) code.appendRight( this.start, '(' );
12960
12961 var lastIndex = this.start;
12962
12963 ordered.forEach( function ( node, i ) {
12964 var prefix = i === 0 ?
12965 parenthesise ? '(' : '' :
12966 ' + ';
12967
12968 if ( node.type === 'TemplateElement' ) {
12969 code.overwrite( lastIndex, node.end, prefix + JSON.stringify( node.value.cooked ) );
12970 } else {
12971 var parenthesise$1 = node.type !== 'Identifier'; // TODO other cases where it's safe
12972
12973 if ( parenthesise$1 ) prefix += '(';
12974
12975 code.remove( lastIndex, node.start );
12976
12977 if ( prefix ) code.prependRight( node.start, prefix );
12978 if ( parenthesise$1 ) code.appendLeft( node.end, ')' );
12979 }
12980
12981 lastIndex = node.end;
12982 });
12983
12984 if ( parenthesise ) code.appendLeft( lastIndex, ')' );
12985 code.remove( lastIndex, this.end );
12986 }
12987
12988 Node.prototype.transpile.call( this, code, transforms );
12989 };
12990
12991 return TemplateLiteral;
12992}(Node$1));
12993
12994var ThisExpression = (function (Node) {
12995 function ThisExpression () {
12996 Node.apply(this, arguments);
12997 }
12998
12999 if ( Node ) ThisExpression.__proto__ = Node;
13000 ThisExpression.prototype = Object.create( Node && Node.prototype );
13001 ThisExpression.prototype.constructor = ThisExpression;
13002
13003 ThisExpression.prototype.initialise = function initialise ( transforms ) {
13004 if ( transforms.arrow ) {
13005 var lexicalBoundary = this.findLexicalBoundary();
13006 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
13007 var loop = this.findNearest( loopStatement );
13008
13009 if ( ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth )
13010 || ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth )
13011 || ( loop && loop.right && loop.right.contains( this ) ) ) {
13012 this.alias = lexicalBoundary.getThisAlias();
13013 }
13014 }
13015 };
13016
13017 ThisExpression.prototype.transpile = function transpile ( code ) {
13018 if ( this.alias ) {
13019 code.overwrite( this.start, this.end, this.alias, {
13020 storeName: true,
13021 contentOnly: true
13022 });
13023 }
13024 };
13025
13026 return ThisExpression;
13027}(Node$1));
13028
13029var UpdateExpression = (function (Node) {
13030 function UpdateExpression () {
13031 Node.apply(this, arguments);
13032 }
13033
13034 if ( Node ) UpdateExpression.__proto__ = Node;
13035 UpdateExpression.prototype = Object.create( Node && Node.prototype );
13036 UpdateExpression.prototype.constructor = UpdateExpression;
13037
13038 UpdateExpression.prototype.initialise = function initialise ( transforms ) {
13039 if ( this.argument.type === 'Identifier' ) {
13040 var declaration = this.findScope( false ).findDeclaration( this.argument.name );
13041 if ( declaration && declaration.kind === 'const' ) {
13042 throw new CompileError$1( ((this.argument.name) + " is read-only"), this );
13043 }
13044
13045 // special case – https://gitlab.com/Rich-Harris/buble/issues/150
13046 var statement = declaration && declaration.node.ancestor( 3 );
13047 if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
13048 statement.reassigned[ this.argument.name ] = true;
13049 }
13050 }
13051
13052 Node.prototype.initialise.call( this, transforms );
13053 };
13054
13055 return UpdateExpression;
13056}(Node$1));
13057
13058var VariableDeclaration = (function (Node) {
13059 function VariableDeclaration () {
13060 Node.apply(this, arguments);
13061 }
13062
13063 if ( Node ) VariableDeclaration.__proto__ = Node;
13064 VariableDeclaration.prototype = Object.create( Node && Node.prototype );
13065 VariableDeclaration.prototype.constructor = VariableDeclaration;
13066
13067 VariableDeclaration.prototype.initialise = function initialise ( transforms ) {
13068 this.scope = this.findScope( this.kind === 'var' );
13069 this.declarations.forEach( function ( declarator ) { return declarator.initialise( transforms ); } );
13070 };
13071
13072 VariableDeclaration.prototype.transpile = function transpile ( code, transforms ) {
13073 var this$1 = this;
13074
13075 var i0 = this.getIndentation();
13076 var kind = this.kind;
13077
13078 if ( transforms.letConst && kind !== 'var' ) {
13079 kind = 'var';
13080 code.overwrite( this.start, this.start + this.kind.length, kind, { storeName: true });
13081 }
13082
13083 if ( transforms.destructuring && this.parent.type !== 'ForOfStatement' ) {
13084 var c = this.start;
13085 var lastDeclaratorIsPattern;
13086
13087 this.declarations.forEach( function ( declarator, i ) {
13088 declarator.transpile( code, transforms );
13089
13090 if ( declarator.id.type === 'Identifier' ) {
13091 if ( i > 0 && this$1.declarations[ i - 1 ].id.type !== 'Identifier' ) {
13092 code.overwrite( c, declarator.id.start, "var " );
13093 }
13094 } else {
13095 var inline = loopStatement.test( this$1.parent.type );
13096
13097 if ( i === 0 ) {
13098 code.remove( c, declarator.id.start );
13099 } else {
13100 code.overwrite( c, declarator.id.start, (";\n" + i0) );
13101 }
13102
13103 var simple = declarator.init.type === 'Identifier' && !declarator.init.rewritten;
13104
13105 var name = simple ? declarator.init.name : declarator.findScope( true ).createIdentifier( 'ref' );
13106
13107 var statementGenerators = [];
13108
13109 if ( simple ) {
13110 code.remove( declarator.id.end, declarator.end );
13111 } else {
13112 statementGenerators.push( function ( start, prefix, suffix ) {
13113 code.prependRight( declarator.id.end, ("var " + name) );
13114 code.appendLeft( declarator.init.end, ("" + suffix) );
13115 code.move( declarator.id.end, declarator.end, start );
13116 });
13117 }
13118
13119 destructure( code, declarator.findScope( false ), declarator.id, name, inline, statementGenerators );
13120
13121 var prefix = inline ? 'var ' : '';
13122 var suffix = inline ? ", " : (";\n" + i0);
13123 statementGenerators.forEach( function ( fn, j ) {
13124 if ( i === this$1.declarations.length - 1 && j === statementGenerators.length - 1 ) {
13125 suffix = inline ? '' : ';';
13126 }
13127
13128 fn( declarator.start, j === 0 ? prefix : '', suffix );
13129 });
13130 }
13131
13132 c = declarator.end;
13133 lastDeclaratorIsPattern = declarator.id.type !== 'Identifier';
13134 });
13135
13136 if ( lastDeclaratorIsPattern && this.end > c ) {
13137 code.overwrite( c, this.end, '', { contentOnly: true });
13138 }
13139 }
13140
13141 else {
13142 this.declarations.forEach( function ( declarator ) {
13143 declarator.transpile( code, transforms );
13144 });
13145 }
13146 };
13147
13148 return VariableDeclaration;
13149}(Node$1));
13150
13151var VariableDeclarator = (function (Node) {
13152 function VariableDeclarator () {
13153 Node.apply(this, arguments);
13154 }
13155
13156 if ( Node ) VariableDeclarator.__proto__ = Node;
13157 VariableDeclarator.prototype = Object.create( Node && Node.prototype );
13158 VariableDeclarator.prototype.constructor = VariableDeclarator;
13159
13160 VariableDeclarator.prototype.initialise = function initialise ( transforms ) {
13161 var kind = this.parent.kind;
13162 if ( kind === 'let' && this.parent.parent.type === 'ForStatement' ) {
13163 kind = 'for.let'; // special case...
13164 }
13165
13166 this.parent.scope.addDeclaration( this.id, kind );
13167 Node.prototype.initialise.call( this, transforms );
13168 };
13169
13170 VariableDeclarator.prototype.transpile = function transpile ( code, transforms ) {
13171 if ( !this.init && transforms.letConst && this.parent.kind !== 'var' ) {
13172 var inLoop = this.findNearest( /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/ );
13173 if ( inLoop && ! /Function/.test( inLoop.type ) && ! this.isLeftDeclaratorOfLoop() ) {
13174 code.appendLeft( this.id.end, ' = (void 0)' );
13175 }
13176 }
13177
13178 if ( this.id ) this.id.transpile( code, transforms );
13179 if ( this.init ) this.init.transpile( code, transforms );
13180 };
13181
13182 VariableDeclarator.prototype.isLeftDeclaratorOfLoop = function isLeftDeclaratorOfLoop () {
13183 return this.parent
13184 && this.parent.type === 'VariableDeclaration'
13185 && this.parent.parent
13186 && (this.parent.parent.type === 'ForInStatement'
13187 || this.parent.parent.type === 'ForOfStatement')
13188 && this.parent.parent.left
13189 && this.parent.parent.left.declarations[0] === this;
13190 };
13191
13192 return VariableDeclarator;
13193}(Node$1));
13194
13195var types$1$1 = {
13196 ArrayExpression: ArrayExpression,
13197 ArrowFunctionExpression: ArrowFunctionExpression,
13198 AssignmentExpression: AssignmentExpression,
13199 BinaryExpression: BinaryExpression,
13200 BreakStatement: BreakStatement,
13201 CallExpression: CallExpression,
13202 ClassBody: ClassBody,
13203 ClassDeclaration: ClassDeclaration,
13204 ClassExpression: ClassExpression,
13205 ContinueStatement: ContinueStatement,
13206 DoWhileStatement: LoopStatement,
13207 ExportNamedDeclaration: ExportNamedDeclaration,
13208 ExportDefaultDeclaration: ExportDefaultDeclaration,
13209 ForStatement: ForStatement,
13210 ForInStatement: ForInStatement,
13211 ForOfStatement: ForOfStatement,
13212 FunctionDeclaration: FunctionDeclaration,
13213 FunctionExpression: FunctionExpression,
13214 Identifier: Identifier,
13215 IfStatement: IfStatement,
13216 ImportDeclaration: ImportDeclaration,
13217 ImportDefaultSpecifier: ImportDefaultSpecifier,
13218 ImportSpecifier: ImportSpecifier,
13219 JSXAttribute: JSXAttribute,
13220 JSXClosingElement: JSXClosingElement,
13221 JSXElement: JSXElement,
13222 JSXExpressionContainer: JSXExpressionContainer,
13223 JSXOpeningElement: JSXOpeningElement,
13224 JSXSpreadAttribute: JSXSpreadAttribute,
13225 Literal: Literal,
13226 MemberExpression: MemberExpression,
13227 NewExpression: NewExpression,
13228 ObjectExpression: ObjectExpression,
13229 Property: Property,
13230 ReturnStatement: ReturnStatement,
13231 SpreadElement: SpreadElement,
13232 Super: Super,
13233 TaggedTemplateExpression: TaggedTemplateExpression,
13234 TemplateElement: TemplateElement,
13235 TemplateLiteral: TemplateLiteral,
13236 ThisExpression: ThisExpression,
13237 UpdateExpression: UpdateExpression,
13238 VariableDeclaration: VariableDeclaration,
13239 VariableDeclarator: VariableDeclarator,
13240 WhileStatement: LoopStatement
13241};
13242
13243var statementsWithBlocks = {
13244 IfStatement: 'consequent',
13245 ForStatement: 'body',
13246 ForInStatement: 'body',
13247 ForOfStatement: 'body',
13248 WhileStatement: 'body',
13249 DoWhileStatement: 'body',
13250 ArrowFunctionExpression: 'body'
13251};
13252
13253function wrap ( raw, parent ) {
13254 if ( !raw ) return;
13255
13256 if ( 'length' in raw ) {
13257 var i = raw.length;
13258 while ( i-- ) wrap( raw[i], parent );
13259 return;
13260 }
13261
13262 // with e.g. shorthand properties, key and value are
13263 // the same node. We don't want to wrap an object twice
13264 if ( raw.__wrapped ) return;
13265 raw.__wrapped = true;
13266
13267 if ( !keys[ raw.type ] ) {
13268 keys[ raw.type ] = Object.keys( raw ).filter( function ( key ) { return typeof raw[ key ] === 'object'; } );
13269 }
13270
13271 // special case – body-less if/for/while statements. TODO others?
13272 var bodyType = statementsWithBlocks[ raw.type ];
13273 if ( bodyType && raw[ bodyType ].type !== 'BlockStatement' ) {
13274 var expression = raw[ bodyType ];
13275
13276 // create a synthetic block statement, otherwise all hell
13277 // breaks loose when it comes to block scoping
13278 raw[ bodyType ] = {
13279 start: expression.start,
13280 end: expression.end,
13281 type: 'BlockStatement',
13282 body: [ expression ],
13283 synthetic: true
13284 };
13285 }
13286
13287 new Node$1( raw, parent );
13288
13289 var type = ( raw.type === 'BlockStatement' ? BlockStatement : types$1$1[ raw.type ] ) || Node$1;
13290 raw.__proto__ = type.prototype;
13291}
13292
13293function Scope ( options ) {
13294 options = options || {};
13295
13296 this.parent = options.parent;
13297 this.isBlockScope = !!options.block;
13298
13299 var scope = this;
13300 while ( scope.isBlockScope ) scope = scope.parent;
13301 this.functionScope = scope;
13302
13303 this.identifiers = [];
13304 this.declarations = Object.create( null );
13305 this.references = Object.create( null );
13306 this.blockScopedDeclarations = this.isBlockScope ? null : Object.create( null );
13307 this.aliases = this.isBlockScope ? null : Object.create( null );
13308}
13309
13310Scope.prototype = {
13311 addDeclaration: function addDeclaration ( node, kind ) {
13312 for ( var i = 0, list = extractNames( node ); i < list.length; i += 1 ) {
13313 var identifier = list[i];
13314
13315 var name = identifier.name;
13316
13317 var declaration = { name: name, node: identifier, kind: kind, instances: [] };
13318 this.declarations[ name ] = declaration;
13319
13320 if ( this.isBlockScope ) {
13321 if ( !this.functionScope.blockScopedDeclarations[ name ] ) this.functionScope.blockScopedDeclarations[ name ] = [];
13322 this.functionScope.blockScopedDeclarations[ name ].push( declaration );
13323 }
13324 }
13325 },
13326
13327 addReference: function addReference ( identifier ) {
13328 if ( this.consolidated ) {
13329 this.consolidateReference( identifier );
13330 } else {
13331 this.identifiers.push( identifier );
13332 }
13333 },
13334
13335 consolidate: function consolidate () {
13336 var this$1 = this;
13337
13338 for ( var i = 0; i < this$1.identifiers.length; i += 1 ) { // we might push to the array during consolidation, so don't cache length
13339 var identifier = this$1.identifiers[i];
13340 this$1.consolidateReference( identifier );
13341 }
13342
13343 this.consolidated = true; // TODO understand why this is necessary... seems bad
13344 },
13345
13346 consolidateReference: function consolidateReference ( identifier ) {
13347 var declaration = this.declarations[ identifier.name ];
13348 if ( declaration ) {
13349 declaration.instances.push( identifier );
13350 } else {
13351 this.references[ identifier.name ] = true;
13352 if ( this.parent ) this.parent.addReference( identifier );
13353 }
13354 },
13355
13356 contains: function contains ( name ) {
13357 return this.declarations[ name ] ||
13358 ( this.parent ? this.parent.contains( name ) : false );
13359 },
13360
13361 createIdentifier: function createIdentifier ( base ) {
13362 var this$1 = this;
13363
13364 if ( typeof base === 'number' ) base = base.toString();
13365
13366 base = base
13367 .replace( /\s/g, '' )
13368 .replace( /\[([^\]]+)\]/g, '_$1' )
13369 .replace( /[^a-zA-Z0-9_$]/g, '_' )
13370 .replace( /_{2,}/, '_' );
13371
13372 var name = base;
13373 var counter = 1;
13374
13375 while ( this$1.declarations[ name ] || this$1.references[ name ] || this$1.aliases[ name ] || name in reserved ) {
13376 name = base + "$" + (counter++);
13377 }
13378
13379 this.aliases[ name ] = true;
13380 return name;
13381 },
13382
13383 findDeclaration: function findDeclaration ( name ) {
13384 return this.declarations[ name ] ||
13385 ( this.parent && this.parent.findDeclaration( name ) );
13386 }
13387};
13388
13389function isUseStrict ( node ) {
13390 if ( !node ) return false;
13391 if ( node.type !== 'ExpressionStatement' ) return false;
13392 if ( node.expression.type !== 'Literal' ) return false;
13393 return node.expression.value === 'use strict';
13394}
13395
13396var BlockStatement = (function (Node) {
13397 function BlockStatement () {
13398 Node.apply(this, arguments);
13399 }
13400
13401 if ( Node ) BlockStatement.__proto__ = Node;
13402 BlockStatement.prototype = Object.create( Node && Node.prototype );
13403 BlockStatement.prototype.constructor = BlockStatement;
13404
13405 BlockStatement.prototype.createScope = function createScope () {
13406 var this$1 = this;
13407
13408 this.parentIsFunction = /Function/.test( this.parent.type );
13409 this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root';
13410 this.scope = new Scope({
13411 block: !this.isFunctionBlock,
13412 parent: this.parent.findScope( false )
13413 });
13414
13415 if ( this.parentIsFunction ) {
13416 this.parent.params.forEach( function ( node ) {
13417 this$1.scope.addDeclaration( node, 'param' );
13418 });
13419 }
13420 };
13421
13422 BlockStatement.prototype.initialise = function initialise ( transforms ) {
13423 this.thisAlias = null;
13424 this.argumentsAlias = null;
13425 this.defaultParameters = [];
13426
13427 // normally the scope gets created here, during initialisation,
13428 // but in some cases (e.g. `for` statements), we need to create
13429 // the scope early, as it pertains to both the init block and
13430 // the body of the statement
13431 if ( !this.scope ) this.createScope();
13432
13433 this.body.forEach( function ( node ) { return node.initialise( transforms ); } );
13434
13435 this.scope.consolidate();
13436 };
13437
13438 BlockStatement.prototype.findLexicalBoundary = function findLexicalBoundary () {
13439 if ( this.type === 'Program' ) return this;
13440 if ( /^Function/.test( this.parent.type ) ) return this;
13441
13442 return this.parent.findLexicalBoundary();
13443 };
13444
13445 BlockStatement.prototype.findScope = function findScope ( functionScope ) {
13446 if ( functionScope && !this.isFunctionBlock ) return this.parent.findScope( functionScope );
13447 return this.scope;
13448 };
13449
13450 BlockStatement.prototype.getArgumentsAlias = function getArgumentsAlias () {
13451 if ( !this.argumentsAlias ) {
13452 this.argumentsAlias = this.scope.createIdentifier( 'arguments' );
13453 }
13454
13455 return this.argumentsAlias;
13456 };
13457
13458 BlockStatement.prototype.getArgumentsArrayAlias = function getArgumentsArrayAlias () {
13459 if ( !this.argumentsArrayAlias ) {
13460 this.argumentsArrayAlias = this.scope.createIdentifier( 'argsArray' );
13461 }
13462
13463 return this.argumentsArrayAlias;
13464 };
13465
13466 BlockStatement.prototype.getThisAlias = function getThisAlias () {
13467 if ( !this.thisAlias ) {
13468 this.thisAlias = this.scope.createIdentifier( 'this' );
13469 }
13470
13471 return this.thisAlias;
13472 };
13473
13474 BlockStatement.prototype.getIndentation = function getIndentation () {
13475 var this$1 = this;
13476
13477 if ( this.indentation === undefined ) {
13478 var source = this.program.magicString.original;
13479
13480 var useOuter = this.synthetic || !this.body.length;
13481 var c = useOuter ? this.start : this.body[0].start;
13482
13483 while ( c && source[c] !== '\n' ) c -= 1;
13484
13485 this.indentation = '';
13486
13487 while ( true ) { // eslint-disable-line no-constant-condition
13488 c += 1;
13489 var char = source[c];
13490
13491 if ( char !== ' ' && char !== '\t' ) break;
13492
13493 this$1.indentation += char;
13494 }
13495
13496 var indentString = this.program.magicString.getIndentString();
13497
13498 // account for dedented class constructors
13499 var parent = this.parent;
13500 while ( parent ) {
13501 if ( parent.kind === 'constructor' && !parent.parent.parent.superClass ) {
13502 this$1.indentation = this$1.indentation.replace( indentString, '' );
13503 }
13504
13505 parent = parent.parent;
13506 }
13507
13508 if ( useOuter ) this.indentation += indentString;
13509 }
13510
13511 return this.indentation;
13512 };
13513
13514 BlockStatement.prototype.transpile = function transpile ( code, transforms ) {
13515 var this$1 = this;
13516
13517 var indentation = this.getIndentation();
13518
13519 var introStatementGenerators = [];
13520
13521 if ( this.argumentsAlias ) {
13522 introStatementGenerators.push( function ( start, prefix, suffix ) {
13523 var assignment = prefix + "var " + (this$1.argumentsAlias) + " = arguments" + suffix;
13524 code.appendLeft( start, assignment );
13525 });
13526 }
13527
13528 if ( this.thisAlias ) {
13529 introStatementGenerators.push( function ( start, prefix, suffix ) {
13530 var assignment = prefix + "var " + (this$1.thisAlias) + " = this" + suffix;
13531 code.appendLeft( start, assignment );
13532 });
13533 }
13534
13535 if ( this.argumentsArrayAlias ) {
13536 introStatementGenerators.push( function ( start, prefix, suffix ) {
13537 var i = this$1.scope.createIdentifier( 'i' );
13538 var assignment = prefix + "var " + i + " = arguments.length, " + (this$1.argumentsArrayAlias) + " = Array(" + i + ");\n" + indentation + "while ( " + i + "-- ) " + (this$1.argumentsArrayAlias) + "[" + i + "] = arguments[" + i + "]" + suffix;
13539 code.appendLeft( start, assignment );
13540 });
13541 }
13542
13543 if ( /Function/.test( this.parent.type ) ) {
13544 this.transpileParameters( code, transforms, indentation, introStatementGenerators );
13545 }
13546
13547 if ( transforms.letConst && this.isFunctionBlock ) {
13548 this.transpileBlockScopedIdentifiers( code );
13549 }
13550
13551 Node.prototype.transpile.call( this, code, transforms );
13552
13553 if ( this.synthetic ) {
13554 if ( this.parent.type === 'ArrowFunctionExpression' ) {
13555 var expr = this.body[0];
13556
13557 if ( introStatementGenerators.length ) {
13558 code.appendLeft( this.start, "{" ).prependRight( this.end, ((this.parent.getIndentation()) + "}") );
13559
13560 code.prependRight( expr.start, ("\n" + indentation + "return ") );
13561 code.appendLeft( expr.end, ";\n" );
13562 } else if ( transforms.arrow ) {
13563 code.prependRight( expr.start, "{ return " );
13564 code.appendLeft( expr.end, "; }" );
13565 }
13566 }
13567
13568 else if ( introStatementGenerators.length ) {
13569 code.prependRight( this.start, "{" ).appendLeft( this.end, "}" );
13570 }
13571 }
13572
13573 var start;
13574 if ( isUseStrict( this.body[0] ) ) {
13575 start = this.body[0].end;
13576 } else if ( this.synthetic || this.parent.type === 'Root' ) {
13577 start = this.start;
13578 } else {
13579 start = this.start + 1;
13580 }
13581
13582 var prefix = "\n" + indentation;
13583 var suffix = ';';
13584 introStatementGenerators.forEach( function ( fn, i ) {
13585 if ( i === introStatementGenerators.length - 1 ) suffix = ";\n";
13586 fn( start, prefix, suffix );
13587 });
13588 };
13589
13590 BlockStatement.prototype.transpileParameters = function transpileParameters ( code, transforms, indentation, introStatementGenerators ) {
13591 var this$1 = this;
13592
13593 var params = this.parent.params;
13594
13595 params.forEach( function ( param ) {
13596 if ( param.type === 'AssignmentPattern' && param.left.type === 'Identifier' ) {
13597 if ( transforms.defaultParameter ) {
13598 introStatementGenerators.push( function ( start, prefix, suffix ) {
13599 var lhs = prefix + "if ( " + (param.left.name) + " === void 0 ) " + (param.left.name);
13600
13601 code
13602 .prependRight( param.left.end, lhs )
13603 .move( param.left.end, param.right.end, start )
13604 .appendLeft( param.right.end, suffix );
13605 });
13606 }
13607 }
13608
13609 else if ( param.type === 'RestElement' ) {
13610 if ( transforms.spreadRest ) {
13611 introStatementGenerators.push( function ( start, prefix, suffix ) {
13612 var penultimateParam = params[ params.length - 2 ];
13613
13614 if ( penultimateParam ) {
13615 code.remove( penultimateParam ? penultimateParam.end : param.start, param.end );
13616 } else {
13617 var start$1 = param.start, end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8
13618
13619 while ( /\s/.test( code.original[ start$1 - 1 ] ) ) start$1 -= 1;
13620 while ( /\s/.test( code.original[ end ] ) ) end += 1;
13621
13622 code.remove( start$1, end );
13623 }
13624
13625 var name = param.argument.name;
13626 var len = this$1.scope.createIdentifier( 'len' );
13627 var count = params.length - 1;
13628
13629 if ( count ) {
13630 code.prependRight( start, (prefix + "var " + name + " = [], " + len + " = arguments.length - " + count + ";\n" + indentation + "while ( " + len + "-- > 0 ) " + name + "[ " + len + " ] = arguments[ " + len + " + " + count + " ]" + suffix) );
13631 } else {
13632 code.prependRight( start, (prefix + "var " + name + " = [], " + len + " = arguments.length;\n" + indentation + "while ( " + len + "-- ) " + name + "[ " + len + " ] = arguments[ " + len + " ]" + suffix) );
13633 }
13634 });
13635 }
13636 }
13637
13638 else if ( param.type !== 'Identifier' ) {
13639 if ( transforms.parameterDestructuring ) {
13640 var ref = this$1.scope.createIdentifier( 'ref' );
13641 destructure( code, this$1.scope, param, ref, false, introStatementGenerators );
13642 code.prependRight( param.start, ref );
13643 }
13644 }
13645 });
13646 };
13647
13648 BlockStatement.prototype.transpileBlockScopedIdentifiers = function transpileBlockScopedIdentifiers ( code ) {
13649 var this$1 = this;
13650
13651 Object.keys( this.scope.blockScopedDeclarations ).forEach( function ( name ) {
13652 var declarations = this$1.scope.blockScopedDeclarations[ name ];
13653
13654 for ( var i = 0, list = declarations; i < list.length; i += 1 ) {
13655 var declaration = list[i];
13656
13657 var cont = false; // TODO implement proper continue...
13658
13659 if ( declaration.kind === 'for.let' ) {
13660 // special case
13661 var forStatement = declaration.node.findNearest( 'ForStatement' );
13662
13663 if ( forStatement.shouldRewriteAsFunction ) {
13664 var outerAlias = this$1.scope.createIdentifier( name );
13665 var innerAlias = forStatement.reassigned[ name ] ?
13666 this$1.scope.createIdentifier( name ) :
13667 name;
13668
13669 declaration.name = outerAlias;
13670 code.overwrite( declaration.node.start, declaration.node.end, outerAlias, { storeName: true });
13671
13672 forStatement.aliases[ name ] = {
13673 outer: outerAlias,
13674 inner: innerAlias
13675 };
13676
13677 for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
13678 var identifier = list$1[i$1];
13679
13680 var alias = forStatement.body.contains( identifier ) ?
13681 innerAlias :
13682 outerAlias;
13683
13684 if ( name !== alias ) {
13685 code.overwrite( identifier.start, identifier.end, alias, { storeName: true });
13686 }
13687 }
13688
13689 cont = true;
13690 }
13691 }
13692
13693 if ( !cont ) {
13694 var alias$1 = this$1.scope.createIdentifier( name );
13695
13696 if ( name !== alias$1 ) {
13697 declaration.name = alias$1;
13698 code.overwrite( declaration.node.start, declaration.node.end, alias$1, { storeName: true });
13699
13700 for ( var i$2 = 0, list$2 = declaration.instances; i$2 < list$2.length; i$2 += 1 ) {
13701 var identifier$1 = list$2[i$2];
13702
13703 identifier$1.rewritten = true;
13704 code.overwrite( identifier$1.start, identifier$1.end, alias$1, { storeName: true });
13705 }
13706 }
13707 }
13708 }
13709 });
13710 };
13711
13712 return BlockStatement;
13713}(Node$1));
13714
13715function Program ( source, ast, transforms, options ) {
13716 var this$1 = this;
13717
13718 this.type = 'Root';
13719
13720 // options
13721 this.jsx = options.jsx || 'React.createElement';
13722 this.options = options;
13723
13724 this.source = source;
13725 this.magicString = new MagicString$1( source );
13726
13727 this.ast = ast;
13728 this.depth = 0;
13729
13730 wrap( this.body = ast, this );
13731 this.body.__proto__ = BlockStatement.prototype;
13732
13733 this.indentExclusionElements = [];
13734 this.body.initialise( transforms );
13735
13736 this.indentExclusions = Object.create( null );
13737 for ( var i$1 = 0, list = this.indentExclusionElements; i$1 < list.length; i$1 += 1 ) {
13738 var node = list[i$1];
13739
13740 for ( var i = node.start; i < node.end; i += 1 ) {
13741 this$1.indentExclusions[ i ] = true;
13742 }
13743 }
13744
13745 this.body.transpile( this.magicString, transforms );
13746}
13747
13748Program.prototype = {
13749 export: function export$1 ( options ) {
13750 if ( options === void 0 ) options = {};
13751
13752 return {
13753 code: this.magicString.toString(),
13754 map: this.magicString.generateMap({
13755 file: options.file,
13756 source: options.source,
13757 includeContent: options.includeContent !== false
13758 })
13759 };
13760 },
13761
13762 findNearest: function findNearest () {
13763 return null;
13764 },
13765
13766 findScope: function findScope () {
13767 return null;
13768 }
13769};
13770
13771var matrix = {
13772 chrome: {
13773 48: 1333689725,
13774 49: 1342078975,
13775 50: 1610514431,
13776 51: 1610514431,
13777 52: 2147385343
13778 },
13779 firefox: {
13780 43: 1207307741,
13781 44: 1207307741,
13782 45: 1207307741,
13783 46: 1476267485,
13784 47: 1476296671,
13785 48: 1476296671
13786 },
13787 safari: {
13788 8: 1073741824,
13789 9: 1328940894
13790 },
13791 ie: {
13792 8: 0,
13793 9: 1073741824,
13794 10: 1073741824,
13795 11: 1073770592
13796 },
13797 edge: {
13798 12: 1591620701,
13799 13: 1608400479
13800 },
13801 node: {
13802 '0.10': 1075052608,
13803 '0.12': 1091830852,
13804 4: 1327398527,
13805 5: 1327398527,
13806 6: 1610514431
13807 }
13808};
13809
13810var features = [
13811 'arrow',
13812 'classes',
13813 'collections',
13814 'computedProperty',
13815 'conciseMethodProperty',
13816 'constLoop',
13817 'constRedef',
13818 'defaultParameter',
13819 'destructuring',
13820 'extendNatives',
13821 'forOf',
13822 'generator',
13823 'letConst',
13824 'letLoop',
13825 'letLoopScope',
13826 'moduleExport',
13827 'moduleImport',
13828 'numericLiteral',
13829 'objectProto',
13830 'objectSuper',
13831 'oldOctalLiteral',
13832 'parameterDestructuring',
13833 'spreadRest',
13834 'stickyRegExp',
13835 'symbol',
13836 'templateString',
13837 'unicodeEscape',
13838 'unicodeIdentifier',
13839 'unicodeRegExp',
13840
13841 // ES2016
13842 'exponentiation',
13843
13844 // additional transforms, not from
13845 // https://featuretests.io
13846 'reservedProperties'
13847];
13848
13849var version$1 = "0.17.0";
13850
13851var ref = [
13852 inject$1,
13853 inject
13854].reduce( function ( final, plugin ) { return plugin( final ); }, acorn );
13855var parse = ref.parse;
13856
13857var dangerousTransforms = [
13858 'dangerousTaggedTemplateString',
13859 'dangerousForOf'
13860];
13861
13862function target ( target ) {
13863 var targets = Object.keys( target );
13864 var bitmask = targets.length ?
13865 2147483647 :
13866 1073741824;
13867
13868 Object.keys( target ).forEach( function ( environment ) {
13869 var versions = matrix[ environment ];
13870 if ( !versions ) throw new Error( ("Unknown environment '" + environment + "'. Please raise an issue at https://gitlab.com/Rich-Harris/buble/issues") );
13871
13872 var targetVersion = target[ environment ];
13873 if ( !( targetVersion in versions ) ) throw new Error( ("Support data exists for the following versions of " + environment + ": " + (Object.keys( versions ).join( ', ')) + ". Please raise an issue at https://gitlab.com/Rich-Harris/buble/issues") );
13874 var support = versions[ targetVersion ];
13875
13876 bitmask &= support;
13877 });
13878
13879 var transforms = Object.create( null );
13880 features.forEach( function ( name, i ) {
13881 transforms[ name ] = !( bitmask & 1 << i );
13882 });
13883
13884 dangerousTransforms.forEach( function ( name ) {
13885 transforms[ name ] = false;
13886 });
13887
13888 return transforms;
13889}
13890
13891function transform ( source, options ) {
13892 if ( options === void 0 ) options = {};
13893
13894 var ast;
13895 var jsx = null;
13896
13897 try {
13898 ast = parse( source, {
13899 ecmaVersion: 8,
13900 preserveParens: true,
13901 sourceType: 'module',
13902 onComment: function (block, text) {
13903 if ( !jsx ) {
13904 var match = /@jsx\s+([^\s]+)/.exec( text );
13905 if ( match ) jsx = match[1];
13906 }
13907 },
13908 plugins: {
13909 jsx: true,
13910 objectSpread: true
13911 }
13912 });
13913 options.jsx = jsx || options.jsx;
13914 } catch ( err ) {
13915 err.snippet = getSnippet( source, err.loc );
13916 err.toString = function () { return ((err.name) + ": " + (err.message) + "\n" + (err.snippet)); };
13917 throw err;
13918 }
13919
13920 var transforms = target( options.target || {} );
13921 Object.keys( options.transforms || {} ).forEach( function ( name ) {
13922 if ( name === 'modules' ) {
13923 if ( !( 'moduleImport' in options.transforms ) ) transforms.moduleImport = options.transforms.modules;
13924 if ( !( 'moduleExport' in options.transforms ) ) transforms.moduleExport = options.transforms.modules;
13925 return;
13926 }
13927
13928 if ( !( name in transforms ) ) throw new Error( ("Unknown transform '" + name + "'") );
13929 transforms[ name ] = options.transforms[ name ];
13930 });
13931
13932 return new Program( source, ast, transforms, options ).export( options );
13933}
13934
13935exports.target = target;
13936exports.transform = transform;
13937exports.VERSION = version$1;
13938
13939Object.defineProperty(exports, '__esModule', { value: true });
13940
13941})));
13942//# sourceMappingURL=buble.deps.js.map