UNPKG

404 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('magic-string')) :
3 typeof define === 'function' && define.amd ? define(['exports', 'magic-string'], factory) :
4 (factory((global.buble = {}),global.MagicString));
5}(this, (function (exports,MagicString) { 'use strict';
6
7MagicString = MagicString && MagicString.hasOwnProperty('default') ? MagicString['default'] : MagicString;
8
9// Reserved word lists for various dialects of the language
10
11var reservedWords = {
12 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",
13 5: "class enum extends super const export import",
14 6: "enum",
15 strict: "implements interface let package private protected public static yield",
16 strictBind: "eval arguments"
17};
18
19// And the keywords
20
21var 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";
22
23var keywords = {
24 5: ecma5AndLessKeywords,
25 6: ecma5AndLessKeywords + " const class extends export import super"
26};
27
28// ## Character categories
29
30// Big ugly regular expressions that match characters in the
31// whitespace, identifier, and identifier-start categories. These
32// are only applied when a character is found to actually have a
33// code point above 128.
34// Generated by `bin/generate-identifier-regex.js`.
35
36var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fd5\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ae\ua7b0-\ua7b7\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
37var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d4-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d01-\u0d03\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1cf8\u1cf9\u1dc0-\u1df5\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
38
39var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
40var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
41
42nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
43
44// These are a run-length and offset encoded representation of the
45// >0xffff code points that are a valid part of identifiers. The
46// offset starts at 0x10000, and each pair of numbers represents an
47// offset to the next range, and then a size of the range. They were
48// generated by bin/generate-identifier-regex.js
49
50// eslint-disable-next-line comma-spacing
51var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,25,391,63,32,0,449,56,264,8,2,36,18,0,50,29,881,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,65,0,32,6124,20,754,9486,1,3071,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,10591,541];
52
53// eslint-disable-next-line comma-spacing
54var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,7,0,161,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,87,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,9,838,7,2,7,17,9,57,21,2,13,19882,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239];
55
56// This has a complexity linear to the value of the code. The
57// assumption is that looking up astral identifier characters is
58// rare.
59function isInAstralSet(code, set) {
60 var pos = 0x10000;
61 for (var i = 0; i < set.length; i += 2) {
62 pos += set[i];
63 if (pos > code) { return false }
64 pos += set[i + 1];
65 if (pos >= code) { return true }
66 }
67}
68
69// Test whether a given character code starts an identifier.
70
71function isIdentifierStart(code, astral) {
72 if (code < 65) { return code === 36 }
73 if (code < 91) { return true }
74 if (code < 97) { return code === 95 }
75 if (code < 123) { return true }
76 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
77 if (astral === false) { return false }
78 return isInAstralSet(code, astralIdentifierStartCodes)
79}
80
81// Test whether a given character is part of an identifier.
82
83function isIdentifierChar(code, astral) {
84 if (code < 48) { return code === 36 }
85 if (code < 58) { return true }
86 if (code < 65) { return false }
87 if (code < 91) { return true }
88 if (code < 97) { return code === 95 }
89 if (code < 123) { return true }
90 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
91 if (astral === false) { return false }
92 return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
93}
94
95// ## Token types
96
97// The assignment of fine-grained, information-carrying type objects
98// allows the tokenizer to store the information it has about a
99// token in a way that is very cheap for the parser to look up.
100
101// All token type variables start with an underscore, to make them
102// easy to recognize.
103
104// The `beforeExpr` property is used to disambiguate between regular
105// expressions and divisions. It is set on all token types that can
106// be followed by an expression (thus, a slash after them would be a
107// regular expression).
108//
109// The `startsExpr` property is used to check if the token ends a
110// `yield` expression. It is set on all token types that either can
111// directly start an expression (like a quotation mark) or can
112// continue an expression (like the body of a string).
113//
114// `isLoop` marks a keyword as starting a loop, which is important
115// to know when parsing a label, in order to allow or disallow
116// continue jumps to that label.
117
118var TokenType = function TokenType(label, conf) {
119 if ( conf === void 0 ) conf = {};
120
121 this.label = label;
122 this.keyword = conf.keyword;
123 this.beforeExpr = !!conf.beforeExpr;
124 this.startsExpr = !!conf.startsExpr;
125 this.isLoop = !!conf.isLoop;
126 this.isAssign = !!conf.isAssign;
127 this.prefix = !!conf.prefix;
128 this.postfix = !!conf.postfix;
129 this.binop = conf.binop || null;
130 this.updateContext = null;
131};
132
133function binop(name, prec) {
134 return new TokenType(name, {beforeExpr: true, binop: prec})
135}
136var beforeExpr = {beforeExpr: true};
137var startsExpr = {startsExpr: true};
138
139// Map keyword names to token types.
140
141var keywords$1 = {};
142
143// Succinct definitions of keyword token types
144function kw(name, options) {
145 if ( options === void 0 ) options = {};
146
147 options.keyword = name;
148 return keywords$1[name] = new TokenType(name, options)
149}
150
151var types = {
152 num: new TokenType("num", startsExpr),
153 regexp: new TokenType("regexp", startsExpr),
154 string: new TokenType("string", startsExpr),
155 name: new TokenType("name", startsExpr),
156 eof: new TokenType("eof"),
157
158 // Punctuation token types.
159 bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
160 bracketR: new TokenType("]"),
161 braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
162 braceR: new TokenType("}"),
163 parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
164 parenR: new TokenType(")"),
165 comma: new TokenType(",", beforeExpr),
166 semi: new TokenType(";", beforeExpr),
167 colon: new TokenType(":", beforeExpr),
168 dot: new TokenType("."),
169 question: new TokenType("?", beforeExpr),
170 arrow: new TokenType("=>", beforeExpr),
171 template: new TokenType("template"),
172 invalidTemplate: new TokenType("invalidTemplate"),
173 ellipsis: new TokenType("...", beforeExpr),
174 backQuote: new TokenType("`", startsExpr),
175 dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
176
177 // Operators. These carry several kinds of properties to help the
178 // parser use them properly (the presence of these properties is
179 // what categorizes them as operators).
180 //
181 // `binop`, when present, specifies that this operator is a binary
182 // operator, and will refer to its precedence.
183 //
184 // `prefix` and `postfix` mark the operator as a prefix or postfix
185 // unary operator.
186 //
187 // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
188 // binary operators with a very low precedence, that should result
189 // in AssignmentExpression nodes.
190
191 eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
192 assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
193 incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
194 prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
195 logicalOR: binop("||", 1),
196 logicalAND: binop("&&", 2),
197 bitwiseOR: binop("|", 3),
198 bitwiseXOR: binop("^", 4),
199 bitwiseAND: binop("&", 5),
200 equality: binop("==/!=/===/!==", 6),
201 relational: binop("</>/<=/>=", 7),
202 bitShift: binop("<</>>/>>>", 8),
203 plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
204 modulo: binop("%", 10),
205 star: binop("*", 10),
206 slash: binop("/", 10),
207 starstar: new TokenType("**", {beforeExpr: true}),
208
209 // Keyword token types.
210 _break: kw("break"),
211 _case: kw("case", beforeExpr),
212 _catch: kw("catch"),
213 _continue: kw("continue"),
214 _debugger: kw("debugger"),
215 _default: kw("default", beforeExpr),
216 _do: kw("do", {isLoop: true, beforeExpr: true}),
217 _else: kw("else", beforeExpr),
218 _finally: kw("finally"),
219 _for: kw("for", {isLoop: true}),
220 _function: kw("function", startsExpr),
221 _if: kw("if"),
222 _return: kw("return", beforeExpr),
223 _switch: kw("switch"),
224 _throw: kw("throw", beforeExpr),
225 _try: kw("try"),
226 _var: kw("var"),
227 _const: kw("const"),
228 _while: kw("while", {isLoop: true}),
229 _with: kw("with"),
230 _new: kw("new", {beforeExpr: true, startsExpr: true}),
231 _this: kw("this", startsExpr),
232 _super: kw("super", startsExpr),
233 _class: kw("class", startsExpr),
234 _extends: kw("extends", beforeExpr),
235 _export: kw("export"),
236 _import: kw("import"),
237 _null: kw("null", startsExpr),
238 _true: kw("true", startsExpr),
239 _false: kw("false", startsExpr),
240 _in: kw("in", {beforeExpr: true, binop: 7}),
241 _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
242 _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
243 _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
244 _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
245};
246
247// Matches a whole line break (where CRLF is considered a single
248// line break). Used to count lines.
249
250var lineBreak = /\r\n?|\n|\u2028|\u2029/;
251var lineBreakG = new RegExp(lineBreak.source, "g");
252
253function isNewLine(code) {
254 return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
255}
256
257var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
258
259var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
260
261var ref$1 = Object.prototype;
262var hasOwnProperty = ref$1.hasOwnProperty;
263var toString = ref$1.toString;
264
265// Checks if an object has a property.
266
267function has(obj, propName) {
268 return hasOwnProperty.call(obj, propName)
269}
270
271var isArray = Array.isArray || (function (obj) { return (
272 toString.call(obj) === "[object Array]"
273); });
274
275// These are used when `options.locations` is on, for the
276// `startLoc` and `endLoc` properties.
277
278var Position = function Position(line, col) {
279 this.line = line;
280 this.column = col;
281};
282
283Position.prototype.offset = function offset (n) {
284 return new Position(this.line, this.column + n)
285};
286
287var SourceLocation = function SourceLocation(p, start, end) {
288 this.start = start;
289 this.end = end;
290 if (p.sourceFile !== null) { this.source = p.sourceFile; }
291};
292
293// The `getLineInfo` function is mostly useful when the
294// `locations` option is off (for performance reasons) and you
295// want to find the line/column position for a given character
296// offset. `input` should be the code string that the offset refers
297// into.
298
299function getLineInfo(input, offset) {
300 for (var line = 1, cur = 0;;) {
301 lineBreakG.lastIndex = cur;
302 var match = lineBreakG.exec(input);
303 if (match && match.index < offset) {
304 ++line;
305 cur = match.index + match[0].length;
306 } else {
307 return new Position(line, offset - cur)
308 }
309 }
310}
311
312// A second optional argument can be given to further configure
313// the parser process. These options are recognized:
314
315var defaultOptions = {
316 // `ecmaVersion` indicates the ECMAScript version to parse. Must
317 // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
318 // for strict mode, the set of reserved words, and support for
319 // new syntax features. The default is 7.
320 ecmaVersion: 7,
321 // `sourceType` indicates the mode the code should be parsed in.
322 // Can be either `"script"` or `"module"`. This influences global
323 // strict mode and parsing of `import` and `export` declarations.
324 sourceType: "script",
325 // `onInsertedSemicolon` can be a callback that will be called
326 // when a semicolon is automatically inserted. It will be passed
327 // th position of the comma as an offset, and if `locations` is
328 // enabled, it is given the location as a `{line, column}` object
329 // as second argument.
330 onInsertedSemicolon: null,
331 // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
332 // trailing commas.
333 onTrailingComma: null,
334 // By default, reserved words are only enforced if ecmaVersion >= 5.
335 // Set `allowReserved` to a boolean value to explicitly turn this on
336 // an off. When this option has the value "never", reserved words
337 // and keywords can also not be used as property names.
338 allowReserved: null,
339 // When enabled, a return at the top level is not considered an
340 // error.
341 allowReturnOutsideFunction: false,
342 // When enabled, import/export statements are not constrained to
343 // appearing at the top of the program.
344 allowImportExportEverywhere: false,
345 // When enabled, hashbang directive in the beginning of file
346 // is allowed and treated as a line comment.
347 allowHashBang: false,
348 // When `locations` is on, `loc` properties holding objects with
349 // `start` and `end` properties in `{line, column}` form (with
350 // line being 1-based and column 0-based) will be attached to the
351 // nodes.
352 locations: false,
353 // A function can be passed as `onToken` option, which will
354 // cause Acorn to call that function with object in the same
355 // format as tokens returned from `tokenizer().getToken()`. Note
356 // that you are not allowed to call the parser from the
357 // callback—that will corrupt its internal state.
358 onToken: null,
359 // A function can be passed as `onComment` option, which will
360 // cause Acorn to call that function with `(block, text, start,
361 // end)` parameters whenever a comment is skipped. `block` is a
362 // boolean indicating whether this is a block (`/* */`) comment,
363 // `text` is the content of the comment, and `start` and `end` are
364 // character offsets that denote the start and end of the comment.
365 // When the `locations` option is on, two more parameters are
366 // passed, the full `{line, column}` locations of the start and
367 // end of the comments. Note that you are not allowed to call the
368 // parser from the callback—that will corrupt its internal state.
369 onComment: null,
370 // Nodes have their start and end characters offsets recorded in
371 // `start` and `end` properties (directly on the node, rather than
372 // the `loc` object, which holds line/column data. To also add a
373 // [semi-standardized][range] `range` property holding a `[start,
374 // end]` array with the same numbers, set the `ranges` option to
375 // `true`.
376 //
377 // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
378 ranges: false,
379 // It is possible to parse multiple files into a single AST by
380 // passing the tree produced by parsing the first file as
381 // `program` option in subsequent parses. This will add the
382 // toplevel forms of the parsed file to the `Program` (top) node
383 // of an existing parse tree.
384 program: null,
385 // When `locations` is on, you can pass this to record the source
386 // file in every node's `loc` object.
387 sourceFile: null,
388 // This value, if given, is stored in every node, whether
389 // `locations` is on or off.
390 directSourceFile: null,
391 // When enabled, parenthesized expressions are represented by
392 // (non-standard) ParenthesizedExpression nodes
393 preserveParens: false,
394 plugins: {}
395};
396
397// Interpret and default an options object
398
399function getOptions(opts) {
400 var options = {};
401
402 for (var opt in defaultOptions)
403 { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
404
405 if (options.ecmaVersion >= 2015)
406 { options.ecmaVersion -= 2009; }
407
408 if (options.allowReserved == null)
409 { options.allowReserved = options.ecmaVersion < 5; }
410
411 if (isArray(options.onToken)) {
412 var tokens = options.onToken;
413 options.onToken = function (token) { return tokens.push(token); };
414 }
415 if (isArray(options.onComment))
416 { options.onComment = pushComment(options, options.onComment); }
417
418 return options
419}
420
421function pushComment(options, array) {
422 return function(block, text, start, end, startLoc, endLoc) {
423 var comment = {
424 type: block ? "Block" : "Line",
425 value: text,
426 start: start,
427 end: end
428 };
429 if (options.locations)
430 { comment.loc = new SourceLocation(this, startLoc, endLoc); }
431 if (options.ranges)
432 { comment.range = [start, end]; }
433 array.push(comment);
434 }
435}
436
437// Registered plugins
438var plugins = {};
439
440function keywordRegexp(words) {
441 return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
442}
443
444var Parser = function Parser(options, input, startPos) {
445 this.options = options = getOptions(options);
446 this.sourceFile = options.sourceFile;
447 this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
448 var reserved = "";
449 if (!options.allowReserved) {
450 for (var v = options.ecmaVersion;; v--)
451 { if (reserved = reservedWords[v]) { break } }
452 if (options.sourceType == "module") { reserved += " await"; }
453 }
454 this.reservedWords = keywordRegexp(reserved);
455 var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
456 this.reservedWordsStrict = keywordRegexp(reservedStrict);
457 this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
458 this.input = String(input);
459
460 // Used to signal to callers of `readWord1` whether the word
461 // contained any escape sequences. This is needed because words with
462 // escape sequences must not be interpreted as keywords.
463 this.containsEsc = false;
464
465 // Load plugins
466 this.loadPlugins(options.plugins);
467
468 // Set up token state
469
470 // The current position of the tokenizer in the input.
471 if (startPos) {
472 this.pos = startPos;
473 this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
474 this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
475 } else {
476 this.pos = this.lineStart = 0;
477 this.curLine = 1;
478 }
479
480 // Properties of the current token:
481 // Its type
482 this.type = types.eof;
483 // For tokens that include more information than their type, the value
484 this.value = null;
485 // Its start and end offset
486 this.start = this.end = this.pos;
487 // And, if locations are used, the {line, column} object
488 // corresponding to those offsets
489 this.startLoc = this.endLoc = this.curPosition();
490
491 // Position information for the previous token
492 this.lastTokEndLoc = this.lastTokStartLoc = null;
493 this.lastTokStart = this.lastTokEnd = this.pos;
494
495 // The context stack is used to superficially track syntactic
496 // context to predict whether a regular expression is allowed in a
497 // given position.
498 this.context = this.initialContext();
499 this.exprAllowed = true;
500
501 // Figure out if it's a module code.
502 this.inModule = options.sourceType === "module";
503 this.strict = this.inModule || this.strictDirective(this.pos);
504
505 // Used to signify the start of a potential arrow function
506 this.potentialArrowAt = -1;
507
508 // Flags to track whether we are in a function, a generator, an async function.
509 this.inFunction = this.inGenerator = this.inAsync = false;
510 // Positions to delayed-check that yield/await does not exist in default parameters.
511 this.yieldPos = this.awaitPos = 0;
512 // Labels in scope.
513 this.labels = [];
514
515 // If enabled, skip leading hashbang line.
516 if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
517 { this.skipLineComment(2); }
518
519 // Scope tracking for duplicate variable names (see scope.js)
520 this.scopeStack = [];
521 this.enterFunctionScope();
522};
523
524// DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
525Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
526Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
527
528Parser.prototype.extend = function extend (name, f) {
529 this[name] = f(this[name]);
530};
531
532Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
533 var this$1 = this;
534
535 for (var name in pluginConfigs) {
536 var plugin = plugins[name];
537 if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
538 plugin(this$1, pluginConfigs[name]);
539 }
540};
541
542Parser.prototype.parse = function parse () {
543 var node = this.options.program || this.startNode();
544 this.nextToken();
545 return this.parseTopLevel(node)
546};
547
548var pp = Parser.prototype;
549
550// ## Parser utilities
551
552var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
553pp.strictDirective = function(start) {
554 var this$1 = this;
555
556 for (;;) {
557 skipWhiteSpace.lastIndex = start;
558 start += skipWhiteSpace.exec(this$1.input)[0].length;
559 var match = literal.exec(this$1.input.slice(start));
560 if (!match) { return false }
561 if ((match[1] || match[2]) == "use strict") { return true }
562 start += match[0].length;
563 }
564};
565
566// Predicate that tests whether the next token is of the given
567// type, and if yes, consumes it as a side effect.
568
569pp.eat = function(type) {
570 if (this.type === type) {
571 this.next();
572 return true
573 } else {
574 return false
575 }
576};
577
578// Tests whether parsed token is a contextual keyword.
579
580pp.isContextual = function(name) {
581 return this.type === types.name && this.value === name
582};
583
584// Consumes contextual keyword if possible.
585
586pp.eatContextual = function(name) {
587 return this.value === name && this.eat(types.name)
588};
589
590// Asserts that following token is given contextual keyword.
591
592pp.expectContextual = function(name) {
593 if (!this.eatContextual(name)) { this.unexpected(); }
594};
595
596// Test whether a semicolon can be inserted at the current position.
597
598pp.canInsertSemicolon = function() {
599 return this.type === types.eof ||
600 this.type === types.braceR ||
601 lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
602};
603
604pp.insertSemicolon = function() {
605 if (this.canInsertSemicolon()) {
606 if (this.options.onInsertedSemicolon)
607 { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
608 return true
609 }
610};
611
612// Consume a semicolon, or, failing that, see if we are allowed to
613// pretend that there is a semicolon at this position.
614
615pp.semicolon = function() {
616 if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
617};
618
619pp.afterTrailingComma = function(tokType, notNext) {
620 if (this.type == tokType) {
621 if (this.options.onTrailingComma)
622 { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
623 if (!notNext)
624 { this.next(); }
625 return true
626 }
627};
628
629// Expect a token of a given type. If found, consume it, otherwise,
630// raise an unexpected token error.
631
632pp.expect = function(type) {
633 this.eat(type) || this.unexpected();
634};
635
636// Raise an unexpected token error.
637
638pp.unexpected = function(pos) {
639 this.raise(pos != null ? pos : this.start, "Unexpected token");
640};
641
642function DestructuringErrors() {
643 this.shorthandAssign =
644 this.trailingComma =
645 this.parenthesizedAssign =
646 this.parenthesizedBind =
647 -1;
648}
649
650pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
651 if (!refDestructuringErrors) { return }
652 if (refDestructuringErrors.trailingComma > -1)
653 { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
654 var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
655 if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
656};
657
658pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
659 var pos = refDestructuringErrors ? refDestructuringErrors.shorthandAssign : -1;
660 if (!andThrow) { return pos >= 0 }
661 if (pos > -1) { this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns"); }
662};
663
664pp.checkYieldAwaitInDefaultParams = function() {
665 if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
666 { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
667 if (this.awaitPos)
668 { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
669};
670
671pp.isSimpleAssignTarget = function(expr) {
672 if (expr.type === "ParenthesizedExpression")
673 { return this.isSimpleAssignTarget(expr.expression) }
674 return expr.type === "Identifier" || expr.type === "MemberExpression"
675};
676
677var pp$1 = Parser.prototype;
678
679// ### Statement parsing
680
681// Parse a program. Initializes the parser, reads any number of
682// statements, and wraps them in a Program node. Optionally takes a
683// `program` argument. If present, the statements will be appended
684// to its body instead of creating a new node.
685
686pp$1.parseTopLevel = function(node) {
687 var this$1 = this;
688
689 var exports = {};
690 if (!node.body) { node.body = []; }
691 while (this.type !== types.eof) {
692 var stmt = this$1.parseStatement(true, true, exports);
693 node.body.push(stmt);
694 }
695 this.next();
696 if (this.options.ecmaVersion >= 6) {
697 node.sourceType = this.options.sourceType;
698 }
699 return this.finishNode(node, "Program")
700};
701
702var loopLabel = {kind: "loop"};
703var switchLabel = {kind: "switch"};
704
705pp$1.isLet = function() {
706 if (this.type !== types.name || this.options.ecmaVersion < 6 || this.value != "let") { return false }
707 skipWhiteSpace.lastIndex = this.pos;
708 var skip = skipWhiteSpace.exec(this.input);
709 var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
710 if (nextCh === 91 || nextCh == 123) { return true } // '{' and '['
711 if (isIdentifierStart(nextCh, true)) {
712 var pos = next + 1;
713 while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
714 var ident = this.input.slice(next, pos);
715 if (!this.isKeyword(ident)) { return true }
716 }
717 return false
718};
719
720// check 'async [no LineTerminator here] function'
721// - 'async /*foo*/ function' is OK.
722// - 'async /*\n*/ function' is invalid.
723pp$1.isAsyncFunction = function() {
724 if (this.type !== types.name || this.options.ecmaVersion < 8 || this.value != "async")
725 { return false }
726
727 skipWhiteSpace.lastIndex = this.pos;
728 var skip = skipWhiteSpace.exec(this.input);
729 var next = this.pos + skip[0].length;
730 return !lineBreak.test(this.input.slice(this.pos, next)) &&
731 this.input.slice(next, next + 8) === "function" &&
732 (next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
733};
734
735// Parse a single statement.
736//
737// If expecting a statement and finding a slash operator, parse a
738// regular expression literal. This is to handle cases like
739// `if (foo) /blah/.exec(foo)`, where looking at the previous token
740// does not help.
741
742pp$1.parseStatement = function(declaration, topLevel, exports) {
743 var starttype = this.type, node = this.startNode(), kind;
744
745 if (this.isLet()) {
746 starttype = types._var;
747 kind = "let";
748 }
749
750 // Most types of statements are recognized by the keyword they
751 // start with. Many are trivial to parse, some require a bit of
752 // complexity.
753
754 switch (starttype) {
755 case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
756 case types._debugger: return this.parseDebuggerStatement(node)
757 case types._do: return this.parseDoStatement(node)
758 case types._for: return this.parseForStatement(node)
759 case types._function:
760 if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
761 return this.parseFunctionStatement(node, false)
762 case types._class:
763 if (!declaration) { this.unexpected(); }
764 return this.parseClass(node, true)
765 case types._if: return this.parseIfStatement(node)
766 case types._return: return this.parseReturnStatement(node)
767 case types._switch: return this.parseSwitchStatement(node)
768 case types._throw: return this.parseThrowStatement(node)
769 case types._try: return this.parseTryStatement(node)
770 case types._const: case types._var:
771 kind = kind || this.value;
772 if (!declaration && kind != "var") { this.unexpected(); }
773 return this.parseVarStatement(node, kind)
774 case types._while: return this.parseWhileStatement(node)
775 case types._with: return this.parseWithStatement(node)
776 case types.braceL: return this.parseBlock()
777 case types.semi: return this.parseEmptyStatement(node)
778 case types._export:
779 case types._import:
780 if (!this.options.allowImportExportEverywhere) {
781 if (!topLevel)
782 { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
783 if (!this.inModule)
784 { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
785 }
786 return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
787
788 // If the statement does not start with a statement keyword or a
789 // brace, it's an ExpressionStatement or LabeledStatement. We
790 // simply start parsing an expression, and afterwards, if the
791 // next token is a colon and the expression was a simple
792 // Identifier node, we switch to interpreting it as a label.
793 default:
794 if (this.isAsyncFunction() && declaration) {
795 this.next();
796 return this.parseFunctionStatement(node, true)
797 }
798
799 var maybeName = this.value, expr = this.parseExpression();
800 if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
801 { return this.parseLabeledStatement(node, maybeName, expr) }
802 else { return this.parseExpressionStatement(node, expr) }
803 }
804};
805
806pp$1.parseBreakContinueStatement = function(node, keyword) {
807 var this$1 = this;
808
809 var isBreak = keyword == "break";
810 this.next();
811 if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
812 else if (this.type !== types.name) { this.unexpected(); }
813 else {
814 node.label = this.parseIdent();
815 this.semicolon();
816 }
817
818 // Verify that there is an actual destination to break or
819 // continue to.
820 var i = 0;
821 for (; i < this.labels.length; ++i) {
822 var lab = this$1.labels[i];
823 if (node.label == null || lab.name === node.label.name) {
824 if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
825 if (node.label && isBreak) { break }
826 }
827 }
828 if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
829 return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
830};
831
832pp$1.parseDebuggerStatement = function(node) {
833 this.next();
834 this.semicolon();
835 return this.finishNode(node, "DebuggerStatement")
836};
837
838pp$1.parseDoStatement = function(node) {
839 this.next();
840 this.labels.push(loopLabel);
841 node.body = this.parseStatement(false);
842 this.labels.pop();
843 this.expect(types._while);
844 node.test = this.parseParenExpression();
845 if (this.options.ecmaVersion >= 6)
846 { this.eat(types.semi); }
847 else
848 { this.semicolon(); }
849 return this.finishNode(node, "DoWhileStatement")
850};
851
852// Disambiguating between a `for` and a `for`/`in` or `for`/`of`
853// loop is non-trivial. Basically, we have to parse the init `var`
854// statement or expression, disallowing the `in` operator (see
855// the second parameter to `parseExpression`), and then check
856// whether the next token is `in` or `of`. When there is no init
857// part (semicolon immediately after the opening parenthesis), it
858// is a regular `for` loop.
859
860pp$1.parseForStatement = function(node) {
861 this.next();
862 this.labels.push(loopLabel);
863 this.enterLexicalScope();
864 this.expect(types.parenL);
865 if (this.type === types.semi) { return this.parseFor(node, null) }
866 var isLet = this.isLet();
867 if (this.type === types._var || this.type === types._const || isLet) {
868 var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
869 this.next();
870 this.parseVar(init$1, true, kind);
871 this.finishNode(init$1, "VariableDeclaration");
872 if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
873 !(kind !== "var" && init$1.declarations[0].init))
874 { return this.parseForIn(node, init$1) }
875 return this.parseFor(node, init$1)
876 }
877 var refDestructuringErrors = new DestructuringErrors;
878 var init = this.parseExpression(true, refDestructuringErrors);
879 if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
880 this.toAssignable(init);
881 this.checkLVal(init);
882 this.checkPatternErrors(refDestructuringErrors, true);
883 return this.parseForIn(node, init)
884 } else {
885 this.checkExpressionErrors(refDestructuringErrors, true);
886 }
887 return this.parseFor(node, init)
888};
889
890pp$1.parseFunctionStatement = function(node, isAsync) {
891 this.next();
892 return this.parseFunction(node, true, false, isAsync)
893};
894
895pp$1.isFunction = function() {
896 return this.type === types._function || this.isAsyncFunction()
897};
898
899pp$1.parseIfStatement = function(node) {
900 this.next();
901 node.test = this.parseParenExpression();
902 // allow function declarations in branches, but only in non-strict mode
903 node.consequent = this.parseStatement(!this.strict && this.isFunction());
904 node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.isFunction()) : null;
905 return this.finishNode(node, "IfStatement")
906};
907
908pp$1.parseReturnStatement = function(node) {
909 if (!this.inFunction && !this.options.allowReturnOutsideFunction)
910 { this.raise(this.start, "'return' outside of function"); }
911 this.next();
912
913 // In `return` (and `break`/`continue`), the keywords with
914 // optional arguments, we eagerly look for a semicolon or the
915 // possibility to insert one.
916
917 if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
918 else { node.argument = this.parseExpression(); this.semicolon(); }
919 return this.finishNode(node, "ReturnStatement")
920};
921
922pp$1.parseSwitchStatement = function(node) {
923 var this$1 = this;
924
925 this.next();
926 node.discriminant = this.parseParenExpression();
927 node.cases = [];
928 this.expect(types.braceL);
929 this.labels.push(switchLabel);
930 this.enterLexicalScope();
931
932 // Statements under must be grouped (by label) in SwitchCase
933 // nodes. `cur` is used to keep the node that we are currently
934 // adding statements to.
935
936 var cur;
937 for (var sawDefault = false; this.type != types.braceR;) {
938 if (this$1.type === types._case || this$1.type === types._default) {
939 var isCase = this$1.type === types._case;
940 if (cur) { this$1.finishNode(cur, "SwitchCase"); }
941 node.cases.push(cur = this$1.startNode());
942 cur.consequent = [];
943 this$1.next();
944 if (isCase) {
945 cur.test = this$1.parseExpression();
946 } else {
947 if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
948 sawDefault = true;
949 cur.test = null;
950 }
951 this$1.expect(types.colon);
952 } else {
953 if (!cur) { this$1.unexpected(); }
954 cur.consequent.push(this$1.parseStatement(true));
955 }
956 }
957 this.exitLexicalScope();
958 if (cur) { this.finishNode(cur, "SwitchCase"); }
959 this.next(); // Closing brace
960 this.labels.pop();
961 return this.finishNode(node, "SwitchStatement")
962};
963
964pp$1.parseThrowStatement = function(node) {
965 this.next();
966 if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
967 { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
968 node.argument = this.parseExpression();
969 this.semicolon();
970 return this.finishNode(node, "ThrowStatement")
971};
972
973// Reused empty array added for node fields that are always empty.
974
975var empty = [];
976
977pp$1.parseTryStatement = function(node) {
978 this.next();
979 node.block = this.parseBlock();
980 node.handler = null;
981 if (this.type === types._catch) {
982 var clause = this.startNode();
983 this.next();
984 this.expect(types.parenL);
985 clause.param = this.parseBindingAtom();
986 this.enterLexicalScope();
987 this.checkLVal(clause.param, "let");
988 this.expect(types.parenR);
989 clause.body = this.parseBlock(false);
990 this.exitLexicalScope();
991 node.handler = this.finishNode(clause, "CatchClause");
992 }
993 node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
994 if (!node.handler && !node.finalizer)
995 { this.raise(node.start, "Missing catch or finally clause"); }
996 return this.finishNode(node, "TryStatement")
997};
998
999pp$1.parseVarStatement = function(node, kind) {
1000 this.next();
1001 this.parseVar(node, false, kind);
1002 this.semicolon();
1003 return this.finishNode(node, "VariableDeclaration")
1004};
1005
1006pp$1.parseWhileStatement = function(node) {
1007 this.next();
1008 node.test = this.parseParenExpression();
1009 this.labels.push(loopLabel);
1010 node.body = this.parseStatement(false);
1011 this.labels.pop();
1012 return this.finishNode(node, "WhileStatement")
1013};
1014
1015pp$1.parseWithStatement = function(node) {
1016 if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
1017 this.next();
1018 node.object = this.parseParenExpression();
1019 node.body = this.parseStatement(false);
1020 return this.finishNode(node, "WithStatement")
1021};
1022
1023pp$1.parseEmptyStatement = function(node) {
1024 this.next();
1025 return this.finishNode(node, "EmptyStatement")
1026};
1027
1028pp$1.parseLabeledStatement = function(node, maybeName, expr) {
1029 var this$1 = this;
1030
1031 for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
1032 {
1033 var label = list[i$1];
1034
1035 if (label.name === maybeName)
1036 { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
1037 } }
1038 var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
1039 for (var i = this.labels.length - 1; i >= 0; i--) {
1040 var label$1 = this$1.labels[i];
1041 if (label$1.statementStart == node.start) {
1042 label$1.statementStart = this$1.start;
1043 label$1.kind = kind;
1044 } else { break }
1045 }
1046 this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
1047 node.body = this.parseStatement(true);
1048 if (node.body.type == "ClassDeclaration" ||
1049 node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
1050 node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator))
1051 { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
1052 this.labels.pop();
1053 node.label = expr;
1054 return this.finishNode(node, "LabeledStatement")
1055};
1056
1057pp$1.parseExpressionStatement = function(node, expr) {
1058 node.expression = expr;
1059 this.semicolon();
1060 return this.finishNode(node, "ExpressionStatement")
1061};
1062
1063// Parse a semicolon-enclosed block of statements, handling `"use
1064// strict"` declarations when `allowStrict` is true (used for
1065// function bodies).
1066
1067pp$1.parseBlock = function(createNewLexicalScope) {
1068 var this$1 = this;
1069 if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
1070
1071 var node = this.startNode();
1072 node.body = [];
1073 this.expect(types.braceL);
1074 if (createNewLexicalScope) {
1075 this.enterLexicalScope();
1076 }
1077 while (!this.eat(types.braceR)) {
1078 var stmt = this$1.parseStatement(true);
1079 node.body.push(stmt);
1080 }
1081 if (createNewLexicalScope) {
1082 this.exitLexicalScope();
1083 }
1084 return this.finishNode(node, "BlockStatement")
1085};
1086
1087// Parse a regular `for` loop. The disambiguation code in
1088// `parseStatement` will already have parsed the init statement or
1089// expression.
1090
1091pp$1.parseFor = function(node, init) {
1092 node.init = init;
1093 this.expect(types.semi);
1094 node.test = this.type === types.semi ? null : this.parseExpression();
1095 this.expect(types.semi);
1096 node.update = this.type === types.parenR ? null : this.parseExpression();
1097 this.expect(types.parenR);
1098 this.exitLexicalScope();
1099 node.body = this.parseStatement(false);
1100 this.labels.pop();
1101 return this.finishNode(node, "ForStatement")
1102};
1103
1104// Parse a `for`/`in` and `for`/`of` loop, which are almost
1105// same from parser's perspective.
1106
1107pp$1.parseForIn = function(node, init) {
1108 var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
1109 this.next();
1110 node.left = init;
1111 node.right = this.parseExpression();
1112 this.expect(types.parenR);
1113 this.exitLexicalScope();
1114 node.body = this.parseStatement(false);
1115 this.labels.pop();
1116 return this.finishNode(node, type)
1117};
1118
1119// Parse a list of variable declarations.
1120
1121pp$1.parseVar = function(node, isFor, kind) {
1122 var this$1 = this;
1123
1124 node.declarations = [];
1125 node.kind = kind;
1126 for (;;) {
1127 var decl = this$1.startNode();
1128 this$1.parseVarId(decl, kind);
1129 if (this$1.eat(types.eq)) {
1130 decl.init = this$1.parseMaybeAssign(isFor);
1131 } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
1132 this$1.unexpected();
1133 } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
1134 this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
1135 } else {
1136 decl.init = null;
1137 }
1138 node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
1139 if (!this$1.eat(types.comma)) { break }
1140 }
1141 return node
1142};
1143
1144pp$1.parseVarId = function(decl, kind) {
1145 decl.id = this.parseBindingAtom(kind);
1146 this.checkLVal(decl.id, kind, false);
1147};
1148
1149// Parse a function declaration or literal (depending on the
1150// `isStatement` parameter).
1151
1152pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
1153 this.initFunction(node);
1154 if (this.options.ecmaVersion >= 6 && !isAsync)
1155 { node.generator = this.eat(types.star); }
1156 if (this.options.ecmaVersion >= 8)
1157 { node.async = !!isAsync; }
1158
1159 if (isStatement) {
1160 node.id = isStatement === "nullableID" && this.type != types.name ? null : this.parseIdent();
1161 if (node.id) {
1162 this.checkLVal(node.id, "var");
1163 }
1164 }
1165
1166 var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
1167 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
1168 this.inGenerator = node.generator;
1169 this.inAsync = node.async;
1170 this.yieldPos = 0;
1171 this.awaitPos = 0;
1172 this.inFunction = true;
1173 this.enterFunctionScope();
1174
1175 if (!isStatement)
1176 { node.id = this.type == types.name ? this.parseIdent() : null; }
1177
1178 this.parseFunctionParams(node);
1179 this.parseFunctionBody(node, allowExpressionBody);
1180
1181 this.inGenerator = oldInGen;
1182 this.inAsync = oldInAsync;
1183 this.yieldPos = oldYieldPos;
1184 this.awaitPos = oldAwaitPos;
1185 this.inFunction = oldInFunc;
1186 return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
1187};
1188
1189pp$1.parseFunctionParams = function(node) {
1190 this.expect(types.parenL);
1191 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
1192 this.checkYieldAwaitInDefaultParams();
1193};
1194
1195// Parse a class declaration or literal (depending on the
1196// `isStatement` parameter).
1197
1198pp$1.parseClass = function(node, isStatement) {
1199 var this$1 = this;
1200
1201 this.next();
1202
1203 this.parseClassId(node, isStatement);
1204 this.parseClassSuper(node);
1205 var classBody = this.startNode();
1206 var hadConstructor = false;
1207 classBody.body = [];
1208 this.expect(types.braceL);
1209 while (!this.eat(types.braceR)) {
1210 if (this$1.eat(types.semi)) { continue }
1211 var method = this$1.startNode();
1212 var isGenerator = this$1.eat(types.star);
1213 var isAsync = false;
1214 var isMaybeStatic = this$1.type === types.name && this$1.value === "static";
1215 this$1.parsePropertyName(method);
1216 method.static = isMaybeStatic && this$1.type !== types.parenL;
1217 if (method.static) {
1218 if (isGenerator) { this$1.unexpected(); }
1219 isGenerator = this$1.eat(types.star);
1220 this$1.parsePropertyName(method);
1221 }
1222 if (this$1.options.ecmaVersion >= 8 && !isGenerator && !method.computed &&
1223 method.key.type === "Identifier" && method.key.name === "async" && this$1.type !== types.parenL &&
1224 !this$1.canInsertSemicolon()) {
1225 isAsync = true;
1226 this$1.parsePropertyName(method);
1227 }
1228 method.kind = "method";
1229 var isGetSet = false;
1230 if (!method.computed) {
1231 var key = method.key;
1232 if (!isGenerator && !isAsync && key.type === "Identifier" && this$1.type !== types.parenL && (key.name === "get" || key.name === "set")) {
1233 isGetSet = true;
1234 method.kind = key.name;
1235 key = this$1.parsePropertyName(method);
1236 }
1237 if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
1238 key.type === "Literal" && key.value === "constructor")) {
1239 if (hadConstructor) { this$1.raise(key.start, "Duplicate constructor in the same class"); }
1240 if (isGetSet) { this$1.raise(key.start, "Constructor can't have get/set modifier"); }
1241 if (isGenerator) { this$1.raise(key.start, "Constructor can't be a generator"); }
1242 if (isAsync) { this$1.raise(key.start, "Constructor can't be an async method"); }
1243 method.kind = "constructor";
1244 hadConstructor = true;
1245 }
1246 }
1247 this$1.parseClassMethod(classBody, method, isGenerator, isAsync);
1248 if (isGetSet) {
1249 var paramCount = method.kind === "get" ? 0 : 1;
1250 if (method.value.params.length !== paramCount) {
1251 var start = method.value.start;
1252 if (method.kind === "get")
1253 { this$1.raiseRecoverable(start, "getter should have no params"); }
1254 else
1255 { this$1.raiseRecoverable(start, "setter should have exactly one param"); }
1256 } else {
1257 if (method.kind === "set" && method.value.params[0].type === "RestElement")
1258 { this$1.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
1259 }
1260 }
1261 }
1262 node.body = this.finishNode(classBody, "ClassBody");
1263 return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
1264};
1265
1266pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
1267 method.value = this.parseMethod(isGenerator, isAsync);
1268 classBody.body.push(this.finishNode(method, "MethodDefinition"));
1269};
1270
1271pp$1.parseClassId = function(node, isStatement) {
1272 node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
1273};
1274
1275pp$1.parseClassSuper = function(node) {
1276 node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
1277};
1278
1279// Parses module export declaration.
1280
1281pp$1.parseExport = function(node, exports) {
1282 var this$1 = this;
1283
1284 this.next();
1285 // export * from '...'
1286 if (this.eat(types.star)) {
1287 this.expectContextual("from");
1288 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1289 this.semicolon();
1290 return this.finishNode(node, "ExportAllDeclaration")
1291 }
1292 if (this.eat(types._default)) { // export default ...
1293 this.checkExport(exports, "default", this.lastTokStart);
1294 var isAsync;
1295 if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
1296 var fNode = this.startNode();
1297 this.next();
1298 if (isAsync) { this.next(); }
1299 node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
1300 } else if (this.type === types._class) {
1301 var cNode = this.startNode();
1302 node.declaration = this.parseClass(cNode, "nullableID");
1303 } else {
1304 node.declaration = this.parseMaybeAssign();
1305 this.semicolon();
1306 }
1307 return this.finishNode(node, "ExportDefaultDeclaration")
1308 }
1309 // export var|const|let|function|class ...
1310 if (this.shouldParseExportStatement()) {
1311 node.declaration = this.parseStatement(true);
1312 if (node.declaration.type === "VariableDeclaration")
1313 { this.checkVariableExport(exports, node.declaration.declarations); }
1314 else
1315 { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
1316 node.specifiers = [];
1317 node.source = null;
1318 } else { // export { x, y as z } [from '...']
1319 node.declaration = null;
1320 node.specifiers = this.parseExportSpecifiers(exports);
1321 if (this.eatContextual("from")) {
1322 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1323 } else {
1324 // check for keywords used as local names
1325 for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
1326 var spec = list[i];
1327
1328 this$1.checkUnreserved(spec.local);
1329 }
1330
1331 node.source = null;
1332 }
1333 this.semicolon();
1334 }
1335 return this.finishNode(node, "ExportNamedDeclaration")
1336};
1337
1338pp$1.checkExport = function(exports, name, pos) {
1339 if (!exports) { return }
1340 if (has(exports, name))
1341 { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
1342 exports[name] = true;
1343};
1344
1345pp$1.checkPatternExport = function(exports, pat) {
1346 var this$1 = this;
1347
1348 var type = pat.type;
1349 if (type == "Identifier")
1350 { this.checkExport(exports, pat.name, pat.start); }
1351 else if (type == "ObjectPattern")
1352 { for (var i = 0, list = pat.properties; i < list.length; i += 1)
1353 {
1354 var prop = list[i];
1355
1356 this$1.checkPatternExport(exports, prop.value);
1357 } }
1358 else if (type == "ArrayPattern")
1359 { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
1360 var elt = list$1[i$1];
1361
1362 if (elt) { this$1.checkPatternExport(exports, elt); }
1363 } }
1364 else if (type == "AssignmentPattern")
1365 { this.checkPatternExport(exports, pat.left); }
1366 else if (type == "ParenthesizedExpression")
1367 { this.checkPatternExport(exports, pat.expression); }
1368};
1369
1370pp$1.checkVariableExport = function(exports, decls) {
1371 var this$1 = this;
1372
1373 if (!exports) { return }
1374 for (var i = 0, list = decls; i < list.length; i += 1)
1375 {
1376 var decl = list[i];
1377
1378 this$1.checkPatternExport(exports, decl.id);
1379 }
1380};
1381
1382pp$1.shouldParseExportStatement = function() {
1383 return this.type.keyword === "var" ||
1384 this.type.keyword === "const" ||
1385 this.type.keyword === "class" ||
1386 this.type.keyword === "function" ||
1387 this.isLet() ||
1388 this.isAsyncFunction()
1389};
1390
1391// Parses a comma-separated list of module exports.
1392
1393pp$1.parseExportSpecifiers = function(exports) {
1394 var this$1 = this;
1395
1396 var nodes = [], first = true;
1397 // export { x, y as z } [from '...']
1398 this.expect(types.braceL);
1399 while (!this.eat(types.braceR)) {
1400 if (!first) {
1401 this$1.expect(types.comma);
1402 if (this$1.afterTrailingComma(types.braceR)) { break }
1403 } else { first = false; }
1404
1405 var node = this$1.startNode();
1406 node.local = this$1.parseIdent(true);
1407 node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
1408 this$1.checkExport(exports, node.exported.name, node.exported.start);
1409 nodes.push(this$1.finishNode(node, "ExportSpecifier"));
1410 }
1411 return nodes
1412};
1413
1414// Parses import declaration.
1415
1416pp$1.parseImport = function(node) {
1417 this.next();
1418 // import '...'
1419 if (this.type === types.string) {
1420 node.specifiers = empty;
1421 node.source = this.parseExprAtom();
1422 } else {
1423 node.specifiers = this.parseImportSpecifiers();
1424 this.expectContextual("from");
1425 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1426 }
1427 this.semicolon();
1428 return this.finishNode(node, "ImportDeclaration")
1429};
1430
1431// Parses a comma-separated list of module imports.
1432
1433pp$1.parseImportSpecifiers = function() {
1434 var this$1 = this;
1435
1436 var nodes = [], first = true;
1437 if (this.type === types.name) {
1438 // import defaultObj, { x, y as z } from '...'
1439 var node = this.startNode();
1440 node.local = this.parseIdent();
1441 this.checkLVal(node.local, "let");
1442 nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
1443 if (!this.eat(types.comma)) { return nodes }
1444 }
1445 if (this.type === types.star) {
1446 var node$1 = this.startNode();
1447 this.next();
1448 this.expectContextual("as");
1449 node$1.local = this.parseIdent();
1450 this.checkLVal(node$1.local, "let");
1451 nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
1452 return nodes
1453 }
1454 this.expect(types.braceL);
1455 while (!this.eat(types.braceR)) {
1456 if (!first) {
1457 this$1.expect(types.comma);
1458 if (this$1.afterTrailingComma(types.braceR)) { break }
1459 } else { first = false; }
1460
1461 var node$2 = this$1.startNode();
1462 node$2.imported = this$1.parseIdent(true);
1463 if (this$1.eatContextual("as")) {
1464 node$2.local = this$1.parseIdent();
1465 } else {
1466 this$1.checkUnreserved(node$2.imported);
1467 node$2.local = node$2.imported;
1468 }
1469 this$1.checkLVal(node$2.local, "let");
1470 nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
1471 }
1472 return nodes
1473};
1474
1475var pp$2 = Parser.prototype;
1476
1477// Convert existing expression atom to assignable pattern
1478// if possible.
1479
1480pp$2.toAssignable = function(node, isBinding) {
1481 var this$1 = this;
1482
1483 if (this.options.ecmaVersion >= 6 && node) {
1484 switch (node.type) {
1485 case "Identifier":
1486 if (this.inAsync && node.name === "await")
1487 { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
1488 break
1489
1490 case "ObjectPattern":
1491 case "ArrayPattern":
1492 break
1493
1494 case "ObjectExpression":
1495 node.type = "ObjectPattern";
1496 for (var i = 0, list = node.properties; i < list.length; i += 1) {
1497 var prop = list[i];
1498
1499 if (prop.kind !== "init") { this$1.raise(prop.key.start, "Object pattern can't contain getter or setter"); }
1500 this$1.toAssignable(prop.value, isBinding);
1501 }
1502 break
1503
1504 case "ArrayExpression":
1505 node.type = "ArrayPattern";
1506 this.toAssignableList(node.elements, isBinding);
1507 break
1508
1509 case "AssignmentExpression":
1510 if (node.operator === "=") {
1511 node.type = "AssignmentPattern";
1512 delete node.operator;
1513 this.toAssignable(node.left, isBinding);
1514 // falls through to AssignmentPattern
1515 } else {
1516 this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
1517 break
1518 }
1519
1520 case "AssignmentPattern":
1521 break
1522
1523 case "ParenthesizedExpression":
1524 this.toAssignable(node.expression, isBinding);
1525 break
1526
1527 case "MemberExpression":
1528 if (!isBinding) { break }
1529
1530 default:
1531 this.raise(node.start, "Assigning to rvalue");
1532 }
1533 }
1534 return node
1535};
1536
1537// Convert list of expression atoms to binding list.
1538
1539pp$2.toAssignableList = function(exprList, isBinding) {
1540 var this$1 = this;
1541
1542 var end = exprList.length;
1543 if (end) {
1544 var last = exprList[end - 1];
1545 if (last && last.type == "RestElement") {
1546 --end;
1547 } else if (last && last.type == "SpreadElement") {
1548 last.type = "RestElement";
1549 var arg = last.argument;
1550 this.toAssignable(arg, isBinding);
1551 --end;
1552 }
1553
1554 if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
1555 { this.unexpected(last.argument.start); }
1556 }
1557 for (var i = 0; i < end; i++) {
1558 var elt = exprList[i];
1559 if (elt) { this$1.toAssignable(elt, isBinding); }
1560 }
1561 return exprList
1562};
1563
1564// Parses spread element.
1565
1566pp$2.parseSpread = function(refDestructuringErrors) {
1567 var node = this.startNode();
1568 this.next();
1569 node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
1570 return this.finishNode(node, "SpreadElement")
1571};
1572
1573pp$2.parseRestBinding = function() {
1574 var node = this.startNode();
1575 this.next();
1576
1577 // RestElement inside of a function parameter must be an identifier
1578 if (this.options.ecmaVersion === 6 && this.type !== types.name)
1579 { this.unexpected(); }
1580
1581 node.argument = this.parseBindingAtom();
1582
1583 return this.finishNode(node, "RestElement")
1584};
1585
1586// Parses lvalue (assignable) atom.
1587
1588pp$2.parseBindingAtom = function() {
1589 if (this.options.ecmaVersion < 6) { return this.parseIdent() }
1590 switch (this.type) {
1591 case types.name:
1592 return this.parseIdent()
1593
1594 case types.bracketL:
1595 var node = this.startNode();
1596 this.next();
1597 node.elements = this.parseBindingList(types.bracketR, true, true);
1598 return this.finishNode(node, "ArrayPattern")
1599
1600 case types.braceL:
1601 return this.parseObj(true)
1602
1603 default:
1604 this.unexpected();
1605 }
1606};
1607
1608pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
1609 var this$1 = this;
1610
1611 var elts = [], first = true;
1612 while (!this.eat(close)) {
1613 if (first) { first = false; }
1614 else { this$1.expect(types.comma); }
1615 if (allowEmpty && this$1.type === types.comma) {
1616 elts.push(null);
1617 } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
1618 break
1619 } else if (this$1.type === types.ellipsis) {
1620 var rest = this$1.parseRestBinding();
1621 this$1.parseBindingListItem(rest);
1622 elts.push(rest);
1623 if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
1624 this$1.expect(close);
1625 break
1626 } else {
1627 var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
1628 this$1.parseBindingListItem(elem);
1629 elts.push(elem);
1630 }
1631 }
1632 return elts
1633};
1634
1635pp$2.parseBindingListItem = function(param) {
1636 return param
1637};
1638
1639// Parses assignment pattern around given atom if possible.
1640
1641pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
1642 left = left || this.parseBindingAtom();
1643 if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
1644 var node = this.startNodeAt(startPos, startLoc);
1645 node.left = left;
1646 node.right = this.parseMaybeAssign();
1647 return this.finishNode(node, "AssignmentPattern")
1648};
1649
1650// Verify that a node is an lval — something that can be assigned
1651// to.
1652// bindingType can be either:
1653// 'var' indicating that the lval creates a 'var' binding
1654// 'let' indicating that the lval creates a lexical ('let' or 'const') binding
1655// 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
1656
1657pp$2.checkLVal = function(expr, bindingType, checkClashes) {
1658 var this$1 = this;
1659
1660 switch (expr.type) {
1661 case "Identifier":
1662 if (this.strict && this.reservedWordsStrictBind.test(expr.name))
1663 { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
1664 if (checkClashes) {
1665 if (has(checkClashes, expr.name))
1666 { this.raiseRecoverable(expr.start, "Argument name clash"); }
1667 checkClashes[expr.name] = true;
1668 }
1669 if (bindingType && bindingType !== "none") {
1670 if (
1671 bindingType === "var" && !this.canDeclareVarName(expr.name) ||
1672 bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
1673 ) {
1674 this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
1675 }
1676 if (bindingType === "var") {
1677 this.declareVarName(expr.name);
1678 } else {
1679 this.declareLexicalName(expr.name);
1680 }
1681 }
1682 break
1683
1684 case "MemberExpression":
1685 if (bindingType) { this.raiseRecoverable(expr.start, (bindingType ? "Binding" : "Assigning to") + " member expression"); }
1686 break
1687
1688 case "ObjectPattern":
1689 for (var i = 0, list = expr.properties; i < list.length; i += 1)
1690 {
1691 var prop = list[i];
1692
1693 this$1.checkLVal(prop.value, bindingType, checkClashes);
1694 }
1695 break
1696
1697 case "ArrayPattern":
1698 for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
1699 var elem = list$1[i$1];
1700
1701 if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
1702 }
1703 break
1704
1705 case "AssignmentPattern":
1706 this.checkLVal(expr.left, bindingType, checkClashes);
1707 break
1708
1709 case "RestElement":
1710 this.checkLVal(expr.argument, bindingType, checkClashes);
1711 break
1712
1713 case "ParenthesizedExpression":
1714 this.checkLVal(expr.expression, bindingType, checkClashes);
1715 break
1716
1717 default:
1718 this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
1719 }
1720};
1721
1722// A recursive descent parser operates by defining functions for all
1723// syntactic elements, and recursively calling those, each function
1724// advancing the input stream and returning an AST node. Precedence
1725// of constructs (for example, the fact that `!x[1]` means `!(x[1])`
1726// instead of `(!x)[1]` is handled by the fact that the parser
1727// function that parses unary prefix operators is called first, and
1728// in turn calls the function that parses `[]` subscripts — that
1729// way, it'll receive the node for `x[1]` already parsed, and wraps
1730// *that* in the unary operator node.
1731//
1732// Acorn uses an [operator precedence parser][opp] to handle binary
1733// operator precedence, because it is much more compact than using
1734// the technique outlined above, which uses different, nesting
1735// functions to specify precedence, for all of the ten binary
1736// precedence levels that JavaScript defines.
1737//
1738// [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
1739
1740var pp$3 = Parser.prototype;
1741
1742// Check if property name clashes with already added.
1743// Object/class getters and setters are not allowed to clash —
1744// either with each other or with an init property — and in
1745// strict mode, init properties are also not allowed to be repeated.
1746
1747pp$3.checkPropClash = function(prop, propHash) {
1748 if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
1749 { return }
1750 var key = prop.key;
1751 var name;
1752 switch (key.type) {
1753 case "Identifier": name = key.name; break
1754 case "Literal": name = String(key.value); break
1755 default: return
1756 }
1757 var kind = prop.kind;
1758 if (this.options.ecmaVersion >= 6) {
1759 if (name === "__proto__" && kind === "init") {
1760 if (propHash.proto) { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
1761 propHash.proto = true;
1762 }
1763 return
1764 }
1765 name = "$" + name;
1766 var other = propHash[name];
1767 if (other) {
1768 var redefinition;
1769 if (kind === "init") {
1770 redefinition = this.strict && other.init || other.get || other.set;
1771 } else {
1772 redefinition = other.init || other[kind];
1773 }
1774 if (redefinition)
1775 { this.raiseRecoverable(key.start, "Redefinition of property"); }
1776 } else {
1777 other = propHash[name] = {
1778 init: false,
1779 get: false,
1780 set: false
1781 };
1782 }
1783 other[kind] = true;
1784};
1785
1786// ### Expression parsing
1787
1788// These nest, from the most general expression type at the top to
1789// 'atomic', nondivisible expression types at the bottom. Most of
1790// the functions will simply let the function(s) below them parse,
1791// and, *if* the syntactic construct they handle is present, wrap
1792// the AST node that the inner parser gave them in another node.
1793
1794// Parse a full expression. The optional arguments are used to
1795// forbid the `in` operator (in for loops initalization expressions)
1796// and provide reference for storing '=' operator inside shorthand
1797// property assignment in contexts where both object expression
1798// and object pattern might appear (so it's possible to raise
1799// delayed syntax error at correct position).
1800
1801pp$3.parseExpression = function(noIn, refDestructuringErrors) {
1802 var this$1 = this;
1803
1804 var startPos = this.start, startLoc = this.startLoc;
1805 var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
1806 if (this.type === types.comma) {
1807 var node = this.startNodeAt(startPos, startLoc);
1808 node.expressions = [expr];
1809 while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
1810 return this.finishNode(node, "SequenceExpression")
1811 }
1812 return expr
1813};
1814
1815// Parse an assignment expression. This includes applications of
1816// operators like `+=`.
1817
1818pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
1819 if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
1820
1821 var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
1822 if (refDestructuringErrors) {
1823 oldParenAssign = refDestructuringErrors.parenthesizedAssign;
1824 oldTrailingComma = refDestructuringErrors.trailingComma;
1825 refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
1826 } else {
1827 refDestructuringErrors = new DestructuringErrors;
1828 ownDestructuringErrors = true;
1829 }
1830
1831 var startPos = this.start, startLoc = this.startLoc;
1832 if (this.type == types.parenL || this.type == types.name)
1833 { this.potentialArrowAt = this.start; }
1834 var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
1835 if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
1836 if (this.type.isAssign) {
1837 this.checkPatternErrors(refDestructuringErrors, true);
1838 if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
1839 var node = this.startNodeAt(startPos, startLoc);
1840 node.operator = this.value;
1841 node.left = this.type === types.eq ? this.toAssignable(left) : left;
1842 refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
1843 this.checkLVal(left);
1844 this.next();
1845 node.right = this.parseMaybeAssign(noIn);
1846 return this.finishNode(node, "AssignmentExpression")
1847 } else {
1848 if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
1849 }
1850 if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
1851 if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
1852 return left
1853};
1854
1855// Parse a ternary conditional (`?:`) operator.
1856
1857pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
1858 var startPos = this.start, startLoc = this.startLoc;
1859 var expr = this.parseExprOps(noIn, refDestructuringErrors);
1860 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1861 if (this.eat(types.question)) {
1862 var node = this.startNodeAt(startPos, startLoc);
1863 node.test = expr;
1864 node.consequent = this.parseMaybeAssign();
1865 this.expect(types.colon);
1866 node.alternate = this.parseMaybeAssign(noIn);
1867 return this.finishNode(node, "ConditionalExpression")
1868 }
1869 return expr
1870};
1871
1872// Start the precedence parser.
1873
1874pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
1875 var startPos = this.start, startLoc = this.startLoc;
1876 var expr = this.parseMaybeUnary(refDestructuringErrors, false);
1877 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1878 return expr.start == startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
1879};
1880
1881// Parse binary operators with the operator precedence parsing
1882// algorithm. `left` is the left-hand side of the operator.
1883// `minPrec` provides context that allows the function to stop and
1884// defer further parser to one of its callers when it encounters an
1885// operator that has a lower precedence than the set it is parsing.
1886
1887pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
1888 var prec = this.type.binop;
1889 if (prec != null && (!noIn || this.type !== types._in)) {
1890 if (prec > minPrec) {
1891 var logical = this.type === types.logicalOR || this.type === types.logicalAND;
1892 var op = this.value;
1893 this.next();
1894 var startPos = this.start, startLoc = this.startLoc;
1895 var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
1896 var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
1897 return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
1898 }
1899 }
1900 return left
1901};
1902
1903pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
1904 var node = this.startNodeAt(startPos, startLoc);
1905 node.left = left;
1906 node.operator = op;
1907 node.right = right;
1908 return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
1909};
1910
1911// Parse unary operators, both prefix and postfix.
1912
1913pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
1914 var this$1 = this;
1915
1916 var startPos = this.start, startLoc = this.startLoc, expr;
1917 if (this.inAsync && this.isContextual("await")) {
1918 expr = this.parseAwait(refDestructuringErrors);
1919 sawUnary = true;
1920 } else if (this.type.prefix) {
1921 var node = this.startNode(), update = this.type === types.incDec;
1922 node.operator = this.value;
1923 node.prefix = true;
1924 this.next();
1925 node.argument = this.parseMaybeUnary(null, true);
1926 this.checkExpressionErrors(refDestructuringErrors, true);
1927 if (update) { this.checkLVal(node.argument); }
1928 else if (this.strict && node.operator === "delete" &&
1929 node.argument.type === "Identifier")
1930 { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
1931 else { sawUnary = true; }
1932 expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
1933 } else {
1934 expr = this.parseExprSubscripts(refDestructuringErrors);
1935 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1936 while (this.type.postfix && !this.canInsertSemicolon()) {
1937 var node$1 = this$1.startNodeAt(startPos, startLoc);
1938 node$1.operator = this$1.value;
1939 node$1.prefix = false;
1940 node$1.argument = expr;
1941 this$1.checkLVal(expr);
1942 this$1.next();
1943 expr = this$1.finishNode(node$1, "UpdateExpression");
1944 }
1945 }
1946
1947 if (!sawUnary && this.eat(types.starstar))
1948 { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
1949 else
1950 { return expr }
1951};
1952
1953// Parse call, dot, and `[]`-subscript expressions.
1954
1955pp$3.parseExprSubscripts = function(refDestructuringErrors) {
1956 var startPos = this.start, startLoc = this.startLoc;
1957 var expr = this.parseExprAtom(refDestructuringErrors);
1958 var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
1959 if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
1960 var result = this.parseSubscripts(expr, startPos, startLoc);
1961 if (refDestructuringErrors && result.type === "MemberExpression") {
1962 if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
1963 if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
1964 }
1965 return result
1966};
1967
1968pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
1969 var this$1 = this;
1970
1971 var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
1972 this.lastTokEnd == base.end && !this.canInsertSemicolon();
1973 for (var computed = (void 0);;) {
1974 if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
1975 var node = this$1.startNodeAt(startPos, startLoc);
1976 node.object = base;
1977 node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
1978 node.computed = !!computed;
1979 if (computed) { this$1.expect(types.bracketR); }
1980 base = this$1.finishNode(node, "MemberExpression");
1981 } else if (!noCalls && this$1.eat(types.parenL)) {
1982 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
1983 this$1.yieldPos = 0;
1984 this$1.awaitPos = 0;
1985 var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
1986 if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
1987 this$1.checkPatternErrors(refDestructuringErrors, false);
1988 this$1.checkYieldAwaitInDefaultParams();
1989 this$1.yieldPos = oldYieldPos;
1990 this$1.awaitPos = oldAwaitPos;
1991 return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
1992 }
1993 this$1.checkExpressionErrors(refDestructuringErrors, true);
1994 this$1.yieldPos = oldYieldPos || this$1.yieldPos;
1995 this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
1996 var node$1 = this$1.startNodeAt(startPos, startLoc);
1997 node$1.callee = base;
1998 node$1.arguments = exprList;
1999 base = this$1.finishNode(node$1, "CallExpression");
2000 } else if (this$1.type === types.backQuote) {
2001 var node$2 = this$1.startNodeAt(startPos, startLoc);
2002 node$2.tag = base;
2003 node$2.quasi = this$1.parseTemplate({isTagged: true});
2004 base = this$1.finishNode(node$2, "TaggedTemplateExpression");
2005 } else {
2006 return base
2007 }
2008 }
2009};
2010
2011// Parse an atomic expression — either a single token that is an
2012// expression, an expression started by a keyword like `function` or
2013// `new`, or an expression wrapped in punctuation like `()`, `[]`,
2014// or `{}`.
2015
2016pp$3.parseExprAtom = function(refDestructuringErrors) {
2017 var node, canBeArrow = this.potentialArrowAt == this.start;
2018 switch (this.type) {
2019 case types._super:
2020 if (!this.inFunction)
2021 { this.raise(this.start, "'super' outside of function or class"); }
2022
2023 case types._this:
2024 var type = this.type === types._this ? "ThisExpression" : "Super";
2025 node = this.startNode();
2026 this.next();
2027 return this.finishNode(node, type)
2028
2029 case types.name:
2030 var startPos = this.start, startLoc = this.startLoc;
2031 var id = this.parseIdent(this.type !== types.name);
2032 if (this.options.ecmaVersion >= 8 && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
2033 { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
2034 if (canBeArrow && !this.canInsertSemicolon()) {
2035 if (this.eat(types.arrow))
2036 { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
2037 if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name) {
2038 id = this.parseIdent();
2039 if (this.canInsertSemicolon() || !this.eat(types.arrow))
2040 { this.unexpected(); }
2041 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
2042 }
2043 }
2044 return id
2045
2046 case types.regexp:
2047 var value = this.value;
2048 node = this.parseLiteral(value.value);
2049 node.regex = {pattern: value.pattern, flags: value.flags};
2050 return node
2051
2052 case types.num: case types.string:
2053 return this.parseLiteral(this.value)
2054
2055 case types._null: case types._true: case types._false:
2056 node = this.startNode();
2057 node.value = this.type === types._null ? null : this.type === types._true;
2058 node.raw = this.type.keyword;
2059 this.next();
2060 return this.finishNode(node, "Literal")
2061
2062 case types.parenL:
2063 var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
2064 if (refDestructuringErrors) {
2065 if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
2066 { refDestructuringErrors.parenthesizedAssign = start; }
2067 if (refDestructuringErrors.parenthesizedBind < 0)
2068 { refDestructuringErrors.parenthesizedBind = start; }
2069 }
2070 return expr
2071
2072 case types.bracketL:
2073 node = this.startNode();
2074 this.next();
2075 node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
2076 return this.finishNode(node, "ArrayExpression")
2077
2078 case types.braceL:
2079 return this.parseObj(false, refDestructuringErrors)
2080
2081 case types._function:
2082 node = this.startNode();
2083 this.next();
2084 return this.parseFunction(node, false)
2085
2086 case types._class:
2087 return this.parseClass(this.startNode(), false)
2088
2089 case types._new:
2090 return this.parseNew()
2091
2092 case types.backQuote:
2093 return this.parseTemplate()
2094
2095 default:
2096 this.unexpected();
2097 }
2098};
2099
2100pp$3.parseLiteral = function(value) {
2101 var node = this.startNode();
2102 node.value = value;
2103 node.raw = this.input.slice(this.start, this.end);
2104 this.next();
2105 return this.finishNode(node, "Literal")
2106};
2107
2108pp$3.parseParenExpression = function() {
2109 this.expect(types.parenL);
2110 var val = this.parseExpression();
2111 this.expect(types.parenR);
2112 return val
2113};
2114
2115pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
2116 var this$1 = this;
2117
2118 var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
2119 if (this.options.ecmaVersion >= 6) {
2120 this.next();
2121
2122 var innerStartPos = this.start, innerStartLoc = this.startLoc;
2123 var exprList = [], first = true, lastIsComma = false;
2124 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart, innerParenStart;
2125 this.yieldPos = 0;
2126 this.awaitPos = 0;
2127 while (this.type !== types.parenR) {
2128 first ? first = false : this$1.expect(types.comma);
2129 if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
2130 lastIsComma = true;
2131 break
2132 } else if (this$1.type === types.ellipsis) {
2133 spreadStart = this$1.start;
2134 exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
2135 if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
2136 break
2137 } else {
2138 if (this$1.type === types.parenL && !innerParenStart) {
2139 innerParenStart = this$1.start;
2140 }
2141 exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
2142 }
2143 }
2144 var innerEndPos = this.start, innerEndLoc = this.startLoc;
2145 this.expect(types.parenR);
2146
2147 if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2148 this.checkPatternErrors(refDestructuringErrors, false);
2149 this.checkYieldAwaitInDefaultParams();
2150 if (innerParenStart) { this.unexpected(innerParenStart); }
2151 this.yieldPos = oldYieldPos;
2152 this.awaitPos = oldAwaitPos;
2153 return this.parseParenArrowList(startPos, startLoc, exprList)
2154 }
2155
2156 if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
2157 if (spreadStart) { this.unexpected(spreadStart); }
2158 this.checkExpressionErrors(refDestructuringErrors, true);
2159 this.yieldPos = oldYieldPos || this.yieldPos;
2160 this.awaitPos = oldAwaitPos || this.awaitPos;
2161
2162 if (exprList.length > 1) {
2163 val = this.startNodeAt(innerStartPos, innerStartLoc);
2164 val.expressions = exprList;
2165 this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
2166 } else {
2167 val = exprList[0];
2168 }
2169 } else {
2170 val = this.parseParenExpression();
2171 }
2172
2173 if (this.options.preserveParens) {
2174 var par = this.startNodeAt(startPos, startLoc);
2175 par.expression = val;
2176 return this.finishNode(par, "ParenthesizedExpression")
2177 } else {
2178 return val
2179 }
2180};
2181
2182pp$3.parseParenItem = function(item) {
2183 return item
2184};
2185
2186pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
2187 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
2188};
2189
2190// New's precedence is slightly tricky. It must allow its argument to
2191// be a `[]` or dot subscript expression, but not a call — at least,
2192// not without wrapping it in parentheses. Thus, it uses the noCalls
2193// argument to parseSubscripts to prevent it from consuming the
2194// argument list.
2195
2196var empty$1 = [];
2197
2198pp$3.parseNew = function() {
2199 var node = this.startNode();
2200 var meta = this.parseIdent(true);
2201 if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
2202 node.meta = meta;
2203 node.property = this.parseIdent(true);
2204 if (node.property.name !== "target")
2205 { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
2206 if (!this.inFunction)
2207 { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
2208 return this.finishNode(node, "MetaProperty")
2209 }
2210 var startPos = this.start, startLoc = this.startLoc;
2211 node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
2212 if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
2213 else { node.arguments = empty$1; }
2214 return this.finishNode(node, "NewExpression")
2215};
2216
2217// Parse template expression.
2218
2219pp$3.parseTemplateElement = function(ref) {
2220 var isTagged = ref.isTagged;
2221
2222 var elem = this.startNode();
2223 if (this.type === types.invalidTemplate) {
2224 if (!isTagged) {
2225 this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
2226 }
2227 elem.value = {
2228 raw: this.value,
2229 cooked: null
2230 };
2231 } else {
2232 elem.value = {
2233 raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
2234 cooked: this.value
2235 };
2236 }
2237 this.next();
2238 elem.tail = this.type === types.backQuote;
2239 return this.finishNode(elem, "TemplateElement")
2240};
2241
2242pp$3.parseTemplate = function(ref) {
2243 var this$1 = this;
2244 if ( ref === void 0 ) ref = {};
2245 var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
2246
2247 var node = this.startNode();
2248 this.next();
2249 node.expressions = [];
2250 var curElt = this.parseTemplateElement({isTagged: isTagged});
2251 node.quasis = [curElt];
2252 while (!curElt.tail) {
2253 this$1.expect(types.dollarBraceL);
2254 node.expressions.push(this$1.parseExpression());
2255 this$1.expect(types.braceR);
2256 node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
2257 }
2258 this.next();
2259 return this.finishNode(node, "TemplateLiteral")
2260};
2261
2262// Parse an object literal or binding pattern.
2263
2264pp$3.isAsyncProp = function(prop) {
2265 return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
2266 (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword) &&
2267 !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
2268};
2269
2270pp$3.parseObj = function(isPattern, refDestructuringErrors) {
2271 var this$1 = this;
2272
2273 var node = this.startNode(), first = true, propHash = {};
2274 node.properties = [];
2275 this.next();
2276 while (!this.eat(types.braceR)) {
2277 if (!first) {
2278 this$1.expect(types.comma);
2279 if (this$1.afterTrailingComma(types.braceR)) { break }
2280 } else { first = false; }
2281
2282 var prop = this$1.startNode(), isGenerator = (void 0), isAsync = (void 0), startPos = (void 0), startLoc = (void 0);
2283 if (this$1.options.ecmaVersion >= 6) {
2284 prop.method = false;
2285 prop.shorthand = false;
2286 if (isPattern || refDestructuringErrors) {
2287 startPos = this$1.start;
2288 startLoc = this$1.startLoc;
2289 }
2290 if (!isPattern)
2291 { isGenerator = this$1.eat(types.star); }
2292 }
2293 this$1.parsePropertyName(prop);
2294 if (!isPattern && this$1.options.ecmaVersion >= 8 && !isGenerator && this$1.isAsyncProp(prop)) {
2295 isAsync = true;
2296 this$1.parsePropertyName(prop, refDestructuringErrors);
2297 } else {
2298 isAsync = false;
2299 }
2300 this$1.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
2301 this$1.checkPropClash(prop, propHash);
2302 node.properties.push(this$1.finishNode(prop, "Property"));
2303 }
2304 return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
2305};
2306
2307pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) {
2308 if ((isGenerator || isAsync) && this.type === types.colon)
2309 { this.unexpected(); }
2310
2311 if (this.eat(types.colon)) {
2312 prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
2313 prop.kind = "init";
2314 } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
2315 if (isPattern) { this.unexpected(); }
2316 prop.kind = "init";
2317 prop.method = true;
2318 prop.value = this.parseMethod(isGenerator, isAsync);
2319 } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
2320 (prop.key.name === "get" || prop.key.name === "set") &&
2321 (this.type != types.comma && this.type != types.braceR)) {
2322 if (isGenerator || isAsync || isPattern) { this.unexpected(); }
2323 prop.kind = prop.key.name;
2324 this.parsePropertyName(prop);
2325 prop.value = this.parseMethod(false);
2326 var paramCount = prop.kind === "get" ? 0 : 1;
2327 if (prop.value.params.length !== paramCount) {
2328 var start = prop.value.start;
2329 if (prop.kind === "get")
2330 { this.raiseRecoverable(start, "getter should have no params"); }
2331 else
2332 { this.raiseRecoverable(start, "setter should have exactly one param"); }
2333 } else {
2334 if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
2335 { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
2336 }
2337 } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
2338 this.checkUnreserved(prop.key);
2339 prop.kind = "init";
2340 if (isPattern) {
2341 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2342 } else if (this.type === types.eq && refDestructuringErrors) {
2343 if (refDestructuringErrors.shorthandAssign < 0)
2344 { refDestructuringErrors.shorthandAssign = this.start; }
2345 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2346 } else {
2347 prop.value = prop.key;
2348 }
2349 prop.shorthand = true;
2350 } else { this.unexpected(); }
2351};
2352
2353pp$3.parsePropertyName = function(prop) {
2354 if (this.options.ecmaVersion >= 6) {
2355 if (this.eat(types.bracketL)) {
2356 prop.computed = true;
2357 prop.key = this.parseMaybeAssign();
2358 this.expect(types.bracketR);
2359 return prop.key
2360 } else {
2361 prop.computed = false;
2362 }
2363 }
2364 return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
2365};
2366
2367// Initialize empty function node.
2368
2369pp$3.initFunction = function(node) {
2370 node.id = null;
2371 if (this.options.ecmaVersion >= 6) {
2372 node.generator = false;
2373 node.expression = false;
2374 }
2375 if (this.options.ecmaVersion >= 8)
2376 { node.async = false; }
2377};
2378
2379// Parse object or class method.
2380
2381pp$3.parseMethod = function(isGenerator, isAsync) {
2382 var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
2383 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
2384
2385 this.initFunction(node);
2386 if (this.options.ecmaVersion >= 6)
2387 { node.generator = isGenerator; }
2388 if (this.options.ecmaVersion >= 8)
2389 { node.async = !!isAsync; }
2390
2391 this.inGenerator = node.generator;
2392 this.inAsync = node.async;
2393 this.yieldPos = 0;
2394 this.awaitPos = 0;
2395 this.inFunction = true;
2396 this.enterFunctionScope();
2397
2398 this.expect(types.parenL);
2399 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
2400 this.checkYieldAwaitInDefaultParams();
2401 this.parseFunctionBody(node, false);
2402
2403 this.inGenerator = oldInGen;
2404 this.inAsync = oldInAsync;
2405 this.yieldPos = oldYieldPos;
2406 this.awaitPos = oldAwaitPos;
2407 this.inFunction = oldInFunc;
2408 return this.finishNode(node, "FunctionExpression")
2409};
2410
2411// Parse arrow function expression with given parameters.
2412
2413pp$3.parseArrowExpression = function(node, params, isAsync) {
2414 var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
2415 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
2416
2417 this.enterFunctionScope();
2418 this.initFunction(node);
2419 if (this.options.ecmaVersion >= 8)
2420 { node.async = !!isAsync; }
2421
2422 this.inGenerator = false;
2423 this.inAsync = node.async;
2424 this.yieldPos = 0;
2425 this.awaitPos = 0;
2426 this.inFunction = true;
2427
2428 node.params = this.toAssignableList(params, true);
2429 this.parseFunctionBody(node, true);
2430
2431 this.inGenerator = oldInGen;
2432 this.inAsync = oldInAsync;
2433 this.yieldPos = oldYieldPos;
2434 this.awaitPos = oldAwaitPos;
2435 this.inFunction = oldInFunc;
2436 return this.finishNode(node, "ArrowFunctionExpression")
2437};
2438
2439// Parse function body and check parameters.
2440
2441pp$3.parseFunctionBody = function(node, isArrowFunction) {
2442 var isExpression = isArrowFunction && this.type !== types.braceL;
2443 var oldStrict = this.strict, useStrict = false;
2444
2445 if (isExpression) {
2446 node.body = this.parseMaybeAssign();
2447 node.expression = true;
2448 this.checkParams(node, false);
2449 } else {
2450 var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
2451 if (!oldStrict || nonSimple) {
2452 useStrict = this.strictDirective(this.end);
2453 // If this is a strict mode function, verify that argument names
2454 // are not repeated, and it does not try to bind the words `eval`
2455 // or `arguments`.
2456 if (useStrict && nonSimple)
2457 { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
2458 }
2459 // Start a new scope with regard to labels and the `inFunction`
2460 // flag (restore them to their old value afterwards).
2461 var oldLabels = this.labels;
2462 this.labels = [];
2463 if (useStrict) { this.strict = true; }
2464
2465 // Add the params to varDeclaredNames to ensure that an error is thrown
2466 // if a let/const declaration in the function clashes with one of the params.
2467 this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
2468 node.body = this.parseBlock(false);
2469 node.expression = false;
2470 this.labels = oldLabels;
2471 }
2472 this.exitFunctionScope();
2473
2474 if (this.strict && node.id) {
2475 // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
2476 this.checkLVal(node.id, "none");
2477 }
2478 this.strict = oldStrict;
2479};
2480
2481pp$3.isSimpleParamList = function(params) {
2482 for (var i = 0, list = params; i < list.length; i += 1)
2483 {
2484 var param = list[i];
2485
2486 if (param.type !== "Identifier") { return false
2487 } }
2488 return true
2489};
2490
2491// Checks function params for various disallowed patterns such as using "eval"
2492// or "arguments" and duplicate parameters.
2493
2494pp$3.checkParams = function(node, allowDuplicates) {
2495 var this$1 = this;
2496
2497 var nameHash = {};
2498 for (var i = 0, list = node.params; i < list.length; i += 1)
2499 {
2500 var param = list[i];
2501
2502 this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
2503 }
2504};
2505
2506// Parses a comma-separated list of expressions, and returns them as
2507// an array. `close` is the token type that ends the list, and
2508// `allowEmpty` can be turned on to allow subsequent commas with
2509// nothing in between them to be parsed as `null` (which is needed
2510// for array literals).
2511
2512pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
2513 var this$1 = this;
2514
2515 var elts = [], first = true;
2516 while (!this.eat(close)) {
2517 if (!first) {
2518 this$1.expect(types.comma);
2519 if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
2520 } else { first = false; }
2521
2522 var elt = (void 0);
2523 if (allowEmpty && this$1.type === types.comma)
2524 { elt = null; }
2525 else if (this$1.type === types.ellipsis) {
2526 elt = this$1.parseSpread(refDestructuringErrors);
2527 if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
2528 { refDestructuringErrors.trailingComma = this$1.start; }
2529 } else {
2530 elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
2531 }
2532 elts.push(elt);
2533 }
2534 return elts
2535};
2536
2537// Parse the next token as an identifier. If `liberal` is true (used
2538// when parsing properties), it will also convert keywords into
2539// identifiers.
2540
2541pp$3.checkUnreserved = function(ref) {
2542 var start = ref.start;
2543 var end = ref.end;
2544 var name = ref.name;
2545
2546 if (this.inGenerator && name === "yield")
2547 { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
2548 if (this.inAsync && name === "await")
2549 { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
2550 if (this.isKeyword(name))
2551 { this.raise(start, ("Unexpected keyword '" + name + "'")); }
2552 if (this.options.ecmaVersion < 6 &&
2553 this.input.slice(start, end).indexOf("\\") != -1) { return }
2554 var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
2555 if (re.test(name))
2556 { this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved")); }
2557};
2558
2559pp$3.parseIdent = function(liberal, isBinding) {
2560 var node = this.startNode();
2561 if (liberal && this.options.allowReserved == "never") { liberal = false; }
2562 if (this.type === types.name) {
2563 node.name = this.value;
2564 } else if (this.type.keyword) {
2565 node.name = this.type.keyword;
2566 } else {
2567 this.unexpected();
2568 }
2569 this.next();
2570 this.finishNode(node, "Identifier");
2571 if (!liberal) { this.checkUnreserved(node); }
2572 return node
2573};
2574
2575// Parses yield expression inside generator.
2576
2577pp$3.parseYield = function() {
2578 if (!this.yieldPos) { this.yieldPos = this.start; }
2579
2580 var node = this.startNode();
2581 this.next();
2582 if (this.type == types.semi || this.canInsertSemicolon() || (this.type != types.star && !this.type.startsExpr)) {
2583 node.delegate = false;
2584 node.argument = null;
2585 } else {
2586 node.delegate = this.eat(types.star);
2587 node.argument = this.parseMaybeAssign();
2588 }
2589 return this.finishNode(node, "YieldExpression")
2590};
2591
2592pp$3.parseAwait = function() {
2593 if (!this.awaitPos) { this.awaitPos = this.start; }
2594
2595 var node = this.startNode();
2596 this.next();
2597 node.argument = this.parseMaybeUnary(null, true);
2598 return this.finishNode(node, "AwaitExpression")
2599};
2600
2601var pp$4 = Parser.prototype;
2602
2603// This function is used to raise exceptions on parse errors. It
2604// takes an offset integer (into the current `input`) to indicate
2605// the location of the error, attaches the position to the end
2606// of the error message, and then raises a `SyntaxError` with that
2607// message.
2608
2609pp$4.raise = function(pos, message) {
2610 var loc = getLineInfo(this.input, pos);
2611 message += " (" + loc.line + ":" + loc.column + ")";
2612 var err = new SyntaxError(message);
2613 err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
2614 throw err
2615};
2616
2617pp$4.raiseRecoverable = pp$4.raise;
2618
2619pp$4.curPosition = function() {
2620 if (this.options.locations) {
2621 return new Position(this.curLine, this.pos - this.lineStart)
2622 }
2623};
2624
2625var pp$5 = Parser.prototype;
2626
2627// Object.assign polyfill
2628var assign = Object.assign || function(target) {
2629 var sources = [], len = arguments.length - 1;
2630 while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
2631
2632 for (var i = 0, list = sources; i < list.length; i += 1) {
2633 var source = list[i];
2634
2635 for (var key in source) {
2636 if (has(source, key)) {
2637 target[key] = source[key];
2638 }
2639 }
2640 }
2641 return target
2642};
2643
2644// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
2645
2646pp$5.enterFunctionScope = function() {
2647 // var: a hash of var-declared names in the current lexical scope
2648 // lexical: a hash of lexically-declared names in the current lexical scope
2649 // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
2650 // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
2651 this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
2652};
2653
2654pp$5.exitFunctionScope = function() {
2655 this.scopeStack.pop();
2656};
2657
2658pp$5.enterLexicalScope = function() {
2659 var parentScope = this.scopeStack[this.scopeStack.length - 1];
2660 var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
2661
2662 this.scopeStack.push(childScope);
2663 assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
2664};
2665
2666pp$5.exitLexicalScope = function() {
2667 var childScope = this.scopeStack.pop();
2668 var parentScope = this.scopeStack[this.scopeStack.length - 1];
2669
2670 assign(parentScope.childVar, childScope.var, childScope.childVar);
2671};
2672
2673/**
2674 * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
2675 * in the current lexical scope or any of the parent lexical scopes in this function.
2676 */
2677pp$5.canDeclareVarName = function(name) {
2678 var currentScope = this.scopeStack[this.scopeStack.length - 1];
2679
2680 return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
2681};
2682
2683/**
2684 * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
2685 * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
2686 * any child lexical scopes in this function.
2687 */
2688pp$5.canDeclareLexicalName = function(name) {
2689 var currentScope = this.scopeStack[this.scopeStack.length - 1];
2690
2691 return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
2692};
2693
2694pp$5.declareVarName = function(name) {
2695 this.scopeStack[this.scopeStack.length - 1].var[name] = true;
2696};
2697
2698pp$5.declareLexicalName = function(name) {
2699 this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
2700};
2701
2702var Node = function Node(parser, pos, loc) {
2703 this.type = "";
2704 this.start = pos;
2705 this.end = 0;
2706 if (parser.options.locations)
2707 { this.loc = new SourceLocation(parser, loc); }
2708 if (parser.options.directSourceFile)
2709 { this.sourceFile = parser.options.directSourceFile; }
2710 if (parser.options.ranges)
2711 { this.range = [pos, 0]; }
2712};
2713
2714// Start an AST node, attaching a start offset.
2715
2716var pp$6 = Parser.prototype;
2717
2718pp$6.startNode = function() {
2719 return new Node(this, this.start, this.startLoc)
2720};
2721
2722pp$6.startNodeAt = function(pos, loc) {
2723 return new Node(this, pos, loc)
2724};
2725
2726// Finish an AST node, adding `type` and `end` properties.
2727
2728function finishNodeAt(node, type, pos, loc) {
2729 node.type = type;
2730 node.end = pos;
2731 if (this.options.locations)
2732 { node.loc.end = loc; }
2733 if (this.options.ranges)
2734 { node.range[1] = pos; }
2735 return node
2736}
2737
2738pp$6.finishNode = function(node, type) {
2739 return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
2740};
2741
2742// Finish node at given position
2743
2744pp$6.finishNodeAt = function(node, type, pos, loc) {
2745 return finishNodeAt.call(this, node, type, pos, loc)
2746};
2747
2748// The algorithm used to determine whether a regexp can appear at a
2749// given point in the program is loosely based on sweet.js' approach.
2750// See https://github.com/mozilla/sweet.js/wiki/design
2751
2752var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
2753 this.token = token;
2754 this.isExpr = !!isExpr;
2755 this.preserveSpace = !!preserveSpace;
2756 this.override = override;
2757 this.generator = !!generator;
2758};
2759
2760var types$1 = {
2761 b_stat: new TokContext("{", false),
2762 b_expr: new TokContext("{", true),
2763 b_tmpl: new TokContext("${", false),
2764 p_stat: new TokContext("(", false),
2765 p_expr: new TokContext("(", true),
2766 q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
2767 f_stat: new TokContext("function", false),
2768 f_expr: new TokContext("function", true),
2769 f_expr_gen: new TokContext("function", true, false, null, true),
2770 f_gen: new TokContext("function", false, false, null, true)
2771};
2772
2773var pp$7 = Parser.prototype;
2774
2775pp$7.initialContext = function() {
2776 return [types$1.b_stat]
2777};
2778
2779pp$7.braceIsBlock = function(prevType) {
2780 var parent = this.curContext();
2781 if (parent === types$1.f_expr || parent === types$1.f_stat)
2782 { return true }
2783 if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
2784 { return !parent.isExpr }
2785
2786 // The check for `tt.name && exprAllowed` detects whether we are
2787 // after a `yield` or `of` construct. See the `updateContext` for
2788 // `tt.name`.
2789 if (prevType === types._return || prevType == types.name && this.exprAllowed)
2790 { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
2791 if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType == types.arrow)
2792 { return true }
2793 if (prevType == types.braceL)
2794 { return parent === types$1.b_stat }
2795 if (prevType == types._var || prevType == types.name)
2796 { return false }
2797 return !this.exprAllowed
2798};
2799
2800pp$7.inGeneratorContext = function() {
2801 var this$1 = this;
2802
2803 for (var i = this.context.length - 1; i >= 1; i--) {
2804 var context = this$1.context[i];
2805 if (context.token === "function")
2806 { return context.generator }
2807 }
2808 return false
2809};
2810
2811pp$7.updateContext = function(prevType) {
2812 var update, type = this.type;
2813 if (type.keyword && prevType == types.dot)
2814 { this.exprAllowed = false; }
2815 else if (update = type.updateContext)
2816 { update.call(this, prevType); }
2817 else
2818 { this.exprAllowed = type.beforeExpr; }
2819};
2820
2821// Token-specific context update code
2822
2823types.parenR.updateContext = types.braceR.updateContext = function() {
2824 if (this.context.length == 1) {
2825 this.exprAllowed = true;
2826 return
2827 }
2828 var out = this.context.pop();
2829 if (out === types$1.b_stat && this.curContext().token === "function") {
2830 out = this.context.pop();
2831 }
2832 this.exprAllowed = !out.isExpr;
2833};
2834
2835types.braceL.updateContext = function(prevType) {
2836 this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
2837 this.exprAllowed = true;
2838};
2839
2840types.dollarBraceL.updateContext = function() {
2841 this.context.push(types$1.b_tmpl);
2842 this.exprAllowed = true;
2843};
2844
2845types.parenL.updateContext = function(prevType) {
2846 var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
2847 this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
2848 this.exprAllowed = true;
2849};
2850
2851types.incDec.updateContext = function() {
2852 // tokExprAllowed stays unchanged
2853};
2854
2855types._function.updateContext = types._class.updateContext = function(prevType) {
2856 if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
2857 !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
2858 { this.context.push(types$1.f_expr); }
2859 else
2860 { this.context.push(types$1.f_stat); }
2861 this.exprAllowed = false;
2862};
2863
2864types.backQuote.updateContext = function() {
2865 if (this.curContext() === types$1.q_tmpl)
2866 { this.context.pop(); }
2867 else
2868 { this.context.push(types$1.q_tmpl); }
2869 this.exprAllowed = false;
2870};
2871
2872types.star.updateContext = function(prevType) {
2873 if (prevType == types._function) {
2874 var index = this.context.length - 1;
2875 if (this.context[index] === types$1.f_expr)
2876 { this.context[index] = types$1.f_expr_gen; }
2877 else
2878 { this.context[index] = types$1.f_gen; }
2879 }
2880 this.exprAllowed = true;
2881};
2882
2883types.name.updateContext = function(prevType) {
2884 var allowed = false;
2885 if (this.options.ecmaVersion >= 6) {
2886 if (this.value == "of" && !this.exprAllowed ||
2887 this.value == "yield" && this.inGeneratorContext())
2888 { allowed = true; }
2889 }
2890 this.exprAllowed = allowed;
2891};
2892
2893// Object type used to represent tokens. Note that normally, tokens
2894// simply exist as properties on the parser object. This is only
2895// used for the onToken callback and the external tokenizer.
2896
2897var Token = function Token(p) {
2898 this.type = p.type;
2899 this.value = p.value;
2900 this.start = p.start;
2901 this.end = p.end;
2902 if (p.options.locations)
2903 { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
2904 if (p.options.ranges)
2905 { this.range = [p.start, p.end]; }
2906};
2907
2908// ## Tokenizer
2909
2910var pp$8 = Parser.prototype;
2911
2912// Are we running under Rhino?
2913var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
2914
2915// Move to the next token
2916
2917pp$8.next = function() {
2918 if (this.options.onToken)
2919 { this.options.onToken(new Token(this)); }
2920
2921 this.lastTokEnd = this.end;
2922 this.lastTokStart = this.start;
2923 this.lastTokEndLoc = this.endLoc;
2924 this.lastTokStartLoc = this.startLoc;
2925 this.nextToken();
2926};
2927
2928pp$8.getToken = function() {
2929 this.next();
2930 return new Token(this)
2931};
2932
2933// If we're in an ES6 environment, make parsers iterable
2934if (typeof Symbol !== "undefined")
2935 { pp$8[Symbol.iterator] = function() {
2936 var this$1 = this;
2937
2938 return {
2939 next: function () {
2940 var token = this$1.getToken();
2941 return {
2942 done: token.type === types.eof,
2943 value: token
2944 }
2945 }
2946 }
2947 }; }
2948
2949// Toggle strict mode. Re-reads the next number or string to please
2950// pedantic tests (`"use strict"; 010;` should fail).
2951
2952pp$8.curContext = function() {
2953 return this.context[this.context.length - 1]
2954};
2955
2956// Read a single token, updating the parser object's token-related
2957// properties.
2958
2959pp$8.nextToken = function() {
2960 var curContext = this.curContext();
2961 if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
2962
2963 this.start = this.pos;
2964 if (this.options.locations) { this.startLoc = this.curPosition(); }
2965 if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
2966
2967 if (curContext.override) { return curContext.override(this) }
2968 else { this.readToken(this.fullCharCodeAtPos()); }
2969};
2970
2971pp$8.readToken = function(code) {
2972 // Identifier or keyword. '\uXXXX' sequences are allowed in
2973 // identifiers, so '\' also dispatches to that.
2974 if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
2975 { return this.readWord() }
2976
2977 return this.getTokenFromCode(code)
2978};
2979
2980pp$8.fullCharCodeAtPos = function() {
2981 var code = this.input.charCodeAt(this.pos);
2982 if (code <= 0xd7ff || code >= 0xe000) { return code }
2983 var next = this.input.charCodeAt(this.pos + 1);
2984 return (code << 10) + next - 0x35fdc00
2985};
2986
2987pp$8.skipBlockComment = function() {
2988 var this$1 = this;
2989
2990 var startLoc = this.options.onComment && this.curPosition();
2991 var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
2992 if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
2993 this.pos = end + 2;
2994 if (this.options.locations) {
2995 lineBreakG.lastIndex = start;
2996 var match;
2997 while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
2998 ++this$1.curLine;
2999 this$1.lineStart = match.index + match[0].length;
3000 }
3001 }
3002 if (this.options.onComment)
3003 { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
3004 startLoc, this.curPosition()); }
3005};
3006
3007pp$8.skipLineComment = function(startSkip) {
3008 var this$1 = this;
3009
3010 var start = this.pos;
3011 var startLoc = this.options.onComment && this.curPosition();
3012 var ch = this.input.charCodeAt(this.pos += startSkip);
3013 while (this.pos < this.input.length && !isNewLine(ch)) {
3014 ch = this$1.input.charCodeAt(++this$1.pos);
3015 }
3016 if (this.options.onComment)
3017 { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
3018 startLoc, this.curPosition()); }
3019};
3020
3021// Called at the start of the parse and after every token. Skips
3022// whitespace and comments, and.
3023
3024pp$8.skipSpace = function() {
3025 var this$1 = this;
3026
3027 loop: while (this.pos < this.input.length) {
3028 var ch = this$1.input.charCodeAt(this$1.pos);
3029 switch (ch) {
3030 case 32: case 160: // ' '
3031 ++this$1.pos;
3032 break
3033 case 13:
3034 if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
3035 ++this$1.pos;
3036 }
3037 case 10: case 8232: case 8233:
3038 ++this$1.pos;
3039 if (this$1.options.locations) {
3040 ++this$1.curLine;
3041 this$1.lineStart = this$1.pos;
3042 }
3043 break
3044 case 47: // '/'
3045 switch (this$1.input.charCodeAt(this$1.pos + 1)) {
3046 case 42: // '*'
3047 this$1.skipBlockComment();
3048 break
3049 case 47:
3050 this$1.skipLineComment(2);
3051 break
3052 default:
3053 break loop
3054 }
3055 break
3056 default:
3057 if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
3058 ++this$1.pos;
3059 } else {
3060 break loop
3061 }
3062 }
3063 }
3064};
3065
3066// Called at the end of every token. Sets `end`, `val`, and
3067// maintains `context` and `exprAllowed`, and skips the space after
3068// the token, so that the next one's `start` will point at the
3069// right position.
3070
3071pp$8.finishToken = function(type, val) {
3072 this.end = this.pos;
3073 if (this.options.locations) { this.endLoc = this.curPosition(); }
3074 var prevType = this.type;
3075 this.type = type;
3076 this.value = val;
3077
3078 this.updateContext(prevType);
3079};
3080
3081// ### Token reading
3082
3083// This is the function that is called to fetch the next token. It
3084// is somewhat obscure, because it works in character codes rather
3085// than characters, and because operator parsing has been inlined
3086// into it.
3087//
3088// All in the name of speed.
3089//
3090pp$8.readToken_dot = function() {
3091 var next = this.input.charCodeAt(this.pos + 1);
3092 if (next >= 48 && next <= 57) { return this.readNumber(true) }
3093 var next2 = this.input.charCodeAt(this.pos + 2);
3094 if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
3095 this.pos += 3;
3096 return this.finishToken(types.ellipsis)
3097 } else {
3098 ++this.pos;
3099 return this.finishToken(types.dot)
3100 }
3101};
3102
3103pp$8.readToken_slash = function() { // '/'
3104 var next = this.input.charCodeAt(this.pos + 1);
3105 if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
3106 if (next === 61) { return this.finishOp(types.assign, 2) }
3107 return this.finishOp(types.slash, 1)
3108};
3109
3110pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
3111 var next = this.input.charCodeAt(this.pos + 1);
3112 var size = 1;
3113 var tokentype = code === 42 ? types.star : types.modulo;
3114
3115 // exponentiation operator ** and **=
3116 if (this.options.ecmaVersion >= 7 && next === 42) {
3117 ++size;
3118 tokentype = types.starstar;
3119 next = this.input.charCodeAt(this.pos + 2);
3120 }
3121
3122 if (next === 61) { return this.finishOp(types.assign, size + 1) }
3123 return this.finishOp(tokentype, size)
3124};
3125
3126pp$8.readToken_pipe_amp = function(code) { // '|&'
3127 var next = this.input.charCodeAt(this.pos + 1);
3128 if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
3129 if (next === 61) { return this.finishOp(types.assign, 2) }
3130 return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
3131};
3132
3133pp$8.readToken_caret = function() { // '^'
3134 var next = this.input.charCodeAt(this.pos + 1);
3135 if (next === 61) { return this.finishOp(types.assign, 2) }
3136 return this.finishOp(types.bitwiseXOR, 1)
3137};
3138
3139pp$8.readToken_plus_min = function(code) { // '+-'
3140 var next = this.input.charCodeAt(this.pos + 1);
3141 if (next === code) {
3142 if (next == 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 62 &&
3143 (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
3144 // A `-->` line comment
3145 this.skipLineComment(3);
3146 this.skipSpace();
3147 return this.nextToken()
3148 }
3149 return this.finishOp(types.incDec, 2)
3150 }
3151 if (next === 61) { return this.finishOp(types.assign, 2) }
3152 return this.finishOp(types.plusMin, 1)
3153};
3154
3155pp$8.readToken_lt_gt = function(code) { // '<>'
3156 var next = this.input.charCodeAt(this.pos + 1);
3157 var size = 1;
3158 if (next === code) {
3159 size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
3160 if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
3161 return this.finishOp(types.bitShift, size)
3162 }
3163 if (next == 33 && code == 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 45 &&
3164 this.input.charCodeAt(this.pos + 3) == 45) {
3165 // `<!--`, an XML-style comment that should be interpreted as a line comment
3166 this.skipLineComment(4);
3167 this.skipSpace();
3168 return this.nextToken()
3169 }
3170 if (next === 61) { size = 2; }
3171 return this.finishOp(types.relational, size)
3172};
3173
3174pp$8.readToken_eq_excl = function(code) { // '=!'
3175 var next = this.input.charCodeAt(this.pos + 1);
3176 if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
3177 if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
3178 this.pos += 2;
3179 return this.finishToken(types.arrow)
3180 }
3181 return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
3182};
3183
3184pp$8.getTokenFromCode = function(code) {
3185 switch (code) {
3186 // The interpretation of a dot depends on whether it is followed
3187 // by a digit or another two dots.
3188 case 46: // '.'
3189 return this.readToken_dot()
3190
3191 // Punctuation tokens.
3192 case 40: ++this.pos; return this.finishToken(types.parenL)
3193 case 41: ++this.pos; return this.finishToken(types.parenR)
3194 case 59: ++this.pos; return this.finishToken(types.semi)
3195 case 44: ++this.pos; return this.finishToken(types.comma)
3196 case 91: ++this.pos; return this.finishToken(types.bracketL)
3197 case 93: ++this.pos; return this.finishToken(types.bracketR)
3198 case 123: ++this.pos; return this.finishToken(types.braceL)
3199 case 125: ++this.pos; return this.finishToken(types.braceR)
3200 case 58: ++this.pos; return this.finishToken(types.colon)
3201 case 63: ++this.pos; return this.finishToken(types.question)
3202
3203 case 96: // '`'
3204 if (this.options.ecmaVersion < 6) { break }
3205 ++this.pos;
3206 return this.finishToken(types.backQuote)
3207
3208 case 48: // '0'
3209 var next = this.input.charCodeAt(this.pos + 1);
3210 if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
3211 if (this.options.ecmaVersion >= 6) {
3212 if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
3213 if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
3214 }
3215 // Anything else beginning with a digit is an integer, octal
3216 // number, or float.
3217 case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
3218 return this.readNumber(false)
3219
3220 // Quotes produce strings.
3221 case 34: case 39: // '"', "'"
3222 return this.readString(code)
3223
3224 // Operators are parsed inline in tiny state machines. '=' (61) is
3225 // often referred to. `finishOp` simply skips the amount of
3226 // characters it is given as second argument, and returns a token
3227 // of the type given by its first argument.
3228
3229 case 47: // '/'
3230 return this.readToken_slash()
3231
3232 case 37: case 42: // '%*'
3233 return this.readToken_mult_modulo_exp(code)
3234
3235 case 124: case 38: // '|&'
3236 return this.readToken_pipe_amp(code)
3237
3238 case 94: // '^'
3239 return this.readToken_caret()
3240
3241 case 43: case 45: // '+-'
3242 return this.readToken_plus_min(code)
3243
3244 case 60: case 62: // '<>'
3245 return this.readToken_lt_gt(code)
3246
3247 case 61: case 33: // '=!'
3248 return this.readToken_eq_excl(code)
3249
3250 case 126: // '~'
3251 return this.finishOp(types.prefix, 1)
3252 }
3253
3254 this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
3255};
3256
3257pp$8.finishOp = function(type, size) {
3258 var str = this.input.slice(this.pos, this.pos + size);
3259 this.pos += size;
3260 return this.finishToken(type, str)
3261};
3262
3263// Parse a regular expression. Some context-awareness is necessary,
3264// since a '/' inside a '[]' set does not end the expression.
3265
3266function tryCreateRegexp(src, flags, throwErrorAt, parser) {
3267 try {
3268 return new RegExp(src, flags)
3269 } catch (e) {
3270 if (throwErrorAt !== undefined) {
3271 if (e instanceof SyntaxError) { parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message); }
3272 throw e
3273 }
3274 }
3275}
3276
3277var regexpUnicodeSupport = !!tryCreateRegexp("\uffff", "u");
3278
3279pp$8.readRegexp = function() {
3280 var this$1 = this;
3281
3282 var escaped, inClass, start = this.pos;
3283 for (;;) {
3284 if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
3285 var ch = this$1.input.charAt(this$1.pos);
3286 if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
3287 if (!escaped) {
3288 if (ch === "[") { inClass = true; }
3289 else if (ch === "]" && inClass) { inClass = false; }
3290 else if (ch === "/" && !inClass) { break }
3291 escaped = ch === "\\";
3292 } else { escaped = false; }
3293 ++this$1.pos;
3294 }
3295 var content = this.input.slice(start, this.pos);
3296 ++this.pos;
3297 // Need to use `readWord1` because '\uXXXX' sequences are allowed
3298 // here (don't ask).
3299 var mods = this.readWord1();
3300 var tmp = content, tmpFlags = "";
3301 if (mods) {
3302 var validFlags = /^[gim]*$/;
3303 if (this.options.ecmaVersion >= 6) { validFlags = /^[gimuy]*$/; }
3304 if (!validFlags.test(mods)) { this.raise(start, "Invalid regular expression flag"); }
3305 if (mods.indexOf("u") >= 0) {
3306 if (regexpUnicodeSupport) {
3307 tmpFlags = "u";
3308 } else {
3309 // Replace each astral symbol and every Unicode escape sequence that
3310 // possibly represents an astral symbol or a paired surrogate with a
3311 // single ASCII symbol to avoid throwing on regular expressions that
3312 // are only valid in combination with the `/u` flag.
3313 // Note: replacing with the ASCII symbol `x` might cause false
3314 // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
3315 // perfectly valid pattern that is equivalent to `[a-b]`, but it would
3316 // be replaced by `[x-b]` which throws an error.
3317 tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
3318 code = Number("0x" + code);
3319 if (code > 0x10FFFF) { this$1.raise(start + offset + 3, "Code point out of bounds"); }
3320 return "x"
3321 });
3322 tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
3323 tmpFlags = tmpFlags.replace("u", "");
3324 }
3325 }
3326 }
3327 // Detect invalid regular expressions.
3328 var value = null;
3329 // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
3330 // so don't do detection if we are running under Rhino
3331 if (!isRhino) {
3332 tryCreateRegexp(tmp, tmpFlags, start, this);
3333 // Get a regular expression object for this pattern-flag pair, or `null` in
3334 // case the current environment doesn't support the flags it uses.
3335 value = tryCreateRegexp(content, mods);
3336 }
3337 return this.finishToken(types.regexp, {pattern: content, flags: mods, value: value})
3338};
3339
3340// Read an integer in the given radix. Return null if zero digits
3341// were read, the integer value otherwise. When `len` is given, this
3342// will return `null` unless the integer has exactly `len` digits.
3343
3344pp$8.readInt = function(radix, len) {
3345 var this$1 = this;
3346
3347 var start = this.pos, total = 0;
3348 for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
3349 var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
3350 if (code >= 97) { val = code - 97 + 10; } // a
3351 else if (code >= 65) { val = code - 65 + 10; } // A
3352 else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
3353 else { val = Infinity; }
3354 if (val >= radix) { break }
3355 ++this$1.pos;
3356 total = total * radix + val;
3357 }
3358 if (this.pos === start || len != null && this.pos - start !== len) { return null }
3359
3360 return total
3361};
3362
3363pp$8.readRadixNumber = function(radix) {
3364 this.pos += 2; // 0x
3365 var val = this.readInt(radix);
3366 if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
3367 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
3368 return this.finishToken(types.num, val)
3369};
3370
3371// Read an integer, octal integer, or floating-point number.
3372
3373pp$8.readNumber = function(startsWithDot) {
3374 var start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48;
3375 if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
3376 if (octal && this.pos == start + 1) { octal = false; }
3377 var next = this.input.charCodeAt(this.pos);
3378 if (next === 46 && !octal) { // '.'
3379 ++this.pos;
3380 this.readInt(10);
3381 isFloat = true;
3382 next = this.input.charCodeAt(this.pos);
3383 }
3384 if ((next === 69 || next === 101) && !octal) { // 'eE'
3385 next = this.input.charCodeAt(++this.pos);
3386 if (next === 43 || next === 45) { ++this.pos; } // '+-'
3387 if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
3388 isFloat = true;
3389 }
3390 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
3391
3392 var str = this.input.slice(start, this.pos), val;
3393 if (isFloat) { val = parseFloat(str); }
3394 else if (!octal || str.length === 1) { val = parseInt(str, 10); }
3395 else if (this.strict) { this.raise(start, "Invalid number"); }
3396 else if (/[89]/.test(str)) { val = parseInt(str, 10); }
3397 else { val = parseInt(str, 8); }
3398 return this.finishToken(types.num, val)
3399};
3400
3401// Read a string value, interpreting backslash-escapes.
3402
3403pp$8.readCodePoint = function() {
3404 var ch = this.input.charCodeAt(this.pos), code;
3405
3406 if (ch === 123) { // '{'
3407 if (this.options.ecmaVersion < 6) { this.unexpected(); }
3408 var codePos = ++this.pos;
3409 code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
3410 ++this.pos;
3411 if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
3412 } else {
3413 code = this.readHexChar(4);
3414 }
3415 return code
3416};
3417
3418function codePointToString(code) {
3419 // UTF-16 Decoding
3420 if (code <= 0xFFFF) { return String.fromCharCode(code) }
3421 code -= 0x10000;
3422 return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
3423}
3424
3425pp$8.readString = function(quote) {
3426 var this$1 = this;
3427
3428 var out = "", chunkStart = ++this.pos;
3429 for (;;) {
3430 if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
3431 var ch = this$1.input.charCodeAt(this$1.pos);
3432 if (ch === quote) { break }
3433 if (ch === 92) { // '\'
3434 out += this$1.input.slice(chunkStart, this$1.pos);
3435 out += this$1.readEscapedChar(false);
3436 chunkStart = this$1.pos;
3437 } else {
3438 if (isNewLine(ch)) { this$1.raise(this$1.start, "Unterminated string constant"); }
3439 ++this$1.pos;
3440 }
3441 }
3442 out += this.input.slice(chunkStart, this.pos++);
3443 return this.finishToken(types.string, out)
3444};
3445
3446// Reads template string tokens.
3447
3448var INVALID_TEMPLATE_ESCAPE_ERROR = {};
3449
3450pp$8.tryReadTemplateToken = function() {
3451 this.inTemplateElement = true;
3452 try {
3453 this.readTmplToken();
3454 } catch (err) {
3455 if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
3456 this.readInvalidTemplateToken();
3457 } else {
3458 throw err
3459 }
3460 }
3461
3462 this.inTemplateElement = false;
3463};
3464
3465pp$8.invalidStringToken = function(position, message) {
3466 if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
3467 throw INVALID_TEMPLATE_ESCAPE_ERROR
3468 } else {
3469 this.raise(position, message);
3470 }
3471};
3472
3473pp$8.readTmplToken = function() {
3474 var this$1 = this;
3475
3476 var out = "", chunkStart = this.pos;
3477 for (;;) {
3478 if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
3479 var ch = this$1.input.charCodeAt(this$1.pos);
3480 if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
3481 if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
3482 if (ch === 36) {
3483 this$1.pos += 2;
3484 return this$1.finishToken(types.dollarBraceL)
3485 } else {
3486 ++this$1.pos;
3487 return this$1.finishToken(types.backQuote)
3488 }
3489 }
3490 out += this$1.input.slice(chunkStart, this$1.pos);
3491 return this$1.finishToken(types.template, out)
3492 }
3493 if (ch === 92) { // '\'
3494 out += this$1.input.slice(chunkStart, this$1.pos);
3495 out += this$1.readEscapedChar(true);
3496 chunkStart = this$1.pos;
3497 } else if (isNewLine(ch)) {
3498 out += this$1.input.slice(chunkStart, this$1.pos);
3499 ++this$1.pos;
3500 switch (ch) {
3501 case 13:
3502 if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
3503 case 10:
3504 out += "\n";
3505 break
3506 default:
3507 out += String.fromCharCode(ch);
3508 break
3509 }
3510 if (this$1.options.locations) {
3511 ++this$1.curLine;
3512 this$1.lineStart = this$1.pos;
3513 }
3514 chunkStart = this$1.pos;
3515 } else {
3516 ++this$1.pos;
3517 }
3518 }
3519};
3520
3521// Reads a template token to search for the end, without validating any escape sequences
3522pp$8.readInvalidTemplateToken = function() {
3523 var this$1 = this;
3524
3525 for (; this.pos < this.input.length; this.pos++) {
3526 switch (this$1.input[this$1.pos]) {
3527 case "\\":
3528 ++this$1.pos;
3529 break
3530
3531 case "$":
3532 if (this$1.input[this$1.pos + 1] !== "{") {
3533 break
3534 }
3535 // falls through
3536
3537 case "`":
3538 return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
3539
3540 // no default
3541 }
3542 }
3543 this.raise(this.start, "Unterminated template");
3544};
3545
3546// Used to read escaped characters
3547
3548pp$8.readEscapedChar = function(inTemplate) {
3549 var ch = this.input.charCodeAt(++this.pos);
3550 ++this.pos;
3551 switch (ch) {
3552 case 110: return "\n" // 'n' -> '\n'
3553 case 114: return "\r" // 'r' -> '\r'
3554 case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
3555 case 117: return codePointToString(this.readCodePoint()) // 'u'
3556 case 116: return "\t" // 't' -> '\t'
3557 case 98: return "\b" // 'b' -> '\b'
3558 case 118: return "\u000b" // 'v' -> '\u000b'
3559 case 102: return "\f" // 'f' -> '\f'
3560 case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
3561 case 10: // ' \n'
3562 if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
3563 return ""
3564 default:
3565 if (ch >= 48 && ch <= 55) {
3566 var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
3567 var octal = parseInt(octalStr, 8);
3568 if (octal > 255) {
3569 octalStr = octalStr.slice(0, -1);
3570 octal = parseInt(octalStr, 8);
3571 }
3572 if (octalStr !== "0" && (this.strict || inTemplate)) {
3573 this.invalidStringToken(this.pos - 2, "Octal literal in strict mode");
3574 }
3575 this.pos += octalStr.length - 1;
3576 return String.fromCharCode(octal)
3577 }
3578 return String.fromCharCode(ch)
3579 }
3580};
3581
3582// Used to read character escape sequences ('\x', '\u', '\U').
3583
3584pp$8.readHexChar = function(len) {
3585 var codePos = this.pos;
3586 var n = this.readInt(16, len);
3587 if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
3588 return n
3589};
3590
3591// Read an identifier, and return it as a string. Sets `this.containsEsc`
3592// to whether the word contained a '\u' escape.
3593//
3594// Incrementally adds only escaped chars, adding other chunks as-is
3595// as a micro-optimization.
3596
3597pp$8.readWord1 = function() {
3598 var this$1 = this;
3599
3600 this.containsEsc = false;
3601 var word = "", first = true, chunkStart = this.pos;
3602 var astral = this.options.ecmaVersion >= 6;
3603 while (this.pos < this.input.length) {
3604 var ch = this$1.fullCharCodeAtPos();
3605 if (isIdentifierChar(ch, astral)) {
3606 this$1.pos += ch <= 0xffff ? 1 : 2;
3607 } else if (ch === 92) { // "\"
3608 this$1.containsEsc = true;
3609 word += this$1.input.slice(chunkStart, this$1.pos);
3610 var escStart = this$1.pos;
3611 if (this$1.input.charCodeAt(++this$1.pos) != 117) // "u"
3612 { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
3613 ++this$1.pos;
3614 var esc = this$1.readCodePoint();
3615 if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
3616 { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
3617 word += codePointToString(esc);
3618 chunkStart = this$1.pos;
3619 } else {
3620 break
3621 }
3622 first = false;
3623 }
3624 return word + this.input.slice(chunkStart, this.pos)
3625};
3626
3627// Read an identifier or keyword token. Will check for reserved
3628// words when necessary.
3629
3630pp$8.readWord = function() {
3631 var word = this.readWord1();
3632 var type = types.name;
3633 if (this.keywords.test(word)) {
3634 if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
3635 type = keywords$1[word];
3636 }
3637 return this.finishToken(type, word)
3638};
3639
3640// Acorn is a tiny, fast JavaScript parser written in JavaScript.
3641//
3642// Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
3643// various contributors and released under an MIT license.
3644//
3645// Git repositories for Acorn are available at
3646//
3647// http://marijnhaverbeke.nl/git/acorn
3648// https://github.com/ternjs/acorn.git
3649//
3650// Please use the [github bug tracker][ghbt] to report issues.
3651//
3652// [ghbt]: https://github.com/ternjs/acorn/issues
3653//
3654// This file defines the main parser interface. The library also comes
3655// with a [error-tolerant parser][dammit] and an
3656// [abstract syntax tree walker][walk], defined in other files.
3657//
3658// [dammit]: acorn_loose.js
3659// [walk]: util/walk.js
3660
3661var version = "5.1.2";
3662
3663// The main exported interface (under `self.acorn` when in the
3664// browser) is a `parse` function that takes a code string and
3665// returns an abstract syntax tree as specified by [Mozilla parser
3666// API][api].
3667//
3668// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
3669
3670function parse$1(input, options) {
3671 return new Parser(options, input).parse()
3672}
3673
3674// This function tries to parse a single expression at a given
3675// offset in a string. Useful for parsing mixed-language formats
3676// that embed JavaScript expressions.
3677
3678function parseExpressionAt(input, pos, options) {
3679 var p = new Parser(options, input, pos);
3680 p.nextToken();
3681 return p.parseExpression()
3682}
3683
3684// Acorn is organized as a tokenizer and a recursive-descent parser.
3685// The `tokenizer` export provides an interface to the tokenizer.
3686
3687function tokenizer(input, options) {
3688 return new Parser(options, input)
3689}
3690
3691// This is a terrible kludge to support the existing, pre-ES6
3692// interface where the loose parser module retroactively adds exports
3693// to this module.
3694var parse_dammit;
3695var LooseParser;
3696var pluginsLoose; // eslint-disable-line camelcase
3697function addLooseExports(parse, Parser$$1, plugins$$1) {
3698 parse_dammit = parse; // eslint-disable-line camelcase
3699 LooseParser = Parser$$1;
3700 pluginsLoose = plugins$$1;
3701}
3702
3703
3704
3705
3706var acorn = Object.freeze({
3707 version: version,
3708 parse: parse$1,
3709 parseExpressionAt: parseExpressionAt,
3710 tokenizer: tokenizer,
3711 get parse_dammit () { return parse_dammit; },
3712 get LooseParser () { return LooseParser; },
3713 get pluginsLoose () { return pluginsLoose; },
3714 addLooseExports: addLooseExports,
3715 Parser: Parser,
3716 plugins: plugins,
3717 defaultOptions: defaultOptions,
3718 Position: Position,
3719 SourceLocation: SourceLocation,
3720 getLineInfo: getLineInfo,
3721 Node: Node,
3722 TokenType: TokenType,
3723 tokTypes: types,
3724 keywordTypes: keywords$1,
3725 TokContext: TokContext,
3726 tokContexts: types$1,
3727 isIdentifierChar: isIdentifierChar,
3728 isIdentifierStart: isIdentifierStart,
3729 Token: Token,
3730 isNewLine: isNewLine,
3731 lineBreak: lineBreak,
3732 lineBreakG: lineBreakG,
3733 nonASCIIwhitespace: nonASCIIwhitespace
3734});
3735
3736var xhtml = {
3737 quot: '\u0022',
3738 amp: '&',
3739 apos: '\u0027',
3740 lt: '<',
3741 gt: '>',
3742 nbsp: '\u00A0',
3743 iexcl: '\u00A1',
3744 cent: '\u00A2',
3745 pound: '\u00A3',
3746 curren: '\u00A4',
3747 yen: '\u00A5',
3748 brvbar: '\u00A6',
3749 sect: '\u00A7',
3750 uml: '\u00A8',
3751 copy: '\u00A9',
3752 ordf: '\u00AA',
3753 laquo: '\u00AB',
3754 not: '\u00AC',
3755 shy: '\u00AD',
3756 reg: '\u00AE',
3757 macr: '\u00AF',
3758 deg: '\u00B0',
3759 plusmn: '\u00B1',
3760 sup2: '\u00B2',
3761 sup3: '\u00B3',
3762 acute: '\u00B4',
3763 micro: '\u00B5',
3764 para: '\u00B6',
3765 middot: '\u00B7',
3766 cedil: '\u00B8',
3767 sup1: '\u00B9',
3768 ordm: '\u00BA',
3769 raquo: '\u00BB',
3770 frac14: '\u00BC',
3771 frac12: '\u00BD',
3772 frac34: '\u00BE',
3773 iquest: '\u00BF',
3774 Agrave: '\u00C0',
3775 Aacute: '\u00C1',
3776 Acirc: '\u00C2',
3777 Atilde: '\u00C3',
3778 Auml: '\u00C4',
3779 Aring: '\u00C5',
3780 AElig: '\u00C6',
3781 Ccedil: '\u00C7',
3782 Egrave: '\u00C8',
3783 Eacute: '\u00C9',
3784 Ecirc: '\u00CA',
3785 Euml: '\u00CB',
3786 Igrave: '\u00CC',
3787 Iacute: '\u00CD',
3788 Icirc: '\u00CE',
3789 Iuml: '\u00CF',
3790 ETH: '\u00D0',
3791 Ntilde: '\u00D1',
3792 Ograve: '\u00D2',
3793 Oacute: '\u00D3',
3794 Ocirc: '\u00D4',
3795 Otilde: '\u00D5',
3796 Ouml: '\u00D6',
3797 times: '\u00D7',
3798 Oslash: '\u00D8',
3799 Ugrave: '\u00D9',
3800 Uacute: '\u00DA',
3801 Ucirc: '\u00DB',
3802 Uuml: '\u00DC',
3803 Yacute: '\u00DD',
3804 THORN: '\u00DE',
3805 szlig: '\u00DF',
3806 agrave: '\u00E0',
3807 aacute: '\u00E1',
3808 acirc: '\u00E2',
3809 atilde: '\u00E3',
3810 auml: '\u00E4',
3811 aring: '\u00E5',
3812 aelig: '\u00E6',
3813 ccedil: '\u00E7',
3814 egrave: '\u00E8',
3815 eacute: '\u00E9',
3816 ecirc: '\u00EA',
3817 euml: '\u00EB',
3818 igrave: '\u00EC',
3819 iacute: '\u00ED',
3820 icirc: '\u00EE',
3821 iuml: '\u00EF',
3822 eth: '\u00F0',
3823 ntilde: '\u00F1',
3824 ograve: '\u00F2',
3825 oacute: '\u00F3',
3826 ocirc: '\u00F4',
3827 otilde: '\u00F5',
3828 ouml: '\u00F6',
3829 divide: '\u00F7',
3830 oslash: '\u00F8',
3831 ugrave: '\u00F9',
3832 uacute: '\u00FA',
3833 ucirc: '\u00FB',
3834 uuml: '\u00FC',
3835 yacute: '\u00FD',
3836 thorn: '\u00FE',
3837 yuml: '\u00FF',
3838 OElig: '\u0152',
3839 oelig: '\u0153',
3840 Scaron: '\u0160',
3841 scaron: '\u0161',
3842 Yuml: '\u0178',
3843 fnof: '\u0192',
3844 circ: '\u02C6',
3845 tilde: '\u02DC',
3846 Alpha: '\u0391',
3847 Beta: '\u0392',
3848 Gamma: '\u0393',
3849 Delta: '\u0394',
3850 Epsilon: '\u0395',
3851 Zeta: '\u0396',
3852 Eta: '\u0397',
3853 Theta: '\u0398',
3854 Iota: '\u0399',
3855 Kappa: '\u039A',
3856 Lambda: '\u039B',
3857 Mu: '\u039C',
3858 Nu: '\u039D',
3859 Xi: '\u039E',
3860 Omicron: '\u039F',
3861 Pi: '\u03A0',
3862 Rho: '\u03A1',
3863 Sigma: '\u03A3',
3864 Tau: '\u03A4',
3865 Upsilon: '\u03A5',
3866 Phi: '\u03A6',
3867 Chi: '\u03A7',
3868 Psi: '\u03A8',
3869 Omega: '\u03A9',
3870 alpha: '\u03B1',
3871 beta: '\u03B2',
3872 gamma: '\u03B3',
3873 delta: '\u03B4',
3874 epsilon: '\u03B5',
3875 zeta: '\u03B6',
3876 eta: '\u03B7',
3877 theta: '\u03B8',
3878 iota: '\u03B9',
3879 kappa: '\u03BA',
3880 lambda: '\u03BB',
3881 mu: '\u03BC',
3882 nu: '\u03BD',
3883 xi: '\u03BE',
3884 omicron: '\u03BF',
3885 pi: '\u03C0',
3886 rho: '\u03C1',
3887 sigmaf: '\u03C2',
3888 sigma: '\u03C3',
3889 tau: '\u03C4',
3890 upsilon: '\u03C5',
3891 phi: '\u03C6',
3892 chi: '\u03C7',
3893 psi: '\u03C8',
3894 omega: '\u03C9',
3895 thetasym: '\u03D1',
3896 upsih: '\u03D2',
3897 piv: '\u03D6',
3898 ensp: '\u2002',
3899 emsp: '\u2003',
3900 thinsp: '\u2009',
3901 zwnj: '\u200C',
3902 zwj: '\u200D',
3903 lrm: '\u200E',
3904 rlm: '\u200F',
3905 ndash: '\u2013',
3906 mdash: '\u2014',
3907 lsquo: '\u2018',
3908 rsquo: '\u2019',
3909 sbquo: '\u201A',
3910 ldquo: '\u201C',
3911 rdquo: '\u201D',
3912 bdquo: '\u201E',
3913 dagger: '\u2020',
3914 Dagger: '\u2021',
3915 bull: '\u2022',
3916 hellip: '\u2026',
3917 permil: '\u2030',
3918 prime: '\u2032',
3919 Prime: '\u2033',
3920 lsaquo: '\u2039',
3921 rsaquo: '\u203A',
3922 oline: '\u203E',
3923 frasl: '\u2044',
3924 euro: '\u20AC',
3925 image: '\u2111',
3926 weierp: '\u2118',
3927 real: '\u211C',
3928 trade: '\u2122',
3929 alefsym: '\u2135',
3930 larr: '\u2190',
3931 uarr: '\u2191',
3932 rarr: '\u2192',
3933 darr: '\u2193',
3934 harr: '\u2194',
3935 crarr: '\u21B5',
3936 lArr: '\u21D0',
3937 uArr: '\u21D1',
3938 rArr: '\u21D2',
3939 dArr: '\u21D3',
3940 hArr: '\u21D4',
3941 forall: '\u2200',
3942 part: '\u2202',
3943 exist: '\u2203',
3944 empty: '\u2205',
3945 nabla: '\u2207',
3946 isin: '\u2208',
3947 notin: '\u2209',
3948 ni: '\u220B',
3949 prod: '\u220F',
3950 sum: '\u2211',
3951 minus: '\u2212',
3952 lowast: '\u2217',
3953 radic: '\u221A',
3954 prop: '\u221D',
3955 infin: '\u221E',
3956 ang: '\u2220',
3957 and: '\u2227',
3958 or: '\u2228',
3959 cap: '\u2229',
3960 cup: '\u222A',
3961 'int': '\u222B',
3962 there4: '\u2234',
3963 sim: '\u223C',
3964 cong: '\u2245',
3965 asymp: '\u2248',
3966 ne: '\u2260',
3967 equiv: '\u2261',
3968 le: '\u2264',
3969 ge: '\u2265',
3970 sub: '\u2282',
3971 sup: '\u2283',
3972 nsub: '\u2284',
3973 sube: '\u2286',
3974 supe: '\u2287',
3975 oplus: '\u2295',
3976 otimes: '\u2297',
3977 perp: '\u22A5',
3978 sdot: '\u22C5',
3979 lceil: '\u2308',
3980 rceil: '\u2309',
3981 lfloor: '\u230A',
3982 rfloor: '\u230B',
3983 lang: '\u2329',
3984 rang: '\u232A',
3985 loz: '\u25CA',
3986 spades: '\u2660',
3987 clubs: '\u2663',
3988 hearts: '\u2665',
3989 diams: '\u2666'
3990};
3991
3992'use strict';
3993
3994
3995
3996var hexNumber = /^[\da-fA-F]+$/;
3997var decimalNumber = /^\d+$/;
3998
3999var inject = function(acorn) {
4000 var tt = acorn.tokTypes;
4001 var tc = acorn.tokContexts;
4002
4003 tc.j_oTag = new acorn.TokContext('<tag', false);
4004 tc.j_cTag = new acorn.TokContext('</tag', false);
4005 tc.j_expr = new acorn.TokContext('<tag>...</tag>', true, true);
4006
4007 tt.jsxName = new acorn.TokenType('jsxName');
4008 tt.jsxText = new acorn.TokenType('jsxText', {beforeExpr: true});
4009 tt.jsxTagStart = new acorn.TokenType('jsxTagStart');
4010 tt.jsxTagEnd = new acorn.TokenType('jsxTagEnd');
4011
4012 tt.jsxTagStart.updateContext = function() {
4013 this.context.push(tc.j_expr); // treat as beginning of JSX expression
4014 this.context.push(tc.j_oTag); // start opening tag context
4015 this.exprAllowed = false;
4016 };
4017 tt.jsxTagEnd.updateContext = function(prevType) {
4018 var out = this.context.pop();
4019 if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) {
4020 this.context.pop();
4021 this.exprAllowed = this.curContext() === tc.j_expr;
4022 } else {
4023 this.exprAllowed = true;
4024 }
4025 };
4026
4027 var pp = acorn.Parser.prototype;
4028
4029 // Reads inline JSX contents token.
4030
4031 pp.jsx_readToken = function() {
4032 var out = '', chunkStart = this.pos;
4033 for (;;) {
4034 if (this.pos >= this.input.length)
4035 this.raise(this.start, 'Unterminated JSX contents');
4036 var ch = this.input.charCodeAt(this.pos);
4037
4038 switch (ch) {
4039 case 60: // '<'
4040 case 123: // '{'
4041 if (this.pos === this.start) {
4042 if (ch === 60 && this.exprAllowed) {
4043 ++this.pos;
4044 return this.finishToken(tt.jsxTagStart);
4045 }
4046 return this.getTokenFromCode(ch);
4047 }
4048 out += this.input.slice(chunkStart, this.pos);
4049 return this.finishToken(tt.jsxText, out);
4050
4051 case 38: // '&'
4052 out += this.input.slice(chunkStart, this.pos);
4053 out += this.jsx_readEntity();
4054 chunkStart = this.pos;
4055 break;
4056
4057 default:
4058 if (acorn.isNewLine(ch)) {
4059 out += this.input.slice(chunkStart, this.pos);
4060 out += this.jsx_readNewLine(true);
4061 chunkStart = this.pos;
4062 } else {
4063 ++this.pos;
4064 }
4065 }
4066 }
4067 };
4068
4069 pp.jsx_readNewLine = function(normalizeCRLF) {
4070 var ch = this.input.charCodeAt(this.pos);
4071 var out;
4072 ++this.pos;
4073 if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
4074 ++this.pos;
4075 out = normalizeCRLF ? '\n' : '\r\n';
4076 } else {
4077 out = String.fromCharCode(ch);
4078 }
4079 if (this.options.locations) {
4080 ++this.curLine;
4081 this.lineStart = this.pos;
4082 }
4083
4084 return out;
4085 };
4086
4087 pp.jsx_readString = function(quote) {
4088 var out = '', chunkStart = ++this.pos;
4089 for (;;) {
4090 if (this.pos >= this.input.length)
4091 this.raise(this.start, 'Unterminated string constant');
4092 var ch = this.input.charCodeAt(this.pos);
4093 if (ch === quote) break;
4094 if (ch === 38) { // '&'
4095 out += this.input.slice(chunkStart, this.pos);
4096 out += this.jsx_readEntity();
4097 chunkStart = this.pos;
4098 } else if (acorn.isNewLine(ch)) {
4099 out += this.input.slice(chunkStart, this.pos);
4100 out += this.jsx_readNewLine(false);
4101 chunkStart = this.pos;
4102 } else {
4103 ++this.pos;
4104 }
4105 }
4106 out += this.input.slice(chunkStart, this.pos++);
4107 return this.finishToken(tt.string, out);
4108 };
4109
4110 pp.jsx_readEntity = function() {
4111 var str = '', count = 0, entity;
4112 var ch = this.input[this.pos];
4113 if (ch !== '&')
4114 this.raise(this.pos, 'Entity must start with an ampersand');
4115 var startPos = ++this.pos;
4116 while (this.pos < this.input.length && count++ < 10) {
4117 ch = this.input[this.pos++];
4118 if (ch === ';') {
4119 if (str[0] === '#') {
4120 if (str[1] === 'x') {
4121 str = str.substr(2);
4122 if (hexNumber.test(str))
4123 entity = String.fromCharCode(parseInt(str, 16));
4124 } else {
4125 str = str.substr(1);
4126 if (decimalNumber.test(str))
4127 entity = String.fromCharCode(parseInt(str, 10));
4128 }
4129 } else {
4130 entity = xhtml[str];
4131 }
4132 break;
4133 }
4134 str += ch;
4135 }
4136 if (!entity) {
4137 this.pos = startPos;
4138 return '&';
4139 }
4140 return entity;
4141 };
4142
4143
4144 // Read a JSX identifier (valid tag or attribute name).
4145 //
4146 // Optimized version since JSX identifiers can't contain
4147 // escape characters and so can be read as single slice.
4148 // Also assumes that first character was already checked
4149 // by isIdentifierStart in readToken.
4150
4151 pp.jsx_readWord = function() {
4152 var ch, start = this.pos;
4153 do {
4154 ch = this.input.charCodeAt(++this.pos);
4155 } while (acorn.isIdentifierChar(ch) || ch === 45); // '-'
4156 return this.finishToken(tt.jsxName, this.input.slice(start, this.pos));
4157 };
4158
4159 // Transforms JSX element name to string.
4160
4161 function getQualifiedJSXName(object) {
4162 if (object.type === 'JSXIdentifier')
4163 return object.name;
4164
4165 if (object.type === 'JSXNamespacedName')
4166 return object.namespace.name + ':' + object.name.name;
4167
4168 if (object.type === 'JSXMemberExpression')
4169 return getQualifiedJSXName(object.object) + '.' +
4170 getQualifiedJSXName(object.property);
4171 }
4172
4173 // Parse next token as JSX identifier
4174
4175 pp.jsx_parseIdentifier = function() {
4176 var node = this.startNode();
4177 if (this.type === tt.jsxName)
4178 node.name = this.value;
4179 else if (this.type.keyword)
4180 node.name = this.type.keyword;
4181 else
4182 this.unexpected();
4183 this.next();
4184 return this.finishNode(node, 'JSXIdentifier');
4185 };
4186
4187 // Parse namespaced identifier.
4188
4189 pp.jsx_parseNamespacedName = function() {
4190 var startPos = this.start, startLoc = this.startLoc;
4191 var name = this.jsx_parseIdentifier();
4192 if (!this.options.plugins.jsx.allowNamespaces || !this.eat(tt.colon)) return name;
4193 var node = this.startNodeAt(startPos, startLoc);
4194 node.namespace = name;
4195 node.name = this.jsx_parseIdentifier();
4196 return this.finishNode(node, 'JSXNamespacedName');
4197 };
4198
4199 // Parses element name in any form - namespaced, member
4200 // or single identifier.
4201
4202 pp.jsx_parseElementName = function() {
4203 var startPos = this.start, startLoc = this.startLoc;
4204 var node = this.jsx_parseNamespacedName();
4205 if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !this.options.plugins.jsx.allowNamespacedObjects) {
4206 this.unexpected();
4207 }
4208 while (this.eat(tt.dot)) {
4209 var newNode = this.startNodeAt(startPos, startLoc);
4210 newNode.object = node;
4211 newNode.property = this.jsx_parseIdentifier();
4212 node = this.finishNode(newNode, 'JSXMemberExpression');
4213 }
4214 return node;
4215 };
4216
4217 // Parses any type of JSX attribute value.
4218
4219 pp.jsx_parseAttributeValue = function() {
4220 switch (this.type) {
4221 case tt.braceL:
4222 var node = this.jsx_parseExpressionContainer();
4223 if (node.expression.type === 'JSXEmptyExpression')
4224 this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression');
4225 return node;
4226
4227 case tt.jsxTagStart:
4228 case tt.string:
4229 return this.parseExprAtom();
4230
4231 default:
4232 this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
4233 }
4234 };
4235
4236 // JSXEmptyExpression is unique type since it doesn't actually parse anything,
4237 // and so it should start at the end of last read token (left brace) and finish
4238 // at the beginning of the next one (right brace).
4239
4240 pp.jsx_parseEmptyExpression = function() {
4241 var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
4242 return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
4243 };
4244
4245 // Parses JSX expression enclosed into curly brackets.
4246
4247
4248 pp.jsx_parseExpressionContainer = function() {
4249 var node = this.startNode();
4250 this.next();
4251 node.expression = this.type === tt.braceR
4252 ? this.jsx_parseEmptyExpression()
4253 : this.parseExpression();
4254 this.expect(tt.braceR);
4255 return this.finishNode(node, 'JSXExpressionContainer');
4256 };
4257
4258 // Parses following JSX attribute name-value pair.
4259
4260 pp.jsx_parseAttribute = function() {
4261 var node = this.startNode();
4262 if (this.eat(tt.braceL)) {
4263 this.expect(tt.ellipsis);
4264 node.argument = this.parseMaybeAssign();
4265 this.expect(tt.braceR);
4266 return this.finishNode(node, 'JSXSpreadAttribute');
4267 }
4268 node.name = this.jsx_parseNamespacedName();
4269 node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
4270 return this.finishNode(node, 'JSXAttribute');
4271 };
4272
4273 // Parses JSX opening tag starting after '<'.
4274
4275 pp.jsx_parseOpeningElementAt = function(startPos, startLoc) {
4276 var node = this.startNodeAt(startPos, startLoc);
4277 node.attributes = [];
4278 node.name = this.jsx_parseElementName();
4279 while (this.type !== tt.slash && this.type !== tt.jsxTagEnd)
4280 node.attributes.push(this.jsx_parseAttribute());
4281 node.selfClosing = this.eat(tt.slash);
4282 this.expect(tt.jsxTagEnd);
4283 return this.finishNode(node, 'JSXOpeningElement');
4284 };
4285
4286 // Parses JSX closing tag starting after '</'.
4287
4288 pp.jsx_parseClosingElementAt = function(startPos, startLoc) {
4289 var node = this.startNodeAt(startPos, startLoc);
4290 node.name = this.jsx_parseElementName();
4291 this.expect(tt.jsxTagEnd);
4292 return this.finishNode(node, 'JSXClosingElement');
4293 };
4294
4295 // Parses entire JSX element, including it's opening tag
4296 // (starting after '<'), attributes, contents and closing tag.
4297
4298 pp.jsx_parseElementAt = function(startPos, startLoc) {
4299 var node = this.startNodeAt(startPos, startLoc);
4300 var children = [];
4301 var openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
4302 var closingElement = null;
4303
4304 if (!openingElement.selfClosing) {
4305 contents: for (;;) {
4306 switch (this.type) {
4307 case tt.jsxTagStart:
4308 startPos = this.start; startLoc = this.startLoc;
4309 this.next();
4310 if (this.eat(tt.slash)) {
4311 closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
4312 break contents;
4313 }
4314 children.push(this.jsx_parseElementAt(startPos, startLoc));
4315 break;
4316
4317 case tt.jsxText:
4318 children.push(this.parseExprAtom());
4319 break;
4320
4321 case tt.braceL:
4322 children.push(this.jsx_parseExpressionContainer());
4323 break;
4324
4325 default:
4326 this.unexpected();
4327 }
4328 }
4329 if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
4330 this.raise(
4331 closingElement.start,
4332 'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
4333 }
4334 }
4335
4336 node.openingElement = openingElement;
4337 node.closingElement = closingElement;
4338 node.children = children;
4339 if (this.type === tt.relational && this.value === "<") {
4340 this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
4341 }
4342 return this.finishNode(node, 'JSXElement');
4343 };
4344
4345 // Parses entire JSX element from current position.
4346
4347 pp.jsx_parseElement = function() {
4348 var startPos = this.start, startLoc = this.startLoc;
4349 this.next();
4350 return this.jsx_parseElementAt(startPos, startLoc);
4351 };
4352
4353 acorn.plugins.jsx = function(instance, opts) {
4354 if (!opts) {
4355 return;
4356 }
4357
4358 if (typeof opts !== 'object') {
4359 opts = {};
4360 }
4361
4362 instance.options.plugins.jsx = {
4363 allowNamespaces: opts.allowNamespaces !== false,
4364 allowNamespacedObjects: !!opts.allowNamespacedObjects
4365 };
4366
4367 instance.extend('parseExprAtom', function(inner) {
4368 return function(refShortHandDefaultPos) {
4369 if (this.type === tt.jsxText)
4370 return this.parseLiteral(this.value);
4371 else if (this.type === tt.jsxTagStart)
4372 return this.jsx_parseElement();
4373 else
4374 return inner.call(this, refShortHandDefaultPos);
4375 };
4376 });
4377
4378 instance.extend('readToken', function(inner) {
4379 return function(code) {
4380 var context = this.curContext();
4381
4382 if (context === tc.j_expr) return this.jsx_readToken();
4383
4384 if (context === tc.j_oTag || context === tc.j_cTag) {
4385 if (acorn.isIdentifierStart(code)) return this.jsx_readWord();
4386
4387 if (code == 62) {
4388 ++this.pos;
4389 return this.finishToken(tt.jsxTagEnd);
4390 }
4391
4392 if ((code === 34 || code === 39) && context == tc.j_oTag)
4393 return this.jsx_readString(code);
4394 }
4395
4396 if (code === 60 && this.exprAllowed) {
4397 ++this.pos;
4398 return this.finishToken(tt.jsxTagStart);
4399 }
4400 return inner.call(this, code);
4401 };
4402 });
4403
4404 instance.extend('updateContext', function(inner) {
4405 return function(prevType) {
4406 if (this.type == tt.braceL) {
4407 var curContext = this.curContext();
4408 if (curContext == tc.j_oTag) this.context.push(tc.b_expr);
4409 else if (curContext == tc.j_expr) this.context.push(tc.b_tmpl);
4410 else inner.call(this, prevType);
4411 this.exprAllowed = true;
4412 } else if (this.type === tt.slash && prevType === tt.jsxTagStart) {
4413 this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
4414 this.context.push(tc.j_cTag); // reconsider as closing tag context
4415 this.exprAllowed = false;
4416 } else {
4417 return inner.call(this, prevType);
4418 }
4419 };
4420 });
4421 };
4422
4423 return acorn;
4424};
4425
4426'use strict';
4427
4428var inject$1 = function(acorn) {
4429 if (acorn.version.substr(0, 1) !== "5") {
4430 throw new Error("Unsupported acorn version " + acorn.version + ", please use acorn 5");
4431 }
4432 var tt = acorn.tokTypes;
4433 var pp = acorn.Parser.prototype;
4434
4435 // this is the same parseObj that acorn has with...
4436 function parseObj(isPattern, refDestructuringErrors) {
4437 let node = this.startNode(), first = true, propHash = {};
4438 node.properties = [];
4439 this.next();
4440 while (!this.eat(tt.braceR)) {
4441 if (!first) {
4442 this.expect(tt.comma);
4443 if (this.afterTrailingComma(tt.braceR)) break
4444 } else first = false;
4445
4446 let prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
4447 if (this.options.ecmaVersion >= 6) {
4448 // ...the spread logic borrowed from babylon :)
4449 if (this.type === tt.ellipsis) {
4450 prop = isPattern ? this.parseRestBinding() : this.parseSpread(refDestructuringErrors);
4451 node.properties.push(prop);
4452 if (this.type === tt.comma) {
4453 if (isPattern) {
4454 this.raise(this.start, "Comma is not permitted after the rest element");
4455 } else if (refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
4456 refDestructuringErrors.trailingComma = this.start;
4457 }
4458 }
4459 continue
4460 }
4461
4462 prop.method = false;
4463 prop.shorthand = false;
4464 if (isPattern || refDestructuringErrors) {
4465 startPos = this.start;
4466 startLoc = this.startLoc;
4467 }
4468 if (!isPattern)
4469 isGenerator = this.eat(tt.star);
4470 }
4471 this.parsePropertyName(prop);
4472 if (!isPattern && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
4473 isAsync = true;
4474 this.parsePropertyName(prop, refDestructuringErrors);
4475 } else {
4476 isAsync = false;
4477 }
4478 this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
4479 if (!isPattern) this.checkPropClash(prop, propHash);
4480 node.properties.push(this.finishNode(prop, "Property"));
4481 }
4482 return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
4483 }
4484
4485 const getCheckLVal = origCheckLVal => function (expr, bindingType, checkClashes) {
4486 if (expr.type == "ObjectPattern") {
4487 for (let prop of expr.properties)
4488 this.checkLVal(prop, bindingType, checkClashes);
4489 return
4490 } else if (expr.type === "Property") {
4491 // AssignmentProperty has type == "Property"
4492 return this.checkLVal(expr.value, bindingType, checkClashes)
4493 }
4494 return origCheckLVal.apply(this, arguments)
4495 };
4496
4497 acorn.plugins.objectSpread = function objectSpreadPlugin(instance) {
4498 pp.parseObj = parseObj;
4499 instance.extend("checkLVal", getCheckLVal);
4500 instance.extend("toAssignable", nextMethod => function(node, isBinding) {
4501 if (this.options.ecmaVersion >= 6 && node) {
4502 if (node.type == "ObjectExpression") {
4503 node.type = "ObjectPattern";
4504 for (let prop of node.properties)
4505 this.toAssignable(prop, isBinding);
4506 return node
4507 } else if (node.type === "Property") {
4508 // AssignmentProperty has type == "Property"
4509 if (node.kind !== "init") this.raise(node.key.start, "Object pattern can't contain getter or setter");
4510 return this.toAssignable(node.value, isBinding)
4511 } else if (node.type === "SpreadElement") {
4512 node.type = "RestElement";
4513 return this.toAssignable(node.argument, isBinding)
4514 }
4515 }
4516 return nextMethod.apply(this, arguments)
4517 });
4518 instance.extend("checkPatternExport", nextMethod => function(exports, pat) {
4519 if (pat.type == "ObjectPattern") {
4520 for (let prop of pat.properties)
4521 this.checkPatternExport(exports, prop);
4522 return
4523 } else if (pat.type === "Property") {
4524 return this.checkPatternExport(exports, pat.value)
4525 } else if (pat.type === "RestElement") {
4526 return this.checkPatternExport(exports, pat.argument)
4527 }
4528 nextMethod.apply(this, arguments);
4529 });
4530 };
4531
4532 return acorn;
4533};
4534
4535var keys = {
4536 Program: [ 'body' ],
4537 Literal: []
4538};
4539
4540// used for debugging, without the noise created by
4541// circular references
4542function toJSON ( node ) {
4543 var obj = {};
4544
4545 Object.keys( node ).forEach( function ( key ) {
4546 if ( key === 'parent' || key === 'program' || key === 'keys' || key === '__wrapped' ) return;
4547
4548 if ( Array.isArray( node[ key ] ) ) {
4549 obj[ key ] = node[ key ].map( toJSON );
4550 } else if ( node[ key ] && node[ key ].toJSON ) {
4551 obj[ key ] = node[ key ].toJSON();
4552 } else {
4553 obj[ key ] = node[ key ];
4554 }
4555 });
4556
4557 return obj;
4558}
4559
4560var Node$1 = function Node ( raw, parent ) {
4561 raw.parent = parent;
4562 raw.program = parent.program || parent;
4563 raw.depth = parent.depth + 1;
4564 raw.keys = keys[ raw.type ];
4565 raw.indentation = undefined;
4566
4567 for ( var i = 0, list = keys[ raw.type ]; i < list.length; i += 1 ) {
4568 var key = list[i];
4569
4570 wrap( raw[ key ], raw );
4571 }
4572
4573 raw.program.magicString.addSourcemapLocation( raw.start );
4574 raw.program.magicString.addSourcemapLocation( raw.end );
4575};
4576
4577Node$1.prototype.ancestor = function ancestor ( level ) {
4578 var node = this;
4579 while ( level-- ) {
4580 node = node.parent;
4581 if ( !node ) return null;
4582 }
4583
4584 return node;
4585};
4586
4587Node$1.prototype.contains = function contains ( node ) {
4588 var this$1 = this;
4589
4590 while ( node ) {
4591 if ( node === this$1 ) return true;
4592 node = node.parent;
4593 }
4594
4595 return false;
4596};
4597
4598Node$1.prototype.findLexicalBoundary = function findLexicalBoundary () {
4599 return this.parent.findLexicalBoundary();
4600};
4601
4602Node$1.prototype.findNearest = function findNearest ( type ) {
4603 if ( typeof type === 'string' ) type = new RegExp( ("^" + type + "$") );
4604 if ( type.test( this.type ) ) return this;
4605 return this.parent.findNearest( type );
4606};
4607
4608Node$1.prototype.unparenthesizedParent = function unparenthesizedParent () {
4609 var node = this.parent;
4610 while ( node && node.type === 'ParenthesizedExpression' ) {
4611 node = node.parent;
4612 }
4613 return node;
4614};
4615
4616Node$1.prototype.unparenthesize = function unparenthesize () {
4617 var node = this;
4618 while ( node.type === 'ParenthesizedExpression' ) {
4619 node = node.expression;
4620 }
4621 return node;
4622};
4623
4624Node$1.prototype.findScope = function findScope ( functionScope ) {
4625 return this.parent.findScope( functionScope );
4626};
4627
4628Node$1.prototype.getIndentation = function getIndentation () {
4629 return this.parent.getIndentation();
4630};
4631
4632Node$1.prototype.initialise = function initialise ( transforms ) {
4633 for ( var i = 0, list = this.keys; i < list.length; i += 1 ) {
4634 var key = list[i];
4635
4636 var value = this[ key ];
4637
4638 if ( Array.isArray( value ) ) {
4639 value.forEach( function ( node ) { return node && node.initialise( transforms ); } );
4640 } else if ( value && typeof value === 'object' ) {
4641 value.initialise( transforms );
4642 }
4643 }
4644};
4645
4646Node$1.prototype.toJSON = function toJSON$1 () {
4647 return toJSON( this );
4648};
4649
4650Node$1.prototype.toString = function toString () {
4651 return this.program.magicString.original.slice( this.start, this.end );
4652};
4653
4654Node$1.prototype.transpile = function transpile ( code, transforms ) {
4655 for ( var i = 0, list = this.keys; i < list.length; i += 1 ) {
4656 var key = list[i];
4657
4658 var value = this[ key ];
4659
4660 if ( Array.isArray( value ) ) {
4661 value.forEach( function ( node ) { return node && node.transpile( code, transforms ); } );
4662 } else if ( value && typeof value === 'object' ) {
4663 value.transpile( code, transforms );
4664 }
4665 }
4666};
4667
4668function isArguments ( node ) {
4669 return node.type === 'Identifier' && node.name === 'arguments';
4670}
4671
4672function spread ( code, elements, start, argumentsArrayAlias, isNew ) {
4673 var i = elements.length;
4674 var firstSpreadIndex = -1;
4675
4676 while ( i-- ) {
4677 var element$1 = elements[i];
4678 if ( element$1 && element$1.type === 'SpreadElement' ) {
4679 if ( isArguments( element$1.argument ) ) {
4680 code.overwrite( element$1.argument.start, element$1.argument.end, argumentsArrayAlias );
4681 }
4682
4683 firstSpreadIndex = i;
4684 }
4685 }
4686
4687 if ( firstSpreadIndex === -1 ) return false; // false indicates no spread elements
4688
4689 if (isNew) {
4690 for ( i = 0; i < elements.length; i += 1 ) {
4691 var element$2 = elements[i];
4692 if ( element$2.type === 'SpreadElement' ) {
4693 code.remove( element$2.start, element$2.argument.start );
4694 } else {
4695 code.prependRight( element$2.start, '[' );
4696 code.prependRight( element$2.end, ']' );
4697 }
4698 }
4699
4700 return true; // true indicates some spread elements
4701 }
4702
4703 var element = elements[ firstSpreadIndex ];
4704 var previousElement = elements[ firstSpreadIndex - 1 ];
4705
4706 if ( !previousElement ) {
4707 code.remove( start, element.start );
4708 code.overwrite( element.end, elements[1].start, '.concat( ' );
4709 } else {
4710 code.overwrite( previousElement.end, element.start, ' ].concat( ' );
4711 }
4712
4713 for ( i = firstSpreadIndex; i < elements.length; i += 1 ) {
4714 element = elements[i];
4715
4716 if ( element ) {
4717 if ( element.type === 'SpreadElement' ) {
4718 code.remove( element.start, element.argument.start );
4719 } else {
4720 code.appendLeft( element.start, '[' );
4721 code.appendLeft( element.end, ']' );
4722 }
4723 }
4724 }
4725
4726 return true; // true indicates some spread elements
4727}
4728
4729var ArrayExpression = (function (Node) {
4730 function ArrayExpression () {
4731 Node.apply(this, arguments);
4732 }
4733
4734 if ( Node ) ArrayExpression.__proto__ = Node;
4735 ArrayExpression.prototype = Object.create( Node && Node.prototype );
4736 ArrayExpression.prototype.constructor = ArrayExpression;
4737
4738 ArrayExpression.prototype.initialise = function initialise ( transforms ) {
4739 var this$1 = this;
4740
4741 if ( transforms.spreadRest && this.elements.length ) {
4742 var lexicalBoundary = this.findLexicalBoundary();
4743
4744 var i = this.elements.length;
4745 while ( i-- ) {
4746 var element = this$1.elements[i];
4747 if ( element && element.type === 'SpreadElement' && isArguments( element.argument ) ) {
4748 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
4749 }
4750 }
4751 }
4752
4753 Node.prototype.initialise.call( this, transforms );
4754 };
4755
4756 ArrayExpression.prototype.transpile = function transpile ( code, transforms ) {
4757 if ( transforms.spreadRest ) {
4758 // erase trailing comma after last array element if not an array hole
4759 if ( this.elements.length ) {
4760 var lastElement = this.elements[ this.elements.length - 1 ];
4761 if ( lastElement && /\s*,/.test( code.original.slice( lastElement.end, this.end ) ) ) {
4762 code.overwrite( lastElement.end, this.end - 1, ' ' );
4763 }
4764 }
4765
4766 if ( this.elements.length === 1 ) {
4767 var element = this.elements[0];
4768
4769 if ( element && element.type === 'SpreadElement' ) {
4770 // special case – [ ...arguments ]
4771 if ( isArguments( element.argument ) ) {
4772 code.overwrite( this.start, this.end, ("[].concat( " + (this.argumentsArrayAlias) + " )") ); // TODO if this is the only use of argsArray, don't bother concating
4773 } else {
4774 code.overwrite( this.start, element.argument.start, '[].concat( ' );
4775 code.overwrite( element.end, this.end, ' )' );
4776 }
4777 }
4778 }
4779 else {
4780 var hasSpreadElements = spread( code, this.elements, this.start, this.argumentsArrayAlias );
4781
4782 if ( hasSpreadElements ) {
4783 code.overwrite( this.end - 1, this.end, ')' );
4784 }
4785 }
4786 }
4787
4788 Node.prototype.transpile.call( this, code, transforms );
4789 };
4790
4791 return ArrayExpression;
4792}(Node$1));
4793
4794var ArrowFunctionExpression = (function (Node) {
4795 function ArrowFunctionExpression () {
4796 Node.apply(this, arguments);
4797 }
4798
4799 if ( Node ) ArrowFunctionExpression.__proto__ = Node;
4800 ArrowFunctionExpression.prototype = Object.create( Node && Node.prototype );
4801 ArrowFunctionExpression.prototype.constructor = ArrowFunctionExpression;
4802
4803 ArrowFunctionExpression.prototype.initialise = function initialise ( transforms ) {
4804 this.body.createScope();
4805 Node.prototype.initialise.call( this, transforms );
4806 };
4807
4808 ArrowFunctionExpression.prototype.transpile = function transpile ( code, transforms ) {
4809 if ( transforms.arrow || this.needsArguments(transforms) ) {
4810 // remove arrow
4811 var charIndex = this.body.start;
4812 while ( code.original[ charIndex ] !== '=' ) {
4813 charIndex -= 1;
4814 }
4815 code.remove( charIndex, this.body.start );
4816
4817 Node.prototype.transpile.call( this, code, transforms );
4818
4819 // wrap naked parameter
4820 if ( this.params.length === 1 && this.start === this.params[0].start ) {
4821 code.prependRight( this.params[0].start, '(' );
4822 code.appendLeft( this.params[0].end, ')' );
4823 }
4824
4825 // add function
4826 if ( this.parent && this.parent.type === 'ExpressionStatement' ) {
4827 // standalone expression statement
4828 code.prependRight( this.start, '!function' );
4829 } else {
4830 code.prependRight( this.start, 'function ' );
4831 }
4832 }
4833
4834 else {
4835 Node.prototype.transpile.call( this, code, transforms );
4836 }
4837 };
4838
4839 // Returns whether any transforms that will happen use `arguments`
4840 ArrowFunctionExpression.prototype.needsArguments = function needsArguments(transforms) {
4841 return transforms.spreadRest && this.params.filter( function ( param ) { return param.type === 'RestElement'; } ).length > 0
4842 };
4843
4844 return ArrowFunctionExpression;
4845}(Node$1));
4846
4847function locate ( source, index ) {
4848 var lines = source.split( '\n' );
4849 var len = lines.length;
4850
4851 var lineStart = 0;
4852 var i;
4853
4854 for ( i = 0; i < len; i += 1 ) {
4855 var line = lines[i];
4856 var lineEnd = lineStart + line.length + 1; // +1 for newline
4857
4858 if ( lineEnd > index ) {
4859 return { line: i + 1, column: index - lineStart, char: i };
4860 }
4861
4862 lineStart = lineEnd;
4863 }
4864
4865 throw new Error( 'Could not determine location of character' );
4866}
4867
4868function pad ( num, len ) {
4869 var result = String( num );
4870 return result + repeat( ' ', len - result.length );
4871}
4872
4873function repeat ( str, times ) {
4874 var result = '';
4875 while ( times-- ) result += str;
4876 return result;
4877}
4878
4879function getSnippet ( source, loc, length ) {
4880 if ( length === void 0 ) length = 1;
4881
4882 var first = Math.max( loc.line - 5, 0 );
4883 var last = loc.line;
4884
4885 var numDigits = String( last ).length;
4886
4887 var lines = source.split( '\n' ).slice( first, last );
4888
4889 var lastLine = lines[ lines.length - 1 ];
4890 var offset = lastLine.slice( 0, loc.column ).replace( /\t/g, ' ' ).length;
4891
4892 var snippet = lines
4893 .map( function ( line, i ) { return ((pad( i + first + 1, numDigits )) + " : " + (line.replace( /\t/g, ' '))); } )
4894 .join( '\n' );
4895
4896 snippet += '\n' + repeat( ' ', numDigits + 3 + offset ) + repeat( '^', length );
4897
4898 return snippet;
4899}
4900
4901var CompileError$1 = (function (Error) {
4902 function CompileError ( message, node ) {
4903 Error.call( this, message );
4904
4905 this.name = 'CompileError';
4906 if ( !node ) { return; }
4907
4908 var source = node.program.magicString.original;
4909 var loc = locate( source, node.start );
4910
4911 this.message = message + " (" + (loc.line) + ":" + (loc.column) + ")";
4912
4913 this.stack = new Error().stack.replace( new RegExp( (".+new " + (this.name) + ".+\\n"), 'm' ), '' );
4914
4915 this.loc = loc;
4916 this.snippet = getSnippet( source, loc, node.end - node.start );
4917 }
4918
4919 if ( Error ) CompileError.__proto__ = Error;
4920 CompileError.prototype = Object.create( Error && Error.prototype );
4921 CompileError.prototype.constructor = CompileError;
4922
4923 CompileError.prototype.toString = function toString () {
4924 return ((this.name) + ": " + (this.message) + "\n" + (this.snippet));
4925 };
4926
4927 return CompileError;
4928}(Error));
4929
4930var AssignmentExpression = (function (Node) {
4931 function AssignmentExpression () {
4932 Node.apply(this, arguments);
4933 }
4934
4935 if ( Node ) AssignmentExpression.__proto__ = Node;
4936 AssignmentExpression.prototype = Object.create( Node && Node.prototype );
4937 AssignmentExpression.prototype.constructor = AssignmentExpression;
4938
4939 AssignmentExpression.prototype.initialise = function initialise ( transforms ) {
4940 if ( this.left.type === 'Identifier' ) {
4941 var declaration = this.findScope( false ).findDeclaration( this.left.name );
4942 if ( declaration && declaration.kind === 'const' ) {
4943 throw new CompileError$1( ((this.left.name) + " is read-only"), this.left );
4944 }
4945
4946 // special case – https://gitlab.com/Rich-Harris/buble/issues/11
4947 var statement = declaration && declaration.node.ancestor( 3 );
4948 if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
4949 statement.reassigned[ this.left.name ] = true;
4950 }
4951 }
4952
4953 Node.prototype.initialise.call( this, transforms );
4954 };
4955
4956 AssignmentExpression.prototype.transpile = function transpile ( code, transforms ) {
4957 if ( this.operator === '**=' && transforms.exponentiation ) {
4958 this.transpileExponentiation( code, transforms );
4959 }
4960
4961 else if ( /Pattern/.test( this.left.type ) && transforms.destructuring ) {
4962 this.transpileDestructuring( code, transforms );
4963 }
4964
4965 Node.prototype.transpile.call( this, code, transforms );
4966 };
4967
4968 AssignmentExpression.prototype.transpileDestructuring = function transpileDestructuring ( code ) {
4969 var scope = this.findScope( true );
4970 var assign = scope.createIdentifier( 'assign' );
4971 var temporaries = [ assign ];
4972
4973 var start = this.start;
4974
4975 // We need to pick out some elements from the original code,
4976 // interleaved with generated code. These helpers are used to
4977 // easily do that while keeping the order of the output
4978 // predictable.
4979 var text = '';
4980 function use ( node ) {
4981 code.prependRight( node.start, text );
4982 code.move( node.start, node.end, start );
4983 text = '';
4984 }
4985 function write ( string ) {
4986 text += string;
4987 }
4988
4989 write( ("(" + assign + " = ") );
4990 use( this.right );
4991
4992 // Walk `pattern`, generating code that assigns the value in
4993 // `ref` to it. When `mayDuplicate` is false, the function
4994 // must take care to only output `ref` once.
4995 function destructure ( pattern, ref, mayDuplicate ) {
4996 if ( pattern.type === 'Identifier' || pattern.type === 'MemberExpression' ) {
4997 write( ', ' );
4998 use( pattern );
4999 write( (" = " + ref) );
5000 }
5001
5002 else if ( pattern.type === 'AssignmentPattern' ) {
5003 if ( pattern.left.type === 'Identifier' ) {
5004 code.remove( pattern.start, pattern.right.start );
5005
5006 var target = pattern.left.name;
5007 var source = ref;
5008 if ( !mayDuplicate ) {
5009 write( (", " + target + " = " + ref) );
5010 source = target;
5011 }
5012 write( (", " + target + " = " + source + " === void 0 ? ") );
5013 use( pattern.right );
5014 write( (" : " + source) );
5015 } else {
5016 code.remove( pattern.left.end, pattern.right.start );
5017
5018 var target$1 = scope.createIdentifier( 'temp' );
5019 var source$1 = ref;
5020 temporaries.push( target$1 );
5021 if ( !mayDuplicate ) {
5022 write( (", " + target$1 + " = " + ref) );
5023 source$1 = target$1;
5024 }
5025 write( (", " + target$1 + " = " + source$1 + " === void 0 ? ") );
5026 use( pattern.right );
5027 write( (" : " + source$1) );
5028 destructure( pattern.left, target$1, true );
5029 }
5030 }
5031
5032 else if ( pattern.type === 'ArrayPattern' ) {
5033 var elements = pattern.elements;
5034 if ( elements.length === 1 ) {
5035 code.remove( pattern.start, elements[0].start );
5036 destructure( elements[0], (ref + "[0]"), false );
5037 code.remove( elements[0].end, pattern.end );
5038 }
5039 else {
5040 if ( !mayDuplicate ) {
5041 var temp = scope.createIdentifier( 'array' );
5042 temporaries.push( temp );
5043 write( (", " + temp + " = " + ref) );
5044 ref = temp;
5045 }
5046
5047 var c = pattern.start;
5048 elements.forEach( function ( element, i ) {
5049 if (!element) return;
5050
5051 code.remove(c, element.start);
5052 c = element.end;
5053
5054 if ( element.type === 'RestElement' ) {
5055 code.remove( element.start, element.argument.start );
5056 destructure( element.argument, (ref + ".slice(" + i + ")"), false );
5057 } else {
5058 destructure( element, (ref + "[" + i + "]"), false );
5059 }
5060 });
5061
5062 code.remove(c, pattern.end);
5063 }
5064 }
5065
5066 else if ( pattern.type === 'ObjectPattern' ) {
5067 var props = pattern.properties;
5068 if ( props.length == 1 ) {
5069 var prop = props[0];
5070 var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
5071
5072 code.remove( pattern.start, prop.value.start );
5073 destructure( prop.value, value, false );
5074 code.remove( prop.end, pattern.end );
5075 }
5076 else {
5077 if ( !mayDuplicate ) {
5078 var temp$1 = scope.createIdentifier( 'obj' );
5079 temporaries.push( temp$1 );
5080 write( (", " + temp$1 + " = " + ref) );
5081 ref = temp$1;
5082 }
5083
5084 var c$1 = pattern.start;
5085
5086 props.forEach( function ( prop ) {
5087 var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
5088
5089 code.remove(c$1, prop.value.start);
5090 c$1 = prop.end;
5091
5092 destructure( prop.value, value, false );
5093 });
5094
5095 code.remove(c$1, pattern.end);
5096 }
5097 }
5098
5099 else {
5100 throw new Error( ("Unexpected node type in destructuring assignment (" + (pattern.type) + ")") );
5101 }
5102 }
5103
5104 destructure( this.left, assign, true );
5105 code.remove( this.left.end, this.right.start );
5106
5107 if ( this.unparenthesizedParent().type === 'ExpressionStatement' ) {
5108 // no rvalue needed for expression statement
5109 code.prependRight( start, (text + ")") );
5110 } else {
5111 // destructuring is part of an expression - need an rvalue
5112 code.prependRight( start, (text + ", " + assign + ")") );
5113 }
5114
5115 var statement = this.findNearest( /(?:Statement|Declaration)$/ );
5116 code.appendLeft( statement.start, ("var " + (temporaries.join( ', ' )) + ";\n" + (statement.getIndentation())) );
5117 };
5118
5119 AssignmentExpression.prototype.transpileExponentiation = function transpileExponentiation ( code ) {
5120 var scope = this.findScope( false );
5121 var getAlias = function ( name ) {
5122 var declaration = scope.findDeclaration( name );
5123 return declaration ? declaration.name : name;
5124 };
5125
5126 // first, the easy part – `**=` -> `=`
5127 var charIndex = this.left.end;
5128 while ( code.original[ charIndex ] !== '*' ) charIndex += 1;
5129 code.remove( charIndex, charIndex + 2 );
5130
5131 // how we do the next part depends on a number of factors – whether
5132 // this is a top-level statement, and whether we're updating a
5133 // simple or complex reference
5134 var base;
5135
5136 var left = this.left.unparenthesize();
5137
5138 if ( left.type === 'Identifier' ) {
5139 base = getAlias( left.name );
5140 } else if ( left.type === 'MemberExpression' ) {
5141 var object;
5142 var needsObjectVar = false;
5143 var property;
5144 var needsPropertyVar = false;
5145
5146 var statement = this.findNearest( /(?:Statement|Declaration)$/ );
5147 var i0 = statement.getIndentation();
5148
5149 if ( left.property.type === 'Identifier' ) {
5150 property = left.computed ? getAlias( left.property.name ) : left.property.name;
5151 } else {
5152 property = scope.createIdentifier( 'property' );
5153 needsPropertyVar = true;
5154 }
5155
5156 if ( left.object.type === 'Identifier' ) {
5157 object = getAlias( left.object.name );
5158 } else {
5159 object = scope.createIdentifier( 'object' );
5160 needsObjectVar = true;
5161 }
5162
5163 if ( left.start === statement.start ) {
5164 if ( needsObjectVar && needsPropertyVar ) {
5165 code.prependRight( statement.start, ("var " + object + " = ") );
5166 code.overwrite( left.object.end, left.property.start, (";\n" + i0 + "var " + property + " = ") );
5167 code.overwrite( left.property.end, left.end, (";\n" + i0 + object + "[" + property + "]") );
5168 }
5169
5170 else if ( needsObjectVar ) {
5171 code.prependRight( statement.start, ("var " + object + " = ") );
5172 code.appendLeft( left.object.end, (";\n" + i0) );
5173 code.appendLeft( left.object.end, object );
5174 }
5175
5176 else if ( needsPropertyVar ) {
5177 code.prependRight( left.property.start, ("var " + property + " = ") );
5178 code.appendLeft( left.property.end, (";\n" + i0) );
5179 code.move( left.property.start, left.property.end, this.start );
5180
5181 code.appendLeft( left.object.end, ("[" + property + "]") );
5182 code.remove( left.object.end, left.property.start );
5183 code.remove( left.property.end, left.end );
5184 }
5185 }
5186
5187 else {
5188 var declarators = [];
5189 if ( needsObjectVar ) declarators.push( object );
5190 if ( needsPropertyVar ) declarators.push( property );
5191
5192 if ( declarators.length ) {
5193 code.prependRight( statement.start, ("var " + (declarators.join( ', ' )) + ";\n" + i0) );
5194 }
5195
5196 if ( needsObjectVar && needsPropertyVar ) {
5197 code.prependRight( left.start, ("( " + object + " = ") );
5198 code.overwrite( left.object.end, left.property.start, (", " + property + " = ") );
5199 code.overwrite( left.property.end, left.end, (", " + object + "[" + property + "]") );
5200 }
5201
5202 else if ( needsObjectVar ) {
5203 code.prependRight( left.start, ("( " + object + " = ") );
5204 code.appendLeft( left.object.end, (", " + object) );
5205 }
5206
5207 else if ( needsPropertyVar ) {
5208 code.prependRight( left.property.start, ("( " + property + " = ") );
5209 code.appendLeft( left.property.end, ", " );
5210 code.move( left.property.start, left.property.end, left.start );
5211
5212 code.overwrite( left.object.end, left.property.start, ("[" + property + "]") );
5213 code.remove( left.property.end, left.end );
5214 }
5215
5216 if ( needsPropertyVar ) {
5217 code.appendLeft( this.end, " )" );
5218 }
5219 }
5220
5221 base = object + ( left.computed || needsPropertyVar ? ("[" + property + "]") : ("." + property) );
5222 }
5223
5224 code.prependRight( this.right.start, ("Math.pow( " + base + ", ") );
5225 code.appendLeft( this.right.end, " )" );
5226 };
5227
5228 return AssignmentExpression;
5229}(Node$1));
5230
5231var BinaryExpression = (function (Node) {
5232 function BinaryExpression () {
5233 Node.apply(this, arguments);
5234 }
5235
5236 if ( Node ) BinaryExpression.__proto__ = Node;
5237 BinaryExpression.prototype = Object.create( Node && Node.prototype );
5238 BinaryExpression.prototype.constructor = BinaryExpression;
5239
5240 BinaryExpression.prototype.transpile = function transpile ( code, transforms ) {
5241 if ( this.operator === '**' && transforms.exponentiation ) {
5242 code.prependRight( this.start, "Math.pow( " );
5243 code.overwrite( this.left.end, this.right.start, ", " );
5244 code.appendLeft( this.end, " )" );
5245 }
5246 Node.prototype.transpile.call( this, code, transforms );
5247 };
5248
5249 return BinaryExpression;
5250}(Node$1));
5251
5252var loopStatement = /(?:For(?:In|Of)?|While)Statement/;
5253
5254var BreakStatement = (function (Node) {
5255 function BreakStatement () {
5256 Node.apply(this, arguments);
5257 }
5258
5259 if ( Node ) BreakStatement.__proto__ = Node;
5260 BreakStatement.prototype = Object.create( Node && Node.prototype );
5261 BreakStatement.prototype.constructor = BreakStatement;
5262
5263 BreakStatement.prototype.initialise = function initialise () {
5264 var loop = this.findNearest( loopStatement );
5265 var switchCase = this.findNearest( 'SwitchCase' );
5266
5267 if ( loop && ( !switchCase || loop.depth > switchCase.depth ) ) {
5268 loop.canBreak = true;
5269 this.loop = loop;
5270 }
5271 };
5272
5273 BreakStatement.prototype.transpile = function transpile ( code ) {
5274 if ( this.loop && this.loop.shouldRewriteAsFunction ) {
5275 if ( this.label ) throw new CompileError$1( 'Labels are not currently supported in a loop with locally-scoped variables', this );
5276 code.overwrite( this.start, this.start + 5, "return 'break'" );
5277 }
5278 };
5279
5280 return BreakStatement;
5281}(Node$1));
5282
5283var CallExpression = (function (Node) {
5284 function CallExpression () {
5285 Node.apply(this, arguments);
5286 }
5287
5288 if ( Node ) CallExpression.__proto__ = Node;
5289 CallExpression.prototype = Object.create( Node && Node.prototype );
5290 CallExpression.prototype.constructor = CallExpression;
5291
5292 CallExpression.prototype.initialise = function initialise ( transforms ) {
5293 var this$1 = this;
5294
5295 if ( transforms.spreadRest && this.arguments.length > 1 ) {
5296 var lexicalBoundary = this.findLexicalBoundary();
5297
5298 var i = this.arguments.length;
5299 while ( i-- ) {
5300 var arg = this$1.arguments[i];
5301 if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
5302 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
5303 }
5304 }
5305 }
5306
5307 Node.prototype.initialise.call( this, transforms );
5308 };
5309
5310 CallExpression.prototype.transpile = function transpile ( code, transforms ) {
5311 if ( transforms.spreadRest && this.arguments.length ) {
5312 var hasSpreadElements = false;
5313 var context;
5314
5315 var firstArgument = this.arguments[0];
5316
5317 if ( this.arguments.length === 1 ) {
5318 if ( firstArgument.type === 'SpreadElement' ) {
5319 code.remove( firstArgument.start, firstArgument.argument.start );
5320 hasSpreadElements = true;
5321 }
5322 } else {
5323 hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias );
5324 }
5325
5326 if ( hasSpreadElements ) {
5327
5328 // we need to handle super() and super.method() differently
5329 // due to its instance
5330 var _super = null;
5331 if ( this.callee.type === 'Super' ) {
5332 _super = this.callee;
5333 }
5334 else if ( this.callee.type === 'MemberExpression' && this.callee.object.type === 'Super' ) {
5335 _super = this.callee.object;
5336 }
5337
5338 if ( !_super && this.callee.type === 'MemberExpression' ) {
5339 if ( this.callee.object.type === 'Identifier' ) {
5340 context = this.callee.object.name;
5341 } else {
5342 context = this.findScope( true ).createIdentifier( 'ref' );
5343 var callExpression = this.callee.object;
5344 var enclosure = callExpression.findNearest( /Function/ );
5345 var block = enclosure ? enclosure.body.body
5346 : callExpression.findNearest( /^Program$/ ).body;
5347 var lastStatementInBlock = block[ block.length - 1 ];
5348 var i0 = lastStatementInBlock.getIndentation();
5349 code.prependRight( callExpression.start, ("(" + context + " = ") );
5350 code.appendLeft( callExpression.end, ")" );
5351 code.appendLeft( lastStatementInBlock.end, ("\n" + i0 + "var " + context + ";") );
5352 }
5353 } else {
5354 context = 'void 0';
5355 }
5356
5357 code.appendLeft( this.callee.end, '.apply' );
5358
5359 if ( _super ) {
5360 _super.noCall = true; // bit hacky...
5361
5362 if ( this.arguments.length > 1 ) {
5363 if ( firstArgument.type !== 'SpreadElement' ) {
5364 code.prependRight( firstArgument.start, "[ " );
5365 }
5366
5367 code.appendLeft( this.arguments[ this.arguments.length - 1 ].end, ' )' );
5368 }
5369 }
5370
5371 else if ( this.arguments.length === 1 ) {
5372 code.prependRight( firstArgument.start, (context + ", ") );
5373 } else {
5374 if ( firstArgument.type === 'SpreadElement' ) {
5375 code.appendLeft( firstArgument.start, (context + ", ") );
5376 } else {
5377 code.appendLeft( firstArgument.start, (context + ", [ ") );
5378 }
5379
5380 code.appendLeft( this.arguments[ this.arguments.length - 1 ].end, ' )' );
5381 }
5382 }
5383 }
5384
5385 Node.prototype.transpile.call( this, code, transforms );
5386 };
5387
5388 return CallExpression;
5389}(Node$1));
5390
5391function findIndex ( array, fn ) {
5392 for ( var i = 0; i < array.length; i += 1 ) {
5393 if ( fn( array[i], i ) ) return i;
5394 }
5395
5396 return -1;
5397}
5398
5399var reserved = Object.create( null );
5400'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( ' ' )
5401 .forEach( function ( word ) { return reserved[ word ] = true; } );
5402
5403// TODO this code is pretty wild, tidy it up
5404var ClassBody = (function (Node) {
5405 function ClassBody () {
5406 Node.apply(this, arguments);
5407 }
5408
5409 if ( Node ) ClassBody.__proto__ = Node;
5410 ClassBody.prototype = Object.create( Node && Node.prototype );
5411 ClassBody.prototype.constructor = ClassBody;
5412
5413 ClassBody.prototype.transpile = function transpile ( code, transforms, inFunctionExpression, superName ) {
5414 var this$1 = this;
5415
5416 if ( transforms.classes ) {
5417 var name = this.parent.name;
5418
5419 var indentStr = code.getIndentString();
5420 var i0 = this.getIndentation() + ( inFunctionExpression ? indentStr : '' );
5421 var i1 = i0 + indentStr;
5422
5423 var constructorIndex = findIndex( this.body, function ( node ) { return node.kind === 'constructor'; } );
5424 var constructor = this.body[ constructorIndex ];
5425
5426 var introBlock = '';
5427 var outroBlock = '';
5428
5429 if ( this.body.length ) {
5430 code.remove( this.start, this.body[0].start );
5431 code.remove( this.body[ this.body.length - 1 ].end, this.end );
5432 } else {
5433 code.remove( this.start, this.end );
5434 }
5435
5436 if ( constructor ) {
5437 constructor.value.body.isConstructorBody = true;
5438
5439 var previousMethod = this.body[ constructorIndex - 1 ];
5440 var nextMethod = this.body[ constructorIndex + 1 ];
5441
5442 // ensure constructor is first
5443 if ( constructorIndex > 0 ) {
5444 code.remove( previousMethod.end, constructor.start );
5445 code.move( constructor.start, nextMethod ? nextMethod.start : this.end - 1, this.body[0].start );
5446 }
5447
5448 if ( !inFunctionExpression ) code.appendLeft( constructor.end, ';' );
5449 }
5450
5451 var namedFunctions = this.program.options.namedFunctionExpressions !== false;
5452 var namedConstructor = namedFunctions || this.parent.superClass || this.parent.type !== 'ClassDeclaration';
5453 if ( this.parent.superClass ) {
5454 var inheritanceBlock = "if ( " + superName + " ) " + name + ".__proto__ = " + superName + ";\n" + i0 + name + ".prototype = Object.create( " + superName + " && " + superName + ".prototype );\n" + i0 + name + ".prototype.constructor = " + name + ";";
5455
5456 if ( constructor ) {
5457 introBlock += "\n\n" + i0 + inheritanceBlock;
5458 } else {
5459 var fn = "function " + name + " () {" + ( superName ?
5460 ("\n" + i1 + superName + ".apply(this, arguments);\n" + i0 + "}") :
5461 "}" ) + ( inFunctionExpression ? '' : ';' ) + ( this.body.length ? ("\n\n" + i0) : '' );
5462
5463 inheritanceBlock = fn + inheritanceBlock;
5464 introBlock += inheritanceBlock + "\n\n" + i0;
5465 }
5466 } else if ( !constructor ) {
5467 var fn$1 = 'function ' + (namedConstructor ? name + ' ' : '') + '() {}';
5468 if ( this.parent.type === 'ClassDeclaration' ) fn$1 += ';';
5469 if ( this.body.length ) fn$1 += "\n\n" + i0;
5470
5471 introBlock += fn$1;
5472 }
5473
5474 var scope = this.findScope( false );
5475
5476 var prototypeGettersAndSetters = [];
5477 var staticGettersAndSetters = [];
5478 var prototypeAccessors;
5479 var staticAccessors;
5480
5481 this.body.forEach( function ( method, i ) {
5482 if ( method.kind === 'constructor' ) {
5483 var constructorName = namedConstructor ? ' ' + name : '';
5484 code.overwrite( method.key.start, method.key.end, ("function" + constructorName) );
5485 return;
5486 }
5487
5488 if ( method.static ) {
5489 var len = code.original[ method.start + 6 ] == ' ' ? 7 : 6;
5490 code.remove( method.start, method.start + len );
5491 }
5492
5493 var isAccessor = method.kind !== 'method';
5494 var lhs;
5495
5496 var methodName = method.key.name;
5497 if ( reserved[ methodName ] || method.value.body.scope.references[methodName] ) {
5498 methodName = scope.createIdentifier( methodName );
5499 }
5500
5501 // when method name is a string or a number let's pretend it's a computed method
5502
5503 var fake_computed = false;
5504 if ( ! method.computed && method.key.type === 'Literal' ) {
5505 fake_computed = true;
5506 method.computed = true;
5507 }
5508
5509 if ( isAccessor ) {
5510 if ( method.computed ) {
5511 throw new Error( 'Computed accessor properties are not currently supported' );
5512 }
5513
5514 code.remove( method.start, method.key.start );
5515
5516 if ( method.static ) {
5517 if ( !~staticGettersAndSetters.indexOf( method.key.name ) ) staticGettersAndSetters.push( method.key.name );
5518 if ( !staticAccessors ) staticAccessors = scope.createIdentifier( 'staticAccessors' );
5519
5520 lhs = "" + staticAccessors;
5521 } else {
5522 if ( !~prototypeGettersAndSetters.indexOf( method.key.name ) ) prototypeGettersAndSetters.push( method.key.name );
5523 if ( !prototypeAccessors ) prototypeAccessors = scope.createIdentifier( 'prototypeAccessors' );
5524
5525 lhs = "" + prototypeAccessors;
5526 }
5527 } else {
5528 lhs = method.static ?
5529 ("" + name) :
5530 (name + ".prototype");
5531 }
5532
5533 if ( !method.computed ) lhs += '.';
5534
5535 var insertNewlines = ( constructorIndex > 0 && i === constructorIndex + 1 ) ||
5536 ( i === 0 && constructorIndex === this$1.body.length - 1 );
5537
5538 if ( insertNewlines ) lhs = "\n\n" + i0 + lhs;
5539
5540 var c = method.key.end;
5541 if ( method.computed ) {
5542 if ( fake_computed ) {
5543 code.prependRight( method.key.start, '[' );
5544 code.appendLeft( method.key.end, ']' );
5545 } else {
5546 while ( code.original[c] !== ']' ) c += 1;
5547 c += 1;
5548 }
5549 }
5550
5551 var funcName = method.computed || isAccessor || !namedFunctions ? '' : (methodName + " ");
5552 var rhs = ( isAccessor ? ("." + (method.kind)) : '' ) + " = function" + ( method.value.generator ? '* ' : ' ' ) + funcName;
5553 code.remove( c, method.value.start );
5554 code.prependRight( method.value.start, rhs );
5555 code.appendLeft( method.end, ';' );
5556
5557 if ( method.value.generator ) code.remove( method.start, method.key.start );
5558
5559 code.prependRight( method.start, lhs );
5560 });
5561
5562 if ( prototypeGettersAndSetters.length || staticGettersAndSetters.length ) {
5563 var intro = [];
5564 var outro = [];
5565
5566 if ( prototypeGettersAndSetters.length ) {
5567 intro.push( ("var " + prototypeAccessors + " = { " + (prototypeGettersAndSetters.map( function ( name ) { return (name + ": { configurable: true }"); } ).join( ',' )) + " };") );
5568 outro.push( ("Object.defineProperties( " + name + ".prototype, " + prototypeAccessors + " );") );
5569 }
5570
5571 if ( staticGettersAndSetters.length ) {
5572 intro.push( ("var " + staticAccessors + " = { " + (staticGettersAndSetters.map( function ( name ) { return (name + ": { configurable: true }"); } ).join( ',' )) + " };") );
5573 outro.push( ("Object.defineProperties( " + name + ", " + staticAccessors + " );") );
5574 }
5575
5576 if ( constructor ) introBlock += "\n\n" + i0;
5577 introBlock += intro.join( ("\n" + i0) );
5578 if ( !constructor ) introBlock += "\n\n" + i0;
5579
5580 outroBlock += "\n\n" + i0 + outro.join( ("\n" + i0) );
5581 }
5582
5583 if ( constructor ) {
5584 code.appendLeft( constructor.end, introBlock );
5585 } else {
5586 code.prependRight( this.start, introBlock );
5587 }
5588
5589 code.appendLeft( this.end, outroBlock );
5590 }
5591
5592 Node.prototype.transpile.call( this, code, transforms );
5593 };
5594
5595 return ClassBody;
5596}(Node$1));
5597
5598// TODO this function is slightly flawed – it works on the original string,
5599// not its current edited state.
5600// That's not a problem for the way that it's currently used, but it could
5601// be in future...
5602function deindent ( node, code ) {
5603 var start = node.start;
5604 var end = node.end;
5605
5606 var indentStr = code.getIndentString();
5607 var indentStrLen = indentStr.length;
5608 var indentStart = start - indentStrLen;
5609
5610 if ( !node.program.indentExclusions[ indentStart ]
5611 && code.original.slice( indentStart, start ) === indentStr ) {
5612 code.remove( indentStart, start );
5613 }
5614
5615 var pattern = new RegExp( indentStr + '\\S', 'g' );
5616 var slice = code.original.slice( start, end );
5617 var match;
5618
5619 while ( match = pattern.exec( slice ) ) {
5620 var removeStart = start + match.index;
5621 if ( !node.program.indentExclusions[ removeStart ] ) {
5622 code.remove( removeStart, removeStart + indentStrLen );
5623 }
5624 }
5625}
5626
5627var ClassDeclaration = (function (Node) {
5628 function ClassDeclaration () {
5629 Node.apply(this, arguments);
5630 }
5631
5632 if ( Node ) ClassDeclaration.__proto__ = Node;
5633 ClassDeclaration.prototype = Object.create( Node && Node.prototype );
5634 ClassDeclaration.prototype.constructor = ClassDeclaration;
5635
5636 ClassDeclaration.prototype.initialise = function initialise ( transforms ) {
5637 this.name = this.id.name;
5638 this.findScope( true ).addDeclaration( this.id, 'class' );
5639
5640 Node.prototype.initialise.call( this, transforms );
5641 };
5642
5643 ClassDeclaration.prototype.transpile = function transpile ( code, transforms ) {
5644 if ( transforms.classes ) {
5645 if ( !this.superClass ) deindent( this.body, code );
5646
5647 var superName = this.superClass && ( this.superClass.name || 'superclass' );
5648
5649 var i0 = this.getIndentation();
5650 var i1 = i0 + code.getIndentString();
5651
5652 // if this is an export default statement, we have to move the export to
5653 // after the declaration, because `export default var Foo = ...` is illegal
5654 var syntheticDefaultExport = this.parent.type === 'ExportDefaultDeclaration' ?
5655 ("\n\n" + i0 + "export default " + (this.id.name) + ";") :
5656 '';
5657
5658 if ( syntheticDefaultExport ) code.remove( this.parent.start, this.start );
5659
5660 code.overwrite( this.start, this.id.start, 'var ' );
5661
5662 if ( this.superClass ) {
5663 if ( this.superClass.end === this.body.start ) {
5664 code.remove( this.id.end, this.superClass.start );
5665 code.appendLeft( this.id.end, (" = (function (" + superName + ") {\n" + i1) );
5666 } else {
5667 code.overwrite( this.id.end, this.superClass.start, ' = ' );
5668 code.overwrite( this.superClass.end, this.body.start, ("(function (" + superName + ") {\n" + i1) );
5669 }
5670 } else {
5671 if ( this.id.end === this.body.start ) {
5672 code.appendLeft( this.id.end, ' = ' );
5673 } else {
5674 code.overwrite( this.id.end, this.body.start, ' = ' );
5675 }
5676 }
5677
5678 this.body.transpile( code, transforms, !!this.superClass, superName );
5679
5680 if ( this.superClass ) {
5681 code.appendLeft( this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(") );
5682 code.move( this.superClass.start, this.superClass.end, this.end );
5683 code.prependRight( this.end, ("));" + syntheticDefaultExport) );
5684 } else if ( syntheticDefaultExport ) {
5685 code.prependRight( this.end, syntheticDefaultExport );
5686 }
5687 }
5688
5689 else {
5690 this.body.transpile( code, transforms, false, null );
5691 }
5692 };
5693
5694 return ClassDeclaration;
5695}(Node$1));
5696
5697var ClassExpression = (function (Node) {
5698 function ClassExpression () {
5699 Node.apply(this, arguments);
5700 }
5701
5702 if ( Node ) ClassExpression.__proto__ = Node;
5703 ClassExpression.prototype = Object.create( Node && Node.prototype );
5704 ClassExpression.prototype.constructor = ClassExpression;
5705
5706 ClassExpression.prototype.initialise = function initialise ( transforms ) {
5707 this.name = this.id ? this.id.name :
5708 this.parent.type === 'VariableDeclarator' ? this.parent.id.name :
5709 this.parent.type === 'AssignmentExpression' ? this.parent.left.name :
5710 this.findScope( true ).createIdentifier( 'anonymous' );
5711
5712 Node.prototype.initialise.call( this, transforms );
5713 };
5714
5715 ClassExpression.prototype.transpile = function transpile ( code, transforms ) {
5716 if ( transforms.classes ) {
5717 var superName = this.superClass && ( this.superClass.name || 'superclass' );
5718
5719 var i0 = this.getIndentation();
5720 var i1 = i0 + code.getIndentString();
5721
5722 if ( this.superClass ) {
5723 code.remove( this.start, this.superClass.start );
5724 code.remove( this.superClass.end, this.body.start );
5725 code.appendLeft( this.start, ("(function (" + superName + ") {\n" + i1) );
5726 } else {
5727 code.overwrite( this.start, this.body.start, ("(function () {\n" + i1) );
5728 }
5729
5730 this.body.transpile( code, transforms, true, superName );
5731
5732 var outro = "\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(";
5733
5734 if ( this.superClass ) {
5735 code.appendLeft( this.end, outro );
5736 code.move( this.superClass.start, this.superClass.end, this.end );
5737 code.prependRight( this.end, '))' );
5738 } else {
5739 code.appendLeft( this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}())") );
5740 }
5741 }
5742
5743 else {
5744 this.body.transpile( code, transforms, false );
5745 }
5746 };
5747
5748 return ClassExpression;
5749}(Node$1));
5750
5751var ContinueStatement = (function (Node) {
5752 function ContinueStatement () {
5753 Node.apply(this, arguments);
5754 }
5755
5756 if ( Node ) ContinueStatement.__proto__ = Node;
5757 ContinueStatement.prototype = Object.create( Node && Node.prototype );
5758 ContinueStatement.prototype.constructor = ContinueStatement;
5759
5760 ContinueStatement.prototype.transpile = function transpile ( code ) {
5761 var loop = this.findNearest( loopStatement );
5762 if ( loop.shouldRewriteAsFunction ) {
5763 if ( this.label ) throw new CompileError$1( 'Labels are not currently supported in a loop with locally-scoped variables', this );
5764 code.overwrite( this.start, this.start + 8, 'return' );
5765 }
5766 };
5767
5768 return ContinueStatement;
5769}(Node$1));
5770
5771var ExportDefaultDeclaration = (function (Node) {
5772 function ExportDefaultDeclaration () {
5773 Node.apply(this, arguments);
5774 }
5775
5776 if ( Node ) ExportDefaultDeclaration.__proto__ = Node;
5777 ExportDefaultDeclaration.prototype = Object.create( Node && Node.prototype );
5778 ExportDefaultDeclaration.prototype.constructor = ExportDefaultDeclaration;
5779
5780 ExportDefaultDeclaration.prototype.initialise = function initialise ( transforms ) {
5781 if ( transforms.moduleExport ) throw new CompileError$1( 'export is not supported', this );
5782 Node.prototype.initialise.call( this, transforms );
5783 };
5784
5785 return ExportDefaultDeclaration;
5786}(Node$1));
5787
5788var ExportNamedDeclaration = (function (Node) {
5789 function ExportNamedDeclaration () {
5790 Node.apply(this, arguments);
5791 }
5792
5793 if ( Node ) ExportNamedDeclaration.__proto__ = Node;
5794 ExportNamedDeclaration.prototype = Object.create( Node && Node.prototype );
5795 ExportNamedDeclaration.prototype.constructor = ExportNamedDeclaration;
5796
5797 ExportNamedDeclaration.prototype.initialise = function initialise ( transforms ) {
5798 if ( transforms.moduleExport ) throw new CompileError$1( 'export is not supported', this );
5799 Node.prototype.initialise.call( this, transforms );
5800 };
5801
5802 return ExportNamedDeclaration;
5803}(Node$1));
5804
5805var LoopStatement = (function (Node) {
5806 function LoopStatement () {
5807 Node.apply(this, arguments);
5808 }
5809
5810 if ( Node ) LoopStatement.__proto__ = Node;
5811 LoopStatement.prototype = Object.create( Node && Node.prototype );
5812 LoopStatement.prototype.constructor = LoopStatement;
5813
5814 LoopStatement.prototype.findScope = function findScope ( functionScope ) {
5815 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
5816 };
5817
5818 LoopStatement.prototype.initialise = function initialise ( transforms ) {
5819 var this$1 = this;
5820
5821 this.body.createScope();
5822 this.createdScope = true;
5823
5824 // this is populated as and when reassignments occur
5825 this.reassigned = Object.create( null );
5826 this.aliases = Object.create( null );
5827
5828 Node.prototype.initialise.call( this, transforms );
5829
5830 if ( transforms.letConst ) {
5831 // see if any block-scoped declarations are referenced
5832 // inside function expressions
5833 var names = Object.keys( this.body.scope.declarations );
5834
5835 var i = names.length;
5836 while ( i-- ) {
5837 var name = names[i];
5838 var declaration = this$1.body.scope.declarations[ name ];
5839
5840 var j = declaration.instances.length;
5841 while ( j-- ) {
5842 var instance = declaration.instances[j];
5843 var nearestFunctionExpression = instance.findNearest( /Function/ );
5844
5845 if ( nearestFunctionExpression && nearestFunctionExpression.depth > this$1.depth ) {
5846 this$1.shouldRewriteAsFunction = true;
5847 break;
5848 }
5849 }
5850
5851 if ( this$1.shouldRewriteAsFunction ) break;
5852 }
5853 }
5854 };
5855
5856 LoopStatement.prototype.transpile = function transpile ( code, transforms ) {
5857 var needsBlock = this.type != 'ForOfStatement' && (
5858 this.body.type !== 'BlockStatement'
5859 || this.body.type === 'BlockStatement' && this.body.synthetic );
5860
5861 if ( this.shouldRewriteAsFunction ) {
5862 var i0 = this.getIndentation();
5863 var i1 = i0 + code.getIndentString();
5864
5865 var argString = this.args ? (" " + (this.args.join( ', ' )) + " ") : '';
5866 var paramString = this.params ? (" " + (this.params.join( ', ' )) + " ") : '';
5867
5868 var functionScope = this.findScope( true );
5869 var loop = functionScope.createIdentifier( 'loop' );
5870
5871 var before = "var " + loop + " = function (" + paramString + ") " + ( this.body.synthetic ? ("{\n" + i0 + (code.getIndentString())) : '' );
5872 var after = ( this.body.synthetic ? ("\n" + i0 + "}") : '' ) + ";\n\n" + i0;
5873
5874 code.prependRight( this.body.start, before );
5875 code.appendLeft( this.body.end, after );
5876 code.move( this.start, this.body.start, this.body.end );
5877
5878 if ( this.canBreak || this.canReturn ) {
5879 var returned = functionScope.createIdentifier( 'returned' );
5880
5881 var insert = "{\n" + i1 + "var " + returned + " = " + loop + "(" + argString + ");\n";
5882 if ( this.canBreak ) insert += "\n" + i1 + "if ( " + returned + " === 'break' ) break;";
5883 if ( this.canReturn ) insert += "\n" + i1 + "if ( " + returned + " ) return " + returned + ".v;";
5884 insert += "\n" + i0 + "}";
5885
5886 code.prependRight( this.body.end, insert );
5887 } else {
5888 var callExpression = loop + "(" + argString + ");";
5889
5890 if ( this.type === 'DoWhileStatement' ) {
5891 code.overwrite( this.start, this.body.start, ("do {\n" + i1 + callExpression + "\n" + i0 + "}") );
5892 } else {
5893 code.prependRight( this.body.end, callExpression );
5894 }
5895 }
5896 } else if ( needsBlock ) {
5897 code.appendLeft( this.body.start, '{ ' );
5898 code.prependRight( this.body.end, ' }' );
5899 }
5900
5901 Node.prototype.transpile.call( this, code, transforms );
5902 };
5903
5904 return LoopStatement;
5905}(Node$1));
5906
5907function extractNames ( node ) {
5908 var names = [];
5909 extractors[ node.type ]( names, node );
5910 return names;
5911}
5912
5913var extractors = {
5914 Identifier: function Identifier ( names, node ) {
5915 names.push( node );
5916 },
5917
5918 ObjectPattern: function ObjectPattern ( names, node ) {
5919 for ( var i = 0, list = node.properties; i < list.length; i += 1 ) {
5920 var prop = list[i];
5921
5922 extractors[ prop.type ]( names, prop );
5923 }
5924 },
5925
5926 Property: function Property ( names, node ) {
5927 extractors[ node.value.type ]( names, node.value );
5928 },
5929
5930 RestElement: function RestElement ( names, node ) {
5931 extractors[ node.argument.type ]( names, node.argument );
5932 },
5933
5934 ArrayPattern: function ArrayPattern ( names, node ) {
5935 for ( var i = 0, list = node.elements; i < list.length; i += 1 ) {
5936 var element = list[i];
5937
5938 if ( element ) extractors[ element.type ]( names, element );
5939 }
5940 },
5941
5942 RestElement: function RestElement$1 ( names, node ) {
5943 extractors[ node.argument.type ]( names, node.argument );
5944 },
5945
5946 AssignmentPattern: function AssignmentPattern ( names, node ) {
5947 extractors[ node.left.type ]( names, node.left );
5948 }
5949};
5950
5951var ForStatement = (function (LoopStatement$$1) {
5952 function ForStatement () {
5953 LoopStatement$$1.apply(this, arguments);
5954 }
5955
5956 if ( LoopStatement$$1 ) ForStatement.__proto__ = LoopStatement$$1;
5957 ForStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
5958 ForStatement.prototype.constructor = ForStatement;
5959
5960 ForStatement.prototype.findScope = function findScope ( functionScope ) {
5961 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
5962 };
5963
5964 ForStatement.prototype.transpile = function transpile ( code, transforms ) {
5965 var this$1 = this;
5966
5967 var i1 = this.getIndentation() + code.getIndentString();
5968
5969 if ( this.shouldRewriteAsFunction ) {
5970 // which variables are declared in the init statement?
5971 var names = this.init.type === 'VariableDeclaration' ?
5972 [].concat.apply( [], this.init.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
5973 [];
5974
5975 var aliases = this.aliases;
5976
5977 this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
5978 this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
5979
5980 var updates = Object.keys( this.reassigned )
5981 .map( function ( name ) { return ((aliases[ name ].outer) + " = " + (aliases[ name ].inner) + ";"); } );
5982
5983 if ( updates.length ) {
5984 if ( this.body.synthetic ) {
5985 code.appendLeft( this.body.body[0].end, ("; " + (updates.join(" "))) );
5986 } else {
5987 var lastStatement = this.body.body[ this.body.body.length - 1 ];
5988 code.appendLeft( lastStatement.end, ("\n\n" + i1 + (updates.join(("\n" + i1)))) );
5989 }
5990 }
5991 }
5992
5993 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
5994 };
5995
5996 return ForStatement;
5997}(LoopStatement));
5998
5999var ForInStatement = (function (LoopStatement$$1) {
6000 function ForInStatement () {
6001 LoopStatement$$1.apply(this, arguments);
6002 }
6003
6004 if ( LoopStatement$$1 ) ForInStatement.__proto__ = LoopStatement$$1;
6005 ForInStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
6006 ForInStatement.prototype.constructor = ForInStatement;
6007
6008 ForInStatement.prototype.findScope = function findScope ( functionScope ) {
6009 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
6010 };
6011
6012 ForInStatement.prototype.transpile = function transpile ( code, transforms ) {
6013 var this$1 = this;
6014
6015 if ( this.shouldRewriteAsFunction ) {
6016 // which variables are declared in the init statement?
6017 var names = this.left.type === 'VariableDeclaration' ?
6018 [].concat.apply( [], this.left.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
6019 [];
6020
6021 this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
6022 this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
6023 }
6024
6025 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
6026 };
6027
6028 return ForInStatement;
6029}(LoopStatement));
6030
6031var handlers = {
6032 Identifier: destructureIdentifier,
6033 AssignmentPattern: destructureAssignmentPattern,
6034 ArrayPattern: destructureArrayPattern,
6035 ObjectPattern: destructureObjectPattern
6036};
6037
6038function destructure ( code, scope, node, ref, inline, statementGenerators ) {
6039 handlers[ node.type ]( code, scope, node, ref, inline, statementGenerators );
6040}
6041
6042function destructureIdentifier ( code, scope, node, ref, inline, statementGenerators ) {
6043 statementGenerators.push( function ( start, prefix, suffix ) {
6044 code.prependRight( node.start, inline ? prefix : (prefix + "var ") );
6045 code.appendLeft( node.end, (" = " + ref + suffix) );
6046 code.move( node.start, node.end, start );
6047 });
6048}
6049
6050function destructureAssignmentPattern ( code, scope, node, ref, inline, statementGenerators ) {
6051 var isIdentifier = node.left.type === 'Identifier';
6052 var name = isIdentifier ? node.left.name : ref;
6053
6054 if ( !inline ) {
6055 statementGenerators.push( function ( start, prefix, suffix ) {
6056 code.prependRight( node.left.end, (prefix + "if ( " + name + " === void 0 ) " + name) );
6057 code.move( node.left.end, node.right.end, start );
6058 code.appendLeft( node.right.end, suffix );
6059 });
6060 }
6061
6062 if ( !isIdentifier ) {
6063 destructure( code, scope, node.left, ref, inline, statementGenerators );
6064 }
6065}
6066
6067function destructureArrayPattern ( code, scope, node, ref, inline, statementGenerators ) {
6068 var c = node.start;
6069
6070 node.elements.forEach( function ( element, i ) {
6071 if ( !element ) return;
6072
6073 if ( element.type === 'RestElement' ) {
6074 handleProperty( code, scope, c, element.argument, (ref + ".slice(" + i + ")"), inline, statementGenerators );
6075 } else {
6076 handleProperty( code, scope, c, element, (ref + "[" + i + "]"), inline, statementGenerators );
6077 }
6078 c = element.end;
6079 });
6080
6081 code.remove( c, node.end );
6082}
6083
6084function destructureObjectPattern ( code, scope, node, ref, inline, statementGenerators ) {
6085 var this$1 = this;
6086
6087 var c = node.start;
6088
6089 var nonRestKeys = [];
6090 node.properties.forEach( function ( prop ) {
6091 var value;
6092 var content;
6093 if (prop.type === "Property") {
6094 var isComputedKey = prop.computed || prop.key.type !== 'Identifier';
6095 var key = isComputedKey ? code.slice(prop.key.start, prop.key.end) : prop.key.name;
6096 value = isComputedKey ? (ref + "[" + key + "]") : (ref + "." + key);
6097 content = prop.value;
6098 nonRestKeys.push(isComputedKey ? key : '"' + key + '"');
6099 } else if (prop.type === "RestElement") {
6100 content = prop.argument;
6101 value = scope.createIdentifier( 'rest' );
6102 var n = scope.createIdentifier( 'n' );
6103 statementGenerators.push( function ( start, prefix, suffix ) {
6104 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));
6105 code.move(prop.start, c, start);
6106 } );
6107 } else {
6108 throw new CompileError( this$1, ("Unexpected node of type " + (prop.type) + " in object pattern"))
6109 }
6110 handleProperty( code, scope, c, content, value, inline, statementGenerators );
6111 c = prop.end;
6112 });
6113
6114 code.remove( c, node.end );
6115}
6116
6117function handleProperty ( code, scope, c, node, value, inline, statementGenerators ) {
6118 switch ( node.type ) {
6119 case 'Identifier': {
6120 code.remove( c, node.start );
6121 destructureIdentifier( code, scope, node, value, inline, statementGenerators );
6122 break;
6123 }
6124
6125 case 'AssignmentPattern': {
6126 var name;
6127
6128 var isIdentifier = node.left.type === 'Identifier';
6129
6130 if ( isIdentifier ) {
6131 name = node.left.name;
6132 var declaration = scope.findDeclaration( name );
6133 if ( declaration ) name = declaration.name;
6134 } else {
6135 name = scope.createIdentifier( value );
6136 }
6137
6138 statementGenerators.push( function ( start, prefix, suffix ) {
6139 if ( inline ) {
6140 code.prependRight( node.right.start, (name + " = " + value + " === undefined ? ") );
6141 code.appendLeft( node.right.end, (" : " + value) );
6142 } else {
6143 code.prependRight( node.right.start, (prefix + "var " + name + " = " + value + "; if ( " + name + " === void 0 ) " + name + " = ") );
6144 code.appendLeft( node.right.end, suffix );
6145 }
6146
6147 code.move( node.right.start, node.right.end, start );
6148 });
6149
6150 if ( isIdentifier ) {
6151 code.remove( c, node.right.start );
6152 } else {
6153 code.remove( c, node.left.start );
6154 code.remove( node.left.end, node.right.start );
6155 handleProperty( code, scope, c, node.left, name, inline, statementGenerators );
6156 }
6157
6158 break;
6159 }
6160
6161 case 'ObjectPattern': {
6162 code.remove( c, c = node.start );
6163
6164 var ref = value;
6165 if ( node.properties.length > 1 ) {
6166 ref = scope.createIdentifier( value );
6167
6168 statementGenerators.push( function ( start, prefix, suffix ) {
6169 // this feels a tiny bit hacky, but we can't do a
6170 // straightforward appendLeft and keep correct order...
6171 code.prependRight( node.start, (prefix + "var " + ref + " = ") );
6172 code.overwrite( node.start, c = node.start + 1, value );
6173 code.appendLeft( c, suffix );
6174
6175 code.overwrite( node.start, c = node.start + 1, (prefix + "var " + ref + " = " + value + suffix) );
6176 code.move( node.start, c, start );
6177 });
6178 }
6179
6180 destructureObjectPattern( code, scope, node, ref, inline, statementGenerators );
6181
6182 break;
6183 }
6184
6185 case 'ArrayPattern': {
6186 code.remove( c, c = node.start );
6187
6188 if ( node.elements.filter( Boolean ).length > 1 ) {
6189 var ref$1 = scope.createIdentifier( value );
6190
6191 statementGenerators.push( function ( start, prefix, suffix ) {
6192 code.prependRight( node.start, (prefix + "var " + ref$1 + " = ") );
6193 code.overwrite( node.start, c = node.start + 1, value, { contentOnly: true });
6194 code.appendLeft( c, suffix );
6195
6196 code.move( node.start, c, start );
6197 });
6198
6199 node.elements.forEach( function ( element, i ) {
6200 if ( !element ) return;
6201
6202 if ( element.type === 'RestElement' ) {
6203 handleProperty( code, scope, c, element.argument, (ref$1 + ".slice(" + i + ")"), inline, statementGenerators );
6204 } else {
6205 handleProperty( code, scope, c, element, (ref$1 + "[" + i + "]"), inline, statementGenerators );
6206 }
6207 c = element.end;
6208 });
6209 } else {
6210 var index = findIndex( node.elements, Boolean );
6211 var element = node.elements[ index ];
6212 if ( element.type === 'RestElement' ) {
6213 handleProperty( code, scope, c, element.argument, (value + ".slice(" + index + ")"), inline, statementGenerators );
6214 } else {
6215 handleProperty( code, scope, c, element, (value + "[" + index + "]"), inline, statementGenerators );
6216 }
6217 c = element.end;
6218 }
6219
6220 code.remove( c, node.end );
6221 break;
6222 }
6223
6224 default: {
6225 throw new Error( ("Unexpected node type in destructuring (" + (node.type) + ")") );
6226 }
6227 }
6228}
6229
6230var ForOfStatement = (function (LoopStatement$$1) {
6231 function ForOfStatement () {
6232 LoopStatement$$1.apply(this, arguments);
6233 }
6234
6235 if ( LoopStatement$$1 ) ForOfStatement.__proto__ = LoopStatement$$1;
6236 ForOfStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
6237 ForOfStatement.prototype.constructor = ForOfStatement;
6238
6239 ForOfStatement.prototype.initialise = function initialise ( transforms ) {
6240 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 );
6241 LoopStatement$$1.prototype.initialise.call( this, transforms );
6242 };
6243
6244 ForOfStatement.prototype.transpile = function transpile ( code, transforms ) {
6245 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
6246 if ( !transforms.dangerousForOf ) return;
6247
6248 // edge case (#80)
6249 if ( !this.body.body[0] ) {
6250 if ( this.left.type === 'VariableDeclaration' && this.left.kind === 'var' ) {
6251 code.remove( this.start, this.left.start );
6252 code.appendLeft( this.left.end, ';' );
6253 code.remove( this.left.end, this.end );
6254 } else {
6255 code.remove( this.start, this.end );
6256 }
6257
6258 return;
6259 }
6260
6261 var scope = this.findScope( true );
6262 var i0 = this.getIndentation();
6263 var i1 = i0 + code.getIndentString();
6264
6265 var key = scope.createIdentifier( 'i' );
6266 var list = scope.createIdentifier( 'list' );
6267
6268 if ( this.body.synthetic ) {
6269 code.prependRight( this.left.start, ("{\n" + i1) );
6270 code.appendLeft( this.body.body[0].end, ("\n" + i0 + "}") );
6271 }
6272
6273 var bodyStart = this.body.body[0].start;
6274
6275 code.remove( this.left.end, this.right.start );
6276 code.move( this.left.start, this.left.end, bodyStart );
6277
6278
6279 code.prependRight( this.right.start, ("var " + key + " = 0, " + list + " = ") );
6280 code.appendLeft( this.right.end, ("; " + key + " < " + list + ".length; " + key + " += 1") );
6281
6282 // destructuring. TODO non declaration destructuring
6283 var declarator = this.left.type === 'VariableDeclaration' && this.left.declarations[0];
6284 if ( declarator && declarator.id.type !== 'Identifier' ) {
6285 var statementGenerators = [];
6286 var ref = scope.createIdentifier( 'ref' );
6287 destructure( code, scope, declarator.id, ref, false, statementGenerators );
6288
6289 var suffix = ";\n" + i1;
6290 statementGenerators.forEach( function ( fn, i ) {
6291 if ( i === statementGenerators.length - 1 ) {
6292 suffix = ";\n\n" + i1;
6293 }
6294
6295 fn( bodyStart, '', suffix );
6296 });
6297
6298 code.appendLeft( this.left.start + this.left.kind.length + 1, ref );
6299 code.appendLeft( this.left.end, (" = " + list + "[" + key + "];\n" + i1) );
6300 } else {
6301 code.appendLeft( this.left.end, (" = " + list + "[" + key + "];\n\n" + i1) );
6302 }
6303 };
6304
6305 return ForOfStatement;
6306}(LoopStatement));
6307
6308var FunctionDeclaration = (function (Node) {
6309 function FunctionDeclaration () {
6310 Node.apply(this, arguments);
6311 }
6312
6313 if ( Node ) FunctionDeclaration.__proto__ = Node;
6314 FunctionDeclaration.prototype = Object.create( Node && Node.prototype );
6315 FunctionDeclaration.prototype.constructor = FunctionDeclaration;
6316
6317 FunctionDeclaration.prototype.initialise = function initialise ( transforms ) {
6318 if ( this.generator && transforms.generator ) {
6319 throw new CompileError$1( 'Generators are not supported', this );
6320 }
6321
6322 this.body.createScope();
6323
6324 this.findScope( true ).addDeclaration( this.id, 'function' );
6325 Node.prototype.initialise.call( this, transforms );
6326 };
6327
6328 return FunctionDeclaration;
6329}(Node$1));
6330
6331var FunctionExpression = (function (Node) {
6332 function FunctionExpression () {
6333 Node.apply(this, arguments);
6334 }
6335
6336 if ( Node ) FunctionExpression.__proto__ = Node;
6337 FunctionExpression.prototype = Object.create( Node && Node.prototype );
6338 FunctionExpression.prototype.constructor = FunctionExpression;
6339
6340 FunctionExpression.prototype.initialise = function initialise ( transforms ) {
6341 if ( this.generator && transforms.generator ) {
6342 throw new CompileError$1( 'Generators are not supported', this );
6343 }
6344
6345 this.body.createScope();
6346
6347 if ( this.id ) {
6348 // function expression IDs belong to the child scope...
6349 this.body.scope.addDeclaration( this.id, 'function' );
6350 }
6351
6352 Node.prototype.initialise.call( this, transforms );
6353
6354 var parent = this.parent;
6355 var methodName;
6356
6357 if ( transforms.conciseMethodProperty
6358 && parent.type === 'Property'
6359 && parent.kind === 'init'
6360 && parent.method
6361 && parent.key.type === 'Identifier' ) {
6362 // object literal concise method
6363 methodName = parent.key.name;
6364 }
6365 else if ( transforms.classes
6366 && parent.type === 'MethodDefinition'
6367 && parent.kind === 'method'
6368 && parent.key.type === 'Identifier' ) {
6369 // method definition in a class
6370 methodName = parent.key.name;
6371 }
6372 else if ( this.id && this.id.type === 'Identifier' ) {
6373 // naked function expression
6374 methodName = this.id.alias || this.id.name;
6375 }
6376
6377 if ( methodName ) {
6378 for ( var i = 0, list = this.params; i < list.length; i += 1 ) {
6379 var param = list[i];
6380
6381 if ( param.type === 'Identifier' && methodName === param.name ) {
6382 // workaround for Safari 9/WebKit bug:
6383 // https://gitlab.com/Rich-Harris/buble/issues/154
6384 // change parameter name when same as method name
6385
6386 var scope = this.body.scope;
6387 var declaration = scope.declarations[ methodName ];
6388
6389 var alias = scope.createIdentifier( methodName );
6390 param.alias = alias;
6391
6392 for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
6393 var identifier = list$1[i$1];
6394
6395 identifier.alias = alias;
6396 }
6397
6398 break;
6399 }
6400 }
6401 }
6402 };
6403
6404 return FunctionExpression;
6405}(Node$1));
6406
6407function isReference ( node, parent ) {
6408 if ( node.type === 'MemberExpression' ) {
6409 return !node.computed && isReference( node.object, node );
6410 }
6411
6412 if ( node.type === 'Identifier' ) {
6413 // the only time we could have an identifier node without a parent is
6414 // if it's the entire body of a function without a block statement –
6415 // i.e. an arrow function expression like `a => a`
6416 if ( !parent ) return true;
6417
6418 if ( /(Function|Class)Expression/.test( parent.type ) ) return false;
6419
6420 if ( parent.type === 'VariableDeclarator' ) return node === parent.init;
6421
6422 // TODO is this right?
6423 if ( parent.type === 'MemberExpression' || parent.type === 'MethodDefinition' ) {
6424 return parent.computed || node === parent.object;
6425 }
6426
6427 if ( parent.type === 'ArrayPattern' ) return false;
6428
6429 // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
6430 if ( parent.type === 'Property' ) {
6431 if ( parent.parent.type === 'ObjectPattern' ) return false;
6432 return parent.computed || node === parent.value;
6433 }
6434
6435 // disregard the `bar` in `class Foo { bar () {...} }`
6436 if ( parent.type === 'MethodDefinition' ) return false;
6437
6438 // disregard the `bar` in `export { foo as bar }`
6439 if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return false;
6440
6441 return true;
6442 }
6443}
6444
6445var Identifier = (function (Node) {
6446 function Identifier () {
6447 Node.apply(this, arguments);
6448 }
6449
6450 if ( Node ) Identifier.__proto__ = Node;
6451 Identifier.prototype = Object.create( Node && Node.prototype );
6452 Identifier.prototype.constructor = Identifier;
6453
6454 Identifier.prototype.findScope = function findScope ( functionScope ) {
6455 if ( this.parent.params && ~this.parent.params.indexOf( this ) ) {
6456 return this.parent.body.scope;
6457 }
6458
6459 if ( this.parent.type === 'FunctionExpression' && this === this.parent.id ) {
6460 return this.parent.body.scope;
6461 }
6462
6463 return this.parent.findScope( functionScope );
6464 };
6465
6466 Identifier.prototype.initialise = function initialise ( transforms ) {
6467 if ( transforms.arrow && isReference( this, this.parent ) ) {
6468 if ( this.name === 'arguments' && !this.findScope( false ).contains( this.name ) ) {
6469 var lexicalBoundary = this.findLexicalBoundary();
6470 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
6471 var loop = this.findNearest( loopStatement );
6472
6473 if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
6474 this.alias = lexicalBoundary.getArgumentsAlias();
6475 }
6476
6477 if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
6478 this.alias = lexicalBoundary.getArgumentsAlias();
6479 }
6480 }
6481
6482 this.findScope( false ).addReference( this );
6483 }
6484 };
6485
6486 Identifier.prototype.transpile = function transpile ( code ) {
6487 if ( this.alias ) {
6488 code.overwrite( this.start, this.end, this.alias, { storeName: true, contentOnly: true });
6489 }
6490 };
6491
6492 return Identifier;
6493}(Node$1));
6494
6495var IfStatement = (function (Node) {
6496 function IfStatement () {
6497 Node.apply(this, arguments);
6498 }
6499
6500 if ( Node ) IfStatement.__proto__ = Node;
6501 IfStatement.prototype = Object.create( Node && Node.prototype );
6502 IfStatement.prototype.constructor = IfStatement;
6503
6504 IfStatement.prototype.initialise = function initialise ( transforms ) {
6505 Node.prototype.initialise.call( this, transforms );
6506 };
6507
6508 IfStatement.prototype.transpile = function transpile ( code, transforms ) {
6509 if ( this.consequent.type !== 'BlockStatement'
6510 || this.consequent.type === 'BlockStatement' && this.consequent.synthetic ) {
6511 code.appendLeft( this.consequent.start, '{ ' );
6512 code.prependRight( this.consequent.end, ' }' );
6513 }
6514
6515 if ( this.alternate && this.alternate.type !== 'IfStatement' && (
6516 this.alternate.type !== 'BlockStatement'
6517 || this.alternate.type === 'BlockStatement' && this.alternate.synthetic ) ) {
6518 code.appendLeft( this.alternate.start, '{ ' );
6519 code.prependRight( this.alternate.end, ' }' );
6520 }
6521
6522 Node.prototype.transpile.call( this, code, transforms );
6523 };
6524
6525 return IfStatement;
6526}(Node$1));
6527
6528var ImportDeclaration = (function (Node) {
6529 function ImportDeclaration () {
6530 Node.apply(this, arguments);
6531 }
6532
6533 if ( Node ) ImportDeclaration.__proto__ = Node;
6534 ImportDeclaration.prototype = Object.create( Node && Node.prototype );
6535 ImportDeclaration.prototype.constructor = ImportDeclaration;
6536
6537 ImportDeclaration.prototype.initialise = function initialise ( transforms ) {
6538 if ( transforms.moduleImport ) throw new CompileError$1( 'import is not supported', this );
6539 Node.prototype.initialise.call( this, transforms );
6540 };
6541
6542 return ImportDeclaration;
6543}(Node$1));
6544
6545var ImportDefaultSpecifier = (function (Node) {
6546 function ImportDefaultSpecifier () {
6547 Node.apply(this, arguments);
6548 }
6549
6550 if ( Node ) ImportDefaultSpecifier.__proto__ = Node;
6551 ImportDefaultSpecifier.prototype = Object.create( Node && Node.prototype );
6552 ImportDefaultSpecifier.prototype.constructor = ImportDefaultSpecifier;
6553
6554 ImportDefaultSpecifier.prototype.initialise = function initialise ( transforms ) {
6555 this.findScope( true ).addDeclaration( this.local, 'import' );
6556 Node.prototype.initialise.call( this, transforms );
6557 };
6558
6559 return ImportDefaultSpecifier;
6560}(Node$1));
6561
6562var ImportSpecifier = (function (Node) {
6563 function ImportSpecifier () {
6564 Node.apply(this, arguments);
6565 }
6566
6567 if ( Node ) ImportSpecifier.__proto__ = Node;
6568 ImportSpecifier.prototype = Object.create( Node && Node.prototype );
6569 ImportSpecifier.prototype.constructor = ImportSpecifier;
6570
6571 ImportSpecifier.prototype.initialise = function initialise ( transforms ) {
6572 this.findScope( true ).addDeclaration( this.local, 'import' );
6573 Node.prototype.initialise.call( this, transforms );
6574 };
6575
6576 return ImportSpecifier;
6577}(Node$1));
6578
6579var hasDashes = function ( val ) { return /-/.test(val); };
6580
6581var formatKey = function ( key ) { return hasDashes(key) ? ("'" + key + "'") : key; };
6582
6583var formatVal = function ( val ) { return val ? '' : 'true'; };
6584
6585var JSXAttribute = (function (Node) {
6586 function JSXAttribute () {
6587 Node.apply(this, arguments);
6588 }
6589
6590 if ( Node ) JSXAttribute.__proto__ = Node;
6591 JSXAttribute.prototype = Object.create( Node && Node.prototype );
6592 JSXAttribute.prototype.constructor = JSXAttribute;
6593
6594 JSXAttribute.prototype.transpile = function transpile ( code, transforms ) {
6595 var ref = this.name;
6596 var start = ref.start;
6597 var name = ref.name;
6598
6599 // Overwrite equals sign if value is present.
6600 var end = this.value ? this.value.start : this.name.end;
6601
6602 code.overwrite( start, end, ((formatKey(name)) + ": " + (formatVal(this.value))) );
6603
6604 Node.prototype.transpile.call( this, code, transforms );
6605 };
6606
6607 return JSXAttribute;
6608}(Node$1));
6609
6610function containsNewLine ( node ) {
6611 return node.type === 'Literal' && !/\S/.test( node.value ) && /\n/.test( node.value );
6612}
6613
6614var JSXClosingElement = (function (Node) {
6615 function JSXClosingElement () {
6616 Node.apply(this, arguments);
6617 }
6618
6619 if ( Node ) JSXClosingElement.__proto__ = Node;
6620 JSXClosingElement.prototype = Object.create( Node && Node.prototype );
6621 JSXClosingElement.prototype.constructor = JSXClosingElement;
6622
6623 JSXClosingElement.prototype.transpile = function transpile ( code ) {
6624 var spaceBeforeParen = true;
6625
6626 var lastChild = this.parent.children[ this.parent.children.length - 1 ];
6627
6628 // omit space before closing paren if
6629 // a) this is on a separate line, or
6630 // b) there are no children but there are attributes
6631 if ( ( lastChild && containsNewLine( lastChild ) ) || ( this.parent.openingElement.attributes.length ) ) {
6632 spaceBeforeParen = false;
6633 }
6634
6635 code.overwrite( this.start, this.end, spaceBeforeParen ? ' )' : ')' );
6636 };
6637
6638 return JSXClosingElement;
6639}(Node$1));
6640
6641function normalise ( str, removeTrailingWhitespace ) {
6642 if ( removeTrailingWhitespace && /\n/.test( str ) ) {
6643 str = str.replace( /\s+$/, '' );
6644 }
6645
6646 str = str
6647 .replace( /^\n\r?\s+/, '' ) // remove leading newline + space
6648 .replace( /\s*\n\r?\s*/gm, ' ' ); // replace newlines with spaces
6649
6650 // TODO prefer single quotes?
6651 return JSON.stringify( str );
6652}
6653
6654var JSXElement = (function (Node) {
6655 function JSXElement () {
6656 Node.apply(this, arguments);
6657 }
6658
6659 if ( Node ) JSXElement.__proto__ = Node;
6660 JSXElement.prototype = Object.create( Node && Node.prototype );
6661 JSXElement.prototype.constructor = JSXElement;
6662
6663 JSXElement.prototype.transpile = function transpile ( code, transforms ) {
6664 Node.prototype.transpile.call( this, code, transforms );
6665
6666 var children = this.children.filter( function ( child ) {
6667 if ( child.type !== 'Literal' ) return true;
6668
6669 // remove whitespace-only literals, unless on a single line
6670 return /\S/.test( child.value ) || !/\n/.test( child.value );
6671 });
6672
6673 if ( children.length ) {
6674 var c = this.openingElement.end;
6675
6676 var i;
6677 for ( i = 0; i < children.length; i += 1 ) {
6678 var child = children[i];
6679
6680 if ( child.type === 'JSXExpressionContainer' && child.expression.type === 'JSXEmptyExpression' ) {
6681 // empty block is a no op
6682 } else {
6683 var tail = code.original[ c ] === '\n' && child.type !== 'Literal' ? '' : ' ';
6684 code.appendLeft( c, ("," + tail) );
6685 }
6686
6687 if ( child.type === 'Literal' ) {
6688 var str = normalise( child.value, i === children.length - 1 );
6689 code.overwrite( child.start, child.end, str );
6690 }
6691
6692 c = child.end;
6693 }
6694 }
6695 };
6696
6697 return JSXElement;
6698}(Node$1));
6699
6700var JSXExpressionContainer = (function (Node) {
6701 function JSXExpressionContainer () {
6702 Node.apply(this, arguments);
6703 }
6704
6705 if ( Node ) JSXExpressionContainer.__proto__ = Node;
6706 JSXExpressionContainer.prototype = Object.create( Node && Node.prototype );
6707 JSXExpressionContainer.prototype.constructor = JSXExpressionContainer;
6708
6709 JSXExpressionContainer.prototype.transpile = function transpile ( code, transforms ) {
6710 code.remove( this.start, this.expression.start );
6711 code.remove( this.expression.end, this.end );
6712
6713 Node.prototype.transpile.call( this, code, transforms );
6714 };
6715
6716 return JSXExpressionContainer;
6717}(Node$1));
6718
6719var JSXOpeningElement = (function (Node) {
6720 function JSXOpeningElement () {
6721 Node.apply(this, arguments);
6722 }
6723
6724 if ( Node ) JSXOpeningElement.__proto__ = Node;
6725 JSXOpeningElement.prototype = Object.create( Node && Node.prototype );
6726 JSXOpeningElement.prototype.constructor = JSXOpeningElement;
6727
6728 JSXOpeningElement.prototype.transpile = function transpile ( code, transforms ) {
6729 var this$1 = this;
6730
6731 Node.prototype.transpile.call( this, code, transforms );
6732
6733 code.overwrite( this.start, this.name.start, ((this.program.jsx) + "( ") );
6734
6735 var html = this.name.type === 'JSXIdentifier' && this.name.name[0] === this.name.name[0].toLowerCase();
6736 if ( html ) code.prependRight( this.name.start, "'" );
6737
6738 var len = this.attributes.length;
6739 var c = this.name.end;
6740
6741 if ( len ) {
6742 var i;
6743
6744 var hasSpread = false;
6745 for ( i = 0; i < len; i += 1 ) {
6746 if ( this$1.attributes[i].type === 'JSXSpreadAttribute' ) {
6747 hasSpread = true;
6748 break;
6749 }
6750 }
6751
6752 c = this.attributes[0].end;
6753
6754 for ( i = 0; i < len; i += 1 ) {
6755 var attr = this$1.attributes[i];
6756
6757 if ( i > 0 ) {
6758 if ( attr.start === c )
6759 code.prependRight( c, ', ' );
6760 else
6761 code.overwrite( c, attr.start, ', ' );
6762 }
6763
6764 if ( hasSpread && attr.type !== 'JSXSpreadAttribute' ) {
6765 var lastAttr = this$1.attributes[ i - 1 ];
6766 var nextAttr = this$1.attributes[ i + 1 ];
6767
6768 if ( !lastAttr || lastAttr.type === 'JSXSpreadAttribute' ) {
6769 code.prependRight( attr.start, '{ ' );
6770 }
6771
6772 if ( !nextAttr || nextAttr.type === 'JSXSpreadAttribute' ) {
6773 code.appendLeft( attr.end, ' }' );
6774 }
6775 }
6776
6777 c = attr.end;
6778 }
6779
6780 var after;
6781 var before;
6782 if ( hasSpread ) {
6783 if ( len === 1 ) {
6784 before = html ? "'," : ',';
6785 } else {
6786 if (!this.program.options.objectAssign) {
6787 throw new CompileError$1( 'Mixed JSX attributes ending in spread requires specified objectAssign option with \'Object.assign\' or polyfill helper.', this );
6788 }
6789 before = html ? ("', " + (this.program.options.objectAssign) + "({},") : (", " + (this.program.options.objectAssign) + "({},");
6790 after = ')';
6791 }
6792 } else {
6793 before = html ? "', {" : ', {';
6794 after = ' }';
6795 }
6796
6797 code.prependRight( this.name.end, before );
6798
6799 if ( after ) {
6800 code.appendLeft( this.attributes[ len - 1 ].end, after );
6801 }
6802 } else {
6803 code.appendLeft( this.name.end, html ? "', null" : ", null" );
6804 c = this.name.end;
6805 }
6806
6807 if ( this.selfClosing ) {
6808 code.overwrite( c, this.end, this.attributes.length ? ")" : " )" );
6809 } else {
6810 code.remove( c, this.end );
6811 }
6812 };
6813
6814 return JSXOpeningElement;
6815}(Node$1));
6816
6817var JSXSpreadAttribute = (function (Node) {
6818 function JSXSpreadAttribute () {
6819 Node.apply(this, arguments);
6820 }
6821
6822 if ( Node ) JSXSpreadAttribute.__proto__ = Node;
6823 JSXSpreadAttribute.prototype = Object.create( Node && Node.prototype );
6824 JSXSpreadAttribute.prototype.constructor = JSXSpreadAttribute;
6825
6826 JSXSpreadAttribute.prototype.transpile = function transpile ( code, transforms ) {
6827 code.remove( this.start, this.argument.start );
6828 code.remove( this.argument.end, this.end );
6829
6830 Node.prototype.transpile.call( this, code, transforms );
6831 };
6832
6833 return JSXSpreadAttribute;
6834}(Node$1));
6835
6836var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6837
6838function commonjsRequire () {
6839 throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
6840}
6841
6842
6843
6844function createCommonjsModule(fn, module) {
6845 return module = { exports: {} }, fn(module, module.exports), module.exports;
6846}
6847
6848var regjsgen = createCommonjsModule(function (module, exports) {
6849/*!
6850 * regjsgen 0.3.0
6851 * Copyright 2014-2016 Benjamin Tan <https://demoneaux.github.io/>
6852 * Available under MIT license <https://github.com/demoneaux/regjsgen/blob/master/LICENSE>
6853 */
6854(function() {
6855 'use strict';
6856
6857 // Used to determine if values are of the language type `Object`.
6858 var objectTypes = {
6859 'function': true,
6860 'object': true
6861 };
6862
6863 // Used as a reference to the global object.
6864 var root = (objectTypes[typeof window] && window) || this;
6865
6866 // Detect free variable `exports`.
6867 var freeExports = objectTypes['object'] && exports;
6868
6869 // Detect free variable `module`.
6870 var freeModule = objectTypes['object'] && module && !module.nodeType && module;
6871
6872 // Detect free variable `global` from Node.js or Browserified code and use it as `root`.
6873 var freeGlobal = freeExports && freeModule && typeof commonjsGlobal == 'object' && commonjsGlobal;
6874 if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
6875 root = freeGlobal;
6876 }
6877
6878 // Used to check objects for own properties.
6879 var hasOwnProperty = Object.prototype.hasOwnProperty;
6880
6881 /*--------------------------------------------------------------------------*/
6882
6883 // Generates strings based on the given code points.
6884 // Based on https://mths.be/fromcodepoint v0.2.0 by @mathias.
6885 var stringFromCharCode = String.fromCharCode;
6886 var floor = Math.floor;
6887 function fromCodePoint() {
6888 var MAX_SIZE = 0x4000;
6889 var codeUnits = [];
6890 var highSurrogate;
6891 var lowSurrogate;
6892 var index = -1;
6893 var length = arguments.length;
6894 if (!length) {
6895 return '';
6896 }
6897 var result = '';
6898 while (++index < length) {
6899 var codePoint = Number(arguments[index]);
6900 if (
6901 !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
6902 codePoint < 0 || // not a valid Unicode code point
6903 codePoint > 0x10FFFF || // not a valid Unicode code point
6904 floor(codePoint) != codePoint // not an integer
6905 ) {
6906 throw RangeError('Invalid code point: ' + codePoint);
6907 }
6908 if (codePoint <= 0xFFFF) {
6909 // BMP code point
6910 codeUnits.push(codePoint);
6911 } else {
6912 // Astral code point; split in surrogate halves
6913 // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
6914 codePoint -= 0x10000;
6915 highSurrogate = (codePoint >> 10) + 0xD800;
6916 lowSurrogate = (codePoint % 0x400) + 0xDC00;
6917 codeUnits.push(highSurrogate, lowSurrogate);
6918 }
6919 if (index + 1 == length || codeUnits.length > MAX_SIZE) {
6920 result += stringFromCharCode.apply(null, codeUnits);
6921 codeUnits.length = 0;
6922 }
6923 }
6924 return result;
6925 }
6926
6927 /*--------------------------------------------------------------------------*/
6928
6929 // Ensures that nodes have the correct types.
6930 var assertTypeRegexMap = {};
6931 function assertType(type, expected) {
6932 if (expected.indexOf('|') == -1) {
6933 if (type == expected) {
6934 return;
6935 }
6936
6937 throw Error('Invalid node type: ' + type + '; expected type: ' + expected);
6938 }
6939
6940 expected = hasOwnProperty.call(assertTypeRegexMap, expected)
6941 ? assertTypeRegexMap[expected]
6942 : (assertTypeRegexMap[expected] = RegExp('^(?:' + expected + ')$'));
6943
6944 if (expected.test(type)) {
6945 return;
6946 }
6947
6948 throw Error('Invalid node type: ' + type + '; expected types: ' + expected);
6949 }
6950
6951 /*--------------------------------------------------------------------------*/
6952
6953 // Generates a regular expression string based on an AST.
6954 function generate(node) {
6955 var type = node.type;
6956
6957 if (hasOwnProperty.call(generators, type)) {
6958 return generators[type](node);
6959 }
6960
6961 throw Error('Invalid node type: ' + type);
6962 }
6963
6964 /*--------------------------------------------------------------------------*/
6965
6966 function generateAlternative(node) {
6967 assertType(node.type, 'alternative');
6968
6969 var terms = node.body,
6970 i = -1,
6971 length = terms.length,
6972 result = '';
6973
6974 while (++i < length) {
6975 result += generateTerm(terms[i]);
6976 }
6977
6978 return result;
6979 }
6980
6981 function generateAnchor(node) {
6982 assertType(node.type, 'anchor');
6983
6984 switch (node.kind) {
6985 case 'start':
6986 return '^';
6987 case 'end':
6988 return '$';
6989 case 'boundary':
6990 return '\\b';
6991 case 'not-boundary':
6992 return '\\B';
6993 default:
6994 throw Error('Invalid assertion');
6995 }
6996 }
6997
6998 function generateAtom(node) {
6999 assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
7000
7001 return generate(node);
7002 }
7003
7004 function generateCharacterClass(node) {
7005 assertType(node.type, 'characterClass');
7006
7007 var classRanges = node.body,
7008 i = -1,
7009 length = classRanges.length,
7010 result = '';
7011
7012 if (node.negative) {
7013 result += '^';
7014 }
7015
7016 while (++i < length) {
7017 result += generateClassAtom(classRanges[i]);
7018 }
7019
7020 return '[' + result + ']';
7021 }
7022
7023 function generateCharacterClassEscape(node) {
7024 assertType(node.type, 'characterClassEscape');
7025
7026 return '\\' + node.value;
7027 }
7028
7029 function generateUnicodePropertyEscape(node) {
7030 assertType(node.type, 'unicodePropertyEscape');
7031
7032 return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
7033 }
7034
7035 function generateCharacterClassRange(node) {
7036 assertType(node.type, 'characterClassRange');
7037
7038 var min = node.min,
7039 max = node.max;
7040
7041 if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
7042 throw Error('Invalid character class range');
7043 }
7044
7045 return generateClassAtom(min) + '-' + generateClassAtom(max);
7046 }
7047
7048 function generateClassAtom(node) {
7049 assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value');
7050
7051 return generate(node);
7052 }
7053
7054 function generateDisjunction(node) {
7055 assertType(node.type, 'disjunction');
7056
7057 var body = node.body,
7058 i = -1,
7059 length = body.length,
7060 result = '';
7061
7062 while (++i < length) {
7063 if (i != 0) {
7064 result += '|';
7065 }
7066 result += generate(body[i]);
7067 }
7068
7069 return result;
7070 }
7071
7072 function generateDot(node) {
7073 assertType(node.type, 'dot');
7074
7075 return '.';
7076 }
7077
7078 function generateGroup(node) {
7079 assertType(node.type, 'group');
7080
7081 var result = '';
7082
7083 switch (node.behavior) {
7084 case 'normal':
7085 break;
7086 case 'ignore':
7087 result += '?:';
7088 break;
7089 case 'lookahead':
7090 result += '?=';
7091 break;
7092 case 'negativeLookahead':
7093 result += '?!';
7094 break;
7095 default:
7096 throw Error('Invalid behaviour: ' + node.behaviour);
7097 }
7098
7099 var body = node.body,
7100 i = -1,
7101 length = body.length;
7102
7103 while (++i < length) {
7104 result += generate(body[i]);
7105 }
7106
7107 return '(' + result + ')';
7108 }
7109
7110 function generateQuantifier(node) {
7111 assertType(node.type, 'quantifier');
7112
7113 var quantifier = '',
7114 min = node.min,
7115 max = node.max;
7116
7117 if (max == null) {
7118 if (min == 0) {
7119 quantifier = '*';
7120 } else if (min == 1) {
7121 quantifier = '+';
7122 } else {
7123 quantifier = '{' + min + ',}';
7124 }
7125 } else if (min == max) {
7126 quantifier = '{' + min + '}';
7127 } else if (min == 0 && max == 1) {
7128 quantifier = '?';
7129 } else {
7130 quantifier = '{' + min + ',' + max + '}';
7131 }
7132
7133 if (!node.greedy) {
7134 quantifier += '?';
7135 }
7136
7137 return generateAtom(node.body[0]) + quantifier;
7138 }
7139
7140 function generateReference(node) {
7141 assertType(node.type, 'reference');
7142
7143 return '\\' + node.matchIndex;
7144 }
7145
7146 function generateTerm(node) {
7147 assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value');
7148
7149 return generate(node);
7150 }
7151
7152 function generateValue(node) {
7153 assertType(node.type, 'value');
7154
7155 var kind = node.kind,
7156 codePoint = node.codePoint;
7157
7158 switch (kind) {
7159 case 'controlLetter':
7160 return '\\c' + fromCodePoint(codePoint + 64);
7161 case 'hexadecimalEscape':
7162 return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
7163 case 'identifier':
7164 return '\\' + fromCodePoint(codePoint);
7165 case 'null':
7166 return '\\' + codePoint;
7167 case 'octal':
7168 return '\\' + codePoint.toString(8);
7169 case 'singleEscape':
7170 switch (codePoint) {
7171 case 0x0008:
7172 return '\\b';
7173 case 0x0009:
7174 return '\\t';
7175 case 0x000A:
7176 return '\\n';
7177 case 0x000B:
7178 return '\\v';
7179 case 0x000C:
7180 return '\\f';
7181 case 0x000D:
7182 return '\\r';
7183 default:
7184 throw Error('Invalid codepoint: ' + codePoint);
7185 }
7186 case 'symbol':
7187 return fromCodePoint(codePoint);
7188 case 'unicodeEscape':
7189 return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
7190 case 'unicodeCodePointEscape':
7191 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
7192 default:
7193 throw Error('Unsupported node kind: ' + kind);
7194 }
7195 }
7196
7197 /*--------------------------------------------------------------------------*/
7198
7199 // Used to generate strings for each node type.
7200 var generators = {
7201 'alternative': generateAlternative,
7202 'anchor': generateAnchor,
7203 'characterClass': generateCharacterClass,
7204 'characterClassEscape': generateCharacterClassEscape,
7205 'characterClassRange': generateCharacterClassRange,
7206 'unicodePropertyEscape': generateUnicodePropertyEscape,
7207 'disjunction': generateDisjunction,
7208 'dot': generateDot,
7209 'group': generateGroup,
7210 'quantifier': generateQuantifier,
7211 'reference': generateReference,
7212 'value': generateValue
7213 };
7214
7215 /*--------------------------------------------------------------------------*/
7216
7217 // Export regjsgen.
7218 // Some AMD build optimizers, like r.js, check for condition patterns like the following:
7219 if (typeof undefined == 'function' && typeof undefined.amd == 'object' && undefined.amd) {
7220 // Define as an anonymous module so it can be aliased through path mapping.
7221 undefined(function() {
7222 return {
7223 'generate': generate
7224 };
7225 });
7226 }
7227 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
7228 else if (freeExports && freeModule) {
7229 // Export for CommonJS support.
7230 freeExports.generate = generate;
7231 }
7232 else {
7233 // Export to the global object.
7234 root.regjsgen = {
7235 'generate': generate
7236 };
7237 }
7238}.call(commonjsGlobal));
7239});
7240
7241var parser = createCommonjsModule(function (module) {
7242// regjsparser
7243//
7244// ==================================================================
7245//
7246// See ECMA-262 Standard: 15.10.1
7247//
7248// NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the
7249// term "Anchor" is used.
7250//
7251// Pattern ::
7252// Disjunction
7253//
7254// Disjunction ::
7255// Alternative
7256// Alternative | Disjunction
7257//
7258// Alternative ::
7259// [empty]
7260// Alternative Term
7261//
7262// Term ::
7263// Anchor
7264// Atom
7265// Atom Quantifier
7266//
7267// Anchor ::
7268// ^
7269// $
7270// \ b
7271// \ B
7272// ( ? = Disjunction )
7273// ( ? ! Disjunction )
7274//
7275// Quantifier ::
7276// QuantifierPrefix
7277// QuantifierPrefix ?
7278//
7279// QuantifierPrefix ::
7280// *
7281// +
7282// ?
7283// { DecimalDigits }
7284// { DecimalDigits , }
7285// { DecimalDigits , DecimalDigits }
7286//
7287// Atom ::
7288// PatternCharacter
7289// .
7290// \ AtomEscape
7291// CharacterClass
7292// ( Disjunction )
7293// ( ? : Disjunction )
7294//
7295// PatternCharacter ::
7296// SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |
7297//
7298// AtomEscape ::
7299// DecimalEscape
7300// CharacterEscape
7301// CharacterClassEscape
7302//
7303// CharacterEscape[U] ::
7304// ControlEscape
7305// c ControlLetter
7306// HexEscapeSequence
7307// RegExpUnicodeEscapeSequence[?U] (ES6)
7308// IdentityEscape[?U]
7309//
7310// ControlEscape ::
7311// one of f n r t v
7312// ControlLetter ::
7313// one of
7314// 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
7315// 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
7316//
7317// IdentityEscape ::
7318// SourceCharacter but not IdentifierPart
7319// <ZWJ>
7320// <ZWNJ>
7321//
7322// DecimalEscape ::
7323// DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
7324//
7325// CharacterClassEscape ::
7326// one of d D s S w W
7327//
7328// CharacterClass ::
7329// [ [lookahead ∉ {^}] ClassRanges ]
7330// [ ^ ClassRanges ]
7331//
7332// ClassRanges ::
7333// [empty]
7334// NonemptyClassRanges
7335//
7336// NonemptyClassRanges ::
7337// ClassAtom
7338// ClassAtom NonemptyClassRangesNoDash
7339// ClassAtom - ClassAtom ClassRanges
7340//
7341// NonemptyClassRangesNoDash ::
7342// ClassAtom
7343// ClassAtomNoDash NonemptyClassRangesNoDash
7344// ClassAtomNoDash - ClassAtom ClassRanges
7345//
7346// ClassAtom ::
7347// -
7348// ClassAtomNoDash
7349//
7350// ClassAtomNoDash ::
7351// SourceCharacter but not one of \ or ] or -
7352// \ ClassEscape
7353//
7354// ClassEscape ::
7355// DecimalEscape
7356// b
7357// CharacterEscape
7358// CharacterClassEscape
7359
7360(function() {
7361
7362 function parse(str, flags, features) {
7363 if (!features) {
7364 features = {};
7365 }
7366 function addRaw(node) {
7367 node.raw = str.substring(node.range[0], node.range[1]);
7368 return node;
7369 }
7370
7371 function updateRawStart(node, start) {
7372 node.range[0] = start;
7373 return addRaw(node);
7374 }
7375
7376 function createAnchor(kind, rawLength) {
7377 return addRaw({
7378 type: 'anchor',
7379 kind: kind,
7380 range: [
7381 pos - rawLength,
7382 pos
7383 ]
7384 });
7385 }
7386
7387 function createValue(kind, codePoint, from, to) {
7388 return addRaw({
7389 type: 'value',
7390 kind: kind,
7391 codePoint: codePoint,
7392 range: [from, to]
7393 });
7394 }
7395
7396 function createEscaped(kind, codePoint, value, fromOffset) {
7397 fromOffset = fromOffset || 0;
7398 return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);
7399 }
7400
7401 function createCharacter(matches) {
7402 var _char = matches[0];
7403 var first = _char.charCodeAt(0);
7404 if (hasUnicodeFlag) {
7405 var second;
7406 if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
7407 second = lookahead().charCodeAt(0);
7408 if (second >= 0xDC00 && second <= 0xDFFF) {
7409 // Unicode surrogate pair
7410 pos++;
7411 return createValue(
7412 'symbol',
7413 (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,
7414 pos - 2, pos);
7415 }
7416 }
7417 }
7418 return createValue('symbol', first, pos - 1, pos);
7419 }
7420
7421 function createDisjunction(alternatives, from, to) {
7422 return addRaw({
7423 type: 'disjunction',
7424 body: alternatives,
7425 range: [
7426 from,
7427 to
7428 ]
7429 });
7430 }
7431
7432 function createDot() {
7433 return addRaw({
7434 type: 'dot',
7435 range: [
7436 pos - 1,
7437 pos
7438 ]
7439 });
7440 }
7441
7442 function createCharacterClassEscape(value) {
7443 return addRaw({
7444 type: 'characterClassEscape',
7445 value: value,
7446 range: [
7447 pos - 2,
7448 pos
7449 ]
7450 });
7451 }
7452
7453 function createReference(matchIndex) {
7454 return addRaw({
7455 type: 'reference',
7456 matchIndex: parseInt(matchIndex, 10),
7457 range: [
7458 pos - 1 - matchIndex.length,
7459 pos
7460 ]
7461 });
7462 }
7463
7464 function createGroup(behavior, disjunction, from, to) {
7465 return addRaw({
7466 type: 'group',
7467 behavior: behavior,
7468 body: disjunction,
7469 range: [
7470 from,
7471 to
7472 ]
7473 });
7474 }
7475
7476 function createQuantifier(min, max, from, to) {
7477 if (to == null) {
7478 from = pos - 1;
7479 to = pos;
7480 }
7481
7482 return addRaw({
7483 type: 'quantifier',
7484 min: min,
7485 max: max,
7486 greedy: true,
7487 body: null, // set later on
7488 range: [
7489 from,
7490 to
7491 ]
7492 });
7493 }
7494
7495 function createAlternative(terms, from, to) {
7496 return addRaw({
7497 type: 'alternative',
7498 body: terms,
7499 range: [
7500 from,
7501 to
7502 ]
7503 });
7504 }
7505
7506 function createCharacterClass(classRanges, negative, from, to) {
7507 return addRaw({
7508 type: 'characterClass',
7509 body: classRanges,
7510 negative: negative,
7511 range: [
7512 from,
7513 to
7514 ]
7515 });
7516 }
7517
7518 function createClassRange(min, max, from, to) {
7519 // See 15.10.2.15:
7520 if (min.codePoint > max.codePoint) {
7521 bail('invalid range in character class', min.raw + '-' + max.raw, from, to);
7522 }
7523
7524 return addRaw({
7525 type: 'characterClassRange',
7526 min: min,
7527 max: max,
7528 range: [
7529 from,
7530 to
7531 ]
7532 });
7533 }
7534
7535 function flattenBody(body) {
7536 if (body.type === 'alternative') {
7537 return body.body;
7538 } else {
7539 return [body];
7540 }
7541 }
7542
7543 function incr(amount) {
7544 amount = (amount || 1);
7545 var res = str.substring(pos, pos + amount);
7546 pos += (amount || 1);
7547 return res;
7548 }
7549
7550 function skip(value) {
7551 if (!match(value)) {
7552 bail('character', value);
7553 }
7554 }
7555
7556 function match(value) {
7557 if (str.indexOf(value, pos) === pos) {
7558 return incr(value.length);
7559 }
7560 }
7561
7562 function lookahead() {
7563 return str[pos];
7564 }
7565
7566 function current(value) {
7567 return str.indexOf(value, pos) === pos;
7568 }
7569
7570 function next(value) {
7571 return str[pos + 1] === value;
7572 }
7573
7574 function matchReg(regExp) {
7575 var subStr = str.substring(pos);
7576 var res = subStr.match(regExp);
7577 if (res) {
7578 res.range = [];
7579 res.range[0] = pos;
7580 incr(res[0].length);
7581 res.range[1] = pos;
7582 }
7583 return res;
7584 }
7585
7586 function parseDisjunction() {
7587 // Disjunction ::
7588 // Alternative
7589 // Alternative | Disjunction
7590 var res = [], from = pos;
7591 res.push(parseAlternative());
7592
7593 while (match('|')) {
7594 res.push(parseAlternative());
7595 }
7596
7597 if (res.length === 1) {
7598 return res[0];
7599 }
7600
7601 return createDisjunction(res, from, pos);
7602 }
7603
7604 function parseAlternative() {
7605 var res = [], from = pos;
7606 var term;
7607
7608 // Alternative ::
7609 // [empty]
7610 // Alternative Term
7611 while (term = parseTerm()) {
7612 res.push(term);
7613 }
7614
7615 if (res.length === 1) {
7616 return res[0];
7617 }
7618
7619 return createAlternative(res, from, pos);
7620 }
7621
7622 function parseTerm() {
7623 // Term ::
7624 // Anchor
7625 // Atom
7626 // Atom Quantifier
7627
7628 if (pos >= str.length || current('|') || current(')')) {
7629 return null; /* Means: The term is empty */
7630 }
7631
7632 var anchor = parseAnchor();
7633
7634 if (anchor) {
7635 return anchor;
7636 }
7637
7638 var atom = parseAtom();
7639 if (!atom) {
7640 bail('Expected atom');
7641 }
7642 var quantifier = parseQuantifier() || false;
7643 if (quantifier) {
7644 quantifier.body = flattenBody(atom);
7645 // The quantifier contains the atom. Therefore, the beginning of the
7646 // quantifier range is given by the beginning of the atom.
7647 updateRawStart(quantifier, atom.range[0]);
7648 return quantifier;
7649 }
7650 return atom;
7651 }
7652
7653 function parseGroup(matchA, typeA, matchB, typeB) {
7654 var type = null, from = pos;
7655
7656 if (match(matchA)) {
7657 type = typeA;
7658 } else if (match(matchB)) {
7659 type = typeB;
7660 } else {
7661 return false;
7662 }
7663
7664 var body = parseDisjunction();
7665 if (!body) {
7666 bail('Expected disjunction');
7667 }
7668 skip(')');
7669 var group = createGroup(type, flattenBody(body), from, pos);
7670
7671 if (type == 'normal') {
7672 // Keep track of the number of closed groups. This is required for
7673 // parseDecimalEscape(). In case the string is parsed a second time the
7674 // value already holds the total count and no incrementation is required.
7675 if (firstIteration) {
7676 closedCaptureCounter++;
7677 }
7678 }
7679 return group;
7680 }
7681
7682 function parseAnchor() {
7683 // Anchor ::
7684 // ^
7685 // $
7686 // \ b
7687 // \ B
7688 // ( ? = Disjunction )
7689 // ( ? ! Disjunction )
7690 if (match('^')) {
7691 return createAnchor('start', 1 /* rawLength */);
7692 } else if (match('$')) {
7693 return createAnchor('end', 1 /* rawLength */);
7694 } else if (match('\\b')) {
7695 return createAnchor('boundary', 2 /* rawLength */);
7696 } else if (match('\\B')) {
7697 return createAnchor('not-boundary', 2 /* rawLength */);
7698 } else {
7699 return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');
7700 }
7701 }
7702
7703 function parseQuantifier() {
7704 // Quantifier ::
7705 // QuantifierPrefix
7706 // QuantifierPrefix ?
7707 //
7708 // QuantifierPrefix ::
7709 // *
7710 // +
7711 // ?
7712 // { DecimalDigits }
7713 // { DecimalDigits , }
7714 // { DecimalDigits , DecimalDigits }
7715
7716 var res, from = pos;
7717 var quantifier;
7718 var min, max;
7719
7720 if (match('*')) {
7721 quantifier = createQuantifier(0);
7722 }
7723 else if (match('+')) {
7724 quantifier = createQuantifier(1);
7725 }
7726 else if (match('?')) {
7727 quantifier = createQuantifier(0, 1);
7728 }
7729 else if (res = matchReg(/^\{([0-9]+)\}/)) {
7730 min = parseInt(res[1], 10);
7731 quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
7732 }
7733 else if (res = matchReg(/^\{([0-9]+),\}/)) {
7734 min = parseInt(res[1], 10);
7735 quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
7736 }
7737 else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
7738 min = parseInt(res[1], 10);
7739 max = parseInt(res[2], 10);
7740 if (min > max) {
7741 bail('numbers out of order in {} quantifier', '', from, pos);
7742 }
7743 quantifier = createQuantifier(min, max, res.range[0], res.range[1]);
7744 }
7745
7746 if (quantifier) {
7747 if (match('?')) {
7748 quantifier.greedy = false;
7749 quantifier.range[1] += 1;
7750 }
7751 }
7752
7753 return quantifier;
7754 }
7755
7756 function parseAtom() {
7757 // Atom ::
7758 // PatternCharacter
7759 // .
7760 // \ AtomEscape
7761 // CharacterClass
7762 // ( Disjunction )
7763 // ( ? : Disjunction )
7764
7765 var res;
7766
7767 // jviereck: allow ']', '}' here as well to be compatible with browser's
7768 // implementations: ']'.match(/]/);
7769 // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) {
7770 if (res = matchReg(/^[^^$\\.*+?(){[|]/)) {
7771 // PatternCharacter
7772 return createCharacter(res);
7773 }
7774 else if (match('.')) {
7775 // .
7776 return createDot();
7777 }
7778 else if (match('\\')) {
7779 // \ AtomEscape
7780 res = parseAtomEscape();
7781 if (!res) {
7782 bail('atomEscape');
7783 }
7784 return res;
7785 }
7786 else if (res = parseCharacterClass()) {
7787 return res;
7788 }
7789 else {
7790 // ( Disjunction )
7791 // ( ? : Disjunction )
7792 return parseGroup('(?:', 'ignore', '(', 'normal');
7793 }
7794 }
7795
7796 function parseUnicodeSurrogatePairEscape(firstEscape) {
7797 if (hasUnicodeFlag) {
7798 var first, second;
7799 if (firstEscape.kind == 'unicodeEscape' &&
7800 (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&
7801 current('\\') && next('u') ) {
7802 var prevPos = pos;
7803 pos++;
7804 var secondEscape = parseClassEscape();
7805 if (secondEscape.kind == 'unicodeEscape' &&
7806 (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {
7807 // Unicode surrogate pair
7808 firstEscape.range[1] = secondEscape.range[1];
7809 firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
7810 firstEscape.type = 'value';
7811 firstEscape.kind = 'unicodeCodePointEscape';
7812 addRaw(firstEscape);
7813 }
7814 else {
7815 pos = prevPos;
7816 }
7817 }
7818 }
7819 return firstEscape;
7820 }
7821
7822 function parseClassEscape() {
7823 return parseAtomEscape(true);
7824 }
7825
7826 function parseAtomEscape(insideCharacterClass) {
7827 // AtomEscape ::
7828 // DecimalEscape
7829 // CharacterEscape
7830 // CharacterClassEscape
7831
7832 var res, from = pos;
7833
7834 res = parseDecimalEscape();
7835 if (res) {
7836 return res;
7837 }
7838
7839 // For ClassEscape
7840 if (insideCharacterClass) {
7841 if (match('b')) {
7842 // 15.10.2.19
7843 // The production ClassEscape :: b evaluates by returning the
7844 // CharSet containing the one character <BS> (Unicode value 0008).
7845 return createEscaped('singleEscape', 0x0008, '\\b');
7846 } else if (match('B')) {
7847 bail('\\B not possible inside of CharacterClass', '', from);
7848 }
7849 }
7850
7851 res = parseCharacterEscape();
7852
7853 return res;
7854 }
7855
7856
7857 function parseDecimalEscape() {
7858 // DecimalEscape ::
7859 // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
7860 // CharacterClassEscape :: one of d D s S w W
7861
7862 var res, match;
7863
7864 if (res = matchReg(/^(?!0)\d+/)) {
7865 match = res[0];
7866 var refIdx = parseInt(res[0], 10);
7867 if (refIdx <= closedCaptureCounter) {
7868 // If the number is smaller than the normal-groups found so
7869 // far, then it is a reference...
7870 return createReference(res[0]);
7871 } else {
7872 // ... otherwise it needs to be interpreted as a octal (if the
7873 // number is in an octal format). If it is NOT octal format,
7874 // then the slash is ignored and the number is matched later
7875 // as normal characters.
7876
7877 // Recall the negative decision to decide if the input must be parsed
7878 // a second time with the total normal-groups.
7879 backrefDenied.push(refIdx);
7880
7881 // Reset the position again, as maybe only parts of the previous
7882 // matched numbers are actual octal numbers. E.g. in '019' only
7883 // the '01' should be matched.
7884 incr(-res[0].length);
7885 if (res = matchReg(/^[0-7]{1,3}/)) {
7886 return createEscaped('octal', parseInt(res[0], 8), res[0], 1);
7887 } else {
7888 // If we end up here, we have a case like /\91/. Then the
7889 // first slash is to be ignored and the 9 & 1 to be treated
7890 // like ordinary characters. Create a character for the
7891 // first number only here - other number-characters
7892 // (if available) will be matched later.
7893 res = createCharacter(matchReg(/^[89]/));
7894 return updateRawStart(res, res.range[0] - 1);
7895 }
7896 }
7897 }
7898 // Only allow octal numbers in the following. All matched numbers start
7899 // with a zero (if the do not, the previous if-branch is executed).
7900 // If the number is not octal format and starts with zero (e.g. `091`)
7901 // then only the zeros `0` is treated here and the `91` are ordinary
7902 // characters.
7903 // Example:
7904 // /\091/.exec('\091')[0].length === 3
7905 else if (res = matchReg(/^[0-7]{1,3}/)) {
7906 match = res[0];
7907 if (/^0{1,3}$/.test(match)) {
7908 // If they are all zeros, then only take the first one.
7909 return createEscaped('null', 0x0000, '0', match.length + 1);
7910 } else {
7911 return createEscaped('octal', parseInt(match, 8), match, 1);
7912 }
7913 } else if (res = matchReg(/^[dDsSwW]/)) {
7914 return createCharacterClassEscape(res[0]);
7915 }
7916 return false;
7917 }
7918
7919 function parseCharacterEscape() {
7920 // CharacterEscape ::
7921 // ControlEscape
7922 // c ControlLetter
7923 // HexEscapeSequence
7924 // UnicodeEscapeSequence
7925 // IdentityEscape
7926
7927 var res;
7928 if (res = matchReg(/^[fnrtv]/)) {
7929 // ControlEscape
7930 var codePoint = 0;
7931 switch (res[0]) {
7932 case 't': codePoint = 0x009; break;
7933 case 'n': codePoint = 0x00A; break;
7934 case 'v': codePoint = 0x00B; break;
7935 case 'f': codePoint = 0x00C; break;
7936 case 'r': codePoint = 0x00D; break;
7937 }
7938 return createEscaped('singleEscape', codePoint, '\\' + res[0]);
7939 } else if (res = matchReg(/^c([a-zA-Z])/)) {
7940 // c ControlLetter
7941 return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);
7942 } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) {
7943 // HexEscapeSequence
7944 return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2);
7945 } else if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {
7946 // UnicodeEscapeSequence
7947 return parseUnicodeSurrogatePairEscape(
7948 createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2)
7949 );
7950 } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {
7951 // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)
7952 return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);
7953 } else if (features.unicodePropertyEscape && hasUnicodeFlag && (res = matchReg(/^([pP])\{([^\}]+)\}/))) {
7954 // https://github.com/jviereck/regjsparser/issues/77
7955 return addRaw({
7956 type: 'unicodePropertyEscape',
7957 negative: res[1] === 'P',
7958 value: res[2],
7959 range: [res.range[0] - 1, res.range[1]],
7960 raw: res[0]
7961 });
7962 } else {
7963 // IdentityEscape
7964 return parseIdentityEscape();
7965 }
7966 }
7967
7968 // Taken from the Esprima parser.
7969 function isIdentifierPart(ch) {
7970 // Generated by `tools/generate-identifier-regex.js`.
7971 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]');
7972
7973 return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
7974 (ch >= 65 && ch <= 90) || // A..Z
7975 (ch >= 97 && ch <= 122) || // a..z
7976 (ch >= 48 && ch <= 57) || // 0..9
7977 (ch === 92) || // \ (backslash)
7978 ((ch >= 0x80) && NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
7979 }
7980
7981 function parseIdentityEscape() {
7982 // IdentityEscape ::
7983 // SourceCharacter but not IdentifierPart
7984 // <ZWJ>
7985 // <ZWNJ>
7986
7987 var ZWJ = '\u200C';
7988 var ZWNJ = '\u200D';
7989
7990 var tmp;
7991
7992 if (!isIdentifierPart(lookahead())) {
7993 tmp = incr();
7994 return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1);
7995 }
7996
7997 if (match(ZWJ)) {
7998 // <ZWJ>
7999 return createEscaped('identifier', 0x200C, ZWJ);
8000 } else if (match(ZWNJ)) {
8001 // <ZWNJ>
8002 return createEscaped('identifier', 0x200D, ZWNJ);
8003 }
8004
8005 return null;
8006 }
8007
8008 function parseCharacterClass() {
8009 // CharacterClass ::
8010 // [ [lookahead ∉ {^}] ClassRanges ]
8011 // [ ^ ClassRanges ]
8012
8013 var res, from = pos;
8014 if (res = matchReg(/^\[\^/)) {
8015 res = parseClassRanges();
8016 skip(']');
8017 return createCharacterClass(res, true, from, pos);
8018 } else if (match('[')) {
8019 res = parseClassRanges();
8020 skip(']');
8021 return createCharacterClass(res, false, from, pos);
8022 }
8023
8024 return null;
8025 }
8026
8027 function parseClassRanges() {
8028 // ClassRanges ::
8029 // [empty]
8030 // NonemptyClassRanges
8031
8032 var res;
8033 if (current(']')) {
8034 // Empty array means nothing insinde of the ClassRange.
8035 return [];
8036 } else {
8037 res = parseNonemptyClassRanges();
8038 if (!res) {
8039 bail('nonEmptyClassRanges');
8040 }
8041 return res;
8042 }
8043 }
8044
8045 function parseHelperClassRanges(atom) {
8046 var from, to, res;
8047 if (current('-') && !next(']')) {
8048 // ClassAtom - ClassAtom ClassRanges
8049 skip('-');
8050
8051 res = parseClassAtom();
8052 if (!res) {
8053 bail('classAtom');
8054 }
8055 to = pos;
8056 var classRanges = parseClassRanges();
8057 if (!classRanges) {
8058 bail('classRanges');
8059 }
8060 from = atom.range[0];
8061 if (classRanges.type === 'empty') {
8062 return [createClassRange(atom, res, from, to)];
8063 }
8064 return [createClassRange(atom, res, from, to)].concat(classRanges);
8065 }
8066
8067 res = parseNonemptyClassRangesNoDash();
8068 if (!res) {
8069 bail('nonEmptyClassRangesNoDash');
8070 }
8071
8072 return [atom].concat(res);
8073 }
8074
8075 function parseNonemptyClassRanges() {
8076 // NonemptyClassRanges ::
8077 // ClassAtom
8078 // ClassAtom NonemptyClassRangesNoDash
8079 // ClassAtom - ClassAtom ClassRanges
8080
8081 var atom = parseClassAtom();
8082 if (!atom) {
8083 bail('classAtom');
8084 }
8085
8086 if (current(']')) {
8087 // ClassAtom
8088 return [atom];
8089 }
8090
8091 // ClassAtom NonemptyClassRangesNoDash
8092 // ClassAtom - ClassAtom ClassRanges
8093 return parseHelperClassRanges(atom);
8094 }
8095
8096 function parseNonemptyClassRangesNoDash() {
8097 // NonemptyClassRangesNoDash ::
8098 // ClassAtom
8099 // ClassAtomNoDash NonemptyClassRangesNoDash
8100 // ClassAtomNoDash - ClassAtom ClassRanges
8101
8102 var res = parseClassAtom();
8103 if (!res) {
8104 bail('classAtom');
8105 }
8106 if (current(']')) {
8107 // ClassAtom
8108 return res;
8109 }
8110
8111 // ClassAtomNoDash NonemptyClassRangesNoDash
8112 // ClassAtomNoDash - ClassAtom ClassRanges
8113 return parseHelperClassRanges(res);
8114 }
8115
8116 function parseClassAtom() {
8117 // ClassAtom ::
8118 // -
8119 // ClassAtomNoDash
8120 if (match('-')) {
8121 return createCharacter('-');
8122 } else {
8123 return parseClassAtomNoDash();
8124 }
8125 }
8126
8127 function parseClassAtomNoDash() {
8128 // ClassAtomNoDash ::
8129 // SourceCharacter but not one of \ or ] or -
8130 // \ ClassEscape
8131
8132 var res;
8133 if (res = matchReg(/^[^\\\]-]/)) {
8134 return createCharacter(res[0]);
8135 } else if (match('\\')) {
8136 res = parseClassEscape();
8137 if (!res) {
8138 bail('classEscape');
8139 }
8140
8141 return parseUnicodeSurrogatePairEscape(res);
8142 }
8143 }
8144
8145 function bail(message, details, from, to) {
8146 from = from == null ? pos : from;
8147 to = to == null ? from : to;
8148
8149 var contextStart = Math.max(0, from - 10);
8150 var contextEnd = Math.min(to + 10, str.length);
8151
8152 // Output a bit of context and a line pointing to where our error is.
8153 //
8154 // We are assuming that there are no actual newlines in the content as this is a regular expression.
8155 var context = ' ' + str.substring(contextStart, contextEnd);
8156 var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^';
8157
8158 throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer);
8159 }
8160
8161 var backrefDenied = [];
8162 var closedCaptureCounter = 0;
8163 var firstIteration = true;
8164 var hasUnicodeFlag = (flags || "").indexOf("u") !== -1;
8165 var pos = 0;
8166
8167 // Convert the input to a string and treat the empty string special.
8168 str = String(str);
8169 if (str === '') {
8170 str = '(?:)';
8171 }
8172
8173 var result = parseDisjunction();
8174
8175 if (result.range[1] !== str.length) {
8176 bail('Could not parse entire input - got stuck', '', result.range[1]);
8177 }
8178
8179 // The spec requires to interpret the `\2` in `/\2()()/` as backreference.
8180 // As the parser collects the number of capture groups as the string is
8181 // parsed it is impossible to make these decisions at the point when the
8182 // `\2` is handled. In case the local decision turns out to be wrong after
8183 // the parsing has finished, the input string is parsed a second time with
8184 // the total number of capture groups set.
8185 //
8186 // SEE: https://github.com/jviereck/regjsparser/issues/70
8187 for (var i = 0; i < backrefDenied.length; i++) {
8188 if (backrefDenied[i] <= closedCaptureCounter) {
8189 // Parse the input a second time.
8190 pos = 0;
8191 firstIteration = false;
8192 return parseDisjunction();
8193 }
8194 }
8195
8196 return result;
8197 }
8198
8199 var regjsparser = {
8200 parse: parse
8201 };
8202
8203 if ('object' !== 'undefined' && module.exports) {
8204 module.exports = regjsparser;
8205 } else {
8206 window.regjsparser = regjsparser;
8207 }
8208
8209}());
8210});
8211
8212var regenerate = createCommonjsModule(function (module, exports) {
8213/*! https://mths.be/regenerate v1.3.3 by @mathias | MIT license */
8214(function(root) {
8215
8216 // Detect free variables `exports`.
8217 var freeExports = 'object' == 'object' && exports;
8218
8219 // Detect free variable `module`.
8220 var freeModule = 'object' == 'object' && module &&
8221 module.exports == freeExports && module;
8222
8223 // Detect free variable `global`, from Node.js/io.js or Browserified code,
8224 // and use it as `root`.
8225 var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
8226 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
8227 root = freeGlobal;
8228 }
8229
8230 /*--------------------------------------------------------------------------*/
8231
8232 var ERRORS = {
8233 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
8234 'to the `start` value.',
8235 'codePointRange': 'Invalid code point value. Code points range from ' +
8236 'U+000000 to U+10FFFF.'
8237 };
8238
8239 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
8240 var HIGH_SURROGATE_MIN = 0xD800;
8241 var HIGH_SURROGATE_MAX = 0xDBFF;
8242 var LOW_SURROGATE_MIN = 0xDC00;
8243 var LOW_SURROGATE_MAX = 0xDFFF;
8244
8245 // In Regenerate output, `\0` is never preceded by `\` because we sort by
8246 // code point value, so let’s keep this regular expression simple.
8247 var regexNull = /\\x00([^0123456789]|$)/g;
8248
8249 var object = {};
8250 var hasOwnProperty = object.hasOwnProperty;
8251 var extend = function(destination, source) {
8252 var key;
8253 for (key in source) {
8254 if (hasOwnProperty.call(source, key)) {
8255 destination[key] = source[key];
8256 }
8257 }
8258 return destination;
8259 };
8260
8261 var forEach = function(array, callback) {
8262 var index = -1;
8263 var length = array.length;
8264 while (++index < length) {
8265 callback(array[index], index);
8266 }
8267 };
8268
8269 var toString = object.toString;
8270 var isArray = function(value) {
8271 return toString.call(value) == '[object Array]';
8272 };
8273 var isNumber = function(value) {
8274 return typeof value == 'number' ||
8275 toString.call(value) == '[object Number]';
8276 };
8277
8278 // This assumes that `number` is a positive integer that `toString()`s nicely
8279 // (which is the case for all code point values).
8280 var zeroes = '0000';
8281 var pad = function(number, totalCharacters) {
8282 var string = String(number);
8283 return string.length < totalCharacters
8284 ? (zeroes + string).slice(-totalCharacters)
8285 : string;
8286 };
8287
8288 var hex = function(number) {
8289 return Number(number).toString(16).toUpperCase();
8290 };
8291
8292 var slice = [].slice;
8293
8294 /*--------------------------------------------------------------------------*/
8295
8296 var dataFromCodePoints = function(codePoints) {
8297 var index = -1;
8298 var length = codePoints.length;
8299 var max = length - 1;
8300 var result = [];
8301 var isStart = true;
8302 var tmp;
8303 var previous = 0;
8304 while (++index < length) {
8305 tmp = codePoints[index];
8306 if (isStart) {
8307 result.push(tmp);
8308 previous = tmp;
8309 isStart = false;
8310 } else {
8311 if (tmp == previous + 1) {
8312 if (index != max) {
8313 previous = tmp;
8314 continue;
8315 } else {
8316 isStart = true;
8317 result.push(tmp + 1);
8318 }
8319 } else {
8320 // End the previous range and start a new one.
8321 result.push(previous + 1, tmp);
8322 previous = tmp;
8323 }
8324 }
8325 }
8326 if (!isStart) {
8327 result.push(tmp + 1);
8328 }
8329 return result;
8330 };
8331
8332 var dataRemove = function(data, codePoint) {
8333 // Iterate over the data per `(start, end)` pair.
8334 var index = 0;
8335 var start;
8336 var end;
8337 var length = data.length;
8338 while (index < length) {
8339 start = data[index];
8340 end = data[index + 1];
8341 if (codePoint >= start && codePoint < end) {
8342 // Modify this pair.
8343 if (codePoint == start) {
8344 if (end == start + 1) {
8345 // Just remove `start` and `end`.
8346 data.splice(index, 2);
8347 return data;
8348 } else {
8349 // Just replace `start` with a new value.
8350 data[index] = codePoint + 1;
8351 return data;
8352 }
8353 } else if (codePoint == end - 1) {
8354 // Just replace `end` with a new value.
8355 data[index + 1] = codePoint;
8356 return data;
8357 } else {
8358 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
8359 data.splice(index, 2, start, codePoint, codePoint + 1, end);
8360 return data;
8361 }
8362 }
8363 index += 2;
8364 }
8365 return data;
8366 };
8367
8368 var dataRemoveRange = function(data, rangeStart, rangeEnd) {
8369 if (rangeEnd < rangeStart) {
8370 throw Error(ERRORS.rangeOrder);
8371 }
8372 // Iterate over the data per `(start, end)` pair.
8373 var index = 0;
8374 var start;
8375 var end;
8376 while (index < data.length) {
8377 start = data[index];
8378 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8379
8380 // Exit as soon as no more matching pairs can be found.
8381 if (start > rangeEnd) {
8382 return data;
8383 }
8384
8385 // Check if this range pair is equal to, or forms a subset of, the range
8386 // to be removed.
8387 // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
8388 // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
8389 if (rangeStart <= start && rangeEnd >= end) {
8390 // Remove this pair.
8391 data.splice(index, 2);
8392 continue;
8393 }
8394
8395 // Check if both `rangeStart` and `rangeEnd` are within the bounds of
8396 // this pair.
8397 // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
8398 if (rangeStart >= start && rangeEnd < end) {
8399 if (rangeStart == start) {
8400 // Replace `[start, end]` with `[startB, endB]`.
8401 data[index] = rangeEnd + 1;
8402 data[index + 1] = end + 1;
8403 return data;
8404 }
8405 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
8406 data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
8407 return data;
8408 }
8409
8410 // Check if only `rangeStart` is within the bounds of this pair.
8411 // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
8412 if (rangeStart >= start && rangeStart <= end) {
8413 // Replace `end` with `rangeStart`.
8414 data[index + 1] = rangeStart;
8415 // Note: we cannot `return` just yet, in case any following pairs still
8416 // contain matching code points.
8417 // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
8418 // → `[0, 4, 21, 31]`.
8419 }
8420
8421 // Check if only `rangeEnd` is within the bounds of this pair.
8422 // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
8423 else if (rangeEnd >= start && rangeEnd <= end) {
8424 // Just replace `start`.
8425 data[index] = rangeEnd + 1;
8426 return data;
8427 }
8428
8429 index += 2;
8430 }
8431 return data;
8432 };
8433
8434 var dataAdd = function(data, codePoint) {
8435 // Iterate over the data per `(start, end)` pair.
8436 var index = 0;
8437 var start;
8438 var end;
8439 var lastIndex = null;
8440 var length = data.length;
8441 if (codePoint < 0x0 || codePoint > 0x10FFFF) {
8442 throw RangeError(ERRORS.codePointRange);
8443 }
8444 while (index < length) {
8445 start = data[index];
8446 end = data[index + 1];
8447
8448 // Check if the code point is already in the set.
8449 if (codePoint >= start && codePoint < end) {
8450 return data;
8451 }
8452
8453 if (codePoint == start - 1) {
8454 // Just replace `start` with a new value.
8455 data[index] = codePoint;
8456 return data;
8457 }
8458
8459 // At this point, if `start` is `greater` than `codePoint`, insert a new
8460 // `[start, end]` pair before the current pair, or after the current pair
8461 // if there is a known `lastIndex`.
8462 if (start > codePoint) {
8463 data.splice(
8464 lastIndex != null ? lastIndex + 2 : 0,
8465 0,
8466 codePoint,
8467 codePoint + 1
8468 );
8469 return data;
8470 }
8471
8472 if (codePoint == end) {
8473 // Check if adding this code point causes two separate ranges to become
8474 // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
8475 if (codePoint + 1 == data[index + 2]) {
8476 data.splice(index, 4, start, data[index + 3]);
8477 return data;
8478 }
8479 // Else, just replace `end` with a new value.
8480 data[index + 1] = codePoint + 1;
8481 return data;
8482 }
8483 lastIndex = index;
8484 index += 2;
8485 }
8486 // The loop has finished; add the new pair to the end of the data set.
8487 data.push(codePoint, codePoint + 1);
8488 return data;
8489 };
8490
8491 var dataAddData = function(dataA, dataB) {
8492 // Iterate over the data per `(start, end)` pair.
8493 var index = 0;
8494 var start;
8495 var end;
8496 var data = dataA.slice();
8497 var length = dataB.length;
8498 while (index < length) {
8499 start = dataB[index];
8500 end = dataB[index + 1] - 1;
8501 if (start == end) {
8502 data = dataAdd(data, start);
8503 } else {
8504 data = dataAddRange(data, start, end);
8505 }
8506 index += 2;
8507 }
8508 return data;
8509 };
8510
8511 var dataRemoveData = function(dataA, dataB) {
8512 // Iterate over the data per `(start, end)` pair.
8513 var index = 0;
8514 var start;
8515 var end;
8516 var data = dataA.slice();
8517 var length = dataB.length;
8518 while (index < length) {
8519 start = dataB[index];
8520 end = dataB[index + 1] - 1;
8521 if (start == end) {
8522 data = dataRemove(data, start);
8523 } else {
8524 data = dataRemoveRange(data, start, end);
8525 }
8526 index += 2;
8527 }
8528 return data;
8529 };
8530
8531 var dataAddRange = function(data, rangeStart, rangeEnd) {
8532 if (rangeEnd < rangeStart) {
8533 throw Error(ERRORS.rangeOrder);
8534 }
8535 if (
8536 rangeStart < 0x0 || rangeStart > 0x10FFFF ||
8537 rangeEnd < 0x0 || rangeEnd > 0x10FFFF
8538 ) {
8539 throw RangeError(ERRORS.codePointRange);
8540 }
8541 // Iterate over the data per `(start, end)` pair.
8542 var index = 0;
8543 var start;
8544 var end;
8545 var added = false;
8546 var length = data.length;
8547 while (index < length) {
8548 start = data[index];
8549 end = data[index + 1];
8550
8551 if (added) {
8552 // The range has already been added to the set; at this point, we just
8553 // need to get rid of the following ranges in case they overlap.
8554
8555 // Check if this range can be combined with the previous range.
8556 if (start == rangeEnd + 1) {
8557 data.splice(index - 1, 2);
8558 return data;
8559 }
8560
8561 // Exit as soon as no more possibly overlapping pairs can be found.
8562 if (start > rangeEnd) {
8563 return data;
8564 }
8565
8566 // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
8567 // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
8568 // `0,16` range that was previously added.
8569 if (start >= rangeStart && start <= rangeEnd) {
8570 // `start` lies within the range that was previously added.
8571
8572 if (end > rangeStart && end - 1 <= rangeEnd) {
8573 // `end` lies within the range that was previously added as well,
8574 // so remove this pair.
8575 data.splice(index, 2);
8576 index -= 2;
8577 // Note: we cannot `return` just yet, as there may still be other
8578 // overlapping pairs.
8579 } else {
8580 // `start` lies within the range that was previously added, but
8581 // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
8582 // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
8583 // Remove the previously added `end` and the current `start`.
8584 data.splice(index - 1, 2);
8585 index -= 2;
8586 }
8587
8588 // Note: we cannot return yet.
8589 }
8590
8591 }
8592
8593 else if (start == rangeEnd + 1) {
8594 data[index] = rangeStart;
8595 return data;
8596 }
8597
8598 // Check if a new pair must be inserted *before* the current one.
8599 else if (start > rangeEnd) {
8600 data.splice(index, 0, rangeStart, rangeEnd + 1);
8601 return data;
8602 }
8603
8604 else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
8605 // The new range lies entirely within an existing range pair. No action
8606 // needed.
8607 return data;
8608 }
8609
8610 else if (
8611 // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
8612 (rangeStart >= start && rangeStart < end) ||
8613 // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
8614 end == rangeStart
8615 ) {
8616 // Replace `end` with the new value.
8617 data[index + 1] = rangeEnd + 1;
8618 // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
8619 // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
8620 added = true;
8621 // Note: we cannot `return` just yet.
8622 }
8623
8624 else if (rangeStart <= start && rangeEnd + 1 >= end) {
8625 // The new range is a superset of the old range.
8626 data[index] = rangeStart;
8627 data[index + 1] = rangeEnd + 1;
8628 added = true;
8629 }
8630
8631 index += 2;
8632 }
8633 // The loop has finished without doing anything; add the new pair to the end
8634 // of the data set.
8635 if (!added) {
8636 data.push(rangeStart, rangeEnd + 1);
8637 }
8638 return data;
8639 };
8640
8641 var dataContains = function(data, codePoint) {
8642 var index = 0;
8643 var length = data.length;
8644 // Exit early if `codePoint` is not within `data`’s overall range.
8645 var start = data[index];
8646 var end = data[length - 1];
8647 if (length >= 2) {
8648 if (codePoint < start || codePoint > end) {
8649 return false;
8650 }
8651 }
8652 // Iterate over the data per `(start, end)` pair.
8653 while (index < length) {
8654 start = data[index];
8655 end = data[index + 1];
8656 if (codePoint >= start && codePoint < end) {
8657 return true;
8658 }
8659 index += 2;
8660 }
8661 return false;
8662 };
8663
8664 var dataIntersection = function(data, codePoints) {
8665 var index = 0;
8666 var length = codePoints.length;
8667 var codePoint;
8668 var result = [];
8669 while (index < length) {
8670 codePoint = codePoints[index];
8671 if (dataContains(data, codePoint)) {
8672 result.push(codePoint);
8673 }
8674 ++index;
8675 }
8676 return dataFromCodePoints(result);
8677 };
8678
8679 var dataIsEmpty = function(data) {
8680 return !data.length;
8681 };
8682
8683 var dataIsSingleton = function(data) {
8684 // Check if the set only represents a single code point.
8685 return data.length == 2 && data[0] + 1 == data[1];
8686 };
8687
8688 var dataToArray = function(data) {
8689 // Iterate over the data per `(start, end)` pair.
8690 var index = 0;
8691 var start;
8692 var end;
8693 var result = [];
8694 var length = data.length;
8695 while (index < length) {
8696 start = data[index];
8697 end = data[index + 1];
8698 while (start < end) {
8699 result.push(start);
8700 ++start;
8701 }
8702 index += 2;
8703 }
8704 return result;
8705 };
8706
8707 /*--------------------------------------------------------------------------*/
8708
8709 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
8710 var floor = Math.floor;
8711 var highSurrogate = function(codePoint) {
8712 return parseInt(
8713 floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
8714 10
8715 );
8716 };
8717
8718 var lowSurrogate = function(codePoint) {
8719 return parseInt(
8720 (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
8721 10
8722 );
8723 };
8724
8725 var stringFromCharCode = String.fromCharCode;
8726 var codePointToString = function(codePoint) {
8727 var string;
8728 // https://mathiasbynens.be/notes/javascript-escapes#single
8729 // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
8730 // different meaning in regular expressions (word boundary), so it cannot
8731 // be used here.
8732 if (codePoint == 0x09) {
8733 string = '\\t';
8734 }
8735 // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
8736 // else if (codePoint == 0x0B) {
8737 // string = '\\v';
8738 // }
8739 else if (codePoint == 0x0A) {
8740 string = '\\n';
8741 }
8742 else if (codePoint == 0x0C) {
8743 string = '\\f';
8744 }
8745 else if (codePoint == 0x0D) {
8746 string = '\\r';
8747 }
8748 else if (codePoint == 0x5C) {
8749 string = '\\\\';
8750 }
8751 else if (
8752 codePoint == 0x24 ||
8753 (codePoint >= 0x28 && codePoint <= 0x2B) ||
8754 (codePoint >= 0x2D && codePoint <= 0x2F) ||
8755 codePoint == 0x3F ||
8756 (codePoint >= 0x5B && codePoint <= 0x5E) ||
8757 (codePoint >= 0x7B && codePoint <= 0x7D)
8758 ) {
8759 // The code point maps to an unsafe printable ASCII character;
8760 // backslash-escape it. Here’s the list of those symbols:
8761 //
8762 // $()*+-./?[\]^{|}
8763 //
8764 // See #7 for more info.
8765 string = '\\' + stringFromCharCode(codePoint);
8766 }
8767 else if (codePoint >= 0x20 && codePoint <= 0x7E) {
8768 // The code point maps to one of these printable ASCII symbols
8769 // (including the space character):
8770 //
8771 // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
8772 // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
8773 //
8774 // These can safely be used directly.
8775 string = stringFromCharCode(codePoint);
8776 }
8777 else if (codePoint <= 0xFF) {
8778 // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
8779 string = '\\x' + pad(hex(codePoint), 2);
8780 }
8781 else { // `codePoint <= 0xFFFF` holds true.
8782 // https://mathiasbynens.be/notes/javascript-escapes#unicode
8783 string = '\\u' + pad(hex(codePoint), 4);
8784 }
8785
8786 // There’s no need to account for astral symbols / surrogate pairs here,
8787 // since `codePointToString` is private and only used for BMP code points.
8788 // But if that’s what you need, just add an `else` block with this code:
8789 //
8790 // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
8791 // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
8792
8793 return string;
8794 };
8795
8796 var codePointToStringUnicode = function(codePoint) {
8797 if (codePoint <= 0xFFFF) {
8798 return codePointToString(codePoint);
8799 }
8800 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
8801 };
8802
8803 var symbolToCodePoint = function(symbol) {
8804 var length = symbol.length;
8805 var first = symbol.charCodeAt(0);
8806 var second;
8807 if (
8808 first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
8809 length > 1 // There is a next code unit.
8810 ) {
8811 // `first` is a high surrogate, and there is a next character. Assume
8812 // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
8813 second = symbol.charCodeAt(1);
8814 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
8815 return (first - HIGH_SURROGATE_MIN) * 0x400 +
8816 second - LOW_SURROGATE_MIN + 0x10000;
8817 }
8818 return first;
8819 };
8820
8821 var createBMPCharacterClasses = function(data) {
8822 // Iterate over the data per `(start, end)` pair.
8823 var result = '';
8824 var index = 0;
8825 var start;
8826 var end;
8827 var length = data.length;
8828 if (dataIsSingleton(data)) {
8829 return codePointToString(data[0]);
8830 }
8831 while (index < length) {
8832 start = data[index];
8833 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8834 if (start == end) {
8835 result += codePointToString(start);
8836 } else if (start + 1 == end) {
8837 result += codePointToString(start) + codePointToString(end);
8838 } else {
8839 result += codePointToString(start) + '-' + codePointToString(end);
8840 }
8841 index += 2;
8842 }
8843 return '[' + result + ']';
8844 };
8845
8846 var createUnicodeCharacterClasses = function(data) {
8847 // Iterate over the data per `(start, end)` pair.
8848 var result = '';
8849 var index = 0;
8850 var start;
8851 var end;
8852 var length = data.length;
8853 if (dataIsSingleton(data)) {
8854 return codePointToStringUnicode(data[0]);
8855 }
8856 while (index < length) {
8857 start = data[index];
8858 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8859 if (start == end) {
8860 result += codePointToStringUnicode(start);
8861 } else if (start + 1 == end) {
8862 result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
8863 } else {
8864 result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
8865 }
8866 index += 2;
8867 }
8868 return '[' + result + ']';
8869 };
8870
8871 var splitAtBMP = function(data) {
8872 // Iterate over the data per `(start, end)` pair.
8873 var loneHighSurrogates = [];
8874 var loneLowSurrogates = [];
8875 var bmp = [];
8876 var astral = [];
8877 var index = 0;
8878 var start;
8879 var end;
8880 var length = data.length;
8881 while (index < length) {
8882 start = data[index];
8883 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8884
8885 if (start < HIGH_SURROGATE_MIN) {
8886
8887 // The range starts and ends before the high surrogate range.
8888 // E.g. (0, 0x10).
8889 if (end < HIGH_SURROGATE_MIN) {
8890 bmp.push(start, end + 1);
8891 }
8892
8893 // The range starts before the high surrogate range and ends within it.
8894 // E.g. (0, 0xD855).
8895 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
8896 bmp.push(start, HIGH_SURROGATE_MIN);
8897 loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
8898 }
8899
8900 // The range starts before the high surrogate range and ends in the low
8901 // surrogate range. E.g. (0, 0xDCFF).
8902 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8903 bmp.push(start, HIGH_SURROGATE_MIN);
8904 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
8905 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
8906 }
8907
8908 // The range starts before the high surrogate range and ends after the
8909 // low surrogate range. E.g. (0, 0x10FFFF).
8910 if (end > LOW_SURROGATE_MAX) {
8911 bmp.push(start, HIGH_SURROGATE_MIN);
8912 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
8913 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
8914 if (end <= 0xFFFF) {
8915 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8916 } else {
8917 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8918 astral.push(0xFFFF + 1, end + 1);
8919 }
8920 }
8921
8922 } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
8923
8924 // The range starts and ends in the high surrogate range.
8925 // E.g. (0xD855, 0xD866).
8926 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
8927 loneHighSurrogates.push(start, end + 1);
8928 }
8929
8930 // The range starts in the high surrogate range and ends in the low
8931 // surrogate range. E.g. (0xD855, 0xDCFF).
8932 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8933 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
8934 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
8935 }
8936
8937 // The range starts in the high surrogate range and ends after the low
8938 // surrogate range. E.g. (0xD855, 0x10FFFF).
8939 if (end > LOW_SURROGATE_MAX) {
8940 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
8941 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
8942 if (end <= 0xFFFF) {
8943 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8944 } else {
8945 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8946 astral.push(0xFFFF + 1, end + 1);
8947 }
8948 }
8949
8950 } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
8951
8952 // The range starts and ends in the low surrogate range.
8953 // E.g. (0xDCFF, 0xDDFF).
8954 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8955 loneLowSurrogates.push(start, end + 1);
8956 }
8957
8958 // The range starts in the low surrogate range and ends after the low
8959 // surrogate range. E.g. (0xDCFF, 0x10FFFF).
8960 if (end > LOW_SURROGATE_MAX) {
8961 loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
8962 if (end <= 0xFFFF) {
8963 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8964 } else {
8965 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8966 astral.push(0xFFFF + 1, end + 1);
8967 }
8968 }
8969
8970 } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
8971
8972 // The range starts and ends after the low surrogate range.
8973 // E.g. (0xFFAA, 0x10FFFF).
8974 if (end <= 0xFFFF) {
8975 bmp.push(start, end + 1);
8976 } else {
8977 bmp.push(start, 0xFFFF + 1);
8978 astral.push(0xFFFF + 1, end + 1);
8979 }
8980
8981 } else {
8982
8983 // The range starts and ends in the astral range.
8984 astral.push(start, end + 1);
8985
8986 }
8987
8988 index += 2;
8989 }
8990 return {
8991 'loneHighSurrogates': loneHighSurrogates,
8992 'loneLowSurrogates': loneLowSurrogates,
8993 'bmp': bmp,
8994 'astral': astral
8995 };
8996 };
8997
8998 var optimizeSurrogateMappings = function(surrogateMappings) {
8999 var result = [];
9000 var tmpLow = [];
9001 var addLow = false;
9002 var mapping;
9003 var nextMapping;
9004 var highSurrogates;
9005 var lowSurrogates;
9006 var nextHighSurrogates;
9007 var nextLowSurrogates;
9008 var index = -1;
9009 var length = surrogateMappings.length;
9010 while (++index < length) {
9011 mapping = surrogateMappings[index];
9012 nextMapping = surrogateMappings[index + 1];
9013 if (!nextMapping) {
9014 result.push(mapping);
9015 continue;
9016 }
9017 highSurrogates = mapping[0];
9018 lowSurrogates = mapping[1];
9019 nextHighSurrogates = nextMapping[0];
9020 nextLowSurrogates = nextMapping[1];
9021
9022 // Check for identical high surrogate ranges.
9023 tmpLow = lowSurrogates;
9024 while (
9025 nextHighSurrogates &&
9026 highSurrogates[0] == nextHighSurrogates[0] &&
9027 highSurrogates[1] == nextHighSurrogates[1]
9028 ) {
9029 // Merge with the next item.
9030 if (dataIsSingleton(nextLowSurrogates)) {
9031 tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
9032 } else {
9033 tmpLow = dataAddRange(
9034 tmpLow,
9035 nextLowSurrogates[0],
9036 nextLowSurrogates[1] - 1
9037 );
9038 }
9039 ++index;
9040 mapping = surrogateMappings[index];
9041 highSurrogates = mapping[0];
9042 lowSurrogates = mapping[1];
9043 nextMapping = surrogateMappings[index + 1];
9044 nextHighSurrogates = nextMapping && nextMapping[0];
9045 nextLowSurrogates = nextMapping && nextMapping[1];
9046 addLow = true;
9047 }
9048 result.push([
9049 highSurrogates,
9050 addLow ? tmpLow : lowSurrogates
9051 ]);
9052 addLow = false;
9053 }
9054 return optimizeByLowSurrogates(result);
9055 };
9056
9057 var optimizeByLowSurrogates = function(surrogateMappings) {
9058 if (surrogateMappings.length == 1) {
9059 return surrogateMappings;
9060 }
9061 var index = -1;
9062 var innerIndex = -1;
9063 while (++index < surrogateMappings.length) {
9064 var mapping = surrogateMappings[index];
9065 var lowSurrogates = mapping[1];
9066 var lowSurrogateStart = lowSurrogates[0];
9067 var lowSurrogateEnd = lowSurrogates[1];
9068 innerIndex = index; // Note: the loop starts at the next index.
9069 while (++innerIndex < surrogateMappings.length) {
9070 var otherMapping = surrogateMappings[innerIndex];
9071 var otherLowSurrogates = otherMapping[1];
9072 var otherLowSurrogateStart = otherLowSurrogates[0];
9073 var otherLowSurrogateEnd = otherLowSurrogates[1];
9074 if (
9075 lowSurrogateStart == otherLowSurrogateStart &&
9076 lowSurrogateEnd == otherLowSurrogateEnd
9077 ) {
9078 // Add the code points in the other item to this one.
9079 if (dataIsSingleton(otherMapping[0])) {
9080 mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
9081 } else {
9082 mapping[0] = dataAddRange(
9083 mapping[0],
9084 otherMapping[0][0],
9085 otherMapping[0][1] - 1
9086 );
9087 }
9088 // Remove the other, now redundant, item.
9089 surrogateMappings.splice(innerIndex, 1);
9090 --innerIndex;
9091 }
9092 }
9093 }
9094 return surrogateMappings;
9095 };
9096
9097 var surrogateSet = function(data) {
9098 // Exit early if `data` is an empty set.
9099 if (!data.length) {
9100 return [];
9101 }
9102
9103 // Iterate over the data per `(start, end)` pair.
9104 var index = 0;
9105 var start;
9106 var end;
9107 var startHigh;
9108 var startLow;
9109 var endHigh;
9110 var endLow;
9111 var surrogateMappings = [];
9112 var length = data.length;
9113 while (index < length) {
9114 start = data[index];
9115 end = data[index + 1] - 1;
9116
9117 startHigh = highSurrogate(start);
9118 startLow = lowSurrogate(start);
9119 endHigh = highSurrogate(end);
9120 endLow = lowSurrogate(end);
9121
9122 var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
9123 var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
9124 var complete = false;
9125
9126 // Append the previous high-surrogate-to-low-surrogate mappings.
9127 // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
9128 if (
9129 startHigh == endHigh ||
9130 startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
9131 ) {
9132 surrogateMappings.push([
9133 [startHigh, endHigh + 1],
9134 [startLow, endLow + 1]
9135 ]);
9136 complete = true;
9137 } else {
9138 surrogateMappings.push([
9139 [startHigh, startHigh + 1],
9140 [startLow, LOW_SURROGATE_MAX + 1]
9141 ]);
9142 }
9143
9144 // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
9145 // `(endHigh - 1, LOW_SURROGATE_MAX)`.
9146 if (!complete && startHigh + 1 < endHigh) {
9147 if (endsWithHighestLowSurrogate) {
9148 // Combine step 2 and step 3.
9149 surrogateMappings.push([
9150 [startHigh + 1, endHigh + 1],
9151 [LOW_SURROGATE_MIN, endLow + 1]
9152 ]);
9153 complete = true;
9154 } else {
9155 surrogateMappings.push([
9156 [startHigh + 1, endHigh],
9157 [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
9158 ]);
9159 }
9160 }
9161
9162 // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
9163 if (!complete) {
9164 surrogateMappings.push([
9165 [endHigh, endHigh + 1],
9166 [LOW_SURROGATE_MIN, endLow + 1]
9167 ]);
9168 }
9169
9170 index += 2;
9171 }
9172
9173 // The format of `surrogateMappings` is as follows:
9174 //
9175 // [ surrogateMapping1, surrogateMapping2 ]
9176 //
9177 // i.e.:
9178 //
9179 // [
9180 // [ highSurrogates1, lowSurrogates1 ],
9181 // [ highSurrogates2, lowSurrogates2 ]
9182 // ]
9183 return optimizeSurrogateMappings(surrogateMappings);
9184 };
9185
9186 var createSurrogateCharacterClasses = function(surrogateMappings) {
9187 var result = [];
9188 forEach(surrogateMappings, function(surrogateMapping) {
9189 var highSurrogates = surrogateMapping[0];
9190 var lowSurrogates = surrogateMapping[1];
9191 result.push(
9192 createBMPCharacterClasses(highSurrogates) +
9193 createBMPCharacterClasses(lowSurrogates)
9194 );
9195 });
9196 return result.join('|');
9197 };
9198
9199 var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
9200 if (hasUnicodeFlag) {
9201 return createUnicodeCharacterClasses(data);
9202 }
9203 var result = [];
9204
9205 var parts = splitAtBMP(data);
9206 var loneHighSurrogates = parts.loneHighSurrogates;
9207 var loneLowSurrogates = parts.loneLowSurrogates;
9208 var bmp = parts.bmp;
9209 var astral = parts.astral;
9210 var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
9211 var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
9212
9213 var surrogateMappings = surrogateSet(astral);
9214
9215 if (bmpOnly) {
9216 bmp = dataAddData(bmp, loneHighSurrogates);
9217 hasLoneHighSurrogates = false;
9218 bmp = dataAddData(bmp, loneLowSurrogates);
9219 hasLoneLowSurrogates = false;
9220 }
9221
9222 if (!dataIsEmpty(bmp)) {
9223 // The data set contains BMP code points that are not high surrogates
9224 // needed for astral code points in the set.
9225 result.push(createBMPCharacterClasses(bmp));
9226 }
9227 if (surrogateMappings.length) {
9228 // The data set contains astral code points; append character classes
9229 // based on their surrogate pairs.
9230 result.push(createSurrogateCharacterClasses(surrogateMappings));
9231 }
9232 // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
9233 if (hasLoneHighSurrogates) {
9234 result.push(
9235 createBMPCharacterClasses(loneHighSurrogates) +
9236 // Make sure the high surrogates aren’t part of a surrogate pair.
9237 '(?![\\uDC00-\\uDFFF])'
9238 );
9239 }
9240 if (hasLoneLowSurrogates) {
9241 result.push(
9242 // It is not possible to accurately assert the low surrogates aren’t
9243 // part of a surrogate pair, since JavaScript regular expressions do
9244 // not support lookbehind.
9245 '(?:[^\\uD800-\\uDBFF]|^)' +
9246 createBMPCharacterClasses(loneLowSurrogates)
9247 );
9248 }
9249 return result.join('|');
9250 };
9251
9252 /*--------------------------------------------------------------------------*/
9253
9254 // `regenerate` can be used as a constructor (and new methods can be added to
9255 // its prototype) but also as a regular function, the latter of which is the
9256 // documented and most common usage. For that reason, it’s not capitalized.
9257 var regenerate = function(value) {
9258 if (arguments.length > 1) {
9259 value = slice.call(arguments);
9260 }
9261 if (this instanceof regenerate) {
9262 this.data = [];
9263 return value ? this.add(value) : this;
9264 }
9265 return (new regenerate).add(value);
9266 };
9267
9268 regenerate.version = '1.3.3';
9269
9270 var proto = regenerate.prototype;
9271 extend(proto, {
9272 'add': function(value) {
9273 var $this = this;
9274 if (value == null) {
9275 return $this;
9276 }
9277 if (value instanceof regenerate) {
9278 // Allow passing other Regenerate instances.
9279 $this.data = dataAddData($this.data, value.data);
9280 return $this;
9281 }
9282 if (arguments.length > 1) {
9283 value = slice.call(arguments);
9284 }
9285 if (isArray(value)) {
9286 forEach(value, function(item) {
9287 $this.add(item);
9288 });
9289 return $this;
9290 }
9291 $this.data = dataAdd(
9292 $this.data,
9293 isNumber(value) ? value : symbolToCodePoint(value)
9294 );
9295 return $this;
9296 },
9297 'remove': function(value) {
9298 var $this = this;
9299 if (value == null) {
9300 return $this;
9301 }
9302 if (value instanceof regenerate) {
9303 // Allow passing other Regenerate instances.
9304 $this.data = dataRemoveData($this.data, value.data);
9305 return $this;
9306 }
9307 if (arguments.length > 1) {
9308 value = slice.call(arguments);
9309 }
9310 if (isArray(value)) {
9311 forEach(value, function(item) {
9312 $this.remove(item);
9313 });
9314 return $this;
9315 }
9316 $this.data = dataRemove(
9317 $this.data,
9318 isNumber(value) ? value : symbolToCodePoint(value)
9319 );
9320 return $this;
9321 },
9322 'addRange': function(start, end) {
9323 var $this = this;
9324 $this.data = dataAddRange($this.data,
9325 isNumber(start) ? start : symbolToCodePoint(start),
9326 isNumber(end) ? end : symbolToCodePoint(end)
9327 );
9328 return $this;
9329 },
9330 'removeRange': function(start, end) {
9331 var $this = this;
9332 var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
9333 var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
9334 $this.data = dataRemoveRange(
9335 $this.data,
9336 startCodePoint,
9337 endCodePoint
9338 );
9339 return $this;
9340 },
9341 'intersection': function(argument) {
9342 var $this = this;
9343 // Allow passing other Regenerate instances.
9344 // TODO: Optimize this by writing and using `dataIntersectionData()`.
9345 var array = argument instanceof regenerate ?
9346 dataToArray(argument.data) :
9347 argument;
9348 $this.data = dataIntersection($this.data, array);
9349 return $this;
9350 },
9351 'contains': function(codePoint) {
9352 return dataContains(
9353 this.data,
9354 isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
9355 );
9356 },
9357 'clone': function() {
9358 var set = new regenerate;
9359 set.data = this.data.slice(0);
9360 return set;
9361 },
9362 'toString': function(options) {
9363 var result = createCharacterClassesFromData(
9364 this.data,
9365 options ? options.bmpOnly : false,
9366 options ? options.hasUnicodeFlag : false
9367 );
9368 if (!result) {
9369 // For an empty set, return something that can be inserted `/here/` to
9370 // form a valid regular expression. Avoid `(?:)` since that matches the
9371 // empty string.
9372 return '[]';
9373 }
9374 // Use `\0` instead of `\x00` where possible.
9375 return result.replace(regexNull, '\\0$1');
9376 },
9377 'toRegExp': function(flags) {
9378 var pattern = this.toString(
9379 flags && flags.indexOf('u') != -1 ?
9380 { 'hasUnicodeFlag': true } :
9381 null
9382 );
9383 return RegExp(pattern, flags || '');
9384 },
9385 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
9386 return dataToArray(this.data);
9387 }
9388 });
9389
9390 proto.toArray = proto.valueOf;
9391
9392 // Some AMD build optimizers, like r.js, check for specific condition patterns
9393 // like the following:
9394 if (
9395 typeof undefined == 'function' &&
9396 typeof undefined.amd == 'object' &&
9397 undefined.amd
9398 ) {
9399 undefined(function() {
9400 return regenerate;
9401 });
9402 } else if (freeExports && !freeExports.nodeType) {
9403 if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
9404 freeModule.exports = regenerate;
9405 } else { // in Narwhal or RingoJS v0.7.0-
9406 freeExports.regenerate = regenerate;
9407 }
9408 } else { // in Rhino or a web browser
9409 root.regenerate = regenerate;
9410 }
9411
9412}(commonjsGlobal));
9413});
9414
9415var unicodeCanonicalPropertyNamesEcmascript = new Set([
9416 // Non-binary properties:
9417 'General_Category',
9418 'Script',
9419 'Script_Extensions',
9420 // Binary properties:
9421 'Alphabetic',
9422 'Any',
9423 'ASCII',
9424 'ASCII_Hex_Digit',
9425 'Assigned',
9426 'Bidi_Control',
9427 'Bidi_Mirrored',
9428 'Case_Ignorable',
9429 'Cased',
9430 'Changes_When_Casefolded',
9431 'Changes_When_Casemapped',
9432 'Changes_When_Lowercased',
9433 'Changes_When_NFKC_Casefolded',
9434 'Changes_When_Titlecased',
9435 'Changes_When_Uppercased',
9436 'Dash',
9437 'Default_Ignorable_Code_Point',
9438 'Deprecated',
9439 'Diacritic',
9440 'Emoji',
9441 'Emoji_Component',
9442 'Emoji_Modifier',
9443 'Emoji_Modifier_Base',
9444 'Emoji_Presentation',
9445 'Extended_Pictographic',
9446 'Extender',
9447 'Grapheme_Base',
9448 'Grapheme_Extend',
9449 'Hex_Digit',
9450 'ID_Continue',
9451 'ID_Start',
9452 'Ideographic',
9453 'IDS_Binary_Operator',
9454 'IDS_Trinary_Operator',
9455 'Join_Control',
9456 'Logical_Order_Exception',
9457 'Lowercase',
9458 'Math',
9459 'Noncharacter_Code_Point',
9460 'Pattern_Syntax',
9461 'Pattern_White_Space',
9462 'Quotation_Mark',
9463 'Radical',
9464 'Regional_Indicator',
9465 'Sentence_Terminal',
9466 'Soft_Dotted',
9467 'Terminal_Punctuation',
9468 'Unified_Ideograph',
9469 'Uppercase',
9470 'Variation_Selector',
9471 'White_Space',
9472 'XID_Continue',
9473 'XID_Start'
9474]);
9475
9476// Generated using `npm run build`. Do not edit!
9477var unicodePropertyAliasesEcmascript = new Map([
9478 ['scx', 'Script_Extensions'],
9479 ['sc', 'Script'],
9480 ['gc', 'General_Category'],
9481 ['AHex', 'ASCII_Hex_Digit'],
9482 ['Alpha', 'Alphabetic'],
9483 ['Bidi_C', 'Bidi_Control'],
9484 ['Bidi_M', 'Bidi_Mirrored'],
9485 ['Cased', 'Cased'],
9486 ['CI', 'Case_Ignorable'],
9487 ['CWCF', 'Changes_When_Casefolded'],
9488 ['CWCM', 'Changes_When_Casemapped'],
9489 ['CWKCF', 'Changes_When_NFKC_Casefolded'],
9490 ['CWL', 'Changes_When_Lowercased'],
9491 ['CWT', 'Changes_When_Titlecased'],
9492 ['CWU', 'Changes_When_Uppercased'],
9493 ['Dash', 'Dash'],
9494 ['Dep', 'Deprecated'],
9495 ['DI', 'Default_Ignorable_Code_Point'],
9496 ['Dia', 'Diacritic'],
9497 ['Ext', 'Extender'],
9498 ['Gr_Base', 'Grapheme_Base'],
9499 ['Gr_Ext', 'Grapheme_Extend'],
9500 ['Hex', 'Hex_Digit'],
9501 ['IDC', 'ID_Continue'],
9502 ['Ideo', 'Ideographic'],
9503 ['IDS', 'ID_Start'],
9504 ['IDSB', 'IDS_Binary_Operator'],
9505 ['IDST', 'IDS_Trinary_Operator'],
9506 ['Join_C', 'Join_Control'],
9507 ['LOE', 'Logical_Order_Exception'],
9508 ['Lower', 'Lowercase'],
9509 ['Math', 'Math'],
9510 ['NChar', 'Noncharacter_Code_Point'],
9511 ['Pat_Syn', 'Pattern_Syntax'],
9512 ['Pat_WS', 'Pattern_White_Space'],
9513 ['QMark', 'Quotation_Mark'],
9514 ['Radical', 'Radical'],
9515 ['RI', 'Regional_Indicator'],
9516 ['SD', 'Soft_Dotted'],
9517 ['STerm', 'Sentence_Terminal'],
9518 ['Term', 'Terminal_Punctuation'],
9519 ['UIdeo', 'Unified_Ideograph'],
9520 ['Upper', 'Uppercase'],
9521 ['VS', 'Variation_Selector'],
9522 ['WSpace', 'White_Space'],
9523 ['space', 'White_Space'],
9524 ['XIDC', 'XID_Continue'],
9525 ['XIDS', 'XID_Start']
9526]);
9527
9528'use strict';
9529
9530
9531
9532
9533const matchProperty = function(property) {
9534 if (unicodeCanonicalPropertyNamesEcmascript.has(property)) {
9535 return property;
9536 }
9537 if (unicodePropertyAliasesEcmascript.has(property)) {
9538 return unicodePropertyAliasesEcmascript.get(property);
9539 }
9540 throw new Error(`Unknown property: ${ property }`);
9541};
9542
9543var unicodeMatchPropertyEcmascript = matchProperty;
9544
9545var mappings = new Map([
9546 ['General_Category', new Map([
9547 ['C', 'Other'],
9548 ['Cc', 'Control'],
9549 ['cntrl', 'Control'],
9550 ['Cf', 'Format'],
9551 ['Cn', 'Unassigned'],
9552 ['Co', 'Private_Use'],
9553 ['Cs', 'Surrogate'],
9554 ['L', 'Letter'],
9555 ['LC', 'Cased_Letter'],
9556 ['Ll', 'Lowercase_Letter'],
9557 ['Lm', 'Modifier_Letter'],
9558 ['Lo', 'Other_Letter'],
9559 ['Lt', 'Titlecase_Letter'],
9560 ['Lu', 'Uppercase_Letter'],
9561 ['M', 'Mark'],
9562 ['Combining_Mark', 'Mark'],
9563 ['Mc', 'Spacing_Mark'],
9564 ['Me', 'Enclosing_Mark'],
9565 ['Mn', 'Nonspacing_Mark'],
9566 ['N', 'Number'],
9567 ['Nd', 'Decimal_Number'],
9568 ['digit', 'Decimal_Number'],
9569 ['Nl', 'Letter_Number'],
9570 ['No', 'Other_Number'],
9571 ['P', 'Punctuation'],
9572 ['punct', 'Punctuation'],
9573 ['Pc', 'Connector_Punctuation'],
9574 ['Pd', 'Dash_Punctuation'],
9575 ['Pe', 'Close_Punctuation'],
9576 ['Pf', 'Final_Punctuation'],
9577 ['Pi', 'Initial_Punctuation'],
9578 ['Po', 'Other_Punctuation'],
9579 ['Ps', 'Open_Punctuation'],
9580 ['S', 'Symbol'],
9581 ['Sc', 'Currency_Symbol'],
9582 ['Sk', 'Modifier_Symbol'],
9583 ['Sm', 'Math_Symbol'],
9584 ['So', 'Other_Symbol'],
9585 ['Z', 'Separator'],
9586 ['Zl', 'Line_Separator'],
9587 ['Zp', 'Paragraph_Separator'],
9588 ['Zs', 'Space_Separator'],
9589 ['Other', 'Other'],
9590 ['Control', 'Control'],
9591 ['Format', 'Format'],
9592 ['Unassigned', 'Unassigned'],
9593 ['Private_Use', 'Private_Use'],
9594 ['Surrogate', 'Surrogate'],
9595 ['Letter', 'Letter'],
9596 ['Cased_Letter', 'Cased_Letter'],
9597 ['Lowercase_Letter', 'Lowercase_Letter'],
9598 ['Modifier_Letter', 'Modifier_Letter'],
9599 ['Other_Letter', 'Other_Letter'],
9600 ['Titlecase_Letter', 'Titlecase_Letter'],
9601 ['Uppercase_Letter', 'Uppercase_Letter'],
9602 ['Mark', 'Mark'],
9603 ['Spacing_Mark', 'Spacing_Mark'],
9604 ['Enclosing_Mark', 'Enclosing_Mark'],
9605 ['Nonspacing_Mark', 'Nonspacing_Mark'],
9606 ['Number', 'Number'],
9607 ['Decimal_Number', 'Decimal_Number'],
9608 ['Letter_Number', 'Letter_Number'],
9609 ['Other_Number', 'Other_Number'],
9610 ['Punctuation', 'Punctuation'],
9611 ['Connector_Punctuation', 'Connector_Punctuation'],
9612 ['Dash_Punctuation', 'Dash_Punctuation'],
9613 ['Close_Punctuation', 'Close_Punctuation'],
9614 ['Final_Punctuation', 'Final_Punctuation'],
9615 ['Initial_Punctuation', 'Initial_Punctuation'],
9616 ['Other_Punctuation', 'Other_Punctuation'],
9617 ['Open_Punctuation', 'Open_Punctuation'],
9618 ['Symbol', 'Symbol'],
9619 ['Currency_Symbol', 'Currency_Symbol'],
9620 ['Modifier_Symbol', 'Modifier_Symbol'],
9621 ['Math_Symbol', 'Math_Symbol'],
9622 ['Other_Symbol', 'Other_Symbol'],
9623 ['Separator', 'Separator'],
9624 ['Line_Separator', 'Line_Separator'],
9625 ['Paragraph_Separator', 'Paragraph_Separator'],
9626 ['Space_Separator', 'Space_Separator']
9627 ])],
9628 ['Script', new Map([
9629 ['Adlm', 'Adlam'],
9630 ['Aghb', 'Caucasian_Albanian'],
9631 ['Ahom', 'Ahom'],
9632 ['Arab', 'Arabic'],
9633 ['Armi', 'Imperial_Aramaic'],
9634 ['Armn', 'Armenian'],
9635 ['Avst', 'Avestan'],
9636 ['Bali', 'Balinese'],
9637 ['Bamu', 'Bamum'],
9638 ['Bass', 'Bassa_Vah'],
9639 ['Batk', 'Batak'],
9640 ['Beng', 'Bengali'],
9641 ['Bhks', 'Bhaiksuki'],
9642 ['Bopo', 'Bopomofo'],
9643 ['Brah', 'Brahmi'],
9644 ['Brai', 'Braille'],
9645 ['Bugi', 'Buginese'],
9646 ['Buhd', 'Buhid'],
9647 ['Cakm', 'Chakma'],
9648 ['Cans', 'Canadian_Aboriginal'],
9649 ['Cari', 'Carian'],
9650 ['Cham', 'Cham'],
9651 ['Cher', 'Cherokee'],
9652 ['Copt', 'Coptic'],
9653 ['Qaac', 'Coptic'],
9654 ['Cprt', 'Cypriot'],
9655 ['Cyrl', 'Cyrillic'],
9656 ['Deva', 'Devanagari'],
9657 ['Dsrt', 'Deseret'],
9658 ['Dupl', 'Duployan'],
9659 ['Egyp', 'Egyptian_Hieroglyphs'],
9660 ['Elba', 'Elbasan'],
9661 ['Ethi', 'Ethiopic'],
9662 ['Geor', 'Georgian'],
9663 ['Glag', 'Glagolitic'],
9664 ['Gonm', 'Masaram_Gondi'],
9665 ['Goth', 'Gothic'],
9666 ['Gran', 'Grantha'],
9667 ['Grek', 'Greek'],
9668 ['Gujr', 'Gujarati'],
9669 ['Guru', 'Gurmukhi'],
9670 ['Hang', 'Hangul'],
9671 ['Hani', 'Han'],
9672 ['Hano', 'Hanunoo'],
9673 ['Hatr', 'Hatran'],
9674 ['Hebr', 'Hebrew'],
9675 ['Hira', 'Hiragana'],
9676 ['Hluw', 'Anatolian_Hieroglyphs'],
9677 ['Hmng', 'Pahawh_Hmong'],
9678 ['Hrkt', 'Katakana_Or_Hiragana'],
9679 ['Hung', 'Old_Hungarian'],
9680 ['Ital', 'Old_Italic'],
9681 ['Java', 'Javanese'],
9682 ['Kali', 'Kayah_Li'],
9683 ['Kana', 'Katakana'],
9684 ['Khar', 'Kharoshthi'],
9685 ['Khmr', 'Khmer'],
9686 ['Khoj', 'Khojki'],
9687 ['Knda', 'Kannada'],
9688 ['Kthi', 'Kaithi'],
9689 ['Lana', 'Tai_Tham'],
9690 ['Laoo', 'Lao'],
9691 ['Latn', 'Latin'],
9692 ['Lepc', 'Lepcha'],
9693 ['Limb', 'Limbu'],
9694 ['Lina', 'Linear_A'],
9695 ['Linb', 'Linear_B'],
9696 ['Lisu', 'Lisu'],
9697 ['Lyci', 'Lycian'],
9698 ['Lydi', 'Lydian'],
9699 ['Mahj', 'Mahajani'],
9700 ['Mand', 'Mandaic'],
9701 ['Mani', 'Manichaean'],
9702 ['Marc', 'Marchen'],
9703 ['Mend', 'Mende_Kikakui'],
9704 ['Merc', 'Meroitic_Cursive'],
9705 ['Mero', 'Meroitic_Hieroglyphs'],
9706 ['Mlym', 'Malayalam'],
9707 ['Modi', 'Modi'],
9708 ['Mong', 'Mongolian'],
9709 ['Mroo', 'Mro'],
9710 ['Mtei', 'Meetei_Mayek'],
9711 ['Mult', 'Multani'],
9712 ['Mymr', 'Myanmar'],
9713 ['Narb', 'Old_North_Arabian'],
9714 ['Nbat', 'Nabataean'],
9715 ['Newa', 'Newa'],
9716 ['Nkoo', 'Nko'],
9717 ['Nshu', 'Nushu'],
9718 ['Ogam', 'Ogham'],
9719 ['Olck', 'Ol_Chiki'],
9720 ['Orkh', 'Old_Turkic'],
9721 ['Orya', 'Oriya'],
9722 ['Osge', 'Osage'],
9723 ['Osma', 'Osmanya'],
9724 ['Palm', 'Palmyrene'],
9725 ['Pauc', 'Pau_Cin_Hau'],
9726 ['Perm', 'Old_Permic'],
9727 ['Phag', 'Phags_Pa'],
9728 ['Phli', 'Inscriptional_Pahlavi'],
9729 ['Phlp', 'Psalter_Pahlavi'],
9730 ['Phnx', 'Phoenician'],
9731 ['Plrd', 'Miao'],
9732 ['Prti', 'Inscriptional_Parthian'],
9733 ['Rjng', 'Rejang'],
9734 ['Runr', 'Runic'],
9735 ['Samr', 'Samaritan'],
9736 ['Sarb', 'Old_South_Arabian'],
9737 ['Saur', 'Saurashtra'],
9738 ['Sgnw', 'SignWriting'],
9739 ['Shaw', 'Shavian'],
9740 ['Shrd', 'Sharada'],
9741 ['Sidd', 'Siddham'],
9742 ['Sind', 'Khudawadi'],
9743 ['Sinh', 'Sinhala'],
9744 ['Sora', 'Sora_Sompeng'],
9745 ['Soyo', 'Soyombo'],
9746 ['Sund', 'Sundanese'],
9747 ['Sylo', 'Syloti_Nagri'],
9748 ['Syrc', 'Syriac'],
9749 ['Tagb', 'Tagbanwa'],
9750 ['Takr', 'Takri'],
9751 ['Tale', 'Tai_Le'],
9752 ['Talu', 'New_Tai_Lue'],
9753 ['Taml', 'Tamil'],
9754 ['Tang', 'Tangut'],
9755 ['Tavt', 'Tai_Viet'],
9756 ['Telu', 'Telugu'],
9757 ['Tfng', 'Tifinagh'],
9758 ['Tglg', 'Tagalog'],
9759 ['Thaa', 'Thaana'],
9760 ['Thai', 'Thai'],
9761 ['Tibt', 'Tibetan'],
9762 ['Tirh', 'Tirhuta'],
9763 ['Ugar', 'Ugaritic'],
9764 ['Vaii', 'Vai'],
9765 ['Wara', 'Warang_Citi'],
9766 ['Xpeo', 'Old_Persian'],
9767 ['Xsux', 'Cuneiform'],
9768 ['Yiii', 'Yi'],
9769 ['Zanb', 'Zanabazar_Square'],
9770 ['Zinh', 'Inherited'],
9771 ['Qaai', 'Inherited'],
9772 ['Zyyy', 'Common'],
9773 ['Zzzz', 'Unknown'],
9774 ['Adlam', 'Adlam'],
9775 ['Caucasian_Albanian', 'Caucasian_Albanian'],
9776 ['Arabic', 'Arabic'],
9777 ['Imperial_Aramaic', 'Imperial_Aramaic'],
9778 ['Armenian', 'Armenian'],
9779 ['Avestan', 'Avestan'],
9780 ['Balinese', 'Balinese'],
9781 ['Bamum', 'Bamum'],
9782 ['Bassa_Vah', 'Bassa_Vah'],
9783 ['Batak', 'Batak'],
9784 ['Bengali', 'Bengali'],
9785 ['Bhaiksuki', 'Bhaiksuki'],
9786 ['Bopomofo', 'Bopomofo'],
9787 ['Brahmi', 'Brahmi'],
9788 ['Braille', 'Braille'],
9789 ['Buginese', 'Buginese'],
9790 ['Buhid', 'Buhid'],
9791 ['Chakma', 'Chakma'],
9792 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
9793 ['Carian', 'Carian'],
9794 ['Cherokee', 'Cherokee'],
9795 ['Coptic', 'Coptic'],
9796 ['Cypriot', 'Cypriot'],
9797 ['Cyrillic', 'Cyrillic'],
9798 ['Devanagari', 'Devanagari'],
9799 ['Deseret', 'Deseret'],
9800 ['Duployan', 'Duployan'],
9801 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
9802 ['Elbasan', 'Elbasan'],
9803 ['Ethiopic', 'Ethiopic'],
9804 ['Georgian', 'Georgian'],
9805 ['Glagolitic', 'Glagolitic'],
9806 ['Masaram_Gondi', 'Masaram_Gondi'],
9807 ['Gothic', 'Gothic'],
9808 ['Grantha', 'Grantha'],
9809 ['Greek', 'Greek'],
9810 ['Gujarati', 'Gujarati'],
9811 ['Gurmukhi', 'Gurmukhi'],
9812 ['Hangul', 'Hangul'],
9813 ['Han', 'Han'],
9814 ['Hanunoo', 'Hanunoo'],
9815 ['Hatran', 'Hatran'],
9816 ['Hebrew', 'Hebrew'],
9817 ['Hiragana', 'Hiragana'],
9818 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
9819 ['Pahawh_Hmong', 'Pahawh_Hmong'],
9820 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
9821 ['Old_Hungarian', 'Old_Hungarian'],
9822 ['Old_Italic', 'Old_Italic'],
9823 ['Javanese', 'Javanese'],
9824 ['Kayah_Li', 'Kayah_Li'],
9825 ['Katakana', 'Katakana'],
9826 ['Kharoshthi', 'Kharoshthi'],
9827 ['Khmer', 'Khmer'],
9828 ['Khojki', 'Khojki'],
9829 ['Kannada', 'Kannada'],
9830 ['Kaithi', 'Kaithi'],
9831 ['Tai_Tham', 'Tai_Tham'],
9832 ['Lao', 'Lao'],
9833 ['Latin', 'Latin'],
9834 ['Lepcha', 'Lepcha'],
9835 ['Limbu', 'Limbu'],
9836 ['Linear_A', 'Linear_A'],
9837 ['Linear_B', 'Linear_B'],
9838 ['Lycian', 'Lycian'],
9839 ['Lydian', 'Lydian'],
9840 ['Mahajani', 'Mahajani'],
9841 ['Mandaic', 'Mandaic'],
9842 ['Manichaean', 'Manichaean'],
9843 ['Marchen', 'Marchen'],
9844 ['Mende_Kikakui', 'Mende_Kikakui'],
9845 ['Meroitic_Cursive', 'Meroitic_Cursive'],
9846 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
9847 ['Malayalam', 'Malayalam'],
9848 ['Mongolian', 'Mongolian'],
9849 ['Mro', 'Mro'],
9850 ['Meetei_Mayek', 'Meetei_Mayek'],
9851 ['Multani', 'Multani'],
9852 ['Myanmar', 'Myanmar'],
9853 ['Old_North_Arabian', 'Old_North_Arabian'],
9854 ['Nabataean', 'Nabataean'],
9855 ['Nko', 'Nko'],
9856 ['Nushu', 'Nushu'],
9857 ['Ogham', 'Ogham'],
9858 ['Ol_Chiki', 'Ol_Chiki'],
9859 ['Old_Turkic', 'Old_Turkic'],
9860 ['Oriya', 'Oriya'],
9861 ['Osage', 'Osage'],
9862 ['Osmanya', 'Osmanya'],
9863 ['Palmyrene', 'Palmyrene'],
9864 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
9865 ['Old_Permic', 'Old_Permic'],
9866 ['Phags_Pa', 'Phags_Pa'],
9867 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
9868 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
9869 ['Phoenician', 'Phoenician'],
9870 ['Miao', 'Miao'],
9871 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
9872 ['Rejang', 'Rejang'],
9873 ['Runic', 'Runic'],
9874 ['Samaritan', 'Samaritan'],
9875 ['Old_South_Arabian', 'Old_South_Arabian'],
9876 ['Saurashtra', 'Saurashtra'],
9877 ['SignWriting', 'SignWriting'],
9878 ['Shavian', 'Shavian'],
9879 ['Sharada', 'Sharada'],
9880 ['Siddham', 'Siddham'],
9881 ['Khudawadi', 'Khudawadi'],
9882 ['Sinhala', 'Sinhala'],
9883 ['Sora_Sompeng', 'Sora_Sompeng'],
9884 ['Soyombo', 'Soyombo'],
9885 ['Sundanese', 'Sundanese'],
9886 ['Syloti_Nagri', 'Syloti_Nagri'],
9887 ['Syriac', 'Syriac'],
9888 ['Tagbanwa', 'Tagbanwa'],
9889 ['Takri', 'Takri'],
9890 ['Tai_Le', 'Tai_Le'],
9891 ['New_Tai_Lue', 'New_Tai_Lue'],
9892 ['Tamil', 'Tamil'],
9893 ['Tangut', 'Tangut'],
9894 ['Tai_Viet', 'Tai_Viet'],
9895 ['Telugu', 'Telugu'],
9896 ['Tifinagh', 'Tifinagh'],
9897 ['Tagalog', 'Tagalog'],
9898 ['Thaana', 'Thaana'],
9899 ['Tibetan', 'Tibetan'],
9900 ['Tirhuta', 'Tirhuta'],
9901 ['Ugaritic', 'Ugaritic'],
9902 ['Vai', 'Vai'],
9903 ['Warang_Citi', 'Warang_Citi'],
9904 ['Old_Persian', 'Old_Persian'],
9905 ['Cuneiform', 'Cuneiform'],
9906 ['Yi', 'Yi'],
9907 ['Zanabazar_Square', 'Zanabazar_Square'],
9908 ['Inherited', 'Inherited'],
9909 ['Common', 'Common'],
9910 ['Unknown', 'Unknown']
9911 ])],
9912 ['Script_Extensions', new Map([
9913 ['Adlm', 'Adlam'],
9914 ['Aghb', 'Caucasian_Albanian'],
9915 ['Ahom', 'Ahom'],
9916 ['Arab', 'Arabic'],
9917 ['Armi', 'Imperial_Aramaic'],
9918 ['Armn', 'Armenian'],
9919 ['Avst', 'Avestan'],
9920 ['Bali', 'Balinese'],
9921 ['Bamu', 'Bamum'],
9922 ['Bass', 'Bassa_Vah'],
9923 ['Batk', 'Batak'],
9924 ['Beng', 'Bengali'],
9925 ['Bhks', 'Bhaiksuki'],
9926 ['Bopo', 'Bopomofo'],
9927 ['Brah', 'Brahmi'],
9928 ['Brai', 'Braille'],
9929 ['Bugi', 'Buginese'],
9930 ['Buhd', 'Buhid'],
9931 ['Cakm', 'Chakma'],
9932 ['Cans', 'Canadian_Aboriginal'],
9933 ['Cari', 'Carian'],
9934 ['Cham', 'Cham'],
9935 ['Cher', 'Cherokee'],
9936 ['Copt', 'Coptic'],
9937 ['Qaac', 'Coptic'],
9938 ['Cprt', 'Cypriot'],
9939 ['Cyrl', 'Cyrillic'],
9940 ['Deva', 'Devanagari'],
9941 ['Dsrt', 'Deseret'],
9942 ['Dupl', 'Duployan'],
9943 ['Egyp', 'Egyptian_Hieroglyphs'],
9944 ['Elba', 'Elbasan'],
9945 ['Ethi', 'Ethiopic'],
9946 ['Geor', 'Georgian'],
9947 ['Glag', 'Glagolitic'],
9948 ['Gonm', 'Masaram_Gondi'],
9949 ['Goth', 'Gothic'],
9950 ['Gran', 'Grantha'],
9951 ['Grek', 'Greek'],
9952 ['Gujr', 'Gujarati'],
9953 ['Guru', 'Gurmukhi'],
9954 ['Hang', 'Hangul'],
9955 ['Hani', 'Han'],
9956 ['Hano', 'Hanunoo'],
9957 ['Hatr', 'Hatran'],
9958 ['Hebr', 'Hebrew'],
9959 ['Hira', 'Hiragana'],
9960 ['Hluw', 'Anatolian_Hieroglyphs'],
9961 ['Hmng', 'Pahawh_Hmong'],
9962 ['Hrkt', 'Katakana_Or_Hiragana'],
9963 ['Hung', 'Old_Hungarian'],
9964 ['Ital', 'Old_Italic'],
9965 ['Java', 'Javanese'],
9966 ['Kali', 'Kayah_Li'],
9967 ['Kana', 'Katakana'],
9968 ['Khar', 'Kharoshthi'],
9969 ['Khmr', 'Khmer'],
9970 ['Khoj', 'Khojki'],
9971 ['Knda', 'Kannada'],
9972 ['Kthi', 'Kaithi'],
9973 ['Lana', 'Tai_Tham'],
9974 ['Laoo', 'Lao'],
9975 ['Latn', 'Latin'],
9976 ['Lepc', 'Lepcha'],
9977 ['Limb', 'Limbu'],
9978 ['Lina', 'Linear_A'],
9979 ['Linb', 'Linear_B'],
9980 ['Lisu', 'Lisu'],
9981 ['Lyci', 'Lycian'],
9982 ['Lydi', 'Lydian'],
9983 ['Mahj', 'Mahajani'],
9984 ['Mand', 'Mandaic'],
9985 ['Mani', 'Manichaean'],
9986 ['Marc', 'Marchen'],
9987 ['Mend', 'Mende_Kikakui'],
9988 ['Merc', 'Meroitic_Cursive'],
9989 ['Mero', 'Meroitic_Hieroglyphs'],
9990 ['Mlym', 'Malayalam'],
9991 ['Modi', 'Modi'],
9992 ['Mong', 'Mongolian'],
9993 ['Mroo', 'Mro'],
9994 ['Mtei', 'Meetei_Mayek'],
9995 ['Mult', 'Multani'],
9996 ['Mymr', 'Myanmar'],
9997 ['Narb', 'Old_North_Arabian'],
9998 ['Nbat', 'Nabataean'],
9999 ['Newa', 'Newa'],
10000 ['Nkoo', 'Nko'],
10001 ['Nshu', 'Nushu'],
10002 ['Ogam', 'Ogham'],
10003 ['Olck', 'Ol_Chiki'],
10004 ['Orkh', 'Old_Turkic'],
10005 ['Orya', 'Oriya'],
10006 ['Osge', 'Osage'],
10007 ['Osma', 'Osmanya'],
10008 ['Palm', 'Palmyrene'],
10009 ['Pauc', 'Pau_Cin_Hau'],
10010 ['Perm', 'Old_Permic'],
10011 ['Phag', 'Phags_Pa'],
10012 ['Phli', 'Inscriptional_Pahlavi'],
10013 ['Phlp', 'Psalter_Pahlavi'],
10014 ['Phnx', 'Phoenician'],
10015 ['Plrd', 'Miao'],
10016 ['Prti', 'Inscriptional_Parthian'],
10017 ['Rjng', 'Rejang'],
10018 ['Runr', 'Runic'],
10019 ['Samr', 'Samaritan'],
10020 ['Sarb', 'Old_South_Arabian'],
10021 ['Saur', 'Saurashtra'],
10022 ['Sgnw', 'SignWriting'],
10023 ['Shaw', 'Shavian'],
10024 ['Shrd', 'Sharada'],
10025 ['Sidd', 'Siddham'],
10026 ['Sind', 'Khudawadi'],
10027 ['Sinh', 'Sinhala'],
10028 ['Sora', 'Sora_Sompeng'],
10029 ['Soyo', 'Soyombo'],
10030 ['Sund', 'Sundanese'],
10031 ['Sylo', 'Syloti_Nagri'],
10032 ['Syrc', 'Syriac'],
10033 ['Tagb', 'Tagbanwa'],
10034 ['Takr', 'Takri'],
10035 ['Tale', 'Tai_Le'],
10036 ['Talu', 'New_Tai_Lue'],
10037 ['Taml', 'Tamil'],
10038 ['Tang', 'Tangut'],
10039 ['Tavt', 'Tai_Viet'],
10040 ['Telu', 'Telugu'],
10041 ['Tfng', 'Tifinagh'],
10042 ['Tglg', 'Tagalog'],
10043 ['Thaa', 'Thaana'],
10044 ['Thai', 'Thai'],
10045 ['Tibt', 'Tibetan'],
10046 ['Tirh', 'Tirhuta'],
10047 ['Ugar', 'Ugaritic'],
10048 ['Vaii', 'Vai'],
10049 ['Wara', 'Warang_Citi'],
10050 ['Xpeo', 'Old_Persian'],
10051 ['Xsux', 'Cuneiform'],
10052 ['Yiii', 'Yi'],
10053 ['Zanb', 'Zanabazar_Square'],
10054 ['Zinh', 'Inherited'],
10055 ['Qaai', 'Inherited'],
10056 ['Zyyy', 'Common'],
10057 ['Zzzz', 'Unknown'],
10058 ['Adlam', 'Adlam'],
10059 ['Caucasian_Albanian', 'Caucasian_Albanian'],
10060 ['Arabic', 'Arabic'],
10061 ['Imperial_Aramaic', 'Imperial_Aramaic'],
10062 ['Armenian', 'Armenian'],
10063 ['Avestan', 'Avestan'],
10064 ['Balinese', 'Balinese'],
10065 ['Bamum', 'Bamum'],
10066 ['Bassa_Vah', 'Bassa_Vah'],
10067 ['Batak', 'Batak'],
10068 ['Bengali', 'Bengali'],
10069 ['Bhaiksuki', 'Bhaiksuki'],
10070 ['Bopomofo', 'Bopomofo'],
10071 ['Brahmi', 'Brahmi'],
10072 ['Braille', 'Braille'],
10073 ['Buginese', 'Buginese'],
10074 ['Buhid', 'Buhid'],
10075 ['Chakma', 'Chakma'],
10076 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
10077 ['Carian', 'Carian'],
10078 ['Cherokee', 'Cherokee'],
10079 ['Coptic', 'Coptic'],
10080 ['Cypriot', 'Cypriot'],
10081 ['Cyrillic', 'Cyrillic'],
10082 ['Devanagari', 'Devanagari'],
10083 ['Deseret', 'Deseret'],
10084 ['Duployan', 'Duployan'],
10085 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
10086 ['Elbasan', 'Elbasan'],
10087 ['Ethiopic', 'Ethiopic'],
10088 ['Georgian', 'Georgian'],
10089 ['Glagolitic', 'Glagolitic'],
10090 ['Masaram_Gondi', 'Masaram_Gondi'],
10091 ['Gothic', 'Gothic'],
10092 ['Grantha', 'Grantha'],
10093 ['Greek', 'Greek'],
10094 ['Gujarati', 'Gujarati'],
10095 ['Gurmukhi', 'Gurmukhi'],
10096 ['Hangul', 'Hangul'],
10097 ['Han', 'Han'],
10098 ['Hanunoo', 'Hanunoo'],
10099 ['Hatran', 'Hatran'],
10100 ['Hebrew', 'Hebrew'],
10101 ['Hiragana', 'Hiragana'],
10102 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
10103 ['Pahawh_Hmong', 'Pahawh_Hmong'],
10104 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
10105 ['Old_Hungarian', 'Old_Hungarian'],
10106 ['Old_Italic', 'Old_Italic'],
10107 ['Javanese', 'Javanese'],
10108 ['Kayah_Li', 'Kayah_Li'],
10109 ['Katakana', 'Katakana'],
10110 ['Kharoshthi', 'Kharoshthi'],
10111 ['Khmer', 'Khmer'],
10112 ['Khojki', 'Khojki'],
10113 ['Kannada', 'Kannada'],
10114 ['Kaithi', 'Kaithi'],
10115 ['Tai_Tham', 'Tai_Tham'],
10116 ['Lao', 'Lao'],
10117 ['Latin', 'Latin'],
10118 ['Lepcha', 'Lepcha'],
10119 ['Limbu', 'Limbu'],
10120 ['Linear_A', 'Linear_A'],
10121 ['Linear_B', 'Linear_B'],
10122 ['Lycian', 'Lycian'],
10123 ['Lydian', 'Lydian'],
10124 ['Mahajani', 'Mahajani'],
10125 ['Mandaic', 'Mandaic'],
10126 ['Manichaean', 'Manichaean'],
10127 ['Marchen', 'Marchen'],
10128 ['Mende_Kikakui', 'Mende_Kikakui'],
10129 ['Meroitic_Cursive', 'Meroitic_Cursive'],
10130 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
10131 ['Malayalam', 'Malayalam'],
10132 ['Mongolian', 'Mongolian'],
10133 ['Mro', 'Mro'],
10134 ['Meetei_Mayek', 'Meetei_Mayek'],
10135 ['Multani', 'Multani'],
10136 ['Myanmar', 'Myanmar'],
10137 ['Old_North_Arabian', 'Old_North_Arabian'],
10138 ['Nabataean', 'Nabataean'],
10139 ['Nko', 'Nko'],
10140 ['Nushu', 'Nushu'],
10141 ['Ogham', 'Ogham'],
10142 ['Ol_Chiki', 'Ol_Chiki'],
10143 ['Old_Turkic', 'Old_Turkic'],
10144 ['Oriya', 'Oriya'],
10145 ['Osage', 'Osage'],
10146 ['Osmanya', 'Osmanya'],
10147 ['Palmyrene', 'Palmyrene'],
10148 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
10149 ['Old_Permic', 'Old_Permic'],
10150 ['Phags_Pa', 'Phags_Pa'],
10151 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
10152 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
10153 ['Phoenician', 'Phoenician'],
10154 ['Miao', 'Miao'],
10155 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
10156 ['Rejang', 'Rejang'],
10157 ['Runic', 'Runic'],
10158 ['Samaritan', 'Samaritan'],
10159 ['Old_South_Arabian', 'Old_South_Arabian'],
10160 ['Saurashtra', 'Saurashtra'],
10161 ['SignWriting', 'SignWriting'],
10162 ['Shavian', 'Shavian'],
10163 ['Sharada', 'Sharada'],
10164 ['Siddham', 'Siddham'],
10165 ['Khudawadi', 'Khudawadi'],
10166 ['Sinhala', 'Sinhala'],
10167 ['Sora_Sompeng', 'Sora_Sompeng'],
10168 ['Soyombo', 'Soyombo'],
10169 ['Sundanese', 'Sundanese'],
10170 ['Syloti_Nagri', 'Syloti_Nagri'],
10171 ['Syriac', 'Syriac'],
10172 ['Tagbanwa', 'Tagbanwa'],
10173 ['Takri', 'Takri'],
10174 ['Tai_Le', 'Tai_Le'],
10175 ['New_Tai_Lue', 'New_Tai_Lue'],
10176 ['Tamil', 'Tamil'],
10177 ['Tangut', 'Tangut'],
10178 ['Tai_Viet', 'Tai_Viet'],
10179 ['Telugu', 'Telugu'],
10180 ['Tifinagh', 'Tifinagh'],
10181 ['Tagalog', 'Tagalog'],
10182 ['Thaana', 'Thaana'],
10183 ['Tibetan', 'Tibetan'],
10184 ['Tirhuta', 'Tirhuta'],
10185 ['Ugaritic', 'Ugaritic'],
10186 ['Vai', 'Vai'],
10187 ['Warang_Citi', 'Warang_Citi'],
10188 ['Old_Persian', 'Old_Persian'],
10189 ['Cuneiform', 'Cuneiform'],
10190 ['Yi', 'Yi'],
10191 ['Zanabazar_Square', 'Zanabazar_Square'],
10192 ['Inherited', 'Inherited'],
10193 ['Common', 'Common'],
10194 ['Unknown', 'Unknown']
10195 ])]
10196]);
10197
10198'use strict';
10199
10200
10201
10202const matchPropertyValue = function(property, value) {
10203 const aliasToValue = mappings.get(property);
10204 if (!aliasToValue) {
10205 throw new Error(`Unknown property \`${ property }\`.`);
10206 }
10207 const canonicalValue = aliasToValue.get(value);
10208 if (canonicalValue) {
10209 return canonicalValue;
10210 }
10211 throw new Error(
10212 `Unknown value \`${ value }\` for property \`${ property }\`.`
10213 );
10214};
10215
10216var unicodeMatchPropertyValueEcmascript = matchPropertyValue;
10217
10218var iuMappings = new Map([
10219 [0x4B, 0x212A],
10220 [0x53, 0x17F],
10221 [0x6B, 0x212A],
10222 [0x73, 0x17F],
10223 [0xB5, 0x39C],
10224 [0xC5, 0x212B],
10225 [0xDF, 0x1E9E],
10226 [0xE5, 0x212B],
10227 [0x17F, 0x53],
10228 [0x1C4, 0x1C5],
10229 [0x1C5, 0x1C4],
10230 [0x1C7, 0x1C8],
10231 [0x1C8, 0x1C7],
10232 [0x1CA, 0x1CB],
10233 [0x1CB, 0x1CA],
10234 [0x1F1, 0x1F2],
10235 [0x1F2, 0x1F1],
10236 [0x26A, 0xA7AE],
10237 [0x29D, 0xA7B2],
10238 [0x345, 0x1FBE],
10239 [0x392, 0x3D0],
10240 [0x395, 0x3F5],
10241 [0x398, 0x3F4],
10242 [0x399, 0x1FBE],
10243 [0x39A, 0x3F0],
10244 [0x39C, 0xB5],
10245 [0x3A0, 0x3D6],
10246 [0x3A1, 0x3F1],
10247 [0x3A3, 0x3C2],
10248 [0x3A6, 0x3D5],
10249 [0x3A9, 0x2126],
10250 [0x3B8, 0x3F4],
10251 [0x3C2, 0x3A3],
10252 [0x3C9, 0x2126],
10253 [0x3D0, 0x392],
10254 [0x3D1, 0x3F4],
10255 [0x3D5, 0x3A6],
10256 [0x3D6, 0x3A0],
10257 [0x3F0, 0x39A],
10258 [0x3F1, 0x3A1],
10259 [0x3F4, [
10260 0x398,
10261 0x3D1,
10262 0x3B8
10263 ]],
10264 [0x3F5, 0x395],
10265 [0x412, 0x1C80],
10266 [0x414, 0x1C81],
10267 [0x41E, 0x1C82],
10268 [0x421, 0x1C83],
10269 [0x422, 0x1C85],
10270 [0x42A, 0x1C86],
10271 [0x432, 0x1C80],
10272 [0x434, 0x1C81],
10273 [0x43E, 0x1C82],
10274 [0x441, 0x1C83],
10275 [0x442, [
10276 0x1C84,
10277 0x1C85
10278 ]],
10279 [0x44A, 0x1C86],
10280 [0x462, 0x1C87],
10281 [0x463, 0x1C87],
10282 [0x13A0, 0xAB70],
10283 [0x13A1, 0xAB71],
10284 [0x13A2, 0xAB72],
10285 [0x13A3, 0xAB73],
10286 [0x13A4, 0xAB74],
10287 [0x13A5, 0xAB75],
10288 [0x13A6, 0xAB76],
10289 [0x13A7, 0xAB77],
10290 [0x13A8, 0xAB78],
10291 [0x13A9, 0xAB79],
10292 [0x13AA, 0xAB7A],
10293 [0x13AB, 0xAB7B],
10294 [0x13AC, 0xAB7C],
10295 [0x13AD, 0xAB7D],
10296 [0x13AE, 0xAB7E],
10297 [0x13AF, 0xAB7F],
10298 [0x13B0, 0xAB80],
10299 [0x13B1, 0xAB81],
10300 [0x13B2, 0xAB82],
10301 [0x13B3, 0xAB83],
10302 [0x13B4, 0xAB84],
10303 [0x13B5, 0xAB85],
10304 [0x13B6, 0xAB86],
10305 [0x13B7, 0xAB87],
10306 [0x13B8, 0xAB88],
10307 [0x13B9, 0xAB89],
10308 [0x13BA, 0xAB8A],
10309 [0x13BB, 0xAB8B],
10310 [0x13BC, 0xAB8C],
10311 [0x13BD, 0xAB8D],
10312 [0x13BE, 0xAB8E],
10313 [0x13BF, 0xAB8F],
10314 [0x13C0, 0xAB90],
10315 [0x13C1, 0xAB91],
10316 [0x13C2, 0xAB92],
10317 [0x13C3, 0xAB93],
10318 [0x13C4, 0xAB94],
10319 [0x13C5, 0xAB95],
10320 [0x13C6, 0xAB96],
10321 [0x13C7, 0xAB97],
10322 [0x13C8, 0xAB98],
10323 [0x13C9, 0xAB99],
10324 [0x13CA, 0xAB9A],
10325 [0x13CB, 0xAB9B],
10326 [0x13CC, 0xAB9C],
10327 [0x13CD, 0xAB9D],
10328 [0x13CE, 0xAB9E],
10329 [0x13CF, 0xAB9F],
10330 [0x13D0, 0xABA0],
10331 [0x13D1, 0xABA1],
10332 [0x13D2, 0xABA2],
10333 [0x13D3, 0xABA3],
10334 [0x13D4, 0xABA4],
10335 [0x13D5, 0xABA5],
10336 [0x13D6, 0xABA6],
10337 [0x13D7, 0xABA7],
10338 [0x13D8, 0xABA8],
10339 [0x13D9, 0xABA9],
10340 [0x13DA, 0xABAA],
10341 [0x13DB, 0xABAB],
10342 [0x13DC, 0xABAC],
10343 [0x13DD, 0xABAD],
10344 [0x13DE, 0xABAE],
10345 [0x13DF, 0xABAF],
10346 [0x13E0, 0xABB0],
10347 [0x13E1, 0xABB1],
10348 [0x13E2, 0xABB2],
10349 [0x13E3, 0xABB3],
10350 [0x13E4, 0xABB4],
10351 [0x13E5, 0xABB5],
10352 [0x13E6, 0xABB6],
10353 [0x13E7, 0xABB7],
10354 [0x13E8, 0xABB8],
10355 [0x13E9, 0xABB9],
10356 [0x13EA, 0xABBA],
10357 [0x13EB, 0xABBB],
10358 [0x13EC, 0xABBC],
10359 [0x13ED, 0xABBD],
10360 [0x13EE, 0xABBE],
10361 [0x13EF, 0xABBF],
10362 [0x13F0, 0x13F8],
10363 [0x13F1, 0x13F9],
10364 [0x13F2, 0x13FA],
10365 [0x13F3, 0x13FB],
10366 [0x13F4, 0x13FC],
10367 [0x13F5, 0x13FD],
10368 [0x13F8, 0x13F0],
10369 [0x13F9, 0x13F1],
10370 [0x13FA, 0x13F2],
10371 [0x13FB, 0x13F3],
10372 [0x13FC, 0x13F4],
10373 [0x13FD, 0x13F5],
10374 [0x1C80, [
10375 0x412,
10376 0x432
10377 ]],
10378 [0x1C81, [
10379 0x414,
10380 0x434
10381 ]],
10382 [0x1C82, [
10383 0x41E,
10384 0x43E
10385 ]],
10386 [0x1C83, [
10387 0x421,
10388 0x441
10389 ]],
10390 [0x1C84, [
10391 0x1C85,
10392 0x442
10393 ]],
10394 [0x1C85, [
10395 0x422,
10396 0x1C84,
10397 0x442
10398 ]],
10399 [0x1C86, [
10400 0x42A,
10401 0x44A
10402 ]],
10403 [0x1C87, [
10404 0x462,
10405 0x463
10406 ]],
10407 [0x1C88, [
10408 0xA64A,
10409 0xA64B
10410 ]],
10411 [0x1E60, 0x1E9B],
10412 [0x1E9B, 0x1E60],
10413 [0x1E9E, 0xDF],
10414 [0x1F80, 0x1F88],
10415 [0x1F81, 0x1F89],
10416 [0x1F82, 0x1F8A],
10417 [0x1F83, 0x1F8B],
10418 [0x1F84, 0x1F8C],
10419 [0x1F85, 0x1F8D],
10420 [0x1F86, 0x1F8E],
10421 [0x1F87, 0x1F8F],
10422 [0x1F88, 0x1F80],
10423 [0x1F89, 0x1F81],
10424 [0x1F8A, 0x1F82],
10425 [0x1F8B, 0x1F83],
10426 [0x1F8C, 0x1F84],
10427 [0x1F8D, 0x1F85],
10428 [0x1F8E, 0x1F86],
10429 [0x1F8F, 0x1F87],
10430 [0x1F90, 0x1F98],
10431 [0x1F91, 0x1F99],
10432 [0x1F92, 0x1F9A],
10433 [0x1F93, 0x1F9B],
10434 [0x1F94, 0x1F9C],
10435 [0x1F95, 0x1F9D],
10436 [0x1F96, 0x1F9E],
10437 [0x1F97, 0x1F9F],
10438 [0x1F98, 0x1F90],
10439 [0x1F99, 0x1F91],
10440 [0x1F9A, 0x1F92],
10441 [0x1F9B, 0x1F93],
10442 [0x1F9C, 0x1F94],
10443 [0x1F9D, 0x1F95],
10444 [0x1F9E, 0x1F96],
10445 [0x1F9F, 0x1F97],
10446 [0x1FA0, 0x1FA8],
10447 [0x1FA1, 0x1FA9],
10448 [0x1FA2, 0x1FAA],
10449 [0x1FA3, 0x1FAB],
10450 [0x1FA4, 0x1FAC],
10451 [0x1FA5, 0x1FAD],
10452 [0x1FA6, 0x1FAE],
10453 [0x1FA7, 0x1FAF],
10454 [0x1FA8, 0x1FA0],
10455 [0x1FA9, 0x1FA1],
10456 [0x1FAA, 0x1FA2],
10457 [0x1FAB, 0x1FA3],
10458 [0x1FAC, 0x1FA4],
10459 [0x1FAD, 0x1FA5],
10460 [0x1FAE, 0x1FA6],
10461 [0x1FAF, 0x1FA7],
10462 [0x1FB3, 0x1FBC],
10463 [0x1FBC, 0x1FB3],
10464 [0x1FBE, [
10465 0x345,
10466 0x399
10467 ]],
10468 [0x1FC3, 0x1FCC],
10469 [0x1FCC, 0x1FC3],
10470 [0x1FF3, 0x1FFC],
10471 [0x1FFC, 0x1FF3],
10472 [0x2126, [
10473 0x3A9,
10474 0x3C9
10475 ]],
10476 [0x212A, 0x4B],
10477 [0x212B, [
10478 0xC5,
10479 0xE5
10480 ]],
10481 [0xA64A, 0x1C88],
10482 [0xA64B, 0x1C88],
10483 [0xA7AE, 0x26A],
10484 [0xA7B2, 0x29D],
10485 [0xA7B3, 0xAB53],
10486 [0xA7B4, 0xA7B5],
10487 [0xA7B5, 0xA7B4],
10488 [0xA7B6, 0xA7B7],
10489 [0xA7B7, 0xA7B6],
10490 [0xAB53, 0xA7B3],
10491 [0xAB70, 0x13A0],
10492 [0xAB71, 0x13A1],
10493 [0xAB72, 0x13A2],
10494 [0xAB73, 0x13A3],
10495 [0xAB74, 0x13A4],
10496 [0xAB75, 0x13A5],
10497 [0xAB76, 0x13A6],
10498 [0xAB77, 0x13A7],
10499 [0xAB78, 0x13A8],
10500 [0xAB79, 0x13A9],
10501 [0xAB7A, 0x13AA],
10502 [0xAB7B, 0x13AB],
10503 [0xAB7C, 0x13AC],
10504 [0xAB7D, 0x13AD],
10505 [0xAB7E, 0x13AE],
10506 [0xAB7F, 0x13AF],
10507 [0xAB80, 0x13B0],
10508 [0xAB81, 0x13B1],
10509 [0xAB82, 0x13B2],
10510 [0xAB83, 0x13B3],
10511 [0xAB84, 0x13B4],
10512 [0xAB85, 0x13B5],
10513 [0xAB86, 0x13B6],
10514 [0xAB87, 0x13B7],
10515 [0xAB88, 0x13B8],
10516 [0xAB89, 0x13B9],
10517 [0xAB8A, 0x13BA],
10518 [0xAB8B, 0x13BB],
10519 [0xAB8C, 0x13BC],
10520 [0xAB8D, 0x13BD],
10521 [0xAB8E, 0x13BE],
10522 [0xAB8F, 0x13BF],
10523 [0xAB90, 0x13C0],
10524 [0xAB91, 0x13C1],
10525 [0xAB92, 0x13C2],
10526 [0xAB93, 0x13C3],
10527 [0xAB94, 0x13C4],
10528 [0xAB95, 0x13C5],
10529 [0xAB96, 0x13C6],
10530 [0xAB97, 0x13C7],
10531 [0xAB98, 0x13C8],
10532 [0xAB99, 0x13C9],
10533 [0xAB9A, 0x13CA],
10534 [0xAB9B, 0x13CB],
10535 [0xAB9C, 0x13CC],
10536 [0xAB9D, 0x13CD],
10537 [0xAB9E, 0x13CE],
10538 [0xAB9F, 0x13CF],
10539 [0xABA0, 0x13D0],
10540 [0xABA1, 0x13D1],
10541 [0xABA2, 0x13D2],
10542 [0xABA3, 0x13D3],
10543 [0xABA4, 0x13D4],
10544 [0xABA5, 0x13D5],
10545 [0xABA6, 0x13D6],
10546 [0xABA7, 0x13D7],
10547 [0xABA8, 0x13D8],
10548 [0xABA9, 0x13D9],
10549 [0xABAA, 0x13DA],
10550 [0xABAB, 0x13DB],
10551 [0xABAC, 0x13DC],
10552 [0xABAD, 0x13DD],
10553 [0xABAE, 0x13DE],
10554 [0xABAF, 0x13DF],
10555 [0xABB0, 0x13E0],
10556 [0xABB1, 0x13E1],
10557 [0xABB2, 0x13E2],
10558 [0xABB3, 0x13E3],
10559 [0xABB4, 0x13E4],
10560 [0xABB5, 0x13E5],
10561 [0xABB6, 0x13E6],
10562 [0xABB7, 0x13E7],
10563 [0xABB8, 0x13E8],
10564 [0xABB9, 0x13E9],
10565 [0xABBA, 0x13EA],
10566 [0xABBB, 0x13EB],
10567 [0xABBC, 0x13EC],
10568 [0xABBD, 0x13ED],
10569 [0xABBE, 0x13EE],
10570 [0xABBF, 0x13EF],
10571 [0x10400, 0x10428],
10572 [0x10401, 0x10429],
10573 [0x10402, 0x1042A],
10574 [0x10403, 0x1042B],
10575 [0x10404, 0x1042C],
10576 [0x10405, 0x1042D],
10577 [0x10406, 0x1042E],
10578 [0x10407, 0x1042F],
10579 [0x10408, 0x10430],
10580 [0x10409, 0x10431],
10581 [0x1040A, 0x10432],
10582 [0x1040B, 0x10433],
10583 [0x1040C, 0x10434],
10584 [0x1040D, 0x10435],
10585 [0x1040E, 0x10436],
10586 [0x1040F, 0x10437],
10587 [0x10410, 0x10438],
10588 [0x10411, 0x10439],
10589 [0x10412, 0x1043A],
10590 [0x10413, 0x1043B],
10591 [0x10414, 0x1043C],
10592 [0x10415, 0x1043D],
10593 [0x10416, 0x1043E],
10594 [0x10417, 0x1043F],
10595 [0x10418, 0x10440],
10596 [0x10419, 0x10441],
10597 [0x1041A, 0x10442],
10598 [0x1041B, 0x10443],
10599 [0x1041C, 0x10444],
10600 [0x1041D, 0x10445],
10601 [0x1041E, 0x10446],
10602 [0x1041F, 0x10447],
10603 [0x10420, 0x10448],
10604 [0x10421, 0x10449],
10605 [0x10422, 0x1044A],
10606 [0x10423, 0x1044B],
10607 [0x10424, 0x1044C],
10608 [0x10425, 0x1044D],
10609 [0x10426, 0x1044E],
10610 [0x10427, 0x1044F],
10611 [0x10428, 0x10400],
10612 [0x10429, 0x10401],
10613 [0x1042A, 0x10402],
10614 [0x1042B, 0x10403],
10615 [0x1042C, 0x10404],
10616 [0x1042D, 0x10405],
10617 [0x1042E, 0x10406],
10618 [0x1042F, 0x10407],
10619 [0x10430, 0x10408],
10620 [0x10431, 0x10409],
10621 [0x10432, 0x1040A],
10622 [0x10433, 0x1040B],
10623 [0x10434, 0x1040C],
10624 [0x10435, 0x1040D],
10625 [0x10436, 0x1040E],
10626 [0x10437, 0x1040F],
10627 [0x10438, 0x10410],
10628 [0x10439, 0x10411],
10629 [0x1043A, 0x10412],
10630 [0x1043B, 0x10413],
10631 [0x1043C, 0x10414],
10632 [0x1043D, 0x10415],
10633 [0x1043E, 0x10416],
10634 [0x1043F, 0x10417],
10635 [0x10440, 0x10418],
10636 [0x10441, 0x10419],
10637 [0x10442, 0x1041A],
10638 [0x10443, 0x1041B],
10639 [0x10444, 0x1041C],
10640 [0x10445, 0x1041D],
10641 [0x10446, 0x1041E],
10642 [0x10447, 0x1041F],
10643 [0x10448, 0x10420],
10644 [0x10449, 0x10421],
10645 [0x1044A, 0x10422],
10646 [0x1044B, 0x10423],
10647 [0x1044C, 0x10424],
10648 [0x1044D, 0x10425],
10649 [0x1044E, 0x10426],
10650 [0x1044F, 0x10427],
10651 [0x104B0, 0x104D8],
10652 [0x104B1, 0x104D9],
10653 [0x104B2, 0x104DA],
10654 [0x104B3, 0x104DB],
10655 [0x104B4, 0x104DC],
10656 [0x104B5, 0x104DD],
10657 [0x104B6, 0x104DE],
10658 [0x104B7, 0x104DF],
10659 [0x104B8, 0x104E0],
10660 [0x104B9, 0x104E1],
10661 [0x104BA, 0x104E2],
10662 [0x104BB, 0x104E3],
10663 [0x104BC, 0x104E4],
10664 [0x104BD, 0x104E5],
10665 [0x104BE, 0x104E6],
10666 [0x104BF, 0x104E7],
10667 [0x104C0, 0x104E8],
10668 [0x104C1, 0x104E9],
10669 [0x104C2, 0x104EA],
10670 [0x104C3, 0x104EB],
10671 [0x104C4, 0x104EC],
10672 [0x104C5, 0x104ED],
10673 [0x104C6, 0x104EE],
10674 [0x104C7, 0x104EF],
10675 [0x104C8, 0x104F0],
10676 [0x104C9, 0x104F1],
10677 [0x104CA, 0x104F2],
10678 [0x104CB, 0x104F3],
10679 [0x104CC, 0x104F4],
10680 [0x104CD, 0x104F5],
10681 [0x104CE, 0x104F6],
10682 [0x104CF, 0x104F7],
10683 [0x104D0, 0x104F8],
10684 [0x104D1, 0x104F9],
10685 [0x104D2, 0x104FA],
10686 [0x104D3, 0x104FB],
10687 [0x104D8, 0x104B0],
10688 [0x104D9, 0x104B1],
10689 [0x104DA, 0x104B2],
10690 [0x104DB, 0x104B3],
10691 [0x104DC, 0x104B4],
10692 [0x104DD, 0x104B5],
10693 [0x104DE, 0x104B6],
10694 [0x104DF, 0x104B7],
10695 [0x104E0, 0x104B8],
10696 [0x104E1, 0x104B9],
10697 [0x104E2, 0x104BA],
10698 [0x104E3, 0x104BB],
10699 [0x104E4, 0x104BC],
10700 [0x104E5, 0x104BD],
10701 [0x104E6, 0x104BE],
10702 [0x104E7, 0x104BF],
10703 [0x104E8, 0x104C0],
10704 [0x104E9, 0x104C1],
10705 [0x104EA, 0x104C2],
10706 [0x104EB, 0x104C3],
10707 [0x104EC, 0x104C4],
10708 [0x104ED, 0x104C5],
10709 [0x104EE, 0x104C6],
10710 [0x104EF, 0x104C7],
10711 [0x104F0, 0x104C8],
10712 [0x104F1, 0x104C9],
10713 [0x104F2, 0x104CA],
10714 [0x104F3, 0x104CB],
10715 [0x104F4, 0x104CC],
10716 [0x104F5, 0x104CD],
10717 [0x104F6, 0x104CE],
10718 [0x104F7, 0x104CF],
10719 [0x104F8, 0x104D0],
10720 [0x104F9, 0x104D1],
10721 [0x104FA, 0x104D2],
10722 [0x104FB, 0x104D3],
10723 [0x10C80, 0x10CC0],
10724 [0x10C81, 0x10CC1],
10725 [0x10C82, 0x10CC2],
10726 [0x10C83, 0x10CC3],
10727 [0x10C84, 0x10CC4],
10728 [0x10C85, 0x10CC5],
10729 [0x10C86, 0x10CC6],
10730 [0x10C87, 0x10CC7],
10731 [0x10C88, 0x10CC8],
10732 [0x10C89, 0x10CC9],
10733 [0x10C8A, 0x10CCA],
10734 [0x10C8B, 0x10CCB],
10735 [0x10C8C, 0x10CCC],
10736 [0x10C8D, 0x10CCD],
10737 [0x10C8E, 0x10CCE],
10738 [0x10C8F, 0x10CCF],
10739 [0x10C90, 0x10CD0],
10740 [0x10C91, 0x10CD1],
10741 [0x10C92, 0x10CD2],
10742 [0x10C93, 0x10CD3],
10743 [0x10C94, 0x10CD4],
10744 [0x10C95, 0x10CD5],
10745 [0x10C96, 0x10CD6],
10746 [0x10C97, 0x10CD7],
10747 [0x10C98, 0x10CD8],
10748 [0x10C99, 0x10CD9],
10749 [0x10C9A, 0x10CDA],
10750 [0x10C9B, 0x10CDB],
10751 [0x10C9C, 0x10CDC],
10752 [0x10C9D, 0x10CDD],
10753 [0x10C9E, 0x10CDE],
10754 [0x10C9F, 0x10CDF],
10755 [0x10CA0, 0x10CE0],
10756 [0x10CA1, 0x10CE1],
10757 [0x10CA2, 0x10CE2],
10758 [0x10CA3, 0x10CE3],
10759 [0x10CA4, 0x10CE4],
10760 [0x10CA5, 0x10CE5],
10761 [0x10CA6, 0x10CE6],
10762 [0x10CA7, 0x10CE7],
10763 [0x10CA8, 0x10CE8],
10764 [0x10CA9, 0x10CE9],
10765 [0x10CAA, 0x10CEA],
10766 [0x10CAB, 0x10CEB],
10767 [0x10CAC, 0x10CEC],
10768 [0x10CAD, 0x10CED],
10769 [0x10CAE, 0x10CEE],
10770 [0x10CAF, 0x10CEF],
10771 [0x10CB0, 0x10CF0],
10772 [0x10CB1, 0x10CF1],
10773 [0x10CB2, 0x10CF2],
10774 [0x10CC0, 0x10C80],
10775 [0x10CC1, 0x10C81],
10776 [0x10CC2, 0x10C82],
10777 [0x10CC3, 0x10C83],
10778 [0x10CC4, 0x10C84],
10779 [0x10CC5, 0x10C85],
10780 [0x10CC6, 0x10C86],
10781 [0x10CC7, 0x10C87],
10782 [0x10CC8, 0x10C88],
10783 [0x10CC9, 0x10C89],
10784 [0x10CCA, 0x10C8A],
10785 [0x10CCB, 0x10C8B],
10786 [0x10CCC, 0x10C8C],
10787 [0x10CCD, 0x10C8D],
10788 [0x10CCE, 0x10C8E],
10789 [0x10CCF, 0x10C8F],
10790 [0x10CD0, 0x10C90],
10791 [0x10CD1, 0x10C91],
10792 [0x10CD2, 0x10C92],
10793 [0x10CD3, 0x10C93],
10794 [0x10CD4, 0x10C94],
10795 [0x10CD5, 0x10C95],
10796 [0x10CD6, 0x10C96],
10797 [0x10CD7, 0x10C97],
10798 [0x10CD8, 0x10C98],
10799 [0x10CD9, 0x10C99],
10800 [0x10CDA, 0x10C9A],
10801 [0x10CDB, 0x10C9B],
10802 [0x10CDC, 0x10C9C],
10803 [0x10CDD, 0x10C9D],
10804 [0x10CDE, 0x10C9E],
10805 [0x10CDF, 0x10C9F],
10806 [0x10CE0, 0x10CA0],
10807 [0x10CE1, 0x10CA1],
10808 [0x10CE2, 0x10CA2],
10809 [0x10CE3, 0x10CA3],
10810 [0x10CE4, 0x10CA4],
10811 [0x10CE5, 0x10CA5],
10812 [0x10CE6, 0x10CA6],
10813 [0x10CE7, 0x10CA7],
10814 [0x10CE8, 0x10CA8],
10815 [0x10CE9, 0x10CA9],
10816 [0x10CEA, 0x10CAA],
10817 [0x10CEB, 0x10CAB],
10818 [0x10CEC, 0x10CAC],
10819 [0x10CED, 0x10CAD],
10820 [0x10CEE, 0x10CAE],
10821 [0x10CEF, 0x10CAF],
10822 [0x10CF0, 0x10CB0],
10823 [0x10CF1, 0x10CB1],
10824 [0x10CF2, 0x10CB2],
10825 [0x118A0, 0x118C0],
10826 [0x118A1, 0x118C1],
10827 [0x118A2, 0x118C2],
10828 [0x118A3, 0x118C3],
10829 [0x118A4, 0x118C4],
10830 [0x118A5, 0x118C5],
10831 [0x118A6, 0x118C6],
10832 [0x118A7, 0x118C7],
10833 [0x118A8, 0x118C8],
10834 [0x118A9, 0x118C9],
10835 [0x118AA, 0x118CA],
10836 [0x118AB, 0x118CB],
10837 [0x118AC, 0x118CC],
10838 [0x118AD, 0x118CD],
10839 [0x118AE, 0x118CE],
10840 [0x118AF, 0x118CF],
10841 [0x118B0, 0x118D0],
10842 [0x118B1, 0x118D1],
10843 [0x118B2, 0x118D2],
10844 [0x118B3, 0x118D3],
10845 [0x118B4, 0x118D4],
10846 [0x118B5, 0x118D5],
10847 [0x118B6, 0x118D6],
10848 [0x118B7, 0x118D7],
10849 [0x118B8, 0x118D8],
10850 [0x118B9, 0x118D9],
10851 [0x118BA, 0x118DA],
10852 [0x118BB, 0x118DB],
10853 [0x118BC, 0x118DC],
10854 [0x118BD, 0x118DD],
10855 [0x118BE, 0x118DE],
10856 [0x118BF, 0x118DF],
10857 [0x118C0, 0x118A0],
10858 [0x118C1, 0x118A1],
10859 [0x118C2, 0x118A2],
10860 [0x118C3, 0x118A3],
10861 [0x118C4, 0x118A4],
10862 [0x118C5, 0x118A5],
10863 [0x118C6, 0x118A6],
10864 [0x118C7, 0x118A7],
10865 [0x118C8, 0x118A8],
10866 [0x118C9, 0x118A9],
10867 [0x118CA, 0x118AA],
10868 [0x118CB, 0x118AB],
10869 [0x118CC, 0x118AC],
10870 [0x118CD, 0x118AD],
10871 [0x118CE, 0x118AE],
10872 [0x118CF, 0x118AF],
10873 [0x118D0, 0x118B0],
10874 [0x118D1, 0x118B1],
10875 [0x118D2, 0x118B2],
10876 [0x118D3, 0x118B3],
10877 [0x118D4, 0x118B4],
10878 [0x118D5, 0x118B5],
10879 [0x118D6, 0x118B6],
10880 [0x118D7, 0x118B7],
10881 [0x118D8, 0x118B8],
10882 [0x118D9, 0x118B9],
10883 [0x118DA, 0x118BA],
10884 [0x118DB, 0x118BB],
10885 [0x118DC, 0x118BC],
10886 [0x118DD, 0x118BD],
10887 [0x118DE, 0x118BE],
10888 [0x118DF, 0x118BF],
10889 [0x1E900, 0x1E922],
10890 [0x1E901, 0x1E923],
10891 [0x1E902, 0x1E924],
10892 [0x1E903, 0x1E925],
10893 [0x1E904, 0x1E926],
10894 [0x1E905, 0x1E927],
10895 [0x1E906, 0x1E928],
10896 [0x1E907, 0x1E929],
10897 [0x1E908, 0x1E92A],
10898 [0x1E909, 0x1E92B],
10899 [0x1E90A, 0x1E92C],
10900 [0x1E90B, 0x1E92D],
10901 [0x1E90C, 0x1E92E],
10902 [0x1E90D, 0x1E92F],
10903 [0x1E90E, 0x1E930],
10904 [0x1E90F, 0x1E931],
10905 [0x1E910, 0x1E932],
10906 [0x1E911, 0x1E933],
10907 [0x1E912, 0x1E934],
10908 [0x1E913, 0x1E935],
10909 [0x1E914, 0x1E936],
10910 [0x1E915, 0x1E937],
10911 [0x1E916, 0x1E938],
10912 [0x1E917, 0x1E939],
10913 [0x1E918, 0x1E93A],
10914 [0x1E919, 0x1E93B],
10915 [0x1E91A, 0x1E93C],
10916 [0x1E91B, 0x1E93D],
10917 [0x1E91C, 0x1E93E],
10918 [0x1E91D, 0x1E93F],
10919 [0x1E91E, 0x1E940],
10920 [0x1E91F, 0x1E941],
10921 [0x1E920, 0x1E942],
10922 [0x1E921, 0x1E943],
10923 [0x1E922, 0x1E900],
10924 [0x1E923, 0x1E901],
10925 [0x1E924, 0x1E902],
10926 [0x1E925, 0x1E903],
10927 [0x1E926, 0x1E904],
10928 [0x1E927, 0x1E905],
10929 [0x1E928, 0x1E906],
10930 [0x1E929, 0x1E907],
10931 [0x1E92A, 0x1E908],
10932 [0x1E92B, 0x1E909],
10933 [0x1E92C, 0x1E90A],
10934 [0x1E92D, 0x1E90B],
10935 [0x1E92E, 0x1E90C],
10936 [0x1E92F, 0x1E90D],
10937 [0x1E930, 0x1E90E],
10938 [0x1E931, 0x1E90F],
10939 [0x1E932, 0x1E910],
10940 [0x1E933, 0x1E911],
10941 [0x1E934, 0x1E912],
10942 [0x1E935, 0x1E913],
10943 [0x1E936, 0x1E914],
10944 [0x1E937, 0x1E915],
10945 [0x1E938, 0x1E916],
10946 [0x1E939, 0x1E917],
10947 [0x1E93A, 0x1E918],
10948 [0x1E93B, 0x1E919],
10949 [0x1E93C, 0x1E91A],
10950 [0x1E93D, 0x1E91B],
10951 [0x1E93E, 0x1E91C],
10952 [0x1E93F, 0x1E91D],
10953 [0x1E940, 0x1E91E],
10954 [0x1E941, 0x1E91F],
10955 [0x1E942, 0x1E920],
10956 [0x1E943, 0x1E921]
10957]);
10958
10959// Generated using `npm run build`. Do not edit.
10960'use strict';
10961
10962
10963
10964var REGULAR = new Map([
10965 ['d', regenerate()
10966 .addRange(0x30, 0x39)],
10967 ['D', regenerate()
10968 .addRange(0x0, 0x2F)
10969 .addRange(0x3A, 0xFFFF)],
10970 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
10971 .addRange(0x9, 0xD)
10972 .addRange(0x2000, 0x200A)
10973 .addRange(0x2028, 0x2029)],
10974 ['S', regenerate()
10975 .addRange(0x0, 0x8)
10976 .addRange(0xE, 0x1F)
10977 .addRange(0x21, 0x9F)
10978 .addRange(0xA1, 0x167F)
10979 .addRange(0x1681, 0x1FFF)
10980 .addRange(0x200B, 0x2027)
10981 .addRange(0x202A, 0x202E)
10982 .addRange(0x2030, 0x205E)
10983 .addRange(0x2060, 0x2FFF)
10984 .addRange(0x3001, 0xFEFE)
10985 .addRange(0xFF00, 0xFFFF)],
10986 ['w', regenerate(0x5F)
10987 .addRange(0x30, 0x39)
10988 .addRange(0x41, 0x5A)
10989 .addRange(0x61, 0x7A)],
10990 ['W', regenerate(0x60)
10991 .addRange(0x0, 0x2F)
10992 .addRange(0x3A, 0x40)
10993 .addRange(0x5B, 0x5E)
10994 .addRange(0x7B, 0xFFFF)]
10995]);
10996
10997var UNICODE = new Map([
10998 ['d', regenerate()
10999 .addRange(0x30, 0x39)],
11000 ['D', regenerate()
11001 .addRange(0x0, 0x2F)
11002 .addRange(0x3A, 0x10FFFF)],
11003 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
11004 .addRange(0x9, 0xD)
11005 .addRange(0x2000, 0x200A)
11006 .addRange(0x2028, 0x2029)],
11007 ['S', regenerate()
11008 .addRange(0x0, 0x8)
11009 .addRange(0xE, 0x1F)
11010 .addRange(0x21, 0x9F)
11011 .addRange(0xA1, 0x167F)
11012 .addRange(0x1681, 0x1FFF)
11013 .addRange(0x200B, 0x2027)
11014 .addRange(0x202A, 0x202E)
11015 .addRange(0x2030, 0x205E)
11016 .addRange(0x2060, 0x2FFF)
11017 .addRange(0x3001, 0xFEFE)
11018 .addRange(0xFF00, 0x10FFFF)],
11019 ['w', regenerate(0x5F)
11020 .addRange(0x30, 0x39)
11021 .addRange(0x41, 0x5A)
11022 .addRange(0x61, 0x7A)],
11023 ['W', regenerate(0x60)
11024 .addRange(0x0, 0x2F)
11025 .addRange(0x3A, 0x40)
11026 .addRange(0x5B, 0x5E)
11027 .addRange(0x7B, 0x10FFFF)]
11028]);
11029
11030var UNICODE_IGNORE_CASE = new Map([
11031 ['d', regenerate()
11032 .addRange(0x30, 0x39)],
11033 ['D', regenerate()
11034 .addRange(0x0, 0x2F)
11035 .addRange(0x3A, 0x10FFFF)],
11036 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
11037 .addRange(0x9, 0xD)
11038 .addRange(0x2000, 0x200A)
11039 .addRange(0x2028, 0x2029)],
11040 ['S', regenerate()
11041 .addRange(0x0, 0x8)
11042 .addRange(0xE, 0x1F)
11043 .addRange(0x21, 0x9F)
11044 .addRange(0xA1, 0x167F)
11045 .addRange(0x1681, 0x1FFF)
11046 .addRange(0x200B, 0x2027)
11047 .addRange(0x202A, 0x202E)
11048 .addRange(0x2030, 0x205E)
11049 .addRange(0x2060, 0x2FFF)
11050 .addRange(0x3001, 0xFEFE)
11051 .addRange(0xFF00, 0x10FFFF)],
11052 ['w', regenerate(0x5F, 0x17F, 0x212A)
11053 .addRange(0x30, 0x39)
11054 .addRange(0x41, 0x5A)
11055 .addRange(0x61, 0x7A)],
11056 ['W', regenerate(0x60)
11057 .addRange(0x0, 0x2F)
11058 .addRange(0x3A, 0x40)
11059 .addRange(0x5B, 0x5E)
11060 .addRange(0x7B, 0x17E)
11061 .addRange(0x180, 0x2129)
11062 .addRange(0x212B, 0x10FFFF)]
11063]);
11064
11065var characterClassEscapeSets = {
11066 REGULAR: REGULAR,
11067 UNICODE: UNICODE,
11068 UNICODE_IGNORE_CASE: UNICODE_IGNORE_CASE
11069};
11070
11071var rewritePattern_1 = createCommonjsModule(function (module) {
11072'use strict';
11073
11074var generate = regjsgen.generate;
11075var parse = parser.parse;
11076
11077
11078
11079
11080
11081
11082// Prepare a Regenerate set containing all code points, used for negative
11083// character classes (if any).
11084var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
11085// Without the `u` flag, the range stops at 0xFFFF.
11086// https://mths.be/es6#sec-pattern-semantics
11087var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
11088
11089// Prepare a Regenerate set containing all code points that are supposed to be
11090// matched by `/./u`. https://mths.be/es6#sec-atom
11091var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
11092 .remove(
11093 // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
11094 0x000A, // Line Feed <LF>
11095 0x000D, // Carriage Return <CR>
11096 0x2028, // Line Separator <LS>
11097 0x2029 // Paragraph Separator <PS>
11098 );
11099// Prepare a Regenerate set containing all code points that are supposed to be
11100// matched by `/./` (only BMP code points).
11101var DOT_SET = DOT_SET_UNICODE.clone()
11102 .intersection(BMP_SET);
11103
11104var getCharacterClassEscapeSet = function (character, unicode, ignoreCase) {
11105 if (unicode) {
11106 if (ignoreCase) {
11107 return characterClassEscapeSets.UNICODE_IGNORE_CASE.get(character);
11108 }
11109 return characterClassEscapeSets.UNICODE.get(character);
11110 }
11111 return characterClassEscapeSets.REGULAR.get(character);
11112};
11113
11114var getDotSet = function (unicode, dotAll) {
11115 if (dotAll) {
11116 return unicode ? UNICODE_SET : BMP_SET;
11117 }
11118 return unicode ? DOT_SET_UNICODE : DOT_SET;
11119};
11120
11121var getUnicodePropertyValueSet = function (property, value) {
11122 var path = value ?
11123 (property + "/" + value) :
11124 ("Binary_Property/" + property);
11125 try {
11126 return commonjsRequire(("regenerate-unicode-properties/" + path + ".js"));
11127 } catch (exception) {
11128 throw new Error(
11129 "Failed to recognize value `" + value + "` for property " +
11130 "`" + property + "`."
11131 );
11132 }
11133};
11134
11135var handleLoneUnicodePropertyNameOrValue = function (value) {
11136 // It could be a `General_Category` value or a binary property.
11137 // Note: `unicodeMatchPropertyValue` throws on invalid values.
11138 try {
11139 var property$1 = 'General_Category';
11140 var category = unicodeMatchPropertyValueEcmascript(property$1, value);
11141 return getUnicodePropertyValueSet(property$1, category);
11142 } catch (exception) {}
11143 // It’s not a `General_Category` value, so check if it’s a binary
11144 // property. Note: `unicodeMatchProperty` throws on invalid properties.
11145 var property = unicodeMatchPropertyEcmascript(value);
11146 return getUnicodePropertyValueSet(property);
11147};
11148
11149var getUnicodePropertyEscapeSet = function (value, isNegative) {
11150 var parts = value.split('=');
11151 var firstPart = parts[0];
11152 var set;
11153 if (parts.length == 1) {
11154 set = handleLoneUnicodePropertyNameOrValue(firstPart);
11155 } else {
11156 // The pattern consists of two parts, i.e. `Property=Value`.
11157 var property = unicodeMatchPropertyEcmascript(firstPart);
11158 var value$1 = unicodeMatchPropertyValueEcmascript(property, parts[1]);
11159 set = getUnicodePropertyValueSet(property, value$1);
11160 }
11161 if (isNegative) {
11162 return UNICODE_SET.clone().remove(set);
11163 }
11164 return set.clone();
11165};
11166
11167// Given a range of code points, add any case-folded code points in that range
11168// to a set.
11169regenerate.prototype.iuAddRange = function(min, max) {
11170 var $this = this;
11171 do {
11172 var folded = caseFold(min);
11173 if (folded) {
11174 $this.add(folded);
11175 }
11176 } while (++min <= max);
11177 return $this;
11178};
11179
11180var update = function (item, pattern) {
11181 var tree = parse(pattern, config.useUnicodeFlag ? 'u' : '');
11182 switch (tree.type) {
11183 case 'characterClass':
11184 case 'group':
11185 case 'value':
11186 // No wrapping needed.
11187 break;
11188 default:
11189 // Wrap the pattern in a non-capturing group.
11190 tree = wrap(tree, pattern);
11191 }
11192 Object.assign(item, tree);
11193};
11194
11195var wrap = function (tree, pattern) {
11196 // Wrap the pattern in a non-capturing group.
11197 return {
11198 'type': 'group',
11199 'behavior': 'ignore',
11200 'body': [tree],
11201 'raw': ("(?:" + pattern + ")")
11202 };
11203};
11204
11205var caseFold = function (codePoint) {
11206 return iuMappings.get(codePoint) || false;
11207};
11208
11209var processCharacterClass = function (characterClassItem, regenerateOptions) {
11210 var set = regenerate();
11211 for (var i = 0, list = characterClassItem.body; i < list.length; i += 1) {
11212 var item = list[i];
11213
11214 switch (item.type) {
11215 case 'value':
11216 set.add(item.codePoint);
11217 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11218 var folded = caseFold(item.codePoint);
11219 if (folded) {
11220 set.add(folded);
11221 }
11222 }
11223 break;
11224 case 'characterClassRange':
11225 var min = item.min.codePoint;
11226 var max = item.max.codePoint;
11227 set.addRange(min, max);
11228 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11229 set.iuAddRange(min, max);
11230 }
11231 break;
11232 case 'characterClassEscape':
11233 set.add(getCharacterClassEscapeSet(
11234 item.value,
11235 config.unicode,
11236 config.ignoreCase
11237 ));
11238 break;
11239 case 'unicodePropertyEscape':
11240 set.add(getUnicodePropertyEscapeSet(item.value, item.negative));
11241 break;
11242 // The `default` clause is only here as a safeguard; it should never be
11243 // reached. Code coverage tools should ignore it.
11244 /* istanbul ignore next */
11245 default:
11246 throw new Error(("Unknown term type: " + (item.type)));
11247 }
11248 }
11249 if (characterClassItem.negative) {
11250 set = (config.unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
11251 }
11252 update(characterClassItem, set.toString(regenerateOptions));
11253 return characterClassItem;
11254};
11255
11256var processTerm = function (item, regenerateOptions) {
11257 switch (item.type) {
11258 case 'dot':
11259 update(
11260 item,
11261 getDotSet(config.unicode, config.dotAll).toString(regenerateOptions)
11262 );
11263 break;
11264 case 'characterClass':
11265 item = processCharacterClass(item, regenerateOptions);
11266 break;
11267 case 'unicodePropertyEscape':
11268 update(
11269 item,
11270 getUnicodePropertyEscapeSet(item.value, item.negative)
11271 .toString(regenerateOptions)
11272 );
11273 break;
11274 case 'characterClassEscape':
11275 update(
11276 item,
11277 getCharacterClassEscapeSet(
11278 item.value,
11279 config.unicode,
11280 config.ignoreCase
11281 ).toString(regenerateOptions)
11282 );
11283 break;
11284 case 'alternative':
11285 case 'disjunction':
11286 case 'group':
11287 case 'quantifier':
11288 item.body = item.body.map(function ( term ) {
11289 return processTerm(term, regenerateOptions);
11290 });
11291 break;
11292 case 'value':
11293 var codePoint = item.codePoint;
11294 var set = regenerate(codePoint);
11295 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11296 var folded = caseFold(codePoint);
11297 if (folded) {
11298 set.add(folded);
11299 }
11300 }
11301 update(item, set.toString(regenerateOptions));
11302 break;
11303 case 'anchor':
11304 case 'empty':
11305 case 'group':
11306 case 'reference':
11307 // Nothing to do here.
11308 break;
11309 // The `default` clause is only here as a safeguard; it should never be
11310 // reached. Code coverage tools should ignore it.
11311 /* istanbul ignore next */
11312 default:
11313 throw new Error(("Unknown term type: " + (item.type)));
11314 }
11315 return item;
11316};
11317
11318var config = {
11319 'ignoreCase': false,
11320 'unicode': false,
11321 'dotAll': false,
11322 'useUnicodeFlag': false
11323};
11324var rewritePattern = function (pattern, flags, options) {
11325 var regjsparserFeatures = {
11326 'unicodePropertyEscape': options && options.unicodePropertyEscape
11327 };
11328 config.ignoreCase = flags && flags.includes('i');
11329 config.unicode = flags && flags.includes('u');
11330 var supportDotAllFlag = options && options.dotAllFlag;
11331 config.dotAll = supportDotAllFlag && flags && flags.includes('s');
11332 config.useUnicodeFlag = options && options.useUnicodeFlag;
11333 var regenerateOptions = {
11334 'hasUnicodeFlag': config.useUnicodeFlag,
11335 'bmpOnly': !config.unicode
11336 };
11337 var tree = parse(pattern, flags, regjsparserFeatures);
11338 // Note: `processTerm` mutates `tree`.
11339 processTerm(tree, regenerateOptions);
11340 return generate(tree);
11341};
11342
11343module.exports = rewritePattern;
11344});
11345
11346var Literal = (function (Node) {
11347 function Literal () {
11348 Node.apply(this, arguments);
11349 }
11350
11351 if ( Node ) Literal.__proto__ = Node;
11352 Literal.prototype = Object.create( Node && Node.prototype );
11353 Literal.prototype.constructor = Literal;
11354
11355 Literal.prototype.initialise = function initialise () {
11356 if ( typeof this.value === 'string' ) {
11357 this.program.indentExclusionElements.push( this );
11358 }
11359 };
11360
11361 Literal.prototype.transpile = function transpile ( code, transforms ) {
11362 if ( transforms.numericLiteral ) {
11363 var leading = this.raw.slice( 0, 2 );
11364 if ( leading === '0b' || leading === '0o' ) {
11365 code.overwrite( this.start, this.end, String( this.value ), {
11366 storeName: true,
11367 contentOnly: true
11368 });
11369 }
11370 }
11371
11372 if ( this.regex ) {
11373 var ref = this.regex;
11374 var pattern = ref.pattern;
11375 var flags = ref.flags;
11376
11377 if ( transforms.stickyRegExp && /y/.test( flags ) ) throw new CompileError$1( 'Regular expression sticky flag is not supported', this );
11378 if ( transforms.unicodeRegExp && /u/.test( flags ) ) {
11379 code.overwrite( this.start, this.end, ("/" + (rewritePattern_1( pattern, flags )) + "/" + (flags.replace( 'u', '' ))), {
11380 contentOnly: true
11381 });
11382 }
11383 }
11384 };
11385
11386 return Literal;
11387}(Node$1));
11388
11389var MemberExpression = (function (Node) {
11390 function MemberExpression () {
11391 Node.apply(this, arguments);
11392 }
11393
11394 if ( Node ) MemberExpression.__proto__ = Node;
11395 MemberExpression.prototype = Object.create( Node && Node.prototype );
11396 MemberExpression.prototype.constructor = MemberExpression;
11397
11398 MemberExpression.prototype.transpile = function transpile ( code, transforms ) {
11399 if ( transforms.reservedProperties && reserved[ this.property.name ] ) {
11400 code.overwrite( this.object.end, this.property.start, "['" );
11401 code.appendLeft( this.property.end, "']" );
11402 }
11403
11404 Node.prototype.transpile.call( this, code, transforms );
11405 };
11406
11407 return MemberExpression;
11408}(Node$1));
11409
11410var NewExpression = (function (Node) {
11411 function NewExpression () {
11412 Node.apply(this, arguments);
11413 }
11414
11415 if ( Node ) NewExpression.__proto__ = Node;
11416 NewExpression.prototype = Object.create( Node && Node.prototype );
11417 NewExpression.prototype.constructor = NewExpression;
11418
11419 NewExpression.prototype.initialise = function initialise ( transforms ) {
11420 var this$1 = this;
11421
11422 if ( transforms.spreadRest && this.arguments.length ) {
11423 var lexicalBoundary = this.findLexicalBoundary();
11424
11425 var i = this.arguments.length;
11426 while ( i-- ) {
11427 var arg = this$1.arguments[i];
11428 if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
11429 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
11430 break;
11431 }
11432 }
11433 }
11434
11435 Node.prototype.initialise.call( this, transforms );
11436 };
11437
11438 NewExpression.prototype.transpile = function transpile ( code, transforms ) {
11439 if ( transforms.spreadRest && this.arguments.length ) {
11440 var firstArgument = this.arguments[0];
11441 var isNew = true;
11442 var hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias, isNew );
11443
11444 if ( hasSpreadElements ) {
11445 code.prependRight( this.start + 'new'.length, ' (Function.prototype.bind.apply(' );
11446 code.overwrite( this.callee.end, firstArgument.start, ', [ null ].concat( ' );
11447 code.appendLeft( this.end, ' ))' );
11448 }
11449 }
11450
11451 Node.prototype.transpile.call( this, code, transforms );
11452 };
11453
11454 return NewExpression;
11455}(Node$1));
11456
11457var ObjectExpression = (function (Node) {
11458 function ObjectExpression () {
11459 Node.apply(this, arguments);
11460 }
11461
11462 if ( Node ) ObjectExpression.__proto__ = Node;
11463 ObjectExpression.prototype = Object.create( Node && Node.prototype );
11464 ObjectExpression.prototype.constructor = ObjectExpression;
11465
11466 ObjectExpression.prototype.transpile = function transpile ( code, transforms ) {
11467 var this$1 = this;
11468
11469 Node.prototype.transpile.call( this, code, transforms );
11470
11471 var firstPropertyStart = this.start + 1;
11472 var regularPropertyCount = 0;
11473 var spreadPropertyCount = 0;
11474 var computedPropertyCount = 0;
11475
11476 for ( var i$2 = 0, list = this.properties; i$2 < list.length; i$2 += 1 ) {
11477 var prop = list[i$2];
11478
11479 if ( prop.type === 'SpreadElement' ) {
11480 spreadPropertyCount += 1;
11481 } else if ( prop.computed ) {
11482 computedPropertyCount += 1;
11483 } else if ( prop.type === 'Property' ) {
11484 regularPropertyCount += 1;
11485 }
11486 }
11487
11488 if ( spreadPropertyCount ) {
11489 if ( !this.program.options.objectAssign ) {
11490 throw new CompileError$1( 'Object spread operator requires specified objectAssign option with \'Object.assign\' or polyfill helper.', this );
11491 }
11492 // enclose run of non-spread properties in curlies
11493 var i = this.properties.length;
11494 if ( regularPropertyCount ) {
11495 while ( i-- ) {
11496 var prop$1 = this$1.properties[i];
11497
11498 if ( prop$1.type === 'Property' && !prop$1.computed ) {
11499 var lastProp = this$1.properties[ i - 1 ];
11500 var nextProp = this$1.properties[ i + 1 ];
11501
11502 if ( !lastProp || lastProp.type !== 'Property' || lastProp.computed ) {
11503 code.prependRight( prop$1.start, '{' );
11504 }
11505
11506 if ( !nextProp || nextProp.type !== 'Property' || nextProp.computed ) {
11507 code.appendLeft( prop$1.end, '}' );
11508 }
11509 }
11510 }
11511 }
11512
11513 // wrap the whole thing in Object.assign
11514 firstPropertyStart = this.properties[0].start;
11515 code.overwrite( this.start, firstPropertyStart, ((this.program.options.objectAssign) + "({}, "));
11516 code.overwrite( this.properties[ this.properties.length - 1 ].end, this.end, ')' );
11517 }
11518
11519 if ( computedPropertyCount && transforms.computedProperty ) {
11520 var i0 = this.getIndentation();
11521
11522 var isSimpleAssignment;
11523 var name;
11524
11525 if ( this.parent.type === 'VariableDeclarator' && this.parent.parent.declarations.length === 1 ) {
11526 isSimpleAssignment = true;
11527 name = this.parent.id.alias || this.parent.id.name; // TODO is this right?
11528 } else if ( this.parent.type === 'AssignmentExpression' && this.parent.parent.type === 'ExpressionStatement' && this.parent.left.type === 'Identifier' ) {
11529 isSimpleAssignment = true;
11530 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
11531 } else if ( this.parent.type === 'AssignmentPattern' && this.parent.left.type === 'Identifier' ) {
11532 isSimpleAssignment = true;
11533 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
11534 }
11535
11536 // handle block scoping
11537 var declaration = this.findScope( false ).findDeclaration( name );
11538 if ( declaration ) name = declaration.name;
11539
11540 var start = firstPropertyStart;
11541 var end = this.end;
11542
11543 if ( isSimpleAssignment ) {
11544 // ???
11545 } else {
11546 name = this.findScope( true ).createIdentifier( 'obj' );
11547
11548 var statement = this.findNearest( /(?:Statement|Declaration)$/ );
11549 code.appendLeft( statement.end, ("\n" + i0 + "var " + name + ";") );
11550
11551 code.prependRight( this.start, ("( " + name + " = ") );
11552 }
11553
11554 var len = this.properties.length;
11555 var lastComputedProp;
11556 var sawNonComputedProperty = false;
11557
11558 for ( var i$1 = 0; i$1 < len; i$1 += 1 ) {
11559 var prop$2 = this$1.properties[i$1];
11560
11561 if ( prop$2.computed ) {
11562 lastComputedProp = prop$2;
11563 var moveStart = i$1 > 0 ? this$1.properties[ i$1 - 1 ].end : start;
11564
11565 var propId = isSimpleAssignment ? (";\n" + i0 + name) : (", " + name);
11566
11567 if (moveStart < prop$2.start) {
11568 code.overwrite( moveStart, prop$2.start, propId );
11569 } else {
11570 code.prependRight( prop$2.start, propId );
11571 }
11572
11573 var c = prop$2.key.end;
11574 while ( code.original[c] !== ']' ) c += 1;
11575 c += 1;
11576
11577 if ( prop$2.value.start > c ) code.remove( c, prop$2.value.start );
11578 code.appendLeft( c, ' = ' );
11579 code.move( moveStart, prop$2.end, end );
11580
11581 if ( i$1 < len - 1 && ! sawNonComputedProperty ) {
11582 // remove trailing comma
11583 c = prop$2.end;
11584 while ( code.original[c] !== ',' ) c += 1;
11585
11586 code.remove( prop$2.end, c + 1 );
11587 }
11588
11589 if ( prop$2.method && transforms.conciseMethodProperty ) {
11590 code.prependRight( prop$2.value.start, 'function ' );
11591 }
11592 } else {
11593 sawNonComputedProperty = true;
11594 }
11595 }
11596
11597 // special case
11598 if ( computedPropertyCount === len ) {
11599 code.remove( this.properties[ len - 1 ].end, this.end - 1 );
11600 }
11601
11602 if ( !isSimpleAssignment ) {
11603 code.appendLeft( lastComputedProp.end, (", " + name + " )") );
11604 }
11605 }
11606 };
11607
11608 return ObjectExpression;
11609}(Node$1));
11610
11611var Property = (function (Node) {
11612 function Property () {
11613 Node.apply(this, arguments);
11614 }
11615
11616 if ( Node ) Property.__proto__ = Node;
11617 Property.prototype = Object.create( Node && Node.prototype );
11618 Property.prototype.constructor = Property;
11619
11620 Property.prototype.transpile = function transpile ( code, transforms ) {
11621 Node.prototype.transpile.call( this, code, transforms );
11622
11623 if ( transforms.conciseMethodProperty && !this.computed && this.parent.type !== 'ObjectPattern' ) {
11624 if ( this.shorthand ) {
11625 code.prependRight( this.start, ((this.key.name) + ": ") );
11626 } else if ( this.method ) {
11627 var name = '';
11628 if ( this.program.options.namedFunctionExpressions !== false ) {
11629 if ( this.key.type === 'Literal' && typeof this.key.value === 'number' ) {
11630 name = "";
11631 } else if ( this.key.type === 'Identifier' ) {
11632 if ( reserved[ this.key.name ] ||
11633 ! /^[a-z_$][a-z0-9_$]*$/i.test( this.key.name ) ||
11634 this.value.body.scope.references[this.key.name] ) {
11635 name = this.findScope( true ).createIdentifier( this.key.name );
11636 } else {
11637 name = this.key.name;
11638 }
11639 } else {
11640 name = this.findScope( true ).createIdentifier( this.key.value );
11641 }
11642 name = ' ' + name;
11643 }
11644
11645 if ( this.value.generator ) code.remove( this.start, this.key.start );
11646 code.appendLeft( this.key.end, (": function" + (this.value.generator ? '*' : '') + name) );
11647 }
11648 }
11649
11650 if ( transforms.reservedProperties && reserved[ this.key.name ] ) {
11651 code.prependRight( this.key.start, "'" );
11652 code.appendLeft( this.key.end, "'" );
11653 }
11654 };
11655
11656 return Property;
11657}(Node$1));
11658
11659var ReturnStatement = (function (Node) {
11660 function ReturnStatement () {
11661 Node.apply(this, arguments);
11662 }
11663
11664 if ( Node ) ReturnStatement.__proto__ = Node;
11665 ReturnStatement.prototype = Object.create( Node && Node.prototype );
11666 ReturnStatement.prototype.constructor = ReturnStatement;
11667
11668 ReturnStatement.prototype.initialise = function initialise ( transforms ) {
11669 this.loop = this.findNearest( loopStatement );
11670 this.nearestFunction = this.findNearest( /Function/ );
11671
11672 if ( this.loop && ( !this.nearestFunction || this.loop.depth > this.nearestFunction.depth ) ) {
11673 this.loop.canReturn = true;
11674 this.shouldWrap = true;
11675 }
11676
11677 if ( this.argument ) this.argument.initialise( transforms );
11678 };
11679
11680 ReturnStatement.prototype.transpile = function transpile ( code, transforms ) {
11681 var shouldWrap = this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;
11682
11683 if ( this.argument ) {
11684 if ( shouldWrap ) code.prependRight( this.argument.start, "{ v: " );
11685 this.argument.transpile( code, transforms );
11686 if ( shouldWrap ) code.appendLeft( this.argument.end, " }" );
11687 } else if ( shouldWrap ) {
11688 code.appendLeft( this.start + 6, ' {}' );
11689 }
11690 };
11691
11692 return ReturnStatement;
11693}(Node$1));
11694
11695var SpreadElement = (function (Node) {
11696 function SpreadElement () {
11697 Node.apply(this, arguments);
11698 }
11699
11700 if ( Node ) SpreadElement.__proto__ = Node;
11701 SpreadElement.prototype = Object.create( Node && Node.prototype );
11702 SpreadElement.prototype.constructor = SpreadElement;
11703
11704 SpreadElement.prototype.transpile = function transpile ( code, transforms ) {
11705 if (this.parent.type == "ObjectExpression") {
11706 code.remove( this.start, this.argument.start );
11707 code.remove( this.argument.end, this.end );
11708 }
11709
11710 Node.prototype.transpile.call( this, code, transforms );
11711 };
11712
11713 return SpreadElement;
11714}(Node$1));
11715
11716var Super = (function (Node) {
11717 function Super () {
11718 Node.apply(this, arguments);
11719 }
11720
11721 if ( Node ) Super.__proto__ = Node;
11722 Super.prototype = Object.create( Node && Node.prototype );
11723 Super.prototype.constructor = Super;
11724
11725 Super.prototype.initialise = function initialise ( transforms ) {
11726 if ( transforms.classes ) {
11727 this.method = this.findNearest( 'MethodDefinition' );
11728 if ( !this.method ) throw new CompileError$1( this, 'use of super outside class method' );
11729
11730 var parentClass = this.findNearest( 'ClassBody' ).parent;
11731 this.superClassName = parentClass.superClass && (parentClass.superClass.name || 'superclass');
11732
11733 if ( !this.superClassName ) throw new CompileError$1( 'super used in base class', this );
11734
11735 this.isCalled = this.parent.type === 'CallExpression' && this === this.parent.callee;
11736
11737 if ( this.method.kind !== 'constructor' && this.isCalled ) {
11738 throw new CompileError$1( 'super() not allowed outside class constructor', this );
11739 }
11740
11741 this.isMember = this.parent.type === 'MemberExpression';
11742
11743 if ( !this.isCalled && !this.isMember ) {
11744 throw new CompileError$1( 'Unexpected use of `super` (expected `super(...)` or `super.*`)', this );
11745 }
11746 }
11747
11748 if ( transforms.arrow ) {
11749 var lexicalBoundary = this.findLexicalBoundary();
11750 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
11751 var loop = this.findNearest( loopStatement );
11752
11753 if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
11754 this.thisAlias = lexicalBoundary.getThisAlias();
11755 }
11756
11757 if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
11758 this.thisAlias = lexicalBoundary.getThisAlias();
11759 }
11760 }
11761 };
11762
11763 Super.prototype.transpile = function transpile ( code, transforms ) {
11764 if ( transforms.classes ) {
11765 var expression = ( this.isCalled || this.method.static ) ?
11766 this.superClassName :
11767 ((this.superClassName) + ".prototype");
11768
11769 code.overwrite( this.start, this.end, expression, { storeName: true, contentOnly: true });
11770
11771 var callExpression = this.isCalled ? this.parent : this.parent.parent;
11772
11773 if ( callExpression && callExpression.type === 'CallExpression' ) {
11774 if ( !this.noCall ) { // special case – `super( ...args )`
11775 code.appendLeft( callExpression.callee.end, '.call' );
11776 }
11777
11778 var thisAlias = this.thisAlias || 'this';
11779
11780 if ( callExpression.arguments.length ) {
11781 code.appendLeft( callExpression.arguments[0].start, (thisAlias + ", ") );
11782 } else {
11783 code.appendLeft( callExpression.end - 1, ("" + thisAlias) );
11784 }
11785 }
11786 }
11787 };
11788
11789 return Super;
11790}(Node$1));
11791
11792var TaggedTemplateExpression = (function (Node) {
11793 function TaggedTemplateExpression () {
11794 Node.apply(this, arguments);
11795 }
11796
11797 if ( Node ) TaggedTemplateExpression.__proto__ = Node;
11798 TaggedTemplateExpression.prototype = Object.create( Node && Node.prototype );
11799 TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
11800
11801 TaggedTemplateExpression.prototype.initialise = function initialise ( transforms ) {
11802 if ( transforms.templateString && !transforms.dangerousTaggedTemplateString ) {
11803 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 );
11804 }
11805
11806 Node.prototype.initialise.call( this, transforms );
11807 };
11808
11809 TaggedTemplateExpression.prototype.transpile = function transpile ( code, transforms ) {
11810 if ( transforms.templateString && transforms.dangerousTaggedTemplateString ) {
11811 var ordered = this.quasi.expressions.concat( this.quasi.quasis ).sort( function ( a, b ) { return a.start - b.start; } );
11812
11813 // insert strings at start
11814 var templateStrings = this.quasi.quasis.map( function ( quasi ) { return JSON.stringify( quasi.value.cooked ); } );
11815 code.overwrite( this.tag.end, ordered[0].start, ("([" + (templateStrings.join(', ')) + "]") );
11816
11817 var lastIndex = ordered[0].start;
11818 ordered.forEach( function ( node ) {
11819 if ( node.type === 'TemplateElement' ) {
11820 code.remove( lastIndex, node.end );
11821 } else {
11822 code.overwrite( lastIndex, node.start, ', ' );
11823 }
11824
11825 lastIndex = node.end;
11826 });
11827
11828 code.overwrite( lastIndex, this.end, ')' );
11829 }
11830
11831 Node.prototype.transpile.call( this, code, transforms );
11832 };
11833
11834 return TaggedTemplateExpression;
11835}(Node$1));
11836
11837var TemplateElement = (function (Node) {
11838 function TemplateElement () {
11839 Node.apply(this, arguments);
11840 }
11841
11842 if ( Node ) TemplateElement.__proto__ = Node;
11843 TemplateElement.prototype = Object.create( Node && Node.prototype );
11844 TemplateElement.prototype.constructor = TemplateElement;
11845
11846 TemplateElement.prototype.initialise = function initialise () {
11847 this.program.indentExclusionElements.push( this );
11848 };
11849
11850 return TemplateElement;
11851}(Node$1));
11852
11853var TemplateLiteral = (function (Node) {
11854 function TemplateLiteral () {
11855 Node.apply(this, arguments);
11856 }
11857
11858 if ( Node ) TemplateLiteral.__proto__ = Node;
11859 TemplateLiteral.prototype = Object.create( Node && Node.prototype );
11860 TemplateLiteral.prototype.constructor = TemplateLiteral;
11861
11862 TemplateLiteral.prototype.transpile = function transpile ( code, transforms ) {
11863 if ( transforms.templateString && this.parent.type !== 'TaggedTemplateExpression' ) {
11864 var ordered = this.expressions.concat( this.quasis )
11865 .sort( function ( a, b ) { return a.start - b.start || a.end - b.end; } )
11866 .filter( function ( node, i ) {
11867 // include all expressions
11868 if ( node.type !== 'TemplateElement' ) return true;
11869
11870 // include all non-empty strings
11871 if ( node.value.raw ) return true;
11872
11873 // exclude all empty strings not at the head
11874 return !i;
11875 });
11876
11877 // special case – we may be able to skip the first element,
11878 // if it's the empty string, but only if the second and
11879 // third elements aren't both expressions (since they maybe
11880 // be numeric, and `1 + 2 + '3' === '33'`)
11881 if ( ordered.length >= 3 ) {
11882 var first = ordered[0];
11883 var third = ordered[2];
11884 if ( first.type === 'TemplateElement' && first.value.raw === '' && third.type === 'TemplateElement' ) {
11885 ordered.shift();
11886 }
11887 }
11888
11889 var parenthesise = ( this.quasis.length !== 1 || this.expressions.length !== 0 ) &&
11890 this.parent.type !== 'AssignmentExpression' &&
11891 this.parent.type !== 'AssignmentPattern' &&
11892 this.parent.type !== 'VariableDeclarator' &&
11893 ( this.parent.type !== 'BinaryExpression' || this.parent.operator !== '+' );
11894
11895 if ( parenthesise ) code.appendRight( this.start, '(' );
11896
11897 var lastIndex = this.start;
11898
11899 ordered.forEach( function ( node, i ) {
11900 var prefix = i === 0 ?
11901 parenthesise ? '(' : '' :
11902 ' + ';
11903
11904 if ( node.type === 'TemplateElement' ) {
11905 code.overwrite( lastIndex, node.end, prefix + JSON.stringify( node.value.cooked ) );
11906 } else {
11907 var parenthesise$1 = node.type !== 'Identifier'; // TODO other cases where it's safe
11908
11909 if ( parenthesise$1 ) prefix += '(';
11910
11911 code.remove( lastIndex, node.start );
11912
11913 if ( prefix ) code.prependRight( node.start, prefix );
11914 if ( parenthesise$1 ) code.appendLeft( node.end, ')' );
11915 }
11916
11917 lastIndex = node.end;
11918 });
11919
11920 if ( parenthesise ) code.appendLeft( lastIndex, ')' );
11921 code.remove( lastIndex, this.end );
11922 }
11923
11924 Node.prototype.transpile.call( this, code, transforms );
11925 };
11926
11927 return TemplateLiteral;
11928}(Node$1));
11929
11930var ThisExpression = (function (Node) {
11931 function ThisExpression () {
11932 Node.apply(this, arguments);
11933 }
11934
11935 if ( Node ) ThisExpression.__proto__ = Node;
11936 ThisExpression.prototype = Object.create( Node && Node.prototype );
11937 ThisExpression.prototype.constructor = ThisExpression;
11938
11939 ThisExpression.prototype.initialise = function initialise ( transforms ) {
11940 if ( transforms.arrow ) {
11941 var lexicalBoundary = this.findLexicalBoundary();
11942 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
11943 var loop = this.findNearest( loopStatement );
11944
11945 if ( ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth )
11946 || ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth )
11947 || ( loop && loop.right && loop.right.contains( this ) ) ) {
11948 this.alias = lexicalBoundary.getThisAlias();
11949 }
11950 }
11951 };
11952
11953 ThisExpression.prototype.transpile = function transpile ( code ) {
11954 if ( this.alias ) {
11955 code.overwrite( this.start, this.end, this.alias, {
11956 storeName: true,
11957 contentOnly: true
11958 });
11959 }
11960 };
11961
11962 return ThisExpression;
11963}(Node$1));
11964
11965var UpdateExpression = (function (Node) {
11966 function UpdateExpression () {
11967 Node.apply(this, arguments);
11968 }
11969
11970 if ( Node ) UpdateExpression.__proto__ = Node;
11971 UpdateExpression.prototype = Object.create( Node && Node.prototype );
11972 UpdateExpression.prototype.constructor = UpdateExpression;
11973
11974 UpdateExpression.prototype.initialise = function initialise ( transforms ) {
11975 if ( this.argument.type === 'Identifier' ) {
11976 var declaration = this.findScope( false ).findDeclaration( this.argument.name );
11977 if ( declaration && declaration.kind === 'const' ) {
11978 throw new CompileError$1( ((this.argument.name) + " is read-only"), this );
11979 }
11980
11981 // special case – https://gitlab.com/Rich-Harris/buble/issues/150
11982 var statement = declaration && declaration.node.ancestor( 3 );
11983 if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
11984 statement.reassigned[ this.argument.name ] = true;
11985 }
11986 }
11987
11988 Node.prototype.initialise.call( this, transforms );
11989 };
11990
11991 return UpdateExpression;
11992}(Node$1));
11993
11994var VariableDeclaration = (function (Node) {
11995 function VariableDeclaration () {
11996 Node.apply(this, arguments);
11997 }
11998
11999 if ( Node ) VariableDeclaration.__proto__ = Node;
12000 VariableDeclaration.prototype = Object.create( Node && Node.prototype );
12001 VariableDeclaration.prototype.constructor = VariableDeclaration;
12002
12003 VariableDeclaration.prototype.initialise = function initialise ( transforms ) {
12004 this.scope = this.findScope( this.kind === 'var' );
12005 this.declarations.forEach( function ( declarator ) { return declarator.initialise( transforms ); } );
12006 };
12007
12008 VariableDeclaration.prototype.transpile = function transpile ( code, transforms ) {
12009 var this$1 = this;
12010
12011 var i0 = this.getIndentation();
12012 var kind = this.kind;
12013
12014 if ( transforms.letConst && kind !== 'var' ) {
12015 kind = 'var';
12016 code.overwrite( this.start, this.start + this.kind.length, kind, { storeName: true });
12017 }
12018
12019 if ( transforms.destructuring && this.parent.type !== 'ForOfStatement' ) {
12020 var c = this.start;
12021 var lastDeclaratorIsPattern;
12022
12023 this.declarations.forEach( function ( declarator, i ) {
12024 declarator.transpile( code, transforms );
12025
12026 if ( declarator.id.type === 'Identifier' ) {
12027 if ( i > 0 && this$1.declarations[ i - 1 ].id.type !== 'Identifier' ) {
12028 code.overwrite( c, declarator.id.start, "var " );
12029 }
12030 } else {
12031 var inline = loopStatement.test( this$1.parent.type );
12032
12033 if ( i === 0 ) {
12034 code.remove( c, declarator.id.start );
12035 } else {
12036 code.overwrite( c, declarator.id.start, (";\n" + i0) );
12037 }
12038
12039 var simple = declarator.init.type === 'Identifier' && !declarator.init.rewritten;
12040
12041 var name = simple ? declarator.init.name : declarator.findScope( true ).createIdentifier( 'ref' );
12042
12043 var statementGenerators = [];
12044
12045 if ( simple ) {
12046 code.remove( declarator.id.end, declarator.end );
12047 } else {
12048 statementGenerators.push( function ( start, prefix, suffix ) {
12049 code.prependRight( declarator.id.end, ("var " + name) );
12050 code.appendLeft( declarator.init.end, ("" + suffix) );
12051 code.move( declarator.id.end, declarator.end, start );
12052 });
12053 }
12054
12055 destructure( code, declarator.findScope( false ), declarator.id, name, inline, statementGenerators );
12056
12057 var prefix = inline ? 'var ' : '';
12058 var suffix = inline ? ", " : (";\n" + i0);
12059 statementGenerators.forEach( function ( fn, j ) {
12060 if ( i === this$1.declarations.length - 1 && j === statementGenerators.length - 1 ) {
12061 suffix = inline ? '' : ';';
12062 }
12063
12064 fn( declarator.start, j === 0 ? prefix : '', suffix );
12065 });
12066 }
12067
12068 c = declarator.end;
12069 lastDeclaratorIsPattern = declarator.id.type !== 'Identifier';
12070 });
12071
12072 if ( lastDeclaratorIsPattern && this.end > c ) {
12073 code.overwrite( c, this.end, '', { contentOnly: true });
12074 }
12075 }
12076
12077 else {
12078 this.declarations.forEach( function ( declarator ) {
12079 declarator.transpile( code, transforms );
12080 });
12081 }
12082 };
12083
12084 return VariableDeclaration;
12085}(Node$1));
12086
12087var VariableDeclarator = (function (Node) {
12088 function VariableDeclarator () {
12089 Node.apply(this, arguments);
12090 }
12091
12092 if ( Node ) VariableDeclarator.__proto__ = Node;
12093 VariableDeclarator.prototype = Object.create( Node && Node.prototype );
12094 VariableDeclarator.prototype.constructor = VariableDeclarator;
12095
12096 VariableDeclarator.prototype.initialise = function initialise ( transforms ) {
12097 var kind = this.parent.kind;
12098 if ( kind === 'let' && this.parent.parent.type === 'ForStatement' ) {
12099 kind = 'for.let'; // special case...
12100 }
12101
12102 this.parent.scope.addDeclaration( this.id, kind );
12103 Node.prototype.initialise.call( this, transforms );
12104 };
12105
12106 VariableDeclarator.prototype.transpile = function transpile ( code, transforms ) {
12107 if ( !this.init && transforms.letConst && this.parent.kind !== 'var' ) {
12108 var inLoop = this.findNearest( /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/ );
12109 if ( inLoop && ! /Function/.test( inLoop.type ) && ! this.isLeftDeclaratorOfLoop() ) {
12110 code.appendLeft( this.id.end, ' = (void 0)' );
12111 }
12112 }
12113
12114 if ( this.id ) this.id.transpile( code, transforms );
12115 if ( this.init ) this.init.transpile( code, transforms );
12116 };
12117
12118 VariableDeclarator.prototype.isLeftDeclaratorOfLoop = function isLeftDeclaratorOfLoop () {
12119 return this.parent
12120 && this.parent.type === 'VariableDeclaration'
12121 && this.parent.parent
12122 && (this.parent.parent.type === 'ForInStatement'
12123 || this.parent.parent.type === 'ForOfStatement')
12124 && this.parent.parent.left
12125 && this.parent.parent.left.declarations[0] === this;
12126 };
12127
12128 return VariableDeclarator;
12129}(Node$1));
12130
12131var types$1$1 = {
12132 ArrayExpression: ArrayExpression,
12133 ArrowFunctionExpression: ArrowFunctionExpression,
12134 AssignmentExpression: AssignmentExpression,
12135 BinaryExpression: BinaryExpression,
12136 BreakStatement: BreakStatement,
12137 CallExpression: CallExpression,
12138 ClassBody: ClassBody,
12139 ClassDeclaration: ClassDeclaration,
12140 ClassExpression: ClassExpression,
12141 ContinueStatement: ContinueStatement,
12142 DoWhileStatement: LoopStatement,
12143 ExportNamedDeclaration: ExportNamedDeclaration,
12144 ExportDefaultDeclaration: ExportDefaultDeclaration,
12145 ForStatement: ForStatement,
12146 ForInStatement: ForInStatement,
12147 ForOfStatement: ForOfStatement,
12148 FunctionDeclaration: FunctionDeclaration,
12149 FunctionExpression: FunctionExpression,
12150 Identifier: Identifier,
12151 IfStatement: IfStatement,
12152 ImportDeclaration: ImportDeclaration,
12153 ImportDefaultSpecifier: ImportDefaultSpecifier,
12154 ImportSpecifier: ImportSpecifier,
12155 JSXAttribute: JSXAttribute,
12156 JSXClosingElement: JSXClosingElement,
12157 JSXElement: JSXElement,
12158 JSXExpressionContainer: JSXExpressionContainer,
12159 JSXOpeningElement: JSXOpeningElement,
12160 JSXSpreadAttribute: JSXSpreadAttribute,
12161 Literal: Literal,
12162 MemberExpression: MemberExpression,
12163 NewExpression: NewExpression,
12164 ObjectExpression: ObjectExpression,
12165 Property: Property,
12166 ReturnStatement: ReturnStatement,
12167 SpreadElement: SpreadElement,
12168 Super: Super,
12169 TaggedTemplateExpression: TaggedTemplateExpression,
12170 TemplateElement: TemplateElement,
12171 TemplateLiteral: TemplateLiteral,
12172 ThisExpression: ThisExpression,
12173 UpdateExpression: UpdateExpression,
12174 VariableDeclaration: VariableDeclaration,
12175 VariableDeclarator: VariableDeclarator,
12176 WhileStatement: LoopStatement
12177};
12178
12179var statementsWithBlocks = {
12180 IfStatement: 'consequent',
12181 ForStatement: 'body',
12182 ForInStatement: 'body',
12183 ForOfStatement: 'body',
12184 WhileStatement: 'body',
12185 DoWhileStatement: 'body',
12186 ArrowFunctionExpression: 'body'
12187};
12188
12189function wrap ( raw, parent ) {
12190 if ( !raw ) return;
12191
12192 if ( 'length' in raw ) {
12193 var i = raw.length;
12194 while ( i-- ) wrap( raw[i], parent );
12195 return;
12196 }
12197
12198 // with e.g. shorthand properties, key and value are
12199 // the same node. We don't want to wrap an object twice
12200 if ( raw.__wrapped ) return;
12201 raw.__wrapped = true;
12202
12203 if ( !keys[ raw.type ] ) {
12204 keys[ raw.type ] = Object.keys( raw ).filter( function ( key ) { return typeof raw[ key ] === 'object'; } );
12205 }
12206
12207 // special case – body-less if/for/while statements. TODO others?
12208 var bodyType = statementsWithBlocks[ raw.type ];
12209 if ( bodyType && raw[ bodyType ].type !== 'BlockStatement' ) {
12210 var expression = raw[ bodyType ];
12211
12212 // create a synthetic block statement, otherwise all hell
12213 // breaks loose when it comes to block scoping
12214 raw[ bodyType ] = {
12215 start: expression.start,
12216 end: expression.end,
12217 type: 'BlockStatement',
12218 body: [ expression ],
12219 synthetic: true
12220 };
12221 }
12222
12223 new Node$1( raw, parent );
12224
12225 var type = ( raw.type === 'BlockStatement' ? BlockStatement : types$1$1[ raw.type ] ) || Node$1;
12226 raw.__proto__ = type.prototype;
12227}
12228
12229function Scope ( options ) {
12230 options = options || {};
12231
12232 this.parent = options.parent;
12233 this.isBlockScope = !!options.block;
12234
12235 var scope = this;
12236 while ( scope.isBlockScope ) scope = scope.parent;
12237 this.functionScope = scope;
12238
12239 this.identifiers = [];
12240 this.declarations = Object.create( null );
12241 this.references = Object.create( null );
12242 this.blockScopedDeclarations = this.isBlockScope ? null : Object.create( null );
12243 this.aliases = this.isBlockScope ? null : Object.create( null );
12244}
12245
12246Scope.prototype = {
12247 addDeclaration: function addDeclaration ( node, kind ) {
12248 for ( var i = 0, list = extractNames( node ); i < list.length; i += 1 ) {
12249 var identifier = list[i];
12250
12251 var name = identifier.name;
12252
12253 var declaration = { name: name, node: identifier, kind: kind, instances: [] };
12254 this.declarations[ name ] = declaration;
12255
12256 if ( this.isBlockScope ) {
12257 if ( !this.functionScope.blockScopedDeclarations[ name ] ) this.functionScope.blockScopedDeclarations[ name ] = [];
12258 this.functionScope.blockScopedDeclarations[ name ].push( declaration );
12259 }
12260 }
12261 },
12262
12263 addReference: function addReference ( identifier ) {
12264 if ( this.consolidated ) {
12265 this.consolidateReference( identifier );
12266 } else {
12267 this.identifiers.push( identifier );
12268 }
12269 },
12270
12271 consolidate: function consolidate () {
12272 var this$1 = this;
12273
12274 for ( var i = 0; i < this$1.identifiers.length; i += 1 ) { // we might push to the array during consolidation, so don't cache length
12275 var identifier = this$1.identifiers[i];
12276 this$1.consolidateReference( identifier );
12277 }
12278
12279 this.consolidated = true; // TODO understand why this is necessary... seems bad
12280 },
12281
12282 consolidateReference: function consolidateReference ( identifier ) {
12283 var declaration = this.declarations[ identifier.name ];
12284 if ( declaration ) {
12285 declaration.instances.push( identifier );
12286 } else {
12287 this.references[ identifier.name ] = true;
12288 if ( this.parent ) this.parent.addReference( identifier );
12289 }
12290 },
12291
12292 contains: function contains ( name ) {
12293 return this.declarations[ name ] ||
12294 ( this.parent ? this.parent.contains( name ) : false );
12295 },
12296
12297 createIdentifier: function createIdentifier ( base ) {
12298 var this$1 = this;
12299
12300 if ( typeof base === 'number' ) base = base.toString();
12301
12302 base = base
12303 .replace( /\s/g, '' )
12304 .replace( /\[([^\]]+)\]/g, '_$1' )
12305 .replace( /[^a-zA-Z0-9_$]/g, '_' )
12306 .replace( /_{2,}/, '_' );
12307
12308 var name = base;
12309 var counter = 1;
12310
12311 while ( this$1.declarations[ name ] || this$1.references[ name ] || this$1.aliases[ name ] || name in reserved ) {
12312 name = base + "$" + (counter++);
12313 }
12314
12315 this.aliases[ name ] = true;
12316 return name;
12317 },
12318
12319 findDeclaration: function findDeclaration ( name ) {
12320 return this.declarations[ name ] ||
12321 ( this.parent && this.parent.findDeclaration( name ) );
12322 }
12323};
12324
12325function isUseStrict ( node ) {
12326 if ( !node ) return false;
12327 if ( node.type !== 'ExpressionStatement' ) return false;
12328 if ( node.expression.type !== 'Literal' ) return false;
12329 return node.expression.value === 'use strict';
12330}
12331
12332var BlockStatement = (function (Node) {
12333 function BlockStatement () {
12334 Node.apply(this, arguments);
12335 }
12336
12337 if ( Node ) BlockStatement.__proto__ = Node;
12338 BlockStatement.prototype = Object.create( Node && Node.prototype );
12339 BlockStatement.prototype.constructor = BlockStatement;
12340
12341 BlockStatement.prototype.createScope = function createScope () {
12342 var this$1 = this;
12343
12344 this.parentIsFunction = /Function/.test( this.parent.type );
12345 this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root';
12346 this.scope = new Scope({
12347 block: !this.isFunctionBlock,
12348 parent: this.parent.findScope( false )
12349 });
12350
12351 if ( this.parentIsFunction ) {
12352 this.parent.params.forEach( function ( node ) {
12353 this$1.scope.addDeclaration( node, 'param' );
12354 });
12355 }
12356 };
12357
12358 BlockStatement.prototype.initialise = function initialise ( transforms ) {
12359 this.thisAlias = null;
12360 this.argumentsAlias = null;
12361 this.defaultParameters = [];
12362
12363 // normally the scope gets created here, during initialisation,
12364 // but in some cases (e.g. `for` statements), we need to create
12365 // the scope early, as it pertains to both the init block and
12366 // the body of the statement
12367 if ( !this.scope ) this.createScope();
12368
12369 this.body.forEach( function ( node ) { return node.initialise( transforms ); } );
12370
12371 this.scope.consolidate();
12372 };
12373
12374 BlockStatement.prototype.findLexicalBoundary = function findLexicalBoundary () {
12375 if ( this.type === 'Program' ) return this;
12376 if ( /^Function/.test( this.parent.type ) ) return this;
12377
12378 return this.parent.findLexicalBoundary();
12379 };
12380
12381 BlockStatement.prototype.findScope = function findScope ( functionScope ) {
12382 if ( functionScope && !this.isFunctionBlock ) return this.parent.findScope( functionScope );
12383 return this.scope;
12384 };
12385
12386 BlockStatement.prototype.getArgumentsAlias = function getArgumentsAlias () {
12387 if ( !this.argumentsAlias ) {
12388 this.argumentsAlias = this.scope.createIdentifier( 'arguments' );
12389 }
12390
12391 return this.argumentsAlias;
12392 };
12393
12394 BlockStatement.prototype.getArgumentsArrayAlias = function getArgumentsArrayAlias () {
12395 if ( !this.argumentsArrayAlias ) {
12396 this.argumentsArrayAlias = this.scope.createIdentifier( 'argsArray' );
12397 }
12398
12399 return this.argumentsArrayAlias;
12400 };
12401
12402 BlockStatement.prototype.getThisAlias = function getThisAlias () {
12403 if ( !this.thisAlias ) {
12404 this.thisAlias = this.scope.createIdentifier( 'this' );
12405 }
12406
12407 return this.thisAlias;
12408 };
12409
12410 BlockStatement.prototype.getIndentation = function getIndentation () {
12411 var this$1 = this;
12412
12413 if ( this.indentation === undefined ) {
12414 var source = this.program.magicString.original;
12415
12416 var useOuter = this.synthetic || !this.body.length;
12417 var c = useOuter ? this.start : this.body[0].start;
12418
12419 while ( c && source[c] !== '\n' ) c -= 1;
12420
12421 this.indentation = '';
12422
12423 while ( true ) { // eslint-disable-line no-constant-condition
12424 c += 1;
12425 var char = source[c];
12426
12427 if ( char !== ' ' && char !== '\t' ) break;
12428
12429 this$1.indentation += char;
12430 }
12431
12432 var indentString = this.program.magicString.getIndentString();
12433
12434 // account for dedented class constructors
12435 var parent = this.parent;
12436 while ( parent ) {
12437 if ( parent.kind === 'constructor' && !parent.parent.parent.superClass ) {
12438 this$1.indentation = this$1.indentation.replace( indentString, '' );
12439 }
12440
12441 parent = parent.parent;
12442 }
12443
12444 if ( useOuter ) this.indentation += indentString;
12445 }
12446
12447 return this.indentation;
12448 };
12449
12450 BlockStatement.prototype.transpile = function transpile ( code, transforms ) {
12451 var this$1 = this;
12452
12453 var indentation = this.getIndentation();
12454
12455 var introStatementGenerators = [];
12456
12457 if ( this.argumentsAlias ) {
12458 introStatementGenerators.push( function ( start, prefix, suffix ) {
12459 var assignment = prefix + "var " + (this$1.argumentsAlias) + " = arguments" + suffix;
12460 code.appendLeft( start, assignment );
12461 });
12462 }
12463
12464 if ( this.thisAlias ) {
12465 introStatementGenerators.push( function ( start, prefix, suffix ) {
12466 var assignment = prefix + "var " + (this$1.thisAlias) + " = this" + suffix;
12467 code.appendLeft( start, assignment );
12468 });
12469 }
12470
12471 if ( this.argumentsArrayAlias ) {
12472 introStatementGenerators.push( function ( start, prefix, suffix ) {
12473 var i = this$1.scope.createIdentifier( 'i' );
12474 var assignment = prefix + "var " + i + " = arguments.length, " + (this$1.argumentsArrayAlias) + " = Array(" + i + ");\n" + indentation + "while ( " + i + "-- ) " + (this$1.argumentsArrayAlias) + "[" + i + "] = arguments[" + i + "]" + suffix;
12475 code.appendLeft( start, assignment );
12476 });
12477 }
12478
12479 if ( /Function/.test( this.parent.type ) ) {
12480 this.transpileParameters( code, transforms, indentation, introStatementGenerators );
12481 }
12482
12483 if ( transforms.letConst && this.isFunctionBlock ) {
12484 this.transpileBlockScopedIdentifiers( code );
12485 }
12486
12487 Node.prototype.transpile.call( this, code, transforms );
12488
12489 if ( this.synthetic ) {
12490 if ( this.parent.type === 'ArrowFunctionExpression' ) {
12491 var expr = this.body[0];
12492
12493 if ( introStatementGenerators.length ) {
12494 code.appendLeft( this.start, "{" ).prependRight( this.end, ((this.parent.getIndentation()) + "}") );
12495
12496 code.prependRight( expr.start, ("\n" + indentation + "return ") );
12497 code.appendLeft( expr.end, ";\n" );
12498 } else if ( transforms.arrow ) {
12499 code.prependRight( expr.start, "{ return " );
12500 code.appendLeft( expr.end, "; }" );
12501 }
12502 }
12503
12504 else if ( introStatementGenerators.length ) {
12505 code.prependRight( this.start, "{" ).appendLeft( this.end, "}" );
12506 }
12507 }
12508
12509 var start;
12510 if ( isUseStrict( this.body[0] ) ) {
12511 start = this.body[0].end;
12512 } else if ( this.synthetic || this.parent.type === 'Root' ) {
12513 start = this.start;
12514 } else {
12515 start = this.start + 1;
12516 }
12517
12518 var prefix = "\n" + indentation;
12519 var suffix = ';';
12520 introStatementGenerators.forEach( function ( fn, i ) {
12521 if ( i === introStatementGenerators.length - 1 ) suffix = ";\n";
12522 fn( start, prefix, suffix );
12523 });
12524 };
12525
12526 BlockStatement.prototype.transpileParameters = function transpileParameters ( code, transforms, indentation, introStatementGenerators ) {
12527 var this$1 = this;
12528
12529 var params = this.parent.params;
12530
12531 params.forEach( function ( param ) {
12532 if ( param.type === 'AssignmentPattern' && param.left.type === 'Identifier' ) {
12533 if ( transforms.defaultParameter ) {
12534 introStatementGenerators.push( function ( start, prefix, suffix ) {
12535 var lhs = prefix + "if ( " + (param.left.name) + " === void 0 ) " + (param.left.name);
12536
12537 code
12538 .prependRight( param.left.end, lhs )
12539 .move( param.left.end, param.right.end, start )
12540 .appendLeft( param.right.end, suffix );
12541 });
12542 }
12543 }
12544
12545 else if ( param.type === 'RestElement' ) {
12546 if ( transforms.spreadRest ) {
12547 introStatementGenerators.push( function ( start, prefix, suffix ) {
12548 var penultimateParam = params[ params.length - 2 ];
12549
12550 if ( penultimateParam ) {
12551 code.remove( penultimateParam ? penultimateParam.end : param.start, param.end );
12552 } else {
12553 var start$1 = param.start, end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8
12554
12555 while ( /\s/.test( code.original[ start$1 - 1 ] ) ) start$1 -= 1;
12556 while ( /\s/.test( code.original[ end ] ) ) end += 1;
12557
12558 code.remove( start$1, end );
12559 }
12560
12561 var name = param.argument.name;
12562 var len = this$1.scope.createIdentifier( 'len' );
12563 var count = params.length - 1;
12564
12565 if ( count ) {
12566 code.prependRight( start, (prefix + "var " + name + " = [], " + len + " = arguments.length - " + count + ";\n" + indentation + "while ( " + len + "-- > 0 ) " + name + "[ " + len + " ] = arguments[ " + len + " + " + count + " ]" + suffix) );
12567 } else {
12568 code.prependRight( start, (prefix + "var " + name + " = [], " + len + " = arguments.length;\n" + indentation + "while ( " + len + "-- ) " + name + "[ " + len + " ] = arguments[ " + len + " ]" + suffix) );
12569 }
12570 });
12571 }
12572 }
12573
12574 else if ( param.type !== 'Identifier' ) {
12575 if ( transforms.parameterDestructuring ) {
12576 var ref = this$1.scope.createIdentifier( 'ref' );
12577 destructure( code, this$1.scope, param, ref, false, introStatementGenerators );
12578 code.prependRight( param.start, ref );
12579 }
12580 }
12581 });
12582 };
12583
12584 BlockStatement.prototype.transpileBlockScopedIdentifiers = function transpileBlockScopedIdentifiers ( code ) {
12585 var this$1 = this;
12586
12587 Object.keys( this.scope.blockScopedDeclarations ).forEach( function ( name ) {
12588 var declarations = this$1.scope.blockScopedDeclarations[ name ];
12589
12590 for ( var i = 0, list = declarations; i < list.length; i += 1 ) {
12591 var declaration = list[i];
12592
12593 var cont = false; // TODO implement proper continue...
12594
12595 if ( declaration.kind === 'for.let' ) {
12596 // special case
12597 var forStatement = declaration.node.findNearest( 'ForStatement' );
12598
12599 if ( forStatement.shouldRewriteAsFunction ) {
12600 var outerAlias = this$1.scope.createIdentifier( name );
12601 var innerAlias = forStatement.reassigned[ name ] ?
12602 this$1.scope.createIdentifier( name ) :
12603 name;
12604
12605 declaration.name = outerAlias;
12606 code.overwrite( declaration.node.start, declaration.node.end, outerAlias, { storeName: true });
12607
12608 forStatement.aliases[ name ] = {
12609 outer: outerAlias,
12610 inner: innerAlias
12611 };
12612
12613 for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
12614 var identifier = list$1[i$1];
12615
12616 var alias = forStatement.body.contains( identifier ) ?
12617 innerAlias :
12618 outerAlias;
12619
12620 if ( name !== alias ) {
12621 code.overwrite( identifier.start, identifier.end, alias, { storeName: true });
12622 }
12623 }
12624
12625 cont = true;
12626 }
12627 }
12628
12629 if ( !cont ) {
12630 var alias$1 = this$1.scope.createIdentifier( name );
12631
12632 if ( name !== alias$1 ) {
12633 declaration.name = alias$1;
12634 code.overwrite( declaration.node.start, declaration.node.end, alias$1, { storeName: true });
12635
12636 for ( var i$2 = 0, list$2 = declaration.instances; i$2 < list$2.length; i$2 += 1 ) {
12637 var identifier$1 = list$2[i$2];
12638
12639 identifier$1.rewritten = true;
12640 code.overwrite( identifier$1.start, identifier$1.end, alias$1, { storeName: true });
12641 }
12642 }
12643 }
12644 }
12645 });
12646 };
12647
12648 return BlockStatement;
12649}(Node$1));
12650
12651function Program ( source, ast, transforms, options ) {
12652 var this$1 = this;
12653
12654 this.type = 'Root';
12655
12656 // options
12657 this.jsx = options.jsx || 'React.createElement';
12658 this.options = options;
12659
12660 this.source = source;
12661 this.magicString = new MagicString( source );
12662
12663 this.ast = ast;
12664 this.depth = 0;
12665
12666 wrap( this.body = ast, this );
12667 this.body.__proto__ = BlockStatement.prototype;
12668
12669 this.indentExclusionElements = [];
12670 this.body.initialise( transforms );
12671
12672 this.indentExclusions = Object.create( null );
12673 for ( var i$1 = 0, list = this.indentExclusionElements; i$1 < list.length; i$1 += 1 ) {
12674 var node = list[i$1];
12675
12676 for ( var i = node.start; i < node.end; i += 1 ) {
12677 this$1.indentExclusions[ i ] = true;
12678 }
12679 }
12680
12681 this.body.transpile( this.magicString, transforms );
12682}
12683
12684Program.prototype = {
12685 export: function export$1 ( options ) {
12686 if ( options === void 0 ) options = {};
12687
12688 return {
12689 code: this.magicString.toString(),
12690 map: this.magicString.generateMap({
12691 file: options.file,
12692 source: options.source,
12693 includeContent: options.includeContent !== false
12694 })
12695 };
12696 },
12697
12698 findNearest: function findNearest () {
12699 return null;
12700 },
12701
12702 findScope: function findScope () {
12703 return null;
12704 }
12705};
12706
12707var matrix = {
12708 chrome: {
12709 48: 1333689725,
12710 49: 1342078975,
12711 50: 1610514431,
12712 51: 1610514431,
12713 52: 2147385343
12714 },
12715 firefox: {
12716 43: 1207307741,
12717 44: 1207307741,
12718 45: 1207307741,
12719 46: 1476267485,
12720 47: 1476296671,
12721 48: 1476296671
12722 },
12723 safari: {
12724 8: 1073741824,
12725 9: 1328940894
12726 },
12727 ie: {
12728 8: 0,
12729 9: 1073741824,
12730 10: 1073741824,
12731 11: 1073770592
12732 },
12733 edge: {
12734 12: 1591620701,
12735 13: 1608400479
12736 },
12737 node: {
12738 '0.10': 1075052608,
12739 '0.12': 1091830852,
12740 4: 1327398527,
12741 5: 1327398527,
12742 6: 1610514431
12743 }
12744};
12745
12746var features = [
12747 'arrow',
12748 'classes',
12749 'collections',
12750 'computedProperty',
12751 'conciseMethodProperty',
12752 'constLoop',
12753 'constRedef',
12754 'defaultParameter',
12755 'destructuring',
12756 'extendNatives',
12757 'forOf',
12758 'generator',
12759 'letConst',
12760 'letLoop',
12761 'letLoopScope',
12762 'moduleExport',
12763 'moduleImport',
12764 'numericLiteral',
12765 'objectProto',
12766 'objectSuper',
12767 'oldOctalLiteral',
12768 'parameterDestructuring',
12769 'spreadRest',
12770 'stickyRegExp',
12771 'symbol',
12772 'templateString',
12773 'unicodeEscape',
12774 'unicodeIdentifier',
12775 'unicodeRegExp',
12776
12777 // ES2016
12778 'exponentiation',
12779
12780 // additional transforms, not from
12781 // https://featuretests.io
12782 'reservedProperties'
12783];
12784
12785var version$1 = "0.17.0";
12786
12787var ref = [
12788 inject$1,
12789 inject
12790].reduce( function ( final, plugin ) { return plugin( final ); }, acorn );
12791var parse = ref.parse;
12792
12793var dangerousTransforms = [
12794 'dangerousTaggedTemplateString',
12795 'dangerousForOf'
12796];
12797
12798function target ( target ) {
12799 var targets = Object.keys( target );
12800 var bitmask = targets.length ?
12801 2147483647 :
12802 1073741824;
12803
12804 Object.keys( target ).forEach( function ( environment ) {
12805 var versions = matrix[ environment ];
12806 if ( !versions ) throw new Error( ("Unknown environment '" + environment + "'. Please raise an issue at https://gitlab.com/Rich-Harris/buble/issues") );
12807
12808 var targetVersion = target[ environment ];
12809 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") );
12810 var support = versions[ targetVersion ];
12811
12812 bitmask &= support;
12813 });
12814
12815 var transforms = Object.create( null );
12816 features.forEach( function ( name, i ) {
12817 transforms[ name ] = !( bitmask & 1 << i );
12818 });
12819
12820 dangerousTransforms.forEach( function ( name ) {
12821 transforms[ name ] = false;
12822 });
12823
12824 return transforms;
12825}
12826
12827function transform ( source, options ) {
12828 if ( options === void 0 ) options = {};
12829
12830 var ast;
12831 var jsx = null;
12832
12833 try {
12834 ast = parse( source, {
12835 ecmaVersion: 8,
12836 preserveParens: true,
12837 sourceType: 'module',
12838 onComment: function (block, text) {
12839 if ( !jsx ) {
12840 var match = /@jsx\s+([^\s]+)/.exec( text );
12841 if ( match ) jsx = match[1];
12842 }
12843 },
12844 plugins: {
12845 jsx: true,
12846 objectSpread: true
12847 }
12848 });
12849 options.jsx = jsx || options.jsx;
12850 } catch ( err ) {
12851 err.snippet = getSnippet( source, err.loc );
12852 err.toString = function () { return ((err.name) + ": " + (err.message) + "\n" + (err.snippet)); };
12853 throw err;
12854 }
12855
12856 var transforms = target( options.target || {} );
12857 Object.keys( options.transforms || {} ).forEach( function ( name ) {
12858 if ( name === 'modules' ) {
12859 if ( !( 'moduleImport' in options.transforms ) ) transforms.moduleImport = options.transforms.modules;
12860 if ( !( 'moduleExport' in options.transforms ) ) transforms.moduleExport = options.transforms.modules;
12861 return;
12862 }
12863
12864 if ( !( name in transforms ) ) throw new Error( ("Unknown transform '" + name + "'") );
12865 transforms[ name ] = options.transforms[ name ];
12866 });
12867
12868 return new Program( source, ast, transforms, options ).export( options );
12869}
12870
12871exports.target = target;
12872exports.transform = transform;
12873exports.VERSION = version$1;
12874
12875Object.defineProperty(exports, '__esModule', { value: true });
12876
12877})));
12878//# sourceMappingURL=buble.umd.js.map