UNPKG

407 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 ArrayPattern: function ArrayPattern ( names, node ) {
5931 for ( var i = 0, list = node.elements; i < list.length; i += 1 ) {
5932 var element = list[i];
5933
5934 if ( element ) extractors[ element.type ]( names, element );
5935 }
5936 },
5937
5938 RestElement: function RestElement ( names, node ) {
5939 extractors[ node.argument.type ]( names, node.argument );
5940 },
5941
5942 AssignmentPattern: function AssignmentPattern ( names, node ) {
5943 extractors[ node.left.type ]( names, node.left );
5944 }
5945};
5946
5947var ForStatement = (function (LoopStatement$$1) {
5948 function ForStatement () {
5949 LoopStatement$$1.apply(this, arguments);
5950 }
5951
5952 if ( LoopStatement$$1 ) ForStatement.__proto__ = LoopStatement$$1;
5953 ForStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
5954 ForStatement.prototype.constructor = ForStatement;
5955
5956 ForStatement.prototype.findScope = function findScope ( functionScope ) {
5957 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
5958 };
5959
5960 ForStatement.prototype.transpile = function transpile ( code, transforms ) {
5961 var this$1 = this;
5962
5963 var i1 = this.getIndentation() + code.getIndentString();
5964
5965 if ( this.shouldRewriteAsFunction ) {
5966 // which variables are declared in the init statement?
5967 var names = this.init.type === 'VariableDeclaration' ?
5968 [].concat.apply( [], this.init.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
5969 [];
5970
5971 var aliases = this.aliases;
5972
5973 this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
5974 this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
5975
5976 var updates = Object.keys( this.reassigned )
5977 .map( function ( name ) { return ((aliases[ name ].outer) + " = " + (aliases[ name ].inner) + ";"); } );
5978
5979 if ( updates.length ) {
5980 if ( this.body.synthetic ) {
5981 code.appendLeft( this.body.body[0].end, ("; " + (updates.join(" "))) );
5982 } else {
5983 var lastStatement = this.body.body[ this.body.body.length - 1 ];
5984 code.appendLeft( lastStatement.end, ("\n\n" + i1 + (updates.join(("\n" + i1)))) );
5985 }
5986 }
5987 }
5988
5989 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
5990 };
5991
5992 return ForStatement;
5993}(LoopStatement));
5994
5995var ForInStatement = (function (LoopStatement$$1) {
5996 function ForInStatement () {
5997 LoopStatement$$1.apply(this, arguments);
5998 }
5999
6000 if ( LoopStatement$$1 ) ForInStatement.__proto__ = LoopStatement$$1;
6001 ForInStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
6002 ForInStatement.prototype.constructor = ForInStatement;
6003
6004 ForInStatement.prototype.findScope = function findScope ( functionScope ) {
6005 return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
6006 };
6007
6008 ForInStatement.prototype.transpile = function transpile ( code, transforms ) {
6009 var this$1 = this;
6010
6011 if ( this.shouldRewriteAsFunction ) {
6012 // which variables are declared in the init statement?
6013 var names = this.left.type === 'VariableDeclaration' ?
6014 [].concat.apply( [], this.left.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
6015 [];
6016
6017 this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
6018 this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
6019 }
6020
6021 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
6022 };
6023
6024 return ForInStatement;
6025}(LoopStatement));
6026
6027var handlers = {
6028 Identifier: destructureIdentifier,
6029 AssignmentPattern: destructureAssignmentPattern,
6030 ArrayPattern: destructureArrayPattern,
6031 ObjectPattern: destructureObjectPattern
6032};
6033
6034function destructure ( code, scope, node, ref, inline, statementGenerators ) {
6035 handlers[ node.type ]( code, scope, node, ref, inline, statementGenerators );
6036}
6037
6038function destructureIdentifier ( code, scope, node, ref, inline, statementGenerators ) {
6039 statementGenerators.push( function ( start, prefix, suffix ) {
6040 code.prependRight( node.start, inline ? prefix : (prefix + "var ") );
6041 code.appendLeft( node.end, (" = " + ref + suffix) );
6042 code.move( node.start, node.end, start );
6043 });
6044}
6045
6046function destructureAssignmentPattern ( code, scope, node, ref, inline, statementGenerators ) {
6047 var isIdentifier = node.left.type === 'Identifier';
6048 var name = isIdentifier ? node.left.name : ref;
6049
6050 if ( !inline ) {
6051 statementGenerators.push( function ( start, prefix, suffix ) {
6052 code.prependRight( node.left.end, (prefix + "if ( " + name + " === void 0 ) " + name) );
6053 code.move( node.left.end, node.right.end, start );
6054 code.appendLeft( node.right.end, suffix );
6055 });
6056 }
6057
6058 if ( !isIdentifier ) {
6059 destructure( code, scope, node.left, ref, inline, statementGenerators );
6060 }
6061}
6062
6063function destructureArrayPattern ( code, scope, node, ref, inline, statementGenerators ) {
6064 var c = node.start;
6065
6066 node.elements.forEach( function ( element, i ) {
6067 if ( !element ) return;
6068
6069 if ( element.type === 'RestElement' ) {
6070 handleProperty( code, scope, c, element.argument, (ref + ".slice(" + i + ")"), inline, statementGenerators );
6071 } else {
6072 handleProperty( code, scope, c, element, (ref + "[" + i + "]"), inline, statementGenerators );
6073 }
6074 c = element.end;
6075 });
6076
6077 code.remove( c, node.end );
6078}
6079
6080function destructureObjectPattern ( code, scope, node, ref, inline, statementGenerators ) {
6081 var this$1 = this;
6082
6083 var c = node.start;
6084
6085 var nonRestKeys = [];
6086 node.properties.forEach( function ( prop ) {
6087 var value;
6088 var content;
6089 if (prop.type === "Property") {
6090 var isComputedKey = prop.computed || prop.key.type !== 'Identifier';
6091 var key = isComputedKey ? code.slice(prop.key.start, prop.key.end) : prop.key.name;
6092 value = isComputedKey ? (ref + "[" + key + "]") : (ref + "." + key);
6093 content = prop.value;
6094 nonRestKeys.push(isComputedKey ? key : '"' + key + '"');
6095 } else if (prop.type === "RestElement") {
6096 content = prop.argument;
6097 value = scope.createIdentifier( 'rest' );
6098 var n = scope.createIdentifier( 'n' );
6099 statementGenerators.push( function ( start, prefix, suffix ) {
6100 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));
6101 code.move(prop.start, c, start);
6102 } );
6103 } else {
6104 throw new CompileError( this$1, ("Unexpected node of type " + (prop.type) + " in object pattern"))
6105 }
6106 handleProperty( code, scope, c, content, value, inline, statementGenerators );
6107 c = prop.end;
6108 });
6109
6110 code.remove( c, node.end );
6111}
6112
6113function handleProperty ( code, scope, c, node, value, inline, statementGenerators ) {
6114 switch ( node.type ) {
6115 case 'Identifier': {
6116 code.remove( c, node.start );
6117 destructureIdentifier( code, scope, node, value, inline, statementGenerators );
6118 break;
6119 }
6120
6121 case 'AssignmentPattern': {
6122 var name;
6123
6124 var isIdentifier = node.left.type === 'Identifier';
6125
6126 if ( isIdentifier ) {
6127 name = node.left.name;
6128 var declaration = scope.findDeclaration( name );
6129 if ( declaration ) name = declaration.name;
6130 } else {
6131 name = scope.createIdentifier( value );
6132 }
6133
6134 statementGenerators.push( function ( start, prefix, suffix ) {
6135 if ( inline ) {
6136 code.prependRight( node.right.start, (name + " = " + value + " === undefined ? ") );
6137 code.appendLeft( node.right.end, (" : " + value) );
6138 } else {
6139 code.prependRight( node.right.start, (prefix + "var " + name + " = " + value + "; if ( " + name + " === void 0 ) " + name + " = ") );
6140 code.appendLeft( node.right.end, suffix );
6141 }
6142
6143 code.move( node.right.start, node.right.end, start );
6144 });
6145
6146 if ( isIdentifier ) {
6147 code.remove( c, node.right.start );
6148 } else {
6149 code.remove( c, node.left.start );
6150 code.remove( node.left.end, node.right.start );
6151 handleProperty( code, scope, c, node.left, name, inline, statementGenerators );
6152 }
6153
6154 break;
6155 }
6156
6157 case 'ObjectPattern': {
6158 code.remove( c, c = node.start );
6159
6160 var ref = value;
6161 if ( node.properties.length > 1 ) {
6162 ref = scope.createIdentifier( value );
6163
6164 statementGenerators.push( function ( start, prefix, suffix ) {
6165 // this feels a tiny bit hacky, but we can't do a
6166 // straightforward appendLeft and keep correct order...
6167 code.prependRight( node.start, (prefix + "var " + ref + " = ") );
6168 code.overwrite( node.start, c = node.start + 1, value );
6169 code.appendLeft( c, suffix );
6170
6171 code.overwrite( node.start, c = node.start + 1, (prefix + "var " + ref + " = " + value + suffix) );
6172 code.move( node.start, c, start );
6173 });
6174 }
6175
6176 destructureObjectPattern( code, scope, node, ref, inline, statementGenerators );
6177
6178 break;
6179 }
6180
6181 case 'ArrayPattern': {
6182 code.remove( c, c = node.start );
6183
6184 if ( node.elements.filter( Boolean ).length > 1 ) {
6185 var ref$1 = scope.createIdentifier( value );
6186
6187 statementGenerators.push( function ( start, prefix, suffix ) {
6188 code.prependRight( node.start, (prefix + "var " + ref$1 + " = ") );
6189 code.overwrite( node.start, c = node.start + 1, value, { contentOnly: true });
6190 code.appendLeft( c, suffix );
6191
6192 code.move( node.start, c, start );
6193 });
6194
6195 node.elements.forEach( function ( element, i ) {
6196 if ( !element ) return;
6197
6198 if ( element.type === 'RestElement' ) {
6199 handleProperty( code, scope, c, element.argument, (ref$1 + ".slice(" + i + ")"), inline, statementGenerators );
6200 } else {
6201 handleProperty( code, scope, c, element, (ref$1 + "[" + i + "]"), inline, statementGenerators );
6202 }
6203 c = element.end;
6204 });
6205 } else {
6206 var index = findIndex( node.elements, Boolean );
6207 var element = node.elements[ index ];
6208 if ( element.type === 'RestElement' ) {
6209 handleProperty( code, scope, c, element.argument, (value + ".slice(" + index + ")"), inline, statementGenerators );
6210 } else {
6211 handleProperty( code, scope, c, element, (value + "[" + index + "]"), inline, statementGenerators );
6212 }
6213 c = element.end;
6214 }
6215
6216 code.remove( c, node.end );
6217 break;
6218 }
6219
6220 default: {
6221 throw new Error( ("Unexpected node type in destructuring (" + (node.type) + ")") );
6222 }
6223 }
6224}
6225
6226var ForOfStatement = (function (LoopStatement$$1) {
6227 function ForOfStatement () {
6228 LoopStatement$$1.apply(this, arguments);
6229 }
6230
6231 if ( LoopStatement$$1 ) ForOfStatement.__proto__ = LoopStatement$$1;
6232 ForOfStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
6233 ForOfStatement.prototype.constructor = ForOfStatement;
6234
6235 ForOfStatement.prototype.initialise = function initialise ( transforms ) {
6236 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 );
6237 LoopStatement$$1.prototype.initialise.call( this, transforms );
6238 };
6239
6240 ForOfStatement.prototype.transpile = function transpile ( code, transforms ) {
6241 LoopStatement$$1.prototype.transpile.call( this, code, transforms );
6242 if ( !transforms.dangerousForOf ) return;
6243
6244 // edge case (#80)
6245 if ( !this.body.body[0] ) {
6246 if ( this.left.type === 'VariableDeclaration' && this.left.kind === 'var' ) {
6247 code.remove( this.start, this.left.start );
6248 code.appendLeft( this.left.end, ';' );
6249 code.remove( this.left.end, this.end );
6250 } else {
6251 code.remove( this.start, this.end );
6252 }
6253
6254 return;
6255 }
6256
6257 var scope = this.findScope( true );
6258 var i0 = this.getIndentation();
6259 var i1 = i0 + code.getIndentString();
6260
6261 var key = scope.createIdentifier( 'i' );
6262 var list = scope.createIdentifier( 'list' );
6263
6264 if ( this.body.synthetic ) {
6265 code.prependRight( this.left.start, ("{\n" + i1) );
6266 code.appendLeft( this.body.body[0].end, ("\n" + i0 + "}") );
6267 }
6268
6269 var bodyStart = this.body.body[0].start;
6270
6271 code.remove( this.left.end, this.right.start );
6272 code.move( this.left.start, this.left.end, bodyStart );
6273
6274
6275 code.prependRight( this.right.start, ("var " + key + " = 0, " + list + " = ") );
6276 code.appendLeft( this.right.end, ("; " + key + " < " + list + ".length; " + key + " += 1") );
6277
6278 // destructuring. TODO non declaration destructuring
6279 var declarator = this.left.type === 'VariableDeclaration' && this.left.declarations[0];
6280 if ( declarator && declarator.id.type !== 'Identifier' ) {
6281 var statementGenerators = [];
6282 var ref = scope.createIdentifier( 'ref' );
6283 destructure( code, scope, declarator.id, ref, false, statementGenerators );
6284
6285 var suffix = ";\n" + i1;
6286 statementGenerators.forEach( function ( fn, i ) {
6287 if ( i === statementGenerators.length - 1 ) {
6288 suffix = ";\n\n" + i1;
6289 }
6290
6291 fn( bodyStart, '', suffix );
6292 });
6293
6294 code.appendLeft( this.left.start + this.left.kind.length + 1, ref );
6295 code.appendLeft( this.left.end, (" = " + list + "[" + key + "];\n" + i1) );
6296 } else {
6297 code.appendLeft( this.left.end, (" = " + list + "[" + key + "];\n\n" + i1) );
6298 }
6299 };
6300
6301 return ForOfStatement;
6302}(LoopStatement));
6303
6304var FunctionDeclaration = (function (Node) {
6305 function FunctionDeclaration () {
6306 Node.apply(this, arguments);
6307 }
6308
6309 if ( Node ) FunctionDeclaration.__proto__ = Node;
6310 FunctionDeclaration.prototype = Object.create( Node && Node.prototype );
6311 FunctionDeclaration.prototype.constructor = FunctionDeclaration;
6312
6313 FunctionDeclaration.prototype.initialise = function initialise ( transforms ) {
6314 if ( this.generator && transforms.generator ) {
6315 throw new CompileError$1( 'Generators are not supported', this );
6316 }
6317
6318 this.body.createScope();
6319
6320 this.findScope( true ).addDeclaration( this.id, 'function' );
6321 Node.prototype.initialise.call( this, transforms );
6322 };
6323
6324 return FunctionDeclaration;
6325}(Node$1));
6326
6327var FunctionExpression = (function (Node) {
6328 function FunctionExpression () {
6329 Node.apply(this, arguments);
6330 }
6331
6332 if ( Node ) FunctionExpression.__proto__ = Node;
6333 FunctionExpression.prototype = Object.create( Node && Node.prototype );
6334 FunctionExpression.prototype.constructor = FunctionExpression;
6335
6336 FunctionExpression.prototype.initialise = function initialise ( transforms ) {
6337 if ( this.generator && transforms.generator ) {
6338 throw new CompileError$1( 'Generators are not supported', this );
6339 }
6340
6341 this.body.createScope();
6342
6343 if ( this.id ) {
6344 // function expression IDs belong to the child scope...
6345 this.body.scope.addDeclaration( this.id, 'function' );
6346 }
6347
6348 Node.prototype.initialise.call( this, transforms );
6349
6350 var parent = this.parent;
6351 var methodName;
6352
6353 if ( transforms.conciseMethodProperty
6354 && parent.type === 'Property'
6355 && parent.kind === 'init'
6356 && parent.method
6357 && parent.key.type === 'Identifier' ) {
6358 // object literal concise method
6359 methodName = parent.key.name;
6360 }
6361 else if ( transforms.classes
6362 && parent.type === 'MethodDefinition'
6363 && parent.kind === 'method'
6364 && parent.key.type === 'Identifier' ) {
6365 // method definition in a class
6366 methodName = parent.key.name;
6367 }
6368 else if ( this.id && this.id.type === 'Identifier' ) {
6369 // naked function expression
6370 methodName = this.id.alias || this.id.name;
6371 }
6372
6373 if ( methodName ) {
6374 for ( var i = 0, list = this.params; i < list.length; i += 1 ) {
6375 var param = list[i];
6376
6377 if ( param.type === 'Identifier' && methodName === param.name ) {
6378 // workaround for Safari 9/WebKit bug:
6379 // https://gitlab.com/Rich-Harris/buble/issues/154
6380 // change parameter name when same as method name
6381
6382 var scope = this.body.scope;
6383 var declaration = scope.declarations[ methodName ];
6384
6385 var alias = scope.createIdentifier( methodName );
6386 param.alias = alias;
6387
6388 for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
6389 var identifier = list$1[i$1];
6390
6391 identifier.alias = alias;
6392 }
6393
6394 break;
6395 }
6396 }
6397 }
6398 };
6399
6400 return FunctionExpression;
6401}(Node$1));
6402
6403function isReference ( node, parent ) {
6404 if ( node.type === 'MemberExpression' ) {
6405 return !node.computed && isReference( node.object, node );
6406 }
6407
6408 if ( node.type === 'Identifier' ) {
6409 // the only time we could have an identifier node without a parent is
6410 // if it's the entire body of a function without a block statement –
6411 // i.e. an arrow function expression like `a => a`
6412 if ( !parent ) return true;
6413
6414 if ( /(Function|Class)Expression/.test( parent.type ) ) return false;
6415
6416 if ( parent.type === 'VariableDeclarator' ) return node === parent.init;
6417
6418 // TODO is this right?
6419 if ( parent.type === 'MemberExpression' || parent.type === 'MethodDefinition' ) {
6420 return parent.computed || node === parent.object;
6421 }
6422
6423 if ( parent.type === 'ArrayPattern' ) return false;
6424
6425 // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
6426 if ( parent.type === 'Property' ) {
6427 if ( parent.parent.type === 'ObjectPattern' ) return false;
6428 return parent.computed || node === parent.value;
6429 }
6430
6431 // disregard the `bar` in `class Foo { bar () {...} }`
6432 if ( parent.type === 'MethodDefinition' ) return false;
6433
6434 // disregard the `bar` in `export { foo as bar }`
6435 if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return false;
6436
6437 return true;
6438 }
6439}
6440
6441var Identifier = (function (Node) {
6442 function Identifier () {
6443 Node.apply(this, arguments);
6444 }
6445
6446 if ( Node ) Identifier.__proto__ = Node;
6447 Identifier.prototype = Object.create( Node && Node.prototype );
6448 Identifier.prototype.constructor = Identifier;
6449
6450 Identifier.prototype.findScope = function findScope ( functionScope ) {
6451 if ( this.parent.params && ~this.parent.params.indexOf( this ) ) {
6452 return this.parent.body.scope;
6453 }
6454
6455 if ( this.parent.type === 'FunctionExpression' && this === this.parent.id ) {
6456 return this.parent.body.scope;
6457 }
6458
6459 return this.parent.findScope( functionScope );
6460 };
6461
6462 Identifier.prototype.initialise = function initialise ( transforms ) {
6463 if ( transforms.arrow && isReference( this, this.parent ) ) {
6464 if ( this.name === 'arguments' && !this.findScope( false ).contains( this.name ) ) {
6465 var lexicalBoundary = this.findLexicalBoundary();
6466 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
6467 var loop = this.findNearest( loopStatement );
6468
6469 if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
6470 this.alias = lexicalBoundary.getArgumentsAlias();
6471 }
6472
6473 if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
6474 this.alias = lexicalBoundary.getArgumentsAlias();
6475 }
6476 }
6477
6478 this.findScope( false ).addReference( this );
6479 }
6480 };
6481
6482 Identifier.prototype.transpile = function transpile ( code ) {
6483 if ( this.alias ) {
6484 code.overwrite( this.start, this.end, this.alias, { storeName: true, contentOnly: true });
6485 }
6486 };
6487
6488 return Identifier;
6489}(Node$1));
6490
6491var IfStatement = (function (Node) {
6492 function IfStatement () {
6493 Node.apply(this, arguments);
6494 }
6495
6496 if ( Node ) IfStatement.__proto__ = Node;
6497 IfStatement.prototype = Object.create( Node && Node.prototype );
6498 IfStatement.prototype.constructor = IfStatement;
6499
6500 IfStatement.prototype.initialise = function initialise ( transforms ) {
6501 Node.prototype.initialise.call( this, transforms );
6502 };
6503
6504 IfStatement.prototype.transpile = function transpile ( code, transforms ) {
6505 if ( this.consequent.type !== 'BlockStatement'
6506 || this.consequent.type === 'BlockStatement' && this.consequent.synthetic ) {
6507 code.appendLeft( this.consequent.start, '{ ' );
6508 code.prependRight( this.consequent.end, ' }' );
6509 }
6510
6511 if ( this.alternate && this.alternate.type !== 'IfStatement' && (
6512 this.alternate.type !== 'BlockStatement'
6513 || this.alternate.type === 'BlockStatement' && this.alternate.synthetic ) ) {
6514 code.appendLeft( this.alternate.start, '{ ' );
6515 code.prependRight( this.alternate.end, ' }' );
6516 }
6517
6518 Node.prototype.transpile.call( this, code, transforms );
6519 };
6520
6521 return IfStatement;
6522}(Node$1));
6523
6524var ImportDeclaration = (function (Node) {
6525 function ImportDeclaration () {
6526 Node.apply(this, arguments);
6527 }
6528
6529 if ( Node ) ImportDeclaration.__proto__ = Node;
6530 ImportDeclaration.prototype = Object.create( Node && Node.prototype );
6531 ImportDeclaration.prototype.constructor = ImportDeclaration;
6532
6533 ImportDeclaration.prototype.initialise = function initialise ( transforms ) {
6534 if ( transforms.moduleImport ) throw new CompileError$1( 'import is not supported', this );
6535 Node.prototype.initialise.call( this, transforms );
6536 };
6537
6538 return ImportDeclaration;
6539}(Node$1));
6540
6541var ImportDefaultSpecifier = (function (Node) {
6542 function ImportDefaultSpecifier () {
6543 Node.apply(this, arguments);
6544 }
6545
6546 if ( Node ) ImportDefaultSpecifier.__proto__ = Node;
6547 ImportDefaultSpecifier.prototype = Object.create( Node && Node.prototype );
6548 ImportDefaultSpecifier.prototype.constructor = ImportDefaultSpecifier;
6549
6550 ImportDefaultSpecifier.prototype.initialise = function initialise ( transforms ) {
6551 this.findScope( true ).addDeclaration( this.local, 'import' );
6552 Node.prototype.initialise.call( this, transforms );
6553 };
6554
6555 return ImportDefaultSpecifier;
6556}(Node$1));
6557
6558var ImportSpecifier = (function (Node) {
6559 function ImportSpecifier () {
6560 Node.apply(this, arguments);
6561 }
6562
6563 if ( Node ) ImportSpecifier.__proto__ = Node;
6564 ImportSpecifier.prototype = Object.create( Node && Node.prototype );
6565 ImportSpecifier.prototype.constructor = ImportSpecifier;
6566
6567 ImportSpecifier.prototype.initialise = function initialise ( transforms ) {
6568 this.findScope( true ).addDeclaration( this.local, 'import' );
6569 Node.prototype.initialise.call( this, transforms );
6570 };
6571
6572 return ImportSpecifier;
6573}(Node$1));
6574
6575var hasDashes = function ( val ) { return /-/.test(val); };
6576
6577var formatKey = function ( key ) { return hasDashes(key) ? ("'" + key + "'") : key; };
6578
6579var formatVal = function ( val ) { return val ? '' : 'true'; };
6580
6581var JSXAttribute = (function (Node) {
6582 function JSXAttribute () {
6583 Node.apply(this, arguments);
6584 }
6585
6586 if ( Node ) JSXAttribute.__proto__ = Node;
6587 JSXAttribute.prototype = Object.create( Node && Node.prototype );
6588 JSXAttribute.prototype.constructor = JSXAttribute;
6589
6590 JSXAttribute.prototype.transpile = function transpile ( code, transforms ) {
6591 var ref = this.name;
6592 var start = ref.start;
6593 var name = ref.name;
6594
6595 // Overwrite equals sign if value is present.
6596 var end = this.value ? this.value.start : this.name.end;
6597
6598 code.overwrite( start, end, ((formatKey(name)) + ": " + (formatVal(this.value))) );
6599
6600 Node.prototype.transpile.call( this, code, transforms );
6601 };
6602
6603 return JSXAttribute;
6604}(Node$1));
6605
6606function containsNewLine ( node ) {
6607 return node.type === 'Literal' && !/\S/.test( node.value ) && /\n/.test( node.value );
6608}
6609
6610var JSXClosingElement = (function (Node) {
6611 function JSXClosingElement () {
6612 Node.apply(this, arguments);
6613 }
6614
6615 if ( Node ) JSXClosingElement.__proto__ = Node;
6616 JSXClosingElement.prototype = Object.create( Node && Node.prototype );
6617 JSXClosingElement.prototype.constructor = JSXClosingElement;
6618
6619 JSXClosingElement.prototype.transpile = function transpile ( code ) {
6620 var spaceBeforeParen = true;
6621
6622 var lastChild = this.parent.children[ this.parent.children.length - 1 ];
6623
6624 // omit space before closing paren if
6625 // a) this is on a separate line, or
6626 // b) there are no children but there are attributes
6627 if ( ( lastChild && containsNewLine( lastChild ) ) || ( this.parent.openingElement.attributes.length ) ) {
6628 spaceBeforeParen = false;
6629 }
6630
6631 code.overwrite( this.start, this.end, spaceBeforeParen ? ' )' : ')' );
6632 };
6633
6634 return JSXClosingElement;
6635}(Node$1));
6636
6637function normalise ( str, removeTrailingWhitespace ) {
6638 if ( removeTrailingWhitespace && /\n/.test( str ) ) {
6639 str = str.replace( /\s+$/, '' );
6640 }
6641
6642 str = str
6643 .replace( /^\n\r?\s+/, '' ) // remove leading newline + space
6644 .replace( /\s*\n\r?\s*/gm, ' ' ); // replace newlines with spaces
6645
6646 // TODO prefer single quotes?
6647 return JSON.stringify( str );
6648}
6649
6650var JSXElement = (function (Node) {
6651 function JSXElement () {
6652 Node.apply(this, arguments);
6653 }
6654
6655 if ( Node ) JSXElement.__proto__ = Node;
6656 JSXElement.prototype = Object.create( Node && Node.prototype );
6657 JSXElement.prototype.constructor = JSXElement;
6658
6659 JSXElement.prototype.transpile = function transpile ( code, transforms ) {
6660 Node.prototype.transpile.call( this, code, transforms );
6661
6662 var children = this.children.filter( function ( child ) {
6663 if ( child.type !== 'Literal' ) return true;
6664
6665 // remove whitespace-only literals, unless on a single line
6666 return /\S/.test( child.value ) || !/\n/.test( child.value );
6667 });
6668
6669 if ( children.length ) {
6670 var c = this.openingElement.end;
6671
6672 var i;
6673 for ( i = 0; i < children.length; i += 1 ) {
6674 var child = children[i];
6675
6676 if ( child.type === 'JSXExpressionContainer' && child.expression.type === 'JSXEmptyExpression' ) {
6677 // empty block is a no op
6678 } else {
6679 var tail = code.original[ c ] === '\n' && child.type !== 'Literal' ? '' : ' ';
6680 code.appendLeft( c, ("," + tail) );
6681 }
6682
6683 if ( child.type === 'Literal' ) {
6684 var str = normalise( child.value, i === children.length - 1 );
6685 code.overwrite( child.start, child.end, str );
6686 }
6687
6688 c = child.end;
6689 }
6690 }
6691 };
6692
6693 return JSXElement;
6694}(Node$1));
6695
6696var JSXExpressionContainer = (function (Node) {
6697 function JSXExpressionContainer () {
6698 Node.apply(this, arguments);
6699 }
6700
6701 if ( Node ) JSXExpressionContainer.__proto__ = Node;
6702 JSXExpressionContainer.prototype = Object.create( Node && Node.prototype );
6703 JSXExpressionContainer.prototype.constructor = JSXExpressionContainer;
6704
6705 JSXExpressionContainer.prototype.transpile = function transpile ( code, transforms ) {
6706 code.remove( this.start, this.expression.start );
6707 code.remove( this.expression.end, this.end );
6708
6709 Node.prototype.transpile.call( this, code, transforms );
6710 };
6711
6712 return JSXExpressionContainer;
6713}(Node$1));
6714
6715var JSXOpeningElement = (function (Node) {
6716 function JSXOpeningElement () {
6717 Node.apply(this, arguments);
6718 }
6719
6720 if ( Node ) JSXOpeningElement.__proto__ = Node;
6721 JSXOpeningElement.prototype = Object.create( Node && Node.prototype );
6722 JSXOpeningElement.prototype.constructor = JSXOpeningElement;
6723
6724 JSXOpeningElement.prototype.transpile = function transpile ( code, transforms ) {
6725 var this$1 = this;
6726
6727 Node.prototype.transpile.call( this, code, transforms );
6728
6729 code.overwrite( this.start, this.name.start, ((this.program.jsx) + "( ") );
6730
6731 var html = this.name.type === 'JSXIdentifier' && this.name.name[0] === this.name.name[0].toLowerCase();
6732 if ( html ) code.prependRight( this.name.start, "'" );
6733
6734 var len = this.attributes.length;
6735 var c = this.name.end;
6736
6737 if ( len ) {
6738 var i;
6739
6740 var hasSpread = false;
6741 for ( i = 0; i < len; i += 1 ) {
6742 if ( this$1.attributes[i].type === 'JSXSpreadAttribute' ) {
6743 hasSpread = true;
6744 break;
6745 }
6746 }
6747
6748 c = this.attributes[0].end;
6749
6750 for ( i = 0; i < len; i += 1 ) {
6751 var attr = this$1.attributes[i];
6752
6753 if ( i > 0 ) {
6754 if ( attr.start === c )
6755 code.prependRight( c, ', ' );
6756 else
6757 code.overwrite( c, attr.start, ', ' );
6758 }
6759
6760 if ( hasSpread && attr.type !== 'JSXSpreadAttribute' ) {
6761 var lastAttr = this$1.attributes[ i - 1 ];
6762 var nextAttr = this$1.attributes[ i + 1 ];
6763
6764 if ( !lastAttr || lastAttr.type === 'JSXSpreadAttribute' ) {
6765 code.prependRight( attr.start, '{ ' );
6766 }
6767
6768 if ( !nextAttr || nextAttr.type === 'JSXSpreadAttribute' ) {
6769 code.appendLeft( attr.end, ' }' );
6770 }
6771 }
6772
6773 c = attr.end;
6774 }
6775
6776 var after;
6777 var before;
6778 if ( hasSpread ) {
6779 if ( len === 1 ) {
6780 before = html ? "'," : ',';
6781 } else {
6782 if (!this.program.options.objectAssign) {
6783 throw new CompileError$1( 'Mixed JSX attributes ending in spread requires specified objectAssign option with \'Object.assign\' or polyfill helper.', this );
6784 }
6785 before = html ? ("', " + (this.program.options.objectAssign) + "({},") : (", " + (this.program.options.objectAssign) + "({},");
6786 after = ')';
6787 }
6788 } else {
6789 before = html ? "', {" : ', {';
6790 after = ' }';
6791 }
6792
6793 code.prependRight( this.name.end, before );
6794
6795 if ( after ) {
6796 code.appendLeft( this.attributes[ len - 1 ].end, after );
6797 }
6798 } else {
6799 code.appendLeft( this.name.end, html ? "', null" : ", null" );
6800 c = this.name.end;
6801 }
6802
6803 if ( this.selfClosing ) {
6804 code.overwrite( c, this.end, this.attributes.length ? ")" : " )" );
6805 } else {
6806 code.remove( c, this.end );
6807 }
6808 };
6809
6810 return JSXOpeningElement;
6811}(Node$1));
6812
6813var JSXSpreadAttribute = (function (Node) {
6814 function JSXSpreadAttribute () {
6815 Node.apply(this, arguments);
6816 }
6817
6818 if ( Node ) JSXSpreadAttribute.__proto__ = Node;
6819 JSXSpreadAttribute.prototype = Object.create( Node && Node.prototype );
6820 JSXSpreadAttribute.prototype.constructor = JSXSpreadAttribute;
6821
6822 JSXSpreadAttribute.prototype.transpile = function transpile ( code, transforms ) {
6823 code.remove( this.start, this.argument.start );
6824 code.remove( this.argument.end, this.end );
6825
6826 Node.prototype.transpile.call( this, code, transforms );
6827 };
6828
6829 return JSXSpreadAttribute;
6830}(Node$1));
6831
6832var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6833
6834function commonjsRequire () {
6835 throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
6836}
6837
6838
6839
6840function createCommonjsModule(fn, module) {
6841 return module = { exports: {} }, fn(module, module.exports), module.exports;
6842}
6843
6844var regjsgen = createCommonjsModule(function (module, exports) {
6845/*!
6846 * regjsgen 0.3.0
6847 * Copyright 2014-2016 Benjamin Tan <https://demoneaux.github.io/>
6848 * Available under MIT license <https://github.com/demoneaux/regjsgen/blob/master/LICENSE>
6849 */
6850(function() {
6851 'use strict';
6852
6853 // Used to determine if values are of the language type `Object`.
6854 var objectTypes = {
6855 'function': true,
6856 'object': true
6857 };
6858
6859 // Used as a reference to the global object.
6860 var root = (objectTypes[typeof window] && window) || this;
6861
6862 // Detect free variable `exports`.
6863 var freeExports = objectTypes['object'] && exports;
6864
6865 // Detect free variable `module`.
6866 var freeModule = objectTypes['object'] && module && !module.nodeType && module;
6867
6868 // Detect free variable `global` from Node.js or Browserified code and use it as `root`.
6869 var freeGlobal = freeExports && freeModule && typeof commonjsGlobal == 'object' && commonjsGlobal;
6870 if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
6871 root = freeGlobal;
6872 }
6873
6874 // Used to check objects for own properties.
6875 var hasOwnProperty = Object.prototype.hasOwnProperty;
6876
6877 /*--------------------------------------------------------------------------*/
6878
6879 // Generates strings based on the given code points.
6880 // Based on https://mths.be/fromcodepoint v0.2.0 by @mathias.
6881 var stringFromCharCode = String.fromCharCode;
6882 var floor = Math.floor;
6883 function fromCodePoint() {
6884 var MAX_SIZE = 0x4000;
6885 var codeUnits = [];
6886 var highSurrogate;
6887 var lowSurrogate;
6888 var index = -1;
6889 var length = arguments.length;
6890 if (!length) {
6891 return '';
6892 }
6893 var result = '';
6894 while (++index < length) {
6895 var codePoint = Number(arguments[index]);
6896 if (
6897 !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
6898 codePoint < 0 || // not a valid Unicode code point
6899 codePoint > 0x10FFFF || // not a valid Unicode code point
6900 floor(codePoint) != codePoint // not an integer
6901 ) {
6902 throw RangeError('Invalid code point: ' + codePoint);
6903 }
6904 if (codePoint <= 0xFFFF) {
6905 // BMP code point
6906 codeUnits.push(codePoint);
6907 } else {
6908 // Astral code point; split in surrogate halves
6909 // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
6910 codePoint -= 0x10000;
6911 highSurrogate = (codePoint >> 10) + 0xD800;
6912 lowSurrogate = (codePoint % 0x400) + 0xDC00;
6913 codeUnits.push(highSurrogate, lowSurrogate);
6914 }
6915 if (index + 1 == length || codeUnits.length > MAX_SIZE) {
6916 result += stringFromCharCode.apply(null, codeUnits);
6917 codeUnits.length = 0;
6918 }
6919 }
6920 return result;
6921 }
6922
6923 /*--------------------------------------------------------------------------*/
6924
6925 // Ensures that nodes have the correct types.
6926 var assertTypeRegexMap = {};
6927 function assertType(type, expected) {
6928 if (expected.indexOf('|') == -1) {
6929 if (type == expected) {
6930 return;
6931 }
6932
6933 throw Error('Invalid node type: ' + type + '; expected type: ' + expected);
6934 }
6935
6936 expected = hasOwnProperty.call(assertTypeRegexMap, expected)
6937 ? assertTypeRegexMap[expected]
6938 : (assertTypeRegexMap[expected] = RegExp('^(?:' + expected + ')$'));
6939
6940 if (expected.test(type)) {
6941 return;
6942 }
6943
6944 throw Error('Invalid node type: ' + type + '; expected types: ' + expected);
6945 }
6946
6947 /*--------------------------------------------------------------------------*/
6948
6949 // Generates a regular expression string based on an AST.
6950 function generate(node) {
6951 var type = node.type;
6952
6953 if (hasOwnProperty.call(generators, type)) {
6954 return generators[type](node);
6955 }
6956
6957 throw Error('Invalid node type: ' + type);
6958 }
6959
6960 /*--------------------------------------------------------------------------*/
6961
6962 function generateAlternative(node) {
6963 assertType(node.type, 'alternative');
6964
6965 var terms = node.body,
6966 i = -1,
6967 length = terms.length,
6968 result = '';
6969
6970 while (++i < length) {
6971 result += generateTerm(terms[i]);
6972 }
6973
6974 return result;
6975 }
6976
6977 function generateAnchor(node) {
6978 assertType(node.type, 'anchor');
6979
6980 switch (node.kind) {
6981 case 'start':
6982 return '^';
6983 case 'end':
6984 return '$';
6985 case 'boundary':
6986 return '\\b';
6987 case 'not-boundary':
6988 return '\\B';
6989 default:
6990 throw Error('Invalid assertion');
6991 }
6992 }
6993
6994 function generateAtom(node) {
6995 assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
6996
6997 return generate(node);
6998 }
6999
7000 function generateCharacterClass(node) {
7001 assertType(node.type, 'characterClass');
7002
7003 var classRanges = node.body,
7004 i = -1,
7005 length = classRanges.length,
7006 result = '';
7007
7008 if (node.negative) {
7009 result += '^';
7010 }
7011
7012 while (++i < length) {
7013 result += generateClassAtom(classRanges[i]);
7014 }
7015
7016 return '[' + result + ']';
7017 }
7018
7019 function generateCharacterClassEscape(node) {
7020 assertType(node.type, 'characterClassEscape');
7021
7022 return '\\' + node.value;
7023 }
7024
7025 function generateUnicodePropertyEscape(node) {
7026 assertType(node.type, 'unicodePropertyEscape');
7027
7028 return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
7029 }
7030
7031 function generateCharacterClassRange(node) {
7032 assertType(node.type, 'characterClassRange');
7033
7034 var min = node.min,
7035 max = node.max;
7036
7037 if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
7038 throw Error('Invalid character class range');
7039 }
7040
7041 return generateClassAtom(min) + '-' + generateClassAtom(max);
7042 }
7043
7044 function generateClassAtom(node) {
7045 assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value');
7046
7047 return generate(node);
7048 }
7049
7050 function generateDisjunction(node) {
7051 assertType(node.type, 'disjunction');
7052
7053 var body = node.body,
7054 i = -1,
7055 length = body.length,
7056 result = '';
7057
7058 while (++i < length) {
7059 if (i != 0) {
7060 result += '|';
7061 }
7062 result += generate(body[i]);
7063 }
7064
7065 return result;
7066 }
7067
7068 function generateDot(node) {
7069 assertType(node.type, 'dot');
7070
7071 return '.';
7072 }
7073
7074 function generateGroup(node) {
7075 assertType(node.type, 'group');
7076
7077 var result = '';
7078
7079 switch (node.behavior) {
7080 case 'normal':
7081 break;
7082 case 'ignore':
7083 result += '?:';
7084 break;
7085 case 'lookahead':
7086 result += '?=';
7087 break;
7088 case 'negativeLookahead':
7089 result += '?!';
7090 break;
7091 default:
7092 throw Error('Invalid behaviour: ' + node.behaviour);
7093 }
7094
7095 var body = node.body,
7096 i = -1,
7097 length = body.length;
7098
7099 while (++i < length) {
7100 result += generate(body[i]);
7101 }
7102
7103 return '(' + result + ')';
7104 }
7105
7106 function generateQuantifier(node) {
7107 assertType(node.type, 'quantifier');
7108
7109 var quantifier = '',
7110 min = node.min,
7111 max = node.max;
7112
7113 if (max == null) {
7114 if (min == 0) {
7115 quantifier = '*';
7116 } else if (min == 1) {
7117 quantifier = '+';
7118 } else {
7119 quantifier = '{' + min + ',}';
7120 }
7121 } else if (min == max) {
7122 quantifier = '{' + min + '}';
7123 } else if (min == 0 && max == 1) {
7124 quantifier = '?';
7125 } else {
7126 quantifier = '{' + min + ',' + max + '}';
7127 }
7128
7129 if (!node.greedy) {
7130 quantifier += '?';
7131 }
7132
7133 return generateAtom(node.body[0]) + quantifier;
7134 }
7135
7136 function generateReference(node) {
7137 assertType(node.type, 'reference');
7138
7139 return '\\' + node.matchIndex;
7140 }
7141
7142 function generateTerm(node) {
7143 assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value');
7144
7145 return generate(node);
7146 }
7147
7148 function generateValue(node) {
7149 assertType(node.type, 'value');
7150
7151 var kind = node.kind,
7152 codePoint = node.codePoint;
7153
7154 switch (kind) {
7155 case 'controlLetter':
7156 return '\\c' + fromCodePoint(codePoint + 64);
7157 case 'hexadecimalEscape':
7158 return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
7159 case 'identifier':
7160 return '\\' + fromCodePoint(codePoint);
7161 case 'null':
7162 return '\\' + codePoint;
7163 case 'octal':
7164 return '\\' + codePoint.toString(8);
7165 case 'singleEscape':
7166 switch (codePoint) {
7167 case 0x0008:
7168 return '\\b';
7169 case 0x0009:
7170 return '\\t';
7171 case 0x000A:
7172 return '\\n';
7173 case 0x000B:
7174 return '\\v';
7175 case 0x000C:
7176 return '\\f';
7177 case 0x000D:
7178 return '\\r';
7179 default:
7180 throw Error('Invalid codepoint: ' + codePoint);
7181 }
7182 case 'symbol':
7183 return fromCodePoint(codePoint);
7184 case 'unicodeEscape':
7185 return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
7186 case 'unicodeCodePointEscape':
7187 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
7188 default:
7189 throw Error('Unsupported node kind: ' + kind);
7190 }
7191 }
7192
7193 /*--------------------------------------------------------------------------*/
7194
7195 // Used to generate strings for each node type.
7196 var generators = {
7197 'alternative': generateAlternative,
7198 'anchor': generateAnchor,
7199 'characterClass': generateCharacterClass,
7200 'characterClassEscape': generateCharacterClassEscape,
7201 'characterClassRange': generateCharacterClassRange,
7202 'unicodePropertyEscape': generateUnicodePropertyEscape,
7203 'disjunction': generateDisjunction,
7204 'dot': generateDot,
7205 'group': generateGroup,
7206 'quantifier': generateQuantifier,
7207 'reference': generateReference,
7208 'value': generateValue
7209 };
7210
7211 /*--------------------------------------------------------------------------*/
7212
7213 // Export regjsgen.
7214 // Some AMD build optimizers, like r.js, check for condition patterns like the following:
7215 if (typeof undefined == 'function' && typeof undefined.amd == 'object' && undefined.amd) {
7216 // Define as an anonymous module so it can be aliased through path mapping.
7217 undefined(function() {
7218 return {
7219 'generate': generate
7220 };
7221 });
7222 }
7223 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
7224 else if (freeExports && freeModule) {
7225 // Export for CommonJS support.
7226 freeExports.generate = generate;
7227 }
7228 else {
7229 // Export to the global object.
7230 root.regjsgen = {
7231 'generate': generate
7232 };
7233 }
7234}.call(commonjsGlobal));
7235});
7236
7237var parser = createCommonjsModule(function (module) {
7238// regjsparser
7239//
7240// ==================================================================
7241//
7242// See ECMA-262 Standard: 15.10.1
7243//
7244// NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the
7245// term "Anchor" is used.
7246//
7247// Pattern ::
7248// Disjunction
7249//
7250// Disjunction ::
7251// Alternative
7252// Alternative | Disjunction
7253//
7254// Alternative ::
7255// [empty]
7256// Alternative Term
7257//
7258// Term ::
7259// Anchor
7260// Atom
7261// Atom Quantifier
7262//
7263// Anchor ::
7264// ^
7265// $
7266// \ b
7267// \ B
7268// ( ? = Disjunction )
7269// ( ? ! Disjunction )
7270//
7271// Quantifier ::
7272// QuantifierPrefix
7273// QuantifierPrefix ?
7274//
7275// QuantifierPrefix ::
7276// *
7277// +
7278// ?
7279// { DecimalDigits }
7280// { DecimalDigits , }
7281// { DecimalDigits , DecimalDigits }
7282//
7283// Atom ::
7284// PatternCharacter
7285// .
7286// \ AtomEscape
7287// CharacterClass
7288// ( Disjunction )
7289// ( ? : Disjunction )
7290//
7291// PatternCharacter ::
7292// SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |
7293//
7294// AtomEscape ::
7295// DecimalEscape
7296// CharacterEscape
7297// CharacterClassEscape
7298//
7299// CharacterEscape[U] ::
7300// ControlEscape
7301// c ControlLetter
7302// HexEscapeSequence
7303// RegExpUnicodeEscapeSequence[?U] (ES6)
7304// IdentityEscape[?U]
7305//
7306// ControlEscape ::
7307// one of f n r t v
7308// ControlLetter ::
7309// one of
7310// 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
7311// 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
7312//
7313// IdentityEscape ::
7314// SourceCharacter but not IdentifierPart
7315// <ZWJ>
7316// <ZWNJ>
7317//
7318// DecimalEscape ::
7319// DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
7320//
7321// CharacterClassEscape ::
7322// one of d D s S w W
7323//
7324// CharacterClass ::
7325// [ [lookahead ∉ {^}] ClassRanges ]
7326// [ ^ ClassRanges ]
7327//
7328// ClassRanges ::
7329// [empty]
7330// NonemptyClassRanges
7331//
7332// NonemptyClassRanges ::
7333// ClassAtom
7334// ClassAtom NonemptyClassRangesNoDash
7335// ClassAtom - ClassAtom ClassRanges
7336//
7337// NonemptyClassRangesNoDash ::
7338// ClassAtom
7339// ClassAtomNoDash NonemptyClassRangesNoDash
7340// ClassAtomNoDash - ClassAtom ClassRanges
7341//
7342// ClassAtom ::
7343// -
7344// ClassAtomNoDash
7345//
7346// ClassAtomNoDash ::
7347// SourceCharacter but not one of \ or ] or -
7348// \ ClassEscape
7349//
7350// ClassEscape ::
7351// DecimalEscape
7352// b
7353// CharacterEscape
7354// CharacterClassEscape
7355
7356(function() {
7357
7358 function parse(str, flags, features) {
7359 if (!features) {
7360 features = {};
7361 }
7362 function addRaw(node) {
7363 node.raw = str.substring(node.range[0], node.range[1]);
7364 return node;
7365 }
7366
7367 function updateRawStart(node, start) {
7368 node.range[0] = start;
7369 return addRaw(node);
7370 }
7371
7372 function createAnchor(kind, rawLength) {
7373 return addRaw({
7374 type: 'anchor',
7375 kind: kind,
7376 range: [
7377 pos - rawLength,
7378 pos
7379 ]
7380 });
7381 }
7382
7383 function createValue(kind, codePoint, from, to) {
7384 return addRaw({
7385 type: 'value',
7386 kind: kind,
7387 codePoint: codePoint,
7388 range: [from, to]
7389 });
7390 }
7391
7392 function createEscaped(kind, codePoint, value, fromOffset) {
7393 fromOffset = fromOffset || 0;
7394 return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);
7395 }
7396
7397 function createCharacter(matches) {
7398 var _char = matches[0];
7399 var first = _char.charCodeAt(0);
7400 if (hasUnicodeFlag) {
7401 var second;
7402 if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
7403 second = lookahead().charCodeAt(0);
7404 if (second >= 0xDC00 && second <= 0xDFFF) {
7405 // Unicode surrogate pair
7406 pos++;
7407 return createValue(
7408 'symbol',
7409 (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,
7410 pos - 2, pos);
7411 }
7412 }
7413 }
7414 return createValue('symbol', first, pos - 1, pos);
7415 }
7416
7417 function createDisjunction(alternatives, from, to) {
7418 return addRaw({
7419 type: 'disjunction',
7420 body: alternatives,
7421 range: [
7422 from,
7423 to
7424 ]
7425 });
7426 }
7427
7428 function createDot() {
7429 return addRaw({
7430 type: 'dot',
7431 range: [
7432 pos - 1,
7433 pos
7434 ]
7435 });
7436 }
7437
7438 function createCharacterClassEscape(value) {
7439 return addRaw({
7440 type: 'characterClassEscape',
7441 value: value,
7442 range: [
7443 pos - 2,
7444 pos
7445 ]
7446 });
7447 }
7448
7449 function createReference(matchIndex) {
7450 return addRaw({
7451 type: 'reference',
7452 matchIndex: parseInt(matchIndex, 10),
7453 range: [
7454 pos - 1 - matchIndex.length,
7455 pos
7456 ]
7457 });
7458 }
7459
7460 function createGroup(behavior, disjunction, from, to) {
7461 return addRaw({
7462 type: 'group',
7463 behavior: behavior,
7464 body: disjunction,
7465 range: [
7466 from,
7467 to
7468 ]
7469 });
7470 }
7471
7472 function createQuantifier(min, max, from, to) {
7473 if (to == null) {
7474 from = pos - 1;
7475 to = pos;
7476 }
7477
7478 return addRaw({
7479 type: 'quantifier',
7480 min: min,
7481 max: max,
7482 greedy: true,
7483 body: null, // set later on
7484 range: [
7485 from,
7486 to
7487 ]
7488 });
7489 }
7490
7491 function createAlternative(terms, from, to) {
7492 return addRaw({
7493 type: 'alternative',
7494 body: terms,
7495 range: [
7496 from,
7497 to
7498 ]
7499 });
7500 }
7501
7502 function createCharacterClass(classRanges, negative, from, to) {
7503 return addRaw({
7504 type: 'characterClass',
7505 body: classRanges,
7506 negative: negative,
7507 range: [
7508 from,
7509 to
7510 ]
7511 });
7512 }
7513
7514 function createClassRange(min, max, from, to) {
7515 // See 15.10.2.15:
7516 if (min.codePoint > max.codePoint) {
7517 bail('invalid range in character class', min.raw + '-' + max.raw, from, to);
7518 }
7519
7520 return addRaw({
7521 type: 'characterClassRange',
7522 min: min,
7523 max: max,
7524 range: [
7525 from,
7526 to
7527 ]
7528 });
7529 }
7530
7531 function flattenBody(body) {
7532 if (body.type === 'alternative') {
7533 return body.body;
7534 } else {
7535 return [body];
7536 }
7537 }
7538
7539 function incr(amount) {
7540 amount = (amount || 1);
7541 var res = str.substring(pos, pos + amount);
7542 pos += (amount || 1);
7543 return res;
7544 }
7545
7546 function skip(value) {
7547 if (!match(value)) {
7548 bail('character', value);
7549 }
7550 }
7551
7552 function match(value) {
7553 if (str.indexOf(value, pos) === pos) {
7554 return incr(value.length);
7555 }
7556 }
7557
7558 function lookahead() {
7559 return str[pos];
7560 }
7561
7562 function current(value) {
7563 return str.indexOf(value, pos) === pos;
7564 }
7565
7566 function next(value) {
7567 return str[pos + 1] === value;
7568 }
7569
7570 function matchReg(regExp) {
7571 var subStr = str.substring(pos);
7572 var res = subStr.match(regExp);
7573 if (res) {
7574 res.range = [];
7575 res.range[0] = pos;
7576 incr(res[0].length);
7577 res.range[1] = pos;
7578 }
7579 return res;
7580 }
7581
7582 function parseDisjunction() {
7583 // Disjunction ::
7584 // Alternative
7585 // Alternative | Disjunction
7586 var res = [], from = pos;
7587 res.push(parseAlternative());
7588
7589 while (match('|')) {
7590 res.push(parseAlternative());
7591 }
7592
7593 if (res.length === 1) {
7594 return res[0];
7595 }
7596
7597 return createDisjunction(res, from, pos);
7598 }
7599
7600 function parseAlternative() {
7601 var res = [], from = pos;
7602 var term;
7603
7604 // Alternative ::
7605 // [empty]
7606 // Alternative Term
7607 while (term = parseTerm()) {
7608 res.push(term);
7609 }
7610
7611 if (res.length === 1) {
7612 return res[0];
7613 }
7614
7615 return createAlternative(res, from, pos);
7616 }
7617
7618 function parseTerm() {
7619 // Term ::
7620 // Anchor
7621 // Atom
7622 // Atom Quantifier
7623
7624 if (pos >= str.length || current('|') || current(')')) {
7625 return null; /* Means: The term is empty */
7626 }
7627
7628 var anchor = parseAnchor();
7629
7630 if (anchor) {
7631 return anchor;
7632 }
7633
7634 var atom = parseAtom();
7635 if (!atom) {
7636 bail('Expected atom');
7637 }
7638 var quantifier = parseQuantifier() || false;
7639 if (quantifier) {
7640 quantifier.body = flattenBody(atom);
7641 // The quantifier contains the atom. Therefore, the beginning of the
7642 // quantifier range is given by the beginning of the atom.
7643 updateRawStart(quantifier, atom.range[0]);
7644 return quantifier;
7645 }
7646 return atom;
7647 }
7648
7649 function parseGroup(matchA, typeA, matchB, typeB) {
7650 var type = null, from = pos;
7651
7652 if (match(matchA)) {
7653 type = typeA;
7654 } else if (match(matchB)) {
7655 type = typeB;
7656 } else {
7657 return false;
7658 }
7659
7660 var body = parseDisjunction();
7661 if (!body) {
7662 bail('Expected disjunction');
7663 }
7664 skip(')');
7665 var group = createGroup(type, flattenBody(body), from, pos);
7666
7667 if (type == 'normal') {
7668 // Keep track of the number of closed groups. This is required for
7669 // parseDecimalEscape(). In case the string is parsed a second time the
7670 // value already holds the total count and no incrementation is required.
7671 if (firstIteration) {
7672 closedCaptureCounter++;
7673 }
7674 }
7675 return group;
7676 }
7677
7678 function parseAnchor() {
7679 // Anchor ::
7680 // ^
7681 // $
7682 // \ b
7683 // \ B
7684 // ( ? = Disjunction )
7685 // ( ? ! Disjunction )
7686 if (match('^')) {
7687 return createAnchor('start', 1 /* rawLength */);
7688 } else if (match('$')) {
7689 return createAnchor('end', 1 /* rawLength */);
7690 } else if (match('\\b')) {
7691 return createAnchor('boundary', 2 /* rawLength */);
7692 } else if (match('\\B')) {
7693 return createAnchor('not-boundary', 2 /* rawLength */);
7694 } else {
7695 return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');
7696 }
7697 }
7698
7699 function parseQuantifier() {
7700 // Quantifier ::
7701 // QuantifierPrefix
7702 // QuantifierPrefix ?
7703 //
7704 // QuantifierPrefix ::
7705 // *
7706 // +
7707 // ?
7708 // { DecimalDigits }
7709 // { DecimalDigits , }
7710 // { DecimalDigits , DecimalDigits }
7711
7712 var res, from = pos;
7713 var quantifier;
7714 var min, max;
7715
7716 if (match('*')) {
7717 quantifier = createQuantifier(0);
7718 }
7719 else if (match('+')) {
7720 quantifier = createQuantifier(1);
7721 }
7722 else if (match('?')) {
7723 quantifier = createQuantifier(0, 1);
7724 }
7725 else if (res = matchReg(/^\{([0-9]+)\}/)) {
7726 min = parseInt(res[1], 10);
7727 quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
7728 }
7729 else if (res = matchReg(/^\{([0-9]+),\}/)) {
7730 min = parseInt(res[1], 10);
7731 quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
7732 }
7733 else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
7734 min = parseInt(res[1], 10);
7735 max = parseInt(res[2], 10);
7736 if (min > max) {
7737 bail('numbers out of order in {} quantifier', '', from, pos);
7738 }
7739 quantifier = createQuantifier(min, max, res.range[0], res.range[1]);
7740 }
7741
7742 if (quantifier) {
7743 if (match('?')) {
7744 quantifier.greedy = false;
7745 quantifier.range[1] += 1;
7746 }
7747 }
7748
7749 return quantifier;
7750 }
7751
7752 function parseAtom() {
7753 // Atom ::
7754 // PatternCharacter
7755 // .
7756 // \ AtomEscape
7757 // CharacterClass
7758 // ( Disjunction )
7759 // ( ? : Disjunction )
7760
7761 var res;
7762
7763 // jviereck: allow ']', '}' here as well to be compatible with browser's
7764 // implementations: ']'.match(/]/);
7765 // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) {
7766 if (res = matchReg(/^[^^$\\.*+?(){[|]/)) {
7767 // PatternCharacter
7768 return createCharacter(res);
7769 }
7770 else if (match('.')) {
7771 // .
7772 return createDot();
7773 }
7774 else if (match('\\')) {
7775 // \ AtomEscape
7776 res = parseAtomEscape();
7777 if (!res) {
7778 bail('atomEscape');
7779 }
7780 return res;
7781 }
7782 else if (res = parseCharacterClass()) {
7783 return res;
7784 }
7785 else {
7786 // ( Disjunction )
7787 // ( ? : Disjunction )
7788 return parseGroup('(?:', 'ignore', '(', 'normal');
7789 }
7790 }
7791
7792 function parseUnicodeSurrogatePairEscape(firstEscape) {
7793 if (hasUnicodeFlag) {
7794 var first, second;
7795 if (firstEscape.kind == 'unicodeEscape' &&
7796 (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&
7797 current('\\') && next('u') ) {
7798 var prevPos = pos;
7799 pos++;
7800 var secondEscape = parseClassEscape();
7801 if (secondEscape.kind == 'unicodeEscape' &&
7802 (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {
7803 // Unicode surrogate pair
7804 firstEscape.range[1] = secondEscape.range[1];
7805 firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
7806 firstEscape.type = 'value';
7807 firstEscape.kind = 'unicodeCodePointEscape';
7808 addRaw(firstEscape);
7809 }
7810 else {
7811 pos = prevPos;
7812 }
7813 }
7814 }
7815 return firstEscape;
7816 }
7817
7818 function parseClassEscape() {
7819 return parseAtomEscape(true);
7820 }
7821
7822 function parseAtomEscape(insideCharacterClass) {
7823 // AtomEscape ::
7824 // DecimalEscape
7825 // CharacterEscape
7826 // CharacterClassEscape
7827
7828 var res, from = pos;
7829
7830 res = parseDecimalEscape();
7831 if (res) {
7832 return res;
7833 }
7834
7835 // For ClassEscape
7836 if (insideCharacterClass) {
7837 if (match('b')) {
7838 // 15.10.2.19
7839 // The production ClassEscape :: b evaluates by returning the
7840 // CharSet containing the one character <BS> (Unicode value 0008).
7841 return createEscaped('singleEscape', 0x0008, '\\b');
7842 } else if (match('B')) {
7843 bail('\\B not possible inside of CharacterClass', '', from);
7844 }
7845 }
7846
7847 res = parseCharacterEscape();
7848
7849 return res;
7850 }
7851
7852
7853 function parseDecimalEscape() {
7854 // DecimalEscape ::
7855 // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
7856 // CharacterClassEscape :: one of d D s S w W
7857
7858 var res, match;
7859
7860 if (res = matchReg(/^(?!0)\d+/)) {
7861 match = res[0];
7862 var refIdx = parseInt(res[0], 10);
7863 if (refIdx <= closedCaptureCounter) {
7864 // If the number is smaller than the normal-groups found so
7865 // far, then it is a reference...
7866 return createReference(res[0]);
7867 } else {
7868 // ... otherwise it needs to be interpreted as a octal (if the
7869 // number is in an octal format). If it is NOT octal format,
7870 // then the slash is ignored and the number is matched later
7871 // as normal characters.
7872
7873 // Recall the negative decision to decide if the input must be parsed
7874 // a second time with the total normal-groups.
7875 backrefDenied.push(refIdx);
7876
7877 // Reset the position again, as maybe only parts of the previous
7878 // matched numbers are actual octal numbers. E.g. in '019' only
7879 // the '01' should be matched.
7880 incr(-res[0].length);
7881 if (res = matchReg(/^[0-7]{1,3}/)) {
7882 return createEscaped('octal', parseInt(res[0], 8), res[0], 1);
7883 } else {
7884 // If we end up here, we have a case like /\91/. Then the
7885 // first slash is to be ignored and the 9 & 1 to be treated
7886 // like ordinary characters. Create a character for the
7887 // first number only here - other number-characters
7888 // (if available) will be matched later.
7889 res = createCharacter(matchReg(/^[89]/));
7890 return updateRawStart(res, res.range[0] - 1);
7891 }
7892 }
7893 }
7894 // Only allow octal numbers in the following. All matched numbers start
7895 // with a zero (if the do not, the previous if-branch is executed).
7896 // If the number is not octal format and starts with zero (e.g. `091`)
7897 // then only the zeros `0` is treated here and the `91` are ordinary
7898 // characters.
7899 // Example:
7900 // /\091/.exec('\091')[0].length === 3
7901 else if (res = matchReg(/^[0-7]{1,3}/)) {
7902 match = res[0];
7903 if (/^0{1,3}$/.test(match)) {
7904 // If they are all zeros, then only take the first one.
7905 return createEscaped('null', 0x0000, '0', match.length + 1);
7906 } else {
7907 return createEscaped('octal', parseInt(match, 8), match, 1);
7908 }
7909 } else if (res = matchReg(/^[dDsSwW]/)) {
7910 return createCharacterClassEscape(res[0]);
7911 }
7912 return false;
7913 }
7914
7915 function parseCharacterEscape() {
7916 // CharacterEscape ::
7917 // ControlEscape
7918 // c ControlLetter
7919 // HexEscapeSequence
7920 // UnicodeEscapeSequence
7921 // IdentityEscape
7922
7923 var res;
7924 if (res = matchReg(/^[fnrtv]/)) {
7925 // ControlEscape
7926 var codePoint = 0;
7927 switch (res[0]) {
7928 case 't': codePoint = 0x009; break;
7929 case 'n': codePoint = 0x00A; break;
7930 case 'v': codePoint = 0x00B; break;
7931 case 'f': codePoint = 0x00C; break;
7932 case 'r': codePoint = 0x00D; break;
7933 }
7934 return createEscaped('singleEscape', codePoint, '\\' + res[0]);
7935 } else if (res = matchReg(/^c([a-zA-Z])/)) {
7936 // c ControlLetter
7937 return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);
7938 } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) {
7939 // HexEscapeSequence
7940 return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2);
7941 } else if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {
7942 // UnicodeEscapeSequence
7943 return parseUnicodeSurrogatePairEscape(
7944 createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2)
7945 );
7946 } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {
7947 // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)
7948 return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);
7949 } else if (features.unicodePropertyEscape && hasUnicodeFlag && (res = matchReg(/^([pP])\{([^\}]+)\}/))) {
7950 // https://github.com/jviereck/regjsparser/issues/77
7951 return addRaw({
7952 type: 'unicodePropertyEscape',
7953 negative: res[1] === 'P',
7954 value: res[2],
7955 range: [res.range[0] - 1, res.range[1]],
7956 raw: res[0]
7957 });
7958 } else {
7959 // IdentityEscape
7960 return parseIdentityEscape();
7961 }
7962 }
7963
7964 // Taken from the Esprima parser.
7965 function isIdentifierPart(ch) {
7966 // Generated by `tools/generate-identifier-regex.js`.
7967 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]');
7968
7969 return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
7970 (ch >= 65 && ch <= 90) || // A..Z
7971 (ch >= 97 && ch <= 122) || // a..z
7972 (ch >= 48 && ch <= 57) || // 0..9
7973 (ch === 92) || // \ (backslash)
7974 ((ch >= 0x80) && NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
7975 }
7976
7977 function parseIdentityEscape() {
7978 // IdentityEscape ::
7979 // SourceCharacter but not IdentifierPart
7980 // <ZWJ>
7981 // <ZWNJ>
7982
7983 var ZWJ = '\u200C';
7984 var ZWNJ = '\u200D';
7985
7986 var tmp;
7987
7988 if (!isIdentifierPart(lookahead())) {
7989 tmp = incr();
7990 return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1);
7991 }
7992
7993 if (match(ZWJ)) {
7994 // <ZWJ>
7995 return createEscaped('identifier', 0x200C, ZWJ);
7996 } else if (match(ZWNJ)) {
7997 // <ZWNJ>
7998 return createEscaped('identifier', 0x200D, ZWNJ);
7999 }
8000
8001 return null;
8002 }
8003
8004 function parseCharacterClass() {
8005 // CharacterClass ::
8006 // [ [lookahead ∉ {^}] ClassRanges ]
8007 // [ ^ ClassRanges ]
8008
8009 var res, from = pos;
8010 if (res = matchReg(/^\[\^/)) {
8011 res = parseClassRanges();
8012 skip(']');
8013 return createCharacterClass(res, true, from, pos);
8014 } else if (match('[')) {
8015 res = parseClassRanges();
8016 skip(']');
8017 return createCharacterClass(res, false, from, pos);
8018 }
8019
8020 return null;
8021 }
8022
8023 function parseClassRanges() {
8024 // ClassRanges ::
8025 // [empty]
8026 // NonemptyClassRanges
8027
8028 var res;
8029 if (current(']')) {
8030 // Empty array means nothing insinde of the ClassRange.
8031 return [];
8032 } else {
8033 res = parseNonemptyClassRanges();
8034 if (!res) {
8035 bail('nonEmptyClassRanges');
8036 }
8037 return res;
8038 }
8039 }
8040
8041 function parseHelperClassRanges(atom) {
8042 var from, to, res;
8043 if (current('-') && !next(']')) {
8044 // ClassAtom - ClassAtom ClassRanges
8045 skip('-');
8046
8047 res = parseClassAtom();
8048 if (!res) {
8049 bail('classAtom');
8050 }
8051 to = pos;
8052 var classRanges = parseClassRanges();
8053 if (!classRanges) {
8054 bail('classRanges');
8055 }
8056 from = atom.range[0];
8057 if (classRanges.type === 'empty') {
8058 return [createClassRange(atom, res, from, to)];
8059 }
8060 return [createClassRange(atom, res, from, to)].concat(classRanges);
8061 }
8062
8063 res = parseNonemptyClassRangesNoDash();
8064 if (!res) {
8065 bail('nonEmptyClassRangesNoDash');
8066 }
8067
8068 return [atom].concat(res);
8069 }
8070
8071 function parseNonemptyClassRanges() {
8072 // NonemptyClassRanges ::
8073 // ClassAtom
8074 // ClassAtom NonemptyClassRangesNoDash
8075 // ClassAtom - ClassAtom ClassRanges
8076
8077 var atom = parseClassAtom();
8078 if (!atom) {
8079 bail('classAtom');
8080 }
8081
8082 if (current(']')) {
8083 // ClassAtom
8084 return [atom];
8085 }
8086
8087 // ClassAtom NonemptyClassRangesNoDash
8088 // ClassAtom - ClassAtom ClassRanges
8089 return parseHelperClassRanges(atom);
8090 }
8091
8092 function parseNonemptyClassRangesNoDash() {
8093 // NonemptyClassRangesNoDash ::
8094 // ClassAtom
8095 // ClassAtomNoDash NonemptyClassRangesNoDash
8096 // ClassAtomNoDash - ClassAtom ClassRanges
8097
8098 var res = parseClassAtom();
8099 if (!res) {
8100 bail('classAtom');
8101 }
8102 if (current(']')) {
8103 // ClassAtom
8104 return res;
8105 }
8106
8107 // ClassAtomNoDash NonemptyClassRangesNoDash
8108 // ClassAtomNoDash - ClassAtom ClassRanges
8109 return parseHelperClassRanges(res);
8110 }
8111
8112 function parseClassAtom() {
8113 // ClassAtom ::
8114 // -
8115 // ClassAtomNoDash
8116 if (match('-')) {
8117 return createCharacter('-');
8118 } else {
8119 return parseClassAtomNoDash();
8120 }
8121 }
8122
8123 function parseClassAtomNoDash() {
8124 // ClassAtomNoDash ::
8125 // SourceCharacter but not one of \ or ] or -
8126 // \ ClassEscape
8127
8128 var res;
8129 if (res = matchReg(/^[^\\\]-]/)) {
8130 return createCharacter(res[0]);
8131 } else if (match('\\')) {
8132 res = parseClassEscape();
8133 if (!res) {
8134 bail('classEscape');
8135 }
8136
8137 return parseUnicodeSurrogatePairEscape(res);
8138 }
8139 }
8140
8141 function bail(message, details, from, to) {
8142 from = from == null ? pos : from;
8143 to = to == null ? from : to;
8144
8145 var contextStart = Math.max(0, from - 10);
8146 var contextEnd = Math.min(to + 10, str.length);
8147
8148 // Output a bit of context and a line pointing to where our error is.
8149 //
8150 // We are assuming that there are no actual newlines in the content as this is a regular expression.
8151 var context = ' ' + str.substring(contextStart, contextEnd);
8152 var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^';
8153
8154 throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer);
8155 }
8156
8157 var backrefDenied = [];
8158 var closedCaptureCounter = 0;
8159 var firstIteration = true;
8160 var hasUnicodeFlag = (flags || "").indexOf("u") !== -1;
8161 var pos = 0;
8162
8163 // Convert the input to a string and treat the empty string special.
8164 str = String(str);
8165 if (str === '') {
8166 str = '(?:)';
8167 }
8168
8169 var result = parseDisjunction();
8170
8171 if (result.range[1] !== str.length) {
8172 bail('Could not parse entire input - got stuck', '', result.range[1]);
8173 }
8174
8175 // The spec requires to interpret the `\2` in `/\2()()/` as backreference.
8176 // As the parser collects the number of capture groups as the string is
8177 // parsed it is impossible to make these decisions at the point when the
8178 // `\2` is handled. In case the local decision turns out to be wrong after
8179 // the parsing has finished, the input string is parsed a second time with
8180 // the total number of capture groups set.
8181 //
8182 // SEE: https://github.com/jviereck/regjsparser/issues/70
8183 for (var i = 0; i < backrefDenied.length; i++) {
8184 if (backrefDenied[i] <= closedCaptureCounter) {
8185 // Parse the input a second time.
8186 pos = 0;
8187 firstIteration = false;
8188 return parseDisjunction();
8189 }
8190 }
8191
8192 return result;
8193 }
8194
8195 var regjsparser = {
8196 parse: parse
8197 };
8198
8199 if ('object' !== 'undefined' && module.exports) {
8200 module.exports = regjsparser;
8201 } else {
8202 window.regjsparser = regjsparser;
8203 }
8204
8205}());
8206});
8207
8208var regenerate = createCommonjsModule(function (module, exports) {
8209/*! https://mths.be/regenerate v1.3.3 by @mathias | MIT license */
8210(function(root) {
8211
8212 // Detect free variables `exports`.
8213 var freeExports = 'object' == 'object' && exports;
8214
8215 // Detect free variable `module`.
8216 var freeModule = 'object' == 'object' && module &&
8217 module.exports == freeExports && module;
8218
8219 // Detect free variable `global`, from Node.js/io.js or Browserified code,
8220 // and use it as `root`.
8221 var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
8222 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
8223 root = freeGlobal;
8224 }
8225
8226 /*--------------------------------------------------------------------------*/
8227
8228 var ERRORS = {
8229 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
8230 'to the `start` value.',
8231 'codePointRange': 'Invalid code point value. Code points range from ' +
8232 'U+000000 to U+10FFFF.'
8233 };
8234
8235 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
8236 var HIGH_SURROGATE_MIN = 0xD800;
8237 var HIGH_SURROGATE_MAX = 0xDBFF;
8238 var LOW_SURROGATE_MIN = 0xDC00;
8239 var LOW_SURROGATE_MAX = 0xDFFF;
8240
8241 // In Regenerate output, `\0` is never preceded by `\` because we sort by
8242 // code point value, so let’s keep this regular expression simple.
8243 var regexNull = /\\x00([^0123456789]|$)/g;
8244
8245 var object = {};
8246 var hasOwnProperty = object.hasOwnProperty;
8247 var extend = function(destination, source) {
8248 var key;
8249 for (key in source) {
8250 if (hasOwnProperty.call(source, key)) {
8251 destination[key] = source[key];
8252 }
8253 }
8254 return destination;
8255 };
8256
8257 var forEach = function(array, callback) {
8258 var index = -1;
8259 var length = array.length;
8260 while (++index < length) {
8261 callback(array[index], index);
8262 }
8263 };
8264
8265 var toString = object.toString;
8266 var isArray = function(value) {
8267 return toString.call(value) == '[object Array]';
8268 };
8269 var isNumber = function(value) {
8270 return typeof value == 'number' ||
8271 toString.call(value) == '[object Number]';
8272 };
8273
8274 // This assumes that `number` is a positive integer that `toString()`s nicely
8275 // (which is the case for all code point values).
8276 var zeroes = '0000';
8277 var pad = function(number, totalCharacters) {
8278 var string = String(number);
8279 return string.length < totalCharacters
8280 ? (zeroes + string).slice(-totalCharacters)
8281 : string;
8282 };
8283
8284 var hex = function(number) {
8285 return Number(number).toString(16).toUpperCase();
8286 };
8287
8288 var slice = [].slice;
8289
8290 /*--------------------------------------------------------------------------*/
8291
8292 var dataFromCodePoints = function(codePoints) {
8293 var index = -1;
8294 var length = codePoints.length;
8295 var max = length - 1;
8296 var result = [];
8297 var isStart = true;
8298 var tmp;
8299 var previous = 0;
8300 while (++index < length) {
8301 tmp = codePoints[index];
8302 if (isStart) {
8303 result.push(tmp);
8304 previous = tmp;
8305 isStart = false;
8306 } else {
8307 if (tmp == previous + 1) {
8308 if (index != max) {
8309 previous = tmp;
8310 continue;
8311 } else {
8312 isStart = true;
8313 result.push(tmp + 1);
8314 }
8315 } else {
8316 // End the previous range and start a new one.
8317 result.push(previous + 1, tmp);
8318 previous = tmp;
8319 }
8320 }
8321 }
8322 if (!isStart) {
8323 result.push(tmp + 1);
8324 }
8325 return result;
8326 };
8327
8328 var dataRemove = function(data, codePoint) {
8329 // Iterate over the data per `(start, end)` pair.
8330 var index = 0;
8331 var start;
8332 var end;
8333 var length = data.length;
8334 while (index < length) {
8335 start = data[index];
8336 end = data[index + 1];
8337 if (codePoint >= start && codePoint < end) {
8338 // Modify this pair.
8339 if (codePoint == start) {
8340 if (end == start + 1) {
8341 // Just remove `start` and `end`.
8342 data.splice(index, 2);
8343 return data;
8344 } else {
8345 // Just replace `start` with a new value.
8346 data[index] = codePoint + 1;
8347 return data;
8348 }
8349 } else if (codePoint == end - 1) {
8350 // Just replace `end` with a new value.
8351 data[index + 1] = codePoint;
8352 return data;
8353 } else {
8354 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
8355 data.splice(index, 2, start, codePoint, codePoint + 1, end);
8356 return data;
8357 }
8358 }
8359 index += 2;
8360 }
8361 return data;
8362 };
8363
8364 var dataRemoveRange = function(data, rangeStart, rangeEnd) {
8365 if (rangeEnd < rangeStart) {
8366 throw Error(ERRORS.rangeOrder);
8367 }
8368 // Iterate over the data per `(start, end)` pair.
8369 var index = 0;
8370 var start;
8371 var end;
8372 while (index < data.length) {
8373 start = data[index];
8374 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8375
8376 // Exit as soon as no more matching pairs can be found.
8377 if (start > rangeEnd) {
8378 return data;
8379 }
8380
8381 // Check if this range pair is equal to, or forms a subset of, the range
8382 // to be removed.
8383 // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
8384 // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
8385 if (rangeStart <= start && rangeEnd >= end) {
8386 // Remove this pair.
8387 data.splice(index, 2);
8388 continue;
8389 }
8390
8391 // Check if both `rangeStart` and `rangeEnd` are within the bounds of
8392 // this pair.
8393 // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
8394 if (rangeStart >= start && rangeEnd < end) {
8395 if (rangeStart == start) {
8396 // Replace `[start, end]` with `[startB, endB]`.
8397 data[index] = rangeEnd + 1;
8398 data[index + 1] = end + 1;
8399 return data;
8400 }
8401 // Replace `[start, end]` with `[startA, endA, startB, endB]`.
8402 data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
8403 return data;
8404 }
8405
8406 // Check if only `rangeStart` is within the bounds of this pair.
8407 // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
8408 if (rangeStart >= start && rangeStart <= end) {
8409 // Replace `end` with `rangeStart`.
8410 data[index + 1] = rangeStart;
8411 // Note: we cannot `return` just yet, in case any following pairs still
8412 // contain matching code points.
8413 // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
8414 // → `[0, 4, 21, 31]`.
8415 }
8416
8417 // Check if only `rangeEnd` is within the bounds of this pair.
8418 // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
8419 else if (rangeEnd >= start && rangeEnd <= end) {
8420 // Just replace `start`.
8421 data[index] = rangeEnd + 1;
8422 return data;
8423 }
8424
8425 index += 2;
8426 }
8427 return data;
8428 };
8429
8430 var dataAdd = function(data, codePoint) {
8431 // Iterate over the data per `(start, end)` pair.
8432 var index = 0;
8433 var start;
8434 var end;
8435 var lastIndex = null;
8436 var length = data.length;
8437 if (codePoint < 0x0 || codePoint > 0x10FFFF) {
8438 throw RangeError(ERRORS.codePointRange);
8439 }
8440 while (index < length) {
8441 start = data[index];
8442 end = data[index + 1];
8443
8444 // Check if the code point is already in the set.
8445 if (codePoint >= start && codePoint < end) {
8446 return data;
8447 }
8448
8449 if (codePoint == start - 1) {
8450 // Just replace `start` with a new value.
8451 data[index] = codePoint;
8452 return data;
8453 }
8454
8455 // At this point, if `start` is `greater` than `codePoint`, insert a new
8456 // `[start, end]` pair before the current pair, or after the current pair
8457 // if there is a known `lastIndex`.
8458 if (start > codePoint) {
8459 data.splice(
8460 lastIndex != null ? lastIndex + 2 : 0,
8461 0,
8462 codePoint,
8463 codePoint + 1
8464 );
8465 return data;
8466 }
8467
8468 if (codePoint == end) {
8469 // Check if adding this code point causes two separate ranges to become
8470 // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
8471 if (codePoint + 1 == data[index + 2]) {
8472 data.splice(index, 4, start, data[index + 3]);
8473 return data;
8474 }
8475 // Else, just replace `end` with a new value.
8476 data[index + 1] = codePoint + 1;
8477 return data;
8478 }
8479 lastIndex = index;
8480 index += 2;
8481 }
8482 // The loop has finished; add the new pair to the end of the data set.
8483 data.push(codePoint, codePoint + 1);
8484 return data;
8485 };
8486
8487 var dataAddData = function(dataA, dataB) {
8488 // Iterate over the data per `(start, end)` pair.
8489 var index = 0;
8490 var start;
8491 var end;
8492 var data = dataA.slice();
8493 var length = dataB.length;
8494 while (index < length) {
8495 start = dataB[index];
8496 end = dataB[index + 1] - 1;
8497 if (start == end) {
8498 data = dataAdd(data, start);
8499 } else {
8500 data = dataAddRange(data, start, end);
8501 }
8502 index += 2;
8503 }
8504 return data;
8505 };
8506
8507 var dataRemoveData = function(dataA, dataB) {
8508 // Iterate over the data per `(start, end)` pair.
8509 var index = 0;
8510 var start;
8511 var end;
8512 var data = dataA.slice();
8513 var length = dataB.length;
8514 while (index < length) {
8515 start = dataB[index];
8516 end = dataB[index + 1] - 1;
8517 if (start == end) {
8518 data = dataRemove(data, start);
8519 } else {
8520 data = dataRemoveRange(data, start, end);
8521 }
8522 index += 2;
8523 }
8524 return data;
8525 };
8526
8527 var dataAddRange = function(data, rangeStart, rangeEnd) {
8528 if (rangeEnd < rangeStart) {
8529 throw Error(ERRORS.rangeOrder);
8530 }
8531 if (
8532 rangeStart < 0x0 || rangeStart > 0x10FFFF ||
8533 rangeEnd < 0x0 || rangeEnd > 0x10FFFF
8534 ) {
8535 throw RangeError(ERRORS.codePointRange);
8536 }
8537 // Iterate over the data per `(start, end)` pair.
8538 var index = 0;
8539 var start;
8540 var end;
8541 var added = false;
8542 var length = data.length;
8543 while (index < length) {
8544 start = data[index];
8545 end = data[index + 1];
8546
8547 if (added) {
8548 // The range has already been added to the set; at this point, we just
8549 // need to get rid of the following ranges in case they overlap.
8550
8551 // Check if this range can be combined with the previous range.
8552 if (start == rangeEnd + 1) {
8553 data.splice(index - 1, 2);
8554 return data;
8555 }
8556
8557 // Exit as soon as no more possibly overlapping pairs can be found.
8558 if (start > rangeEnd) {
8559 return data;
8560 }
8561
8562 // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
8563 // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
8564 // `0,16` range that was previously added.
8565 if (start >= rangeStart && start <= rangeEnd) {
8566 // `start` lies within the range that was previously added.
8567
8568 if (end > rangeStart && end - 1 <= rangeEnd) {
8569 // `end` lies within the range that was previously added as well,
8570 // so remove this pair.
8571 data.splice(index, 2);
8572 index -= 2;
8573 // Note: we cannot `return` just yet, as there may still be other
8574 // overlapping pairs.
8575 } else {
8576 // `start` lies within the range that was previously added, but
8577 // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
8578 // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
8579 // Remove the previously added `end` and the current `start`.
8580 data.splice(index - 1, 2);
8581 index -= 2;
8582 }
8583
8584 // Note: we cannot return yet.
8585 }
8586
8587 }
8588
8589 else if (start == rangeEnd + 1) {
8590 data[index] = rangeStart;
8591 return data;
8592 }
8593
8594 // Check if a new pair must be inserted *before* the current one.
8595 else if (start > rangeEnd) {
8596 data.splice(index, 0, rangeStart, rangeEnd + 1);
8597 return data;
8598 }
8599
8600 else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
8601 // The new range lies entirely within an existing range pair. No action
8602 // needed.
8603 return data;
8604 }
8605
8606 else if (
8607 // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
8608 (rangeStart >= start && rangeStart < end) ||
8609 // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
8610 end == rangeStart
8611 ) {
8612 // Replace `end` with the new value.
8613 data[index + 1] = rangeEnd + 1;
8614 // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
8615 // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
8616 added = true;
8617 // Note: we cannot `return` just yet.
8618 }
8619
8620 else if (rangeStart <= start && rangeEnd + 1 >= end) {
8621 // The new range is a superset of the old range.
8622 data[index] = rangeStart;
8623 data[index + 1] = rangeEnd + 1;
8624 added = true;
8625 }
8626
8627 index += 2;
8628 }
8629 // The loop has finished without doing anything; add the new pair to the end
8630 // of the data set.
8631 if (!added) {
8632 data.push(rangeStart, rangeEnd + 1);
8633 }
8634 return data;
8635 };
8636
8637 var dataContains = function(data, codePoint) {
8638 var index = 0;
8639 var length = data.length;
8640 // Exit early if `codePoint` is not within `data`’s overall range.
8641 var start = data[index];
8642 var end = data[length - 1];
8643 if (length >= 2) {
8644 if (codePoint < start || codePoint > end) {
8645 return false;
8646 }
8647 }
8648 // Iterate over the data per `(start, end)` pair.
8649 while (index < length) {
8650 start = data[index];
8651 end = data[index + 1];
8652 if (codePoint >= start && codePoint < end) {
8653 return true;
8654 }
8655 index += 2;
8656 }
8657 return false;
8658 };
8659
8660 var dataIntersection = function(data, codePoints) {
8661 var index = 0;
8662 var length = codePoints.length;
8663 var codePoint;
8664 var result = [];
8665 while (index < length) {
8666 codePoint = codePoints[index];
8667 if (dataContains(data, codePoint)) {
8668 result.push(codePoint);
8669 }
8670 ++index;
8671 }
8672 return dataFromCodePoints(result);
8673 };
8674
8675 var dataIsEmpty = function(data) {
8676 return !data.length;
8677 };
8678
8679 var dataIsSingleton = function(data) {
8680 // Check if the set only represents a single code point.
8681 return data.length == 2 && data[0] + 1 == data[1];
8682 };
8683
8684 var dataToArray = function(data) {
8685 // Iterate over the data per `(start, end)` pair.
8686 var index = 0;
8687 var start;
8688 var end;
8689 var result = [];
8690 var length = data.length;
8691 while (index < length) {
8692 start = data[index];
8693 end = data[index + 1];
8694 while (start < end) {
8695 result.push(start);
8696 ++start;
8697 }
8698 index += 2;
8699 }
8700 return result;
8701 };
8702
8703 /*--------------------------------------------------------------------------*/
8704
8705 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
8706 var floor = Math.floor;
8707 var highSurrogate = function(codePoint) {
8708 return parseInt(
8709 floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
8710 10
8711 );
8712 };
8713
8714 var lowSurrogate = function(codePoint) {
8715 return parseInt(
8716 (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
8717 10
8718 );
8719 };
8720
8721 var stringFromCharCode = String.fromCharCode;
8722 var codePointToString = function(codePoint) {
8723 var string;
8724 // https://mathiasbynens.be/notes/javascript-escapes#single
8725 // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
8726 // different meaning in regular expressions (word boundary), so it cannot
8727 // be used here.
8728 if (codePoint == 0x09) {
8729 string = '\\t';
8730 }
8731 // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
8732 // else if (codePoint == 0x0B) {
8733 // string = '\\v';
8734 // }
8735 else if (codePoint == 0x0A) {
8736 string = '\\n';
8737 }
8738 else if (codePoint == 0x0C) {
8739 string = '\\f';
8740 }
8741 else if (codePoint == 0x0D) {
8742 string = '\\r';
8743 }
8744 else if (codePoint == 0x5C) {
8745 string = '\\\\';
8746 }
8747 else if (
8748 codePoint == 0x24 ||
8749 (codePoint >= 0x28 && codePoint <= 0x2B) ||
8750 (codePoint >= 0x2D && codePoint <= 0x2F) ||
8751 codePoint == 0x3F ||
8752 (codePoint >= 0x5B && codePoint <= 0x5E) ||
8753 (codePoint >= 0x7B && codePoint <= 0x7D)
8754 ) {
8755 // The code point maps to an unsafe printable ASCII character;
8756 // backslash-escape it. Here’s the list of those symbols:
8757 //
8758 // $()*+-./?[\]^{|}
8759 //
8760 // See #7 for more info.
8761 string = '\\' + stringFromCharCode(codePoint);
8762 }
8763 else if (codePoint >= 0x20 && codePoint <= 0x7E) {
8764 // The code point maps to one of these printable ASCII symbols
8765 // (including the space character):
8766 //
8767 // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
8768 // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
8769 //
8770 // These can safely be used directly.
8771 string = stringFromCharCode(codePoint);
8772 }
8773 else if (codePoint <= 0xFF) {
8774 // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
8775 string = '\\x' + pad(hex(codePoint), 2);
8776 }
8777 else { // `codePoint <= 0xFFFF` holds true.
8778 // https://mathiasbynens.be/notes/javascript-escapes#unicode
8779 string = '\\u' + pad(hex(codePoint), 4);
8780 }
8781
8782 // There’s no need to account for astral symbols / surrogate pairs here,
8783 // since `codePointToString` is private and only used for BMP code points.
8784 // But if that’s what you need, just add an `else` block with this code:
8785 //
8786 // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
8787 // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
8788
8789 return string;
8790 };
8791
8792 var codePointToStringUnicode = function(codePoint) {
8793 if (codePoint <= 0xFFFF) {
8794 return codePointToString(codePoint);
8795 }
8796 return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
8797 };
8798
8799 var symbolToCodePoint = function(symbol) {
8800 var length = symbol.length;
8801 var first = symbol.charCodeAt(0);
8802 var second;
8803 if (
8804 first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
8805 length > 1 // There is a next code unit.
8806 ) {
8807 // `first` is a high surrogate, and there is a next character. Assume
8808 // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
8809 second = symbol.charCodeAt(1);
8810 // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
8811 return (first - HIGH_SURROGATE_MIN) * 0x400 +
8812 second - LOW_SURROGATE_MIN + 0x10000;
8813 }
8814 return first;
8815 };
8816
8817 var createBMPCharacterClasses = function(data) {
8818 // Iterate over the data per `(start, end)` pair.
8819 var result = '';
8820 var index = 0;
8821 var start;
8822 var end;
8823 var length = data.length;
8824 if (dataIsSingleton(data)) {
8825 return codePointToString(data[0]);
8826 }
8827 while (index < length) {
8828 start = data[index];
8829 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8830 if (start == end) {
8831 result += codePointToString(start);
8832 } else if (start + 1 == end) {
8833 result += codePointToString(start) + codePointToString(end);
8834 } else {
8835 result += codePointToString(start) + '-' + codePointToString(end);
8836 }
8837 index += 2;
8838 }
8839 return '[' + result + ']';
8840 };
8841
8842 var createUnicodeCharacterClasses = function(data) {
8843 // Iterate over the data per `(start, end)` pair.
8844 var result = '';
8845 var index = 0;
8846 var start;
8847 var end;
8848 var length = data.length;
8849 if (dataIsSingleton(data)) {
8850 return codePointToStringUnicode(data[0]);
8851 }
8852 while (index < length) {
8853 start = data[index];
8854 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8855 if (start == end) {
8856 result += codePointToStringUnicode(start);
8857 } else if (start + 1 == end) {
8858 result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
8859 } else {
8860 result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
8861 }
8862 index += 2;
8863 }
8864 return '[' + result + ']';
8865 };
8866
8867 var splitAtBMP = function(data) {
8868 // Iterate over the data per `(start, end)` pair.
8869 var loneHighSurrogates = [];
8870 var loneLowSurrogates = [];
8871 var bmp = [];
8872 var astral = [];
8873 var index = 0;
8874 var start;
8875 var end;
8876 var length = data.length;
8877 while (index < length) {
8878 start = data[index];
8879 end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
8880
8881 if (start < HIGH_SURROGATE_MIN) {
8882
8883 // The range starts and ends before the high surrogate range.
8884 // E.g. (0, 0x10).
8885 if (end < HIGH_SURROGATE_MIN) {
8886 bmp.push(start, end + 1);
8887 }
8888
8889 // The range starts before the high surrogate range and ends within it.
8890 // E.g. (0, 0xD855).
8891 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
8892 bmp.push(start, HIGH_SURROGATE_MIN);
8893 loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
8894 }
8895
8896 // The range starts before the high surrogate range and ends in the low
8897 // surrogate range. E.g. (0, 0xDCFF).
8898 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8899 bmp.push(start, HIGH_SURROGATE_MIN);
8900 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
8901 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
8902 }
8903
8904 // The range starts before the high surrogate range and ends after the
8905 // low surrogate range. E.g. (0, 0x10FFFF).
8906 if (end > LOW_SURROGATE_MAX) {
8907 bmp.push(start, HIGH_SURROGATE_MIN);
8908 loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
8909 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
8910 if (end <= 0xFFFF) {
8911 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8912 } else {
8913 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8914 astral.push(0xFFFF + 1, end + 1);
8915 }
8916 }
8917
8918 } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
8919
8920 // The range starts and ends in the high surrogate range.
8921 // E.g. (0xD855, 0xD866).
8922 if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
8923 loneHighSurrogates.push(start, end + 1);
8924 }
8925
8926 // The range starts in the high surrogate range and ends in the low
8927 // surrogate range. E.g. (0xD855, 0xDCFF).
8928 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8929 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
8930 loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
8931 }
8932
8933 // The range starts in the high surrogate range and ends after the low
8934 // surrogate range. E.g. (0xD855, 0x10FFFF).
8935 if (end > LOW_SURROGATE_MAX) {
8936 loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
8937 loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
8938 if (end <= 0xFFFF) {
8939 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8940 } else {
8941 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8942 astral.push(0xFFFF + 1, end + 1);
8943 }
8944 }
8945
8946 } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
8947
8948 // The range starts and ends in the low surrogate range.
8949 // E.g. (0xDCFF, 0xDDFF).
8950 if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
8951 loneLowSurrogates.push(start, end + 1);
8952 }
8953
8954 // The range starts in the low surrogate range and ends after the low
8955 // surrogate range. E.g. (0xDCFF, 0x10FFFF).
8956 if (end > LOW_SURROGATE_MAX) {
8957 loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
8958 if (end <= 0xFFFF) {
8959 bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
8960 } else {
8961 bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
8962 astral.push(0xFFFF + 1, end + 1);
8963 }
8964 }
8965
8966 } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
8967
8968 // The range starts and ends after the low surrogate range.
8969 // E.g. (0xFFAA, 0x10FFFF).
8970 if (end <= 0xFFFF) {
8971 bmp.push(start, end + 1);
8972 } else {
8973 bmp.push(start, 0xFFFF + 1);
8974 astral.push(0xFFFF + 1, end + 1);
8975 }
8976
8977 } else {
8978
8979 // The range starts and ends in the astral range.
8980 astral.push(start, end + 1);
8981
8982 }
8983
8984 index += 2;
8985 }
8986 return {
8987 'loneHighSurrogates': loneHighSurrogates,
8988 'loneLowSurrogates': loneLowSurrogates,
8989 'bmp': bmp,
8990 'astral': astral
8991 };
8992 };
8993
8994 var optimizeSurrogateMappings = function(surrogateMappings) {
8995 var result = [];
8996 var tmpLow = [];
8997 var addLow = false;
8998 var mapping;
8999 var nextMapping;
9000 var highSurrogates;
9001 var lowSurrogates;
9002 var nextHighSurrogates;
9003 var nextLowSurrogates;
9004 var index = -1;
9005 var length = surrogateMappings.length;
9006 while (++index < length) {
9007 mapping = surrogateMappings[index];
9008 nextMapping = surrogateMappings[index + 1];
9009 if (!nextMapping) {
9010 result.push(mapping);
9011 continue;
9012 }
9013 highSurrogates = mapping[0];
9014 lowSurrogates = mapping[1];
9015 nextHighSurrogates = nextMapping[0];
9016 nextLowSurrogates = nextMapping[1];
9017
9018 // Check for identical high surrogate ranges.
9019 tmpLow = lowSurrogates;
9020 while (
9021 nextHighSurrogates &&
9022 highSurrogates[0] == nextHighSurrogates[0] &&
9023 highSurrogates[1] == nextHighSurrogates[1]
9024 ) {
9025 // Merge with the next item.
9026 if (dataIsSingleton(nextLowSurrogates)) {
9027 tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
9028 } else {
9029 tmpLow = dataAddRange(
9030 tmpLow,
9031 nextLowSurrogates[0],
9032 nextLowSurrogates[1] - 1
9033 );
9034 }
9035 ++index;
9036 mapping = surrogateMappings[index];
9037 highSurrogates = mapping[0];
9038 lowSurrogates = mapping[1];
9039 nextMapping = surrogateMappings[index + 1];
9040 nextHighSurrogates = nextMapping && nextMapping[0];
9041 nextLowSurrogates = nextMapping && nextMapping[1];
9042 addLow = true;
9043 }
9044 result.push([
9045 highSurrogates,
9046 addLow ? tmpLow : lowSurrogates
9047 ]);
9048 addLow = false;
9049 }
9050 return optimizeByLowSurrogates(result);
9051 };
9052
9053 var optimizeByLowSurrogates = function(surrogateMappings) {
9054 if (surrogateMappings.length == 1) {
9055 return surrogateMappings;
9056 }
9057 var index = -1;
9058 var innerIndex = -1;
9059 while (++index < surrogateMappings.length) {
9060 var mapping = surrogateMappings[index];
9061 var lowSurrogates = mapping[1];
9062 var lowSurrogateStart = lowSurrogates[0];
9063 var lowSurrogateEnd = lowSurrogates[1];
9064 innerIndex = index; // Note: the loop starts at the next index.
9065 while (++innerIndex < surrogateMappings.length) {
9066 var otherMapping = surrogateMappings[innerIndex];
9067 var otherLowSurrogates = otherMapping[1];
9068 var otherLowSurrogateStart = otherLowSurrogates[0];
9069 var otherLowSurrogateEnd = otherLowSurrogates[1];
9070 if (
9071 lowSurrogateStart == otherLowSurrogateStart &&
9072 lowSurrogateEnd == otherLowSurrogateEnd
9073 ) {
9074 // Add the code points in the other item to this one.
9075 if (dataIsSingleton(otherMapping[0])) {
9076 mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
9077 } else {
9078 mapping[0] = dataAddRange(
9079 mapping[0],
9080 otherMapping[0][0],
9081 otherMapping[0][1] - 1
9082 );
9083 }
9084 // Remove the other, now redundant, item.
9085 surrogateMappings.splice(innerIndex, 1);
9086 --innerIndex;
9087 }
9088 }
9089 }
9090 return surrogateMappings;
9091 };
9092
9093 var surrogateSet = function(data) {
9094 // Exit early if `data` is an empty set.
9095 if (!data.length) {
9096 return [];
9097 }
9098
9099 // Iterate over the data per `(start, end)` pair.
9100 var index = 0;
9101 var start;
9102 var end;
9103 var startHigh;
9104 var startLow;
9105 var endHigh;
9106 var endLow;
9107 var surrogateMappings = [];
9108 var length = data.length;
9109 while (index < length) {
9110 start = data[index];
9111 end = data[index + 1] - 1;
9112
9113 startHigh = highSurrogate(start);
9114 startLow = lowSurrogate(start);
9115 endHigh = highSurrogate(end);
9116 endLow = lowSurrogate(end);
9117
9118 var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
9119 var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
9120 var complete = false;
9121
9122 // Append the previous high-surrogate-to-low-surrogate mappings.
9123 // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
9124 if (
9125 startHigh == endHigh ||
9126 startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
9127 ) {
9128 surrogateMappings.push([
9129 [startHigh, endHigh + 1],
9130 [startLow, endLow + 1]
9131 ]);
9132 complete = true;
9133 } else {
9134 surrogateMappings.push([
9135 [startHigh, startHigh + 1],
9136 [startLow, LOW_SURROGATE_MAX + 1]
9137 ]);
9138 }
9139
9140 // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
9141 // `(endHigh - 1, LOW_SURROGATE_MAX)`.
9142 if (!complete && startHigh + 1 < endHigh) {
9143 if (endsWithHighestLowSurrogate) {
9144 // Combine step 2 and step 3.
9145 surrogateMappings.push([
9146 [startHigh + 1, endHigh + 1],
9147 [LOW_SURROGATE_MIN, endLow + 1]
9148 ]);
9149 complete = true;
9150 } else {
9151 surrogateMappings.push([
9152 [startHigh + 1, endHigh],
9153 [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
9154 ]);
9155 }
9156 }
9157
9158 // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
9159 if (!complete) {
9160 surrogateMappings.push([
9161 [endHigh, endHigh + 1],
9162 [LOW_SURROGATE_MIN, endLow + 1]
9163 ]);
9164 }
9165
9166 index += 2;
9167 }
9168
9169 // The format of `surrogateMappings` is as follows:
9170 //
9171 // [ surrogateMapping1, surrogateMapping2 ]
9172 //
9173 // i.e.:
9174 //
9175 // [
9176 // [ highSurrogates1, lowSurrogates1 ],
9177 // [ highSurrogates2, lowSurrogates2 ]
9178 // ]
9179 return optimizeSurrogateMappings(surrogateMappings);
9180 };
9181
9182 var createSurrogateCharacterClasses = function(surrogateMappings) {
9183 var result = [];
9184 forEach(surrogateMappings, function(surrogateMapping) {
9185 var highSurrogates = surrogateMapping[0];
9186 var lowSurrogates = surrogateMapping[1];
9187 result.push(
9188 createBMPCharacterClasses(highSurrogates) +
9189 createBMPCharacterClasses(lowSurrogates)
9190 );
9191 });
9192 return result.join('|');
9193 };
9194
9195 var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
9196 if (hasUnicodeFlag) {
9197 return createUnicodeCharacterClasses(data);
9198 }
9199 var result = [];
9200
9201 var parts = splitAtBMP(data);
9202 var loneHighSurrogates = parts.loneHighSurrogates;
9203 var loneLowSurrogates = parts.loneLowSurrogates;
9204 var bmp = parts.bmp;
9205 var astral = parts.astral;
9206 var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
9207 var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
9208
9209 var surrogateMappings = surrogateSet(astral);
9210
9211 if (bmpOnly) {
9212 bmp = dataAddData(bmp, loneHighSurrogates);
9213 hasLoneHighSurrogates = false;
9214 bmp = dataAddData(bmp, loneLowSurrogates);
9215 hasLoneLowSurrogates = false;
9216 }
9217
9218 if (!dataIsEmpty(bmp)) {
9219 // The data set contains BMP code points that are not high surrogates
9220 // needed for astral code points in the set.
9221 result.push(createBMPCharacterClasses(bmp));
9222 }
9223 if (surrogateMappings.length) {
9224 // The data set contains astral code points; append character classes
9225 // based on their surrogate pairs.
9226 result.push(createSurrogateCharacterClasses(surrogateMappings));
9227 }
9228 // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
9229 if (hasLoneHighSurrogates) {
9230 result.push(
9231 createBMPCharacterClasses(loneHighSurrogates) +
9232 // Make sure the high surrogates aren’t part of a surrogate pair.
9233 '(?![\\uDC00-\\uDFFF])'
9234 );
9235 }
9236 if (hasLoneLowSurrogates) {
9237 result.push(
9238 // It is not possible to accurately assert the low surrogates aren’t
9239 // part of a surrogate pair, since JavaScript regular expressions do
9240 // not support lookbehind.
9241 '(?:[^\\uD800-\\uDBFF]|^)' +
9242 createBMPCharacterClasses(loneLowSurrogates)
9243 );
9244 }
9245 return result.join('|');
9246 };
9247
9248 /*--------------------------------------------------------------------------*/
9249
9250 // `regenerate` can be used as a constructor (and new methods can be added to
9251 // its prototype) but also as a regular function, the latter of which is the
9252 // documented and most common usage. For that reason, it’s not capitalized.
9253 var regenerate = function(value) {
9254 if (arguments.length > 1) {
9255 value = slice.call(arguments);
9256 }
9257 if (this instanceof regenerate) {
9258 this.data = [];
9259 return value ? this.add(value) : this;
9260 }
9261 return (new regenerate).add(value);
9262 };
9263
9264 regenerate.version = '1.3.3';
9265
9266 var proto = regenerate.prototype;
9267 extend(proto, {
9268 'add': function(value) {
9269 var $this = this;
9270 if (value == null) {
9271 return $this;
9272 }
9273 if (value instanceof regenerate) {
9274 // Allow passing other Regenerate instances.
9275 $this.data = dataAddData($this.data, value.data);
9276 return $this;
9277 }
9278 if (arguments.length > 1) {
9279 value = slice.call(arguments);
9280 }
9281 if (isArray(value)) {
9282 forEach(value, function(item) {
9283 $this.add(item);
9284 });
9285 return $this;
9286 }
9287 $this.data = dataAdd(
9288 $this.data,
9289 isNumber(value) ? value : symbolToCodePoint(value)
9290 );
9291 return $this;
9292 },
9293 'remove': function(value) {
9294 var $this = this;
9295 if (value == null) {
9296 return $this;
9297 }
9298 if (value instanceof regenerate) {
9299 // Allow passing other Regenerate instances.
9300 $this.data = dataRemoveData($this.data, value.data);
9301 return $this;
9302 }
9303 if (arguments.length > 1) {
9304 value = slice.call(arguments);
9305 }
9306 if (isArray(value)) {
9307 forEach(value, function(item) {
9308 $this.remove(item);
9309 });
9310 return $this;
9311 }
9312 $this.data = dataRemove(
9313 $this.data,
9314 isNumber(value) ? value : symbolToCodePoint(value)
9315 );
9316 return $this;
9317 },
9318 'addRange': function(start, end) {
9319 var $this = this;
9320 $this.data = dataAddRange($this.data,
9321 isNumber(start) ? start : symbolToCodePoint(start),
9322 isNumber(end) ? end : symbolToCodePoint(end)
9323 );
9324 return $this;
9325 },
9326 'removeRange': function(start, end) {
9327 var $this = this;
9328 var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
9329 var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
9330 $this.data = dataRemoveRange(
9331 $this.data,
9332 startCodePoint,
9333 endCodePoint
9334 );
9335 return $this;
9336 },
9337 'intersection': function(argument) {
9338 var $this = this;
9339 // Allow passing other Regenerate instances.
9340 // TODO: Optimize this by writing and using `dataIntersectionData()`.
9341 var array = argument instanceof regenerate ?
9342 dataToArray(argument.data) :
9343 argument;
9344 $this.data = dataIntersection($this.data, array);
9345 return $this;
9346 },
9347 'contains': function(codePoint) {
9348 return dataContains(
9349 this.data,
9350 isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
9351 );
9352 },
9353 'clone': function() {
9354 var set = new regenerate;
9355 set.data = this.data.slice(0);
9356 return set;
9357 },
9358 'toString': function(options) {
9359 var result = createCharacterClassesFromData(
9360 this.data,
9361 options ? options.bmpOnly : false,
9362 options ? options.hasUnicodeFlag : false
9363 );
9364 if (!result) {
9365 // For an empty set, return something that can be inserted `/here/` to
9366 // form a valid regular expression. Avoid `(?:)` since that matches the
9367 // empty string.
9368 return '[]';
9369 }
9370 // Use `\0` instead of `\x00` where possible.
9371 return result.replace(regexNull, '\\0$1');
9372 },
9373 'toRegExp': function(flags) {
9374 var pattern = this.toString(
9375 flags && flags.indexOf('u') != -1 ?
9376 { 'hasUnicodeFlag': true } :
9377 null
9378 );
9379 return RegExp(pattern, flags || '');
9380 },
9381 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
9382 return dataToArray(this.data);
9383 }
9384 });
9385
9386 proto.toArray = proto.valueOf;
9387
9388 // Some AMD build optimizers, like r.js, check for specific condition patterns
9389 // like the following:
9390 if (
9391 typeof undefined == 'function' &&
9392 typeof undefined.amd == 'object' &&
9393 undefined.amd
9394 ) {
9395 undefined(function() {
9396 return regenerate;
9397 });
9398 } else if (freeExports && !freeExports.nodeType) {
9399 if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
9400 freeModule.exports = regenerate;
9401 } else { // in Narwhal or RingoJS v0.7.0-
9402 freeExports.regenerate = regenerate;
9403 }
9404 } else { // in Rhino or a web browser
9405 root.regenerate = regenerate;
9406 }
9407
9408}(commonjsGlobal));
9409});
9410
9411var unicodeCanonicalPropertyNamesEcmascript = new Set([
9412 // Non-binary properties:
9413 'General_Category',
9414 'Script',
9415 'Script_Extensions',
9416 // Binary properties:
9417 'Alphabetic',
9418 'Any',
9419 'ASCII',
9420 'ASCII_Hex_Digit',
9421 'Assigned',
9422 'Bidi_Control',
9423 'Bidi_Mirrored',
9424 'Case_Ignorable',
9425 'Cased',
9426 'Changes_When_Casefolded',
9427 'Changes_When_Casemapped',
9428 'Changes_When_Lowercased',
9429 'Changes_When_NFKC_Casefolded',
9430 'Changes_When_Titlecased',
9431 'Changes_When_Uppercased',
9432 'Dash',
9433 'Default_Ignorable_Code_Point',
9434 'Deprecated',
9435 'Diacritic',
9436 'Emoji',
9437 'Emoji_Component',
9438 'Emoji_Modifier',
9439 'Emoji_Modifier_Base',
9440 'Emoji_Presentation',
9441 'Extended_Pictographic',
9442 'Extender',
9443 'Grapheme_Base',
9444 'Grapheme_Extend',
9445 'Hex_Digit',
9446 'ID_Continue',
9447 'ID_Start',
9448 'Ideographic',
9449 'IDS_Binary_Operator',
9450 'IDS_Trinary_Operator',
9451 'Join_Control',
9452 'Logical_Order_Exception',
9453 'Lowercase',
9454 'Math',
9455 'Noncharacter_Code_Point',
9456 'Pattern_Syntax',
9457 'Pattern_White_Space',
9458 'Quotation_Mark',
9459 'Radical',
9460 'Regional_Indicator',
9461 'Sentence_Terminal',
9462 'Soft_Dotted',
9463 'Terminal_Punctuation',
9464 'Unified_Ideograph',
9465 'Uppercase',
9466 'Variation_Selector',
9467 'White_Space',
9468 'XID_Continue',
9469 'XID_Start'
9470]);
9471
9472// Generated using `npm run build`. Do not edit!
9473var unicodePropertyAliasesEcmascript = new Map([
9474 ['scx', 'Script_Extensions'],
9475 ['sc', 'Script'],
9476 ['gc', 'General_Category'],
9477 ['AHex', 'ASCII_Hex_Digit'],
9478 ['Alpha', 'Alphabetic'],
9479 ['Bidi_C', 'Bidi_Control'],
9480 ['Bidi_M', 'Bidi_Mirrored'],
9481 ['Cased', 'Cased'],
9482 ['CI', 'Case_Ignorable'],
9483 ['CWCF', 'Changes_When_Casefolded'],
9484 ['CWCM', 'Changes_When_Casemapped'],
9485 ['CWKCF', 'Changes_When_NFKC_Casefolded'],
9486 ['CWL', 'Changes_When_Lowercased'],
9487 ['CWT', 'Changes_When_Titlecased'],
9488 ['CWU', 'Changes_When_Uppercased'],
9489 ['Dash', 'Dash'],
9490 ['Dep', 'Deprecated'],
9491 ['DI', 'Default_Ignorable_Code_Point'],
9492 ['Dia', 'Diacritic'],
9493 ['Ext', 'Extender'],
9494 ['Gr_Base', 'Grapheme_Base'],
9495 ['Gr_Ext', 'Grapheme_Extend'],
9496 ['Hex', 'Hex_Digit'],
9497 ['IDC', 'ID_Continue'],
9498 ['Ideo', 'Ideographic'],
9499 ['IDS', 'ID_Start'],
9500 ['IDSB', 'IDS_Binary_Operator'],
9501 ['IDST', 'IDS_Trinary_Operator'],
9502 ['Join_C', 'Join_Control'],
9503 ['LOE', 'Logical_Order_Exception'],
9504 ['Lower', 'Lowercase'],
9505 ['Math', 'Math'],
9506 ['NChar', 'Noncharacter_Code_Point'],
9507 ['Pat_Syn', 'Pattern_Syntax'],
9508 ['Pat_WS', 'Pattern_White_Space'],
9509 ['QMark', 'Quotation_Mark'],
9510 ['Radical', 'Radical'],
9511 ['RI', 'Regional_Indicator'],
9512 ['SD', 'Soft_Dotted'],
9513 ['STerm', 'Sentence_Terminal'],
9514 ['Term', 'Terminal_Punctuation'],
9515 ['UIdeo', 'Unified_Ideograph'],
9516 ['Upper', 'Uppercase'],
9517 ['VS', 'Variation_Selector'],
9518 ['WSpace', 'White_Space'],
9519 ['space', 'White_Space'],
9520 ['XIDC', 'XID_Continue'],
9521 ['XIDS', 'XID_Start']
9522]);
9523
9524'use strict';
9525
9526
9527
9528
9529const matchProperty = function(property) {
9530 if (unicodeCanonicalPropertyNamesEcmascript.has(property)) {
9531 return property;
9532 }
9533 if (unicodePropertyAliasesEcmascript.has(property)) {
9534 return unicodePropertyAliasesEcmascript.get(property);
9535 }
9536 throw new Error(`Unknown property: ${ property }`);
9537};
9538
9539var unicodeMatchPropertyEcmascript = matchProperty;
9540
9541var mappings = new Map([
9542 ['General_Category', new Map([
9543 ['C', 'Other'],
9544 ['Cc', 'Control'],
9545 ['cntrl', 'Control'],
9546 ['Cf', 'Format'],
9547 ['Cn', 'Unassigned'],
9548 ['Co', 'Private_Use'],
9549 ['Cs', 'Surrogate'],
9550 ['L', 'Letter'],
9551 ['LC', 'Cased_Letter'],
9552 ['Ll', 'Lowercase_Letter'],
9553 ['Lm', 'Modifier_Letter'],
9554 ['Lo', 'Other_Letter'],
9555 ['Lt', 'Titlecase_Letter'],
9556 ['Lu', 'Uppercase_Letter'],
9557 ['M', 'Mark'],
9558 ['Combining_Mark', 'Mark'],
9559 ['Mc', 'Spacing_Mark'],
9560 ['Me', 'Enclosing_Mark'],
9561 ['Mn', 'Nonspacing_Mark'],
9562 ['N', 'Number'],
9563 ['Nd', 'Decimal_Number'],
9564 ['digit', 'Decimal_Number'],
9565 ['Nl', 'Letter_Number'],
9566 ['No', 'Other_Number'],
9567 ['P', 'Punctuation'],
9568 ['punct', 'Punctuation'],
9569 ['Pc', 'Connector_Punctuation'],
9570 ['Pd', 'Dash_Punctuation'],
9571 ['Pe', 'Close_Punctuation'],
9572 ['Pf', 'Final_Punctuation'],
9573 ['Pi', 'Initial_Punctuation'],
9574 ['Po', 'Other_Punctuation'],
9575 ['Ps', 'Open_Punctuation'],
9576 ['S', 'Symbol'],
9577 ['Sc', 'Currency_Symbol'],
9578 ['Sk', 'Modifier_Symbol'],
9579 ['Sm', 'Math_Symbol'],
9580 ['So', 'Other_Symbol'],
9581 ['Z', 'Separator'],
9582 ['Zl', 'Line_Separator'],
9583 ['Zp', 'Paragraph_Separator'],
9584 ['Zs', 'Space_Separator'],
9585 ['Other', 'Other'],
9586 ['Control', 'Control'],
9587 ['Format', 'Format'],
9588 ['Unassigned', 'Unassigned'],
9589 ['Private_Use', 'Private_Use'],
9590 ['Surrogate', 'Surrogate'],
9591 ['Letter', 'Letter'],
9592 ['Cased_Letter', 'Cased_Letter'],
9593 ['Lowercase_Letter', 'Lowercase_Letter'],
9594 ['Modifier_Letter', 'Modifier_Letter'],
9595 ['Other_Letter', 'Other_Letter'],
9596 ['Titlecase_Letter', 'Titlecase_Letter'],
9597 ['Uppercase_Letter', 'Uppercase_Letter'],
9598 ['Mark', 'Mark'],
9599 ['Spacing_Mark', 'Spacing_Mark'],
9600 ['Enclosing_Mark', 'Enclosing_Mark'],
9601 ['Nonspacing_Mark', 'Nonspacing_Mark'],
9602 ['Number', 'Number'],
9603 ['Decimal_Number', 'Decimal_Number'],
9604 ['Letter_Number', 'Letter_Number'],
9605 ['Other_Number', 'Other_Number'],
9606 ['Punctuation', 'Punctuation'],
9607 ['Connector_Punctuation', 'Connector_Punctuation'],
9608 ['Dash_Punctuation', 'Dash_Punctuation'],
9609 ['Close_Punctuation', 'Close_Punctuation'],
9610 ['Final_Punctuation', 'Final_Punctuation'],
9611 ['Initial_Punctuation', 'Initial_Punctuation'],
9612 ['Other_Punctuation', 'Other_Punctuation'],
9613 ['Open_Punctuation', 'Open_Punctuation'],
9614 ['Symbol', 'Symbol'],
9615 ['Currency_Symbol', 'Currency_Symbol'],
9616 ['Modifier_Symbol', 'Modifier_Symbol'],
9617 ['Math_Symbol', 'Math_Symbol'],
9618 ['Other_Symbol', 'Other_Symbol'],
9619 ['Separator', 'Separator'],
9620 ['Line_Separator', 'Line_Separator'],
9621 ['Paragraph_Separator', 'Paragraph_Separator'],
9622 ['Space_Separator', 'Space_Separator']
9623 ])],
9624 ['Script', new Map([
9625 ['Adlm', 'Adlam'],
9626 ['Aghb', 'Caucasian_Albanian'],
9627 ['Ahom', 'Ahom'],
9628 ['Arab', 'Arabic'],
9629 ['Armi', 'Imperial_Aramaic'],
9630 ['Armn', 'Armenian'],
9631 ['Avst', 'Avestan'],
9632 ['Bali', 'Balinese'],
9633 ['Bamu', 'Bamum'],
9634 ['Bass', 'Bassa_Vah'],
9635 ['Batk', 'Batak'],
9636 ['Beng', 'Bengali'],
9637 ['Bhks', 'Bhaiksuki'],
9638 ['Bopo', 'Bopomofo'],
9639 ['Brah', 'Brahmi'],
9640 ['Brai', 'Braille'],
9641 ['Bugi', 'Buginese'],
9642 ['Buhd', 'Buhid'],
9643 ['Cakm', 'Chakma'],
9644 ['Cans', 'Canadian_Aboriginal'],
9645 ['Cari', 'Carian'],
9646 ['Cham', 'Cham'],
9647 ['Cher', 'Cherokee'],
9648 ['Copt', 'Coptic'],
9649 ['Qaac', 'Coptic'],
9650 ['Cprt', 'Cypriot'],
9651 ['Cyrl', 'Cyrillic'],
9652 ['Deva', 'Devanagari'],
9653 ['Dsrt', 'Deseret'],
9654 ['Dupl', 'Duployan'],
9655 ['Egyp', 'Egyptian_Hieroglyphs'],
9656 ['Elba', 'Elbasan'],
9657 ['Ethi', 'Ethiopic'],
9658 ['Geor', 'Georgian'],
9659 ['Glag', 'Glagolitic'],
9660 ['Gonm', 'Masaram_Gondi'],
9661 ['Goth', 'Gothic'],
9662 ['Gran', 'Grantha'],
9663 ['Grek', 'Greek'],
9664 ['Gujr', 'Gujarati'],
9665 ['Guru', 'Gurmukhi'],
9666 ['Hang', 'Hangul'],
9667 ['Hani', 'Han'],
9668 ['Hano', 'Hanunoo'],
9669 ['Hatr', 'Hatran'],
9670 ['Hebr', 'Hebrew'],
9671 ['Hira', 'Hiragana'],
9672 ['Hluw', 'Anatolian_Hieroglyphs'],
9673 ['Hmng', 'Pahawh_Hmong'],
9674 ['Hrkt', 'Katakana_Or_Hiragana'],
9675 ['Hung', 'Old_Hungarian'],
9676 ['Ital', 'Old_Italic'],
9677 ['Java', 'Javanese'],
9678 ['Kali', 'Kayah_Li'],
9679 ['Kana', 'Katakana'],
9680 ['Khar', 'Kharoshthi'],
9681 ['Khmr', 'Khmer'],
9682 ['Khoj', 'Khojki'],
9683 ['Knda', 'Kannada'],
9684 ['Kthi', 'Kaithi'],
9685 ['Lana', 'Tai_Tham'],
9686 ['Laoo', 'Lao'],
9687 ['Latn', 'Latin'],
9688 ['Lepc', 'Lepcha'],
9689 ['Limb', 'Limbu'],
9690 ['Lina', 'Linear_A'],
9691 ['Linb', 'Linear_B'],
9692 ['Lisu', 'Lisu'],
9693 ['Lyci', 'Lycian'],
9694 ['Lydi', 'Lydian'],
9695 ['Mahj', 'Mahajani'],
9696 ['Mand', 'Mandaic'],
9697 ['Mani', 'Manichaean'],
9698 ['Marc', 'Marchen'],
9699 ['Mend', 'Mende_Kikakui'],
9700 ['Merc', 'Meroitic_Cursive'],
9701 ['Mero', 'Meroitic_Hieroglyphs'],
9702 ['Mlym', 'Malayalam'],
9703 ['Modi', 'Modi'],
9704 ['Mong', 'Mongolian'],
9705 ['Mroo', 'Mro'],
9706 ['Mtei', 'Meetei_Mayek'],
9707 ['Mult', 'Multani'],
9708 ['Mymr', 'Myanmar'],
9709 ['Narb', 'Old_North_Arabian'],
9710 ['Nbat', 'Nabataean'],
9711 ['Newa', 'Newa'],
9712 ['Nkoo', 'Nko'],
9713 ['Nshu', 'Nushu'],
9714 ['Ogam', 'Ogham'],
9715 ['Olck', 'Ol_Chiki'],
9716 ['Orkh', 'Old_Turkic'],
9717 ['Orya', 'Oriya'],
9718 ['Osge', 'Osage'],
9719 ['Osma', 'Osmanya'],
9720 ['Palm', 'Palmyrene'],
9721 ['Pauc', 'Pau_Cin_Hau'],
9722 ['Perm', 'Old_Permic'],
9723 ['Phag', 'Phags_Pa'],
9724 ['Phli', 'Inscriptional_Pahlavi'],
9725 ['Phlp', 'Psalter_Pahlavi'],
9726 ['Phnx', 'Phoenician'],
9727 ['Plrd', 'Miao'],
9728 ['Prti', 'Inscriptional_Parthian'],
9729 ['Rjng', 'Rejang'],
9730 ['Runr', 'Runic'],
9731 ['Samr', 'Samaritan'],
9732 ['Sarb', 'Old_South_Arabian'],
9733 ['Saur', 'Saurashtra'],
9734 ['Sgnw', 'SignWriting'],
9735 ['Shaw', 'Shavian'],
9736 ['Shrd', 'Sharada'],
9737 ['Sidd', 'Siddham'],
9738 ['Sind', 'Khudawadi'],
9739 ['Sinh', 'Sinhala'],
9740 ['Sora', 'Sora_Sompeng'],
9741 ['Soyo', 'Soyombo'],
9742 ['Sund', 'Sundanese'],
9743 ['Sylo', 'Syloti_Nagri'],
9744 ['Syrc', 'Syriac'],
9745 ['Tagb', 'Tagbanwa'],
9746 ['Takr', 'Takri'],
9747 ['Tale', 'Tai_Le'],
9748 ['Talu', 'New_Tai_Lue'],
9749 ['Taml', 'Tamil'],
9750 ['Tang', 'Tangut'],
9751 ['Tavt', 'Tai_Viet'],
9752 ['Telu', 'Telugu'],
9753 ['Tfng', 'Tifinagh'],
9754 ['Tglg', 'Tagalog'],
9755 ['Thaa', 'Thaana'],
9756 ['Thai', 'Thai'],
9757 ['Tibt', 'Tibetan'],
9758 ['Tirh', 'Tirhuta'],
9759 ['Ugar', 'Ugaritic'],
9760 ['Vaii', 'Vai'],
9761 ['Wara', 'Warang_Citi'],
9762 ['Xpeo', 'Old_Persian'],
9763 ['Xsux', 'Cuneiform'],
9764 ['Yiii', 'Yi'],
9765 ['Zanb', 'Zanabazar_Square'],
9766 ['Zinh', 'Inherited'],
9767 ['Qaai', 'Inherited'],
9768 ['Zyyy', 'Common'],
9769 ['Zzzz', 'Unknown'],
9770 ['Adlam', 'Adlam'],
9771 ['Caucasian_Albanian', 'Caucasian_Albanian'],
9772 ['Arabic', 'Arabic'],
9773 ['Imperial_Aramaic', 'Imperial_Aramaic'],
9774 ['Armenian', 'Armenian'],
9775 ['Avestan', 'Avestan'],
9776 ['Balinese', 'Balinese'],
9777 ['Bamum', 'Bamum'],
9778 ['Bassa_Vah', 'Bassa_Vah'],
9779 ['Batak', 'Batak'],
9780 ['Bengali', 'Bengali'],
9781 ['Bhaiksuki', 'Bhaiksuki'],
9782 ['Bopomofo', 'Bopomofo'],
9783 ['Brahmi', 'Brahmi'],
9784 ['Braille', 'Braille'],
9785 ['Buginese', 'Buginese'],
9786 ['Buhid', 'Buhid'],
9787 ['Chakma', 'Chakma'],
9788 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
9789 ['Carian', 'Carian'],
9790 ['Cherokee', 'Cherokee'],
9791 ['Coptic', 'Coptic'],
9792 ['Cypriot', 'Cypriot'],
9793 ['Cyrillic', 'Cyrillic'],
9794 ['Devanagari', 'Devanagari'],
9795 ['Deseret', 'Deseret'],
9796 ['Duployan', 'Duployan'],
9797 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
9798 ['Elbasan', 'Elbasan'],
9799 ['Ethiopic', 'Ethiopic'],
9800 ['Georgian', 'Georgian'],
9801 ['Glagolitic', 'Glagolitic'],
9802 ['Masaram_Gondi', 'Masaram_Gondi'],
9803 ['Gothic', 'Gothic'],
9804 ['Grantha', 'Grantha'],
9805 ['Greek', 'Greek'],
9806 ['Gujarati', 'Gujarati'],
9807 ['Gurmukhi', 'Gurmukhi'],
9808 ['Hangul', 'Hangul'],
9809 ['Han', 'Han'],
9810 ['Hanunoo', 'Hanunoo'],
9811 ['Hatran', 'Hatran'],
9812 ['Hebrew', 'Hebrew'],
9813 ['Hiragana', 'Hiragana'],
9814 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
9815 ['Pahawh_Hmong', 'Pahawh_Hmong'],
9816 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
9817 ['Old_Hungarian', 'Old_Hungarian'],
9818 ['Old_Italic', 'Old_Italic'],
9819 ['Javanese', 'Javanese'],
9820 ['Kayah_Li', 'Kayah_Li'],
9821 ['Katakana', 'Katakana'],
9822 ['Kharoshthi', 'Kharoshthi'],
9823 ['Khmer', 'Khmer'],
9824 ['Khojki', 'Khojki'],
9825 ['Kannada', 'Kannada'],
9826 ['Kaithi', 'Kaithi'],
9827 ['Tai_Tham', 'Tai_Tham'],
9828 ['Lao', 'Lao'],
9829 ['Latin', 'Latin'],
9830 ['Lepcha', 'Lepcha'],
9831 ['Limbu', 'Limbu'],
9832 ['Linear_A', 'Linear_A'],
9833 ['Linear_B', 'Linear_B'],
9834 ['Lycian', 'Lycian'],
9835 ['Lydian', 'Lydian'],
9836 ['Mahajani', 'Mahajani'],
9837 ['Mandaic', 'Mandaic'],
9838 ['Manichaean', 'Manichaean'],
9839 ['Marchen', 'Marchen'],
9840 ['Mende_Kikakui', 'Mende_Kikakui'],
9841 ['Meroitic_Cursive', 'Meroitic_Cursive'],
9842 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
9843 ['Malayalam', 'Malayalam'],
9844 ['Mongolian', 'Mongolian'],
9845 ['Mro', 'Mro'],
9846 ['Meetei_Mayek', 'Meetei_Mayek'],
9847 ['Multani', 'Multani'],
9848 ['Myanmar', 'Myanmar'],
9849 ['Old_North_Arabian', 'Old_North_Arabian'],
9850 ['Nabataean', 'Nabataean'],
9851 ['Nko', 'Nko'],
9852 ['Nushu', 'Nushu'],
9853 ['Ogham', 'Ogham'],
9854 ['Ol_Chiki', 'Ol_Chiki'],
9855 ['Old_Turkic', 'Old_Turkic'],
9856 ['Oriya', 'Oriya'],
9857 ['Osage', 'Osage'],
9858 ['Osmanya', 'Osmanya'],
9859 ['Palmyrene', 'Palmyrene'],
9860 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
9861 ['Old_Permic', 'Old_Permic'],
9862 ['Phags_Pa', 'Phags_Pa'],
9863 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
9864 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
9865 ['Phoenician', 'Phoenician'],
9866 ['Miao', 'Miao'],
9867 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
9868 ['Rejang', 'Rejang'],
9869 ['Runic', 'Runic'],
9870 ['Samaritan', 'Samaritan'],
9871 ['Old_South_Arabian', 'Old_South_Arabian'],
9872 ['Saurashtra', 'Saurashtra'],
9873 ['SignWriting', 'SignWriting'],
9874 ['Shavian', 'Shavian'],
9875 ['Sharada', 'Sharada'],
9876 ['Siddham', 'Siddham'],
9877 ['Khudawadi', 'Khudawadi'],
9878 ['Sinhala', 'Sinhala'],
9879 ['Sora_Sompeng', 'Sora_Sompeng'],
9880 ['Soyombo', 'Soyombo'],
9881 ['Sundanese', 'Sundanese'],
9882 ['Syloti_Nagri', 'Syloti_Nagri'],
9883 ['Syriac', 'Syriac'],
9884 ['Tagbanwa', 'Tagbanwa'],
9885 ['Takri', 'Takri'],
9886 ['Tai_Le', 'Tai_Le'],
9887 ['New_Tai_Lue', 'New_Tai_Lue'],
9888 ['Tamil', 'Tamil'],
9889 ['Tangut', 'Tangut'],
9890 ['Tai_Viet', 'Tai_Viet'],
9891 ['Telugu', 'Telugu'],
9892 ['Tifinagh', 'Tifinagh'],
9893 ['Tagalog', 'Tagalog'],
9894 ['Thaana', 'Thaana'],
9895 ['Tibetan', 'Tibetan'],
9896 ['Tirhuta', 'Tirhuta'],
9897 ['Ugaritic', 'Ugaritic'],
9898 ['Vai', 'Vai'],
9899 ['Warang_Citi', 'Warang_Citi'],
9900 ['Old_Persian', 'Old_Persian'],
9901 ['Cuneiform', 'Cuneiform'],
9902 ['Yi', 'Yi'],
9903 ['Zanabazar_Square', 'Zanabazar_Square'],
9904 ['Inherited', 'Inherited'],
9905 ['Common', 'Common'],
9906 ['Unknown', 'Unknown']
9907 ])],
9908 ['Script_Extensions', new Map([
9909 ['Adlm', 'Adlam'],
9910 ['Aghb', 'Caucasian_Albanian'],
9911 ['Ahom', 'Ahom'],
9912 ['Arab', 'Arabic'],
9913 ['Armi', 'Imperial_Aramaic'],
9914 ['Armn', 'Armenian'],
9915 ['Avst', 'Avestan'],
9916 ['Bali', 'Balinese'],
9917 ['Bamu', 'Bamum'],
9918 ['Bass', 'Bassa_Vah'],
9919 ['Batk', 'Batak'],
9920 ['Beng', 'Bengali'],
9921 ['Bhks', 'Bhaiksuki'],
9922 ['Bopo', 'Bopomofo'],
9923 ['Brah', 'Brahmi'],
9924 ['Brai', 'Braille'],
9925 ['Bugi', 'Buginese'],
9926 ['Buhd', 'Buhid'],
9927 ['Cakm', 'Chakma'],
9928 ['Cans', 'Canadian_Aboriginal'],
9929 ['Cari', 'Carian'],
9930 ['Cham', 'Cham'],
9931 ['Cher', 'Cherokee'],
9932 ['Copt', 'Coptic'],
9933 ['Qaac', 'Coptic'],
9934 ['Cprt', 'Cypriot'],
9935 ['Cyrl', 'Cyrillic'],
9936 ['Deva', 'Devanagari'],
9937 ['Dsrt', 'Deseret'],
9938 ['Dupl', 'Duployan'],
9939 ['Egyp', 'Egyptian_Hieroglyphs'],
9940 ['Elba', 'Elbasan'],
9941 ['Ethi', 'Ethiopic'],
9942 ['Geor', 'Georgian'],
9943 ['Glag', 'Glagolitic'],
9944 ['Gonm', 'Masaram_Gondi'],
9945 ['Goth', 'Gothic'],
9946 ['Gran', 'Grantha'],
9947 ['Grek', 'Greek'],
9948 ['Gujr', 'Gujarati'],
9949 ['Guru', 'Gurmukhi'],
9950 ['Hang', 'Hangul'],
9951 ['Hani', 'Han'],
9952 ['Hano', 'Hanunoo'],
9953 ['Hatr', 'Hatran'],
9954 ['Hebr', 'Hebrew'],
9955 ['Hira', 'Hiragana'],
9956 ['Hluw', 'Anatolian_Hieroglyphs'],
9957 ['Hmng', 'Pahawh_Hmong'],
9958 ['Hrkt', 'Katakana_Or_Hiragana'],
9959 ['Hung', 'Old_Hungarian'],
9960 ['Ital', 'Old_Italic'],
9961 ['Java', 'Javanese'],
9962 ['Kali', 'Kayah_Li'],
9963 ['Kana', 'Katakana'],
9964 ['Khar', 'Kharoshthi'],
9965 ['Khmr', 'Khmer'],
9966 ['Khoj', 'Khojki'],
9967 ['Knda', 'Kannada'],
9968 ['Kthi', 'Kaithi'],
9969 ['Lana', 'Tai_Tham'],
9970 ['Laoo', 'Lao'],
9971 ['Latn', 'Latin'],
9972 ['Lepc', 'Lepcha'],
9973 ['Limb', 'Limbu'],
9974 ['Lina', 'Linear_A'],
9975 ['Linb', 'Linear_B'],
9976 ['Lisu', 'Lisu'],
9977 ['Lyci', 'Lycian'],
9978 ['Lydi', 'Lydian'],
9979 ['Mahj', 'Mahajani'],
9980 ['Mand', 'Mandaic'],
9981 ['Mani', 'Manichaean'],
9982 ['Marc', 'Marchen'],
9983 ['Mend', 'Mende_Kikakui'],
9984 ['Merc', 'Meroitic_Cursive'],
9985 ['Mero', 'Meroitic_Hieroglyphs'],
9986 ['Mlym', 'Malayalam'],
9987 ['Modi', 'Modi'],
9988 ['Mong', 'Mongolian'],
9989 ['Mroo', 'Mro'],
9990 ['Mtei', 'Meetei_Mayek'],
9991 ['Mult', 'Multani'],
9992 ['Mymr', 'Myanmar'],
9993 ['Narb', 'Old_North_Arabian'],
9994 ['Nbat', 'Nabataean'],
9995 ['Newa', 'Newa'],
9996 ['Nkoo', 'Nko'],
9997 ['Nshu', 'Nushu'],
9998 ['Ogam', 'Ogham'],
9999 ['Olck', 'Ol_Chiki'],
10000 ['Orkh', 'Old_Turkic'],
10001 ['Orya', 'Oriya'],
10002 ['Osge', 'Osage'],
10003 ['Osma', 'Osmanya'],
10004 ['Palm', 'Palmyrene'],
10005 ['Pauc', 'Pau_Cin_Hau'],
10006 ['Perm', 'Old_Permic'],
10007 ['Phag', 'Phags_Pa'],
10008 ['Phli', 'Inscriptional_Pahlavi'],
10009 ['Phlp', 'Psalter_Pahlavi'],
10010 ['Phnx', 'Phoenician'],
10011 ['Plrd', 'Miao'],
10012 ['Prti', 'Inscriptional_Parthian'],
10013 ['Rjng', 'Rejang'],
10014 ['Runr', 'Runic'],
10015 ['Samr', 'Samaritan'],
10016 ['Sarb', 'Old_South_Arabian'],
10017 ['Saur', 'Saurashtra'],
10018 ['Sgnw', 'SignWriting'],
10019 ['Shaw', 'Shavian'],
10020 ['Shrd', 'Sharada'],
10021 ['Sidd', 'Siddham'],
10022 ['Sind', 'Khudawadi'],
10023 ['Sinh', 'Sinhala'],
10024 ['Sora', 'Sora_Sompeng'],
10025 ['Soyo', 'Soyombo'],
10026 ['Sund', 'Sundanese'],
10027 ['Sylo', 'Syloti_Nagri'],
10028 ['Syrc', 'Syriac'],
10029 ['Tagb', 'Tagbanwa'],
10030 ['Takr', 'Takri'],
10031 ['Tale', 'Tai_Le'],
10032 ['Talu', 'New_Tai_Lue'],
10033 ['Taml', 'Tamil'],
10034 ['Tang', 'Tangut'],
10035 ['Tavt', 'Tai_Viet'],
10036 ['Telu', 'Telugu'],
10037 ['Tfng', 'Tifinagh'],
10038 ['Tglg', 'Tagalog'],
10039 ['Thaa', 'Thaana'],
10040 ['Thai', 'Thai'],
10041 ['Tibt', 'Tibetan'],
10042 ['Tirh', 'Tirhuta'],
10043 ['Ugar', 'Ugaritic'],
10044 ['Vaii', 'Vai'],
10045 ['Wara', 'Warang_Citi'],
10046 ['Xpeo', 'Old_Persian'],
10047 ['Xsux', 'Cuneiform'],
10048 ['Yiii', 'Yi'],
10049 ['Zanb', 'Zanabazar_Square'],
10050 ['Zinh', 'Inherited'],
10051 ['Qaai', 'Inherited'],
10052 ['Zyyy', 'Common'],
10053 ['Zzzz', 'Unknown'],
10054 ['Adlam', 'Adlam'],
10055 ['Caucasian_Albanian', 'Caucasian_Albanian'],
10056 ['Arabic', 'Arabic'],
10057 ['Imperial_Aramaic', 'Imperial_Aramaic'],
10058 ['Armenian', 'Armenian'],
10059 ['Avestan', 'Avestan'],
10060 ['Balinese', 'Balinese'],
10061 ['Bamum', 'Bamum'],
10062 ['Bassa_Vah', 'Bassa_Vah'],
10063 ['Batak', 'Batak'],
10064 ['Bengali', 'Bengali'],
10065 ['Bhaiksuki', 'Bhaiksuki'],
10066 ['Bopomofo', 'Bopomofo'],
10067 ['Brahmi', 'Brahmi'],
10068 ['Braille', 'Braille'],
10069 ['Buginese', 'Buginese'],
10070 ['Buhid', 'Buhid'],
10071 ['Chakma', 'Chakma'],
10072 ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
10073 ['Carian', 'Carian'],
10074 ['Cherokee', 'Cherokee'],
10075 ['Coptic', 'Coptic'],
10076 ['Cypriot', 'Cypriot'],
10077 ['Cyrillic', 'Cyrillic'],
10078 ['Devanagari', 'Devanagari'],
10079 ['Deseret', 'Deseret'],
10080 ['Duployan', 'Duployan'],
10081 ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
10082 ['Elbasan', 'Elbasan'],
10083 ['Ethiopic', 'Ethiopic'],
10084 ['Georgian', 'Georgian'],
10085 ['Glagolitic', 'Glagolitic'],
10086 ['Masaram_Gondi', 'Masaram_Gondi'],
10087 ['Gothic', 'Gothic'],
10088 ['Grantha', 'Grantha'],
10089 ['Greek', 'Greek'],
10090 ['Gujarati', 'Gujarati'],
10091 ['Gurmukhi', 'Gurmukhi'],
10092 ['Hangul', 'Hangul'],
10093 ['Han', 'Han'],
10094 ['Hanunoo', 'Hanunoo'],
10095 ['Hatran', 'Hatran'],
10096 ['Hebrew', 'Hebrew'],
10097 ['Hiragana', 'Hiragana'],
10098 ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
10099 ['Pahawh_Hmong', 'Pahawh_Hmong'],
10100 ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
10101 ['Old_Hungarian', 'Old_Hungarian'],
10102 ['Old_Italic', 'Old_Italic'],
10103 ['Javanese', 'Javanese'],
10104 ['Kayah_Li', 'Kayah_Li'],
10105 ['Katakana', 'Katakana'],
10106 ['Kharoshthi', 'Kharoshthi'],
10107 ['Khmer', 'Khmer'],
10108 ['Khojki', 'Khojki'],
10109 ['Kannada', 'Kannada'],
10110 ['Kaithi', 'Kaithi'],
10111 ['Tai_Tham', 'Tai_Tham'],
10112 ['Lao', 'Lao'],
10113 ['Latin', 'Latin'],
10114 ['Lepcha', 'Lepcha'],
10115 ['Limbu', 'Limbu'],
10116 ['Linear_A', 'Linear_A'],
10117 ['Linear_B', 'Linear_B'],
10118 ['Lycian', 'Lycian'],
10119 ['Lydian', 'Lydian'],
10120 ['Mahajani', 'Mahajani'],
10121 ['Mandaic', 'Mandaic'],
10122 ['Manichaean', 'Manichaean'],
10123 ['Marchen', 'Marchen'],
10124 ['Mende_Kikakui', 'Mende_Kikakui'],
10125 ['Meroitic_Cursive', 'Meroitic_Cursive'],
10126 ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
10127 ['Malayalam', 'Malayalam'],
10128 ['Mongolian', 'Mongolian'],
10129 ['Mro', 'Mro'],
10130 ['Meetei_Mayek', 'Meetei_Mayek'],
10131 ['Multani', 'Multani'],
10132 ['Myanmar', 'Myanmar'],
10133 ['Old_North_Arabian', 'Old_North_Arabian'],
10134 ['Nabataean', 'Nabataean'],
10135 ['Nko', 'Nko'],
10136 ['Nushu', 'Nushu'],
10137 ['Ogham', 'Ogham'],
10138 ['Ol_Chiki', 'Ol_Chiki'],
10139 ['Old_Turkic', 'Old_Turkic'],
10140 ['Oriya', 'Oriya'],
10141 ['Osage', 'Osage'],
10142 ['Osmanya', 'Osmanya'],
10143 ['Palmyrene', 'Palmyrene'],
10144 ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
10145 ['Old_Permic', 'Old_Permic'],
10146 ['Phags_Pa', 'Phags_Pa'],
10147 ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
10148 ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
10149 ['Phoenician', 'Phoenician'],
10150 ['Miao', 'Miao'],
10151 ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
10152 ['Rejang', 'Rejang'],
10153 ['Runic', 'Runic'],
10154 ['Samaritan', 'Samaritan'],
10155 ['Old_South_Arabian', 'Old_South_Arabian'],
10156 ['Saurashtra', 'Saurashtra'],
10157 ['SignWriting', 'SignWriting'],
10158 ['Shavian', 'Shavian'],
10159 ['Sharada', 'Sharada'],
10160 ['Siddham', 'Siddham'],
10161 ['Khudawadi', 'Khudawadi'],
10162 ['Sinhala', 'Sinhala'],
10163 ['Sora_Sompeng', 'Sora_Sompeng'],
10164 ['Soyombo', 'Soyombo'],
10165 ['Sundanese', 'Sundanese'],
10166 ['Syloti_Nagri', 'Syloti_Nagri'],
10167 ['Syriac', 'Syriac'],
10168 ['Tagbanwa', 'Tagbanwa'],
10169 ['Takri', 'Takri'],
10170 ['Tai_Le', 'Tai_Le'],
10171 ['New_Tai_Lue', 'New_Tai_Lue'],
10172 ['Tamil', 'Tamil'],
10173 ['Tangut', 'Tangut'],
10174 ['Tai_Viet', 'Tai_Viet'],
10175 ['Telugu', 'Telugu'],
10176 ['Tifinagh', 'Tifinagh'],
10177 ['Tagalog', 'Tagalog'],
10178 ['Thaana', 'Thaana'],
10179 ['Tibetan', 'Tibetan'],
10180 ['Tirhuta', 'Tirhuta'],
10181 ['Ugaritic', 'Ugaritic'],
10182 ['Vai', 'Vai'],
10183 ['Warang_Citi', 'Warang_Citi'],
10184 ['Old_Persian', 'Old_Persian'],
10185 ['Cuneiform', 'Cuneiform'],
10186 ['Yi', 'Yi'],
10187 ['Zanabazar_Square', 'Zanabazar_Square'],
10188 ['Inherited', 'Inherited'],
10189 ['Common', 'Common'],
10190 ['Unknown', 'Unknown']
10191 ])]
10192]);
10193
10194'use strict';
10195
10196
10197
10198const matchPropertyValue = function(property, value) {
10199 const aliasToValue = mappings.get(property);
10200 if (!aliasToValue) {
10201 throw new Error(`Unknown property \`${ property }\`.`);
10202 }
10203 const canonicalValue = aliasToValue.get(value);
10204 if (canonicalValue) {
10205 return canonicalValue;
10206 }
10207 throw new Error(
10208 `Unknown value \`${ value }\` for property \`${ property }\`.`
10209 );
10210};
10211
10212var unicodeMatchPropertyValueEcmascript = matchPropertyValue;
10213
10214var iuMappings = new Map([
10215 [0x4B, 0x212A],
10216 [0x53, 0x17F],
10217 [0x6B, 0x212A],
10218 [0x73, 0x17F],
10219 [0xB5, 0x39C],
10220 [0xC5, 0x212B],
10221 [0xDF, 0x1E9E],
10222 [0xE5, 0x212B],
10223 [0x17F, 0x53],
10224 [0x1C4, 0x1C5],
10225 [0x1C5, 0x1C4],
10226 [0x1C7, 0x1C8],
10227 [0x1C8, 0x1C7],
10228 [0x1CA, 0x1CB],
10229 [0x1CB, 0x1CA],
10230 [0x1F1, 0x1F2],
10231 [0x1F2, 0x1F1],
10232 [0x26A, 0xA7AE],
10233 [0x29D, 0xA7B2],
10234 [0x345, 0x1FBE],
10235 [0x392, 0x3D0],
10236 [0x395, 0x3F5],
10237 [0x398, 0x3F4],
10238 [0x399, 0x1FBE],
10239 [0x39A, 0x3F0],
10240 [0x39C, 0xB5],
10241 [0x3A0, 0x3D6],
10242 [0x3A1, 0x3F1],
10243 [0x3A3, 0x3C2],
10244 [0x3A6, 0x3D5],
10245 [0x3A9, 0x2126],
10246 [0x3B8, 0x3F4],
10247 [0x3C2, 0x3A3],
10248 [0x3C9, 0x2126],
10249 [0x3D0, 0x392],
10250 [0x3D1, 0x3F4],
10251 [0x3D5, 0x3A6],
10252 [0x3D6, 0x3A0],
10253 [0x3F0, 0x39A],
10254 [0x3F1, 0x3A1],
10255 [0x3F4, [
10256 0x398,
10257 0x3D1,
10258 0x3B8
10259 ]],
10260 [0x3F5, 0x395],
10261 [0x412, 0x1C80],
10262 [0x414, 0x1C81],
10263 [0x41E, 0x1C82],
10264 [0x421, 0x1C83],
10265 [0x422, 0x1C85],
10266 [0x42A, 0x1C86],
10267 [0x432, 0x1C80],
10268 [0x434, 0x1C81],
10269 [0x43E, 0x1C82],
10270 [0x441, 0x1C83],
10271 [0x442, [
10272 0x1C84,
10273 0x1C85
10274 ]],
10275 [0x44A, 0x1C86],
10276 [0x462, 0x1C87],
10277 [0x463, 0x1C87],
10278 [0x13A0, 0xAB70],
10279 [0x13A1, 0xAB71],
10280 [0x13A2, 0xAB72],
10281 [0x13A3, 0xAB73],
10282 [0x13A4, 0xAB74],
10283 [0x13A5, 0xAB75],
10284 [0x13A6, 0xAB76],
10285 [0x13A7, 0xAB77],
10286 [0x13A8, 0xAB78],
10287 [0x13A9, 0xAB79],
10288 [0x13AA, 0xAB7A],
10289 [0x13AB, 0xAB7B],
10290 [0x13AC, 0xAB7C],
10291 [0x13AD, 0xAB7D],
10292 [0x13AE, 0xAB7E],
10293 [0x13AF, 0xAB7F],
10294 [0x13B0, 0xAB80],
10295 [0x13B1, 0xAB81],
10296 [0x13B2, 0xAB82],
10297 [0x13B3, 0xAB83],
10298 [0x13B4, 0xAB84],
10299 [0x13B5, 0xAB85],
10300 [0x13B6, 0xAB86],
10301 [0x13B7, 0xAB87],
10302 [0x13B8, 0xAB88],
10303 [0x13B9, 0xAB89],
10304 [0x13BA, 0xAB8A],
10305 [0x13BB, 0xAB8B],
10306 [0x13BC, 0xAB8C],
10307 [0x13BD, 0xAB8D],
10308 [0x13BE, 0xAB8E],
10309 [0x13BF, 0xAB8F],
10310 [0x13C0, 0xAB90],
10311 [0x13C1, 0xAB91],
10312 [0x13C2, 0xAB92],
10313 [0x13C3, 0xAB93],
10314 [0x13C4, 0xAB94],
10315 [0x13C5, 0xAB95],
10316 [0x13C6, 0xAB96],
10317 [0x13C7, 0xAB97],
10318 [0x13C8, 0xAB98],
10319 [0x13C9, 0xAB99],
10320 [0x13CA, 0xAB9A],
10321 [0x13CB, 0xAB9B],
10322 [0x13CC, 0xAB9C],
10323 [0x13CD, 0xAB9D],
10324 [0x13CE, 0xAB9E],
10325 [0x13CF, 0xAB9F],
10326 [0x13D0, 0xABA0],
10327 [0x13D1, 0xABA1],
10328 [0x13D2, 0xABA2],
10329 [0x13D3, 0xABA3],
10330 [0x13D4, 0xABA4],
10331 [0x13D5, 0xABA5],
10332 [0x13D6, 0xABA6],
10333 [0x13D7, 0xABA7],
10334 [0x13D8, 0xABA8],
10335 [0x13D9, 0xABA9],
10336 [0x13DA, 0xABAA],
10337 [0x13DB, 0xABAB],
10338 [0x13DC, 0xABAC],
10339 [0x13DD, 0xABAD],
10340 [0x13DE, 0xABAE],
10341 [0x13DF, 0xABAF],
10342 [0x13E0, 0xABB0],
10343 [0x13E1, 0xABB1],
10344 [0x13E2, 0xABB2],
10345 [0x13E3, 0xABB3],
10346 [0x13E4, 0xABB4],
10347 [0x13E5, 0xABB5],
10348 [0x13E6, 0xABB6],
10349 [0x13E7, 0xABB7],
10350 [0x13E8, 0xABB8],
10351 [0x13E9, 0xABB9],
10352 [0x13EA, 0xABBA],
10353 [0x13EB, 0xABBB],
10354 [0x13EC, 0xABBC],
10355 [0x13ED, 0xABBD],
10356 [0x13EE, 0xABBE],
10357 [0x13EF, 0xABBF],
10358 [0x13F0, 0x13F8],
10359 [0x13F1, 0x13F9],
10360 [0x13F2, 0x13FA],
10361 [0x13F3, 0x13FB],
10362 [0x13F4, 0x13FC],
10363 [0x13F5, 0x13FD],
10364 [0x13F8, 0x13F0],
10365 [0x13F9, 0x13F1],
10366 [0x13FA, 0x13F2],
10367 [0x13FB, 0x13F3],
10368 [0x13FC, 0x13F4],
10369 [0x13FD, 0x13F5],
10370 [0x1C80, [
10371 0x412,
10372 0x432
10373 ]],
10374 [0x1C81, [
10375 0x414,
10376 0x434
10377 ]],
10378 [0x1C82, [
10379 0x41E,
10380 0x43E
10381 ]],
10382 [0x1C83, [
10383 0x421,
10384 0x441
10385 ]],
10386 [0x1C84, [
10387 0x1C85,
10388 0x442
10389 ]],
10390 [0x1C85, [
10391 0x422,
10392 0x1C84,
10393 0x442
10394 ]],
10395 [0x1C86, [
10396 0x42A,
10397 0x44A
10398 ]],
10399 [0x1C87, [
10400 0x462,
10401 0x463
10402 ]],
10403 [0x1C88, [
10404 0xA64A,
10405 0xA64B
10406 ]],
10407 [0x1E60, 0x1E9B],
10408 [0x1E9B, 0x1E60],
10409 [0x1E9E, 0xDF],
10410 [0x1F80, 0x1F88],
10411 [0x1F81, 0x1F89],
10412 [0x1F82, 0x1F8A],
10413 [0x1F83, 0x1F8B],
10414 [0x1F84, 0x1F8C],
10415 [0x1F85, 0x1F8D],
10416 [0x1F86, 0x1F8E],
10417 [0x1F87, 0x1F8F],
10418 [0x1F88, 0x1F80],
10419 [0x1F89, 0x1F81],
10420 [0x1F8A, 0x1F82],
10421 [0x1F8B, 0x1F83],
10422 [0x1F8C, 0x1F84],
10423 [0x1F8D, 0x1F85],
10424 [0x1F8E, 0x1F86],
10425 [0x1F8F, 0x1F87],
10426 [0x1F90, 0x1F98],
10427 [0x1F91, 0x1F99],
10428 [0x1F92, 0x1F9A],
10429 [0x1F93, 0x1F9B],
10430 [0x1F94, 0x1F9C],
10431 [0x1F95, 0x1F9D],
10432 [0x1F96, 0x1F9E],
10433 [0x1F97, 0x1F9F],
10434 [0x1F98, 0x1F90],
10435 [0x1F99, 0x1F91],
10436 [0x1F9A, 0x1F92],
10437 [0x1F9B, 0x1F93],
10438 [0x1F9C, 0x1F94],
10439 [0x1F9D, 0x1F95],
10440 [0x1F9E, 0x1F96],
10441 [0x1F9F, 0x1F97],
10442 [0x1FA0, 0x1FA8],
10443 [0x1FA1, 0x1FA9],
10444 [0x1FA2, 0x1FAA],
10445 [0x1FA3, 0x1FAB],
10446 [0x1FA4, 0x1FAC],
10447 [0x1FA5, 0x1FAD],
10448 [0x1FA6, 0x1FAE],
10449 [0x1FA7, 0x1FAF],
10450 [0x1FA8, 0x1FA0],
10451 [0x1FA9, 0x1FA1],
10452 [0x1FAA, 0x1FA2],
10453 [0x1FAB, 0x1FA3],
10454 [0x1FAC, 0x1FA4],
10455 [0x1FAD, 0x1FA5],
10456 [0x1FAE, 0x1FA6],
10457 [0x1FAF, 0x1FA7],
10458 [0x1FB3, 0x1FBC],
10459 [0x1FBC, 0x1FB3],
10460 [0x1FBE, [
10461 0x345,
10462 0x399
10463 ]],
10464 [0x1FC3, 0x1FCC],
10465 [0x1FCC, 0x1FC3],
10466 [0x1FF3, 0x1FFC],
10467 [0x1FFC, 0x1FF3],
10468 [0x2126, [
10469 0x3A9,
10470 0x3C9
10471 ]],
10472 [0x212A, 0x4B],
10473 [0x212B, [
10474 0xC5,
10475 0xE5
10476 ]],
10477 [0xA64A, 0x1C88],
10478 [0xA64B, 0x1C88],
10479 [0xA7AE, 0x26A],
10480 [0xA7B2, 0x29D],
10481 [0xA7B3, 0xAB53],
10482 [0xA7B4, 0xA7B5],
10483 [0xA7B5, 0xA7B4],
10484 [0xA7B6, 0xA7B7],
10485 [0xA7B7, 0xA7B6],
10486 [0xAB53, 0xA7B3],
10487 [0xAB70, 0x13A0],
10488 [0xAB71, 0x13A1],
10489 [0xAB72, 0x13A2],
10490 [0xAB73, 0x13A3],
10491 [0xAB74, 0x13A4],
10492 [0xAB75, 0x13A5],
10493 [0xAB76, 0x13A6],
10494 [0xAB77, 0x13A7],
10495 [0xAB78, 0x13A8],
10496 [0xAB79, 0x13A9],
10497 [0xAB7A, 0x13AA],
10498 [0xAB7B, 0x13AB],
10499 [0xAB7C, 0x13AC],
10500 [0xAB7D, 0x13AD],
10501 [0xAB7E, 0x13AE],
10502 [0xAB7F, 0x13AF],
10503 [0xAB80, 0x13B0],
10504 [0xAB81, 0x13B1],
10505 [0xAB82, 0x13B2],
10506 [0xAB83, 0x13B3],
10507 [0xAB84, 0x13B4],
10508 [0xAB85, 0x13B5],
10509 [0xAB86, 0x13B6],
10510 [0xAB87, 0x13B7],
10511 [0xAB88, 0x13B8],
10512 [0xAB89, 0x13B9],
10513 [0xAB8A, 0x13BA],
10514 [0xAB8B, 0x13BB],
10515 [0xAB8C, 0x13BC],
10516 [0xAB8D, 0x13BD],
10517 [0xAB8E, 0x13BE],
10518 [0xAB8F, 0x13BF],
10519 [0xAB90, 0x13C0],
10520 [0xAB91, 0x13C1],
10521 [0xAB92, 0x13C2],
10522 [0xAB93, 0x13C3],
10523 [0xAB94, 0x13C4],
10524 [0xAB95, 0x13C5],
10525 [0xAB96, 0x13C6],
10526 [0xAB97, 0x13C7],
10527 [0xAB98, 0x13C8],
10528 [0xAB99, 0x13C9],
10529 [0xAB9A, 0x13CA],
10530 [0xAB9B, 0x13CB],
10531 [0xAB9C, 0x13CC],
10532 [0xAB9D, 0x13CD],
10533 [0xAB9E, 0x13CE],
10534 [0xAB9F, 0x13CF],
10535 [0xABA0, 0x13D0],
10536 [0xABA1, 0x13D1],
10537 [0xABA2, 0x13D2],
10538 [0xABA3, 0x13D3],
10539 [0xABA4, 0x13D4],
10540 [0xABA5, 0x13D5],
10541 [0xABA6, 0x13D6],
10542 [0xABA7, 0x13D7],
10543 [0xABA8, 0x13D8],
10544 [0xABA9, 0x13D9],
10545 [0xABAA, 0x13DA],
10546 [0xABAB, 0x13DB],
10547 [0xABAC, 0x13DC],
10548 [0xABAD, 0x13DD],
10549 [0xABAE, 0x13DE],
10550 [0xABAF, 0x13DF],
10551 [0xABB0, 0x13E0],
10552 [0xABB1, 0x13E1],
10553 [0xABB2, 0x13E2],
10554 [0xABB3, 0x13E3],
10555 [0xABB4, 0x13E4],
10556 [0xABB5, 0x13E5],
10557 [0xABB6, 0x13E6],
10558 [0xABB7, 0x13E7],
10559 [0xABB8, 0x13E8],
10560 [0xABB9, 0x13E9],
10561 [0xABBA, 0x13EA],
10562 [0xABBB, 0x13EB],
10563 [0xABBC, 0x13EC],
10564 [0xABBD, 0x13ED],
10565 [0xABBE, 0x13EE],
10566 [0xABBF, 0x13EF],
10567 [0x10400, 0x10428],
10568 [0x10401, 0x10429],
10569 [0x10402, 0x1042A],
10570 [0x10403, 0x1042B],
10571 [0x10404, 0x1042C],
10572 [0x10405, 0x1042D],
10573 [0x10406, 0x1042E],
10574 [0x10407, 0x1042F],
10575 [0x10408, 0x10430],
10576 [0x10409, 0x10431],
10577 [0x1040A, 0x10432],
10578 [0x1040B, 0x10433],
10579 [0x1040C, 0x10434],
10580 [0x1040D, 0x10435],
10581 [0x1040E, 0x10436],
10582 [0x1040F, 0x10437],
10583 [0x10410, 0x10438],
10584 [0x10411, 0x10439],
10585 [0x10412, 0x1043A],
10586 [0x10413, 0x1043B],
10587 [0x10414, 0x1043C],
10588 [0x10415, 0x1043D],
10589 [0x10416, 0x1043E],
10590 [0x10417, 0x1043F],
10591 [0x10418, 0x10440],
10592 [0x10419, 0x10441],
10593 [0x1041A, 0x10442],
10594 [0x1041B, 0x10443],
10595 [0x1041C, 0x10444],
10596 [0x1041D, 0x10445],
10597 [0x1041E, 0x10446],
10598 [0x1041F, 0x10447],
10599 [0x10420, 0x10448],
10600 [0x10421, 0x10449],
10601 [0x10422, 0x1044A],
10602 [0x10423, 0x1044B],
10603 [0x10424, 0x1044C],
10604 [0x10425, 0x1044D],
10605 [0x10426, 0x1044E],
10606 [0x10427, 0x1044F],
10607 [0x10428, 0x10400],
10608 [0x10429, 0x10401],
10609 [0x1042A, 0x10402],
10610 [0x1042B, 0x10403],
10611 [0x1042C, 0x10404],
10612 [0x1042D, 0x10405],
10613 [0x1042E, 0x10406],
10614 [0x1042F, 0x10407],
10615 [0x10430, 0x10408],
10616 [0x10431, 0x10409],
10617 [0x10432, 0x1040A],
10618 [0x10433, 0x1040B],
10619 [0x10434, 0x1040C],
10620 [0x10435, 0x1040D],
10621 [0x10436, 0x1040E],
10622 [0x10437, 0x1040F],
10623 [0x10438, 0x10410],
10624 [0x10439, 0x10411],
10625 [0x1043A, 0x10412],
10626 [0x1043B, 0x10413],
10627 [0x1043C, 0x10414],
10628 [0x1043D, 0x10415],
10629 [0x1043E, 0x10416],
10630 [0x1043F, 0x10417],
10631 [0x10440, 0x10418],
10632 [0x10441, 0x10419],
10633 [0x10442, 0x1041A],
10634 [0x10443, 0x1041B],
10635 [0x10444, 0x1041C],
10636 [0x10445, 0x1041D],
10637 [0x10446, 0x1041E],
10638 [0x10447, 0x1041F],
10639 [0x10448, 0x10420],
10640 [0x10449, 0x10421],
10641 [0x1044A, 0x10422],
10642 [0x1044B, 0x10423],
10643 [0x1044C, 0x10424],
10644 [0x1044D, 0x10425],
10645 [0x1044E, 0x10426],
10646 [0x1044F, 0x10427],
10647 [0x104B0, 0x104D8],
10648 [0x104B1, 0x104D9],
10649 [0x104B2, 0x104DA],
10650 [0x104B3, 0x104DB],
10651 [0x104B4, 0x104DC],
10652 [0x104B5, 0x104DD],
10653 [0x104B6, 0x104DE],
10654 [0x104B7, 0x104DF],
10655 [0x104B8, 0x104E0],
10656 [0x104B9, 0x104E1],
10657 [0x104BA, 0x104E2],
10658 [0x104BB, 0x104E3],
10659 [0x104BC, 0x104E4],
10660 [0x104BD, 0x104E5],
10661 [0x104BE, 0x104E6],
10662 [0x104BF, 0x104E7],
10663 [0x104C0, 0x104E8],
10664 [0x104C1, 0x104E9],
10665 [0x104C2, 0x104EA],
10666 [0x104C3, 0x104EB],
10667 [0x104C4, 0x104EC],
10668 [0x104C5, 0x104ED],
10669 [0x104C6, 0x104EE],
10670 [0x104C7, 0x104EF],
10671 [0x104C8, 0x104F0],
10672 [0x104C9, 0x104F1],
10673 [0x104CA, 0x104F2],
10674 [0x104CB, 0x104F3],
10675 [0x104CC, 0x104F4],
10676 [0x104CD, 0x104F5],
10677 [0x104CE, 0x104F6],
10678 [0x104CF, 0x104F7],
10679 [0x104D0, 0x104F8],
10680 [0x104D1, 0x104F9],
10681 [0x104D2, 0x104FA],
10682 [0x104D3, 0x104FB],
10683 [0x104D8, 0x104B0],
10684 [0x104D9, 0x104B1],
10685 [0x104DA, 0x104B2],
10686 [0x104DB, 0x104B3],
10687 [0x104DC, 0x104B4],
10688 [0x104DD, 0x104B5],
10689 [0x104DE, 0x104B6],
10690 [0x104DF, 0x104B7],
10691 [0x104E0, 0x104B8],
10692 [0x104E1, 0x104B9],
10693 [0x104E2, 0x104BA],
10694 [0x104E3, 0x104BB],
10695 [0x104E4, 0x104BC],
10696 [0x104E5, 0x104BD],
10697 [0x104E6, 0x104BE],
10698 [0x104E7, 0x104BF],
10699 [0x104E8, 0x104C0],
10700 [0x104E9, 0x104C1],
10701 [0x104EA, 0x104C2],
10702 [0x104EB, 0x104C3],
10703 [0x104EC, 0x104C4],
10704 [0x104ED, 0x104C5],
10705 [0x104EE, 0x104C6],
10706 [0x104EF, 0x104C7],
10707 [0x104F0, 0x104C8],
10708 [0x104F1, 0x104C9],
10709 [0x104F2, 0x104CA],
10710 [0x104F3, 0x104CB],
10711 [0x104F4, 0x104CC],
10712 [0x104F5, 0x104CD],
10713 [0x104F6, 0x104CE],
10714 [0x104F7, 0x104CF],
10715 [0x104F8, 0x104D0],
10716 [0x104F9, 0x104D1],
10717 [0x104FA, 0x104D2],
10718 [0x104FB, 0x104D3],
10719 [0x10C80, 0x10CC0],
10720 [0x10C81, 0x10CC1],
10721 [0x10C82, 0x10CC2],
10722 [0x10C83, 0x10CC3],
10723 [0x10C84, 0x10CC4],
10724 [0x10C85, 0x10CC5],
10725 [0x10C86, 0x10CC6],
10726 [0x10C87, 0x10CC7],
10727 [0x10C88, 0x10CC8],
10728 [0x10C89, 0x10CC9],
10729 [0x10C8A, 0x10CCA],
10730 [0x10C8B, 0x10CCB],
10731 [0x10C8C, 0x10CCC],
10732 [0x10C8D, 0x10CCD],
10733 [0x10C8E, 0x10CCE],
10734 [0x10C8F, 0x10CCF],
10735 [0x10C90, 0x10CD0],
10736 [0x10C91, 0x10CD1],
10737 [0x10C92, 0x10CD2],
10738 [0x10C93, 0x10CD3],
10739 [0x10C94, 0x10CD4],
10740 [0x10C95, 0x10CD5],
10741 [0x10C96, 0x10CD6],
10742 [0x10C97, 0x10CD7],
10743 [0x10C98, 0x10CD8],
10744 [0x10C99, 0x10CD9],
10745 [0x10C9A, 0x10CDA],
10746 [0x10C9B, 0x10CDB],
10747 [0x10C9C, 0x10CDC],
10748 [0x10C9D, 0x10CDD],
10749 [0x10C9E, 0x10CDE],
10750 [0x10C9F, 0x10CDF],
10751 [0x10CA0, 0x10CE0],
10752 [0x10CA1, 0x10CE1],
10753 [0x10CA2, 0x10CE2],
10754 [0x10CA3, 0x10CE3],
10755 [0x10CA4, 0x10CE4],
10756 [0x10CA5, 0x10CE5],
10757 [0x10CA6, 0x10CE6],
10758 [0x10CA7, 0x10CE7],
10759 [0x10CA8, 0x10CE8],
10760 [0x10CA9, 0x10CE9],
10761 [0x10CAA, 0x10CEA],
10762 [0x10CAB, 0x10CEB],
10763 [0x10CAC, 0x10CEC],
10764 [0x10CAD, 0x10CED],
10765 [0x10CAE, 0x10CEE],
10766 [0x10CAF, 0x10CEF],
10767 [0x10CB0, 0x10CF0],
10768 [0x10CB1, 0x10CF1],
10769 [0x10CB2, 0x10CF2],
10770 [0x10CC0, 0x10C80],
10771 [0x10CC1, 0x10C81],
10772 [0x10CC2, 0x10C82],
10773 [0x10CC3, 0x10C83],
10774 [0x10CC4, 0x10C84],
10775 [0x10CC5, 0x10C85],
10776 [0x10CC6, 0x10C86],
10777 [0x10CC7, 0x10C87],
10778 [0x10CC8, 0x10C88],
10779 [0x10CC9, 0x10C89],
10780 [0x10CCA, 0x10C8A],
10781 [0x10CCB, 0x10C8B],
10782 [0x10CCC, 0x10C8C],
10783 [0x10CCD, 0x10C8D],
10784 [0x10CCE, 0x10C8E],
10785 [0x10CCF, 0x10C8F],
10786 [0x10CD0, 0x10C90],
10787 [0x10CD1, 0x10C91],
10788 [0x10CD2, 0x10C92],
10789 [0x10CD3, 0x10C93],
10790 [0x10CD4, 0x10C94],
10791 [0x10CD5, 0x10C95],
10792 [0x10CD6, 0x10C96],
10793 [0x10CD7, 0x10C97],
10794 [0x10CD8, 0x10C98],
10795 [0x10CD9, 0x10C99],
10796 [0x10CDA, 0x10C9A],
10797 [0x10CDB, 0x10C9B],
10798 [0x10CDC, 0x10C9C],
10799 [0x10CDD, 0x10C9D],
10800 [0x10CDE, 0x10C9E],
10801 [0x10CDF, 0x10C9F],
10802 [0x10CE0, 0x10CA0],
10803 [0x10CE1, 0x10CA1],
10804 [0x10CE2, 0x10CA2],
10805 [0x10CE3, 0x10CA3],
10806 [0x10CE4, 0x10CA4],
10807 [0x10CE5, 0x10CA5],
10808 [0x10CE6, 0x10CA6],
10809 [0x10CE7, 0x10CA7],
10810 [0x10CE8, 0x10CA8],
10811 [0x10CE9, 0x10CA9],
10812 [0x10CEA, 0x10CAA],
10813 [0x10CEB, 0x10CAB],
10814 [0x10CEC, 0x10CAC],
10815 [0x10CED, 0x10CAD],
10816 [0x10CEE, 0x10CAE],
10817 [0x10CEF, 0x10CAF],
10818 [0x10CF0, 0x10CB0],
10819 [0x10CF1, 0x10CB1],
10820 [0x10CF2, 0x10CB2],
10821 [0x118A0, 0x118C0],
10822 [0x118A1, 0x118C1],
10823 [0x118A2, 0x118C2],
10824 [0x118A3, 0x118C3],
10825 [0x118A4, 0x118C4],
10826 [0x118A5, 0x118C5],
10827 [0x118A6, 0x118C6],
10828 [0x118A7, 0x118C7],
10829 [0x118A8, 0x118C8],
10830 [0x118A9, 0x118C9],
10831 [0x118AA, 0x118CA],
10832 [0x118AB, 0x118CB],
10833 [0x118AC, 0x118CC],
10834 [0x118AD, 0x118CD],
10835 [0x118AE, 0x118CE],
10836 [0x118AF, 0x118CF],
10837 [0x118B0, 0x118D0],
10838 [0x118B1, 0x118D1],
10839 [0x118B2, 0x118D2],
10840 [0x118B3, 0x118D3],
10841 [0x118B4, 0x118D4],
10842 [0x118B5, 0x118D5],
10843 [0x118B6, 0x118D6],
10844 [0x118B7, 0x118D7],
10845 [0x118B8, 0x118D8],
10846 [0x118B9, 0x118D9],
10847 [0x118BA, 0x118DA],
10848 [0x118BB, 0x118DB],
10849 [0x118BC, 0x118DC],
10850 [0x118BD, 0x118DD],
10851 [0x118BE, 0x118DE],
10852 [0x118BF, 0x118DF],
10853 [0x118C0, 0x118A0],
10854 [0x118C1, 0x118A1],
10855 [0x118C2, 0x118A2],
10856 [0x118C3, 0x118A3],
10857 [0x118C4, 0x118A4],
10858 [0x118C5, 0x118A5],
10859 [0x118C6, 0x118A6],
10860 [0x118C7, 0x118A7],
10861 [0x118C8, 0x118A8],
10862 [0x118C9, 0x118A9],
10863 [0x118CA, 0x118AA],
10864 [0x118CB, 0x118AB],
10865 [0x118CC, 0x118AC],
10866 [0x118CD, 0x118AD],
10867 [0x118CE, 0x118AE],
10868 [0x118CF, 0x118AF],
10869 [0x118D0, 0x118B0],
10870 [0x118D1, 0x118B1],
10871 [0x118D2, 0x118B2],
10872 [0x118D3, 0x118B3],
10873 [0x118D4, 0x118B4],
10874 [0x118D5, 0x118B5],
10875 [0x118D6, 0x118B6],
10876 [0x118D7, 0x118B7],
10877 [0x118D8, 0x118B8],
10878 [0x118D9, 0x118B9],
10879 [0x118DA, 0x118BA],
10880 [0x118DB, 0x118BB],
10881 [0x118DC, 0x118BC],
10882 [0x118DD, 0x118BD],
10883 [0x118DE, 0x118BE],
10884 [0x118DF, 0x118BF],
10885 [0x1E900, 0x1E922],
10886 [0x1E901, 0x1E923],
10887 [0x1E902, 0x1E924],
10888 [0x1E903, 0x1E925],
10889 [0x1E904, 0x1E926],
10890 [0x1E905, 0x1E927],
10891 [0x1E906, 0x1E928],
10892 [0x1E907, 0x1E929],
10893 [0x1E908, 0x1E92A],
10894 [0x1E909, 0x1E92B],
10895 [0x1E90A, 0x1E92C],
10896 [0x1E90B, 0x1E92D],
10897 [0x1E90C, 0x1E92E],
10898 [0x1E90D, 0x1E92F],
10899 [0x1E90E, 0x1E930],
10900 [0x1E90F, 0x1E931],
10901 [0x1E910, 0x1E932],
10902 [0x1E911, 0x1E933],
10903 [0x1E912, 0x1E934],
10904 [0x1E913, 0x1E935],
10905 [0x1E914, 0x1E936],
10906 [0x1E915, 0x1E937],
10907 [0x1E916, 0x1E938],
10908 [0x1E917, 0x1E939],
10909 [0x1E918, 0x1E93A],
10910 [0x1E919, 0x1E93B],
10911 [0x1E91A, 0x1E93C],
10912 [0x1E91B, 0x1E93D],
10913 [0x1E91C, 0x1E93E],
10914 [0x1E91D, 0x1E93F],
10915 [0x1E91E, 0x1E940],
10916 [0x1E91F, 0x1E941],
10917 [0x1E920, 0x1E942],
10918 [0x1E921, 0x1E943],
10919 [0x1E922, 0x1E900],
10920 [0x1E923, 0x1E901],
10921 [0x1E924, 0x1E902],
10922 [0x1E925, 0x1E903],
10923 [0x1E926, 0x1E904],
10924 [0x1E927, 0x1E905],
10925 [0x1E928, 0x1E906],
10926 [0x1E929, 0x1E907],
10927 [0x1E92A, 0x1E908],
10928 [0x1E92B, 0x1E909],
10929 [0x1E92C, 0x1E90A],
10930 [0x1E92D, 0x1E90B],
10931 [0x1E92E, 0x1E90C],
10932 [0x1E92F, 0x1E90D],
10933 [0x1E930, 0x1E90E],
10934 [0x1E931, 0x1E90F],
10935 [0x1E932, 0x1E910],
10936 [0x1E933, 0x1E911],
10937 [0x1E934, 0x1E912],
10938 [0x1E935, 0x1E913],
10939 [0x1E936, 0x1E914],
10940 [0x1E937, 0x1E915],
10941 [0x1E938, 0x1E916],
10942 [0x1E939, 0x1E917],
10943 [0x1E93A, 0x1E918],
10944 [0x1E93B, 0x1E919],
10945 [0x1E93C, 0x1E91A],
10946 [0x1E93D, 0x1E91B],
10947 [0x1E93E, 0x1E91C],
10948 [0x1E93F, 0x1E91D],
10949 [0x1E940, 0x1E91E],
10950 [0x1E941, 0x1E91F],
10951 [0x1E942, 0x1E920],
10952 [0x1E943, 0x1E921]
10953]);
10954
10955// Generated using `npm run build`. Do not edit.
10956'use strict';
10957
10958
10959
10960var REGULAR = new Map([
10961 ['d', regenerate()
10962 .addRange(0x30, 0x39)],
10963 ['D', regenerate()
10964 .addRange(0x0, 0x2F)
10965 .addRange(0x3A, 0xFFFF)],
10966 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
10967 .addRange(0x9, 0xD)
10968 .addRange(0x2000, 0x200A)
10969 .addRange(0x2028, 0x2029)],
10970 ['S', regenerate()
10971 .addRange(0x0, 0x8)
10972 .addRange(0xE, 0x1F)
10973 .addRange(0x21, 0x9F)
10974 .addRange(0xA1, 0x167F)
10975 .addRange(0x1681, 0x1FFF)
10976 .addRange(0x200B, 0x2027)
10977 .addRange(0x202A, 0x202E)
10978 .addRange(0x2030, 0x205E)
10979 .addRange(0x2060, 0x2FFF)
10980 .addRange(0x3001, 0xFEFE)
10981 .addRange(0xFF00, 0xFFFF)],
10982 ['w', regenerate(0x5F)
10983 .addRange(0x30, 0x39)
10984 .addRange(0x41, 0x5A)
10985 .addRange(0x61, 0x7A)],
10986 ['W', regenerate(0x60)
10987 .addRange(0x0, 0x2F)
10988 .addRange(0x3A, 0x40)
10989 .addRange(0x5B, 0x5E)
10990 .addRange(0x7B, 0xFFFF)]
10991]);
10992
10993var UNICODE = new Map([
10994 ['d', regenerate()
10995 .addRange(0x30, 0x39)],
10996 ['D', regenerate()
10997 .addRange(0x0, 0x2F)
10998 .addRange(0x3A, 0x10FFFF)],
10999 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
11000 .addRange(0x9, 0xD)
11001 .addRange(0x2000, 0x200A)
11002 .addRange(0x2028, 0x2029)],
11003 ['S', regenerate()
11004 .addRange(0x0, 0x8)
11005 .addRange(0xE, 0x1F)
11006 .addRange(0x21, 0x9F)
11007 .addRange(0xA1, 0x167F)
11008 .addRange(0x1681, 0x1FFF)
11009 .addRange(0x200B, 0x2027)
11010 .addRange(0x202A, 0x202E)
11011 .addRange(0x2030, 0x205E)
11012 .addRange(0x2060, 0x2FFF)
11013 .addRange(0x3001, 0xFEFE)
11014 .addRange(0xFF00, 0x10FFFF)],
11015 ['w', regenerate(0x5F)
11016 .addRange(0x30, 0x39)
11017 .addRange(0x41, 0x5A)
11018 .addRange(0x61, 0x7A)],
11019 ['W', regenerate(0x60)
11020 .addRange(0x0, 0x2F)
11021 .addRange(0x3A, 0x40)
11022 .addRange(0x5B, 0x5E)
11023 .addRange(0x7B, 0x10FFFF)]
11024]);
11025
11026var UNICODE_IGNORE_CASE = new Map([
11027 ['d', regenerate()
11028 .addRange(0x30, 0x39)],
11029 ['D', regenerate()
11030 .addRange(0x0, 0x2F)
11031 .addRange(0x3A, 0x10FFFF)],
11032 ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
11033 .addRange(0x9, 0xD)
11034 .addRange(0x2000, 0x200A)
11035 .addRange(0x2028, 0x2029)],
11036 ['S', regenerate()
11037 .addRange(0x0, 0x8)
11038 .addRange(0xE, 0x1F)
11039 .addRange(0x21, 0x9F)
11040 .addRange(0xA1, 0x167F)
11041 .addRange(0x1681, 0x1FFF)
11042 .addRange(0x200B, 0x2027)
11043 .addRange(0x202A, 0x202E)
11044 .addRange(0x2030, 0x205E)
11045 .addRange(0x2060, 0x2FFF)
11046 .addRange(0x3001, 0xFEFE)
11047 .addRange(0xFF00, 0x10FFFF)],
11048 ['w', regenerate(0x5F, 0x17F, 0x212A)
11049 .addRange(0x30, 0x39)
11050 .addRange(0x41, 0x5A)
11051 .addRange(0x61, 0x7A)],
11052 ['W', regenerate(0x60)
11053 .addRange(0x0, 0x2F)
11054 .addRange(0x3A, 0x40)
11055 .addRange(0x5B, 0x5E)
11056 .addRange(0x7B, 0x17E)
11057 .addRange(0x180, 0x2129)
11058 .addRange(0x212B, 0x10FFFF)]
11059]);
11060
11061var characterClassEscapeSets = {
11062 REGULAR: REGULAR,
11063 UNICODE: UNICODE,
11064 UNICODE_IGNORE_CASE: UNICODE_IGNORE_CASE
11065};
11066
11067var rewritePattern_1 = createCommonjsModule(function (module) {
11068'use strict';
11069
11070var generate = regjsgen.generate;
11071var parse = parser.parse;
11072
11073
11074
11075
11076
11077
11078// Prepare a Regenerate set containing all code points, used for negative
11079// character classes (if any).
11080var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
11081// Without the `u` flag, the range stops at 0xFFFF.
11082// https://mths.be/es6#sec-pattern-semantics
11083var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
11084
11085// Prepare a Regenerate set containing all code points that are supposed to be
11086// matched by `/./u`. https://mths.be/es6#sec-atom
11087var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
11088 .remove(
11089 // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
11090 0x000A, // Line Feed <LF>
11091 0x000D, // Carriage Return <CR>
11092 0x2028, // Line Separator <LS>
11093 0x2029 // Paragraph Separator <PS>
11094 );
11095// Prepare a Regenerate set containing all code points that are supposed to be
11096// matched by `/./` (only BMP code points).
11097var DOT_SET = DOT_SET_UNICODE.clone()
11098 .intersection(BMP_SET);
11099
11100var getCharacterClassEscapeSet = function (character, unicode, ignoreCase) {
11101 if (unicode) {
11102 if (ignoreCase) {
11103 return characterClassEscapeSets.UNICODE_IGNORE_CASE.get(character);
11104 }
11105 return characterClassEscapeSets.UNICODE.get(character);
11106 }
11107 return characterClassEscapeSets.REGULAR.get(character);
11108};
11109
11110var getDotSet = function (unicode, dotAll) {
11111 if (dotAll) {
11112 return unicode ? UNICODE_SET : BMP_SET;
11113 }
11114 return unicode ? DOT_SET_UNICODE : DOT_SET;
11115};
11116
11117var getUnicodePropertyValueSet = function (property, value) {
11118 var path = value ?
11119 (property + "/" + value) :
11120 ("Binary_Property/" + property);
11121 try {
11122 return commonjsRequire(("regenerate-unicode-properties/" + path + ".js"));
11123 } catch (exception) {
11124 throw new Error(
11125 "Failed to recognize value `" + value + "` for property " +
11126 "`" + property + "`."
11127 );
11128 }
11129};
11130
11131var handleLoneUnicodePropertyNameOrValue = function (value) {
11132 // It could be a `General_Category` value or a binary property.
11133 // Note: `unicodeMatchPropertyValue` throws on invalid values.
11134 try {
11135 var property$1 = 'General_Category';
11136 var category = unicodeMatchPropertyValueEcmascript(property$1, value);
11137 return getUnicodePropertyValueSet(property$1, category);
11138 } catch (exception) {}
11139 // It’s not a `General_Category` value, so check if it’s a binary
11140 // property. Note: `unicodeMatchProperty` throws on invalid properties.
11141 var property = unicodeMatchPropertyEcmascript(value);
11142 return getUnicodePropertyValueSet(property);
11143};
11144
11145var getUnicodePropertyEscapeSet = function (value, isNegative) {
11146 var parts = value.split('=');
11147 var firstPart = parts[0];
11148 var set;
11149 if (parts.length == 1) {
11150 set = handleLoneUnicodePropertyNameOrValue(firstPart);
11151 } else {
11152 // The pattern consists of two parts, i.e. `Property=Value`.
11153 var property = unicodeMatchPropertyEcmascript(firstPart);
11154 var value$1 = unicodeMatchPropertyValueEcmascript(property, parts[1]);
11155 set = getUnicodePropertyValueSet(property, value$1);
11156 }
11157 if (isNegative) {
11158 return UNICODE_SET.clone().remove(set);
11159 }
11160 return set.clone();
11161};
11162
11163// Given a range of code points, add any case-folded code points in that range
11164// to a set.
11165regenerate.prototype.iuAddRange = function(min, max) {
11166 var $this = this;
11167 do {
11168 var folded = caseFold(min);
11169 if (folded) {
11170 $this.add(folded);
11171 }
11172 } while (++min <= max);
11173 return $this;
11174};
11175
11176var update = function (item, pattern) {
11177 var tree = parse(pattern, config.useUnicodeFlag ? 'u' : '');
11178 switch (tree.type) {
11179 case 'characterClass':
11180 case 'group':
11181 case 'value':
11182 // No wrapping needed.
11183 break;
11184 default:
11185 // Wrap the pattern in a non-capturing group.
11186 tree = wrap(tree, pattern);
11187 }
11188 Object.assign(item, tree);
11189};
11190
11191var wrap = function (tree, pattern) {
11192 // Wrap the pattern in a non-capturing group.
11193 return {
11194 'type': 'group',
11195 'behavior': 'ignore',
11196 'body': [tree],
11197 'raw': ("(?:" + pattern + ")")
11198 };
11199};
11200
11201var caseFold = function (codePoint) {
11202 return iuMappings.get(codePoint) || false;
11203};
11204
11205var processCharacterClass = function (characterClassItem, regenerateOptions) {
11206 var set = regenerate();
11207 for (var i = 0, list = characterClassItem.body; i < list.length; i += 1) {
11208 var item = list[i];
11209
11210 switch (item.type) {
11211 case 'value':
11212 set.add(item.codePoint);
11213 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11214 var folded = caseFold(item.codePoint);
11215 if (folded) {
11216 set.add(folded);
11217 }
11218 }
11219 break;
11220 case 'characterClassRange':
11221 var min = item.min.codePoint;
11222 var max = item.max.codePoint;
11223 set.addRange(min, max);
11224 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11225 set.iuAddRange(min, max);
11226 }
11227 break;
11228 case 'characterClassEscape':
11229 set.add(getCharacterClassEscapeSet(
11230 item.value,
11231 config.unicode,
11232 config.ignoreCase
11233 ));
11234 break;
11235 case 'unicodePropertyEscape':
11236 set.add(getUnicodePropertyEscapeSet(item.value, item.negative));
11237 break;
11238 // The `default` clause is only here as a safeguard; it should never be
11239 // reached. Code coverage tools should ignore it.
11240 /* istanbul ignore next */
11241 default:
11242 throw new Error(("Unknown term type: " + (item.type)));
11243 }
11244 }
11245 if (characterClassItem.negative) {
11246 set = (config.unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
11247 }
11248 update(characterClassItem, set.toString(regenerateOptions));
11249 return characterClassItem;
11250};
11251
11252var processTerm = function (item, regenerateOptions) {
11253 switch (item.type) {
11254 case 'dot':
11255 update(
11256 item,
11257 getDotSet(config.unicode, config.dotAll).toString(regenerateOptions)
11258 );
11259 break;
11260 case 'characterClass':
11261 item = processCharacterClass(item, regenerateOptions);
11262 break;
11263 case 'unicodePropertyEscape':
11264 update(
11265 item,
11266 getUnicodePropertyEscapeSet(item.value, item.negative)
11267 .toString(regenerateOptions)
11268 );
11269 break;
11270 case 'characterClassEscape':
11271 update(
11272 item,
11273 getCharacterClassEscapeSet(
11274 item.value,
11275 config.unicode,
11276 config.ignoreCase
11277 ).toString(regenerateOptions)
11278 );
11279 break;
11280 case 'alternative':
11281 case 'disjunction':
11282 case 'group':
11283 case 'quantifier':
11284 item.body = item.body.map(function ( term ) {
11285 return processTerm(term, regenerateOptions);
11286 });
11287 break;
11288 case 'value':
11289 var codePoint = item.codePoint;
11290 var set = regenerate(codePoint);
11291 if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
11292 var folded = caseFold(codePoint);
11293 if (folded) {
11294 set.add(folded);
11295 }
11296 }
11297 update(item, set.toString(regenerateOptions));
11298 break;
11299 case 'anchor':
11300 case 'empty':
11301 case 'group':
11302 case 'reference':
11303 // Nothing to do here.
11304 break;
11305 // The `default` clause is only here as a safeguard; it should never be
11306 // reached. Code coverage tools should ignore it.
11307 /* istanbul ignore next */
11308 default:
11309 throw new Error(("Unknown term type: " + (item.type)));
11310 }
11311 return item;
11312};
11313
11314var config = {
11315 'ignoreCase': false,
11316 'unicode': false,
11317 'dotAll': false,
11318 'useUnicodeFlag': false
11319};
11320var rewritePattern = function (pattern, flags, options) {
11321 var regjsparserFeatures = {
11322 'unicodePropertyEscape': options && options.unicodePropertyEscape
11323 };
11324 config.ignoreCase = flags && flags.includes('i');
11325 config.unicode = flags && flags.includes('u');
11326 var supportDotAllFlag = options && options.dotAllFlag;
11327 config.dotAll = supportDotAllFlag && flags && flags.includes('s');
11328 config.useUnicodeFlag = options && options.useUnicodeFlag;
11329 var regenerateOptions = {
11330 'hasUnicodeFlag': config.useUnicodeFlag,
11331 'bmpOnly': !config.unicode
11332 };
11333 var tree = parse(pattern, flags, regjsparserFeatures);
11334 // Note: `processTerm` mutates `tree`.
11335 processTerm(tree, regenerateOptions);
11336 return generate(tree);
11337};
11338
11339module.exports = rewritePattern;
11340});
11341
11342var Literal = (function (Node) {
11343 function Literal () {
11344 Node.apply(this, arguments);
11345 }
11346
11347 if ( Node ) Literal.__proto__ = Node;
11348 Literal.prototype = Object.create( Node && Node.prototype );
11349 Literal.prototype.constructor = Literal;
11350
11351 Literal.prototype.initialise = function initialise () {
11352 if ( typeof this.value === 'string' ) {
11353 this.program.indentExclusionElements.push( this );
11354 }
11355 };
11356
11357 Literal.prototype.transpile = function transpile ( code, transforms ) {
11358 if ( transforms.numericLiteral ) {
11359 var leading = this.raw.slice( 0, 2 );
11360 if ( leading === '0b' || leading === '0o' ) {
11361 code.overwrite( this.start, this.end, String( this.value ), {
11362 storeName: true,
11363 contentOnly: true
11364 });
11365 }
11366 }
11367
11368 if ( this.regex ) {
11369 var ref = this.regex;
11370 var pattern = ref.pattern;
11371 var flags = ref.flags;
11372
11373 if ( transforms.stickyRegExp && /y/.test( flags ) ) throw new CompileError$1( 'Regular expression sticky flag is not supported', this );
11374 if ( transforms.unicodeRegExp && /u/.test( flags ) ) {
11375 code.overwrite( this.start, this.end, ("/" + (rewritePattern_1( pattern, flags )) + "/" + (flags.replace( 'u', '' ))), {
11376 contentOnly: true
11377 });
11378 }
11379 }
11380 };
11381
11382 return Literal;
11383}(Node$1));
11384
11385var MemberExpression = (function (Node) {
11386 function MemberExpression () {
11387 Node.apply(this, arguments);
11388 }
11389
11390 if ( Node ) MemberExpression.__proto__ = Node;
11391 MemberExpression.prototype = Object.create( Node && Node.prototype );
11392 MemberExpression.prototype.constructor = MemberExpression;
11393
11394 MemberExpression.prototype.transpile = function transpile ( code, transforms ) {
11395 if ( transforms.reservedProperties && reserved[ this.property.name ] ) {
11396 code.overwrite( this.object.end, this.property.start, "['" );
11397 code.appendLeft( this.property.end, "']" );
11398 }
11399
11400 Node.prototype.transpile.call( this, code, transforms );
11401 };
11402
11403 return MemberExpression;
11404}(Node$1));
11405
11406var NewExpression = (function (Node) {
11407 function NewExpression () {
11408 Node.apply(this, arguments);
11409 }
11410
11411 if ( Node ) NewExpression.__proto__ = Node;
11412 NewExpression.prototype = Object.create( Node && Node.prototype );
11413 NewExpression.prototype.constructor = NewExpression;
11414
11415 NewExpression.prototype.initialise = function initialise ( transforms ) {
11416 var this$1 = this;
11417
11418 if ( transforms.spreadRest && this.arguments.length ) {
11419 var lexicalBoundary = this.findLexicalBoundary();
11420
11421 var i = this.arguments.length;
11422 while ( i-- ) {
11423 var arg = this$1.arguments[i];
11424 if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
11425 this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
11426 break;
11427 }
11428 }
11429 }
11430
11431 Node.prototype.initialise.call( this, transforms );
11432 };
11433
11434 NewExpression.prototype.transpile = function transpile ( code, transforms ) {
11435 if ( transforms.spreadRest && this.arguments.length ) {
11436 var firstArgument = this.arguments[0];
11437 var isNew = true;
11438 var hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias, isNew );
11439
11440 if ( hasSpreadElements ) {
11441 code.prependRight( this.start + 'new'.length, ' (Function.prototype.bind.apply(' );
11442 code.overwrite( this.callee.end, firstArgument.start, ', [ null ].concat( ' );
11443 code.appendLeft( this.end, ' ))' );
11444 }
11445 }
11446
11447 Node.prototype.transpile.call( this, code, transforms );
11448 };
11449
11450 return NewExpression;
11451}(Node$1));
11452
11453var ObjectExpression = (function (Node) {
11454 function ObjectExpression () {
11455 Node.apply(this, arguments);
11456 }
11457
11458 if ( Node ) ObjectExpression.__proto__ = Node;
11459 ObjectExpression.prototype = Object.create( Node && Node.prototype );
11460 ObjectExpression.prototype.constructor = ObjectExpression;
11461
11462 ObjectExpression.prototype.transpile = function transpile ( code, transforms ) {
11463 var this$1 = this;
11464
11465 Node.prototype.transpile.call( this, code, transforms );
11466
11467 var firstPropertyStart = this.start + 1;
11468 var regularPropertyCount = 0;
11469 var spreadPropertyCount = 0;
11470 var computedPropertyCount = 0;
11471 var firstSpreadProperty = null;
11472 var firstComputedProperty = null;
11473
11474 for ( var i = 0; i < this$1.properties.length; ++i ) {
11475 var prop = this$1.properties[ i ];
11476 if ( prop.type === 'SpreadElement' ) {
11477 spreadPropertyCount += 1;
11478 if ( firstSpreadProperty === null ) firstSpreadProperty = i;
11479 } else if ( prop.computed ) {
11480 computedPropertyCount += 1;
11481 if ( firstComputedProperty === null ) firstComputedProperty = i;
11482 } else if ( prop.type === 'Property' ) {
11483 regularPropertyCount += 1;
11484 }
11485 }
11486
11487 if ( spreadPropertyCount ) {
11488 if ( !this.program.options.objectAssign ) {
11489 throw new CompileError$1( 'Object spread operator requires specified objectAssign option with \'Object.assign\' or polyfill helper.', this );
11490 }
11491 // enclose run of non-spread properties in curlies
11492 var i$1 = this.properties.length;
11493 if ( regularPropertyCount && !computedPropertyCount ) {
11494 while ( i$1-- ) {
11495 var prop$1 = this$1.properties[i$1];
11496
11497 if ( prop$1.type === 'Property' && !prop$1.computed ) {
11498 var lastProp = this$1.properties[ i$1 - 1 ];
11499 var nextProp = this$1.properties[ i$1 + 1 ];
11500
11501 if ( !lastProp || lastProp.type !== 'Property' || lastProp.computed ) {
11502 code.prependRight( prop$1.start, '{' );
11503 }
11504
11505 if ( !nextProp || nextProp.type !== 'Property' || nextProp.computed ) {
11506 code.appendLeft( prop$1.end, '}' );
11507 }
11508 }
11509 }
11510 }
11511
11512 // wrap the whole thing in Object.assign
11513 firstPropertyStart = this.properties[0].start;
11514 if ( !computedPropertyCount ) {
11515 code.overwrite( this.start, firstPropertyStart, ((this.program.options.objectAssign) + "({}, ") );
11516 code.overwrite( this.properties[ this.properties.length - 1 ].end, this.end, ')' );
11517 } else if ( this.properties[0].type === "SpreadElement" ) {
11518 code.overwrite( this.start, firstPropertyStart, ((this.program.options.objectAssign) + "({}, ") );
11519 code.remove( this.end - 1, this.end );
11520 code.appendRight( this.end, ')' );
11521 } else {
11522 code.prependLeft( this.start, ((this.program.options.objectAssign) + "(") );
11523 code.appendRight( this.end, ')' );
11524 }
11525 }
11526
11527 if ( computedPropertyCount && transforms.computedProperty ) {
11528 var i0 = this.getIndentation();
11529
11530 var isSimpleAssignment;
11531 var name;
11532
11533 if ( this.parent.type === 'VariableDeclarator' && this.parent.parent.declarations.length === 1 && this.parent.id.type === 'Identifier' ) {
11534 isSimpleAssignment = true;
11535 name = this.parent.id.alias || this.parent.id.name; // TODO is this right?
11536 } else if ( this.parent.type === 'AssignmentExpression' && this.parent.parent.type === 'ExpressionStatement' && this.parent.left.type === 'Identifier' ) {
11537 isSimpleAssignment = true;
11538 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
11539 } else if ( this.parent.type === 'AssignmentPattern' && this.parent.left.type === 'Identifier' ) {
11540 isSimpleAssignment = true;
11541 name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
11542 }
11543
11544 if ( spreadPropertyCount ) isSimpleAssignment = false;
11545
11546 // handle block scoping
11547 var declaration = this.findScope( false ).findDeclaration( name );
11548 if ( declaration ) name = declaration.name;
11549
11550 var start = firstPropertyStart;
11551 var end = this.end;
11552
11553 if ( isSimpleAssignment ) {
11554 // ???
11555 } else {
11556 if ( firstSpreadProperty === null || firstComputedProperty < firstSpreadProperty ) {
11557 name = this.findScope( true ).createIdentifier( 'obj' );
11558
11559 code.prependRight( this.start, ("( " + name + " = ") );
11560 } else name = null; // We don't actually need this variable
11561 }
11562
11563 var len = this.properties.length;
11564 var lastComputedProp;
11565 var sawNonComputedProperty = false;
11566 var isFirst = true;
11567
11568 for ( var i$2 = 0; i$2 < len; i$2 += 1 ) {
11569 var prop$2 = this$1.properties[i$2];
11570 var moveStart = i$2 > 0 ? this$1.properties[ i$2 - 1 ].end : start;
11571
11572 if ( prop$2.type === "Property" && ( prop$2.computed || ( lastComputedProp && !spreadPropertyCount ) ) ) {
11573 if ( i$2 === 0 ) moveStart = this$1.start + 1; // Trim leading whitespace
11574 lastComputedProp = prop$2;
11575
11576 if ( !name ) {
11577 name = this$1.findScope( true ).createIdentifier( 'obj' );
11578
11579 var propId = name + ( prop$2.computed ? "" : "." );
11580 code.appendRight( prop$2.start, ("( " + name + " = {}, " + propId) );
11581 } else {
11582
11583 var propId$1 = ( isSimpleAssignment ? (";\n" + i0 + name) : (", " + name) ) + ( prop$2.computed ? "" : "." );
11584
11585 if ( moveStart < prop$2.start ) {
11586 code.overwrite( moveStart, prop$2.start, propId$1 );
11587 } else {
11588 code.prependRight( prop$2.start, propId$1 );
11589 }
11590 }
11591
11592 var c = prop$2.key.end;
11593 if ( prop$2.computed ) {
11594 while ( code.original[c] !== ']' ) c += 1;
11595 c += 1;
11596 }
11597 if ( prop$2.shorthand ) {
11598 code.overwrite( prop$2.start, prop$2.key.end, code.slice( prop$2.start, prop$2.key.end ).replace( /:/, ' =' ) );
11599 } else {
11600 if ( prop$2.value.start > c ) code.remove( c, prop$2.value.start );
11601 code.appendLeft( c, ' = ' );
11602 }
11603
11604 if ( prop$2.method && transforms.conciseMethodProperty ) {
11605 code.prependRight( prop$2.value.start, 'function ' );
11606 }
11607 } else if ( prop$2.type === "SpreadElement" ) {
11608 if ( name && i$2 > 0 ) {
11609 if ( !lastComputedProp ) {
11610 lastComputedProp = this$1.properties[ i$2 - 1 ];
11611 }
11612 code.appendLeft( lastComputedProp.end, (", " + name + " )") );
11613
11614 var statement = this$1.findNearest( /(?:Statement|Declaration)$/ );
11615 code.appendLeft( statement.end, ("\n" + i0 + "var " + name + ";") );
11616
11617 lastComputedProp = null;
11618 name = null;
11619 }
11620 } else {
11621 if ( !isFirst && spreadPropertyCount ) {
11622 // We are in an Object.assign context, so we need to wrap regular properties
11623 code.prependRight( prop$2.start, '{' );
11624 code.appendLeft( prop$2.end, '}' );
11625 }
11626 sawNonComputedProperty = true;
11627 }
11628 if (isFirst && ( prop$2.type === "SpreadElement" || prop$2.computed ) ) {
11629 var beginEnd = sawNonComputedProperty ? this$1.properties[this$1.properties.length - 1].end : this$1.end - 1;
11630 // Trim trailing comma because it can easily become a leading comma which is illegal
11631 if ( code.original[beginEnd] == ',' ) ++beginEnd;
11632 var closing = code.slice( beginEnd, end );
11633 code.prependLeft( moveStart, closing );
11634 code.remove( beginEnd, end );
11635 isFirst = false;
11636 }
11637
11638 // Clean up some extranous whitespace
11639 var c$1 = prop$2.end;
11640 if ( i$2 < len - 1 && ! sawNonComputedProperty ) {
11641 while ( code.original[c$1] !== ',' ) c$1 += 1;
11642 } else if ( i$2 == len - 1 ) c$1 = this$1.end;
11643 code.remove( prop$2.end, c$1 );
11644 }
11645
11646 // special case
11647 if ( computedPropertyCount === len ) {
11648 code.remove( this.properties[ len - 1 ].end, this.end - 1 );
11649 }
11650
11651 if ( !isSimpleAssignment && name ) {
11652 code.appendLeft( lastComputedProp.end, (", " + name + " )") );
11653
11654 var statement$1 = this.findNearest( /(?:Statement|Declaration)$/ );
11655 code.appendLeft( statement$1.end, ("\n" + i0 + "var " + name + ";") );
11656 }
11657 }
11658 };
11659
11660 return ObjectExpression;
11661}(Node$1));
11662
11663var Property = (function (Node) {
11664 function Property () {
11665 Node.apply(this, arguments);
11666 }
11667
11668 if ( Node ) Property.__proto__ = Node;
11669 Property.prototype = Object.create( Node && Node.prototype );
11670 Property.prototype.constructor = Property;
11671
11672 Property.prototype.transpile = function transpile ( code, transforms ) {
11673 Node.prototype.transpile.call( this, code, transforms );
11674
11675 if ( transforms.conciseMethodProperty && !this.computed && this.parent.type !== 'ObjectPattern' ) {
11676 if ( this.shorthand ) {
11677 code.prependRight( this.start, ((this.key.name) + ": ") );
11678 } else if ( this.method ) {
11679 var name = '';
11680 if ( this.program.options.namedFunctionExpressions !== false ) {
11681 if ( this.key.type === 'Literal' && typeof this.key.value === 'number' ) {
11682 name = "";
11683 } else if ( this.key.type === 'Identifier' ) {
11684 if ( reserved[ this.key.name ] ||
11685 ! /^[a-z_$][a-z0-9_$]*$/i.test( this.key.name ) ||
11686 this.value.body.scope.references[this.key.name] ) {
11687 name = this.findScope( true ).createIdentifier( this.key.name );
11688 } else {
11689 name = this.key.name;
11690 }
11691 } else {
11692 name = this.findScope( true ).createIdentifier( this.key.value );
11693 }
11694 name = ' ' + name;
11695 }
11696
11697 if ( this.value.generator ) code.remove( this.start, this.key.start );
11698 code.appendLeft( this.key.end, (": function" + (this.value.generator ? '*' : '') + name) );
11699 }
11700 }
11701
11702 if ( transforms.reservedProperties && reserved[ this.key.name ] ) {
11703 code.prependRight( this.key.start, "'" );
11704 code.appendLeft( this.key.end, "'" );
11705 }
11706 };
11707
11708 return Property;
11709}(Node$1));
11710
11711var ReturnStatement = (function (Node) {
11712 function ReturnStatement () {
11713 Node.apply(this, arguments);
11714 }
11715
11716 if ( Node ) ReturnStatement.__proto__ = Node;
11717 ReturnStatement.prototype = Object.create( Node && Node.prototype );
11718 ReturnStatement.prototype.constructor = ReturnStatement;
11719
11720 ReturnStatement.prototype.initialise = function initialise ( transforms ) {
11721 this.loop = this.findNearest( loopStatement );
11722 this.nearestFunction = this.findNearest( /Function/ );
11723
11724 if ( this.loop && ( !this.nearestFunction || this.loop.depth > this.nearestFunction.depth ) ) {
11725 this.loop.canReturn = true;
11726 this.shouldWrap = true;
11727 }
11728
11729 if ( this.argument ) this.argument.initialise( transforms );
11730 };
11731
11732 ReturnStatement.prototype.transpile = function transpile ( code, transforms ) {
11733 var shouldWrap = this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;
11734
11735 if ( this.argument ) {
11736 if ( shouldWrap ) code.prependRight( this.argument.start, "{ v: " );
11737 this.argument.transpile( code, transforms );
11738 if ( shouldWrap ) code.appendLeft( this.argument.end, " }" );
11739 } else if ( shouldWrap ) {
11740 code.appendLeft( this.start + 6, ' {}' );
11741 }
11742 };
11743
11744 return ReturnStatement;
11745}(Node$1));
11746
11747var SpreadElement = (function (Node) {
11748 function SpreadElement () {
11749 Node.apply(this, arguments);
11750 }
11751
11752 if ( Node ) SpreadElement.__proto__ = Node;
11753 SpreadElement.prototype = Object.create( Node && Node.prototype );
11754 SpreadElement.prototype.constructor = SpreadElement;
11755
11756 SpreadElement.prototype.transpile = function transpile ( code, transforms ) {
11757 if (this.parent.type == "ObjectExpression") {
11758 code.remove( this.start, this.argument.start );
11759 code.remove( this.argument.end, this.end );
11760 }
11761
11762 Node.prototype.transpile.call( this, code, transforms );
11763 };
11764
11765 return SpreadElement;
11766}(Node$1));
11767
11768var Super = (function (Node) {
11769 function Super () {
11770 Node.apply(this, arguments);
11771 }
11772
11773 if ( Node ) Super.__proto__ = Node;
11774 Super.prototype = Object.create( Node && Node.prototype );
11775 Super.prototype.constructor = Super;
11776
11777 Super.prototype.initialise = function initialise ( transforms ) {
11778 if ( transforms.classes ) {
11779 this.method = this.findNearest( 'MethodDefinition' );
11780 if ( !this.method ) throw new CompileError$1( this, 'use of super outside class method' );
11781
11782 var parentClass = this.findNearest( 'ClassBody' ).parent;
11783 this.superClassName = parentClass.superClass && (parentClass.superClass.name || 'superclass');
11784
11785 if ( !this.superClassName ) throw new CompileError$1( 'super used in base class', this );
11786
11787 this.isCalled = this.parent.type === 'CallExpression' && this === this.parent.callee;
11788
11789 if ( this.method.kind !== 'constructor' && this.isCalled ) {
11790 throw new CompileError$1( 'super() not allowed outside class constructor', this );
11791 }
11792
11793 this.isMember = this.parent.type === 'MemberExpression';
11794
11795 if ( !this.isCalled && !this.isMember ) {
11796 throw new CompileError$1( 'Unexpected use of `super` (expected `super(...)` or `super.*`)', this );
11797 }
11798 }
11799
11800 if ( transforms.arrow ) {
11801 var lexicalBoundary = this.findLexicalBoundary();
11802 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
11803 var loop = this.findNearest( loopStatement );
11804
11805 if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
11806 this.thisAlias = lexicalBoundary.getThisAlias();
11807 }
11808
11809 if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
11810 this.thisAlias = lexicalBoundary.getThisAlias();
11811 }
11812 }
11813 };
11814
11815 Super.prototype.transpile = function transpile ( code, transforms ) {
11816 if ( transforms.classes ) {
11817 var expression = ( this.isCalled || this.method.static ) ?
11818 this.superClassName :
11819 ((this.superClassName) + ".prototype");
11820
11821 code.overwrite( this.start, this.end, expression, { storeName: true, contentOnly: true });
11822
11823 var callExpression = this.isCalled ? this.parent : this.parent.parent;
11824
11825 if ( callExpression && callExpression.type === 'CallExpression' ) {
11826 if ( !this.noCall ) { // special case – `super( ...args )`
11827 code.appendLeft( callExpression.callee.end, '.call' );
11828 }
11829
11830 var thisAlias = this.thisAlias || 'this';
11831
11832 if ( callExpression.arguments.length ) {
11833 code.appendLeft( callExpression.arguments[0].start, (thisAlias + ", ") );
11834 } else {
11835 code.appendLeft( callExpression.end - 1, ("" + thisAlias) );
11836 }
11837 }
11838 }
11839 };
11840
11841 return Super;
11842}(Node$1));
11843
11844var TaggedTemplateExpression = (function (Node) {
11845 function TaggedTemplateExpression () {
11846 Node.apply(this, arguments);
11847 }
11848
11849 if ( Node ) TaggedTemplateExpression.__proto__ = Node;
11850 TaggedTemplateExpression.prototype = Object.create( Node && Node.prototype );
11851 TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
11852
11853 TaggedTemplateExpression.prototype.initialise = function initialise ( transforms ) {
11854 if ( transforms.templateString && !transforms.dangerousTaggedTemplateString ) {
11855 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 );
11856 }
11857
11858 Node.prototype.initialise.call( this, transforms );
11859 };
11860
11861 TaggedTemplateExpression.prototype.transpile = function transpile ( code, transforms ) {
11862 if ( transforms.templateString && transforms.dangerousTaggedTemplateString ) {
11863 var ordered = this.quasi.expressions.concat( this.quasi.quasis ).sort( function ( a, b ) { return a.start - b.start; } );
11864
11865 // insert strings at start
11866 var templateStrings = this.quasi.quasis.map( function ( quasi ) { return JSON.stringify( quasi.value.cooked ); } );
11867 code.overwrite( this.tag.end, ordered[0].start, ("([" + (templateStrings.join(', ')) + "]") );
11868
11869 var lastIndex = ordered[0].start;
11870 ordered.forEach( function ( node ) {
11871 if ( node.type === 'TemplateElement' ) {
11872 code.remove( lastIndex, node.end );
11873 } else {
11874 code.overwrite( lastIndex, node.start, ', ' );
11875 }
11876
11877 lastIndex = node.end;
11878 });
11879
11880 code.overwrite( lastIndex, this.end, ')' );
11881 }
11882
11883 Node.prototype.transpile.call( this, code, transforms );
11884 };
11885
11886 return TaggedTemplateExpression;
11887}(Node$1));
11888
11889var TemplateElement = (function (Node) {
11890 function TemplateElement () {
11891 Node.apply(this, arguments);
11892 }
11893
11894 if ( Node ) TemplateElement.__proto__ = Node;
11895 TemplateElement.prototype = Object.create( Node && Node.prototype );
11896 TemplateElement.prototype.constructor = TemplateElement;
11897
11898 TemplateElement.prototype.initialise = function initialise () {
11899 this.program.indentExclusionElements.push( this );
11900 };
11901
11902 return TemplateElement;
11903}(Node$1));
11904
11905var TemplateLiteral = (function (Node) {
11906 function TemplateLiteral () {
11907 Node.apply(this, arguments);
11908 }
11909
11910 if ( Node ) TemplateLiteral.__proto__ = Node;
11911 TemplateLiteral.prototype = Object.create( Node && Node.prototype );
11912 TemplateLiteral.prototype.constructor = TemplateLiteral;
11913
11914 TemplateLiteral.prototype.transpile = function transpile ( code, transforms ) {
11915 if ( transforms.templateString && this.parent.type !== 'TaggedTemplateExpression' ) {
11916 var ordered = this.expressions.concat( this.quasis )
11917 .sort( function ( a, b ) { return a.start - b.start || a.end - b.end; } )
11918 .filter( function ( node, i ) {
11919 // include all expressions
11920 if ( node.type !== 'TemplateElement' ) return true;
11921
11922 // include all non-empty strings
11923 if ( node.value.raw ) return true;
11924
11925 // exclude all empty strings not at the head
11926 return !i;
11927 });
11928
11929 // special case – we may be able to skip the first element,
11930 // if it's the empty string, but only if the second and
11931 // third elements aren't both expressions (since they maybe
11932 // be numeric, and `1 + 2 + '3' === '33'`)
11933 if ( ordered.length >= 3 ) {
11934 var first = ordered[0];
11935 var third = ordered[2];
11936 if ( first.type === 'TemplateElement' && first.value.raw === '' && third.type === 'TemplateElement' ) {
11937 ordered.shift();
11938 }
11939 }
11940
11941 var parenthesise = ( this.quasis.length !== 1 || this.expressions.length !== 0 ) &&
11942 this.parent.type !== 'AssignmentExpression' &&
11943 this.parent.type !== 'AssignmentPattern' &&
11944 this.parent.type !== 'VariableDeclarator' &&
11945 ( this.parent.type !== 'BinaryExpression' || this.parent.operator !== '+' );
11946
11947 if ( parenthesise ) code.appendRight( this.start, '(' );
11948
11949 var lastIndex = this.start;
11950
11951 ordered.forEach( function ( node, i ) {
11952 var prefix = i === 0 ?
11953 parenthesise ? '(' : '' :
11954 ' + ';
11955
11956 if ( node.type === 'TemplateElement' ) {
11957 code.overwrite( lastIndex, node.end, prefix + JSON.stringify( node.value.cooked ) );
11958 } else {
11959 var parenthesise$1 = node.type !== 'Identifier'; // TODO other cases where it's safe
11960
11961 if ( parenthesise$1 ) prefix += '(';
11962
11963 code.remove( lastIndex, node.start );
11964
11965 if ( prefix ) code.prependRight( node.start, prefix );
11966 if ( parenthesise$1 ) code.appendLeft( node.end, ')' );
11967 }
11968
11969 lastIndex = node.end;
11970 });
11971
11972 if ( parenthesise ) code.appendLeft( lastIndex, ')' );
11973 code.remove( lastIndex, this.end );
11974 }
11975
11976 Node.prototype.transpile.call( this, code, transforms );
11977 };
11978
11979 return TemplateLiteral;
11980}(Node$1));
11981
11982var ThisExpression = (function (Node) {
11983 function ThisExpression () {
11984 Node.apply(this, arguments);
11985 }
11986
11987 if ( Node ) ThisExpression.__proto__ = Node;
11988 ThisExpression.prototype = Object.create( Node && Node.prototype );
11989 ThisExpression.prototype.constructor = ThisExpression;
11990
11991 ThisExpression.prototype.initialise = function initialise ( transforms ) {
11992 if ( transforms.arrow ) {
11993 var lexicalBoundary = this.findLexicalBoundary();
11994 var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
11995 var loop = this.findNearest( loopStatement );
11996
11997 if ( ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth )
11998 || ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth )
11999 || ( loop && loop.right && loop.right.contains( this ) ) ) {
12000 this.alias = lexicalBoundary.getThisAlias();
12001 }
12002 }
12003 };
12004
12005 ThisExpression.prototype.transpile = function transpile ( code ) {
12006 if ( this.alias ) {
12007 code.overwrite( this.start, this.end, this.alias, {
12008 storeName: true,
12009 contentOnly: true
12010 });
12011 }
12012 };
12013
12014 return ThisExpression;
12015}(Node$1));
12016
12017var UpdateExpression = (function (Node) {
12018 function UpdateExpression () {
12019 Node.apply(this, arguments);
12020 }
12021
12022 if ( Node ) UpdateExpression.__proto__ = Node;
12023 UpdateExpression.prototype = Object.create( Node && Node.prototype );
12024 UpdateExpression.prototype.constructor = UpdateExpression;
12025
12026 UpdateExpression.prototype.initialise = function initialise ( transforms ) {
12027 if ( this.argument.type === 'Identifier' ) {
12028 var declaration = this.findScope( false ).findDeclaration( this.argument.name );
12029 if ( declaration && declaration.kind === 'const' ) {
12030 throw new CompileError$1( ((this.argument.name) + " is read-only"), this );
12031 }
12032
12033 // special case – https://gitlab.com/Rich-Harris/buble/issues/150
12034 var statement = declaration && declaration.node.ancestor( 3 );
12035 if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
12036 statement.reassigned[ this.argument.name ] = true;
12037 }
12038 }
12039
12040 Node.prototype.initialise.call( this, transforms );
12041 };
12042
12043 return UpdateExpression;
12044}(Node$1));
12045
12046var VariableDeclaration = (function (Node) {
12047 function VariableDeclaration () {
12048 Node.apply(this, arguments);
12049 }
12050
12051 if ( Node ) VariableDeclaration.__proto__ = Node;
12052 VariableDeclaration.prototype = Object.create( Node && Node.prototype );
12053 VariableDeclaration.prototype.constructor = VariableDeclaration;
12054
12055 VariableDeclaration.prototype.initialise = function initialise ( transforms ) {
12056 this.scope = this.findScope( this.kind === 'var' );
12057 this.declarations.forEach( function ( declarator ) { return declarator.initialise( transforms ); } );
12058 };
12059
12060 VariableDeclaration.prototype.transpile = function transpile ( code, transforms ) {
12061 var this$1 = this;
12062
12063 var i0 = this.getIndentation();
12064 var kind = this.kind;
12065
12066 if ( transforms.letConst && kind !== 'var' ) {
12067 kind = 'var';
12068 code.overwrite( this.start, this.start + this.kind.length, kind, { storeName: true });
12069 }
12070
12071 if ( transforms.destructuring && this.parent.type !== 'ForOfStatement' ) {
12072 var c = this.start;
12073 var lastDeclaratorIsPattern;
12074
12075 this.declarations.forEach( function ( declarator, i ) {
12076 declarator.transpile( code, transforms );
12077
12078 if ( declarator.id.type === 'Identifier' ) {
12079 if ( i > 0 && this$1.declarations[ i - 1 ].id.type !== 'Identifier' ) {
12080 code.overwrite( c, declarator.id.start, "var " );
12081 }
12082 } else {
12083 var inline = loopStatement.test( this$1.parent.type );
12084
12085 if ( i === 0 ) {
12086 code.remove( c, declarator.id.start );
12087 } else {
12088 code.overwrite( c, declarator.id.start, (";\n" + i0) );
12089 }
12090
12091 var simple = declarator.init.type === 'Identifier' && !declarator.init.rewritten;
12092
12093 var name = simple ? declarator.init.name : declarator.findScope( true ).createIdentifier( 'ref' );
12094
12095 var statementGenerators = [];
12096
12097 if ( simple ) {
12098 code.remove( declarator.id.end, declarator.end );
12099 } else {
12100 statementGenerators.push( function ( start, prefix, suffix ) {
12101 code.prependRight( declarator.id.end, ("var " + name) );
12102 code.appendLeft( declarator.init.end, ("" + suffix) );
12103 code.move( declarator.id.end, declarator.end, start );
12104 });
12105 }
12106
12107 destructure( code, declarator.findScope( false ), declarator.id, name, inline, statementGenerators );
12108
12109 var prefix = inline ? 'var ' : '';
12110 var suffix = inline ? ", " : (";\n" + i0);
12111 statementGenerators.forEach( function ( fn, j ) {
12112 if ( i === this$1.declarations.length - 1 && j === statementGenerators.length - 1 ) {
12113 suffix = inline ? '' : ';';
12114 }
12115
12116 fn( declarator.start, j === 0 ? prefix : '', suffix );
12117 });
12118 }
12119
12120 c = declarator.end;
12121 lastDeclaratorIsPattern = declarator.id.type !== 'Identifier';
12122 });
12123
12124 if ( lastDeclaratorIsPattern && this.end > c ) {
12125 code.overwrite( c, this.end, '', { contentOnly: true });
12126 }
12127 }
12128
12129 else {
12130 this.declarations.forEach( function ( declarator ) {
12131 declarator.transpile( code, transforms );
12132 });
12133 }
12134 };
12135
12136 return VariableDeclaration;
12137}(Node$1));
12138
12139var VariableDeclarator = (function (Node) {
12140 function VariableDeclarator () {
12141 Node.apply(this, arguments);
12142 }
12143
12144 if ( Node ) VariableDeclarator.__proto__ = Node;
12145 VariableDeclarator.prototype = Object.create( Node && Node.prototype );
12146 VariableDeclarator.prototype.constructor = VariableDeclarator;
12147
12148 VariableDeclarator.prototype.initialise = function initialise ( transforms ) {
12149 var kind = this.parent.kind;
12150 if ( kind === 'let' && this.parent.parent.type === 'ForStatement' ) {
12151 kind = 'for.let'; // special case...
12152 }
12153
12154 this.parent.scope.addDeclaration( this.id, kind );
12155 Node.prototype.initialise.call( this, transforms );
12156 };
12157
12158 VariableDeclarator.prototype.transpile = function transpile ( code, transforms ) {
12159 if ( !this.init && transforms.letConst && this.parent.kind !== 'var' ) {
12160 var inLoop = this.findNearest( /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/ );
12161 if ( inLoop && ! /Function/.test( inLoop.type ) && ! this.isLeftDeclaratorOfLoop() ) {
12162 code.appendLeft( this.id.end, ' = (void 0)' );
12163 }
12164 }
12165
12166 if ( this.id ) this.id.transpile( code, transforms );
12167 if ( this.init ) this.init.transpile( code, transforms );
12168 };
12169
12170 VariableDeclarator.prototype.isLeftDeclaratorOfLoop = function isLeftDeclaratorOfLoop () {
12171 return this.parent
12172 && this.parent.type === 'VariableDeclaration'
12173 && this.parent.parent
12174 && (this.parent.parent.type === 'ForInStatement'
12175 || this.parent.parent.type === 'ForOfStatement')
12176 && this.parent.parent.left
12177 && this.parent.parent.left.declarations[0] === this;
12178 };
12179
12180 return VariableDeclarator;
12181}(Node$1));
12182
12183var types$1$1 = {
12184 ArrayExpression: ArrayExpression,
12185 ArrowFunctionExpression: ArrowFunctionExpression,
12186 AssignmentExpression: AssignmentExpression,
12187 BinaryExpression: BinaryExpression,
12188 BreakStatement: BreakStatement,
12189 CallExpression: CallExpression,
12190 ClassBody: ClassBody,
12191 ClassDeclaration: ClassDeclaration,
12192 ClassExpression: ClassExpression,
12193 ContinueStatement: ContinueStatement,
12194 DoWhileStatement: LoopStatement,
12195 ExportNamedDeclaration: ExportNamedDeclaration,
12196 ExportDefaultDeclaration: ExportDefaultDeclaration,
12197 ForStatement: ForStatement,
12198 ForInStatement: ForInStatement,
12199 ForOfStatement: ForOfStatement,
12200 FunctionDeclaration: FunctionDeclaration,
12201 FunctionExpression: FunctionExpression,
12202 Identifier: Identifier,
12203 IfStatement: IfStatement,
12204 ImportDeclaration: ImportDeclaration,
12205 ImportDefaultSpecifier: ImportDefaultSpecifier,
12206 ImportSpecifier: ImportSpecifier,
12207 JSXAttribute: JSXAttribute,
12208 JSXClosingElement: JSXClosingElement,
12209 JSXElement: JSXElement,
12210 JSXExpressionContainer: JSXExpressionContainer,
12211 JSXOpeningElement: JSXOpeningElement,
12212 JSXSpreadAttribute: JSXSpreadAttribute,
12213 Literal: Literal,
12214 MemberExpression: MemberExpression,
12215 NewExpression: NewExpression,
12216 ObjectExpression: ObjectExpression,
12217 Property: Property,
12218 ReturnStatement: ReturnStatement,
12219 SpreadElement: SpreadElement,
12220 Super: Super,
12221 TaggedTemplateExpression: TaggedTemplateExpression,
12222 TemplateElement: TemplateElement,
12223 TemplateLiteral: TemplateLiteral,
12224 ThisExpression: ThisExpression,
12225 UpdateExpression: UpdateExpression,
12226 VariableDeclaration: VariableDeclaration,
12227 VariableDeclarator: VariableDeclarator,
12228 WhileStatement: LoopStatement
12229};
12230
12231var statementsWithBlocks = {
12232 IfStatement: 'consequent',
12233 ForStatement: 'body',
12234 ForInStatement: 'body',
12235 ForOfStatement: 'body',
12236 WhileStatement: 'body',
12237 DoWhileStatement: 'body',
12238 ArrowFunctionExpression: 'body'
12239};
12240
12241function wrap ( raw, parent ) {
12242 if ( !raw ) return;
12243
12244 if ( 'length' in raw ) {
12245 var i = raw.length;
12246 while ( i-- ) wrap( raw[i], parent );
12247 return;
12248 }
12249
12250 // with e.g. shorthand properties, key and value are
12251 // the same node. We don't want to wrap an object twice
12252 if ( raw.__wrapped ) return;
12253 raw.__wrapped = true;
12254
12255 if ( !keys[ raw.type ] ) {
12256 keys[ raw.type ] = Object.keys( raw ).filter( function ( key ) { return typeof raw[ key ] === 'object'; } );
12257 }
12258
12259 // special case – body-less if/for/while statements. TODO others?
12260 var bodyType = statementsWithBlocks[ raw.type ];
12261 if ( bodyType && raw[ bodyType ].type !== 'BlockStatement' ) {
12262 var expression = raw[ bodyType ];
12263
12264 // create a synthetic block statement, otherwise all hell
12265 // breaks loose when it comes to block scoping
12266 raw[ bodyType ] = {
12267 start: expression.start,
12268 end: expression.end,
12269 type: 'BlockStatement',
12270 body: [ expression ],
12271 synthetic: true
12272 };
12273 }
12274
12275 new Node$1( raw, parent );
12276
12277 var type = ( raw.type === 'BlockStatement' ? BlockStatement : types$1$1[ raw.type ] ) || Node$1;
12278 raw.__proto__ = type.prototype;
12279}
12280
12281function Scope ( options ) {
12282 options = options || {};
12283
12284 this.parent = options.parent;
12285 this.isBlockScope = !!options.block;
12286
12287 var scope = this;
12288 while ( scope.isBlockScope ) scope = scope.parent;
12289 this.functionScope = scope;
12290
12291 this.identifiers = [];
12292 this.declarations = Object.create( null );
12293 this.references = Object.create( null );
12294 this.blockScopedDeclarations = this.isBlockScope ? null : Object.create( null );
12295 this.aliases = this.isBlockScope ? null : Object.create( null );
12296}
12297
12298Scope.prototype = {
12299 addDeclaration: function addDeclaration ( node, kind ) {
12300 for ( var i = 0, list = extractNames( node ); i < list.length; i += 1 ) {
12301 var identifier = list[i];
12302
12303 var name = identifier.name;
12304
12305 var declaration = { name: name, node: identifier, kind: kind, instances: [] };
12306 this.declarations[ name ] = declaration;
12307
12308 if ( this.isBlockScope ) {
12309 if ( !this.functionScope.blockScopedDeclarations[ name ] ) this.functionScope.blockScopedDeclarations[ name ] = [];
12310 this.functionScope.blockScopedDeclarations[ name ].push( declaration );
12311 }
12312 }
12313 },
12314
12315 addReference: function addReference ( identifier ) {
12316 if ( this.consolidated ) {
12317 this.consolidateReference( identifier );
12318 } else {
12319 this.identifiers.push( identifier );
12320 }
12321 },
12322
12323 consolidate: function consolidate () {
12324 var this$1 = this;
12325
12326 for ( var i = 0; i < this$1.identifiers.length; i += 1 ) { // we might push to the array during consolidation, so don't cache length
12327 var identifier = this$1.identifiers[i];
12328 this$1.consolidateReference( identifier );
12329 }
12330
12331 this.consolidated = true; // TODO understand why this is necessary... seems bad
12332 },
12333
12334 consolidateReference: function consolidateReference ( identifier ) {
12335 var declaration = this.declarations[ identifier.name ];
12336 if ( declaration ) {
12337 declaration.instances.push( identifier );
12338 } else {
12339 this.references[ identifier.name ] = true;
12340 if ( this.parent ) this.parent.addReference( identifier );
12341 }
12342 },
12343
12344 contains: function contains ( name ) {
12345 return this.declarations[ name ] ||
12346 ( this.parent ? this.parent.contains( name ) : false );
12347 },
12348
12349 createIdentifier: function createIdentifier ( base ) {
12350 var this$1 = this;
12351
12352 if ( typeof base === 'number' ) base = base.toString();
12353
12354 base = base
12355 .replace( /\s/g, '' )
12356 .replace( /\[([^\]]+)\]/g, '_$1' )
12357 .replace( /[^a-zA-Z0-9_$]/g, '_' )
12358 .replace( /_{2,}/, '_' );
12359
12360 var name = base;
12361 var counter = 1;
12362
12363 while ( this$1.declarations[ name ] || this$1.references[ name ] || this$1.aliases[ name ] || name in reserved ) {
12364 name = base + "$" + (counter++);
12365 }
12366
12367 this.aliases[ name ] = true;
12368 return name;
12369 },
12370
12371 findDeclaration: function findDeclaration ( name ) {
12372 return this.declarations[ name ] ||
12373 ( this.parent && this.parent.findDeclaration( name ) );
12374 }
12375};
12376
12377function isUseStrict ( node ) {
12378 if ( !node ) return false;
12379 if ( node.type !== 'ExpressionStatement' ) return false;
12380 if ( node.expression.type !== 'Literal' ) return false;
12381 return node.expression.value === 'use strict';
12382}
12383
12384var BlockStatement = (function (Node) {
12385 function BlockStatement () {
12386 Node.apply(this, arguments);
12387 }
12388
12389 if ( Node ) BlockStatement.__proto__ = Node;
12390 BlockStatement.prototype = Object.create( Node && Node.prototype );
12391 BlockStatement.prototype.constructor = BlockStatement;
12392
12393 BlockStatement.prototype.createScope = function createScope () {
12394 var this$1 = this;
12395
12396 this.parentIsFunction = /Function/.test( this.parent.type );
12397 this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root';
12398 this.scope = new Scope({
12399 block: !this.isFunctionBlock,
12400 parent: this.parent.findScope( false )
12401 });
12402
12403 if ( this.parentIsFunction ) {
12404 this.parent.params.forEach( function ( node ) {
12405 this$1.scope.addDeclaration( node, 'param' );
12406 });
12407 }
12408 };
12409
12410 BlockStatement.prototype.initialise = function initialise ( transforms ) {
12411 this.thisAlias = null;
12412 this.argumentsAlias = null;
12413 this.defaultParameters = [];
12414
12415 // normally the scope gets created here, during initialisation,
12416 // but in some cases (e.g. `for` statements), we need to create
12417 // the scope early, as it pertains to both the init block and
12418 // the body of the statement
12419 if ( !this.scope ) this.createScope();
12420
12421 this.body.forEach( function ( node ) { return node.initialise( transforms ); } );
12422
12423 this.scope.consolidate();
12424 };
12425
12426 BlockStatement.prototype.findLexicalBoundary = function findLexicalBoundary () {
12427 if ( this.type === 'Program' ) return this;
12428 if ( /^Function/.test( this.parent.type ) ) return this;
12429
12430 return this.parent.findLexicalBoundary();
12431 };
12432
12433 BlockStatement.prototype.findScope = function findScope ( functionScope ) {
12434 if ( functionScope && !this.isFunctionBlock ) return this.parent.findScope( functionScope );
12435 return this.scope;
12436 };
12437
12438 BlockStatement.prototype.getArgumentsAlias = function getArgumentsAlias () {
12439 if ( !this.argumentsAlias ) {
12440 this.argumentsAlias = this.scope.createIdentifier( 'arguments' );
12441 }
12442
12443 return this.argumentsAlias;
12444 };
12445
12446 BlockStatement.prototype.getArgumentsArrayAlias = function getArgumentsArrayAlias () {
12447 if ( !this.argumentsArrayAlias ) {
12448 this.argumentsArrayAlias = this.scope.createIdentifier( 'argsArray' );
12449 }
12450
12451 return this.argumentsArrayAlias;
12452 };
12453
12454 BlockStatement.prototype.getThisAlias = function getThisAlias () {
12455 if ( !this.thisAlias ) {
12456 this.thisAlias = this.scope.createIdentifier( 'this' );
12457 }
12458
12459 return this.thisAlias;
12460 };
12461
12462 BlockStatement.prototype.getIndentation = function getIndentation () {
12463 var this$1 = this;
12464
12465 if ( this.indentation === undefined ) {
12466 var source = this.program.magicString.original;
12467
12468 var useOuter = this.synthetic || !this.body.length;
12469 var c = useOuter ? this.start : this.body[0].start;
12470
12471 while ( c && source[c] !== '\n' ) c -= 1;
12472
12473 this.indentation = '';
12474
12475 while ( true ) { // eslint-disable-line no-constant-condition
12476 c += 1;
12477 var char = source[c];
12478
12479 if ( char !== ' ' && char !== '\t' ) break;
12480
12481 this$1.indentation += char;
12482 }
12483
12484 var indentString = this.program.magicString.getIndentString();
12485
12486 // account for dedented class constructors
12487 var parent = this.parent;
12488 while ( parent ) {
12489 if ( parent.kind === 'constructor' && !parent.parent.parent.superClass ) {
12490 this$1.indentation = this$1.indentation.replace( indentString, '' );
12491 }
12492
12493 parent = parent.parent;
12494 }
12495
12496 if ( useOuter ) this.indentation += indentString;
12497 }
12498
12499 return this.indentation;
12500 };
12501
12502 BlockStatement.prototype.transpile = function transpile ( code, transforms ) {
12503 var this$1 = this;
12504
12505 var indentation = this.getIndentation();
12506
12507 var introStatementGenerators = [];
12508
12509 if ( this.argumentsAlias ) {
12510 introStatementGenerators.push( function ( start, prefix, suffix ) {
12511 var assignment = prefix + "var " + (this$1.argumentsAlias) + " = arguments" + suffix;
12512 code.appendLeft( start, assignment );
12513 });
12514 }
12515
12516 if ( this.thisAlias ) {
12517 introStatementGenerators.push( function ( start, prefix, suffix ) {
12518 var assignment = prefix + "var " + (this$1.thisAlias) + " = this" + suffix;
12519 code.appendLeft( start, assignment );
12520 });
12521 }
12522
12523 if ( this.argumentsArrayAlias ) {
12524 introStatementGenerators.push( function ( start, prefix, suffix ) {
12525 var i = this$1.scope.createIdentifier( 'i' );
12526 var assignment = prefix + "var " + i + " = arguments.length, " + (this$1.argumentsArrayAlias) + " = Array(" + i + ");\n" + indentation + "while ( " + i + "-- ) " + (this$1.argumentsArrayAlias) + "[" + i + "] = arguments[" + i + "]" + suffix;
12527 code.appendLeft( start, assignment );
12528 });
12529 }
12530
12531 if ( /Function/.test( this.parent.type ) ) {
12532 this.transpileParameters( code, transforms, indentation, introStatementGenerators );
12533 }
12534
12535 if ( transforms.letConst && this.isFunctionBlock ) {
12536 this.transpileBlockScopedIdentifiers( code );
12537 }
12538
12539 Node.prototype.transpile.call( this, code, transforms );
12540
12541 if ( this.synthetic ) {
12542 if ( this.parent.type === 'ArrowFunctionExpression' ) {
12543 var expr = this.body[0];
12544
12545 if ( introStatementGenerators.length ) {
12546 code.appendLeft( this.start, "{" ).prependRight( this.end, ((this.parent.getIndentation()) + "}") );
12547
12548 code.prependRight( expr.start, ("\n" + indentation + "return ") );
12549 code.appendLeft( expr.end, ";\n" );
12550 } else if ( transforms.arrow ) {
12551 code.prependRight( expr.start, "{ return " );
12552 code.appendLeft( expr.end, "; }" );
12553 }
12554 }
12555
12556 else if ( introStatementGenerators.length ) {
12557 code.prependRight( this.start, "{" ).appendLeft( this.end, "}" );
12558 }
12559 }
12560
12561 var start;
12562 if ( isUseStrict( this.body[0] ) ) {
12563 start = this.body[0].end;
12564 } else if ( this.synthetic || this.parent.type === 'Root' ) {
12565 start = this.start;
12566 } else {
12567 start = this.start + 1;
12568 }
12569
12570 var prefix = "\n" + indentation;
12571 var suffix = ';';
12572 introStatementGenerators.forEach( function ( fn, i ) {
12573 if ( i === introStatementGenerators.length - 1 ) suffix = ";\n";
12574 fn( start, prefix, suffix );
12575 });
12576 };
12577
12578 BlockStatement.prototype.transpileParameters = function transpileParameters ( code, transforms, indentation, introStatementGenerators ) {
12579 var this$1 = this;
12580
12581 var params = this.parent.params;
12582
12583 params.forEach( function ( param ) {
12584 if ( param.type === 'AssignmentPattern' && param.left.type === 'Identifier' ) {
12585 if ( transforms.defaultParameter ) {
12586 introStatementGenerators.push( function ( start, prefix, suffix ) {
12587 var lhs = prefix + "if ( " + (param.left.name) + " === void 0 ) " + (param.left.name);
12588
12589 code
12590 .prependRight( param.left.end, lhs )
12591 .move( param.left.end, param.right.end, start )
12592 .appendLeft( param.right.end, suffix );
12593 });
12594 }
12595 }
12596
12597 else if ( param.type === 'RestElement' ) {
12598 if ( transforms.spreadRest ) {
12599 introStatementGenerators.push( function ( start, prefix, suffix ) {
12600 var penultimateParam = params[ params.length - 2 ];
12601
12602 if ( penultimateParam ) {
12603 code.remove( penultimateParam ? penultimateParam.end : param.start, param.end );
12604 } else {
12605 var start$1 = param.start, end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8
12606
12607 while ( /\s/.test( code.original[ start$1 - 1 ] ) ) start$1 -= 1;
12608 while ( /\s/.test( code.original[ end ] ) ) end += 1;
12609
12610 code.remove( start$1, end );
12611 }
12612
12613 var name = param.argument.name;
12614 var len = this$1.scope.createIdentifier( 'len' );
12615 var count = params.length - 1;
12616
12617 if ( count ) {
12618 code.prependRight( start, (prefix + "var " + name + " = [], " + len + " = arguments.length - " + count + ";\n" + indentation + "while ( " + len + "-- > 0 ) " + name + "[ " + len + " ] = arguments[ " + len + " + " + count + " ]" + suffix) );
12619 } else {
12620 code.prependRight( start, (prefix + "var " + name + " = [], " + len + " = arguments.length;\n" + indentation + "while ( " + len + "-- ) " + name + "[ " + len + " ] = arguments[ " + len + " ]" + suffix) );
12621 }
12622 });
12623 }
12624 }
12625
12626 else if ( param.type !== 'Identifier' ) {
12627 if ( transforms.parameterDestructuring ) {
12628 var ref = this$1.scope.createIdentifier( 'ref' );
12629 destructure( code, this$1.scope, param, ref, false, introStatementGenerators );
12630 code.prependRight( param.start, ref );
12631 }
12632 }
12633 });
12634 };
12635
12636 BlockStatement.prototype.transpileBlockScopedIdentifiers = function transpileBlockScopedIdentifiers ( code ) {
12637 var this$1 = this;
12638
12639 Object.keys( this.scope.blockScopedDeclarations ).forEach( function ( name ) {
12640 var declarations = this$1.scope.blockScopedDeclarations[ name ];
12641
12642 for ( var i = 0, list = declarations; i < list.length; i += 1 ) {
12643 var declaration = list[i];
12644
12645 var cont = false; // TODO implement proper continue...
12646
12647 if ( declaration.kind === 'for.let' ) {
12648 // special case
12649 var forStatement = declaration.node.findNearest( 'ForStatement' );
12650
12651 if ( forStatement.shouldRewriteAsFunction ) {
12652 var outerAlias = this$1.scope.createIdentifier( name );
12653 var innerAlias = forStatement.reassigned[ name ] ?
12654 this$1.scope.createIdentifier( name ) :
12655 name;
12656
12657 declaration.name = outerAlias;
12658 code.overwrite( declaration.node.start, declaration.node.end, outerAlias, { storeName: true });
12659
12660 forStatement.aliases[ name ] = {
12661 outer: outerAlias,
12662 inner: innerAlias
12663 };
12664
12665 for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
12666 var identifier = list$1[i$1];
12667
12668 var alias = forStatement.body.contains( identifier ) ?
12669 innerAlias :
12670 outerAlias;
12671
12672 if ( name !== alias ) {
12673 code.overwrite( identifier.start, identifier.end, alias, { storeName: true });
12674 }
12675 }
12676
12677 cont = true;
12678 }
12679 }
12680
12681 if ( !cont ) {
12682 var alias$1 = this$1.scope.createIdentifier( name );
12683
12684 if ( name !== alias$1 ) {
12685 declaration.name = alias$1;
12686 code.overwrite( declaration.node.start, declaration.node.end, alias$1, { storeName: true });
12687
12688 for ( var i$2 = 0, list$2 = declaration.instances; i$2 < list$2.length; i$2 += 1 ) {
12689 var identifier$1 = list$2[i$2];
12690
12691 identifier$1.rewritten = true;
12692 code.overwrite( identifier$1.start, identifier$1.end, alias$1, { storeName: true });
12693 }
12694 }
12695 }
12696 }
12697 });
12698 };
12699
12700 return BlockStatement;
12701}(Node$1));
12702
12703function Program ( source, ast, transforms, options ) {
12704 var this$1 = this;
12705
12706 this.type = 'Root';
12707
12708 // options
12709 this.jsx = options.jsx || 'React.createElement';
12710 this.options = options;
12711
12712 this.source = source;
12713 this.magicString = new MagicString( source );
12714
12715 this.ast = ast;
12716 this.depth = 0;
12717
12718 wrap( this.body = ast, this );
12719 this.body.__proto__ = BlockStatement.prototype;
12720
12721 this.indentExclusionElements = [];
12722 this.body.initialise( transforms );
12723
12724 this.indentExclusions = Object.create( null );
12725 for ( var i$1 = 0, list = this.indentExclusionElements; i$1 < list.length; i$1 += 1 ) {
12726 var node = list[i$1];
12727
12728 for ( var i = node.start; i < node.end; i += 1 ) {
12729 this$1.indentExclusions[ i ] = true;
12730 }
12731 }
12732
12733 this.body.transpile( this.magicString, transforms );
12734}
12735
12736Program.prototype = {
12737 export: function export$1 ( options ) {
12738 if ( options === void 0 ) options = {};
12739
12740 return {
12741 code: this.magicString.toString(),
12742 map: this.magicString.generateMap({
12743 file: options.file,
12744 source: options.source,
12745 includeContent: options.includeContent !== false
12746 })
12747 };
12748 },
12749
12750 findNearest: function findNearest () {
12751 return null;
12752 },
12753
12754 findScope: function findScope () {
12755 return null;
12756 }
12757};
12758
12759var matrix = {
12760 chrome: {
12761 48: 1333689725,
12762 49: 1342078975,
12763 50: 1610514431,
12764 51: 1610514431,
12765 52: 2147385343
12766 },
12767 firefox: {
12768 43: 1207307741,
12769 44: 1207307741,
12770 45: 1207307741,
12771 46: 1476267485,
12772 47: 1476296671,
12773 48: 1476296671
12774 },
12775 safari: {
12776 8: 1073741824,
12777 9: 1328940894
12778 },
12779 ie: {
12780 8: 0,
12781 9: 1073741824,
12782 10: 1073741824,
12783 11: 1073770592
12784 },
12785 edge: {
12786 12: 1591620701,
12787 13: 1608400479
12788 },
12789 node: {
12790 '0.10': 1075052608,
12791 '0.12': 1091830852,
12792 4: 1327398527,
12793 5: 1327398527,
12794 6: 1610514431
12795 }
12796};
12797
12798var features = [
12799 'arrow',
12800 'classes',
12801 'collections',
12802 'computedProperty',
12803 'conciseMethodProperty',
12804 'constLoop',
12805 'constRedef',
12806 'defaultParameter',
12807 'destructuring',
12808 'extendNatives',
12809 'forOf',
12810 'generator',
12811 'letConst',
12812 'letLoop',
12813 'letLoopScope',
12814 'moduleExport',
12815 'moduleImport',
12816 'numericLiteral',
12817 'objectProto',
12818 'objectSuper',
12819 'oldOctalLiteral',
12820 'parameterDestructuring',
12821 'spreadRest',
12822 'stickyRegExp',
12823 'symbol',
12824 'templateString',
12825 'unicodeEscape',
12826 'unicodeIdentifier',
12827 'unicodeRegExp',
12828
12829 // ES2016
12830 'exponentiation',
12831
12832 // additional transforms, not from
12833 // https://featuretests.io
12834 'reservedProperties'
12835];
12836
12837var version$1 = "0.17.1";
12838
12839var ref = [
12840 inject$1,
12841 inject
12842].reduce( function ( final, plugin ) { return plugin( final ); }, acorn );
12843var parse = ref.parse;
12844
12845var dangerousTransforms = [
12846 'dangerousTaggedTemplateString',
12847 'dangerousForOf'
12848];
12849
12850function target ( target ) {
12851 var targets = Object.keys( target );
12852 var bitmask = targets.length ?
12853 2147483647 :
12854 1073741824;
12855
12856 Object.keys( target ).forEach( function ( environment ) {
12857 var versions = matrix[ environment ];
12858 if ( !versions ) throw new Error( ("Unknown environment '" + environment + "'. Please raise an issue at https://gitlab.com/Rich-Harris/buble/issues") );
12859
12860 var targetVersion = target[ environment ];
12861 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") );
12862 var support = versions[ targetVersion ];
12863
12864 bitmask &= support;
12865 });
12866
12867 var transforms = Object.create( null );
12868 features.forEach( function ( name, i ) {
12869 transforms[ name ] = !( bitmask & 1 << i );
12870 });
12871
12872 dangerousTransforms.forEach( function ( name ) {
12873 transforms[ name ] = false;
12874 });
12875
12876 return transforms;
12877}
12878
12879function transform ( source, options ) {
12880 if ( options === void 0 ) options = {};
12881
12882 var ast;
12883 var jsx = null;
12884
12885 try {
12886 ast = parse( source, {
12887 ecmaVersion: 8,
12888 preserveParens: true,
12889 sourceType: 'module',
12890 onComment: function (block, text) {
12891 if ( !jsx ) {
12892 var match = /@jsx\s+([^\s]+)/.exec( text );
12893 if ( match ) jsx = match[1];
12894 }
12895 },
12896 plugins: {
12897 jsx: true,
12898 objectSpread: true
12899 }
12900 });
12901 options.jsx = jsx || options.jsx;
12902 } catch ( err ) {
12903 err.snippet = getSnippet( source, err.loc );
12904 err.toString = function () { return ((err.name) + ": " + (err.message) + "\n" + (err.snippet)); };
12905 throw err;
12906 }
12907
12908 var transforms = target( options.target || {} );
12909 Object.keys( options.transforms || {} ).forEach( function ( name ) {
12910 if ( name === 'modules' ) {
12911 if ( !( 'moduleImport' in options.transforms ) ) transforms.moduleImport = options.transforms.modules;
12912 if ( !( 'moduleExport' in options.transforms ) ) transforms.moduleExport = options.transforms.modules;
12913 return;
12914 }
12915
12916 if ( !( name in transforms ) ) throw new Error( ("Unknown transform '" + name + "'") );
12917 transforms[ name ] = options.transforms[ name ];
12918 });
12919
12920 return new Program( source, ast, transforms, options ).export( options );
12921}
12922
12923exports.target = target;
12924exports.transform = transform;
12925exports.VERSION = version$1;
12926
12927Object.defineProperty(exports, '__esModule', { value: true });
12928
12929})));
12930//# sourceMappingURL=buble.umd.js.map