1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
4 | (global = global || self, factory(global.buble = {}));
|
5 | }(this, (function (exports) { 'use strict';
|
6 |
|
7 |
|
8 |
|
9 | var reservedWords = {
|
10 | 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
|
11 | 5: "class enum extends super const export import",
|
12 | 6: "enum",
|
13 | strict: "implements interface let package private protected public static yield",
|
14 | strictBind: "eval arguments"
|
15 | };
|
16 |
|
17 |
|
18 |
|
19 | var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
|
20 |
|
21 | var keywords = {
|
22 | 5: ecma5AndLessKeywords,
|
23 | "5module": ecma5AndLessKeywords + " export import",
|
24 | 6: ecma5AndLessKeywords + " const class extends export import super"
|
25 | };
|
26 |
|
27 | var keywordRelationalOperator = /^in(stanceof)?$/;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7c6\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab67\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";
|
37 | var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\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\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
|
38 |
|
39 | var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
|
40 | var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
|
41 |
|
42 | nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,155,22,13,52,76,44,33,24,27,35,30,0,12,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,21,0,33,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,230,43,117,63,32,0,161,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,754,9486,286,50,2,18,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,2357,44,11,6,17,0,370,43,1301,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541];
|
52 |
|
53 |
|
54 | var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,232,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1014,0,2,54,8,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,262,6,10,9,419,13,1495,6,110,6,6,9,792487,239];
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | function 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 |
|
70 |
|
71 | function 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 |
|
82 |
|
83 | function 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 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | var 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 |
|
133 | function binop(name, prec) {
|
134 | return new TokenType(name, {beforeExpr: true, binop: prec})
|
135 | }
|
136 | var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};
|
137 |
|
138 |
|
139 |
|
140 | var keywords$1 = {};
|
141 |
|
142 |
|
143 | function kw(name, options) {
|
144 | if ( options === void 0 ) options = {};
|
145 |
|
146 | options.keyword = name;
|
147 | return keywords$1[name] = new TokenType(name, options)
|
148 | }
|
149 |
|
150 | var types = {
|
151 | num: new TokenType("num", startsExpr),
|
152 | regexp: new TokenType("regexp", startsExpr),
|
153 | string: new TokenType("string", startsExpr),
|
154 | name: new TokenType("name", startsExpr),
|
155 | eof: new TokenType("eof"),
|
156 |
|
157 |
|
158 | bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
|
159 | bracketR: new TokenType("]"),
|
160 | braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
|
161 | braceR: new TokenType("}"),
|
162 | parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
|
163 | parenR: new TokenType(")"),
|
164 | comma: new TokenType(",", beforeExpr),
|
165 | semi: new TokenType(";", beforeExpr),
|
166 | colon: new TokenType(":", beforeExpr),
|
167 | dot: new TokenType("."),
|
168 | question: new TokenType("?", beforeExpr),
|
169 | arrow: new TokenType("=>", beforeExpr),
|
170 | template: new TokenType("template"),
|
171 | invalidTemplate: new TokenType("invalidTemplate"),
|
172 | ellipsis: new TokenType("...", beforeExpr),
|
173 | backQuote: new TokenType("`", startsExpr),
|
174 | dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 | eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
|
191 | assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
|
192 | incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
|
193 | prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
|
194 | logicalOR: binop("||", 1),
|
195 | logicalAND: binop("&&", 2),
|
196 | bitwiseOR: binop("|", 3),
|
197 | bitwiseXOR: binop("^", 4),
|
198 | bitwiseAND: binop("&", 5),
|
199 | equality: binop("==/!=/===/!==", 6),
|
200 | relational: binop("</>/<=/>=", 7),
|
201 | bitShift: binop("<</>>/>>>", 8),
|
202 | plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
|
203 | modulo: binop("%", 10),
|
204 | star: binop("*", 10),
|
205 | slash: binop("/", 10),
|
206 | starstar: new TokenType("**", {beforeExpr: true}),
|
207 |
|
208 |
|
209 | _break: kw("break"),
|
210 | _case: kw("case", beforeExpr),
|
211 | _catch: kw("catch"),
|
212 | _continue: kw("continue"),
|
213 | _debugger: kw("debugger"),
|
214 | _default: kw("default", beforeExpr),
|
215 | _do: kw("do", {isLoop: true, beforeExpr: true}),
|
216 | _else: kw("else", beforeExpr),
|
217 | _finally: kw("finally"),
|
218 | _for: kw("for", {isLoop: true}),
|
219 | _function: kw("function", startsExpr),
|
220 | _if: kw("if"),
|
221 | _return: kw("return", beforeExpr),
|
222 | _switch: kw("switch"),
|
223 | _throw: kw("throw", beforeExpr),
|
224 | _try: kw("try"),
|
225 | _var: kw("var"),
|
226 | _const: kw("const"),
|
227 | _while: kw("while", {isLoop: true}),
|
228 | _with: kw("with"),
|
229 | _new: kw("new", {beforeExpr: true, startsExpr: true}),
|
230 | _this: kw("this", startsExpr),
|
231 | _super: kw("super", startsExpr),
|
232 | _class: kw("class", startsExpr),
|
233 | _extends: kw("extends", beforeExpr),
|
234 | _export: kw("export"),
|
235 | _import: kw("import", startsExpr),
|
236 | _null: kw("null", startsExpr),
|
237 | _true: kw("true", startsExpr),
|
238 | _false: kw("false", startsExpr),
|
239 | _in: kw("in", {beforeExpr: true, binop: 7}),
|
240 | _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
|
241 | _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
|
242 | _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
|
243 | _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
|
244 | };
|
245 |
|
246 |
|
247 |
|
248 |
|
249 | var lineBreak = /\r\n?|\n|\u2028|\u2029/;
|
250 | var lineBreakG = new RegExp(lineBreak.source, "g");
|
251 |
|
252 | function isNewLine(code, ecma2019String) {
|
253 | return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029))
|
254 | }
|
255 |
|
256 | var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
|
257 |
|
258 | var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
|
259 |
|
260 | var ref = Object.prototype;
|
261 | var hasOwnProperty = ref.hasOwnProperty;
|
262 | var toString = ref.toString;
|
263 |
|
264 |
|
265 |
|
266 | function has(obj, propName) {
|
267 | return hasOwnProperty.call(obj, propName)
|
268 | }
|
269 |
|
270 | var isArray = Array.isArray || (function (obj) { return (
|
271 | toString.call(obj) === "[object Array]"
|
272 | ); });
|
273 |
|
274 | function wordsRegexp(words) {
|
275 | return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
|
276 | }
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | var Position = function Position(line, col) {
|
282 | this.line = line;
|
283 | this.column = col;
|
284 | };
|
285 |
|
286 | Position.prototype.offset = function offset (n) {
|
287 | return new Position(this.line, this.column + n)
|
288 | };
|
289 |
|
290 | var SourceLocation = function SourceLocation(p, start, end) {
|
291 | this.start = start;
|
292 | this.end = end;
|
293 | if (p.sourceFile !== null) { this.source = p.sourceFile; }
|
294 | };
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 | function getLineInfo(input, offset) {
|
303 | for (var line = 1, cur = 0;;) {
|
304 | lineBreakG.lastIndex = cur;
|
305 | var match = lineBreakG.exec(input);
|
306 | if (match && match.index < offset) {
|
307 | ++line;
|
308 | cur = match.index + match[0].length;
|
309 | } else {
|
310 | return new Position(line, offset - cur)
|
311 | }
|
312 | }
|
313 | }
|
314 |
|
315 |
|
316 |
|
317 |
|
318 | var defaultOptions = {
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 | ecmaVersion: 9,
|
325 |
|
326 |
|
327 |
|
328 | sourceType: "script",
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 | onInsertedSemicolon: null,
|
335 |
|
336 |
|
337 | onTrailingComma: null,
|
338 |
|
339 |
|
340 |
|
341 |
|
342 | allowReserved: null,
|
343 |
|
344 |
|
345 | allowReturnOutsideFunction: false,
|
346 |
|
347 |
|
348 | allowImportExportEverywhere: false,
|
349 |
|
350 |
|
351 | allowAwaitOutsideFunction: false,
|
352 |
|
353 |
|
354 | allowHashBang: false,
|
355 |
|
356 |
|
357 |
|
358 |
|
359 | locations: false,
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 | onToken: null,
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 | onComment: null,
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 | ranges: false,
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 | program: null,
|
392 |
|
393 |
|
394 | sourceFile: null,
|
395 |
|
396 |
|
397 | directSourceFile: null,
|
398 |
|
399 |
|
400 | preserveParens: false
|
401 | };
|
402 |
|
403 |
|
404 |
|
405 | function getOptions(opts) {
|
406 | var options = {};
|
407 |
|
408 | for (var opt in defaultOptions)
|
409 | { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
|
410 |
|
411 | if (options.ecmaVersion >= 2015)
|
412 | { options.ecmaVersion -= 2009; }
|
413 |
|
414 | if (options.allowReserved == null)
|
415 | { options.allowReserved = options.ecmaVersion < 5; }
|
416 |
|
417 | if (isArray(options.onToken)) {
|
418 | var tokens = options.onToken;
|
419 | options.onToken = function (token) { return tokens.push(token); };
|
420 | }
|
421 | if (isArray(options.onComment))
|
422 | { options.onComment = pushComment(options, options.onComment); }
|
423 |
|
424 | return options
|
425 | }
|
426 |
|
427 | function pushComment(options, array) {
|
428 | return function(block, text, start, end, startLoc, endLoc) {
|
429 | var comment = {
|
430 | type: block ? "Block" : "Line",
|
431 | value: text,
|
432 | start: start,
|
433 | end: end
|
434 | };
|
435 | if (options.locations)
|
436 | { comment.loc = new SourceLocation(this, startLoc, endLoc); }
|
437 | if (options.ranges)
|
438 | { comment.range = [start, end]; }
|
439 | array.push(comment);
|
440 | }
|
441 | }
|
442 |
|
443 |
|
444 | var
|
445 | SCOPE_TOP = 1,
|
446 | SCOPE_FUNCTION = 2,
|
447 | SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION,
|
448 | SCOPE_ASYNC = 4,
|
449 | SCOPE_GENERATOR = 8,
|
450 | SCOPE_ARROW = 16,
|
451 | SCOPE_SIMPLE_CATCH = 32,
|
452 | SCOPE_SUPER = 64,
|
453 | SCOPE_DIRECT_SUPER = 128;
|
454 |
|
455 | function functionFlags(async, generator) {
|
456 | return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
|
457 | }
|
458 |
|
459 |
|
460 | var
|
461 | BIND_NONE = 0,
|
462 | BIND_VAR = 1,
|
463 | BIND_LEXICAL = 2,
|
464 | BIND_FUNCTION = 3,
|
465 | BIND_SIMPLE_CATCH = 4,
|
466 | BIND_OUTSIDE = 5;
|
467 |
|
468 | var Parser = function Parser(options, input, startPos) {
|
469 | this.options = options = getOptions(options);
|
470 | this.sourceFile = options.sourceFile;
|
471 | this.keywords = wordsRegexp(keywords[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]);
|
472 | var reserved = "";
|
473 | if (options.allowReserved !== true) {
|
474 | for (var v = options.ecmaVersion;; v--)
|
475 | { if (reserved = reservedWords[v]) { break } }
|
476 | if (options.sourceType === "module") { reserved += " await"; }
|
477 | }
|
478 | this.reservedWords = wordsRegexp(reserved);
|
479 | var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
|
480 | this.reservedWordsStrict = wordsRegexp(reservedStrict);
|
481 | this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
|
482 | this.input = String(input);
|
483 |
|
484 |
|
485 |
|
486 |
|
487 | this.containsEsc = false;
|
488 |
|
489 |
|
490 |
|
491 |
|
492 | if (startPos) {
|
493 | this.pos = startPos;
|
494 | this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
|
495 | this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
|
496 | } else {
|
497 | this.pos = this.lineStart = 0;
|
498 | this.curLine = 1;
|
499 | }
|
500 |
|
501 |
|
502 |
|
503 | this.type = types.eof;
|
504 |
|
505 | this.value = null;
|
506 |
|
507 | this.start = this.end = this.pos;
|
508 |
|
509 |
|
510 | this.startLoc = this.endLoc = this.curPosition();
|
511 |
|
512 |
|
513 | this.lastTokEndLoc = this.lastTokStartLoc = null;
|
514 | this.lastTokStart = this.lastTokEnd = this.pos;
|
515 |
|
516 |
|
517 |
|
518 |
|
519 | this.context = this.initialContext();
|
520 | this.exprAllowed = true;
|
521 |
|
522 |
|
523 | this.inModule = options.sourceType === "module";
|
524 | this.strict = this.inModule || this.strictDirective(this.pos);
|
525 |
|
526 |
|
527 | this.potentialArrowAt = -1;
|
528 |
|
529 |
|
530 | this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
|
531 |
|
532 | this.labels = [];
|
533 |
|
534 | this.undefinedExports = {};
|
535 |
|
536 |
|
537 | if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
|
538 | { this.skipLineComment(2); }
|
539 |
|
540 |
|
541 | this.scopeStack = [];
|
542 | this.enterScope(SCOPE_TOP);
|
543 |
|
544 |
|
545 | this.regexpState = null;
|
546 | };
|
547 |
|
548 | var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true } };
|
549 |
|
550 | Parser.prototype.parse = function parse () {
|
551 | var node = this.options.program || this.startNode();
|
552 | this.nextToken();
|
553 | return this.parseTopLevel(node)
|
554 | };
|
555 |
|
556 | prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
|
557 | prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 };
|
558 | prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 };
|
559 | prototypeAccessors.allowSuper.get = function () { return (this.currentThisScope().flags & SCOPE_SUPER) > 0 };
|
560 | prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
|
561 | prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
|
562 |
|
563 |
|
564 | Parser.prototype.inNonArrowFunction = function inNonArrowFunction () { return (this.currentThisScope().flags & SCOPE_FUNCTION) > 0 };
|
565 |
|
566 | Parser.extend = function extend () {
|
567 | var plugins = [], len = arguments.length;
|
568 | while ( len-- ) plugins[ len ] = arguments[ len ];
|
569 |
|
570 | var cls = this;
|
571 | for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
|
572 | return cls
|
573 | };
|
574 |
|
575 | Parser.parse = function parse (input, options) {
|
576 | return new this(options, input).parse()
|
577 | };
|
578 |
|
579 | Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
|
580 | var parser = new this(options, input, pos);
|
581 | parser.nextToken();
|
582 | return parser.parseExpression()
|
583 | };
|
584 |
|
585 | Parser.tokenizer = function tokenizer (input, options) {
|
586 | return new this(options, input)
|
587 | };
|
588 |
|
589 | Object.defineProperties( Parser.prototype, prototypeAccessors );
|
590 |
|
591 | var pp = Parser.prototype;
|
592 |
|
593 |
|
594 |
|
595 | var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)")/;
|
596 | pp.strictDirective = function(start) {
|
597 | for (;;) {
|
598 |
|
599 | skipWhiteSpace.lastIndex = start;
|
600 | start += skipWhiteSpace.exec(this.input)[0].length;
|
601 | var match = literal.exec(this.input.slice(start));
|
602 | if (!match) { return false }
|
603 | if ((match[1] || match[2]) === "use strict") { return true }
|
604 | start += match[0].length;
|
605 |
|
606 |
|
607 | skipWhiteSpace.lastIndex = start;
|
608 | start += skipWhiteSpace.exec(this.input)[0].length;
|
609 | if (this.input[start] === ";")
|
610 | { start++; }
|
611 | }
|
612 | };
|
613 |
|
614 |
|
615 |
|
616 |
|
617 | pp.eat = function(type) {
|
618 | if (this.type === type) {
|
619 | this.next();
|
620 | return true
|
621 | } else {
|
622 | return false
|
623 | }
|
624 | };
|
625 |
|
626 |
|
627 |
|
628 | pp.isContextual = function(name) {
|
629 | return this.type === types.name && this.value === name && !this.containsEsc
|
630 | };
|
631 |
|
632 |
|
633 |
|
634 | pp.eatContextual = function(name) {
|
635 | if (!this.isContextual(name)) { return false }
|
636 | this.next();
|
637 | return true
|
638 | };
|
639 |
|
640 |
|
641 |
|
642 | pp.expectContextual = function(name) {
|
643 | if (!this.eatContextual(name)) { this.unexpected(); }
|
644 | };
|
645 |
|
646 |
|
647 |
|
648 | pp.canInsertSemicolon = function() {
|
649 | return this.type === types.eof ||
|
650 | this.type === types.braceR ||
|
651 | lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
|
652 | };
|
653 |
|
654 | pp.insertSemicolon = function() {
|
655 | if (this.canInsertSemicolon()) {
|
656 | if (this.options.onInsertedSemicolon)
|
657 | { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
|
658 | return true
|
659 | }
|
660 | };
|
661 |
|
662 |
|
663 |
|
664 |
|
665 | pp.semicolon = function() {
|
666 | if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
|
667 | };
|
668 |
|
669 | pp.afterTrailingComma = function(tokType, notNext) {
|
670 | if (this.type === tokType) {
|
671 | if (this.options.onTrailingComma)
|
672 | { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
|
673 | if (!notNext)
|
674 | { this.next(); }
|
675 | return true
|
676 | }
|
677 | };
|
678 |
|
679 |
|
680 |
|
681 |
|
682 | pp.expect = function(type) {
|
683 | this.eat(type) || this.unexpected();
|
684 | };
|
685 |
|
686 |
|
687 |
|
688 | pp.unexpected = function(pos) {
|
689 | this.raise(pos != null ? pos : this.start, "Unexpected token");
|
690 | };
|
691 |
|
692 | function DestructuringErrors() {
|
693 | this.shorthandAssign =
|
694 | this.trailingComma =
|
695 | this.parenthesizedAssign =
|
696 | this.parenthesizedBind =
|
697 | this.doubleProto =
|
698 | -1;
|
699 | }
|
700 |
|
701 | pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
|
702 | if (!refDestructuringErrors) { return }
|
703 | if (refDestructuringErrors.trailingComma > -1)
|
704 | { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
|
705 | var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
|
706 | if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
|
707 | };
|
708 |
|
709 | pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
|
710 | if (!refDestructuringErrors) { return false }
|
711 | var shorthandAssign = refDestructuringErrors.shorthandAssign;
|
712 | var doubleProto = refDestructuringErrors.doubleProto;
|
713 | if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
|
714 | if (shorthandAssign >= 0)
|
715 | { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
|
716 | if (doubleProto >= 0)
|
717 | { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
|
718 | };
|
719 |
|
720 | pp.checkYieldAwaitInDefaultParams = function() {
|
721 | if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
|
722 | { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
|
723 | if (this.awaitPos)
|
724 | { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
|
725 | };
|
726 |
|
727 | pp.isSimpleAssignTarget = function(expr) {
|
728 | if (expr.type === "ParenthesizedExpression")
|
729 | { return this.isSimpleAssignTarget(expr.expression) }
|
730 | return expr.type === "Identifier" || expr.type === "MemberExpression"
|
731 | };
|
732 |
|
733 | var pp$1 = Parser.prototype;
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 | pp$1.parseTopLevel = function(node) {
|
743 | var exports = {};
|
744 | if (!node.body) { node.body = []; }
|
745 | while (this.type !== types.eof) {
|
746 | var stmt = this.parseStatement(null, true, exports);
|
747 | node.body.push(stmt);
|
748 | }
|
749 | if (this.inModule)
|
750 | { for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1)
|
751 | {
|
752 | var name = list[i];
|
753 |
|
754 | this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
|
755 | } }
|
756 | this.adaptDirectivePrologue(node.body);
|
757 | this.next();
|
758 | node.sourceType = this.options.sourceType;
|
759 | return this.finishNode(node, "Program")
|
760 | };
|
761 |
|
762 | var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
|
763 |
|
764 | pp$1.isLet = function(context) {
|
765 | if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
|
766 | skipWhiteSpace.lastIndex = this.pos;
|
767 | var skip = skipWhiteSpace.exec(this.input);
|
768 | var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
|
769 |
|
770 |
|
771 |
|
772 |
|
773 | if (nextCh === 91) { return true }
|
774 | if (context) { return false }
|
775 |
|
776 | if (nextCh === 123) { return true }
|
777 | if (isIdentifierStart(nextCh, true)) {
|
778 | var pos = next + 1;
|
779 | while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
|
780 | var ident = this.input.slice(next, pos);
|
781 | if (!keywordRelationalOperator.test(ident)) { return true }
|
782 | }
|
783 | return false
|
784 | };
|
785 |
|
786 |
|
787 |
|
788 |
|
789 | pp$1.isAsyncFunction = function() {
|
790 | if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
|
791 | { return false }
|
792 |
|
793 | skipWhiteSpace.lastIndex = this.pos;
|
794 | var skip = skipWhiteSpace.exec(this.input);
|
795 | var next = this.pos + skip[0].length;
|
796 | return !lineBreak.test(this.input.slice(this.pos, next)) &&
|
797 | this.input.slice(next, next + 8) === "function" &&
|
798 | (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
|
799 | };
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 | pp$1.parseStatement = function(context, topLevel, exports) {
|
809 | var starttype = this.type, node = this.startNode(), kind;
|
810 |
|
811 | if (this.isLet(context)) {
|
812 | starttype = types._var;
|
813 | kind = "let";
|
814 | }
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 | switch (starttype) {
|
821 | case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
|
822 | case types._debugger: return this.parseDebuggerStatement(node)
|
823 | case types._do: return this.parseDoStatement(node)
|
824 | case types._for: return this.parseForStatement(node)
|
825 | case types._function:
|
826 |
|
827 |
|
828 |
|
829 | if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
|
830 | return this.parseFunctionStatement(node, false, !context)
|
831 | case types._class:
|
832 | if (context) { this.unexpected(); }
|
833 | return this.parseClass(node, true)
|
834 | case types._if: return this.parseIfStatement(node)
|
835 | case types._return: return this.parseReturnStatement(node)
|
836 | case types._switch: return this.parseSwitchStatement(node)
|
837 | case types._throw: return this.parseThrowStatement(node)
|
838 | case types._try: return this.parseTryStatement(node)
|
839 | case types._const: case types._var:
|
840 | kind = kind || this.value;
|
841 | if (context && kind !== "var") { this.unexpected(); }
|
842 | return this.parseVarStatement(node, kind)
|
843 | case types._while: return this.parseWhileStatement(node)
|
844 | case types._with: return this.parseWithStatement(node)
|
845 | case types.braceL: return this.parseBlock(true, node)
|
846 | case types.semi: return this.parseEmptyStatement(node)
|
847 | case types._export:
|
848 | case types._import:
|
849 | if (this.options.ecmaVersion > 10 && starttype === types._import) {
|
850 | skipWhiteSpace.lastIndex = this.pos;
|
851 | var skip = skipWhiteSpace.exec(this.input);
|
852 | var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
|
853 | if (nextCh === 40)
|
854 | { return this.parseExpressionStatement(node, this.parseExpression()) }
|
855 | }
|
856 |
|
857 | if (!this.options.allowImportExportEverywhere) {
|
858 | if (!topLevel)
|
859 | { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
|
860 | if (!this.inModule)
|
861 | { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
|
862 | }
|
863 | return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 | default:
|
871 | if (this.isAsyncFunction()) {
|
872 | if (context) { this.unexpected(); }
|
873 | this.next();
|
874 | return this.parseFunctionStatement(node, true, !context)
|
875 | }
|
876 |
|
877 | var maybeName = this.value, expr = this.parseExpression();
|
878 | if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
|
879 | { return this.parseLabeledStatement(node, maybeName, expr, context) }
|
880 | else { return this.parseExpressionStatement(node, expr) }
|
881 | }
|
882 | };
|
883 |
|
884 | pp$1.parseBreakContinueStatement = function(node, keyword) {
|
885 | var isBreak = keyword === "break";
|
886 | this.next();
|
887 | if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
|
888 | else if (this.type !== types.name) { this.unexpected(); }
|
889 | else {
|
890 | node.label = this.parseIdent();
|
891 | this.semicolon();
|
892 | }
|
893 |
|
894 |
|
895 |
|
896 | var i = 0;
|
897 | for (; i < this.labels.length; ++i) {
|
898 | var lab = this.labels[i];
|
899 | if (node.label == null || lab.name === node.label.name) {
|
900 | if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
|
901 | if (node.label && isBreak) { break }
|
902 | }
|
903 | }
|
904 | if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
|
905 | return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
|
906 | };
|
907 |
|
908 | pp$1.parseDebuggerStatement = function(node) {
|
909 | this.next();
|
910 | this.semicolon();
|
911 | return this.finishNode(node, "DebuggerStatement")
|
912 | };
|
913 |
|
914 | pp$1.parseDoStatement = function(node) {
|
915 | this.next();
|
916 | this.labels.push(loopLabel);
|
917 | node.body = this.parseStatement("do");
|
918 | this.labels.pop();
|
919 | this.expect(types._while);
|
920 | node.test = this.parseParenExpression();
|
921 | if (this.options.ecmaVersion >= 6)
|
922 | { this.eat(types.semi); }
|
923 | else
|
924 | { this.semicolon(); }
|
925 | return this.finishNode(node, "DoWhileStatement")
|
926 | };
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 |
|
933 |
|
934 |
|
935 |
|
936 | pp$1.parseForStatement = function(node) {
|
937 | this.next();
|
938 | var awaitAt = (this.options.ecmaVersion >= 9 && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction)) && this.eatContextual("await")) ? this.lastTokStart : -1;
|
939 | this.labels.push(loopLabel);
|
940 | this.enterScope(0);
|
941 | this.expect(types.parenL);
|
942 | if (this.type === types.semi) {
|
943 | if (awaitAt > -1) { this.unexpected(awaitAt); }
|
944 | return this.parseFor(node, null)
|
945 | }
|
946 | var isLet = this.isLet();
|
947 | if (this.type === types._var || this.type === types._const || isLet) {
|
948 | var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
|
949 | this.next();
|
950 | this.parseVar(init$1, true, kind);
|
951 | this.finishNode(init$1, "VariableDeclaration");
|
952 | if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1) {
|
953 | if (this.options.ecmaVersion >= 9) {
|
954 | if (this.type === types._in) {
|
955 | if (awaitAt > -1) { this.unexpected(awaitAt); }
|
956 | } else { node.await = awaitAt > -1; }
|
957 | }
|
958 | return this.parseForIn(node, init$1)
|
959 | }
|
960 | if (awaitAt > -1) { this.unexpected(awaitAt); }
|
961 | return this.parseFor(node, init$1)
|
962 | }
|
963 | var refDestructuringErrors = new DestructuringErrors;
|
964 | var init = this.parseExpression(true, refDestructuringErrors);
|
965 | if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
|
966 | if (this.options.ecmaVersion >= 9) {
|
967 | if (this.type === types._in) {
|
968 | if (awaitAt > -1) { this.unexpected(awaitAt); }
|
969 | } else { node.await = awaitAt > -1; }
|
970 | }
|
971 | this.toAssignable(init, false, refDestructuringErrors);
|
972 | this.checkLVal(init);
|
973 | return this.parseForIn(node, init)
|
974 | } else {
|
975 | this.checkExpressionErrors(refDestructuringErrors, true);
|
976 | }
|
977 | if (awaitAt > -1) { this.unexpected(awaitAt); }
|
978 | return this.parseFor(node, init)
|
979 | };
|
980 |
|
981 | pp$1.parseFunctionStatement = function(node, isAsync, declarationPosition) {
|
982 | this.next();
|
983 | return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
|
984 | };
|
985 |
|
986 | pp$1.parseIfStatement = function(node) {
|
987 | this.next();
|
988 | node.test = this.parseParenExpression();
|
989 |
|
990 | node.consequent = this.parseStatement("if");
|
991 | node.alternate = this.eat(types._else) ? this.parseStatement("if") : null;
|
992 | return this.finishNode(node, "IfStatement")
|
993 | };
|
994 |
|
995 | pp$1.parseReturnStatement = function(node) {
|
996 | if (!this.inFunction && !this.options.allowReturnOutsideFunction)
|
997 | { this.raise(this.start, "'return' outside of function"); }
|
998 | this.next();
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 | if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
|
1005 | else { node.argument = this.parseExpression(); this.semicolon(); }
|
1006 | return this.finishNode(node, "ReturnStatement")
|
1007 | };
|
1008 |
|
1009 | pp$1.parseSwitchStatement = function(node) {
|
1010 | this.next();
|
1011 | node.discriminant = this.parseParenExpression();
|
1012 | node.cases = [];
|
1013 | this.expect(types.braceL);
|
1014 | this.labels.push(switchLabel);
|
1015 | this.enterScope(0);
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 | var cur;
|
1022 | for (var sawDefault = false; this.type !== types.braceR;) {
|
1023 | if (this.type === types._case || this.type === types._default) {
|
1024 | var isCase = this.type === types._case;
|
1025 | if (cur) { this.finishNode(cur, "SwitchCase"); }
|
1026 | node.cases.push(cur = this.startNode());
|
1027 | cur.consequent = [];
|
1028 | this.next();
|
1029 | if (isCase) {
|
1030 | cur.test = this.parseExpression();
|
1031 | } else {
|
1032 | if (sawDefault) { this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); }
|
1033 | sawDefault = true;
|
1034 | cur.test = null;
|
1035 | }
|
1036 | this.expect(types.colon);
|
1037 | } else {
|
1038 | if (!cur) { this.unexpected(); }
|
1039 | cur.consequent.push(this.parseStatement(null));
|
1040 | }
|
1041 | }
|
1042 | this.exitScope();
|
1043 | if (cur) { this.finishNode(cur, "SwitchCase"); }
|
1044 | this.next();
|
1045 | this.labels.pop();
|
1046 | return this.finishNode(node, "SwitchStatement")
|
1047 | };
|
1048 |
|
1049 | pp$1.parseThrowStatement = function(node) {
|
1050 | this.next();
|
1051 | if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
|
1052 | { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
|
1053 | node.argument = this.parseExpression();
|
1054 | this.semicolon();
|
1055 | return this.finishNode(node, "ThrowStatement")
|
1056 | };
|
1057 |
|
1058 |
|
1059 |
|
1060 | var empty = [];
|
1061 |
|
1062 | pp$1.parseTryStatement = function(node) {
|
1063 | this.next();
|
1064 | node.block = this.parseBlock();
|
1065 | node.handler = null;
|
1066 | if (this.type === types._catch) {
|
1067 | var clause = this.startNode();
|
1068 | this.next();
|
1069 | if (this.eat(types.parenL)) {
|
1070 | clause.param = this.parseBindingAtom();
|
1071 | var simple = clause.param.type === "Identifier";
|
1072 | this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0);
|
1073 | this.checkLVal(clause.param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL);
|
1074 | this.expect(types.parenR);
|
1075 | } else {
|
1076 | if (this.options.ecmaVersion < 10) { this.unexpected(); }
|
1077 | clause.param = null;
|
1078 | this.enterScope(0);
|
1079 | }
|
1080 | clause.body = this.parseBlock(false);
|
1081 | this.exitScope();
|
1082 | node.handler = this.finishNode(clause, "CatchClause");
|
1083 | }
|
1084 | node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
|
1085 | if (!node.handler && !node.finalizer)
|
1086 | { this.raise(node.start, "Missing catch or finally clause"); }
|
1087 | return this.finishNode(node, "TryStatement")
|
1088 | };
|
1089 |
|
1090 | pp$1.parseVarStatement = function(node, kind) {
|
1091 | this.next();
|
1092 | this.parseVar(node, false, kind);
|
1093 | this.semicolon();
|
1094 | return this.finishNode(node, "VariableDeclaration")
|
1095 | };
|
1096 |
|
1097 | pp$1.parseWhileStatement = function(node) {
|
1098 | this.next();
|
1099 | node.test = this.parseParenExpression();
|
1100 | this.labels.push(loopLabel);
|
1101 | node.body = this.parseStatement("while");
|
1102 | this.labels.pop();
|
1103 | return this.finishNode(node, "WhileStatement")
|
1104 | };
|
1105 |
|
1106 | pp$1.parseWithStatement = function(node) {
|
1107 | if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
|
1108 | this.next();
|
1109 | node.object = this.parseParenExpression();
|
1110 | node.body = this.parseStatement("with");
|
1111 | return this.finishNode(node, "WithStatement")
|
1112 | };
|
1113 |
|
1114 | pp$1.parseEmptyStatement = function(node) {
|
1115 | this.next();
|
1116 | return this.finishNode(node, "EmptyStatement")
|
1117 | };
|
1118 |
|
1119 | pp$1.parseLabeledStatement = function(node, maybeName, expr, context) {
|
1120 | for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
|
1121 | {
|
1122 | var label = list[i$1];
|
1123 |
|
1124 | if (label.name === maybeName)
|
1125 | { this.raise(expr.start, "Label '" + maybeName + "' is already declared");
|
1126 | } }
|
1127 | var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
|
1128 | for (var i = this.labels.length - 1; i >= 0; i--) {
|
1129 | var label$1 = this.labels[i];
|
1130 | if (label$1.statementStart === node.start) {
|
1131 |
|
1132 | label$1.statementStart = this.start;
|
1133 | label$1.kind = kind;
|
1134 | } else { break }
|
1135 | }
|
1136 | this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
|
1137 | node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
|
1138 | this.labels.pop();
|
1139 | node.label = expr;
|
1140 | return this.finishNode(node, "LabeledStatement")
|
1141 | };
|
1142 |
|
1143 | pp$1.parseExpressionStatement = function(node, expr) {
|
1144 | node.expression = expr;
|
1145 | this.semicolon();
|
1146 | return this.finishNode(node, "ExpressionStatement")
|
1147 | };
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 |
|
1153 | pp$1.parseBlock = function(createNewLexicalScope, node) {
|
1154 | if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
|
1155 | if ( node === void 0 ) node = this.startNode();
|
1156 |
|
1157 | node.body = [];
|
1158 | this.expect(types.braceL);
|
1159 | if (createNewLexicalScope) { this.enterScope(0); }
|
1160 | while (!this.eat(types.braceR)) {
|
1161 | var stmt = this.parseStatement(null);
|
1162 | node.body.push(stmt);
|
1163 | }
|
1164 | if (createNewLexicalScope) { this.exitScope(); }
|
1165 | return this.finishNode(node, "BlockStatement")
|
1166 | };
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 | pp$1.parseFor = function(node, init) {
|
1173 | node.init = init;
|
1174 | this.expect(types.semi);
|
1175 | node.test = this.type === types.semi ? null : this.parseExpression();
|
1176 | this.expect(types.semi);
|
1177 | node.update = this.type === types.parenR ? null : this.parseExpression();
|
1178 | this.expect(types.parenR);
|
1179 | node.body = this.parseStatement("for");
|
1180 | this.exitScope();
|
1181 | this.labels.pop();
|
1182 | return this.finishNode(node, "ForStatement")
|
1183 | };
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 | pp$1.parseForIn = function(node, init) {
|
1189 | var isForIn = this.type === types._in;
|
1190 | this.next();
|
1191 |
|
1192 | if (
|
1193 | init.type === "VariableDeclaration" &&
|
1194 | init.declarations[0].init != null &&
|
1195 | (
|
1196 | !isForIn ||
|
1197 | this.options.ecmaVersion < 8 ||
|
1198 | this.strict ||
|
1199 | init.kind !== "var" ||
|
1200 | init.declarations[0].id.type !== "Identifier"
|
1201 | )
|
1202 | ) {
|
1203 | this.raise(
|
1204 | init.start,
|
1205 | ((isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer")
|
1206 | );
|
1207 | } else if (init.type === "AssignmentPattern") {
|
1208 | this.raise(init.start, "Invalid left-hand side in for-loop");
|
1209 | }
|
1210 | node.left = init;
|
1211 | node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
|
1212 | this.expect(types.parenR);
|
1213 | node.body = this.parseStatement("for");
|
1214 | this.exitScope();
|
1215 | this.labels.pop();
|
1216 | return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement")
|
1217 | };
|
1218 |
|
1219 |
|
1220 |
|
1221 | pp$1.parseVar = function(node, isFor, kind) {
|
1222 | node.declarations = [];
|
1223 | node.kind = kind;
|
1224 | for (;;) {
|
1225 | var decl = this.startNode();
|
1226 | this.parseVarId(decl, kind);
|
1227 | if (this.eat(types.eq)) {
|
1228 | decl.init = this.parseMaybeAssign(isFor);
|
1229 | } else if (kind === "const" && !(this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
|
1230 | this.unexpected();
|
1231 | } else if (decl.id.type !== "Identifier" && !(isFor && (this.type === types._in || this.isContextual("of")))) {
|
1232 | this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
|
1233 | } else {
|
1234 | decl.init = null;
|
1235 | }
|
1236 | node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
|
1237 | if (!this.eat(types.comma)) { break }
|
1238 | }
|
1239 | return node
|
1240 | };
|
1241 |
|
1242 | pp$1.parseVarId = function(decl, kind) {
|
1243 | decl.id = this.parseBindingAtom();
|
1244 | this.checkLVal(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
|
1245 | };
|
1246 |
|
1247 | var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 | pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync) {
|
1254 | this.initFunction(node);
|
1255 | if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
|
1256 | if (this.type === types.star && (statement & FUNC_HANGING_STATEMENT))
|
1257 | { this.unexpected(); }
|
1258 | node.generator = this.eat(types.star);
|
1259 | }
|
1260 | if (this.options.ecmaVersion >= 8)
|
1261 | { node.async = !!isAsync; }
|
1262 |
|
1263 | if (statement & FUNC_STATEMENT) {
|
1264 | node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types.name ? null : this.parseIdent();
|
1265 | if (node.id && !(statement & FUNC_HANGING_STATEMENT))
|
1266 |
|
1267 |
|
1268 |
|
1269 |
|
1270 | { this.checkLVal(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
|
1271 | }
|
1272 |
|
1273 | var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
|
1274 | this.yieldPos = 0;
|
1275 | this.awaitPos = 0;
|
1276 | this.awaitIdentPos = 0;
|
1277 | this.enterScope(functionFlags(node.async, node.generator));
|
1278 |
|
1279 | if (!(statement & FUNC_STATEMENT))
|
1280 | { node.id = this.type === types.name ? this.parseIdent() : null; }
|
1281 |
|
1282 | this.parseFunctionParams(node);
|
1283 | this.parseFunctionBody(node, allowExpressionBody, false);
|
1284 |
|
1285 | this.yieldPos = oldYieldPos;
|
1286 | this.awaitPos = oldAwaitPos;
|
1287 | this.awaitIdentPos = oldAwaitIdentPos;
|
1288 | return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
|
1289 | };
|
1290 |
|
1291 | pp$1.parseFunctionParams = function(node) {
|
1292 | this.expect(types.parenL);
|
1293 | node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
|
1294 | this.checkYieldAwaitInDefaultParams();
|
1295 | };
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 | pp$1.parseClass = function(node, isStatement) {
|
1301 | this.next();
|
1302 |
|
1303 |
|
1304 |
|
1305 | var oldStrict = this.strict;
|
1306 | this.strict = true;
|
1307 |
|
1308 | this.parseClassId(node, isStatement);
|
1309 | this.parseClassSuper(node);
|
1310 | var classBody = this.startNode();
|
1311 | var hadConstructor = false;
|
1312 | classBody.body = [];
|
1313 | this.expect(types.braceL);
|
1314 | while (!this.eat(types.braceR)) {
|
1315 | var element = this.parseClassElement(node.superClass !== null);
|
1316 | if (element) {
|
1317 | classBody.body.push(element);
|
1318 | if (element.type === "MethodDefinition" && element.kind === "constructor") {
|
1319 | if (hadConstructor) { this.raise(element.start, "Duplicate constructor in the same class"); }
|
1320 | hadConstructor = true;
|
1321 | }
|
1322 | }
|
1323 | }
|
1324 | node.body = this.finishNode(classBody, "ClassBody");
|
1325 | this.strict = oldStrict;
|
1326 | return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
|
1327 | };
|
1328 |
|
1329 | pp$1.parseClassElement = function(constructorAllowsSuper) {
|
1330 | var this$1 = this;
|
1331 |
|
1332 | if (this.eat(types.semi)) { return null }
|
1333 |
|
1334 | var method = this.startNode();
|
1335 | var tryContextual = function (k, noLineBreak) {
|
1336 | if ( noLineBreak === void 0 ) noLineBreak = false;
|
1337 |
|
1338 | var start = this$1.start, startLoc = this$1.startLoc;
|
1339 | if (!this$1.eatContextual(k)) { return false }
|
1340 | if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
|
1341 | if (method.key) { this$1.unexpected(); }
|
1342 | method.computed = false;
|
1343 | method.key = this$1.startNodeAt(start, startLoc);
|
1344 | method.key.name = k;
|
1345 | this$1.finishNode(method.key, "Identifier");
|
1346 | return false
|
1347 | };
|
1348 |
|
1349 | method.kind = "method";
|
1350 | method.static = tryContextual("static");
|
1351 | var isGenerator = this.eat(types.star);
|
1352 | var isAsync = false;
|
1353 | if (!isGenerator) {
|
1354 | if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
|
1355 | isAsync = true;
|
1356 | isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
|
1357 | } else if (tryContextual("get")) {
|
1358 | method.kind = "get";
|
1359 | } else if (tryContextual("set")) {
|
1360 | method.kind = "set";
|
1361 | }
|
1362 | }
|
1363 | if (!method.key) { this.parsePropertyName(method); }
|
1364 | var key = method.key;
|
1365 | var allowsDirectSuper = false;
|
1366 | if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
|
1367 | key.type === "Literal" && key.value === "constructor")) {
|
1368 | if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
|
1369 | if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
|
1370 | if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
|
1371 | method.kind = "constructor";
|
1372 | allowsDirectSuper = constructorAllowsSuper;
|
1373 | } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
|
1374 | this.raise(key.start, "Classes may not have a static property named prototype");
|
1375 | }
|
1376 | this.parseClassMethod(method, isGenerator, isAsync, allowsDirectSuper);
|
1377 | if (method.kind === "get" && method.value.params.length !== 0)
|
1378 | { this.raiseRecoverable(method.value.start, "getter should have no params"); }
|
1379 | if (method.kind === "set" && method.value.params.length !== 1)
|
1380 | { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
|
1381 | if (method.kind === "set" && method.value.params[0].type === "RestElement")
|
1382 | { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
|
1383 | return method
|
1384 | };
|
1385 |
|
1386 | pp$1.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
|
1387 | method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
|
1388 | return this.finishNode(method, "MethodDefinition")
|
1389 | };
|
1390 |
|
1391 | pp$1.parseClassId = function(node, isStatement) {
|
1392 | if (this.type === types.name) {
|
1393 | node.id = this.parseIdent();
|
1394 | if (isStatement)
|
1395 | { this.checkLVal(node.id, BIND_LEXICAL, false); }
|
1396 | } else {
|
1397 | if (isStatement === true)
|
1398 | { this.unexpected(); }
|
1399 | node.id = null;
|
1400 | }
|
1401 | };
|
1402 |
|
1403 | pp$1.parseClassSuper = function(node) {
|
1404 | node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
|
1405 | };
|
1406 |
|
1407 |
|
1408 |
|
1409 | pp$1.parseExport = function(node, exports) {
|
1410 | this.next();
|
1411 |
|
1412 | if (this.eat(types.star)) {
|
1413 | this.expectContextual("from");
|
1414 | if (this.type !== types.string) { this.unexpected(); }
|
1415 | node.source = this.parseExprAtom();
|
1416 | this.semicolon();
|
1417 | return this.finishNode(node, "ExportAllDeclaration")
|
1418 | }
|
1419 | if (this.eat(types._default)) {
|
1420 | this.checkExport(exports, "default", this.lastTokStart);
|
1421 | var isAsync;
|
1422 | if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
|
1423 | var fNode = this.startNode();
|
1424 | this.next();
|
1425 | if (isAsync) { this.next(); }
|
1426 | node.declaration = this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync);
|
1427 | } else if (this.type === types._class) {
|
1428 | var cNode = this.startNode();
|
1429 | node.declaration = this.parseClass(cNode, "nullableID");
|
1430 | } else {
|
1431 | node.declaration = this.parseMaybeAssign();
|
1432 | this.semicolon();
|
1433 | }
|
1434 | return this.finishNode(node, "ExportDefaultDeclaration")
|
1435 | }
|
1436 |
|
1437 | if (this.shouldParseExportStatement()) {
|
1438 | node.declaration = this.parseStatement(null);
|
1439 | if (node.declaration.type === "VariableDeclaration")
|
1440 | { this.checkVariableExport(exports, node.declaration.declarations); }
|
1441 | else
|
1442 | { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
|
1443 | node.specifiers = [];
|
1444 | node.source = null;
|
1445 | } else {
|
1446 | node.declaration = null;
|
1447 | node.specifiers = this.parseExportSpecifiers(exports);
|
1448 | if (this.eatContextual("from")) {
|
1449 | if (this.type !== types.string) { this.unexpected(); }
|
1450 | node.source = this.parseExprAtom();
|
1451 | } else {
|
1452 | for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
|
1453 |
|
1454 | var spec = list[i];
|
1455 |
|
1456 | this.checkUnreserved(spec.local);
|
1457 |
|
1458 | this.checkLocalExport(spec.local);
|
1459 | }
|
1460 |
|
1461 | node.source = null;
|
1462 | }
|
1463 | this.semicolon();
|
1464 | }
|
1465 | return this.finishNode(node, "ExportNamedDeclaration")
|
1466 | };
|
1467 |
|
1468 | pp$1.checkExport = function(exports, name, pos) {
|
1469 | if (!exports) { return }
|
1470 | if (has(exports, name))
|
1471 | { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
|
1472 | exports[name] = true;
|
1473 | };
|
1474 |
|
1475 | pp$1.checkPatternExport = function(exports, pat) {
|
1476 | var type = pat.type;
|
1477 | if (type === "Identifier")
|
1478 | { this.checkExport(exports, pat.name, pat.start); }
|
1479 | else if (type === "ObjectPattern")
|
1480 | { for (var i = 0, list = pat.properties; i < list.length; i += 1)
|
1481 | {
|
1482 | var prop = list[i];
|
1483 |
|
1484 | this.checkPatternExport(exports, prop);
|
1485 | } }
|
1486 | else if (type === "ArrayPattern")
|
1487 | { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
|
1488 | var elt = list$1[i$1];
|
1489 |
|
1490 | if (elt) { this.checkPatternExport(exports, elt); }
|
1491 | } }
|
1492 | else if (type === "Property")
|
1493 | { this.checkPatternExport(exports, pat.value); }
|
1494 | else if (type === "AssignmentPattern")
|
1495 | { this.checkPatternExport(exports, pat.left); }
|
1496 | else if (type === "RestElement")
|
1497 | { this.checkPatternExport(exports, pat.argument); }
|
1498 | else if (type === "ParenthesizedExpression")
|
1499 | { this.checkPatternExport(exports, pat.expression); }
|
1500 | };
|
1501 |
|
1502 | pp$1.checkVariableExport = function(exports, decls) {
|
1503 | if (!exports) { return }
|
1504 | for (var i = 0, list = decls; i < list.length; i += 1)
|
1505 | {
|
1506 | var decl = list[i];
|
1507 |
|
1508 | this.checkPatternExport(exports, decl.id);
|
1509 | }
|
1510 | };
|
1511 |
|
1512 | pp$1.shouldParseExportStatement = function() {
|
1513 | return this.type.keyword === "var" ||
|
1514 | this.type.keyword === "const" ||
|
1515 | this.type.keyword === "class" ||
|
1516 | this.type.keyword === "function" ||
|
1517 | this.isLet() ||
|
1518 | this.isAsyncFunction()
|
1519 | };
|
1520 |
|
1521 |
|
1522 |
|
1523 | pp$1.parseExportSpecifiers = function(exports) {
|
1524 | var nodes = [], first = true;
|
1525 |
|
1526 | this.expect(types.braceL);
|
1527 | while (!this.eat(types.braceR)) {
|
1528 | if (!first) {
|
1529 | this.expect(types.comma);
|
1530 | if (this.afterTrailingComma(types.braceR)) { break }
|
1531 | } else { first = false; }
|
1532 |
|
1533 | var node = this.startNode();
|
1534 | node.local = this.parseIdent(true);
|
1535 | node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
|
1536 | this.checkExport(exports, node.exported.name, node.exported.start);
|
1537 | nodes.push(this.finishNode(node, "ExportSpecifier"));
|
1538 | }
|
1539 | return nodes
|
1540 | };
|
1541 |
|
1542 |
|
1543 |
|
1544 | pp$1.parseImport = function(node) {
|
1545 | this.next();
|
1546 |
|
1547 | if (this.type === types.string) {
|
1548 | node.specifiers = empty;
|
1549 | node.source = this.parseExprAtom();
|
1550 | } else {
|
1551 | node.specifiers = this.parseImportSpecifiers();
|
1552 | this.expectContextual("from");
|
1553 | node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
|
1554 | }
|
1555 | this.semicolon();
|
1556 | return this.finishNode(node, "ImportDeclaration")
|
1557 | };
|
1558 |
|
1559 |
|
1560 |
|
1561 | pp$1.parseImportSpecifiers = function() {
|
1562 | var nodes = [], first = true;
|
1563 | if (this.type === types.name) {
|
1564 |
|
1565 | var node = this.startNode();
|
1566 | node.local = this.parseIdent();
|
1567 | this.checkLVal(node.local, BIND_LEXICAL);
|
1568 | nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
|
1569 | if (!this.eat(types.comma)) { return nodes }
|
1570 | }
|
1571 | if (this.type === types.star) {
|
1572 | var node$1 = this.startNode();
|
1573 | this.next();
|
1574 | this.expectContextual("as");
|
1575 | node$1.local = this.parseIdent();
|
1576 | this.checkLVal(node$1.local, BIND_LEXICAL);
|
1577 | nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
|
1578 | return nodes
|
1579 | }
|
1580 | this.expect(types.braceL);
|
1581 | while (!this.eat(types.braceR)) {
|
1582 | if (!first) {
|
1583 | this.expect(types.comma);
|
1584 | if (this.afterTrailingComma(types.braceR)) { break }
|
1585 | } else { first = false; }
|
1586 |
|
1587 | var node$2 = this.startNode();
|
1588 | node$2.imported = this.parseIdent(true);
|
1589 | if (this.eatContextual("as")) {
|
1590 | node$2.local = this.parseIdent();
|
1591 | } else {
|
1592 | this.checkUnreserved(node$2.imported);
|
1593 | node$2.local = node$2.imported;
|
1594 | }
|
1595 | this.checkLVal(node$2.local, BIND_LEXICAL);
|
1596 | nodes.push(this.finishNode(node$2, "ImportSpecifier"));
|
1597 | }
|
1598 | return nodes
|
1599 | };
|
1600 |
|
1601 |
|
1602 | pp$1.adaptDirectivePrologue = function(statements) {
|
1603 | for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
|
1604 | statements[i].directive = statements[i].expression.raw.slice(1, -1);
|
1605 | }
|
1606 | };
|
1607 | pp$1.isDirectiveCandidate = function(statement) {
|
1608 | return (
|
1609 | statement.type === "ExpressionStatement" &&
|
1610 | statement.expression.type === "Literal" &&
|
1611 | typeof statement.expression.value === "string" &&
|
1612 |
|
1613 | (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
|
1614 | )
|
1615 | };
|
1616 |
|
1617 | var pp$2 = Parser.prototype;
|
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 | pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
|
1623 | if (this.options.ecmaVersion >= 6 && node) {
|
1624 | switch (node.type) {
|
1625 | case "Identifier":
|
1626 | if (this.inAsync && node.name === "await")
|
1627 | { this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
|
1628 | break
|
1629 |
|
1630 | case "ObjectPattern":
|
1631 | case "ArrayPattern":
|
1632 | case "RestElement":
|
1633 | break
|
1634 |
|
1635 | case "ObjectExpression":
|
1636 | node.type = "ObjectPattern";
|
1637 | if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
|
1638 | for (var i = 0, list = node.properties; i < list.length; i += 1) {
|
1639 | var prop = list[i];
|
1640 |
|
1641 | this.toAssignable(prop, isBinding);
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 | if (
|
1648 | prop.type === "RestElement" &&
|
1649 | (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
|
1650 | ) {
|
1651 | this.raise(prop.argument.start, "Unexpected token");
|
1652 | }
|
1653 | }
|
1654 | break
|
1655 |
|
1656 | case "Property":
|
1657 |
|
1658 | if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
|
1659 | this.toAssignable(node.value, isBinding);
|
1660 | break
|
1661 |
|
1662 | case "ArrayExpression":
|
1663 | node.type = "ArrayPattern";
|
1664 | if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
|
1665 | this.toAssignableList(node.elements, isBinding);
|
1666 | break
|
1667 |
|
1668 | case "SpreadElement":
|
1669 | node.type = "RestElement";
|
1670 | this.toAssignable(node.argument, isBinding);
|
1671 | if (node.argument.type === "AssignmentPattern")
|
1672 | { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
|
1673 | break
|
1674 |
|
1675 | case "AssignmentExpression":
|
1676 | if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
|
1677 | node.type = "AssignmentPattern";
|
1678 | delete node.operator;
|
1679 | this.toAssignable(node.left, isBinding);
|
1680 |
|
1681 |
|
1682 | case "AssignmentPattern":
|
1683 | break
|
1684 |
|
1685 | case "ParenthesizedExpression":
|
1686 | this.toAssignable(node.expression, isBinding, refDestructuringErrors);
|
1687 | break
|
1688 |
|
1689 | case "MemberExpression":
|
1690 | if (!isBinding) { break }
|
1691 |
|
1692 | default:
|
1693 | this.raise(node.start, "Assigning to rvalue");
|
1694 | }
|
1695 | } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
|
1696 | return node
|
1697 | };
|
1698 |
|
1699 |
|
1700 |
|
1701 | pp$2.toAssignableList = function(exprList, isBinding) {
|
1702 | var end = exprList.length;
|
1703 | for (var i = 0; i < end; i++) {
|
1704 | var elt = exprList[i];
|
1705 | if (elt) { this.toAssignable(elt, isBinding); }
|
1706 | }
|
1707 | if (end) {
|
1708 | var last = exprList[end - 1];
|
1709 | if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
|
1710 | { this.unexpected(last.argument.start); }
|
1711 | }
|
1712 | return exprList
|
1713 | };
|
1714 |
|
1715 |
|
1716 |
|
1717 | pp$2.parseSpread = function(refDestructuringErrors) {
|
1718 | var node = this.startNode();
|
1719 | this.next();
|
1720 | node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
|
1721 | return this.finishNode(node, "SpreadElement")
|
1722 | };
|
1723 |
|
1724 | pp$2.parseRestBinding = function() {
|
1725 | var node = this.startNode();
|
1726 | this.next();
|
1727 |
|
1728 |
|
1729 | if (this.options.ecmaVersion === 6 && this.type !== types.name)
|
1730 | { this.unexpected(); }
|
1731 |
|
1732 | node.argument = this.parseBindingAtom();
|
1733 |
|
1734 | return this.finishNode(node, "RestElement")
|
1735 | };
|
1736 |
|
1737 |
|
1738 |
|
1739 | pp$2.parseBindingAtom = function() {
|
1740 | if (this.options.ecmaVersion >= 6) {
|
1741 | switch (this.type) {
|
1742 | case types.bracketL:
|
1743 | var node = this.startNode();
|
1744 | this.next();
|
1745 | node.elements = this.parseBindingList(types.bracketR, true, true);
|
1746 | return this.finishNode(node, "ArrayPattern")
|
1747 |
|
1748 | case types.braceL:
|
1749 | return this.parseObj(true)
|
1750 | }
|
1751 | }
|
1752 | return this.parseIdent()
|
1753 | };
|
1754 |
|
1755 | pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
|
1756 | var elts = [], first = true;
|
1757 | while (!this.eat(close)) {
|
1758 | if (first) { first = false; }
|
1759 | else { this.expect(types.comma); }
|
1760 | if (allowEmpty && this.type === types.comma) {
|
1761 | elts.push(null);
|
1762 | } else if (allowTrailingComma && this.afterTrailingComma(close)) {
|
1763 | break
|
1764 | } else if (this.type === types.ellipsis) {
|
1765 | var rest = this.parseRestBinding();
|
1766 | this.parseBindingListItem(rest);
|
1767 | elts.push(rest);
|
1768 | if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
|
1769 | this.expect(close);
|
1770 | break
|
1771 | } else {
|
1772 | var elem = this.parseMaybeDefault(this.start, this.startLoc);
|
1773 | this.parseBindingListItem(elem);
|
1774 | elts.push(elem);
|
1775 | }
|
1776 | }
|
1777 | return elts
|
1778 | };
|
1779 |
|
1780 | pp$2.parseBindingListItem = function(param) {
|
1781 | return param
|
1782 | };
|
1783 |
|
1784 |
|
1785 |
|
1786 | pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
|
1787 | left = left || this.parseBindingAtom();
|
1788 | if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
|
1789 | var node = this.startNodeAt(startPos, startLoc);
|
1790 | node.left = left;
|
1791 | node.right = this.parseMaybeAssign();
|
1792 | return this.finishNode(node, "AssignmentPattern")
|
1793 | };
|
1794 |
|
1795 |
|
1796 |
|
1797 |
|
1798 |
|
1799 |
|
1800 |
|
1801 |
|
1802 | pp$2.checkLVal = function(expr, bindingType, checkClashes) {
|
1803 | if ( bindingType === void 0 ) bindingType = BIND_NONE;
|
1804 |
|
1805 | switch (expr.type) {
|
1806 | case "Identifier":
|
1807 | if (bindingType === BIND_LEXICAL && expr.name === "let")
|
1808 | { this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); }
|
1809 | if (this.strict && this.reservedWordsStrictBind.test(expr.name))
|
1810 | { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
|
1811 | if (checkClashes) {
|
1812 | if (has(checkClashes, expr.name))
|
1813 | { this.raiseRecoverable(expr.start, "Argument name clash"); }
|
1814 | checkClashes[expr.name] = true;
|
1815 | }
|
1816 | if (bindingType !== BIND_NONE && bindingType !== BIND_OUTSIDE) { this.declareName(expr.name, bindingType, expr.start); }
|
1817 | break
|
1818 |
|
1819 | case "MemberExpression":
|
1820 | if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
|
1821 | break
|
1822 |
|
1823 | case "ObjectPattern":
|
1824 | for (var i = 0, list = expr.properties; i < list.length; i += 1)
|
1825 | {
|
1826 | var prop = list[i];
|
1827 |
|
1828 | this.checkLVal(prop, bindingType, checkClashes);
|
1829 | }
|
1830 | break
|
1831 |
|
1832 | case "Property":
|
1833 |
|
1834 | this.checkLVal(expr.value, bindingType, checkClashes);
|
1835 | break
|
1836 |
|
1837 | case "ArrayPattern":
|
1838 | for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
|
1839 | var elem = list$1[i$1];
|
1840 |
|
1841 | if (elem) { this.checkLVal(elem, bindingType, checkClashes); }
|
1842 | }
|
1843 | break
|
1844 |
|
1845 | case "AssignmentPattern":
|
1846 | this.checkLVal(expr.left, bindingType, checkClashes);
|
1847 | break
|
1848 |
|
1849 | case "RestElement":
|
1850 | this.checkLVal(expr.argument, bindingType, checkClashes);
|
1851 | break
|
1852 |
|
1853 | case "ParenthesizedExpression":
|
1854 | this.checkLVal(expr.expression, bindingType, checkClashes);
|
1855 | break
|
1856 |
|
1857 | default:
|
1858 | this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
|
1859 | }
|
1860 | };
|
1861 |
|
1862 |
|
1863 |
|
1864 | var pp$3 = Parser.prototype;
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 |
|
1870 |
|
1871 | pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
|
1872 | if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
|
1873 | { return }
|
1874 | if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
|
1875 | { return }
|
1876 | var key = prop.key;
|
1877 | var name;
|
1878 | switch (key.type) {
|
1879 | case "Identifier": name = key.name; break
|
1880 | case "Literal": name = String(key.value); break
|
1881 | default: return
|
1882 | }
|
1883 | var kind = prop.kind;
|
1884 | if (this.options.ecmaVersion >= 6) {
|
1885 | if (name === "__proto__" && kind === "init") {
|
1886 | if (propHash.proto) {
|
1887 | if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) { refDestructuringErrors.doubleProto = key.start; }
|
1888 |
|
1889 | else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
|
1890 | }
|
1891 | propHash.proto = true;
|
1892 | }
|
1893 | return
|
1894 | }
|
1895 | name = "$" + name;
|
1896 | var other = propHash[name];
|
1897 | if (other) {
|
1898 | var redefinition;
|
1899 | if (kind === "init") {
|
1900 | redefinition = this.strict && other.init || other.get || other.set;
|
1901 | } else {
|
1902 | redefinition = other.init || other[kind];
|
1903 | }
|
1904 | if (redefinition)
|
1905 | { this.raiseRecoverable(key.start, "Redefinition of property"); }
|
1906 | } else {
|
1907 | other = propHash[name] = {
|
1908 | init: false,
|
1909 | get: false,
|
1910 | set: false
|
1911 | };
|
1912 | }
|
1913 | other[kind] = true;
|
1914 | };
|
1915 |
|
1916 | // ### Expression parsing
|
1917 |
|
1918 | // These nest, from the most general expression type at the top to
|
1919 | // 'atomic', nondivisible expression types at the bottom. Most of
|
1920 | // the functions will simply let the function(s) below them parse,
|
1921 | // and, *if* the syntactic construct they handle is present, wrap
|
1922 | // the AST node that the inner parser gave them in another node.
|
1923 |
|
1924 | // Parse a full expression. The optional arguments are used to
|
1925 | // forbid the `in` operator (in for loops initalization expressions)
|
1926 | // and provide reference for storing '=' operator inside shorthand
|
1927 | // property assignment in contexts where both object expression
|
1928 | // and object pattern might appear (so it's possible to raise
|
1929 | // delayed syntax error at correct position).
|
1930 |
|
1931 | pp$3.parseExpression = function(noIn, refDestructuringErrors) {
|
1932 | var startPos = this.start, startLoc = this.startLoc;
|
1933 | var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
|
1934 | if (this.type === types.comma) {
|
1935 | var node = this.startNodeAt(startPos, startLoc);
|
1936 | node.expressions = [expr];
|
1937 | while (this.eat(types.comma)) { node.expressions.push(this.parseMaybeAssign(noIn, refDestructuringErrors)); }
|
1938 | return this.finishNode(node, "SequenceExpression")
|
1939 | }
|
1940 | return expr
|
1941 | };
|
1942 |
|
1943 |
|
1944 |
|
1945 |
|
1946 | pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
|
1947 | if (this.isContextual("yield")) {
|
1948 | if (this.inGenerator) { return this.parseYield(noIn) }
|
1949 |
|
1950 |
|
1951 | else { this.exprAllowed = false; }
|
1952 | }
|
1953 |
|
1954 | var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldShorthandAssign = -1;
|
1955 | if (refDestructuringErrors) {
|
1956 | oldParenAssign = refDestructuringErrors.parenthesizedAssign;
|
1957 | oldTrailingComma = refDestructuringErrors.trailingComma;
|
1958 | oldShorthandAssign = refDestructuringErrors.shorthandAssign;
|
1959 | refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.shorthandAssign = -1;
|
1960 | } else {
|
1961 | refDestructuringErrors = new DestructuringErrors;
|
1962 | ownDestructuringErrors = true;
|
1963 | }
|
1964 |
|
1965 | var startPos = this.start, startLoc = this.startLoc;
|
1966 | if (this.type === types.parenL || this.type === types.name)
|
1967 | { this.potentialArrowAt = this.start; }
|
1968 | var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
|
1969 | if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
|
1970 | if (this.type.isAssign) {
|
1971 | var node = this.startNodeAt(startPos, startLoc);
|
1972 | node.operator = this.value;
|
1973 | node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left;
|
1974 | if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
|
1975 | refDestructuringErrors.shorthandAssign = -1;
|
1976 | this.checkLVal(left);
|
1977 | this.next();
|
1978 | node.right = this.parseMaybeAssign(noIn);
|
1979 | return this.finishNode(node, "AssignmentExpression")
|
1980 | } else {
|
1981 | if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
|
1982 | }
|
1983 | if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
|
1984 | if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
|
1985 | if (oldShorthandAssign > -1) { refDestructuringErrors.shorthandAssign = oldShorthandAssign; }
|
1986 | return left
|
1987 | };
|
1988 |
|
1989 |
|
1990 |
|
1991 | pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
|
1992 | var startPos = this.start, startLoc = this.startLoc;
|
1993 | var expr = this.parseExprOps(noIn, refDestructuringErrors);
|
1994 | if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
|
1995 | if (this.eat(types.question)) {
|
1996 | var node = this.startNodeAt(startPos, startLoc);
|
1997 | node.test = expr;
|
1998 | node.consequent = this.parseMaybeAssign();
|
1999 | this.expect(types.colon);
|
2000 | node.alternate = this.parseMaybeAssign(noIn);
|
2001 | return this.finishNode(node, "ConditionalExpression")
|
2002 | }
|
2003 | return expr
|
2004 | };
|
2005 |
|
2006 |
|
2007 |
|
2008 | pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
|
2009 | var startPos = this.start, startLoc = this.startLoc;
|
2010 | var expr = this.parseMaybeUnary(refDestructuringErrors, false);
|
2011 | if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
|
2012 | return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
|
2013 | };
|
2014 |
|
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 | pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
|
2022 | var prec = this.type.binop;
|
2023 | if (prec != null && (!noIn || this.type !== types._in)) {
|
2024 | if (prec > minPrec) {
|
2025 | var logical = this.type === types.logicalOR || this.type === types.logicalAND;
|
2026 | var op = this.value;
|
2027 | this.next();
|
2028 | var startPos = this.start, startLoc = this.startLoc;
|
2029 | var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
|
2030 | var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
|
2031 | return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
|
2032 | }
|
2033 | }
|
2034 | return left
|
2035 | };
|
2036 |
|
2037 | pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
|
2038 | var node = this.startNodeAt(startPos, startLoc);
|
2039 | node.left = left;
|
2040 | node.operator = op;
|
2041 | node.right = right;
|
2042 | return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
|
2043 | };
|
2044 |
|
2045 |
|
2046 |
|
2047 | pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
|
2048 | var startPos = this.start, startLoc = this.startLoc, expr;
|
2049 | if (this.isContextual("await") && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction))) {
|
2050 | expr = this.parseAwait();
|
2051 | sawUnary = true;
|
2052 | } else if (this.type.prefix) {
|
2053 | var node = this.startNode(), update = this.type === types.incDec;
|
2054 | node.operator = this.value;
|
2055 | node.prefix = true;
|
2056 | this.next();
|
2057 | node.argument = this.parseMaybeUnary(null, true);
|
2058 | this.checkExpressionErrors(refDestructuringErrors, true);
|
2059 | if (update) { this.checkLVal(node.argument); }
|
2060 | else if (this.strict && node.operator === "delete" &&
|
2061 | node.argument.type === "Identifier")
|
2062 | { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
|
2063 | else { sawUnary = true; }
|
2064 | expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
|
2065 | } else {
|
2066 | expr = this.parseExprSubscripts(refDestructuringErrors);
|
2067 | if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
|
2068 | while (this.type.postfix && !this.canInsertSemicolon()) {
|
2069 | var node$1 = this.startNodeAt(startPos, startLoc);
|
2070 | node$1.operator = this.value;
|
2071 | node$1.prefix = false;
|
2072 | node$1.argument = expr;
|
2073 | this.checkLVal(expr);
|
2074 | this.next();
|
2075 | expr = this.finishNode(node$1, "UpdateExpression");
|
2076 | }
|
2077 | }
|
2078 |
|
2079 | if (!sawUnary && this.eat(types.starstar))
|
2080 | { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
|
2081 | else
|
2082 | { return expr }
|
2083 | };
|
2084 |
|
2085 |
|
2086 |
|
2087 | pp$3.parseExprSubscripts = function(refDestructuringErrors) {
|
2088 | var startPos = this.start, startLoc = this.startLoc;
|
2089 | var expr = this.parseExprAtom(refDestructuringErrors);
|
2090 | var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
|
2091 | if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
|
2092 | var result = this.parseSubscripts(expr, startPos, startLoc);
|
2093 | if (refDestructuringErrors && result.type === "MemberExpression") {
|
2094 | if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
|
2095 | if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
|
2096 | }
|
2097 | return result
|
2098 | };
|
2099 |
|
2100 | pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
|
2101 | var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
|
2102 | this.lastTokEnd === base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async";
|
2103 | while (true) {
|
2104 | var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow);
|
2105 | if (element === base || element.type === "ArrowFunctionExpression") { return element }
|
2106 | base = element;
|
2107 | }
|
2108 | };
|
2109 |
|
2110 | pp$3.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow) {
|
2111 | var computed = this.eat(types.bracketL);
|
2112 | if (computed || this.eat(types.dot)) {
|
2113 | var node = this.startNodeAt(startPos, startLoc);
|
2114 | node.object = base;
|
2115 | node.property = computed ? this.parseExpression() : this.parseIdent(this.options.allowReserved !== "never");
|
2116 | node.computed = !!computed;
|
2117 | if (computed) { this.expect(types.bracketR); }
|
2118 | base = this.finishNode(node, "MemberExpression");
|
2119 | } else if (!noCalls && this.eat(types.parenL)) {
|
2120 | var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
|
2121 | this.yieldPos = 0;
|
2122 | this.awaitPos = 0;
|
2123 | this.awaitIdentPos = 0;
|
2124 | var exprList = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8 && base.type !== "Import", false, refDestructuringErrors);
|
2125 | if (maybeAsyncArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
|
2126 | this.checkPatternErrors(refDestructuringErrors, false);
|
2127 | this.checkYieldAwaitInDefaultParams();
|
2128 | if (this.awaitIdentPos > 0)
|
2129 | { this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); }
|
2130 | this.yieldPos = oldYieldPos;
|
2131 | this.awaitPos = oldAwaitPos;
|
2132 | this.awaitIdentPos = oldAwaitIdentPos;
|
2133 | return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true)
|
2134 | }
|
2135 | this.checkExpressionErrors(refDestructuringErrors, true);
|
2136 | this.yieldPos = oldYieldPos || this.yieldPos;
|
2137 | this.awaitPos = oldAwaitPos || this.awaitPos;
|
2138 | this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos;
|
2139 | var node$1 = this.startNodeAt(startPos, startLoc);
|
2140 | node$1.callee = base;
|
2141 | node$1.arguments = exprList;
|
2142 | if (node$1.callee.type === "Import") {
|
2143 | if (node$1.arguments.length !== 1) {
|
2144 | this.raise(node$1.start, "import() requires exactly one argument");
|
2145 | }
|
2146 |
|
2147 | var importArg = node$1.arguments[0];
|
2148 | if (importArg && importArg.type === "SpreadElement") {
|
2149 | this.raise(importArg.start, "... is not allowed in import()");
|
2150 | }
|
2151 | }
|
2152 | base = this.finishNode(node$1, "CallExpression");
|
2153 | } else if (this.type === types.backQuote) {
|
2154 | var node$2 = this.startNodeAt(startPos, startLoc);
|
2155 | node$2.tag = base;
|
2156 | node$2.quasi = this.parseTemplate({isTagged: true});
|
2157 | base = this.finishNode(node$2, "TaggedTemplateExpression");
|
2158 | }
|
2159 | return base
|
2160 | };
|
2161 |
|
2162 |
|
2163 |
|
2164 |
|
2165 |
|
2166 |
|
2167 | pp$3.parseExprAtom = function(refDestructuringErrors) {
|
2168 |
|
2169 |
|
2170 | if (this.type === types.slash) { this.readRegexp(); }
|
2171 |
|
2172 | var node, canBeArrow = this.potentialArrowAt === this.start;
|
2173 | switch (this.type) {
|
2174 | case types._super:
|
2175 | if (!this.allowSuper)
|
2176 | { this.raise(this.start, "'super' keyword outside a method"); }
|
2177 | node = this.startNode();
|
2178 | this.next();
|
2179 | if (this.type === types.parenL && !this.allowDirectSuper)
|
2180 | { this.raise(node.start, "super() call outside constructor of a subclass"); }
|
2181 |
|
2182 |
|
2183 |
|
2184 |
|
2185 |
|
2186 |
|
2187 | if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
|
2188 | { this.unexpected(); }
|
2189 | return this.finishNode(node, "Super")
|
2190 |
|
2191 | case types._this:
|
2192 | node = this.startNode();
|
2193 | this.next();
|
2194 | return this.finishNode(node, "ThisExpression")
|
2195 |
|
2196 | case types.name:
|
2197 | var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
|
2198 | var id = this.parseIdent(false);
|
2199 | if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
|
2200 | { return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true) }
|
2201 | if (canBeArrow && !this.canInsertSemicolon()) {
|
2202 | if (this.eat(types.arrow))
|
2203 | { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
|
2204 | if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
|
2205 | id = this.parseIdent(false);
|
2206 | if (this.canInsertSemicolon() || !this.eat(types.arrow))
|
2207 | { this.unexpected(); }
|
2208 | return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
|
2209 | }
|
2210 | }
|
2211 | return id
|
2212 |
|
2213 | case types.regexp:
|
2214 | var value = this.value;
|
2215 | node = this.parseLiteral(value.value);
|
2216 | node.regex = {pattern: value.pattern, flags: value.flags};
|
2217 | return node
|
2218 |
|
2219 | case types.num: case types.string:
|
2220 | return this.parseLiteral(this.value)
|
2221 |
|
2222 | case types._null: case types._true: case types._false:
|
2223 | node = this.startNode();
|
2224 | node.value = this.type === types._null ? null : this.type === types._true;
|
2225 | node.raw = this.type.keyword;
|
2226 | this.next();
|
2227 | return this.finishNode(node, "Literal")
|
2228 |
|
2229 | case types.parenL:
|
2230 | var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
|
2231 | if (refDestructuringErrors) {
|
2232 | if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
|
2233 | { refDestructuringErrors.parenthesizedAssign = start; }
|
2234 | if (refDestructuringErrors.parenthesizedBind < 0)
|
2235 | { refDestructuringErrors.parenthesizedBind = start; }
|
2236 | }
|
2237 | return expr
|
2238 |
|
2239 | case types.bracketL:
|
2240 | node = this.startNode();
|
2241 | this.next();
|
2242 | node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
|
2243 | return this.finishNode(node, "ArrayExpression")
|
2244 |
|
2245 | case types.braceL:
|
2246 | return this.parseObj(false, refDestructuringErrors)
|
2247 |
|
2248 | case types._function:
|
2249 | node = this.startNode();
|
2250 | this.next();
|
2251 | return this.parseFunction(node, 0)
|
2252 |
|
2253 | case types._class:
|
2254 | return this.parseClass(this.startNode(), false)
|
2255 |
|
2256 | case types._new:
|
2257 | return this.parseNew()
|
2258 |
|
2259 | case types.backQuote:
|
2260 | return this.parseTemplate()
|
2261 |
|
2262 | case types._import:
|
2263 | if (this.options.ecmaVersion > 10) {
|
2264 | return this.parseDynamicImport()
|
2265 | } else {
|
2266 | return this.unexpected()
|
2267 | }
|
2268 |
|
2269 | default:
|
2270 | this.unexpected();
|
2271 | }
|
2272 | };
|
2273 |
|
2274 | pp$3.parseDynamicImport = function() {
|
2275 | var node = this.startNode();
|
2276 | this.next();
|
2277 | if (this.type !== types.parenL) {
|
2278 | this.unexpected();
|
2279 | }
|
2280 | return this.finishNode(node, "Import")
|
2281 | };
|
2282 |
|
2283 | pp$3.parseLiteral = function(value) {
|
2284 | var node = this.startNode();
|
2285 | node.value = value;
|
2286 | node.raw = this.input.slice(this.start, this.end);
|
2287 | if (node.raw.charCodeAt(node.raw.length - 1) === 110) { node.bigint = node.raw.slice(0, -1); }
|
2288 | this.next();
|
2289 | return this.finishNode(node, "Literal")
|
2290 | };
|
2291 |
|
2292 | pp$3.parseParenExpression = function() {
|
2293 | this.expect(types.parenL);
|
2294 | var val = this.parseExpression();
|
2295 | this.expect(types.parenR);
|
2296 | return val
|
2297 | };
|
2298 |
|
2299 | pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
|
2300 | var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
|
2301 | if (this.options.ecmaVersion >= 6) {
|
2302 | this.next();
|
2303 |
|
2304 | var innerStartPos = this.start, innerStartLoc = this.startLoc;
|
2305 | var exprList = [], first = true, lastIsComma = false;
|
2306 | var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
|
2307 | this.yieldPos = 0;
|
2308 | this.awaitPos = 0;
|
2309 |
|
2310 | while (this.type !== types.parenR) {
|
2311 | first ? first = false : this.expect(types.comma);
|
2312 | if (allowTrailingComma && this.afterTrailingComma(types.parenR, true)) {
|
2313 | lastIsComma = true;
|
2314 | break
|
2315 | } else if (this.type === types.ellipsis) {
|
2316 | spreadStart = this.start;
|
2317 | exprList.push(this.parseParenItem(this.parseRestBinding()));
|
2318 | if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
|
2319 | break
|
2320 | } else {
|
2321 | exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
|
2322 | }
|
2323 | }
|
2324 | var innerEndPos = this.start, innerEndLoc = this.startLoc;
|
2325 | this.expect(types.parenR);
|
2326 |
|
2327 | if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
|
2328 | this.checkPatternErrors(refDestructuringErrors, false);
|
2329 | this.checkYieldAwaitInDefaultParams();
|
2330 | this.yieldPos = oldYieldPos;
|
2331 | this.awaitPos = oldAwaitPos;
|
2332 | return this.parseParenArrowList(startPos, startLoc, exprList)
|
2333 | }
|
2334 |
|
2335 | if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
|
2336 | if (spreadStart) { this.unexpected(spreadStart); }
|
2337 | this.checkExpressionErrors(refDestructuringErrors, true);
|
2338 | this.yieldPos = oldYieldPos || this.yieldPos;
|
2339 | this.awaitPos = oldAwaitPos || this.awaitPos;
|
2340 |
|
2341 | if (exprList.length > 1) {
|
2342 | val = this.startNodeAt(innerStartPos, innerStartLoc);
|
2343 | val.expressions = exprList;
|
2344 | this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
|
2345 | } else {
|
2346 | val = exprList[0];
|
2347 | }
|
2348 | } else {
|
2349 | val = this.parseParenExpression();
|
2350 | }
|
2351 |
|
2352 | if (this.options.preserveParens) {
|
2353 | var par = this.startNodeAt(startPos, startLoc);
|
2354 | par.expression = val;
|
2355 | return this.finishNode(par, "ParenthesizedExpression")
|
2356 | } else {
|
2357 | return val
|
2358 | }
|
2359 | };
|
2360 |
|
2361 | pp$3.parseParenItem = function(item) {
|
2362 | return item
|
2363 | };
|
2364 |
|
2365 | pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
|
2366 | return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
|
2367 | };
|
2368 |
|
2369 |
|
2370 |
|
2371 |
|
2372 |
|
2373 |
|
2374 |
|
2375 | var empty$1 = [];
|
2376 |
|
2377 | pp$3.parseNew = function() {
|
2378 | var node = this.startNode();
|
2379 | var meta = this.parseIdent(true);
|
2380 | if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
|
2381 | node.meta = meta;
|
2382 | var containsEsc = this.containsEsc;
|
2383 | node.property = this.parseIdent(true);
|
2384 | if (node.property.name !== "target" || containsEsc)
|
2385 | { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
|
2386 | if (!this.inNonArrowFunction())
|
2387 | { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
|
2388 | return this.finishNode(node, "MetaProperty")
|
2389 | }
|
2390 | var startPos = this.start, startLoc = this.startLoc;
|
2391 | node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
|
2392 | if (this.options.ecmaVersion > 10 && node.callee.type === "Import") {
|
2393 | this.raise(node.callee.start, "Cannot use new with import(...)");
|
2394 | }
|
2395 | if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8 && node.callee.type !== "Import", false); }
|
2396 | else { node.arguments = empty$1; }
|
2397 | return this.finishNode(node, "NewExpression")
|
2398 | };
|
2399 |
|
2400 |
|
2401 |
|
2402 | pp$3.parseTemplateElement = function(ref) {
|
2403 | var isTagged = ref.isTagged;
|
2404 |
|
2405 | var elem = this.startNode();
|
2406 | if (this.type === types.invalidTemplate) {
|
2407 | if (!isTagged) {
|
2408 | this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
|
2409 | }
|
2410 | elem.value = {
|
2411 | raw: this.value,
|
2412 | cooked: null
|
2413 | };
|
2414 | } else {
|
2415 | elem.value = {
|
2416 | raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
|
2417 | cooked: this.value
|
2418 | };
|
2419 | }
|
2420 | this.next();
|
2421 | elem.tail = this.type === types.backQuote;
|
2422 | return this.finishNode(elem, "TemplateElement")
|
2423 | };
|
2424 |
|
2425 | pp$3.parseTemplate = function(ref) {
|
2426 | if ( ref === void 0 ) ref = {};
|
2427 | var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
|
2428 |
|
2429 | var node = this.startNode();
|
2430 | this.next();
|
2431 | node.expressions = [];
|
2432 | var curElt = this.parseTemplateElement({isTagged: isTagged});
|
2433 | node.quasis = [curElt];
|
2434 | while (!curElt.tail) {
|
2435 | if (this.type === types.eof) { this.raise(this.pos, "Unterminated template literal"); }
|
2436 | this.expect(types.dollarBraceL);
|
2437 | node.expressions.push(this.parseExpression());
|
2438 | this.expect(types.braceR);
|
2439 | node.quasis.push(curElt = this.parseTemplateElement({isTagged: isTagged}));
|
2440 | }
|
2441 | this.next();
|
2442 | return this.finishNode(node, "TemplateLiteral")
|
2443 | };
|
2444 |
|
2445 | pp$3.isAsyncProp = function(prop) {
|
2446 | return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
|
2447 | (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types.star)) &&
|
2448 | !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
|
2449 | };
|
2450 |
|
2451 |
|
2452 |
|
2453 | pp$3.parseObj = function(isPattern, refDestructuringErrors) {
|
2454 | var node = this.startNode(), first = true, propHash = {};
|
2455 | node.properties = [];
|
2456 | this.next();
|
2457 | while (!this.eat(types.braceR)) {
|
2458 | if (!first) {
|
2459 | this.expect(types.comma);
|
2460 | if (this.afterTrailingComma(types.braceR)) { break }
|
2461 | } else { first = false; }
|
2462 |
|
2463 | var prop = this.parseProperty(isPattern, refDestructuringErrors);
|
2464 | if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
|
2465 | node.properties.push(prop);
|
2466 | }
|
2467 | return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
|
2468 | };
|
2469 |
|
2470 | pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
|
2471 | var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
|
2472 | if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
|
2473 | if (isPattern) {
|
2474 | prop.argument = this.parseIdent(false);
|
2475 | if (this.type === types.comma) {
|
2476 | this.raise(this.start, "Comma is not permitted after the rest element");
|
2477 | }
|
2478 | return this.finishNode(prop, "RestElement")
|
2479 | }
|
2480 |
|
2481 | if (this.type === types.parenL && refDestructuringErrors) {
|
2482 | if (refDestructuringErrors.parenthesizedAssign < 0) {
|
2483 | refDestructuringErrors.parenthesizedAssign = this.start;
|
2484 | }
|
2485 | if (refDestructuringErrors.parenthesizedBind < 0) {
|
2486 | refDestructuringErrors.parenthesizedBind = this.start;
|
2487 | }
|
2488 | }
|
2489 |
|
2490 | prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
|
2491 |
|
2492 | if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
|
2493 | refDestructuringErrors.trailingComma = this.start;
|
2494 | }
|
2495 |
|
2496 | return this.finishNode(prop, "SpreadElement")
|
2497 | }
|
2498 | if (this.options.ecmaVersion >= 6) {
|
2499 | prop.method = false;
|
2500 | prop.shorthand = false;
|
2501 | if (isPattern || refDestructuringErrors) {
|
2502 | startPos = this.start;
|
2503 | startLoc = this.startLoc;
|
2504 | }
|
2505 | if (!isPattern)
|
2506 | { isGenerator = this.eat(types.star); }
|
2507 | }
|
2508 | var containsEsc = this.containsEsc;
|
2509 | this.parsePropertyName(prop);
|
2510 | if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
|
2511 | isAsync = true;
|
2512 | isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
|
2513 | this.parsePropertyName(prop, refDestructuringErrors);
|
2514 | } else {
|
2515 | isAsync = false;
|
2516 | }
|
2517 | this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
|
2518 | return this.finishNode(prop, "Property")
|
2519 | };
|
2520 |
|
2521 | pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
|
2522 | if ((isGenerator || isAsync) && this.type === types.colon)
|
2523 | { this.unexpected(); }
|
2524 |
|
2525 | if (this.eat(types.colon)) {
|
2526 | prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
|
2527 | prop.kind = "init";
|
2528 | } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
|
2529 | if (isPattern) { this.unexpected(); }
|
2530 | prop.kind = "init";
|
2531 | prop.method = true;
|
2532 | prop.value = this.parseMethod(isGenerator, isAsync);
|
2533 | } else if (!isPattern && !containsEsc &&
|
2534 | this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
|
2535 | (prop.key.name === "get" || prop.key.name === "set") &&
|
2536 | (this.type !== types.comma && this.type !== types.braceR)) {
|
2537 | if (isGenerator || isAsync) { this.unexpected(); }
|
2538 | prop.kind = prop.key.name;
|
2539 | this.parsePropertyName(prop);
|
2540 | prop.value = this.parseMethod(false);
|
2541 | var paramCount = prop.kind === "get" ? 0 : 1;
|
2542 | if (prop.value.params.length !== paramCount) {
|
2543 | var start = prop.value.start;
|
2544 | if (prop.kind === "get")
|
2545 | { this.raiseRecoverable(start, "getter should have no params"); }
|
2546 | else
|
2547 | { this.raiseRecoverable(start, "setter should have exactly one param"); }
|
2548 | } else {
|
2549 | if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
|
2550 | { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
|
2551 | }
|
2552 | } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
|
2553 | if (isGenerator || isAsync) { this.unexpected(); }
|
2554 | this.checkUnreserved(prop.key);
|
2555 | if (prop.key.name === "await" && !this.awaitIdentPos)
|
2556 | { this.awaitIdentPos = startPos; }
|
2557 | prop.kind = "init";
|
2558 | if (isPattern) {
|
2559 | prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
|
2560 | } else if (this.type === types.eq && refDestructuringErrors) {
|
2561 | if (refDestructuringErrors.shorthandAssign < 0)
|
2562 | { refDestructuringErrors.shorthandAssign = this.start; }
|
2563 | prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
|
2564 | } else {
|
2565 | prop.value = prop.key;
|
2566 | }
|
2567 | prop.shorthand = true;
|
2568 | } else { this.unexpected(); }
|
2569 | };
|
2570 |
|
2571 | pp$3.parsePropertyName = function(prop) {
|
2572 | if (this.options.ecmaVersion >= 6) {
|
2573 | if (this.eat(types.bracketL)) {
|
2574 | prop.computed = true;
|
2575 | prop.key = this.parseMaybeAssign();
|
2576 | this.expect(types.bracketR);
|
2577 | return prop.key
|
2578 | } else {
|
2579 | prop.computed = false;
|
2580 | }
|
2581 | }
|
2582 | return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
|
2583 | };
|
2584 |
|
2585 |
|
2586 |
|
2587 | pp$3.initFunction = function(node) {
|
2588 | node.id = null;
|
2589 | if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
|
2590 | if (this.options.ecmaVersion >= 8) { node.async = false; }
|
2591 | };
|
2592 |
|
2593 |
|
2594 |
|
2595 | pp$3.parseMethod = function(isGenerator, isAsync, allowDirectSuper) {
|
2596 | var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
|
2597 |
|
2598 | this.initFunction(node);
|
2599 | if (this.options.ecmaVersion >= 6)
|
2600 | { node.generator = isGenerator; }
|
2601 | if (this.options.ecmaVersion >= 8)
|
2602 | { node.async = !!isAsync; }
|
2603 |
|
2604 | this.yieldPos = 0;
|
2605 | this.awaitPos = 0;
|
2606 | this.awaitIdentPos = 0;
|
2607 | this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
|
2608 |
|
2609 | this.expect(types.parenL);
|
2610 | node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
|
2611 | this.checkYieldAwaitInDefaultParams();
|
2612 | this.parseFunctionBody(node, false, true);
|
2613 |
|
2614 | this.yieldPos = oldYieldPos;
|
2615 | this.awaitPos = oldAwaitPos;
|
2616 | this.awaitIdentPos = oldAwaitIdentPos;
|
2617 | return this.finishNode(node, "FunctionExpression")
|
2618 | };
|
2619 |
|
2620 |
|
2621 |
|
2622 | pp$3.parseArrowExpression = function(node, params, isAsync) {
|
2623 | var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
|
2624 |
|
2625 | this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
|
2626 | this.initFunction(node);
|
2627 | if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
|
2628 |
|
2629 | this.yieldPos = 0;
|
2630 | this.awaitPos = 0;
|
2631 | this.awaitIdentPos = 0;
|
2632 |
|
2633 | node.params = this.toAssignableList(params, true);
|
2634 | this.parseFunctionBody(node, true, false);
|
2635 |
|
2636 | this.yieldPos = oldYieldPos;
|
2637 | this.awaitPos = oldAwaitPos;
|
2638 | this.awaitIdentPos = oldAwaitIdentPos;
|
2639 | return this.finishNode(node, "ArrowFunctionExpression")
|
2640 | };
|
2641 |
|
2642 |
|
2643 |
|
2644 | pp$3.parseFunctionBody = function(node, isArrowFunction, isMethod) {
|
2645 | var isExpression = isArrowFunction && this.type !== types.braceL;
|
2646 | var oldStrict = this.strict, useStrict = false;
|
2647 |
|
2648 | if (isExpression) {
|
2649 | node.body = this.parseMaybeAssign();
|
2650 | node.expression = true;
|
2651 | this.checkParams(node, false);
|
2652 | } else {
|
2653 | var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
|
2654 | if (!oldStrict || nonSimple) {
|
2655 | useStrict = this.strictDirective(this.end);
|
2656 |
|
2657 |
|
2658 |
|
2659 | if (useStrict && nonSimple)
|
2660 | { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
|
2661 | }
|
2662 |
|
2663 |
|
2664 | var oldLabels = this.labels;
|
2665 | this.labels = [];
|
2666 | if (useStrict) { this.strict = true; }
|
2667 |
|
2668 |
|
2669 |
|
2670 | this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params));
|
2671 | node.body = this.parseBlock(false);
|
2672 | node.expression = false;
|
2673 | this.adaptDirectivePrologue(node.body.body);
|
2674 | this.labels = oldLabels;
|
2675 | }
|
2676 | this.exitScope();
|
2677 |
|
2678 |
|
2679 | if (this.strict && node.id) { this.checkLVal(node.id, BIND_OUTSIDE); }
|
2680 | this.strict = oldStrict;
|
2681 | };
|
2682 |
|
2683 | pp$3.isSimpleParamList = function(params) {
|
2684 | for (var i = 0, list = params; i < list.length; i += 1)
|
2685 | {
|
2686 | var param = list[i];
|
2687 |
|
2688 | if (param.type !== "Identifier") { return false
|
2689 | } }
|
2690 | return true
|
2691 | };
|
2692 |
|
2693 |
|
2694 |
|
2695 |
|
2696 | pp$3.checkParams = function(node, allowDuplicates) {
|
2697 | var nameHash = {};
|
2698 | for (var i = 0, list = node.params; i < list.length; i += 1)
|
2699 | {
|
2700 | var param = list[i];
|
2701 |
|
2702 | this.checkLVal(param, BIND_VAR, allowDuplicates ? null : nameHash);
|
2703 | }
|
2704 | };
|
2705 |
|
2706 |
|
2707 |
|
2708 |
|
2709 |
|
2710 |
|
2711 |
|
2712 | pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
|
2713 | var elts = [], first = true;
|
2714 | while (!this.eat(close)) {
|
2715 | if (!first) {
|
2716 | this.expect(types.comma);
|
2717 | if (allowTrailingComma && this.afterTrailingComma(close)) { break }
|
2718 | } else { first = false; }
|
2719 |
|
2720 | var elt = (void 0);
|
2721 | if (allowEmpty && this.type === types.comma)
|
2722 | { elt = null; }
|
2723 | else if (this.type === types.ellipsis) {
|
2724 | elt = this.parseSpread(refDestructuringErrors);
|
2725 | if (refDestructuringErrors && this.type === types.comma && refDestructuringErrors.trailingComma < 0)
|
2726 | { refDestructuringErrors.trailingComma = this.start; }
|
2727 | } else {
|
2728 | elt = this.parseMaybeAssign(false, refDestructuringErrors);
|
2729 | }
|
2730 | elts.push(elt);
|
2731 | }
|
2732 | return elts
|
2733 | };
|
2734 |
|
2735 | pp$3.checkUnreserved = function(ref) {
|
2736 | var start = ref.start;
|
2737 | var end = ref.end;
|
2738 | var name = ref.name;
|
2739 |
|
2740 | if (this.inGenerator && name === "yield")
|
2741 | { this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); }
|
2742 | if (this.inAsync && name === "await")
|
2743 | { this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); }
|
2744 | if (this.keywords.test(name))
|
2745 | { this.raise(start, ("Unexpected keyword '" + name + "'")); }
|
2746 | if (this.options.ecmaVersion < 6 &&
|
2747 | this.input.slice(start, end).indexOf("\\") !== -1) { return }
|
2748 | var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
|
2749 | if (re.test(name)) {
|
2750 | if (!this.inAsync && name === "await")
|
2751 | { this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); }
|
2752 | this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
|
2753 | }
|
2754 | };
|
2755 |
|
2756 |
|
2757 |
|
2758 |
|
2759 |
|
2760 | pp$3.parseIdent = function(liberal, isBinding) {
|
2761 | var node = this.startNode();
|
2762 | if (this.type === types.name) {
|
2763 | node.name = this.value;
|
2764 | } else if (this.type.keyword) {
|
2765 | node.name = this.type.keyword;
|
2766 |
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 | if ((node.name === "class" || node.name === "function") &&
|
2772 | (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
|
2773 | this.context.pop();
|
2774 | }
|
2775 | } else {
|
2776 | this.unexpected();
|
2777 | }
|
2778 | this.next();
|
2779 | this.finishNode(node, "Identifier");
|
2780 | if (!liberal) {
|
2781 | this.checkUnreserved(node);
|
2782 | if (node.name === "await" && !this.awaitIdentPos)
|
2783 | { this.awaitIdentPos = node.start; }
|
2784 | }
|
2785 | return node
|
2786 | };
|
2787 |
|
2788 |
|
2789 |
|
2790 | pp$3.parseYield = function(noIn) {
|
2791 | if (!this.yieldPos) { this.yieldPos = this.start; }
|
2792 |
|
2793 | var node = this.startNode();
|
2794 | this.next();
|
2795 | if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) {
|
2796 | node.delegate = false;
|
2797 | node.argument = null;
|
2798 | } else {
|
2799 | node.delegate = this.eat(types.star);
|
2800 | node.argument = this.parseMaybeAssign(noIn);
|
2801 | }
|
2802 | return this.finishNode(node, "YieldExpression")
|
2803 | };
|
2804 |
|
2805 | pp$3.parseAwait = function() {
|
2806 | if (!this.awaitPos) { this.awaitPos = this.start; }
|
2807 |
|
2808 | var node = this.startNode();
|
2809 | this.next();
|
2810 | node.argument = this.parseMaybeUnary(null, true);
|
2811 | return this.finishNode(node, "AwaitExpression")
|
2812 | };
|
2813 |
|
2814 | var pp$4 = Parser.prototype;
|
2815 |
|
2816 |
|
2817 |
|
2818 |
|
2819 |
|
2820 |
|
2821 |
|
2822 | pp$4.raise = function(pos, message) {
|
2823 | var loc = getLineInfo(this.input, pos);
|
2824 | message += " (" + loc.line + ":" + loc.column + ")";
|
2825 | var err = new SyntaxError(message);
|
2826 | err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
|
2827 | throw err
|
2828 | };
|
2829 |
|
2830 | pp$4.raiseRecoverable = pp$4.raise;
|
2831 |
|
2832 | pp$4.curPosition = function() {
|
2833 | if (this.options.locations) {
|
2834 | return new Position(this.curLine, this.pos - this.lineStart)
|
2835 | }
|
2836 | };
|
2837 |
|
2838 | var pp$5 = Parser.prototype;
|
2839 |
|
2840 | var Scope = function Scope(flags) {
|
2841 | this.flags = flags;
|
2842 |
|
2843 | this.var = [];
|
2844 |
|
2845 | this.lexical = [];
|
2846 |
|
2847 | this.functions = [];
|
2848 | };
|
2849 |
|
2850 |
|
2851 |
|
2852 | pp$5.enterScope = function(flags) {
|
2853 | this.scopeStack.push(new Scope(flags));
|
2854 | };
|
2855 |
|
2856 | pp$5.exitScope = function() {
|
2857 | this.scopeStack.pop();
|
2858 | };
|
2859 |
|
2860 |
|
2861 |
|
2862 |
|
2863 | pp$5.treatFunctionsAsVarInScope = function(scope) {
|
2864 | return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
|
2865 | };
|
2866 |
|
2867 | pp$5.declareName = function(name, bindingType, pos) {
|
2868 | var redeclared = false;
|
2869 | if (bindingType === BIND_LEXICAL) {
|
2870 | var scope = this.currentScope();
|
2871 | redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
|
2872 | scope.lexical.push(name);
|
2873 | if (this.inModule && (scope.flags & SCOPE_TOP))
|
2874 | { delete this.undefinedExports[name]; }
|
2875 | } else if (bindingType === BIND_SIMPLE_CATCH) {
|
2876 | var scope$1 = this.currentScope();
|
2877 | scope$1.lexical.push(name);
|
2878 | } else if (bindingType === BIND_FUNCTION) {
|
2879 | var scope$2 = this.currentScope();
|
2880 | if (this.treatFunctionsAsVar)
|
2881 | { redeclared = scope$2.lexical.indexOf(name) > -1; }
|
2882 | else
|
2883 | { redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
|
2884 | scope$2.functions.push(name);
|
2885 | } else {
|
2886 | for (var i = this.scopeStack.length - 1; i >= 0; --i) {
|
2887 | var scope$3 = this.scopeStack[i];
|
2888 | if (scope$3.lexical.indexOf(name) > -1 && !((scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) ||
|
2889 | !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
|
2890 | redeclared = true;
|
2891 | break
|
2892 | }
|
2893 | scope$3.var.push(name);
|
2894 | if (this.inModule && (scope$3.flags & SCOPE_TOP))
|
2895 | { delete this.undefinedExports[name]; }
|
2896 | if (scope$3.flags & SCOPE_VAR) { break }
|
2897 | }
|
2898 | }
|
2899 | if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); }
|
2900 | };
|
2901 |
|
2902 | pp$5.checkLocalExport = function(id) {
|
2903 |
|
2904 | if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
|
2905 | this.scopeStack[0].var.indexOf(id.name) === -1) {
|
2906 | this.undefinedExports[id.name] = id;
|
2907 | }
|
2908 | };
|
2909 |
|
2910 | pp$5.currentScope = function() {
|
2911 | return this.scopeStack[this.scopeStack.length - 1]
|
2912 | };
|
2913 |
|
2914 | pp$5.currentVarScope = function() {
|
2915 | for (var i = this.scopeStack.length - 1;; i--) {
|
2916 | var scope = this.scopeStack[i];
|
2917 | if (scope.flags & SCOPE_VAR) { return scope }
|
2918 | }
|
2919 | };
|
2920 |
|
2921 |
|
2922 | pp$5.currentThisScope = function() {
|
2923 | for (var i = this.scopeStack.length - 1;; i--) {
|
2924 | var scope = this.scopeStack[i];
|
2925 | if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope }
|
2926 | }
|
2927 | };
|
2928 |
|
2929 | var Node = function Node(parser, pos, loc) {
|
2930 | this.type = "";
|
2931 | this.start = pos;
|
2932 | this.end = 0;
|
2933 | if (parser.options.locations)
|
2934 | { this.loc = new SourceLocation(parser, loc); }
|
2935 | if (parser.options.directSourceFile)
|
2936 | { this.sourceFile = parser.options.directSourceFile; }
|
2937 | if (parser.options.ranges)
|
2938 | { this.range = [pos, 0]; }
|
2939 | };
|
2940 |
|
2941 |
|
2942 |
|
2943 | var pp$6 = Parser.prototype;
|
2944 |
|
2945 | pp$6.startNode = function() {
|
2946 | return new Node(this, this.start, this.startLoc)
|
2947 | };
|
2948 |
|
2949 | pp$6.startNodeAt = function(pos, loc) {
|
2950 | return new Node(this, pos, loc)
|
2951 | };
|
2952 |
|
2953 |
|
2954 |
|
2955 | function finishNodeAt(node, type, pos, loc) {
|
2956 | node.type = type;
|
2957 | node.end = pos;
|
2958 | if (this.options.locations)
|
2959 | { node.loc.end = loc; }
|
2960 | if (this.options.ranges)
|
2961 | { node.range[1] = pos; }
|
2962 | return node
|
2963 | }
|
2964 |
|
2965 | pp$6.finishNode = function(node, type) {
|
2966 | return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
|
2967 | };
|
2968 |
|
2969 |
|
2970 |
|
2971 | pp$6.finishNodeAt = function(node, type, pos, loc) {
|
2972 | return finishNodeAt.call(this, node, type, pos, loc)
|
2973 | };
|
2974 |
|
2975 |
|
2976 |
|
2977 | var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
|
2978 | this.token = token;
|
2979 | this.isExpr = !!isExpr;
|
2980 | this.preserveSpace = !!preserveSpace;
|
2981 | this.override = override;
|
2982 | this.generator = !!generator;
|
2983 | };
|
2984 |
|
2985 | var types$1 = {
|
2986 | b_stat: new TokContext("{", false),
|
2987 | b_expr: new TokContext("{", true),
|
2988 | b_tmpl: new TokContext("${", false),
|
2989 | p_stat: new TokContext("(", false),
|
2990 | p_expr: new TokContext("(", true),
|
2991 | q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
|
2992 | f_stat: new TokContext("function", false),
|
2993 | f_expr: new TokContext("function", true),
|
2994 | f_expr_gen: new TokContext("function", true, false, null, true),
|
2995 | f_gen: new TokContext("function", false, false, null, true)
|
2996 | };
|
2997 |
|
2998 | var pp$7 = Parser.prototype;
|
2999 |
|
3000 | pp$7.initialContext = function() {
|
3001 | return [types$1.b_stat]
|
3002 | };
|
3003 |
|
3004 | pp$7.braceIsBlock = function(prevType) {
|
3005 | var parent = this.curContext();
|
3006 | if (parent === types$1.f_expr || parent === types$1.f_stat)
|
3007 | { return true }
|
3008 | if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
|
3009 | { return !parent.isExpr }
|
3010 |
|
3011 |
|
3012 |
|
3013 |
|
3014 | if (prevType === types._return || prevType === types.name && this.exprAllowed)
|
3015 | { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
|
3016 | if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow)
|
3017 | { return true }
|
3018 | if (prevType === types.braceL)
|
3019 | { return parent === types$1.b_stat }
|
3020 | if (prevType === types._var || prevType === types._const || prevType === types.name)
|
3021 | { return false }
|
3022 | return !this.exprAllowed
|
3023 | };
|
3024 |
|
3025 | pp$7.inGeneratorContext = function() {
|
3026 | for (var i = this.context.length - 1; i >= 1; i--) {
|
3027 | var context = this.context[i];
|
3028 | if (context.token === "function")
|
3029 | { return context.generator }
|
3030 | }
|
3031 | return false
|
3032 | };
|
3033 |
|
3034 | pp$7.updateContext = function(prevType) {
|
3035 | var update, type = this.type;
|
3036 | if (type.keyword && prevType === types.dot)
|
3037 | { this.exprAllowed = false; }
|
3038 | else if (update = type.updateContext)
|
3039 | { update.call(this, prevType); }
|
3040 | else
|
3041 | { this.exprAllowed = type.beforeExpr; }
|
3042 | };
|
3043 |
|
3044 |
|
3045 |
|
3046 | types.parenR.updateContext = types.braceR.updateContext = function() {
|
3047 | if (this.context.length === 1) {
|
3048 | this.exprAllowed = true;
|
3049 | return
|
3050 | }
|
3051 | var out = this.context.pop();
|
3052 | if (out === types$1.b_stat && this.curContext().token === "function") {
|
3053 | out = this.context.pop();
|
3054 | }
|
3055 | this.exprAllowed = !out.isExpr;
|
3056 | };
|
3057 |
|
3058 | types.braceL.updateContext = function(prevType) {
|
3059 | this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
|
3060 | this.exprAllowed = true;
|
3061 | };
|
3062 |
|
3063 | types.dollarBraceL.updateContext = function() {
|
3064 | this.context.push(types$1.b_tmpl);
|
3065 | this.exprAllowed = true;
|
3066 | };
|
3067 |
|
3068 | types.parenL.updateContext = function(prevType) {
|
3069 | var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
|
3070 | this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
|
3071 | this.exprAllowed = true;
|
3072 | };
|
3073 |
|
3074 | types.incDec.updateContext = function() {
|
3075 |
|
3076 | };
|
3077 |
|
3078 | types._function.updateContext = types._class.updateContext = function(prevType) {
|
3079 | if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
|
3080 | !(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
|
3081 | !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
|
3082 | { this.context.push(types$1.f_expr); }
|
3083 | else
|
3084 | { this.context.push(types$1.f_stat); }
|
3085 | this.exprAllowed = false;
|
3086 | };
|
3087 |
|
3088 | types.backQuote.updateContext = function() {
|
3089 | if (this.curContext() === types$1.q_tmpl)
|
3090 | { this.context.pop(); }
|
3091 | else
|
3092 | { this.context.push(types$1.q_tmpl); }
|
3093 | this.exprAllowed = false;
|
3094 | };
|
3095 |
|
3096 | types.star.updateContext = function(prevType) {
|
3097 | if (prevType === types._function) {
|
3098 | var index = this.context.length - 1;
|
3099 | if (this.context[index] === types$1.f_expr)
|
3100 | { this.context[index] = types$1.f_expr_gen; }
|
3101 | else
|
3102 | { this.context[index] = types$1.f_gen; }
|
3103 | }
|
3104 | this.exprAllowed = true;
|
3105 | };
|
3106 |
|
3107 | types.name.updateContext = function(prevType) {
|
3108 | var allowed = false;
|
3109 | if (this.options.ecmaVersion >= 6 && prevType !== types.dot) {
|
3110 | if (this.value === "of" && !this.exprAllowed ||
|
3111 | this.value === "yield" && this.inGeneratorContext())
|
3112 | { allowed = true; }
|
3113 | }
|
3114 | this.exprAllowed = allowed;
|
3115 | };
|
3116 |
|
3117 |
|
3118 |
|
3119 |
|
3120 |
|
3121 |
|
3122 | var ecma9BinaryProperties = "ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS";
|
3123 | var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
|
3124 | var ecma11BinaryProperties = ecma10BinaryProperties;
|
3125 | var unicodeBinaryProperties = {
|
3126 | 9: ecma9BinaryProperties,
|
3127 | 10: ecma10BinaryProperties,
|
3128 | 11: ecma11BinaryProperties
|
3129 | };
|
3130 |
|
3131 |
|
3132 | var unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu";
|
3133 |
|
3134 |
|
3135 | var ecma9ScriptValues = "Adlam Adlm Ahom Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb";
|
3136 | var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd";
|
3137 | var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
|
3138 | var unicodeScriptValues = {
|
3139 | 9: ecma9ScriptValues,
|
3140 | 10: ecma10ScriptValues,
|
3141 | 11: ecma11ScriptValues
|
3142 | };
|
3143 |
|
3144 | var data = {};
|
3145 | function buildUnicodeData(ecmaVersion) {
|
3146 | var d = data[ecmaVersion] = {
|
3147 | binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues),
|
3148 | nonBinary: {
|
3149 | General_Category: wordsRegexp(unicodeGeneralCategoryValues),
|
3150 | Script: wordsRegexp(unicodeScriptValues[ecmaVersion])
|
3151 | }
|
3152 | };
|
3153 | d.nonBinary.Script_Extensions = d.nonBinary.Script;
|
3154 |
|
3155 | d.nonBinary.gc = d.nonBinary.General_Category;
|
3156 | d.nonBinary.sc = d.nonBinary.Script;
|
3157 | d.nonBinary.scx = d.nonBinary.Script_Extensions;
|
3158 | }
|
3159 | buildUnicodeData(9);
|
3160 | buildUnicodeData(10);
|
3161 | buildUnicodeData(11);
|
3162 |
|
3163 | var pp$8 = Parser.prototype;
|
3164 |
|
3165 | var RegExpValidationState = function RegExpValidationState(parser) {
|
3166 | this.parser = parser;
|
3167 | this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
|
3168 | this.unicodeProperties = data[parser.options.ecmaVersion >= 11 ? 11 : parser.options.ecmaVersion];
|
3169 | this.source = "";
|
3170 | this.flags = "";
|
3171 | this.start = 0;
|
3172 | this.switchU = false;
|
3173 | this.switchN = false;
|
3174 | this.pos = 0;
|
3175 | this.lastIntValue = 0;
|
3176 | this.lastStringValue = "";
|
3177 | this.lastAssertionIsQuantifiable = false;
|
3178 | this.numCapturingParens = 0;
|
3179 | this.maxBackReference = 0;
|
3180 | this.groupNames = [];
|
3181 | this.backReferenceNames = [];
|
3182 | };
|
3183 |
|
3184 | RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
|
3185 | var unicode = flags.indexOf("u") !== -1;
|
3186 | this.start = start | 0;
|
3187 | this.source = pattern + "";
|
3188 | this.flags = flags;
|
3189 | this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
|
3190 | this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
|
3191 | };
|
3192 |
|
3193 | RegExpValidationState.prototype.raise = function raise (message) {
|
3194 | this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
|
3195 | };
|
3196 |
|
3197 |
|
3198 |
|
3199 | RegExpValidationState.prototype.at = function at (i) {
|
3200 | var s = this.source;
|
3201 | var l = s.length;
|
3202 | if (i >= l) {
|
3203 | return -1
|
3204 | }
|
3205 | var c = s.charCodeAt(i);
|
3206 | if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
|
3207 | return c
|
3208 | }
|
3209 | var next = s.charCodeAt(i + 1);
|
3210 | return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c
|
3211 | };
|
3212 |
|
3213 | RegExpValidationState.prototype.nextIndex = function nextIndex (i) {
|
3214 | var s = this.source;
|
3215 | var l = s.length;
|
3216 | if (i >= l) {
|
3217 | return l
|
3218 | }
|
3219 | var c = s.charCodeAt(i), next;
|
3220 | if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
|
3221 | (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
|
3222 | return i + 1
|
3223 | }
|
3224 | return i + 2
|
3225 | };
|
3226 |
|
3227 | RegExpValidationState.prototype.current = function current () {
|
3228 | return this.at(this.pos)
|
3229 | };
|
3230 |
|
3231 | RegExpValidationState.prototype.lookahead = function lookahead () {
|
3232 | return this.at(this.nextIndex(this.pos))
|
3233 | };
|
3234 |
|
3235 | RegExpValidationState.prototype.advance = function advance () {
|
3236 | this.pos = this.nextIndex(this.pos);
|
3237 | };
|
3238 |
|
3239 | RegExpValidationState.prototype.eat = function eat (ch) {
|
3240 | if (this.current() === ch) {
|
3241 | this.advance();
|
3242 | return true
|
3243 | }
|
3244 | return false
|
3245 | };
|
3246 |
|
3247 | function codePointToString(ch) {
|
3248 | if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
|
3249 | ch -= 0x10000;
|
3250 | return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
|
3251 | }
|
3252 |
|
3253 | |
3254 |
|
3255 |
|
3256 |
|
3257 |
|
3258 |
|
3259 | pp$8.validateRegExpFlags = function(state) {
|
3260 | var validFlags = state.validFlags;
|
3261 | var flags = state.flags;
|
3262 |
|
3263 | for (var i = 0; i < flags.length; i++) {
|
3264 | var flag = flags.charAt(i);
|
3265 | if (validFlags.indexOf(flag) === -1) {
|
3266 | this.raise(state.start, "Invalid regular expression flag");
|
3267 | }
|
3268 | if (flags.indexOf(flag, i + 1) > -1) {
|
3269 | this.raise(state.start, "Duplicate regular expression flag");
|
3270 | }
|
3271 | }
|
3272 | };
|
3273 |
|
3274 | |
3275 |
|
3276 |
|
3277 |
|
3278 |
|
3279 |
|
3280 | pp$8.validateRegExpPattern = function(state) {
|
3281 | this.regexp_pattern(state);
|
3282 |
|
3283 |
|
3284 |
|
3285 |
|
3286 |
|
3287 |
|
3288 | if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
|
3289 | state.switchN = true;
|
3290 | this.regexp_pattern(state);
|
3291 | }
|
3292 | };
|
3293 |
|
3294 |
|
3295 | pp$8.regexp_pattern = function(state) {
|
3296 | state.pos = 0;
|
3297 | state.lastIntValue = 0;
|
3298 | state.lastStringValue = "";
|
3299 | state.lastAssertionIsQuantifiable = false;
|
3300 | state.numCapturingParens = 0;
|
3301 | state.maxBackReference = 0;
|
3302 | state.groupNames.length = 0;
|
3303 | state.backReferenceNames.length = 0;
|
3304 |
|
3305 | this.regexp_disjunction(state);
|
3306 |
|
3307 | if (state.pos !== state.source.length) {
|
3308 |
|
3309 | if (state.eat(0x29 )) {
|
3310 | state.raise("Unmatched ')'");
|
3311 | }
|
3312 | if (state.eat(0x5D ) || state.eat(0x7D )) {
|
3313 | state.raise("Lone quantifier brackets");
|
3314 | }
|
3315 | }
|
3316 | if (state.maxBackReference > state.numCapturingParens) {
|
3317 | state.raise("Invalid escape");
|
3318 | }
|
3319 | for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
|
3320 | var name = list[i];
|
3321 |
|
3322 | if (state.groupNames.indexOf(name) === -1) {
|
3323 | state.raise("Invalid named capture referenced");
|
3324 | }
|
3325 | }
|
3326 | };
|
3327 |
|
3328 |
|
3329 | pp$8.regexp_disjunction = function(state) {
|
3330 | this.regexp_alternative(state);
|
3331 | while (state.eat(0x7C )) {
|
3332 | this.regexp_alternative(state);
|
3333 | }
|
3334 |
|
3335 |
|
3336 | if (this.regexp_eatQuantifier(state, true)) {
|
3337 | state.raise("Nothing to repeat");
|
3338 | }
|
3339 | if (state.eat(0x7B )) {
|
3340 | state.raise("Lone quantifier brackets");
|
3341 | }
|
3342 | };
|
3343 |
|
3344 |
|
3345 | pp$8.regexp_alternative = function(state) {
|
3346 | while (state.pos < state.source.length && this.regexp_eatTerm(state))
|
3347 | { }
|
3348 | };
|
3349 |
|
3350 |
|
3351 | pp$8.regexp_eatTerm = function(state) {
|
3352 | if (this.regexp_eatAssertion(state)) {
|
3353 |
|
3354 |
|
3355 |
|
3356 | if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
|
3357 |
|
3358 | if (state.switchU) {
|
3359 | state.raise("Invalid quantifier");
|
3360 | }
|
3361 | }
|
3362 | return true
|
3363 | }
|
3364 |
|
3365 | if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
|
3366 | this.regexp_eatQuantifier(state);
|
3367 | return true
|
3368 | }
|
3369 |
|
3370 | return false
|
3371 | };
|
3372 |
|
3373 |
|
3374 | pp$8.regexp_eatAssertion = function(state) {
|
3375 | var start = state.pos;
|
3376 | state.lastAssertionIsQuantifiable = false;
|
3377 |
|
3378 |
|
3379 | if (state.eat(0x5E ) || state.eat(0x24 )) {
|
3380 | return true
|
3381 | }
|
3382 |
|
3383 |
|
3384 | if (state.eat(0x5C )) {
|
3385 | if (state.eat(0x42 ) || state.eat(0x62 )) {
|
3386 | return true
|
3387 | }
|
3388 | state.pos = start;
|
3389 | }
|
3390 |
|
3391 |
|
3392 | if (state.eat(0x28 ) && state.eat(0x3F )) {
|
3393 | var lookbehind = false;
|
3394 | if (this.options.ecmaVersion >= 9) {
|
3395 | lookbehind = state.eat(0x3C );
|
3396 | }
|
3397 | if (state.eat(0x3D ) || state.eat(0x21 )) {
|
3398 | this.regexp_disjunction(state);
|
3399 | if (!state.eat(0x29 )) {
|
3400 | state.raise("Unterminated group");
|
3401 | }
|
3402 | state.lastAssertionIsQuantifiable = !lookbehind;
|
3403 | return true
|
3404 | }
|
3405 | }
|
3406 |
|
3407 | state.pos = start;
|
3408 | return false
|
3409 | };
|
3410 |
|
3411 |
|
3412 | pp$8.regexp_eatQuantifier = function(state, noError) {
|
3413 | if ( noError === void 0 ) noError = false;
|
3414 |
|
3415 | if (this.regexp_eatQuantifierPrefix(state, noError)) {
|
3416 | state.eat(0x3F );
|
3417 | return true
|
3418 | }
|
3419 | return false
|
3420 | };
|
3421 |
|
3422 |
|
3423 | pp$8.regexp_eatQuantifierPrefix = function(state, noError) {
|
3424 | return (
|
3425 | state.eat(0x2A ) ||
|
3426 | state.eat(0x2B ) ||
|
3427 | state.eat(0x3F ) ||
|
3428 | this.regexp_eatBracedQuantifier(state, noError)
|
3429 | )
|
3430 | };
|
3431 | pp$8.regexp_eatBracedQuantifier = function(state, noError) {
|
3432 | var start = state.pos;
|
3433 | if (state.eat(0x7B )) {
|
3434 | var min = 0, max = -1;
|
3435 | if (this.regexp_eatDecimalDigits(state)) {
|
3436 | min = state.lastIntValue;
|
3437 | if (state.eat(0x2C ) && this.regexp_eatDecimalDigits(state)) {
|
3438 | max = state.lastIntValue;
|
3439 | }
|
3440 | if (state.eat(0x7D )) {
|
3441 |
|
3442 | if (max !== -1 && max < min && !noError) {
|
3443 | state.raise("numbers out of order in {} quantifier");
|
3444 | }
|
3445 | return true
|
3446 | }
|
3447 | }
|
3448 | if (state.switchU && !noError) {
|
3449 | state.raise("Incomplete quantifier");
|
3450 | }
|
3451 | state.pos = start;
|
3452 | }
|
3453 | return false
|
3454 | };
|
3455 |
|
3456 |
|
3457 | pp$8.regexp_eatAtom = function(state) {
|
3458 | return (
|
3459 | this.regexp_eatPatternCharacters(state) ||
|
3460 | state.eat(0x2E ) ||
|
3461 | this.regexp_eatReverseSolidusAtomEscape(state) ||
|
3462 | this.regexp_eatCharacterClass(state) ||
|
3463 | this.regexp_eatUncapturingGroup(state) ||
|
3464 | this.regexp_eatCapturingGroup(state)
|
3465 | )
|
3466 | };
|
3467 | pp$8.regexp_eatReverseSolidusAtomEscape = function(state) {
|
3468 | var start = state.pos;
|
3469 | if (state.eat(0x5C )) {
|
3470 | if (this.regexp_eatAtomEscape(state)) {
|
3471 | return true
|
3472 | }
|
3473 | state.pos = start;
|
3474 | }
|
3475 | return false
|
3476 | };
|
3477 | pp$8.regexp_eatUncapturingGroup = function(state) {
|
3478 | var start = state.pos;
|
3479 | if (state.eat(0x28 )) {
|
3480 | if (state.eat(0x3F ) && state.eat(0x3A )) {
|
3481 | this.regexp_disjunction(state);
|
3482 | if (state.eat(0x29 )) {
|
3483 | return true
|
3484 | }
|
3485 | state.raise("Unterminated group");
|
3486 | }
|
3487 | state.pos = start;
|
3488 | }
|
3489 | return false
|
3490 | };
|
3491 | pp$8.regexp_eatCapturingGroup = function(state) {
|
3492 | if (state.eat(0x28 )) {
|
3493 | if (this.options.ecmaVersion >= 9) {
|
3494 | this.regexp_groupSpecifier(state);
|
3495 | } else if (state.current() === 0x3F ) {
|
3496 | state.raise("Invalid group");
|
3497 | }
|
3498 | this.regexp_disjunction(state);
|
3499 | if (state.eat(0x29 )) {
|
3500 | state.numCapturingParens += 1;
|
3501 | return true
|
3502 | }
|
3503 | state.raise("Unterminated group");
|
3504 | }
|
3505 | return false
|
3506 | };
|
3507 |
|
3508 |
|
3509 | pp$8.regexp_eatExtendedAtom = function(state) {
|
3510 | return (
|
3511 | state.eat(0x2E ) ||
|
3512 | this.regexp_eatReverseSolidusAtomEscape(state) ||
|
3513 | this.regexp_eatCharacterClass(state) ||
|
3514 | this.regexp_eatUncapturingGroup(state) ||
|
3515 | this.regexp_eatCapturingGroup(state) ||
|
3516 | this.regexp_eatInvalidBracedQuantifier(state) ||
|
3517 | this.regexp_eatExtendedPatternCharacter(state)
|
3518 | )
|
3519 | };
|
3520 |
|
3521 |
|
3522 | pp$8.regexp_eatInvalidBracedQuantifier = function(state) {
|
3523 | if (this.regexp_eatBracedQuantifier(state, true)) {
|
3524 | state.raise("Nothing to repeat");
|
3525 | }
|
3526 | return false
|
3527 | };
|
3528 |
|
3529 |
|
3530 | pp$8.regexp_eatSyntaxCharacter = function(state) {
|
3531 | var ch = state.current();
|
3532 | if (isSyntaxCharacter(ch)) {
|
3533 | state.lastIntValue = ch;
|
3534 | state.advance();
|
3535 | return true
|
3536 | }
|
3537 | return false
|
3538 | };
|
3539 | function isSyntaxCharacter(ch) {
|
3540 | return (
|
3541 | ch === 0x24 ||
|
3542 | ch >= 0x28 && ch <= 0x2B ||
|
3543 | ch === 0x2E ||
|
3544 | ch === 0x3F ||
|
3545 | ch >= 0x5B && ch <= 0x5E ||
|
3546 | ch >= 0x7B && ch <= 0x7D
|
3547 | )
|
3548 | }
|
3549 |
|
3550 |
|
3551 |
|
3552 | pp$8.regexp_eatPatternCharacters = function(state) {
|
3553 | var start = state.pos;
|
3554 | var ch = 0;
|
3555 | while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
|
3556 | state.advance();
|
3557 | }
|
3558 | return state.pos !== start
|
3559 | };
|
3560 |
|
3561 |
|
3562 | pp$8.regexp_eatExtendedPatternCharacter = function(state) {
|
3563 | var ch = state.current();
|
3564 | if (
|
3565 | ch !== -1 &&
|
3566 | ch !== 0x24 &&
|
3567 | !(ch >= 0x28 && ch <= 0x2B ) &&
|
3568 | ch !== 0x2E &&
|
3569 | ch !== 0x3F &&
|
3570 | ch !== 0x5B &&
|
3571 | ch !== 0x5E &&
|
3572 | ch !== 0x7C
|
3573 | ) {
|
3574 | state.advance();
|
3575 | return true
|
3576 | }
|
3577 | return false
|
3578 | };
|
3579 |
|
3580 |
|
3581 |
|
3582 |
|
3583 | pp$8.regexp_groupSpecifier = function(state) {
|
3584 | if (state.eat(0x3F )) {
|
3585 | if (this.regexp_eatGroupName(state)) {
|
3586 | if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
|
3587 | state.raise("Duplicate capture group name");
|
3588 | }
|
3589 | state.groupNames.push(state.lastStringValue);
|
3590 | return
|
3591 | }
|
3592 | state.raise("Invalid group");
|
3593 | }
|
3594 | };
|
3595 |
|
3596 |
|
3597 |
|
3598 |
|
3599 | pp$8.regexp_eatGroupName = function(state) {
|
3600 | state.lastStringValue = "";
|
3601 | if (state.eat(0x3C )) {
|
3602 | if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E )) {
|
3603 | return true
|
3604 | }
|
3605 | state.raise("Invalid capture group name");
|
3606 | }
|
3607 | return false
|
3608 | };
|
3609 |
|
3610 |
|
3611 |
|
3612 |
|
3613 |
|
3614 | pp$8.regexp_eatRegExpIdentifierName = function(state) {
|
3615 | state.lastStringValue = "";
|
3616 | if (this.regexp_eatRegExpIdentifierStart(state)) {
|
3617 | state.lastStringValue += codePointToString(state.lastIntValue);
|
3618 | while (this.regexp_eatRegExpIdentifierPart(state)) {
|
3619 | state.lastStringValue += codePointToString(state.lastIntValue);
|
3620 | }
|
3621 | return true
|
3622 | }
|
3623 | return false
|
3624 | };
|
3625 |
|
3626 |
|
3627 |
|
3628 |
|
3629 |
|
3630 |
|
3631 | pp$8.regexp_eatRegExpIdentifierStart = function(state) {
|
3632 | var start = state.pos;
|
3633 | var ch = state.current();
|
3634 | state.advance();
|
3635 |
|
3636 | if (ch === 0x5C && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
|
3637 | ch = state.lastIntValue;
|
3638 | }
|
3639 | if (isRegExpIdentifierStart(ch)) {
|
3640 | state.lastIntValue = ch;
|
3641 | return true
|
3642 | }
|
3643 |
|
3644 | state.pos = start;
|
3645 | return false
|
3646 | };
|
3647 | function isRegExpIdentifierStart(ch) {
|
3648 | return isIdentifierStart(ch, true) || ch === 0x24 || ch === 0x5F
|
3649 | }
|
3650 |
|
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 |
|
3656 |
|
3657 |
|
3658 | pp$8.regexp_eatRegExpIdentifierPart = function(state) {
|
3659 | var start = state.pos;
|
3660 | var ch = state.current();
|
3661 | state.advance();
|
3662 |
|
3663 | if (ch === 0x5C && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
|
3664 | ch = state.lastIntValue;
|
3665 | }
|
3666 | if (isRegExpIdentifierPart(ch)) {
|
3667 | state.lastIntValue = ch;
|
3668 | return true
|
3669 | }
|
3670 |
|
3671 | state.pos = start;
|
3672 | return false
|
3673 | };
|
3674 | function isRegExpIdentifierPart(ch) {
|
3675 | return isIdentifierChar(ch, true) || ch === 0x24 || ch === 0x5F || ch === 0x200C || ch === 0x200D
|
3676 | }
|
3677 |
|
3678 |
|
3679 | pp$8.regexp_eatAtomEscape = function(state) {
|
3680 | if (
|
3681 | this.regexp_eatBackReference(state) ||
|
3682 | this.regexp_eatCharacterClassEscape(state) ||
|
3683 | this.regexp_eatCharacterEscape(state) ||
|
3684 | (state.switchN && this.regexp_eatKGroupName(state))
|
3685 | ) {
|
3686 | return true
|
3687 | }
|
3688 | if (state.switchU) {
|
3689 |
|
3690 | if (state.current() === 0x63 ) {
|
3691 | state.raise("Invalid unicode escape");
|
3692 | }
|
3693 | state.raise("Invalid escape");
|
3694 | }
|
3695 | return false
|
3696 | };
|
3697 | pp$8.regexp_eatBackReference = function(state) {
|
3698 | var start = state.pos;
|
3699 | if (this.regexp_eatDecimalEscape(state)) {
|
3700 | var n = state.lastIntValue;
|
3701 | if (state.switchU) {
|
3702 |
|
3703 | if (n > state.maxBackReference) {
|
3704 | state.maxBackReference = n;
|
3705 | }
|
3706 | return true
|
3707 | }
|
3708 | if (n <= state.numCapturingParens) {
|
3709 | return true
|
3710 | }
|
3711 | state.pos = start;
|
3712 | }
|
3713 | return false
|
3714 | };
|
3715 | pp$8.regexp_eatKGroupName = function(state) {
|
3716 | if (state.eat(0x6B )) {
|
3717 | if (this.regexp_eatGroupName(state)) {
|
3718 | state.backReferenceNames.push(state.lastStringValue);
|
3719 | return true
|
3720 | }
|
3721 | state.raise("Invalid named reference");
|
3722 | }
|
3723 | return false
|
3724 | };
|
3725 |
|
3726 |
|
3727 | pp$8.regexp_eatCharacterEscape = function(state) {
|
3728 | return (
|
3729 | this.regexp_eatControlEscape(state) ||
|
3730 | this.regexp_eatCControlLetter(state) ||
|
3731 | this.regexp_eatZero(state) ||
|
3732 | this.regexp_eatHexEscapeSequence(state) ||
|
3733 | this.regexp_eatRegExpUnicodeEscapeSequence(state) ||
|
3734 | (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
|
3735 | this.regexp_eatIdentityEscape(state)
|
3736 | )
|
3737 | };
|
3738 | pp$8.regexp_eatCControlLetter = function(state) {
|
3739 | var start = state.pos;
|
3740 | if (state.eat(0x63 )) {
|
3741 | if (this.regexp_eatControlLetter(state)) {
|
3742 | return true
|
3743 | }
|
3744 | state.pos = start;
|
3745 | }
|
3746 | return false
|
3747 | };
|
3748 | pp$8.regexp_eatZero = function(state) {
|
3749 | if (state.current() === 0x30 && !isDecimalDigit(state.lookahead())) {
|
3750 | state.lastIntValue = 0;
|
3751 | state.advance();
|
3752 | return true
|
3753 | }
|
3754 | return false
|
3755 | };
|
3756 |
|
3757 |
|
3758 | pp$8.regexp_eatControlEscape = function(state) {
|
3759 | var ch = state.current();
|
3760 | if (ch === 0x74 ) {
|
3761 | state.lastIntValue = 0x09;
|
3762 | state.advance();
|
3763 | return true
|
3764 | }
|
3765 | if (ch === 0x6E ) {
|
3766 | state.lastIntValue = 0x0A;
|
3767 | state.advance();
|
3768 | return true
|
3769 | }
|
3770 | if (ch === 0x76 ) {
|
3771 | state.lastIntValue = 0x0B;
|
3772 | state.advance();
|
3773 | return true
|
3774 | }
|
3775 | if (ch === 0x66 ) {
|
3776 | state.lastIntValue = 0x0C;
|
3777 | state.advance();
|
3778 | return true
|
3779 | }
|
3780 | if (ch === 0x72 ) {
|
3781 | state.lastIntValue = 0x0D;
|
3782 | state.advance();
|
3783 | return true
|
3784 | }
|
3785 | return false
|
3786 | };
|
3787 |
|
3788 |
|
3789 | pp$8.regexp_eatControlLetter = function(state) {
|
3790 | var ch = state.current();
|
3791 | if (isControlLetter(ch)) {
|
3792 | state.lastIntValue = ch % 0x20;
|
3793 | state.advance();
|
3794 | return true
|
3795 | }
|
3796 | return false
|
3797 | };
|
3798 | function isControlLetter(ch) {
|
3799 | return (
|
3800 | (ch >= 0x41 && ch <= 0x5A ) ||
|
3801 | (ch >= 0x61 && ch <= 0x7A )
|
3802 | )
|
3803 | }
|
3804 |
|
3805 |
|
3806 | pp$8.regexp_eatRegExpUnicodeEscapeSequence = function(state) {
|
3807 | var start = state.pos;
|
3808 |
|
3809 | if (state.eat(0x75 )) {
|
3810 | if (this.regexp_eatFixedHexDigits(state, 4)) {
|
3811 | var lead = state.lastIntValue;
|
3812 | if (state.switchU && lead >= 0xD800 && lead <= 0xDBFF) {
|
3813 | var leadSurrogateEnd = state.pos;
|
3814 | if (state.eat(0x5C ) && state.eat(0x75 ) && this.regexp_eatFixedHexDigits(state, 4)) {
|
3815 | var trail = state.lastIntValue;
|
3816 | if (trail >= 0xDC00 && trail <= 0xDFFF) {
|
3817 | state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
|
3818 | return true
|
3819 | }
|
3820 | }
|
3821 | state.pos = leadSurrogateEnd;
|
3822 | state.lastIntValue = lead;
|
3823 | }
|
3824 | return true
|
3825 | }
|
3826 | if (
|
3827 | state.switchU &&
|
3828 | state.eat(0x7B ) &&
|
3829 | this.regexp_eatHexDigits(state) &&
|
3830 | state.eat(0x7D ) &&
|
3831 | isValidUnicode(state.lastIntValue)
|
3832 | ) {
|
3833 | return true
|
3834 | }
|
3835 | if (state.switchU) {
|
3836 | state.raise("Invalid unicode escape");
|
3837 | }
|
3838 | state.pos = start;
|
3839 | }
|
3840 |
|
3841 | return false
|
3842 | };
|
3843 | function isValidUnicode(ch) {
|
3844 | return ch >= 0 && ch <= 0x10FFFF
|
3845 | }
|
3846 |
|
3847 |
|
3848 | pp$8.regexp_eatIdentityEscape = function(state) {
|
3849 | if (state.switchU) {
|
3850 | if (this.regexp_eatSyntaxCharacter(state)) {
|
3851 | return true
|
3852 | }
|
3853 | if (state.eat(0x2F )) {
|
3854 | state.lastIntValue = 0x2F;
|
3855 | return true
|
3856 | }
|
3857 | return false
|
3858 | }
|
3859 |
|
3860 | var ch = state.current();
|
3861 | if (ch !== 0x63 && (!state.switchN || ch !== 0x6B )) {
|
3862 | state.lastIntValue = ch;
|
3863 | state.advance();
|
3864 | return true
|
3865 | }
|
3866 |
|
3867 | return false
|
3868 | };
|
3869 |
|
3870 |
|
3871 | pp$8.regexp_eatDecimalEscape = function(state) {
|
3872 | state.lastIntValue = 0;
|
3873 | var ch = state.current();
|
3874 | if (ch >= 0x31 && ch <= 0x39 ) {
|
3875 | do {
|
3876 | state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 );
|
3877 | state.advance();
|
3878 | } while ((ch = state.current()) >= 0x30 && ch <= 0x39 )
|
3879 | return true
|
3880 | }
|
3881 | return false
|
3882 | };
|
3883 |
|
3884 |
|
3885 | pp$8.regexp_eatCharacterClassEscape = function(state) {
|
3886 | var ch = state.current();
|
3887 |
|
3888 | if (isCharacterClassEscape(ch)) {
|
3889 | state.lastIntValue = -1;
|
3890 | state.advance();
|
3891 | return true
|
3892 | }
|
3893 |
|
3894 | if (
|
3895 | state.switchU &&
|
3896 | this.options.ecmaVersion >= 9 &&
|
3897 | (ch === 0x50 || ch === 0x70 )
|
3898 | ) {
|
3899 | state.lastIntValue = -1;
|
3900 | state.advance();
|
3901 | if (
|
3902 | state.eat(0x7B ) &&
|
3903 | this.regexp_eatUnicodePropertyValueExpression(state) &&
|
3904 | state.eat(0x7D )
|
3905 | ) {
|
3906 | return true
|
3907 | }
|
3908 | state.raise("Invalid property name");
|
3909 | }
|
3910 |
|
3911 | return false
|
3912 | };
|
3913 | function isCharacterClassEscape(ch) {
|
3914 | return (
|
3915 | ch === 0x64 ||
|
3916 | ch === 0x44 ||
|
3917 | ch === 0x73 ||
|
3918 | ch === 0x53 ||
|
3919 | ch === 0x77 ||
|
3920 | ch === 0x57
|
3921 | )
|
3922 | }
|
3923 |
|
3924 |
|
3925 |
|
3926 |
|
3927 | pp$8.regexp_eatUnicodePropertyValueExpression = function(state) {
|
3928 | var start = state.pos;
|
3929 |
|
3930 |
|
3931 | if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D )) {
|
3932 | var name = state.lastStringValue;
|
3933 | if (this.regexp_eatUnicodePropertyValue(state)) {
|
3934 | var value = state.lastStringValue;
|
3935 | this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
|
3936 | return true
|
3937 | }
|
3938 | }
|
3939 | state.pos = start;
|
3940 |
|
3941 |
|
3942 | if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
|
3943 | var nameOrValue = state.lastStringValue;
|
3944 | this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
|
3945 | return true
|
3946 | }
|
3947 | return false
|
3948 | };
|
3949 | pp$8.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
|
3950 | if (!has(state.unicodeProperties.nonBinary, name))
|
3951 | { state.raise("Invalid property name"); }
|
3952 | if (!state.unicodeProperties.nonBinary[name].test(value))
|
3953 | { state.raise("Invalid property value"); }
|
3954 | };
|
3955 | pp$8.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
|
3956 | if (!state.unicodeProperties.binary.test(nameOrValue))
|
3957 | { state.raise("Invalid property name"); }
|
3958 | };
|
3959 |
|
3960 |
|
3961 |
|
3962 | pp$8.regexp_eatUnicodePropertyName = function(state) {
|
3963 | var ch = 0;
|
3964 | state.lastStringValue = "";
|
3965 | while (isUnicodePropertyNameCharacter(ch = state.current())) {
|
3966 | state.lastStringValue += codePointToString(ch);
|
3967 | state.advance();
|
3968 | }
|
3969 | return state.lastStringValue !== ""
|
3970 | };
|
3971 | function isUnicodePropertyNameCharacter(ch) {
|
3972 | return isControlLetter(ch) || ch === 0x5F
|
3973 | }
|
3974 |
|
3975 |
|
3976 |
|
3977 | pp$8.regexp_eatUnicodePropertyValue = function(state) {
|
3978 | var ch = 0;
|
3979 | state.lastStringValue = "";
|
3980 | while (isUnicodePropertyValueCharacter(ch = state.current())) {
|
3981 | state.lastStringValue += codePointToString(ch);
|
3982 | state.advance();
|
3983 | }
|
3984 | return state.lastStringValue !== ""
|
3985 | };
|
3986 | function isUnicodePropertyValueCharacter(ch) {
|
3987 | return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
|
3988 | }
|
3989 |
|
3990 |
|
3991 |
|
3992 | pp$8.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
|
3993 | return this.regexp_eatUnicodePropertyValue(state)
|
3994 | };
|
3995 |
|
3996 |
|
3997 | pp$8.regexp_eatCharacterClass = function(state) {
|
3998 | if (state.eat(0x5B )) {
|
3999 | state.eat(0x5E );
|
4000 | this.regexp_classRanges(state);
|
4001 | if (state.eat(0x5D )) {
|
4002 | return true
|
4003 | }
|
4004 |
|
4005 | state.raise("Unterminated character class");
|
4006 | }
|
4007 | return false
|
4008 | };
|
4009 |
|
4010 |
|
4011 |
|
4012 |
|
4013 | pp$8.regexp_classRanges = function(state) {
|
4014 | while (this.regexp_eatClassAtom(state)) {
|
4015 | var left = state.lastIntValue;
|
4016 | if (state.eat(0x2D ) && this.regexp_eatClassAtom(state)) {
|
4017 | var right = state.lastIntValue;
|
4018 | if (state.switchU && (left === -1 || right === -1)) {
|
4019 | state.raise("Invalid character class");
|
4020 | }
|
4021 | if (left !== -1 && right !== -1 && left > right) {
|
4022 | state.raise("Range out of order in character class");
|
4023 | }
|
4024 | }
|
4025 | }
|
4026 | };
|
4027 |
|
4028 |
|
4029 |
|
4030 | pp$8.regexp_eatClassAtom = function(state) {
|
4031 | var start = state.pos;
|
4032 |
|
4033 | if (state.eat(0x5C )) {
|
4034 | if (this.regexp_eatClassEscape(state)) {
|
4035 | return true
|
4036 | }
|
4037 | if (state.switchU) {
|
4038 |
|
4039 | var ch$1 = state.current();
|
4040 | if (ch$1 === 0x63 || isOctalDigit(ch$1)) {
|
4041 | state.raise("Invalid class escape");
|
4042 | }
|
4043 | state.raise("Invalid escape");
|
4044 | }
|
4045 | state.pos = start;
|
4046 | }
|
4047 |
|
4048 | var ch = state.current();
|
4049 | if (ch !== 0x5D ) {
|
4050 | state.lastIntValue = ch;
|
4051 | state.advance();
|
4052 | return true
|
4053 | }
|
4054 |
|
4055 | return false
|
4056 | };
|
4057 |
|
4058 |
|
4059 | pp$8.regexp_eatClassEscape = function(state) {
|
4060 | var start = state.pos;
|
4061 |
|
4062 | if (state.eat(0x62 )) {
|
4063 | state.lastIntValue = 0x08;
|
4064 | return true
|
4065 | }
|
4066 |
|
4067 | if (state.switchU && state.eat(0x2D )) {
|
4068 | state.lastIntValue = 0x2D;
|
4069 | return true
|
4070 | }
|
4071 |
|
4072 | if (!state.switchU && state.eat(0x63 )) {
|
4073 | if (this.regexp_eatClassControlLetter(state)) {
|
4074 | return true
|
4075 | }
|
4076 | state.pos = start;
|
4077 | }
|
4078 |
|
4079 | return (
|
4080 | this.regexp_eatCharacterClassEscape(state) ||
|
4081 | this.regexp_eatCharacterEscape(state)
|
4082 | )
|
4083 | };
|
4084 |
|
4085 |
|
4086 | pp$8.regexp_eatClassControlLetter = function(state) {
|
4087 | var ch = state.current();
|
4088 | if (isDecimalDigit(ch) || ch === 0x5F ) {
|
4089 | state.lastIntValue = ch % 0x20;
|
4090 | state.advance();
|
4091 | return true
|
4092 | }
|
4093 | return false
|
4094 | };
|
4095 |
|
4096 |
|
4097 | pp$8.regexp_eatHexEscapeSequence = function(state) {
|
4098 | var start = state.pos;
|
4099 | if (state.eat(0x78 )) {
|
4100 | if (this.regexp_eatFixedHexDigits(state, 2)) {
|
4101 | return true
|
4102 | }
|
4103 | if (state.switchU) {
|
4104 | state.raise("Invalid escape");
|
4105 | }
|
4106 | state.pos = start;
|
4107 | }
|
4108 | return false
|
4109 | };
|
4110 |
|
4111 |
|
4112 | pp$8.regexp_eatDecimalDigits = function(state) {
|
4113 | var start = state.pos;
|
4114 | var ch = 0;
|
4115 | state.lastIntValue = 0;
|
4116 | while (isDecimalDigit(ch = state.current())) {
|
4117 | state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 );
|
4118 | state.advance();
|
4119 | }
|
4120 | return state.pos !== start
|
4121 | };
|
4122 | function isDecimalDigit(ch) {
|
4123 | return ch >= 0x30 && ch <= 0x39
|
4124 | }
|
4125 |
|
4126 |
|
4127 | pp$8.regexp_eatHexDigits = function(state) {
|
4128 | var start = state.pos;
|
4129 | var ch = 0;
|
4130 | state.lastIntValue = 0;
|
4131 | while (isHexDigit(ch = state.current())) {
|
4132 | state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
|
4133 | state.advance();
|
4134 | }
|
4135 | return state.pos !== start
|
4136 | };
|
4137 | function isHexDigit(ch) {
|
4138 | return (
|
4139 | (ch >= 0x30 && ch <= 0x39 ) ||
|
4140 | (ch >= 0x41 && ch <= 0x46 ) ||
|
4141 | (ch >= 0x61 && ch <= 0x66 )
|
4142 | )
|
4143 | }
|
4144 | function hexToInt(ch) {
|
4145 | if (ch >= 0x41 && ch <= 0x46 ) {
|
4146 | return 10 + (ch - 0x41 )
|
4147 | }
|
4148 | if (ch >= 0x61 && ch <= 0x66 ) {
|
4149 | return 10 + (ch - 0x61 )
|
4150 | }
|
4151 | return ch - 0x30
|
4152 | }
|
4153 |
|
4154 |
|
4155 |
|
4156 | pp$8.regexp_eatLegacyOctalEscapeSequence = function(state) {
|
4157 | if (this.regexp_eatOctalDigit(state)) {
|
4158 | var n1 = state.lastIntValue;
|
4159 | if (this.regexp_eatOctalDigit(state)) {
|
4160 | var n2 = state.lastIntValue;
|
4161 | if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
|
4162 | state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
|
4163 | } else {
|
4164 | state.lastIntValue = n1 * 8 + n2;
|
4165 | }
|
4166 | } else {
|
4167 | state.lastIntValue = n1;
|
4168 | }
|
4169 | return true
|
4170 | }
|
4171 | return false
|
4172 | };
|
4173 |
|
4174 |
|
4175 | pp$8.regexp_eatOctalDigit = function(state) {
|
4176 | var ch = state.current();
|
4177 | if (isOctalDigit(ch)) {
|
4178 | state.lastIntValue = ch - 0x30;
|
4179 | state.advance();
|
4180 | return true
|
4181 | }
|
4182 | state.lastIntValue = 0;
|
4183 | return false
|
4184 | };
|
4185 | function isOctalDigit(ch) {
|
4186 | return ch >= 0x30 && ch <= 0x37
|
4187 | }
|
4188 |
|
4189 |
|
4190 |
|
4191 |
|
4192 | pp$8.regexp_eatFixedHexDigits = function(state, length) {
|
4193 | var start = state.pos;
|
4194 | state.lastIntValue = 0;
|
4195 | for (var i = 0; i < length; ++i) {
|
4196 | var ch = state.current();
|
4197 | if (!isHexDigit(ch)) {
|
4198 | state.pos = start;
|
4199 | return false
|
4200 | }
|
4201 | state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
|
4202 | state.advance();
|
4203 | }
|
4204 | return true
|
4205 | };
|
4206 |
|
4207 |
|
4208 |
|
4209 |
|
4210 |
|
4211 | var Token = function Token(p) {
|
4212 | this.type = p.type;
|
4213 | this.value = p.value;
|
4214 | this.start = p.start;
|
4215 | this.end = p.end;
|
4216 | if (p.options.locations)
|
4217 | { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
|
4218 | if (p.options.ranges)
|
4219 | { this.range = [p.start, p.end]; }
|
4220 | };
|
4221 |
|
4222 |
|
4223 |
|
4224 | var pp$9 = Parser.prototype;
|
4225 |
|
4226 |
|
4227 |
|
4228 | pp$9.next = function() {
|
4229 | if (this.options.onToken)
|
4230 | { this.options.onToken(new Token(this)); }
|
4231 |
|
4232 | this.lastTokEnd = this.end;
|
4233 | this.lastTokStart = this.start;
|
4234 | this.lastTokEndLoc = this.endLoc;
|
4235 | this.lastTokStartLoc = this.startLoc;
|
4236 | this.nextToken();
|
4237 | };
|
4238 |
|
4239 | pp$9.getToken = function() {
|
4240 | this.next();
|
4241 | return new Token(this)
|
4242 | };
|
4243 |
|
4244 |
|
4245 | if (typeof Symbol !== "undefined")
|
4246 | { pp$9[Symbol.iterator] = function() {
|
4247 | var this$1 = this;
|
4248 |
|
4249 | return {
|
4250 | next: function () {
|
4251 | var token = this$1.getToken();
|
4252 | return {
|
4253 | done: token.type === types.eof,
|
4254 | value: token
|
4255 | }
|
4256 | }
|
4257 | }
|
4258 | }; }
|
4259 |
|
4260 |
|
4261 |
|
4262 |
|
4263 | pp$9.curContext = function() {
|
4264 | return this.context[this.context.length - 1]
|
4265 | };
|
4266 |
|
4267 |
|
4268 |
|
4269 |
|
4270 | pp$9.nextToken = function() {
|
4271 | var curContext = this.curContext();
|
4272 | if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
|
4273 |
|
4274 | this.start = this.pos;
|
4275 | if (this.options.locations) { this.startLoc = this.curPosition(); }
|
4276 | if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
|
4277 |
|
4278 | if (curContext.override) { return curContext.override(this) }
|
4279 | else { this.readToken(this.fullCharCodeAtPos()); }
|
4280 | };
|
4281 |
|
4282 | pp$9.readToken = function(code) {
|
4283 |
|
4284 |
|
4285 | if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 )
|
4286 | { return this.readWord() }
|
4287 |
|
4288 | return this.getTokenFromCode(code)
|
4289 | };
|
4290 |
|
4291 | pp$9.fullCharCodeAtPos = function() {
|
4292 | var code = this.input.charCodeAt(this.pos);
|
4293 | if (code <= 0xd7ff || code >= 0xe000) { return code }
|
4294 | var next = this.input.charCodeAt(this.pos + 1);
|
4295 | return (code << 10) + next - 0x35fdc00
|
4296 | };
|
4297 |
|
4298 | pp$9.skipBlockComment = function() {
|
4299 | var startLoc = this.options.onComment && this.curPosition();
|
4300 | var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
|
4301 | if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
|
4302 | this.pos = end + 2;
|
4303 | if (this.options.locations) {
|
4304 | lineBreakG.lastIndex = start;
|
4305 | var match;
|
4306 | while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
|
4307 | ++this.curLine;
|
4308 | this.lineStart = match.index + match[0].length;
|
4309 | }
|
4310 | }
|
4311 | if (this.options.onComment)
|
4312 | { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
|
4313 | startLoc, this.curPosition()); }
|
4314 | };
|
4315 |
|
4316 | pp$9.skipLineComment = function(startSkip) {
|
4317 | var start = this.pos;
|
4318 | var startLoc = this.options.onComment && this.curPosition();
|
4319 | var ch = this.input.charCodeAt(this.pos += startSkip);
|
4320 | while (this.pos < this.input.length && !isNewLine(ch)) {
|
4321 | ch = this.input.charCodeAt(++this.pos);
|
4322 | }
|
4323 | if (this.options.onComment)
|
4324 | { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
|
4325 | startLoc, this.curPosition()); }
|
4326 | };
|
4327 |
|
4328 |
|
4329 |
|
4330 |
|
4331 | pp$9.skipSpace = function() {
|
4332 | loop: while (this.pos < this.input.length) {
|
4333 | var ch = this.input.charCodeAt(this.pos);
|
4334 | switch (ch) {
|
4335 | case 32: case 160:
|
4336 | ++this.pos;
|
4337 | break
|
4338 | case 13:
|
4339 | if (this.input.charCodeAt(this.pos + 1) === 10) {
|
4340 | ++this.pos;
|
4341 | }
|
4342 | case 10: case 8232: case 8233:
|
4343 | ++this.pos;
|
4344 | if (this.options.locations) {
|
4345 | ++this.curLine;
|
4346 | this.lineStart = this.pos;
|
4347 | }
|
4348 | break
|
4349 | case 47:
|
4350 | switch (this.input.charCodeAt(this.pos + 1)) {
|
4351 | case 42:
|
4352 | this.skipBlockComment();
|
4353 | break
|
4354 | case 47:
|
4355 | this.skipLineComment(2);
|
4356 | break
|
4357 | default:
|
4358 | break loop
|
4359 | }
|
4360 | break
|
4361 | default:
|
4362 | if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
|
4363 | ++this.pos;
|
4364 | } else {
|
4365 | break loop
|
4366 | }
|
4367 | }
|
4368 | }
|
4369 | };
|
4370 |
|
4371 |
|
4372 |
|
4373 |
|
4374 |
|
4375 |
|
4376 | pp$9.finishToken = function(type, val) {
|
4377 | this.end = this.pos;
|
4378 | if (this.options.locations) { this.endLoc = this.curPosition(); }
|
4379 | var prevType = this.type;
|
4380 | this.type = type;
|
4381 | this.value = val;
|
4382 |
|
4383 | this.updateContext(prevType);
|
4384 | };
|
4385 |
|
4386 |
|
4387 |
|
4388 |
|
4389 |
|
4390 |
|
4391 |
|
4392 |
|
4393 |
|
4394 |
|
4395 | pp$9.readToken_dot = function() {
|
4396 | var next = this.input.charCodeAt(this.pos + 1);
|
4397 | if (next >= 48 && next <= 57) { return this.readNumber(true) }
|
4398 | var next2 = this.input.charCodeAt(this.pos + 2);
|
4399 | if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) {
|
4400 | this.pos += 3;
|
4401 | return this.finishToken(types.ellipsis)
|
4402 | } else {
|
4403 | ++this.pos;
|
4404 | return this.finishToken(types.dot)
|
4405 | }
|
4406 | };
|
4407 |
|
4408 | pp$9.readToken_slash = function() {
|
4409 | var next = this.input.charCodeAt(this.pos + 1);
|
4410 | if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
|
4411 | if (next === 61) { return this.finishOp(types.assign, 2) }
|
4412 | return this.finishOp(types.slash, 1)
|
4413 | };
|
4414 |
|
4415 | pp$9.readToken_mult_modulo_exp = function(code) {
|
4416 | var next = this.input.charCodeAt(this.pos + 1);
|
4417 | var size = 1;
|
4418 | var tokentype = code === 42 ? types.star : types.modulo;
|
4419 |
|
4420 |
|
4421 | if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
|
4422 | ++size;
|
4423 | tokentype = types.starstar;
|
4424 | next = this.input.charCodeAt(this.pos + 2);
|
4425 | }
|
4426 |
|
4427 | if (next === 61) { return this.finishOp(types.assign, size + 1) }
|
4428 | return this.finishOp(tokentype, size)
|
4429 | };
|
4430 |
|
4431 | pp$9.readToken_pipe_amp = function(code) {
|
4432 | var next = this.input.charCodeAt(this.pos + 1);
|
4433 | if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
|
4434 | if (next === 61) { return this.finishOp(types.assign, 2) }
|
4435 | return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
|
4436 | };
|
4437 |
|
4438 | pp$9.readToken_caret = function() {
|
4439 | var next = this.input.charCodeAt(this.pos + 1);
|
4440 | if (next === 61) { return this.finishOp(types.assign, 2) }
|
4441 | return this.finishOp(types.bitwiseXOR, 1)
|
4442 | };
|
4443 |
|
4444 | pp$9.readToken_plus_min = function(code) {
|
4445 | var next = this.input.charCodeAt(this.pos + 1);
|
4446 | if (next === code) {
|
4447 | if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
|
4448 | (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
|
4449 |
|
4450 | this.skipLineComment(3);
|
4451 | this.skipSpace();
|
4452 | return this.nextToken()
|
4453 | }
|
4454 | return this.finishOp(types.incDec, 2)
|
4455 | }
|
4456 | if (next === 61) { return this.finishOp(types.assign, 2) }
|
4457 | return this.finishOp(types.plusMin, 1)
|
4458 | };
|
4459 |
|
4460 | pp$9.readToken_lt_gt = function(code) {
|
4461 | var next = this.input.charCodeAt(this.pos + 1);
|
4462 | var size = 1;
|
4463 | if (next === code) {
|
4464 | size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
|
4465 | if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
|
4466 | return this.finishOp(types.bitShift, size)
|
4467 | }
|
4468 | if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
|
4469 | this.input.charCodeAt(this.pos + 3) === 45) {
|
4470 |
|
4471 | this.skipLineComment(4);
|
4472 | this.skipSpace();
|
4473 | return this.nextToken()
|
4474 | }
|
4475 | if (next === 61) { size = 2; }
|
4476 | return this.finishOp(types.relational, size)
|
4477 | };
|
4478 |
|
4479 | pp$9.readToken_eq_excl = function(code) {
|
4480 | var next = this.input.charCodeAt(this.pos + 1);
|
4481 | if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
|
4482 | if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) {
|
4483 | this.pos += 2;
|
4484 | return this.finishToken(types.arrow)
|
4485 | }
|
4486 | return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
|
4487 | };
|
4488 |
|
4489 | pp$9.getTokenFromCode = function(code) {
|
4490 | switch (code) {
|
4491 |
|
4492 |
|
4493 | case 46:
|
4494 | return this.readToken_dot()
|
4495 |
|
4496 |
|
4497 | case 40: ++this.pos; return this.finishToken(types.parenL)
|
4498 | case 41: ++this.pos; return this.finishToken(types.parenR)
|
4499 | case 59: ++this.pos; return this.finishToken(types.semi)
|
4500 | case 44: ++this.pos; return this.finishToken(types.comma)
|
4501 | case 91: ++this.pos; return this.finishToken(types.bracketL)
|
4502 | case 93: ++this.pos; return this.finishToken(types.bracketR)
|
4503 | case 123: ++this.pos; return this.finishToken(types.braceL)
|
4504 | case 125: ++this.pos; return this.finishToken(types.braceR)
|
4505 | case 58: ++this.pos; return this.finishToken(types.colon)
|
4506 | case 63: ++this.pos; return this.finishToken(types.question)
|
4507 |
|
4508 | case 96:
|
4509 | if (this.options.ecmaVersion < 6) { break }
|
4510 | ++this.pos;
|
4511 | return this.finishToken(types.backQuote)
|
4512 |
|
4513 | case 48:
|
4514 | var next = this.input.charCodeAt(this.pos + 1);
|
4515 | if (next === 120 || next === 88) { return this.readRadixNumber(16) }
|
4516 | if (this.options.ecmaVersion >= 6) {
|
4517 | if (next === 111 || next === 79) { return this.readRadixNumber(8) }
|
4518 | if (next === 98 || next === 66) { return this.readRadixNumber(2) }
|
4519 | }
|
4520 |
|
4521 |
|
4522 |
|
4523 | case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57:
|
4524 | return this.readNumber(false)
|
4525 |
|
4526 |
|
4527 | case 34: case 39:
|
4528 | return this.readString(code)
|
4529 |
|
4530 |
|
4531 |
|
4532 |
|
4533 |
|
4534 |
|
4535 | case 47:
|
4536 | return this.readToken_slash()
|
4537 |
|
4538 | case 37: case 42:
|
4539 | return this.readToken_mult_modulo_exp(code)
|
4540 |
|
4541 | case 124: case 38:
|
4542 | return this.readToken_pipe_amp(code)
|
4543 |
|
4544 | case 94:
|
4545 | return this.readToken_caret()
|
4546 |
|
4547 | case 43: case 45:
|
4548 | return this.readToken_plus_min(code)
|
4549 |
|
4550 | case 60: case 62:
|
4551 | return this.readToken_lt_gt(code)
|
4552 |
|
4553 | case 61: case 33:
|
4554 | return this.readToken_eq_excl(code)
|
4555 |
|
4556 | case 126:
|
4557 | return this.finishOp(types.prefix, 1)
|
4558 | }
|
4559 |
|
4560 | this.raise(this.pos, "Unexpected character '" + codePointToString$1(code) + "'");
|
4561 | };
|
4562 |
|
4563 | pp$9.finishOp = function(type, size) {
|
4564 | var str = this.input.slice(this.pos, this.pos + size);
|
4565 | this.pos += size;
|
4566 | return this.finishToken(type, str)
|
4567 | };
|
4568 |
|
4569 | pp$9.readRegexp = function() {
|
4570 | var escaped, inClass, start = this.pos;
|
4571 | for (;;) {
|
4572 | if (this.pos >= this.input.length) { this.raise(start, "Unterminated regular expression"); }
|
4573 | var ch = this.input.charAt(this.pos);
|
4574 | if (lineBreak.test(ch)) { this.raise(start, "Unterminated regular expression"); }
|
4575 | if (!escaped) {
|
4576 | if (ch === "[") { inClass = true; }
|
4577 | else if (ch === "]" && inClass) { inClass = false; }
|
4578 | else if (ch === "/" && !inClass) { break }
|
4579 | escaped = ch === "\\";
|
4580 | } else { escaped = false; }
|
4581 | ++this.pos;
|
4582 | }
|
4583 | var pattern = this.input.slice(start, this.pos);
|
4584 | ++this.pos;
|
4585 | var flagsStart = this.pos;
|
4586 | var flags = this.readWord1();
|
4587 | if (this.containsEsc) { this.unexpected(flagsStart); }
|
4588 |
|
4589 |
|
4590 | var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
|
4591 | state.reset(start, pattern, flags);
|
4592 | this.validateRegExpFlags(state);
|
4593 | this.validateRegExpPattern(state);
|
4594 |
|
4595 |
|
4596 | var value = null;
|
4597 | try {
|
4598 | value = new RegExp(pattern, flags);
|
4599 | } catch (e) {
|
4600 |
|
4601 |
|
4602 | }
|
4603 |
|
4604 | return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
|
4605 | };
|
4606 |
|
4607 |
|
4608 |
|
4609 |
|
4610 |
|
4611 | pp$9.readInt = function(radix, len) {
|
4612 | var start = this.pos, total = 0;
|
4613 | for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
|
4614 | var code = this.input.charCodeAt(this.pos), val = (void 0);
|
4615 | if (code >= 97) { val = code - 97 + 10; }
|
4616 | else if (code >= 65) { val = code - 65 + 10; }
|
4617 | else if (code >= 48 && code <= 57) { val = code - 48; }
|
4618 | else { val = Infinity; }
|
4619 | if (val >= radix) { break }
|
4620 | ++this.pos;
|
4621 | total = total * radix + val;
|
4622 | }
|
4623 | if (this.pos === start || len != null && this.pos - start !== len) { return null }
|
4624 |
|
4625 | return total
|
4626 | };
|
4627 |
|
4628 | pp$9.readRadixNumber = function(radix) {
|
4629 | var start = this.pos;
|
4630 | this.pos += 2;
|
4631 | var val = this.readInt(radix);
|
4632 | if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
|
4633 | if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
|
4634 | val = typeof BigInt !== "undefined" ? BigInt(this.input.slice(start, this.pos)) : null;
|
4635 | ++this.pos;
|
4636 | } else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
|
4637 | return this.finishToken(types.num, val)
|
4638 | };
|
4639 |
|
4640 |
|
4641 |
|
4642 | pp$9.readNumber = function(startsWithDot) {
|
4643 | var start = this.pos;
|
4644 | if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
|
4645 | var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
|
4646 | if (octal && this.strict) { this.raise(start, "Invalid number"); }
|
4647 | if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
|
4648 | var next = this.input.charCodeAt(this.pos);
|
4649 | if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
|
4650 | var str$1 = this.input.slice(start, this.pos);
|
4651 | var val$1 = typeof BigInt !== "undefined" ? BigInt(str$1) : null;
|
4652 | ++this.pos;
|
4653 | if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
|
4654 | return this.finishToken(types.num, val$1)
|
4655 | }
|
4656 | if (next === 46 && !octal) {
|
4657 | ++this.pos;
|
4658 | this.readInt(10);
|
4659 | next = this.input.charCodeAt(this.pos);
|
4660 | }
|
4661 | if ((next === 69 || next === 101) && !octal) {
|
4662 | next = this.input.charCodeAt(++this.pos);
|
4663 | if (next === 43 || next === 45) { ++this.pos; }
|
4664 | if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
|
4665 | }
|
4666 | if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
|
4667 |
|
4668 | var str = this.input.slice(start, this.pos);
|
4669 | var val = octal ? parseInt(str, 8) : parseFloat(str);
|
4670 | return this.finishToken(types.num, val)
|
4671 | };
|
4672 |
|
4673 |
|
4674 |
|
4675 | pp$9.readCodePoint = function() {
|
4676 | var ch = this.input.charCodeAt(this.pos), code;
|
4677 |
|
4678 | if (ch === 123) {
|
4679 | if (this.options.ecmaVersion < 6) { this.unexpected(); }
|
4680 | var codePos = ++this.pos;
|
4681 | code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
|
4682 | ++this.pos;
|
4683 | if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
|
4684 | } else {
|
4685 | code = this.readHexChar(4);
|
4686 | }
|
4687 | return code
|
4688 | };
|
4689 |
|
4690 | function codePointToString$1(code) {
|
4691 |
|
4692 | if (code <= 0xFFFF) { return String.fromCharCode(code) }
|
4693 | code -= 0x10000;
|
4694 | return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
|
4695 | }
|
4696 |
|
4697 | pp$9.readString = function(quote) {
|
4698 | var out = "", chunkStart = ++this.pos;
|
4699 | for (;;) {
|
4700 | if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated string constant"); }
|
4701 | var ch = this.input.charCodeAt(this.pos);
|
4702 | if (ch === quote) { break }
|
4703 | if (ch === 92) {
|
4704 | out += this.input.slice(chunkStart, this.pos);
|
4705 | out += this.readEscapedChar(false);
|
4706 | chunkStart = this.pos;
|
4707 | } else {
|
4708 | if (isNewLine(ch, this.options.ecmaVersion >= 10)) { this.raise(this.start, "Unterminated string constant"); }
|
4709 | ++this.pos;
|
4710 | }
|
4711 | }
|
4712 | out += this.input.slice(chunkStart, this.pos++);
|
4713 | return this.finishToken(types.string, out)
|
4714 | };
|
4715 |
|
4716 |
|
4717 |
|
4718 | var INVALID_TEMPLATE_ESCAPE_ERROR = {};
|
4719 |
|
4720 | pp$9.tryReadTemplateToken = function() {
|
4721 | this.inTemplateElement = true;
|
4722 | try {
|
4723 | this.readTmplToken();
|
4724 | } catch (err) {
|
4725 | if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
|
4726 | this.readInvalidTemplateToken();
|
4727 | } else {
|
4728 | throw err
|
4729 | }
|
4730 | }
|
4731 |
|
4732 | this.inTemplateElement = false;
|
4733 | };
|
4734 |
|
4735 | pp$9.invalidStringToken = function(position, message) {
|
4736 | if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
|
4737 | throw INVALID_TEMPLATE_ESCAPE_ERROR
|
4738 | } else {
|
4739 | this.raise(position, message);
|
4740 | }
|
4741 | };
|
4742 |
|
4743 | pp$9.readTmplToken = function() {
|
4744 | var out = "", chunkStart = this.pos;
|
4745 | for (;;) {
|
4746 | if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated template"); }
|
4747 | var ch = this.input.charCodeAt(this.pos);
|
4748 | if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) {
|
4749 | if (this.pos === this.start && (this.type === types.template || this.type === types.invalidTemplate)) {
|
4750 | if (ch === 36) {
|
4751 | this.pos += 2;
|
4752 | return this.finishToken(types.dollarBraceL)
|
4753 | } else {
|
4754 | ++this.pos;
|
4755 | return this.finishToken(types.backQuote)
|
4756 | }
|
4757 | }
|
4758 | out += this.input.slice(chunkStart, this.pos);
|
4759 | return this.finishToken(types.template, out)
|
4760 | }
|
4761 | if (ch === 92) {
|
4762 | out += this.input.slice(chunkStart, this.pos);
|
4763 | out += this.readEscapedChar(true);
|
4764 | chunkStart = this.pos;
|
4765 | } else if (isNewLine(ch)) {
|
4766 | out += this.input.slice(chunkStart, this.pos);
|
4767 | ++this.pos;
|
4768 | switch (ch) {
|
4769 | case 13:
|
4770 | if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
|
4771 | case 10:
|
4772 | out += "\n";
|
4773 | break
|
4774 | default:
|
4775 | out += String.fromCharCode(ch);
|
4776 | break
|
4777 | }
|
4778 | if (this.options.locations) {
|
4779 | ++this.curLine;
|
4780 | this.lineStart = this.pos;
|
4781 | }
|
4782 | chunkStart = this.pos;
|
4783 | } else {
|
4784 | ++this.pos;
|
4785 | }
|
4786 | }
|
4787 | };
|
4788 |
|
4789 |
|
4790 | pp$9.readInvalidTemplateToken = function() {
|
4791 | for (; this.pos < this.input.length; this.pos++) {
|
4792 | switch (this.input[this.pos]) {
|
4793 | case "\\":
|
4794 | ++this.pos;
|
4795 | break
|
4796 |
|
4797 | case "$":
|
4798 | if (this.input[this.pos + 1] !== "{") {
|
4799 | break
|
4800 | }
|
4801 |
|
4802 |
|
4803 | case "`":
|
4804 | return this.finishToken(types.invalidTemplate, this.input.slice(this.start, this.pos))
|
4805 |
|
4806 |
|
4807 | }
|
4808 | }
|
4809 | this.raise(this.start, "Unterminated template");
|
4810 | };
|
4811 |
|
4812 |
|
4813 |
|
4814 | pp$9.readEscapedChar = function(inTemplate) {
|
4815 | var ch = this.input.charCodeAt(++this.pos);
|
4816 | ++this.pos;
|
4817 | switch (ch) {
|
4818 | case 110: return "\n"
|
4819 | case 114: return "\r"
|
4820 | case 120: return String.fromCharCode(this.readHexChar(2))
|
4821 | case 117: return codePointToString$1(this.readCodePoint())
|
4822 | case 116: return "\t"
|
4823 | case 98: return "\b"
|
4824 | case 118: return "\u000b"
|
4825 | case 102: return "\f"
|
4826 | case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
|
4827 | case 10:
|
4828 | if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
|
4829 | return ""
|
4830 | default:
|
4831 | if (ch >= 48 && ch <= 55) {
|
4832 | var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
|
4833 | var octal = parseInt(octalStr, 8);
|
4834 | if (octal > 255) {
|
4835 | octalStr = octalStr.slice(0, -1);
|
4836 | octal = parseInt(octalStr, 8);
|
4837 | }
|
4838 | this.pos += octalStr.length - 1;
|
4839 | ch = this.input.charCodeAt(this.pos);
|
4840 | if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
|
4841 | this.invalidStringToken(
|
4842 | this.pos - 1 - octalStr.length,
|
4843 | inTemplate
|
4844 | ? "Octal literal in template string"
|
4845 | : "Octal literal in strict mode"
|
4846 | );
|
4847 | }
|
4848 | return String.fromCharCode(octal)
|
4849 | }
|
4850 | if (isNewLine(ch)) {
|
4851 |
|
4852 |
|
4853 | return ""
|
4854 | }
|
4855 | return String.fromCharCode(ch)
|
4856 | }
|
4857 | };
|
4858 |
|
4859 |
|
4860 |
|
4861 | pp$9.readHexChar = function(len) {
|
4862 | var codePos = this.pos;
|
4863 | var n = this.readInt(16, len);
|
4864 | if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
|
4865 | return n
|
4866 | };
|
4867 |
|
4868 |
|
4869 |
|
4870 |
|
4871 |
|
4872 |
|
4873 |
|
4874 | pp$9.readWord1 = function() {
|
4875 | this.containsEsc = false;
|
4876 | var word = "", first = true, chunkStart = this.pos;
|
4877 | var astral = this.options.ecmaVersion >= 6;
|
4878 | while (this.pos < this.input.length) {
|
4879 | var ch = this.fullCharCodeAtPos();
|
4880 | if (isIdentifierChar(ch, astral)) {
|
4881 | this.pos += ch <= 0xffff ? 1 : 2;
|
4882 | } else if (ch === 92) {
|
4883 | this.containsEsc = true;
|
4884 | word += this.input.slice(chunkStart, this.pos);
|
4885 | var escStart = this.pos;
|
4886 | if (this.input.charCodeAt(++this.pos) !== 117)
|
4887 | { this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); }
|
4888 | ++this.pos;
|
4889 | var esc = this.readCodePoint();
|
4890 | if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
|
4891 | { this.invalidStringToken(escStart, "Invalid Unicode escape"); }
|
4892 | word += codePointToString$1(esc);
|
4893 | chunkStart = this.pos;
|
4894 | } else {
|
4895 | break
|
4896 | }
|
4897 | first = false;
|
4898 | }
|
4899 | return word + this.input.slice(chunkStart, this.pos)
|
4900 | };
|
4901 |
|
4902 |
|
4903 |
|
4904 |
|
4905 | pp$9.readWord = function() {
|
4906 | var word = this.readWord1();
|
4907 | var type = types.name;
|
4908 | if (this.keywords.test(word)) {
|
4909 | if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
|
4910 | type = keywords$1[word];
|
4911 | }
|
4912 | return this.finishToken(type, word)
|
4913 | };
|
4914 |
|
4915 |
|
4916 |
|
4917 | var version = "6.4.0";
|
4918 |
|
4919 | Parser.acorn = {
|
4920 | Parser: Parser,
|
4921 | version: version,
|
4922 | defaultOptions: defaultOptions,
|
4923 | Position: Position,
|
4924 | SourceLocation: SourceLocation,
|
4925 | getLineInfo: getLineInfo,
|
4926 | Node: Node,
|
4927 | TokenType: TokenType,
|
4928 | tokTypes: types,
|
4929 | keywordTypes: keywords$1,
|
4930 | TokContext: TokContext,
|
4931 | tokContexts: types$1,
|
4932 | isIdentifierChar: isIdentifierChar,
|
4933 | isIdentifierStart: isIdentifierStart,
|
4934 | Token: Token,
|
4935 | isNewLine: isNewLine,
|
4936 | lineBreak: lineBreak,
|
4937 | lineBreakG: lineBreakG,
|
4938 | nonASCIIwhitespace: nonASCIIwhitespace
|
4939 | };
|
4940 |
|
4941 |
|
4942 |
|
4943 |
|
4944 |
|
4945 |
|
4946 |
|
4947 |
|
4948 | function parse(input, options) {
|
4949 | return Parser.parse(input, options)
|
4950 | }
|
4951 |
|
4952 |
|
4953 |
|
4954 |
|
4955 |
|
4956 | function parseExpressionAt(input, pos, options) {
|
4957 | return Parser.parseExpressionAt(input, pos, options)
|
4958 | }
|
4959 |
|
4960 |
|
4961 |
|
4962 |
|
4963 | function tokenizer(input, options) {
|
4964 | return Parser.tokenizer(input, options)
|
4965 | }
|
4966 |
|
4967 | var acorn = Object.freeze({
|
4968 | __proto__: null,
|
4969 | Node: Node,
|
4970 | Parser: Parser,
|
4971 | Position: Position,
|
4972 | SourceLocation: SourceLocation,
|
4973 | TokContext: TokContext,
|
4974 | Token: Token,
|
4975 | TokenType: TokenType,
|
4976 | defaultOptions: defaultOptions,
|
4977 | getLineInfo: getLineInfo,
|
4978 | isIdentifierChar: isIdentifierChar,
|
4979 | isIdentifierStart: isIdentifierStart,
|
4980 | isNewLine: isNewLine,
|
4981 | keywordTypes: keywords$1,
|
4982 | lineBreak: lineBreak,
|
4983 | lineBreakG: lineBreakG,
|
4984 | nonASCIIwhitespace: nonASCIIwhitespace,
|
4985 | parse: parse,
|
4986 | parseExpressionAt: parseExpressionAt,
|
4987 | tokContexts: types$1,
|
4988 | tokTypes: types,
|
4989 | tokenizer: tokenizer,
|
4990 | version: version
|
4991 | });
|
4992 |
|
4993 | var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
4994 |
|
4995 | function commonjsRequire () {
|
4996 | throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
4997 | }
|
4998 |
|
4999 | function unwrapExports (x) {
|
5000 | return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
5001 | }
|
5002 |
|
5003 | function createCommonjsModule(fn, module) {
|
5004 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
5005 | }
|
5006 |
|
5007 | var xhtml = {
|
5008 | quot: '\u0022',
|
5009 | amp: '&',
|
5010 | apos: '\u0027',
|
5011 | lt: '<',
|
5012 | gt: '>',
|
5013 | nbsp: '\u00A0',
|
5014 | iexcl: '\u00A1',
|
5015 | cent: '\u00A2',
|
5016 | pound: '\u00A3',
|
5017 | curren: '\u00A4',
|
5018 | yen: '\u00A5',
|
5019 | brvbar: '\u00A6',
|
5020 | sect: '\u00A7',
|
5021 | uml: '\u00A8',
|
5022 | copy: '\u00A9',
|
5023 | ordf: '\u00AA',
|
5024 | laquo: '\u00AB',
|
5025 | not: '\u00AC',
|
5026 | shy: '\u00AD',
|
5027 | reg: '\u00AE',
|
5028 | macr: '\u00AF',
|
5029 | deg: '\u00B0',
|
5030 | plusmn: '\u00B1',
|
5031 | sup2: '\u00B2',
|
5032 | sup3: '\u00B3',
|
5033 | acute: '\u00B4',
|
5034 | micro: '\u00B5',
|
5035 | para: '\u00B6',
|
5036 | middot: '\u00B7',
|
5037 | cedil: '\u00B8',
|
5038 | sup1: '\u00B9',
|
5039 | ordm: '\u00BA',
|
5040 | raquo: '\u00BB',
|
5041 | frac14: '\u00BC',
|
5042 | frac12: '\u00BD',
|
5043 | frac34: '\u00BE',
|
5044 | iquest: '\u00BF',
|
5045 | Agrave: '\u00C0',
|
5046 | Aacute: '\u00C1',
|
5047 | Acirc: '\u00C2',
|
5048 | Atilde: '\u00C3',
|
5049 | Auml: '\u00C4',
|
5050 | Aring: '\u00C5',
|
5051 | AElig: '\u00C6',
|
5052 | Ccedil: '\u00C7',
|
5053 | Egrave: '\u00C8',
|
5054 | Eacute: '\u00C9',
|
5055 | Ecirc: '\u00CA',
|
5056 | Euml: '\u00CB',
|
5057 | Igrave: '\u00CC',
|
5058 | Iacute: '\u00CD',
|
5059 | Icirc: '\u00CE',
|
5060 | Iuml: '\u00CF',
|
5061 | ETH: '\u00D0',
|
5062 | Ntilde: '\u00D1',
|
5063 | Ograve: '\u00D2',
|
5064 | Oacute: '\u00D3',
|
5065 | Ocirc: '\u00D4',
|
5066 | Otilde: '\u00D5',
|
5067 | Ouml: '\u00D6',
|
5068 | times: '\u00D7',
|
5069 | Oslash: '\u00D8',
|
5070 | Ugrave: '\u00D9',
|
5071 | Uacute: '\u00DA',
|
5072 | Ucirc: '\u00DB',
|
5073 | Uuml: '\u00DC',
|
5074 | Yacute: '\u00DD',
|
5075 | THORN: '\u00DE',
|
5076 | szlig: '\u00DF',
|
5077 | agrave: '\u00E0',
|
5078 | aacute: '\u00E1',
|
5079 | acirc: '\u00E2',
|
5080 | atilde: '\u00E3',
|
5081 | auml: '\u00E4',
|
5082 | aring: '\u00E5',
|
5083 | aelig: '\u00E6',
|
5084 | ccedil: '\u00E7',
|
5085 | egrave: '\u00E8',
|
5086 | eacute: '\u00E9',
|
5087 | ecirc: '\u00EA',
|
5088 | euml: '\u00EB',
|
5089 | igrave: '\u00EC',
|
5090 | iacute: '\u00ED',
|
5091 | icirc: '\u00EE',
|
5092 | iuml: '\u00EF',
|
5093 | eth: '\u00F0',
|
5094 | ntilde: '\u00F1',
|
5095 | ograve: '\u00F2',
|
5096 | oacute: '\u00F3',
|
5097 | ocirc: '\u00F4',
|
5098 | otilde: '\u00F5',
|
5099 | ouml: '\u00F6',
|
5100 | divide: '\u00F7',
|
5101 | oslash: '\u00F8',
|
5102 | ugrave: '\u00F9',
|
5103 | uacute: '\u00FA',
|
5104 | ucirc: '\u00FB',
|
5105 | uuml: '\u00FC',
|
5106 | yacute: '\u00FD',
|
5107 | thorn: '\u00FE',
|
5108 | yuml: '\u00FF',
|
5109 | OElig: '\u0152',
|
5110 | oelig: '\u0153',
|
5111 | Scaron: '\u0160',
|
5112 | scaron: '\u0161',
|
5113 | Yuml: '\u0178',
|
5114 | fnof: '\u0192',
|
5115 | circ: '\u02C6',
|
5116 | tilde: '\u02DC',
|
5117 | Alpha: '\u0391',
|
5118 | Beta: '\u0392',
|
5119 | Gamma: '\u0393',
|
5120 | Delta: '\u0394',
|
5121 | Epsilon: '\u0395',
|
5122 | Zeta: '\u0396',
|
5123 | Eta: '\u0397',
|
5124 | Theta: '\u0398',
|
5125 | Iota: '\u0399',
|
5126 | Kappa: '\u039A',
|
5127 | Lambda: '\u039B',
|
5128 | Mu: '\u039C',
|
5129 | Nu: '\u039D',
|
5130 | Xi: '\u039E',
|
5131 | Omicron: '\u039F',
|
5132 | Pi: '\u03A0',
|
5133 | Rho: '\u03A1',
|
5134 | Sigma: '\u03A3',
|
5135 | Tau: '\u03A4',
|
5136 | Upsilon: '\u03A5',
|
5137 | Phi: '\u03A6',
|
5138 | Chi: '\u03A7',
|
5139 | Psi: '\u03A8',
|
5140 | Omega: '\u03A9',
|
5141 | alpha: '\u03B1',
|
5142 | beta: '\u03B2',
|
5143 | gamma: '\u03B3',
|
5144 | delta: '\u03B4',
|
5145 | epsilon: '\u03B5',
|
5146 | zeta: '\u03B6',
|
5147 | eta: '\u03B7',
|
5148 | theta: '\u03B8',
|
5149 | iota: '\u03B9',
|
5150 | kappa: '\u03BA',
|
5151 | lambda: '\u03BB',
|
5152 | mu: '\u03BC',
|
5153 | nu: '\u03BD',
|
5154 | xi: '\u03BE',
|
5155 | omicron: '\u03BF',
|
5156 | pi: '\u03C0',
|
5157 | rho: '\u03C1',
|
5158 | sigmaf: '\u03C2',
|
5159 | sigma: '\u03C3',
|
5160 | tau: '\u03C4',
|
5161 | upsilon: '\u03C5',
|
5162 | phi: '\u03C6',
|
5163 | chi: '\u03C7',
|
5164 | psi: '\u03C8',
|
5165 | omega: '\u03C9',
|
5166 | thetasym: '\u03D1',
|
5167 | upsih: '\u03D2',
|
5168 | piv: '\u03D6',
|
5169 | ensp: '\u2002',
|
5170 | emsp: '\u2003',
|
5171 | thinsp: '\u2009',
|
5172 | zwnj: '\u200C',
|
5173 | zwj: '\u200D',
|
5174 | lrm: '\u200E',
|
5175 | rlm: '\u200F',
|
5176 | ndash: '\u2013',
|
5177 | mdash: '\u2014',
|
5178 | lsquo: '\u2018',
|
5179 | rsquo: '\u2019',
|
5180 | sbquo: '\u201A',
|
5181 | ldquo: '\u201C',
|
5182 | rdquo: '\u201D',
|
5183 | bdquo: '\u201E',
|
5184 | dagger: '\u2020',
|
5185 | Dagger: '\u2021',
|
5186 | bull: '\u2022',
|
5187 | hellip: '\u2026',
|
5188 | permil: '\u2030',
|
5189 | prime: '\u2032',
|
5190 | Prime: '\u2033',
|
5191 | lsaquo: '\u2039',
|
5192 | rsaquo: '\u203A',
|
5193 | oline: '\u203E',
|
5194 | frasl: '\u2044',
|
5195 | euro: '\u20AC',
|
5196 | image: '\u2111',
|
5197 | weierp: '\u2118',
|
5198 | real: '\u211C',
|
5199 | trade: '\u2122',
|
5200 | alefsym: '\u2135',
|
5201 | larr: '\u2190',
|
5202 | uarr: '\u2191',
|
5203 | rarr: '\u2192',
|
5204 | darr: '\u2193',
|
5205 | harr: '\u2194',
|
5206 | crarr: '\u21B5',
|
5207 | lArr: '\u21D0',
|
5208 | uArr: '\u21D1',
|
5209 | rArr: '\u21D2',
|
5210 | dArr: '\u21D3',
|
5211 | hArr: '\u21D4',
|
5212 | forall: '\u2200',
|
5213 | part: '\u2202',
|
5214 | exist: '\u2203',
|
5215 | empty: '\u2205',
|
5216 | nabla: '\u2207',
|
5217 | isin: '\u2208',
|
5218 | notin: '\u2209',
|
5219 | ni: '\u220B',
|
5220 | prod: '\u220F',
|
5221 | sum: '\u2211',
|
5222 | minus: '\u2212',
|
5223 | lowast: '\u2217',
|
5224 | radic: '\u221A',
|
5225 | prop: '\u221D',
|
5226 | infin: '\u221E',
|
5227 | ang: '\u2220',
|
5228 | and: '\u2227',
|
5229 | or: '\u2228',
|
5230 | cap: '\u2229',
|
5231 | cup: '\u222A',
|
5232 | 'int': '\u222B',
|
5233 | there4: '\u2234',
|
5234 | sim: '\u223C',
|
5235 | cong: '\u2245',
|
5236 | asymp: '\u2248',
|
5237 | ne: '\u2260',
|
5238 | equiv: '\u2261',
|
5239 | le: '\u2264',
|
5240 | ge: '\u2265',
|
5241 | sub: '\u2282',
|
5242 | sup: '\u2283',
|
5243 | nsub: '\u2284',
|
5244 | sube: '\u2286',
|
5245 | supe: '\u2287',
|
5246 | oplus: '\u2295',
|
5247 | otimes: '\u2297',
|
5248 | perp: '\u22A5',
|
5249 | sdot: '\u22C5',
|
5250 | lceil: '\u2308',
|
5251 | rceil: '\u2309',
|
5252 | lfloor: '\u230A',
|
5253 | rfloor: '\u230B',
|
5254 | lang: '\u2329',
|
5255 | rang: '\u232A',
|
5256 | loz: '\u25CA',
|
5257 | spades: '\u2660',
|
5258 | clubs: '\u2663',
|
5259 | hearts: '\u2665',
|
5260 | diams: '\u2666'
|
5261 | };
|
5262 |
|
5263 | var acornJsx = createCommonjsModule(function (module) {
|
5264 |
|
5265 |
|
5266 |
|
5267 | var hexNumber = /^[\da-fA-F]+$/;
|
5268 | var decimalNumber = /^\d+$/;
|
5269 |
|
5270 |
|
5271 | var acornJsxMap = new WeakMap();
|
5272 |
|
5273 |
|
5274 | function getJsxTokens(acorn) {
|
5275 | acorn = acorn.Parser.acorn || acorn;
|
5276 | var acornJsx = acornJsxMap.get(acorn);
|
5277 | if (!acornJsx) {
|
5278 | var tt = acorn.tokTypes;
|
5279 | var TokContext = acorn.TokContext;
|
5280 | var TokenType = acorn.TokenType;
|
5281 | var tc_oTag = new TokContext('<tag', false);
|
5282 | var tc_cTag = new TokContext('</tag', false);
|
5283 | var tc_expr = new TokContext('<tag>...</tag>', true, true);
|
5284 | var tokContexts = {
|
5285 | tc_oTag: tc_oTag,
|
5286 | tc_cTag: tc_cTag,
|
5287 | tc_expr: tc_expr
|
5288 | };
|
5289 | var tokTypes = {
|
5290 | jsxName: new TokenType('jsxName'),
|
5291 | jsxText: new TokenType('jsxText', {beforeExpr: true}),
|
5292 | jsxTagStart: new TokenType('jsxTagStart'),
|
5293 | jsxTagEnd: new TokenType('jsxTagEnd')
|
5294 | };
|
5295 |
|
5296 | tokTypes.jsxTagStart.updateContext = function() {
|
5297 | this.context.push(tc_expr);
|
5298 | this.context.push(tc_oTag);
|
5299 | this.exprAllowed = false;
|
5300 | };
|
5301 | tokTypes.jsxTagEnd.updateContext = function(prevType) {
|
5302 | var out = this.context.pop();
|
5303 | if (out === tc_oTag && prevType === tt.slash || out === tc_cTag) {
|
5304 | this.context.pop();
|
5305 | this.exprAllowed = this.curContext() === tc_expr;
|
5306 | } else {
|
5307 | this.exprAllowed = true;
|
5308 | }
|
5309 | };
|
5310 |
|
5311 | acornJsx = { tokContexts: tokContexts, tokTypes: tokTypes };
|
5312 | acornJsxMap.set(acorn, acornJsx);
|
5313 | }
|
5314 |
|
5315 | return acornJsx;
|
5316 | }
|
5317 |
|
5318 |
|
5319 |
|
5320 | function getQualifiedJSXName(object) {
|
5321 | if (!object)
|
5322 | { return object; }
|
5323 |
|
5324 | if (object.type === 'JSXIdentifier')
|
5325 | { return object.name; }
|
5326 |
|
5327 | if (object.type === 'JSXNamespacedName')
|
5328 | { return object.namespace.name + ':' + object.name.name; }
|
5329 |
|
5330 | if (object.type === 'JSXMemberExpression')
|
5331 | { return getQualifiedJSXName(object.object) + '.' +
|
5332 | getQualifiedJSXName(object.property); }
|
5333 | }
|
5334 |
|
5335 | module.exports = function(options) {
|
5336 | options = options || {};
|
5337 | return function(Parser) {
|
5338 | return plugin({
|
5339 | allowNamespaces: options.allowNamespaces !== false,
|
5340 | allowNamespacedObjects: !!options.allowNamespacedObjects
|
5341 | }, Parser);
|
5342 | };
|
5343 | };
|
5344 |
|
5345 |
|
5346 |
|
5347 | Object.defineProperty(module.exports, "tokTypes", {
|
5348 | get: function get_tokTypes() {
|
5349 | return getJsxTokens(acorn).tokTypes;
|
5350 | },
|
5351 | configurable: true,
|
5352 | enumerable: true
|
5353 | });
|
5354 |
|
5355 | function plugin(options, Parser) {
|
5356 | var acorn$1 = Parser.acorn || acorn;
|
5357 | var acornJsx = getJsxTokens(acorn$1);
|
5358 | var tt = acorn$1.tokTypes;
|
5359 | var tok = acornJsx.tokTypes;
|
5360 | var tokContexts = acorn$1.tokContexts;
|
5361 | var tc_oTag = acornJsx.tokContexts.tc_oTag;
|
5362 | var tc_cTag = acornJsx.tokContexts.tc_cTag;
|
5363 | var tc_expr = acornJsx.tokContexts.tc_expr;
|
5364 | var isNewLine = acorn$1.isNewLine;
|
5365 | var isIdentifierStart = acorn$1.isIdentifierStart;
|
5366 | var isIdentifierChar = acorn$1.isIdentifierChar;
|
5367 |
|
5368 | return (function (Parser) {
|
5369 | function anonymous () {
|
5370 | Parser.apply(this, arguments);
|
5371 | }
|
5372 |
|
5373 | if ( Parser ) anonymous.__proto__ = Parser;
|
5374 | anonymous.prototype = Object.create( Parser && Parser.prototype );
|
5375 | anonymous.prototype.constructor = anonymous;
|
5376 |
|
5377 | var staticAccessors = { acornJsx: { configurable: true } };
|
5378 |
|
5379 | staticAccessors.acornJsx.get = function () {
|
5380 | return acornJsx;
|
5381 | };
|
5382 |
|
5383 |
|
5384 | anonymous.prototype.jsx_readToken = function jsx_readToken () {
|
5385 | var out = '', chunkStart = this.pos;
|
5386 | for (;;) {
|
5387 | if (this.pos >= this.input.length)
|
5388 | { this.raise(this.start, 'Unterminated JSX contents'); }
|
5389 | var ch = this.input.charCodeAt(this.pos);
|
5390 |
|
5391 | switch (ch) {
|
5392 | case 60:
|
5393 | case 123:
|
5394 | if (this.pos === this.start) {
|
5395 | if (ch === 60 && this.exprAllowed) {
|
5396 | ++this.pos;
|
5397 | return this.finishToken(tok.jsxTagStart);
|
5398 | }
|
5399 | return this.getTokenFromCode(ch);
|
5400 | }
|
5401 | out += this.input.slice(chunkStart, this.pos);
|
5402 | return this.finishToken(tok.jsxText, out);
|
5403 |
|
5404 | case 38:
|
5405 | out += this.input.slice(chunkStart, this.pos);
|
5406 | out += this.jsx_readEntity();
|
5407 | chunkStart = this.pos;
|
5408 | break;
|
5409 |
|
5410 | case 62:
|
5411 | case 125:
|
5412 | this.raise(
|
5413 | this.pos,
|
5414 | "Unexpected token `" + this.input[this.pos] + "`. Did you mean `" +
|
5415 | (ch === 62 ? ">" : "}") + "` or " + "`{\"" + this.input[this.pos] + "\"}" + "`?"
|
5416 | );
|
5417 |
|
5418 | default:
|
5419 | if (isNewLine(ch)) {
|
5420 | out += this.input.slice(chunkStart, this.pos);
|
5421 | out += this.jsx_readNewLine(true);
|
5422 | chunkStart = this.pos;
|
5423 | } else {
|
5424 | ++this.pos;
|
5425 | }
|
5426 | }
|
5427 | }
|
5428 | };
|
5429 |
|
5430 | anonymous.prototype.jsx_readNewLine = function jsx_readNewLine (normalizeCRLF) {
|
5431 | var ch = this.input.charCodeAt(this.pos);
|
5432 | var out;
|
5433 | ++this.pos;
|
5434 | if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
|
5435 | ++this.pos;
|
5436 | out = normalizeCRLF ? '\n' : '\r\n';
|
5437 | } else {
|
5438 | out = String.fromCharCode(ch);
|
5439 | }
|
5440 | if (this.options.locations) {
|
5441 | ++this.curLine;
|
5442 | this.lineStart = this.pos;
|
5443 | }
|
5444 |
|
5445 | return out;
|
5446 | };
|
5447 |
|
5448 | anonymous.prototype.jsx_readString = function jsx_readString (quote) {
|
5449 | var out = '', chunkStart = ++this.pos;
|
5450 | for (;;) {
|
5451 | if (this.pos >= this.input.length)
|
5452 | { this.raise(this.start, 'Unterminated string constant'); }
|
5453 | var ch = this.input.charCodeAt(this.pos);
|
5454 | if (ch === quote) { break; }
|
5455 | if (ch === 38) {
|
5456 | out += this.input.slice(chunkStart, this.pos);
|
5457 | out += this.jsx_readEntity();
|
5458 | chunkStart = this.pos;
|
5459 | } else if (isNewLine(ch)) {
|
5460 | out += this.input.slice(chunkStart, this.pos);
|
5461 | out += this.jsx_readNewLine(false);
|
5462 | chunkStart = this.pos;
|
5463 | } else {
|
5464 | ++this.pos;
|
5465 | }
|
5466 | }
|
5467 | out += this.input.slice(chunkStart, this.pos++);
|
5468 | return this.finishToken(tt.string, out);
|
5469 | };
|
5470 |
|
5471 | anonymous.prototype.jsx_readEntity = function jsx_readEntity () {
|
5472 | var str = '', count = 0, entity;
|
5473 | var ch = this.input[this.pos];
|
5474 | if (ch !== '&')
|
5475 | { this.raise(this.pos, 'Entity must start with an ampersand'); }
|
5476 | var startPos = ++this.pos;
|
5477 | while (this.pos < this.input.length && count++ < 10) {
|
5478 | ch = this.input[this.pos++];
|
5479 | if (ch === ';') {
|
5480 | if (str[0] === '#') {
|
5481 | if (str[1] === 'x') {
|
5482 | str = str.substr(2);
|
5483 | if (hexNumber.test(str))
|
5484 | { entity = String.fromCharCode(parseInt(str, 16)); }
|
5485 | } else {
|
5486 | str = str.substr(1);
|
5487 | if (decimalNumber.test(str))
|
5488 | { entity = String.fromCharCode(parseInt(str, 10)); }
|
5489 | }
|
5490 | } else {
|
5491 | entity = xhtml[str];
|
5492 | }
|
5493 | break;
|
5494 | }
|
5495 | str += ch;
|
5496 | }
|
5497 | if (!entity) {
|
5498 | this.pos = startPos;
|
5499 | return '&';
|
5500 | }
|
5501 | return entity;
|
5502 | };
|
5503 |
|
5504 | // Read a JSX identifier (valid tag or attribute name).
|
5505 | //
|
5506 | // Optimized version since JSX identifiers can't contain
|
5507 | // escape characters and so can be read as single slice.
|
5508 | // Also assumes that first character was already checked
|
5509 | // by isIdentifierStart in readToken.
|
5510 |
|
5511 | anonymous.prototype.jsx_readWord = function jsx_readWord () {
|
5512 | var ch, start = this.pos;
|
5513 | do {
|
5514 | ch = this.input.charCodeAt(++this.pos);
|
5515 | } while (isIdentifierChar(ch) || ch === 45); // '-'
|
5516 | return this.finishToken(tok.jsxName, this.input.slice(start, this.pos));
|
5517 | };
|
5518 |
|
5519 | // Parse next token as JSX identifier
|
5520 |
|
5521 | anonymous.prototype.jsx_parseIdentifier = function jsx_parseIdentifier () {
|
5522 | var node = this.startNode();
|
5523 | if (this.type === tok.jsxName)
|
5524 | { node.name = this.value; }
|
5525 | else if (this.type.keyword)
|
5526 | { node.name = this.type.keyword; }
|
5527 | else
|
5528 | { this.unexpected(); }
|
5529 | this.next();
|
5530 | return this.finishNode(node, 'JSXIdentifier');
|
5531 | };
|
5532 |
|
5533 | // Parse namespaced identifier.
|
5534 |
|
5535 | anonymous.prototype.jsx_parseNamespacedName = function jsx_parseNamespacedName () {
|
5536 | var startPos = this.start, startLoc = this.startLoc;
|
5537 | var name = this.jsx_parseIdentifier();
|
5538 | if (!options.allowNamespaces || !this.eat(tt.colon)) { return name; }
|
5539 | var node = this.startNodeAt(startPos, startLoc);
|
5540 | node.namespace = name;
|
5541 | node.name = this.jsx_parseIdentifier();
|
5542 | return this.finishNode(node, 'JSXNamespacedName');
|
5543 | };
|
5544 |
|
5545 | // Parses element name in any form - namespaced, member
|
5546 | // or single identifier.
|
5547 |
|
5548 | anonymous.prototype.jsx_parseElementName = function jsx_parseElementName () {
|
5549 | if (this.type === tok.jsxTagEnd) { return ''; }
|
5550 | var startPos = this.start, startLoc = this.startLoc;
|
5551 | var node = this.jsx_parseNamespacedName();
|
5552 | if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !options.allowNamespacedObjects) {
|
5553 | this.unexpected();
|
5554 | }
|
5555 | while (this.eat(tt.dot)) {
|
5556 | var newNode = this.startNodeAt(startPos, startLoc);
|
5557 | newNode.object = node;
|
5558 | newNode.property = this.jsx_parseIdentifier();
|
5559 | node = this.finishNode(newNode, 'JSXMemberExpression');
|
5560 | }
|
5561 | return node;
|
5562 | };
|
5563 |
|
5564 | // Parses any type of JSX attribute value.
|
5565 |
|
5566 | anonymous.prototype.jsx_parseAttributeValue = function jsx_parseAttributeValue () {
|
5567 | switch (this.type) {
|
5568 | case tt.braceL:
|
5569 | var node = this.jsx_parseExpressionContainer();
|
5570 | if (node.expression.type === 'JSXEmptyExpression')
|
5571 | { this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression'); }
|
5572 | return node;
|
5573 |
|
5574 | case tok.jsxTagStart:
|
5575 | case tt.string:
|
5576 | return this.parseExprAtom();
|
5577 |
|
5578 | default:
|
5579 | this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
|
5580 | }
|
5581 | };
|
5582 |
|
5583 | // JSXEmptyExpression is unique type since it doesn't actually parse anything,
|
5584 | // and so it should start at the end of last read token (left brace) and finish
|
5585 | // at the beginning of the next one (right brace).
|
5586 |
|
5587 | anonymous.prototype.jsx_parseEmptyExpression = function jsx_parseEmptyExpression () {
|
5588 | var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
|
5589 | return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
|
5590 | };
|
5591 |
|
5592 | // Parses JSX expression enclosed into curly brackets.
|
5593 |
|
5594 | anonymous.prototype.jsx_parseExpressionContainer = function jsx_parseExpressionContainer () {
|
5595 | var node = this.startNode();
|
5596 | this.next();
|
5597 | node.expression = this.type === tt.braceR
|
5598 | ? this.jsx_parseEmptyExpression()
|
5599 | : this.parseExpression();
|
5600 | this.expect(tt.braceR);
|
5601 | return this.finishNode(node, 'JSXExpressionContainer');
|
5602 | };
|
5603 |
|
5604 | // Parses following JSX attribute name-value pair.
|
5605 |
|
5606 | anonymous.prototype.jsx_parseAttribute = function jsx_parseAttribute () {
|
5607 | var node = this.startNode();
|
5608 | if (this.eat(tt.braceL)) {
|
5609 | this.expect(tt.ellipsis);
|
5610 | node.argument = this.parseMaybeAssign();
|
5611 | this.expect(tt.braceR);
|
5612 | return this.finishNode(node, 'JSXSpreadAttribute');
|
5613 | }
|
5614 | node.name = this.jsx_parseNamespacedName();
|
5615 | node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
|
5616 | return this.finishNode(node, 'JSXAttribute');
|
5617 | };
|
5618 |
|
5619 | // Parses JSX opening tag starting after '<'.
|
5620 |
|
5621 | anonymous.prototype.jsx_parseOpeningElementAt = function jsx_parseOpeningElementAt (startPos, startLoc) {
|
5622 | var node = this.startNodeAt(startPos, startLoc);
|
5623 | node.attributes = [];
|
5624 | var nodeName = this.jsx_parseElementName();
|
5625 | if (nodeName) { node.name = nodeName; }
|
5626 | while (this.type !== tt.slash && this.type !== tok.jsxTagEnd)
|
5627 | { node.attributes.push(this.jsx_parseAttribute()); }
|
5628 | node.selfClosing = this.eat(tt.slash);
|
5629 | this.expect(tok.jsxTagEnd);
|
5630 | return this.finishNode(node, nodeName ? 'JSXOpeningElement' : 'JSXOpeningFragment');
|
5631 | };
|
5632 |
|
5633 | // Parses JSX closing tag starting after '</'.
|
5634 |
|
5635 | anonymous.prototype.jsx_parseClosingElementAt = function jsx_parseClosingElementAt (startPos, startLoc) {
|
5636 | var node = this.startNodeAt(startPos, startLoc);
|
5637 | var nodeName = this.jsx_parseElementName();
|
5638 | if (nodeName) { node.name = nodeName; }
|
5639 | this.expect(tok.jsxTagEnd);
|
5640 | return this.finishNode(node, nodeName ? 'JSXClosingElement' : 'JSXClosingFragment');
|
5641 | };
|
5642 |
|
5643 | // Parses entire JSX element, including it's opening tag
|
5644 | // (starting after '<'), attributes, contents and closing tag.
|
5645 |
|
5646 | anonymous.prototype.jsx_parseElementAt = function jsx_parseElementAt (startPos, startLoc) {
|
5647 | var node = this.startNodeAt(startPos, startLoc);
|
5648 | var children = [];
|
5649 | var openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
|
5650 | var closingElement = null;
|
5651 |
|
5652 | if (!openingElement.selfClosing) {
|
5653 | contents: for (;;) {
|
5654 | switch (this.type) {
|
5655 | case tok.jsxTagStart:
|
5656 | startPos = this.start; startLoc = this.startLoc;
|
5657 | this.next();
|
5658 | if (this.eat(tt.slash)) {
|
5659 | closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
|
5660 | break contents;
|
5661 | }
|
5662 | children.push(this.jsx_parseElementAt(startPos, startLoc));
|
5663 | break;
|
5664 |
|
5665 | case tok.jsxText:
|
5666 | children.push(this.parseExprAtom());
|
5667 | break;
|
5668 |
|
5669 | case tt.braceL:
|
5670 | children.push(this.jsx_parseExpressionContainer());
|
5671 | break;
|
5672 |
|
5673 | default:
|
5674 | this.unexpected();
|
5675 | }
|
5676 | }
|
5677 | if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
|
5678 | this.raise(
|
5679 | closingElement.start,
|
5680 | 'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
|
5681 | }
|
5682 | }
|
5683 | var fragmentOrElement = openingElement.name ? 'Element' : 'Fragment';
|
5684 |
|
5685 | node['opening' + fragmentOrElement] = openingElement;
|
5686 | node['closing' + fragmentOrElement] = closingElement;
|
5687 | node.children = children;
|
5688 | if (this.type === tt.relational && this.value === "<") {
|
5689 | this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
|
5690 | }
|
5691 | return this.finishNode(node, 'JSX' + fragmentOrElement);
|
5692 | };
|
5693 |
|
5694 | // Parse JSX text
|
5695 |
|
5696 | anonymous.prototype.jsx_parseText = function jsx_parseText () {
|
5697 | var node = this.parseLiteral(this.value);
|
5698 | node.type = "JSXText";
|
5699 | return node;
|
5700 | };
|
5701 |
|
5702 | // Parses entire JSX element from current position.
|
5703 |
|
5704 | anonymous.prototype.jsx_parseElement = function jsx_parseElement () {
|
5705 | var startPos = this.start, startLoc = this.startLoc;
|
5706 | this.next();
|
5707 | return this.jsx_parseElementAt(startPos, startLoc);
|
5708 | };
|
5709 |
|
5710 | anonymous.prototype.parseExprAtom = function parseExprAtom (refShortHandDefaultPos) {
|
5711 | if (this.type === tok.jsxText)
|
5712 | { return this.jsx_parseText(); }
|
5713 | else if (this.type === tok.jsxTagStart)
|
5714 | { return this.jsx_parseElement(); }
|
5715 | else
|
5716 | { return Parser.prototype.parseExprAtom.call(this, refShortHandDefaultPos); }
|
5717 | };
|
5718 |
|
5719 | anonymous.prototype.readToken = function readToken (code) {
|
5720 | var context = this.curContext();
|
5721 |
|
5722 | if (context === tc_expr) { return this.jsx_readToken(); }
|
5723 |
|
5724 | if (context === tc_oTag || context === tc_cTag) {
|
5725 | if (isIdentifierStart(code)) { return this.jsx_readWord(); }
|
5726 |
|
5727 | if (code == 62) {
|
5728 | ++this.pos;
|
5729 | return this.finishToken(tok.jsxTagEnd);
|
5730 | }
|
5731 |
|
5732 | if ((code === 34 || code === 39) && context == tc_oTag)
|
5733 | { return this.jsx_readString(code); }
|
5734 | }
|
5735 |
|
5736 | if (code === 60 && this.exprAllowed && this.input.charCodeAt(this.pos + 1) !== 33) {
|
5737 | ++this.pos;
|
5738 | return this.finishToken(tok.jsxTagStart);
|
5739 | }
|
5740 | return Parser.prototype.readToken.call(this, code);
|
5741 | };
|
5742 |
|
5743 | anonymous.prototype.updateContext = function updateContext (prevType) {
|
5744 | if (this.type == tt.braceL) {
|
5745 | var curContext = this.curContext();
|
5746 | if (curContext == tc_oTag) { this.context.push(tokContexts.b_expr); }
|
5747 | else if (curContext == tc_expr) { this.context.push(tokContexts.b_tmpl); }
|
5748 | else { Parser.prototype.updateContext.call(this, prevType); }
|
5749 | this.exprAllowed = true;
|
5750 | } else if (this.type === tt.slash && prevType === tok.jsxTagStart) {
|
5751 | this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
|
5752 | this.context.push(tc_cTag); // reconsider as closing tag context
|
5753 | this.exprAllowed = false;
|
5754 | } else {
|
5755 | return Parser.prototype.updateContext.call(this, prevType);
|
5756 | }
|
5757 | };
|
5758 |
|
5759 | Object.defineProperties( anonymous, staticAccessors );
|
5760 |
|
5761 | return anonymous;
|
5762 | }(Parser));
|
5763 | }
|
5764 | });
|
5765 |
|
5766 | var lib = createCommonjsModule(function (module, exports) {
|
5767 |
|
5768 | Object.defineProperty(exports, "__esModule", {
|
5769 | value: true
|
5770 | });
|
5771 | exports.DynamicImportKey = undefined;
|
5772 |
|
5773 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
5774 |
|
5775 | var _get = function () {
|
5776 | function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }
|
5777 |
|
5778 | return get;
|
5779 | }();
|
5780 |
|
5781 | exports['default'] = dynamicImport;
|
5782 |
|
5783 |
|
5784 |
|
5785 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
5786 |
|
5787 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
5788 |
|
5789 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* eslint-disable no-underscore-dangle */
|
5790 |
|
5791 |
|
5792 | var DynamicImportKey = exports.DynamicImportKey = 'Import';
|
5793 |
|
5794 | // NOTE: This allows `yield import()` to parse correctly.
|
5795 | acorn.tokTypes._import.startsExpr = true;
|
5796 |
|
5797 | function parseDynamicImport() {
|
5798 | var node = this.startNode();
|
5799 | this.next();
|
5800 | if (this.type !== acorn.tokTypes.parenL) {
|
5801 | this.unexpected();
|
5802 | }
|
5803 | return this.finishNode(node, DynamicImportKey);
|
5804 | }
|
5805 |
|
5806 | function parenAfter() {
|
5807 | return (/^(\s|\/\/.*|\/\*[^]*?\*\/)*\(/.test(this.input.slice(this.pos))
|
5808 | );
|
5809 | }
|
5810 |
|
5811 | function dynamicImport(Parser) {
|
5812 | return function (_Parser) {
|
5813 | _inherits(_class, _Parser);
|
5814 |
|
5815 | function _class() {
|
5816 | _classCallCheck(this, _class);
|
5817 |
|
5818 | return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments));
|
5819 | }
|
5820 |
|
5821 | _createClass(_class, [{
|
5822 | key: 'parseStatement',
|
5823 | value: function () {
|
5824 | function parseStatement(context, topLevel, exports) {
|
5825 | if (this.type === acorn.tokTypes._import && parenAfter.call(this)) {
|
5826 | return this.parseExpressionStatement(this.startNode(), this.parseExpression());
|
5827 | }
|
5828 | return _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'parseStatement', this).call(this, context, topLevel, exports);
|
5829 | }
|
5830 |
|
5831 | return parseStatement;
|
5832 | }()
|
5833 | }, {
|
5834 | key: 'parseExprAtom',
|
5835 | value: function () {
|
5836 | function parseExprAtom(refDestructuringErrors) {
|
5837 | if (this.type === acorn.tokTypes._import) {
|
5838 | return parseDynamicImport.call(this);
|
5839 | }
|
5840 | return _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'parseExprAtom', this).call(this, refDestructuringErrors);
|
5841 | }
|
5842 |
|
5843 | return parseExprAtom;
|
5844 | }()
|
5845 | }]);
|
5846 |
|
5847 | return _class;
|
5848 | }(Parser);
|
5849 | }
|
5850 | });
|
5851 |
|
5852 | var acornDynamicImport = unwrapExports(lib);
|
5853 | var lib_1 = lib.DynamicImportKey;
|
5854 |
|
5855 | var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
5856 | function encode(decoded) {
|
5857 | var sourceFileIndex = 0; // second field
|
5858 | var sourceCodeLine = 0; // third field
|
5859 | var sourceCodeColumn = 0; // fourth field
|
5860 | var nameIndex = 0; // fifth field
|
5861 | var mappings = '';
|
5862 | for (var i = 0; i < decoded.length; i++) {
|
5863 | var line = decoded[i];
|
5864 | if (i > 0)
|
5865 | mappings += ';';
|
5866 | if (line.length === 0)
|
5867 | continue;
|
5868 | var generatedCodeColumn = 0; // first field
|
5869 | var lineMappings = [];
|
5870 | for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {
|
5871 | var segment = line_1[_i];
|
5872 | var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn);
|
5873 | generatedCodeColumn = segment[0];
|
5874 | if (segment.length > 1) {
|
5875 | segmentMappings +=
|
5876 | encodeInteger(segment[1] - sourceFileIndex) +
|
5877 | encodeInteger(segment[2] - sourceCodeLine) +
|
5878 | encodeInteger(segment[3] - sourceCodeColumn);
|
5879 | sourceFileIndex = segment[1];
|
5880 | sourceCodeLine = segment[2];
|
5881 | sourceCodeColumn = segment[3];
|
5882 | }
|
5883 | if (segment.length === 5) {
|
5884 | segmentMappings += encodeInteger(segment[4] - nameIndex);
|
5885 | nameIndex = segment[4];
|
5886 | }
|
5887 | lineMappings.push(segmentMappings);
|
5888 | }
|
5889 | mappings += lineMappings.join(',');
|
5890 | }
|
5891 | return mappings;
|
5892 | }
|
5893 | function encodeInteger(num) {
|
5894 | var result = '';
|
5895 | num = num < 0 ? (-num << 1) | 1 : num << 1;
|
5896 | do {
|
5897 | var clamped = num & 31;
|
5898 | num >>>= 5;
|
5899 | if (num > 0) {
|
5900 | clamped |= 32;
|
5901 | }
|
5902 | result += chars[clamped];
|
5903 | } while (num > 0);
|
5904 | return result;
|
5905 | }
|
5906 |
|
5907 | var BitSet = function BitSet(arg) {
|
5908 | this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
5909 | };
|
5910 |
|
5911 | BitSet.prototype.add = function add (n) {
|
5912 | this.bits[n >> 5] |= 1 << (n & 31);
|
5913 | };
|
5914 |
|
5915 | BitSet.prototype.has = function has (n) {
|
5916 | return !!(this.bits[n >> 5] & (1 << (n & 31)));
|
5917 | };
|
5918 |
|
5919 | var Chunk = function Chunk(start, end, content) {
|
5920 | this.start = start;
|
5921 | this.end = end;
|
5922 | this.original = content;
|
5923 |
|
5924 | this.intro = '';
|
5925 | this.outro = '';
|
5926 |
|
5927 | this.content = content;
|
5928 | this.storeName = false;
|
5929 | this.edited = false;
|
5930 |
|
5931 | // we make these non-enumerable, for sanity while debugging
|
5932 | Object.defineProperties(this, {
|
5933 | previous: { writable: true, value: null },
|
5934 | next: { writable: true, value: null }
|
5935 | });
|
5936 | };
|
5937 |
|
5938 | Chunk.prototype.appendLeft = function appendLeft (content) {
|
5939 | this.outro += content;
|
5940 | };
|
5941 |
|
5942 | Chunk.prototype.appendRight = function appendRight (content) {
|
5943 | this.intro = this.intro + content;
|
5944 | };
|
5945 |
|
5946 | Chunk.prototype.clone = function clone () {
|
5947 | var chunk = new Chunk(this.start, this.end, this.original);
|
5948 |
|
5949 | chunk.intro = this.intro;
|
5950 | chunk.outro = this.outro;
|
5951 | chunk.content = this.content;
|
5952 | chunk.storeName = this.storeName;
|
5953 | chunk.edited = this.edited;
|
5954 |
|
5955 | return chunk;
|
5956 | };
|
5957 |
|
5958 | Chunk.prototype.contains = function contains (index) {
|
5959 | return this.start < index && index < this.end;
|
5960 | };
|
5961 |
|
5962 | Chunk.prototype.eachNext = function eachNext (fn) {
|
5963 | var chunk = this;
|
5964 | while (chunk) {
|
5965 | fn(chunk);
|
5966 | chunk = chunk.next;
|
5967 | }
|
5968 | };
|
5969 |
|
5970 | Chunk.prototype.eachPrevious = function eachPrevious (fn) {
|
5971 | var chunk = this;
|
5972 | while (chunk) {
|
5973 | fn(chunk);
|
5974 | chunk = chunk.previous;
|
5975 | }
|
5976 | };
|
5977 |
|
5978 | Chunk.prototype.edit = function edit (content, storeName, contentOnly) {
|
5979 | this.content = content;
|
5980 | if (!contentOnly) {
|
5981 | this.intro = '';
|
5982 | this.outro = '';
|
5983 | }
|
5984 | this.storeName = storeName;
|
5985 |
|
5986 | this.edited = true;
|
5987 |
|
5988 | return this;
|
5989 | };
|
5990 |
|
5991 | Chunk.prototype.prependLeft = function prependLeft (content) {
|
5992 | this.outro = content + this.outro;
|
5993 | };
|
5994 |
|
5995 | Chunk.prototype.prependRight = function prependRight (content) {
|
5996 | this.intro = content + this.intro;
|
5997 | };
|
5998 |
|
5999 | Chunk.prototype.split = function split (index) {
|
6000 | var sliceIndex = index - this.start;
|
6001 |
|
6002 | var originalBefore = this.original.slice(0, sliceIndex);
|
6003 | var originalAfter = this.original.slice(sliceIndex);
|
6004 |
|
6005 | this.original = originalBefore;
|
6006 |
|
6007 | var newChunk = new Chunk(index, this.end, originalAfter);
|
6008 | newChunk.outro = this.outro;
|
6009 | this.outro = '';
|
6010 |
|
6011 | this.end = index;
|
6012 |
|
6013 | if (this.edited) {
|
6014 | // TODO is this block necessary?...
|
6015 | newChunk.edit('', false);
|
6016 | this.content = '';
|
6017 | } else {
|
6018 | this.content = originalBefore;
|
6019 | }
|
6020 |
|
6021 | newChunk.next = this.next;
|
6022 | if (newChunk.next) { newChunk.next.previous = newChunk; }
|
6023 | newChunk.previous = this;
|
6024 | this.next = newChunk;
|
6025 |
|
6026 | return newChunk;
|
6027 | };
|
6028 |
|
6029 | Chunk.prototype.toString = function toString () {
|
6030 | return this.intro + this.content + this.outro;
|
6031 | };
|
6032 |
|
6033 | Chunk.prototype.trimEnd = function trimEnd (rx) {
|
6034 | this.outro = this.outro.replace(rx, '');
|
6035 | if (this.outro.length) { return true; }
|
6036 |
|
6037 | var trimmed = this.content.replace(rx, '');
|
6038 |
|
6039 | if (trimmed.length) {
|
6040 | if (trimmed !== this.content) {
|
6041 | this.split(this.start + trimmed.length).edit('', undefined, true);
|
6042 | }
|
6043 | return true;
|
6044 |
|
6045 | } else {
|
6046 | this.edit('', undefined, true);
|
6047 |
|
6048 | this.intro = this.intro.replace(rx, '');
|
6049 | if (this.intro.length) { return true; }
|
6050 | }
|
6051 | };
|
6052 |
|
6053 | Chunk.prototype.trimStart = function trimStart (rx) {
|
6054 | this.intro = this.intro.replace(rx, '');
|
6055 | if (this.intro.length) { return true; }
|
6056 |
|
6057 | var trimmed = this.content.replace(rx, '');
|
6058 |
|
6059 | if (trimmed.length) {
|
6060 | if (trimmed !== this.content) {
|
6061 | this.split(this.end - trimmed.length);
|
6062 | this.edit('', undefined, true);
|
6063 | }
|
6064 | return true;
|
6065 |
|
6066 | } else {
|
6067 | this.edit('', undefined, true);
|
6068 |
|
6069 | this.outro = this.outro.replace(rx, '');
|
6070 | if (this.outro.length) { return true; }
|
6071 | }
|
6072 | };
|
6073 |
|
6074 | var btoa = function () {
|
6075 | throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
6076 | };
|
6077 | if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
6078 | btoa = function (str) { return window.btoa(unescape(encodeURIComponent(str))); };
|
6079 | } else if (typeof Buffer === 'function') {
|
6080 | btoa = function (str) { return Buffer.from(str, 'utf-8').toString('base64'); };
|
6081 | }
|
6082 |
|
6083 | var SourceMap = function SourceMap(properties) {
|
6084 | this.version = 3;
|
6085 | this.file = properties.file;
|
6086 | this.sources = properties.sources;
|
6087 | this.sourcesContent = properties.sourcesContent;
|
6088 | this.names = properties.names;
|
6089 | this.mappings = encode(properties.mappings);
|
6090 | };
|
6091 |
|
6092 | SourceMap.prototype.toString = function toString () {
|
6093 | return JSON.stringify(this);
|
6094 | };
|
6095 |
|
6096 | SourceMap.prototype.toUrl = function toUrl () {
|
6097 | return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
|
6098 | };
|
6099 |
|
6100 | function guessIndent(code) {
|
6101 | var lines = code.split('\n');
|
6102 |
|
6103 | var tabbed = lines.filter(function (line) { return /^\t+/.test(line); });
|
6104 | var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); });
|
6105 |
|
6106 | if (tabbed.length === 0 && spaced.length === 0) {
|
6107 | return null;
|
6108 | }
|
6109 |
|
6110 | // More lines tabbed than spaced? Assume tabs, and
|
6111 | // default to tabs in the case of a tie (or nothing
|
6112 | // to go on)
|
6113 | if (tabbed.length >= spaced.length) {
|
6114 | return '\t';
|
6115 | }
|
6116 |
|
6117 | // Otherwise, we need to guess the multiple
|
6118 | var min = spaced.reduce(function (previous, current) {
|
6119 | var numSpaces = /^ +/.exec(current)[0].length;
|
6120 | return Math.min(numSpaces, previous);
|
6121 | }, Infinity);
|
6122 |
|
6123 | return new Array(min + 1).join(' ');
|
6124 | }
|
6125 |
|
6126 | function getRelativePath(from, to) {
|
6127 | var fromParts = from.split(/[/\\]/);
|
6128 | var toParts = to.split(/[/\\]/);
|
6129 |
|
6130 | fromParts.pop(); // get dirname
|
6131 |
|
6132 | while (fromParts[0] === toParts[0]) {
|
6133 | fromParts.shift();
|
6134 | toParts.shift();
|
6135 | }
|
6136 |
|
6137 | if (fromParts.length) {
|
6138 | var i = fromParts.length;
|
6139 | while (i--) { fromParts[i] = '..'; }
|
6140 | }
|
6141 |
|
6142 | return fromParts.concat(toParts).join('/');
|
6143 | }
|
6144 |
|
6145 | var toString$1 = Object.prototype.toString;
|
6146 |
|
6147 | function isObject(thing) {
|
6148 | return toString$1.call(thing) === '[object Object]';
|
6149 | }
|
6150 |
|
6151 | function getLocator(source) {
|
6152 | var originalLines = source.split('\n');
|
6153 | var lineOffsets = [];
|
6154 |
|
6155 | for (var i = 0, pos = 0; i < originalLines.length; i++) {
|
6156 | lineOffsets.push(pos);
|
6157 | pos += originalLines[i].length + 1;
|
6158 | }
|
6159 |
|
6160 | return function locate(index) {
|
6161 | var i = 0;
|
6162 | var j = lineOffsets.length;
|
6163 | while (i < j) {
|
6164 | var m = (i + j) >> 1;
|
6165 | if (index < lineOffsets[m]) {
|
6166 | j = m;
|
6167 | } else {
|
6168 | i = m + 1;
|
6169 | }
|
6170 | }
|
6171 | var line = i - 1;
|
6172 | var column = index - lineOffsets[line];
|
6173 | return { line: line, column: column };
|
6174 | };
|
6175 | }
|
6176 |
|
6177 | var Mappings = function Mappings(hires) {
|
6178 | this.hires = hires;
|
6179 | this.generatedCodeLine = 0;
|
6180 | this.generatedCodeColumn = 0;
|
6181 | this.raw = [];
|
6182 | this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
6183 | this.pending = null;
|
6184 | };
|
6185 |
|
6186 | Mappings.prototype.addEdit = function addEdit (sourceIndex, content, loc, nameIndex) {
|
6187 | if (content.length) {
|
6188 | var segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
6189 | if (nameIndex >= 0) {
|
6190 | segment.push(nameIndex);
|
6191 | }
|
6192 | this.rawSegments.push(segment);
|
6193 | } else if (this.pending) {
|
6194 | this.rawSegments.push(this.pending);
|
6195 | }
|
6196 |
|
6197 | this.advance(content);
|
6198 | this.pending = null;
|
6199 | };
|
6200 |
|
6201 | Mappings.prototype.addUneditedChunk = function addUneditedChunk (sourceIndex, chunk, original, loc, sourcemapLocations) {
|
6202 | var originalCharIndex = chunk.start;
|
6203 | var first = true;
|
6204 |
|
6205 | while (originalCharIndex < chunk.end) {
|
6206 | if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
6207 | this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
|
6208 | }
|
6209 |
|
6210 | if (original[originalCharIndex] === '\n') {
|
6211 | loc.line += 1;
|
6212 | loc.column = 0;
|
6213 | this.generatedCodeLine += 1;
|
6214 | this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
6215 | this.generatedCodeColumn = 0;
|
6216 | first = true;
|
6217 | } else {
|
6218 | loc.column += 1;
|
6219 | this.generatedCodeColumn += 1;
|
6220 | first = false;
|
6221 | }
|
6222 |
|
6223 | originalCharIndex += 1;
|
6224 | }
|
6225 |
|
6226 | this.pending = null;
|
6227 | };
|
6228 |
|
6229 | Mappings.prototype.advance = function advance (str) {
|
6230 | if (!str) { return; }
|
6231 |
|
6232 | var lines = str.split('\n');
|
6233 |
|
6234 | if (lines.length > 1) {
|
6235 | for (var i = 0; i < lines.length - 1; i++) {
|
6236 | this.generatedCodeLine++;
|
6237 | this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
6238 | }
|
6239 | this.generatedCodeColumn = 0;
|
6240 | }
|
6241 |
|
6242 | this.generatedCodeColumn += lines[lines.length - 1].length;
|
6243 | };
|
6244 |
|
6245 | var n = '\n';
|
6246 |
|
6247 | var warned = {
|
6248 | insertLeft: false,
|
6249 | insertRight: false,
|
6250 | storeName: false
|
6251 | };
|
6252 |
|
6253 | var MagicString = function MagicString(string, options) {
|
6254 | if ( options === void 0 ) options = {};
|
6255 |
|
6256 | var chunk = new Chunk(0, string.length, string);
|
6257 |
|
6258 | Object.defineProperties(this, {
|
6259 | original: { writable: true, value: string },
|
6260 | outro: { writable: true, value: '' },
|
6261 | intro: { writable: true, value: '' },
|
6262 | firstChunk: { writable: true, value: chunk },
|
6263 | lastChunk: { writable: true, value: chunk },
|
6264 | lastSearchedChunk: { writable: true, value: chunk },
|
6265 | byStart: { writable: true, value: {} },
|
6266 | byEnd: { writable: true, value: {} },
|
6267 | filename: { writable: true, value: options.filename },
|
6268 | indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
6269 | sourcemapLocations: { writable: true, value: new BitSet() },
|
6270 | storedNames: { writable: true, value: {} },
|
6271 | indentStr: { writable: true, value: guessIndent(string) }
|
6272 | });
|
6273 |
|
6274 | this.byStart[0] = chunk;
|
6275 | this.byEnd[string.length] = chunk;
|
6276 | };
|
6277 |
|
6278 | MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
|
6279 | this.sourcemapLocations.add(char);
|
6280 | };
|
6281 |
|
6282 | MagicString.prototype.append = function append (content) {
|
6283 | if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
|
6284 |
|
6285 | this.outro += content;
|
6286 | return this;
|
6287 | };
|
6288 |
|
6289 | MagicString.prototype.appendLeft = function appendLeft (index, content) {
|
6290 | if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
|
6291 |
|
6292 | this._split(index);
|
6293 |
|
6294 | var chunk = this.byEnd[index];
|
6295 |
|
6296 | if (chunk) {
|
6297 | chunk.appendLeft(content);
|
6298 | } else {
|
6299 | this.intro += content;
|
6300 | }
|
6301 | return this;
|
6302 | };
|
6303 |
|
6304 | MagicString.prototype.appendRight = function appendRight (index, content) {
|
6305 | if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
|
6306 |
|
6307 | this._split(index);
|
6308 |
|
6309 | var chunk = this.byStart[index];
|
6310 |
|
6311 | if (chunk) {
|
6312 | chunk.appendRight(content);
|
6313 | } else {
|
6314 | this.outro += content;
|
6315 | }
|
6316 | return this;
|
6317 | };
|
6318 |
|
6319 | MagicString.prototype.clone = function clone () {
|
6320 | var cloned = new MagicString(this.original, { filename: this.filename });
|
6321 |
|
6322 | var originalChunk = this.firstChunk;
|
6323 | var clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
|
6324 |
|
6325 | while (originalChunk) {
|
6326 | cloned.byStart[clonedChunk.start] = clonedChunk;
|
6327 | cloned.byEnd[clonedChunk.end] = clonedChunk;
|
6328 |
|
6329 | var nextOriginalChunk = originalChunk.next;
|
6330 | var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
6331 |
|
6332 | if (nextClonedChunk) {
|
6333 | clonedChunk.next = nextClonedChunk;
|
6334 | nextClonedChunk.previous = clonedChunk;
|
6335 |
|
6336 | clonedChunk = nextClonedChunk;
|
6337 | }
|
6338 |
|
6339 | originalChunk = nextOriginalChunk;
|
6340 | }
|
6341 |
|
6342 | cloned.lastChunk = clonedChunk;
|
6343 |
|
6344 | if (this.indentExclusionRanges) {
|
6345 | cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
6346 | }
|
6347 |
|
6348 | cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
6349 |
|
6350 | cloned.intro = this.intro;
|
6351 | cloned.outro = this.outro;
|
6352 |
|
6353 | return cloned;
|
6354 | };
|
6355 |
|
6356 | MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
|
6357 | var this$1 = this;
|
6358 |
|
6359 | options = options || {};
|
6360 |
|
6361 | var sourceIndex = 0;
|
6362 | var names = Object.keys(this.storedNames);
|
6363 | var mappings = new Mappings(options.hires);
|
6364 |
|
6365 | var locate = getLocator(this.original);
|
6366 |
|
6367 | if (this.intro) {
|
6368 | mappings.advance(this.intro);
|
6369 | }
|
6370 |
|
6371 | this.firstChunk.eachNext(function (chunk) {
|
6372 | var loc = locate(chunk.start);
|
6373 |
|
6374 | if (chunk.intro.length) { mappings.advance(chunk.intro); }
|
6375 |
|
6376 | if (chunk.edited) {
|
6377 | mappings.addEdit(
|
6378 | sourceIndex,
|
6379 | chunk.content,
|
6380 | loc,
|
6381 | chunk.storeName ? names.indexOf(chunk.original) : -1
|
6382 | );
|
6383 | } else {
|
6384 | mappings.addUneditedChunk(sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations);
|
6385 | }
|
6386 |
|
6387 | if (chunk.outro.length) { mappings.advance(chunk.outro); }
|
6388 | });
|
6389 |
|
6390 | return {
|
6391 | file: options.file ? options.file.split(/[/\\]/).pop() : null,
|
6392 | sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
|
6393 | sourcesContent: options.includeContent ? [this.original] : [null],
|
6394 | names: names,
|
6395 | mappings: mappings.raw
|
6396 | };
|
6397 | };
|
6398 |
|
6399 | MagicString.prototype.generateMap = function generateMap (options) {
|
6400 | return new SourceMap(this.generateDecodedMap(options));
|
6401 | };
|
6402 |
|
6403 | MagicString.prototype.getIndentString = function getIndentString () {
|
6404 | return this.indentStr === null ? '\t' : this.indentStr;
|
6405 | };
|
6406 |
|
6407 | MagicString.prototype.indent = function indent (indentStr, options) {
|
6408 | var pattern = /^[^\r\n]/gm;
|
6409 |
|
6410 | if (isObject(indentStr)) {
|
6411 | options = indentStr;
|
6412 | indentStr = undefined;
|
6413 | }
|
6414 |
|
6415 | indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
|
6416 |
|
6417 | if (indentStr === '') { return this; } // noop
|
6418 |
|
6419 | options = options || {};
|
6420 |
|
6421 | // Process exclusion ranges
|
6422 | var isExcluded = {};
|
6423 |
|
6424 | if (options.exclude) {
|
6425 | var exclusions =
|
6426 | typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
|
6427 | exclusions.forEach(function (exclusion) {
|
6428 | for (var i = exclusion[0]; i < exclusion[1]; i += 1) {
|
6429 | isExcluded[i] = true;
|
6430 | }
|
6431 | });
|
6432 | }
|
6433 |
|
6434 | var shouldIndentNextCharacter = options.indentStart !== false;
|
6435 | var replacer = function (match) {
|
6436 | if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
|
6437 | shouldIndentNextCharacter = true;
|
6438 | return match;
|
6439 | };
|
6440 |
|
6441 | this.intro = this.intro.replace(pattern, replacer);
|
6442 |
|
6443 | var charIndex = 0;
|
6444 | var chunk = this.firstChunk;
|
6445 |
|
6446 | while (chunk) {
|
6447 | var end = chunk.end;
|
6448 |
|
6449 | if (chunk.edited) {
|
6450 | if (!isExcluded[charIndex]) {
|
6451 | chunk.content = chunk.content.replace(pattern, replacer);
|
6452 |
|
6453 | if (chunk.content.length) {
|
6454 | shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
|
6455 | }
|
6456 | }
|
6457 | } else {
|
6458 | charIndex = chunk.start;
|
6459 |
|
6460 | while (charIndex < end) {
|
6461 | if (!isExcluded[charIndex]) {
|
6462 | var char = this.original[charIndex];
|
6463 |
|
6464 | if (char === '\n') {
|
6465 | shouldIndentNextCharacter = true;
|
6466 | } else if (char !== '\r' && shouldIndentNextCharacter) {
|
6467 | shouldIndentNextCharacter = false;
|
6468 |
|
6469 | if (charIndex === chunk.start) {
|
6470 | chunk.prependRight(indentStr);
|
6471 | } else {
|
6472 | this._splitChunk(chunk, charIndex);
|
6473 | chunk = chunk.next;
|
6474 | chunk.prependRight(indentStr);
|
6475 | }
|
6476 | }
|
6477 | }
|
6478 |
|
6479 | charIndex += 1;
|
6480 | }
|
6481 | }
|
6482 |
|
6483 | charIndex = chunk.end;
|
6484 | chunk = chunk.next;
|
6485 | }
|
6486 |
|
6487 | this.outro = this.outro.replace(pattern, replacer);
|
6488 |
|
6489 | return this;
|
6490 | };
|
6491 |
|
6492 | MagicString.prototype.insert = function insert () {
|
6493 | throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
|
6494 | };
|
6495 |
|
6496 | MagicString.prototype.insertLeft = function insertLeft (index, content) {
|
6497 | if (!warned.insertLeft) {
|
6498 | console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
|
6499 | warned.insertLeft = true;
|
6500 | }
|
6501 |
|
6502 | return this.appendLeft(index, content);
|
6503 | };
|
6504 |
|
6505 | MagicString.prototype.insertRight = function insertRight (index, content) {
|
6506 | if (!warned.insertRight) {
|
6507 | console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
|
6508 | warned.insertRight = true;
|
6509 | }
|
6510 |
|
6511 | return this.prependRight(index, content);
|
6512 | };
|
6513 |
|
6514 | MagicString.prototype.move = function move (start, end, index) {
|
6515 | if (index >= start && index <= end) { throw new Error('Cannot move a selection inside itself'); }
|
6516 |
|
6517 | this._split(start);
|
6518 | this._split(end);
|
6519 | this._split(index);
|
6520 |
|
6521 | var first = this.byStart[start];
|
6522 | var last = this.byEnd[end];
|
6523 |
|
6524 | var oldLeft = first.previous;
|
6525 | var oldRight = last.next;
|
6526 |
|
6527 | var newRight = this.byStart[index];
|
6528 | if (!newRight && last === this.lastChunk) { return this; }
|
6529 | var newLeft = newRight ? newRight.previous : this.lastChunk;
|
6530 |
|
6531 | if (oldLeft) { oldLeft.next = oldRight; }
|
6532 | if (oldRight) { oldRight.previous = oldLeft; }
|
6533 |
|
6534 | if (newLeft) { newLeft.next = first; }
|
6535 | if (newRight) { newRight.previous = last; }
|
6536 |
|
6537 | if (!first.previous) { this.firstChunk = last.next; }
|
6538 | if (!last.next) {
|
6539 | this.lastChunk = first.previous;
|
6540 | this.lastChunk.next = null;
|
6541 | }
|
6542 |
|
6543 | first.previous = newLeft;
|
6544 | last.next = newRight || null;
|
6545 |
|
6546 | if (!newLeft) { this.firstChunk = first; }
|
6547 | if (!newRight) { this.lastChunk = last; }
|
6548 | return this;
|
6549 | };
|
6550 |
|
6551 | MagicString.prototype.overwrite = function overwrite (start, end, content, options) {
|
6552 | if (typeof content !== 'string') { throw new TypeError('replacement content must be a string'); }
|
6553 |
|
6554 | while (start < 0) { start += this.original.length; }
|
6555 | while (end < 0) { end += this.original.length; }
|
6556 |
|
6557 | if (end > this.original.length) { throw new Error('end is out of bounds'); }
|
6558 | if (start === end)
|
6559 | { throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
|
6560 |
|
6561 | this._split(start);
|
6562 | this._split(end);
|
6563 |
|
6564 | if (options === true) {
|
6565 | if (!warned.storeName) {
|
6566 | console.warn('The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'); // eslint-disable-line no-console
|
6567 | warned.storeName = true;
|
6568 | }
|
6569 |
|
6570 | options = { storeName: true };
|
6571 | }
|
6572 | var storeName = options !== undefined ? options.storeName : false;
|
6573 | var contentOnly = options !== undefined ? options.contentOnly : false;
|
6574 |
|
6575 | if (storeName) {
|
6576 | var original = this.original.slice(start, end);
|
6577 | this.storedNames[original] = true;
|
6578 | }
|
6579 |
|
6580 | var first = this.byStart[start];
|
6581 | var last = this.byEnd[end];
|
6582 |
|
6583 | if (first) {
|
6584 | if (end > first.end && first.next !== this.byStart[first.end]) {
|
6585 | throw new Error('Cannot overwrite across a split point');
|
6586 | }
|
6587 |
|
6588 | first.edit(content, storeName, contentOnly);
|
6589 |
|
6590 | if (first !== last) {
|
6591 | var chunk = first.next;
|
6592 | while (chunk !== last) {
|
6593 | chunk.edit('', false);
|
6594 | chunk = chunk.next;
|
6595 | }
|
6596 |
|
6597 | chunk.edit('', false);
|
6598 | }
|
6599 | } else {
|
6600 | // must be inserting at the end
|
6601 | var newChunk = new Chunk(start, end, '').edit(content, storeName);
|
6602 |
|
6603 | // TODO last chunk in the array may not be the last chunk, if it's moved...
|
6604 | last.next = newChunk;
|
6605 | newChunk.previous = last;
|
6606 | }
|
6607 | return this;
|
6608 | };
|
6609 |
|
6610 | MagicString.prototype.prepend = function prepend (content) {
|
6611 | if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
|
6612 |
|
6613 | this.intro = content + this.intro;
|
6614 | return this;
|
6615 | };
|
6616 |
|
6617 | MagicString.prototype.prependLeft = function prependLeft (index, content) {
|
6618 | if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
|
6619 |
|
6620 | this._split(index);
|
6621 |
|
6622 | var chunk = this.byEnd[index];
|
6623 |
|
6624 | if (chunk) {
|
6625 | chunk.prependLeft(content);
|
6626 | } else {
|
6627 | this.intro = content + this.intro;
|
6628 | }
|
6629 | return this;
|
6630 | };
|
6631 |
|
6632 | MagicString.prototype.prependRight = function prependRight (index, content) {
|
6633 | if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
|
6634 |
|
6635 | this._split(index);
|
6636 |
|
6637 | var chunk = this.byStart[index];
|
6638 |
|
6639 | if (chunk) {
|
6640 | chunk.prependRight(content);
|
6641 | } else {
|
6642 | this.outro = content + this.outro;
|
6643 | }
|
6644 | return this;
|
6645 | };
|
6646 |
|
6647 | MagicString.prototype.remove = function remove (start, end) {
|
6648 | while (start < 0) { start += this.original.length; }
|
6649 | while (end < 0) { end += this.original.length; }
|
6650 |
|
6651 | if (start === end) { return this; }
|
6652 |
|
6653 | if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); }
|
6654 | if (start > end) { throw new Error('end must be greater than start'); }
|
6655 |
|
6656 | this._split(start);
|
6657 | this._split(end);
|
6658 |
|
6659 | var chunk = this.byStart[start];
|
6660 |
|
6661 | while (chunk) {
|
6662 | chunk.intro = '';
|
6663 | chunk.outro = '';
|
6664 | chunk.edit('');
|
6665 |
|
6666 | chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
6667 | }
|
6668 | return this;
|
6669 | };
|
6670 |
|
6671 | MagicString.prototype.lastChar = function lastChar () {
|
6672 | if (this.outro.length)
|
6673 | { return this.outro[this.outro.length - 1]; }
|
6674 | var chunk = this.lastChunk;
|
6675 | do {
|
6676 | if (chunk.outro.length)
|
6677 | { return chunk.outro[chunk.outro.length - 1]; }
|
6678 | if (chunk.content.length)
|
6679 | { return chunk.content[chunk.content.length - 1]; }
|
6680 | if (chunk.intro.length)
|
6681 | { return chunk.intro[chunk.intro.length - 1]; }
|
6682 | } while (chunk = chunk.previous);
|
6683 | if (this.intro.length)
|
6684 | { return this.intro[this.intro.length - 1]; }
|
6685 | return '';
|
6686 | };
|
6687 |
|
6688 | MagicString.prototype.lastLine = function lastLine () {
|
6689 | var lineIndex = this.outro.lastIndexOf(n);
|
6690 | if (lineIndex !== -1)
|
6691 | { return this.outro.substr(lineIndex + 1); }
|
6692 | var lineStr = this.outro;
|
6693 | var chunk = this.lastChunk;
|
6694 | do {
|
6695 | if (chunk.outro.length > 0) {
|
6696 | lineIndex = chunk.outro.lastIndexOf(n);
|
6697 | if (lineIndex !== -1)
|
6698 | { return chunk.outro.substr(lineIndex + 1) + lineStr; }
|
6699 | lineStr = chunk.outro + lineStr;
|
6700 | }
|
6701 |
|
6702 | if (chunk.content.length > 0) {
|
6703 | lineIndex = chunk.content.lastIndexOf(n);
|
6704 | if (lineIndex !== -1)
|
6705 | { return chunk.content.substr(lineIndex + 1) + lineStr; }
|
6706 | lineStr = chunk.content + lineStr;
|
6707 | }
|
6708 |
|
6709 | if (chunk.intro.length > 0) {
|
6710 | lineIndex = chunk.intro.lastIndexOf(n);
|
6711 | if (lineIndex !== -1)
|
6712 | { return chunk.intro.substr(lineIndex + 1) + lineStr; }
|
6713 | lineStr = chunk.intro + lineStr;
|
6714 | }
|
6715 | } while (chunk = chunk.previous);
|
6716 | lineIndex = this.intro.lastIndexOf(n);
|
6717 | if (lineIndex !== -1)
|
6718 | { return this.intro.substr(lineIndex + 1) + lineStr; }
|
6719 | return this.intro + lineStr;
|
6720 | };
|
6721 |
|
6722 | MagicString.prototype.slice = function slice (start, end) {
|
6723 | if ( start === void 0 ) start = 0;
|
6724 | if ( end === void 0 ) end = this.original.length;
|
6725 |
|
6726 | while (start < 0) { start += this.original.length; }
|
6727 | while (end < 0) { end += this.original.length; }
|
6728 |
|
6729 | var result = '';
|
6730 |
|
6731 | // find start chunk
|
6732 | var chunk = this.firstChunk;
|
6733 | while (chunk && (chunk.start > start || chunk.end <= start)) {
|
6734 | // found end chunk before start
|
6735 | if (chunk.start < end && chunk.end >= end) {
|
6736 | return result;
|
6737 | }
|
6738 |
|
6739 | chunk = chunk.next;
|
6740 | }
|
6741 |
|
6742 | if (chunk && chunk.edited && chunk.start !== start)
|
6743 | { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
|
6744 |
|
6745 | var startChunk = chunk;
|
6746 | while (chunk) {
|
6747 | if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
|
6748 | result += chunk.intro;
|
6749 | }
|
6750 |
|
6751 | var containsEnd = chunk.start < end && chunk.end >= end;
|
6752 | if (containsEnd && chunk.edited && chunk.end !== end)
|
6753 | { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
|
6754 |
|
6755 | var sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
6756 | var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
6757 |
|
6758 | result += chunk.content.slice(sliceStart, sliceEnd);
|
6759 |
|
6760 | if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
6761 | result += chunk.outro;
|
6762 | }
|
6763 |
|
6764 | if (containsEnd) {
|
6765 | break;
|
6766 | }
|
6767 |
|
6768 | chunk = chunk.next;
|
6769 | }
|
6770 |
|
6771 | return result;
|
6772 | };
|
6773 |
|
6774 | // TODO deprecate this? not really very useful
|
6775 | MagicString.prototype.snip = function snip (start, end) {
|
6776 | var clone = this.clone();
|
6777 | clone.remove(0, start);
|
6778 | clone.remove(end, clone.original.length);
|
6779 |
|
6780 | return clone;
|
6781 | };
|
6782 |
|
6783 | MagicString.prototype._split = function _split (index) {
|
6784 | if (this.byStart[index] || this.byEnd[index]) { return; }
|
6785 |
|
6786 | var chunk = this.lastSearchedChunk;
|
6787 | var searchForward = index > chunk.end;
|
6788 |
|
6789 | while (chunk) {
|
6790 | if (chunk.contains(index)) { return this._splitChunk(chunk, index); }
|
6791 |
|
6792 | chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
6793 | }
|
6794 | };
|
6795 |
|
6796 | MagicString.prototype._splitChunk = function _splitChunk (chunk, index) {
|
6797 | if (chunk.edited && chunk.content.length) {
|
6798 | // zero-length edited chunks are a special case (overlapping replacements)
|
6799 | var loc = getLocator(this.original)(index);
|
6800 | throw new Error(
|
6801 | ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")")
|
6802 | );
|
6803 | }
|
6804 |
|
6805 | var newChunk = chunk.split(index);
|
6806 |
|
6807 | this.byEnd[index] = chunk;
|
6808 | this.byStart[index] = newChunk;
|
6809 | this.byEnd[newChunk.end] = newChunk;
|
6810 |
|
6811 | if (chunk === this.lastChunk) { this.lastChunk = newChunk; }
|
6812 |
|
6813 | this.lastSearchedChunk = chunk;
|
6814 | return true;
|
6815 | };
|
6816 |
|
6817 | MagicString.prototype.toString = function toString () {
|
6818 | var str = this.intro;
|
6819 |
|
6820 | var chunk = this.firstChunk;
|
6821 | while (chunk) {
|
6822 | str += chunk.toString();
|
6823 | chunk = chunk.next;
|
6824 | }
|
6825 |
|
6826 | return str + this.outro;
|
6827 | };
|
6828 |
|
6829 | MagicString.prototype.isEmpty = function isEmpty () {
|
6830 | var chunk = this.firstChunk;
|
6831 | do {
|
6832 | if (chunk.intro.length && chunk.intro.trim() ||
|
6833 | chunk.content.length && chunk.content.trim() ||
|
6834 | chunk.outro.length && chunk.outro.trim())
|
6835 | { return false; }
|
6836 | } while (chunk = chunk.next);
|
6837 | return true;
|
6838 | };
|
6839 |
|
6840 | MagicString.prototype.length = function length () {
|
6841 | var chunk = this.firstChunk;
|
6842 | var length = 0;
|
6843 | do {
|
6844 | length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
6845 | } while (chunk = chunk.next);
|
6846 | return length;
|
6847 | };
|
6848 |
|
6849 | MagicString.prototype.trimLines = function trimLines () {
|
6850 | return this.trim('[\\r\\n]');
|
6851 | };
|
6852 |
|
6853 | MagicString.prototype.trim = function trim (charType) {
|
6854 | return this.trimStart(charType).trimEnd(charType);
|
6855 | };
|
6856 |
|
6857 | MagicString.prototype.trimEndAborted = function trimEndAborted (charType) {
|
6858 | var rx = new RegExp((charType || '\\s') + '+$');
|
6859 |
|
6860 | this.outro = this.outro.replace(rx, '');
|
6861 | if (this.outro.length) { return true; }
|
6862 |
|
6863 | var chunk = this.lastChunk;
|
6864 |
|
6865 | do {
|
6866 | var end = chunk.end;
|
6867 | var aborted = chunk.trimEnd(rx);
|
6868 |
|
6869 | // if chunk was trimmed, we have a new lastChunk
|
6870 | if (chunk.end !== end) {
|
6871 | if (this.lastChunk === chunk) {
|
6872 | this.lastChunk = chunk.next;
|
6873 | }
|
6874 |
|
6875 | this.byEnd[chunk.end] = chunk;
|
6876 | this.byStart[chunk.next.start] = chunk.next;
|
6877 | this.byEnd[chunk.next.end] = chunk.next;
|
6878 | }
|
6879 |
|
6880 | if (aborted) { return true; }
|
6881 | chunk = chunk.previous;
|
6882 | } while (chunk);
|
6883 |
|
6884 | return false;
|
6885 | };
|
6886 |
|
6887 | MagicString.prototype.trimEnd = function trimEnd (charType) {
|
6888 | this.trimEndAborted(charType);
|
6889 | return this;
|
6890 | };
|
6891 | MagicString.prototype.trimStartAborted = function trimStartAborted (charType) {
|
6892 | var rx = new RegExp('^' + (charType || '\\s') + '+');
|
6893 |
|
6894 | this.intro = this.intro.replace(rx, '');
|
6895 | if (this.intro.length) { return true; }
|
6896 |
|
6897 | var chunk = this.firstChunk;
|
6898 |
|
6899 | do {
|
6900 | var end = chunk.end;
|
6901 | var aborted = chunk.trimStart(rx);
|
6902 |
|
6903 | if (chunk.end !== end) {
|
6904 | // special case...
|
6905 | if (chunk === this.lastChunk) { this.lastChunk = chunk.next; }
|
6906 |
|
6907 | this.byEnd[chunk.end] = chunk;
|
6908 | this.byStart[chunk.next.start] = chunk.next;
|
6909 | this.byEnd[chunk.next.end] = chunk.next;
|
6910 | }
|
6911 |
|
6912 | if (aborted) { return true; }
|
6913 | chunk = chunk.next;
|
6914 | } while (chunk);
|
6915 |
|
6916 | return false;
|
6917 | };
|
6918 |
|
6919 | MagicString.prototype.trimStart = function trimStart (charType) {
|
6920 | this.trimStartAborted(charType);
|
6921 | return this;
|
6922 | };
|
6923 |
|
6924 | // used for debugging, without the noise created by
|
6925 | // circular references
|
6926 | function toJSON(node) {
|
6927 | var obj = {};
|
6928 |
|
6929 | Object.keys(node).forEach(function (key) {
|
6930 | if (
|
6931 | key === 'parent' ||
|
6932 | key === 'program' ||
|
6933 | key === 'keys' ||
|
6934 | key === '__wrapped'
|
6935 | )
|
6936 | { return; }
|
6937 |
|
6938 | if (Array.isArray(node[key])) {
|
6939 | obj[key] = node[key].map(toJSON);
|
6940 | } else if (node[key] && node[key].toJSON) {
|
6941 | obj[key] = node[key].toJSON();
|
6942 | } else {
|
6943 | obj[key] = node[key];
|
6944 | }
|
6945 | });
|
6946 |
|
6947 | return obj;
|
6948 | }
|
6949 |
|
6950 | var Node$1 = function Node () {};
|
6951 |
|
6952 | Node$1.prototype.ancestor = function ancestor (level) {
|
6953 | var node = this;
|
6954 | while (level--) {
|
6955 | node = node.parent;
|
6956 | if (!node) { return null; }
|
6957 | }
|
6958 |
|
6959 | return node;
|
6960 | };
|
6961 |
|
6962 | Node$1.prototype.contains = function contains (node) {
|
6963 | while (node) {
|
6964 | if (node === this) { return true; }
|
6965 | node = node.parent;
|
6966 | }
|
6967 |
|
6968 | return false;
|
6969 | };
|
6970 |
|
6971 | Node$1.prototype.findLexicalBoundary = function findLexicalBoundary () {
|
6972 | return this.parent.findLexicalBoundary();
|
6973 | };
|
6974 |
|
6975 | Node$1.prototype.findNearest = function findNearest (type) {
|
6976 | if (typeof type === 'string') { type = new RegExp(("^" + type + "$")); }
|
6977 | if (type.test(this.type)) { return this; }
|
6978 | return this.parent.findNearest(type);
|
6979 | };
|
6980 |
|
6981 | Node$1.prototype.unparenthesizedParent = function unparenthesizedParent () {
|
6982 | var node = this.parent;
|
6983 | while (node && node.type === 'ParenthesizedExpression') {
|
6984 | node = node.parent;
|
6985 | }
|
6986 | return node;
|
6987 | };
|
6988 |
|
6989 | Node$1.prototype.unparenthesize = function unparenthesize () {
|
6990 | var node = this;
|
6991 | while (node.type === 'ParenthesizedExpression') {
|
6992 | node = node.expression;
|
6993 | }
|
6994 | return node;
|
6995 | };
|
6996 |
|
6997 | Node$1.prototype.findScope = function findScope (functionScope) {
|
6998 | return this.parent.findScope(functionScope);
|
6999 | };
|
7000 |
|
7001 | Node$1.prototype.getIndentation = function getIndentation () {
|
7002 | return this.parent.getIndentation();
|
7003 | };
|
7004 |
|
7005 | Node$1.prototype.initialise = function initialise (transforms) {
|
7006 | for (var i = 0, list = this.keys; i < list.length; i += 1) {
|
7007 | var key = list[i];
|
7008 |
|
7009 | var value = this[key];
|
7010 |
|
7011 | if (Array.isArray(value)) {
|
7012 | value.forEach(function (node) { return node && node.initialise(transforms); });
|
7013 | } else if (value && typeof value === 'object') {
|
7014 | value.initialise(transforms);
|
7015 | }
|
7016 | }
|
7017 | };
|
7018 |
|
7019 | Node$1.prototype.toJSON = function toJSON$1 () {
|
7020 | return toJSON(this);
|
7021 | };
|
7022 |
|
7023 | Node$1.prototype.toString = function toString () {
|
7024 | return this.program.magicString.original.slice(this.start, this.end);
|
7025 | };
|
7026 |
|
7027 | Node$1.prototype.transpile = function transpile (code, transforms) {
|
7028 | for (var i = 0, list = this.keys; i < list.length; i += 1) {
|
7029 | var key = list[i];
|
7030 |
|
7031 | var value = this[key];
|
7032 |
|
7033 | if (Array.isArray(value)) {
|
7034 | value.forEach(function (node) { return node && node.transpile(code, transforms); });
|
7035 | } else if (value && typeof value === 'object') {
|
7036 | value.transpile(code, transforms);
|
7037 | }
|
7038 | }
|
7039 | };
|
7040 |
|
7041 | function extractNames(node) {
|
7042 | var names = [];
|
7043 | extractors[node.type](names, node);
|
7044 | return names;
|
7045 | }
|
7046 |
|
7047 | var extractors = {
|
7048 | Identifier: function Identifier(names, node) {
|
7049 | names.push(node);
|
7050 | },
|
7051 |
|
7052 | ObjectPattern: function ObjectPattern(names, node) {
|
7053 | for (var i = 0, list = node.properties; i < list.length; i += 1) {
|
7054 | var prop = list[i];
|
7055 |
|
7056 | extractors[prop.type](names, prop);
|
7057 | }
|
7058 | },
|
7059 |
|
7060 | Property: function Property(names, node) {
|
7061 | extractors[node.value.type](names, node.value);
|
7062 | },
|
7063 |
|
7064 | ArrayPattern: function ArrayPattern(names, node) {
|
7065 | for (var i = 0, list = node.elements; i < list.length; i += 1) {
|
7066 | var element = list[i];
|
7067 |
|
7068 | if (element) { extractors[element.type](names, element); }
|
7069 | }
|
7070 | },
|
7071 |
|
7072 | RestElement: function RestElement(names, node) {
|
7073 | extractors[node.argument.type](names, node.argument);
|
7074 | },
|
7075 |
|
7076 | AssignmentPattern: function AssignmentPattern(names, node) {
|
7077 | extractors[node.left.type](names, node.left);
|
7078 | }
|
7079 | };
|
7080 |
|
7081 | var reserved = Object.create(null);
|
7082 | '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'
|
7083 | .split(' ')
|
7084 | .forEach(function (word) { return (reserved[word] = true); });
|
7085 |
|
7086 | function Scope$1(options) {
|
7087 | options = options || {};
|
7088 |
|
7089 | this.parent = options.parent;
|
7090 | this.isBlockScope = !!options.block;
|
7091 | this.createDeclarationCallback = options.declare;
|
7092 |
|
7093 | var scope = this;
|
7094 | while (scope.isBlockScope) { scope = scope.parent; }
|
7095 | this.functionScope = scope;
|
7096 |
|
7097 | this.identifiers = [];
|
7098 | this.declarations = Object.create(null);
|
7099 | this.references = Object.create(null);
|
7100 | this.blockScopedDeclarations = this.isBlockScope ? null : Object.create(null);
|
7101 | this.aliases = Object.create(null);
|
7102 | }
|
7103 |
|
7104 | Scope$1.prototype = {
|
7105 | addDeclaration: function addDeclaration(node, kind) {
|
7106 | for (var i = 0, list = extractNames(node); i < list.length; i += 1) {
|
7107 | var identifier = list[i];
|
7108 |
|
7109 | var name = identifier.name;
|
7110 |
|
7111 | var declaration = { name: name, node: identifier, kind: kind, instances: [] };
|
7112 | this.declarations[name] = declaration;
|
7113 |
|
7114 | if (this.isBlockScope) {
|
7115 | if (!this.functionScope.blockScopedDeclarations[name])
|
7116 | { this.functionScope.blockScopedDeclarations[name] = []; }
|
7117 | this.functionScope.blockScopedDeclarations[name].push(declaration);
|
7118 | }
|
7119 | }
|
7120 | },
|
7121 |
|
7122 | addReference: function addReference(identifier) {
|
7123 | if (this.consolidated) {
|
7124 | this.consolidateReference(identifier);
|
7125 | } else {
|
7126 | this.identifiers.push(identifier);
|
7127 | }
|
7128 | },
|
7129 |
|
7130 | consolidate: function consolidate() {
|
7131 | for (var i = 0; i < this.identifiers.length; i += 1) {
|
7132 | // we might push to the array during consolidation, so don't cache length
|
7133 | var identifier = this.identifiers[i];
|
7134 | this.consolidateReference(identifier);
|
7135 | }
|
7136 |
|
7137 | this.consolidated = true; // TODO understand why this is necessary... seems bad
|
7138 | },
|
7139 |
|
7140 | consolidateReference: function consolidateReference(identifier) {
|
7141 | var declaration = this.declarations[identifier.name];
|
7142 | if (declaration) {
|
7143 | declaration.instances.push(identifier);
|
7144 | } else {
|
7145 | this.references[identifier.name] = true;
|
7146 | if (this.parent) { this.parent.addReference(identifier); }
|
7147 | }
|
7148 | },
|
7149 |
|
7150 | contains: function contains(name) {
|
7151 | return (
|
7152 | this.declarations[name] ||
|
7153 | (this.parent ? this.parent.contains(name) : false)
|
7154 | );
|
7155 | },
|
7156 |
|
7157 | createIdentifier: function createIdentifier(base) {
|
7158 | if (typeof base === 'number') { base = base.toString(); }
|
7159 |
|
7160 | base = base
|
7161 | .replace(/\s/g, '')
|
7162 | .replace(/\[([^\]]+)\]/g, '_$1')
|
7163 | .replace(/[^a-zA-Z0-9_$]/g, '_')
|
7164 | .replace(/_{2,}/, '_');
|
7165 |
|
7166 | var name = base;
|
7167 | var counter = 1;
|
7168 |
|
7169 | while (
|
7170 | this.declarations[name] ||
|
7171 | this.references[name] ||
|
7172 | this.aliases[name] ||
|
7173 | name in reserved
|
7174 | ) {
|
7175 | name = base + "$" + (counter++);
|
7176 | }
|
7177 |
|
7178 | this.aliases[name] = true;
|
7179 | return name;
|
7180 | },
|
7181 |
|
7182 | createDeclaration: function createDeclaration(base) {
|
7183 | var id = this.createIdentifier(base);
|
7184 | this.createDeclarationCallback(id);
|
7185 | return id;
|
7186 | },
|
7187 |
|
7188 | findDeclaration: function findDeclaration(name) {
|
7189 | return (
|
7190 | this.declarations[name] ||
|
7191 | (this.parent && this.parent.findDeclaration(name))
|
7192 | );
|
7193 | },
|
7194 |
|
7195 | // Sometimes, block scope declarations change name during transpilation
|
7196 | resolveName: function resolveName(name) {
|
7197 | var declaration = this.findDeclaration(name);
|
7198 | return declaration ? declaration.name : name;
|
7199 | }
|
7200 | };
|
7201 |
|
7202 | function locate(source, index) {
|
7203 | var lines = source.split('\n');
|
7204 | var len = lines.length;
|
7205 |
|
7206 | var lineStart = 0;
|
7207 | var i;
|
7208 |
|
7209 | for (i = 0; i < len; i += 1) {
|
7210 | var line = lines[i];
|
7211 | var lineEnd = lineStart + line.length + 1; // +1 for newline
|
7212 |
|
7213 | if (lineEnd > index) {
|
7214 | return { line: i + 1, column: index - lineStart, char: i };
|
7215 | }
|
7216 |
|
7217 | lineStart = lineEnd;
|
7218 | }
|
7219 |
|
7220 | throw new Error('Could not determine location of character');
|
7221 | }
|
7222 |
|
7223 | function pad(num, len) {
|
7224 | var result = String(num);
|
7225 | return result + repeat(' ', len - result.length);
|
7226 | }
|
7227 |
|
7228 | function repeat(str, times) {
|
7229 | var result = '';
|
7230 | while (times--) { result += str; }
|
7231 | return result;
|
7232 | }
|
7233 |
|
7234 | function getSnippet(source, loc, length) {
|
7235 | if ( length === void 0 ) length = 1;
|
7236 |
|
7237 | var first = Math.max(loc.line - 5, 0);
|
7238 | var last = loc.line;
|
7239 |
|
7240 | var numDigits = String(last).length;
|
7241 |
|
7242 | var lines = source.split('\n').slice(first, last);
|
7243 |
|
7244 | var lastLine = lines[lines.length - 1];
|
7245 | var offset = lastLine.slice(0, loc.column).replace(/\t/g, ' ').length;
|
7246 |
|
7247 | var snippet = lines
|
7248 | .map(function (line, i) { return ((pad(i + first + 1, numDigits)) + " : " + (line.replace(/\t/g, ' '))); })
|
7249 | .join('\n');
|
7250 |
|
7251 | snippet += '\n' + repeat(' ', numDigits + 3 + offset) + repeat('^', length);
|
7252 |
|
7253 | return snippet;
|
7254 | }
|
7255 |
|
7256 | var CompileError = /*@__PURE__*/(function (Error) {
|
7257 | function CompileError(message, node) {
|
7258 | Error.call(this, message);
|
7259 |
|
7260 | this.name = 'CompileError';
|
7261 | if (!node) {
|
7262 | return;
|
7263 | }
|
7264 |
|
7265 | var source = node.program.magicString.original;
|
7266 | var loc = locate(source, node.start);
|
7267 |
|
7268 | this.message = message + " (" + (loc.line) + ":" + (loc.column) + ")";
|
7269 |
|
7270 | this.stack = new Error().stack.replace(
|
7271 | new RegExp((".+new " + (this.name) + ".+\\n"), 'm'),
|
7272 | ''
|
7273 | );
|
7274 |
|
7275 | this.loc = loc;
|
7276 | this.snippet = getSnippet(source, loc, node.end - node.start);
|
7277 | }
|
7278 |
|
7279 | if ( Error ) CompileError.__proto__ = Error;
|
7280 | CompileError.prototype = Object.create( Error && Error.prototype );
|
7281 | CompileError.prototype.constructor = CompileError;
|
7282 |
|
7283 | CompileError.prototype.toString = function toString () {
|
7284 | return ((this.name) + ": " + (this.message) + "\n" + (this.snippet));
|
7285 | };
|
7286 |
|
7287 | CompileError.missingTransform = function missingTransform (feature, transformKey, node, dangerousKey) {
|
7288 | if ( dangerousKey === void 0 ) dangerousKey = null;
|
7289 |
|
7290 | var maybeDangerous = dangerousKey ? (", or `transforms: { " + dangerousKey + ": true }` if you know what you're doing") : '';
|
7291 | throw new CompileError(("Transforming " + feature + " is not " + (dangerousKey ? "fully supported" : "implemented") + ". Use `transforms: { " + transformKey + ": false }` to skip transformation and disable this error" + maybeDangerous + "."), node);
|
7292 | };
|
7293 |
|
7294 | return CompileError;
|
7295 | }(Error));
|
7296 |
|
7297 | function findIndex(array, fn) {
|
7298 | for (var i = 0; i < array.length; i += 1) {
|
7299 | if (fn(array[i], i)) { return i; }
|
7300 | }
|
7301 |
|
7302 | return -1;
|
7303 | }
|
7304 |
|
7305 | var handlers = {
|
7306 | Identifier: destructureIdentifier,
|
7307 | AssignmentPattern: destructureAssignmentPattern,
|
7308 | ArrayPattern: destructureArrayPattern,
|
7309 | ObjectPattern: destructureObjectPattern
|
7310 | };
|
7311 |
|
7312 | function destructure(
|
7313 | code,
|
7314 | createIdentifier,
|
7315 | resolveName,
|
7316 | node,
|
7317 | ref,
|
7318 | inline,
|
7319 | statementGenerators
|
7320 | ) {
|
7321 | handlers[node.type](code, createIdentifier, resolveName, node, ref, inline, statementGenerators);
|
7322 | }
|
7323 |
|
7324 | function destructureIdentifier(
|
7325 | code,
|
7326 | createIdentifier,
|
7327 | resolveName,
|
7328 | node,
|
7329 | ref,
|
7330 | inline,
|
7331 | statementGenerators
|
7332 | ) {
|
7333 | statementGenerators.push(function (start, prefix, suffix) {
|
7334 | code.overwrite(node.start, node.end, (inline ? prefix : (prefix + "var ")) + resolveName(node) + " = " + ref + suffix);
|
7335 | code.move(node.start, node.end, start);
|
7336 | });
|
7337 | }
|
7338 |
|
7339 | function destructureMemberExpression(
|
7340 | code,
|
7341 | createIdentifier,
|
7342 | resolveName,
|
7343 | node,
|
7344 | ref,
|
7345 | inline,
|
7346 | statementGenerators
|
7347 | ) {
|
7348 | statementGenerators.push(function (start, prefix, suffix) {
|
7349 | code.prependRight(node.start, inline ? prefix : (prefix + "var "));
|
7350 | code.appendLeft(node.end, (" = " + ref + suffix));
|
7351 | code.move(node.start, node.end, start);
|
7352 | });
|
7353 | }
|
7354 |
|
7355 | function destructureAssignmentPattern(
|
7356 | code,
|
7357 | createIdentifier,
|
7358 | resolveName,
|
7359 | node,
|
7360 | ref,
|
7361 | inline,
|
7362 | statementGenerators
|
7363 | ) {
|
7364 | var isIdentifier = node.left.type === 'Identifier';
|
7365 | var name = isIdentifier ? node.left.name : ref;
|
7366 |
|
7367 | if (!inline) {
|
7368 | statementGenerators.push(function (start, prefix, suffix) {
|
7369 | code.prependRight(
|
7370 | node.left.end,
|
7371 | (prefix + "if ( " + name + " === void 0 ) " + name)
|
7372 | );
|
7373 | code.move(node.left.end, node.right.end, start);
|
7374 | code.appendLeft(node.right.end, suffix);
|
7375 | });
|
7376 | }
|
7377 |
|
7378 | if (!isIdentifier) {
|
7379 | destructure(code, createIdentifier, resolveName, node.left, ref, inline, statementGenerators);
|
7380 | }
|
7381 | }
|
7382 |
|
7383 | function destructureArrayPattern(
|
7384 | code,
|
7385 | createIdentifier,
|
7386 | resolveName,
|
7387 | node,
|
7388 | ref,
|
7389 | inline,
|
7390 | statementGenerators
|
7391 | ) {
|
7392 | var c = node.start;
|
7393 |
|
7394 | node.elements.forEach(function (element, i) {
|
7395 | if (!element) { return; }
|
7396 |
|
7397 | if (element.type === 'RestElement') {
|
7398 | handleProperty(
|
7399 | code,
|
7400 | createIdentifier,
|
7401 | resolveName,
|
7402 | c,
|
7403 | element.argument,
|
7404 | (ref + ".slice(" + i + ")"),
|
7405 | inline,
|
7406 | statementGenerators
|
7407 | );
|
7408 | } else {
|
7409 | handleProperty(
|
7410 | code,
|
7411 | createIdentifier,
|
7412 | resolveName,
|
7413 | c,
|
7414 | element,
|
7415 | (ref + "[" + i + "]"),
|
7416 | inline,
|
7417 | statementGenerators
|
7418 | );
|
7419 | }
|
7420 | c = element.end;
|
7421 | });
|
7422 |
|
7423 | code.remove(c, node.end);
|
7424 | }
|
7425 |
|
7426 | function destructureObjectPattern(
|
7427 | code,
|
7428 | createIdentifier,
|
7429 | resolveName,
|
7430 | node,
|
7431 | ref,
|
7432 | inline,
|
7433 | statementGenerators
|
7434 | ) {
|
7435 | var this$1 = this;
|
7436 |
|
7437 | var c = node.start;
|
7438 |
|
7439 | var nonRestKeys = [];
|
7440 | node.properties.forEach(function (prop) {
|
7441 | var value;
|
7442 | var content;
|
7443 | if (prop.type === 'Property') {
|
7444 | content = prop.value;
|
7445 | if (!prop.computed && prop.key.type === 'Identifier') {
|
7446 | value = ref + "." + (prop.key.name);
|
7447 | nonRestKeys.push(("\"" + (prop.key.name) + "\""));
|
7448 | } else if (!prop.computed && prop.key.type === 'Literal') {
|
7449 | value = ref + "[" + (prop.key.raw) + "]";
|
7450 | nonRestKeys.push(JSON.stringify(String(prop.key.value)));
|
7451 | } else {
|
7452 | var expr = code.slice(prop.key.start, prop.key.end);
|
7453 | value = ref + "[" + expr + "]";
|
7454 | nonRestKeys.push(("String(" + expr + ")"));
|
7455 | }
|
7456 | } else if (prop.type === 'RestElement') {
|
7457 | content = prop.argument;
|
7458 | value = createIdentifier('rest');
|
7459 | statementGenerators.push(function (start, prefix, suffix) {
|
7460 | var helper = prop.program.getObjectWithoutPropertiesHelper(code);
|
7461 | code.overwrite(
|
7462 | prop.start,
|
7463 | (c = prop.argument.start),
|
7464 | (inline ? prefix : (prefix + "var ")) + value + " = " + helper + "( " + ref + ", [" + (nonRestKeys.join(', ')) + "] )" + suffix
|
7465 | );
|
7466 | code.move(prop.start, c, start);
|
7467 | });
|
7468 | } else {
|
7469 | throw new CompileError(
|
7470 | this$1,
|
7471 | ("Unexpected node of type " + (prop.type) + " in object pattern")
|
7472 | );
|
7473 | }
|
7474 | handleProperty(code, createIdentifier, resolveName, c, content, value, inline, statementGenerators);
|
7475 | c = prop.end;
|
7476 | });
|
7477 |
|
7478 | code.remove(c, node.end);
|
7479 | }
|
7480 |
|
7481 | function handleProperty(
|
7482 | code,
|
7483 | createIdentifier,
|
7484 | resolveName,
|
7485 | c,
|
7486 | node,
|
7487 | value,
|
7488 | inline,
|
7489 | statementGenerators
|
7490 | ) {
|
7491 | switch (node.type) {
|
7492 | case 'Identifier': {
|
7493 | code.remove(c, node.start);
|
7494 | destructureIdentifier(
|
7495 | code,
|
7496 | createIdentifier,
|
7497 | resolveName,
|
7498 | node,
|
7499 | value,
|
7500 | inline,
|
7501 | statementGenerators
|
7502 | );
|
7503 | break;
|
7504 | }
|
7505 |
|
7506 | case 'MemberExpression':
|
7507 | code.remove(c, node.start);
|
7508 | destructureMemberExpression(
|
7509 | code,
|
7510 | createIdentifier,
|
7511 | resolveName,
|
7512 | node,
|
7513 | value,
|
7514 | true,
|
7515 | statementGenerators
|
7516 | );
|
7517 | break;
|
7518 |
|
7519 | case 'AssignmentPattern': {
|
7520 | var name;
|
7521 |
|
7522 | var isIdentifier = node.left.type === 'Identifier';
|
7523 |
|
7524 | if (isIdentifier) {
|
7525 | name = resolveName(node.left);
|
7526 | } else {
|
7527 | name = createIdentifier(value);
|
7528 | }
|
7529 |
|
7530 | statementGenerators.push(function (start, prefix, suffix) {
|
7531 | if (inline) {
|
7532 | code.prependRight(
|
7533 | node.right.start,
|
7534 | (name + " = " + value + ", " + name + " = " + name + " === void 0 ? ")
|
7535 | );
|
7536 | code.appendLeft(node.right.end, (" : " + name + suffix));
|
7537 | } else {
|
7538 | code.prependRight(
|
7539 | node.right.start,
|
7540 | (prefix + "var " + name + " = " + value + "; if ( " + name + " === void 0 ) " + name + " = ")
|
7541 | );
|
7542 | code.appendLeft(node.right.end, suffix);
|
7543 | }
|
7544 |
|
7545 | code.move(node.right.start, node.right.end, start);
|
7546 | });
|
7547 |
|
7548 | if (isIdentifier) {
|
7549 | code.remove(c, node.right.start);
|
7550 | } else {
|
7551 | code.remove(c, node.left.start);
|
7552 | code.remove(node.left.end, node.right.start);
|
7553 | handleProperty(
|
7554 | code,
|
7555 | createIdentifier,
|
7556 | resolveName,
|
7557 | c,
|
7558 | node.left,
|
7559 | name,
|
7560 | inline,
|
7561 | statementGenerators
|
7562 | );
|
7563 | }
|
7564 |
|
7565 | break;
|
7566 | }
|
7567 |
|
7568 | case 'ObjectPattern': {
|
7569 | code.remove(c, (c = node.start));
|
7570 |
|
7571 | var ref = value;
|
7572 | if (node.properties.length > 1) {
|
7573 | ref = createIdentifier(value);
|
7574 |
|
7575 | statementGenerators.push(function (start, prefix, suffix) {
|
7576 | // this feels a tiny bit hacky, but we can't do a
|
7577 | // straightforward appendLeft and keep correct order...
|
7578 | code.prependRight(node.start, (inline ? '' : (prefix + "var ")) + ref + " = ");
|
7579 | code.overwrite(node.start, (c = node.start + 1), value);
|
7580 | code.appendLeft(c, suffix);
|
7581 |
|
7582 | code.overwrite(
|
7583 | node.start,
|
7584 | (c = node.start + 1),
|
7585 | (inline ? '' : (prefix + "var ")) + ref + " = " + value + suffix
|
7586 | );
|
7587 | code.move(node.start, c, start);
|
7588 | });
|
7589 | }
|
7590 |
|
7591 | destructureObjectPattern(
|
7592 | code,
|
7593 | createIdentifier,
|
7594 | resolveName,
|
7595 | node,
|
7596 | ref,
|
7597 | inline,
|
7598 | statementGenerators
|
7599 | );
|
7600 |
|
7601 | break;
|
7602 | }
|
7603 |
|
7604 | case 'ArrayPattern': {
|
7605 | code.remove(c, (c = node.start));
|
7606 |
|
7607 | if (node.elements.filter(Boolean).length > 1) {
|
7608 | var ref$1 = createIdentifier(value);
|
7609 |
|
7610 | statementGenerators.push(function (start, prefix, suffix) {
|
7611 | code.prependRight(node.start, (inline ? '' : (prefix + "var ")) + ref$1 + " = ");
|
7612 | code.overwrite(node.start, (c = node.start + 1), value, {
|
7613 | contentOnly: true
|
7614 | });
|
7615 | code.appendLeft(c, suffix);
|
7616 |
|
7617 | code.move(node.start, c, start);
|
7618 | });
|
7619 |
|
7620 | node.elements.forEach(function (element, i) {
|
7621 | if (!element) { return; }
|
7622 |
|
7623 | if (element.type === 'RestElement') {
|
7624 | handleProperty(
|
7625 | code,
|
7626 | createIdentifier,
|
7627 | resolveName,
|
7628 | c,
|
7629 | element.argument,
|
7630 | (ref$1 + ".slice(" + i + ")"),
|
7631 | inline,
|
7632 | statementGenerators
|
7633 | );
|
7634 | } else {
|
7635 | handleProperty(
|
7636 | code,
|
7637 | createIdentifier,
|
7638 | resolveName,
|
7639 | c,
|
7640 | element,
|
7641 | (ref$1 + "[" + i + "]"),
|
7642 | inline,
|
7643 | statementGenerators
|
7644 | );
|
7645 | }
|
7646 | c = element.end;
|
7647 | });
|
7648 | } else {
|
7649 | var index = findIndex(node.elements, Boolean);
|
7650 | var element = node.elements[index];
|
7651 | if (element.type === 'RestElement') {
|
7652 | handleProperty(
|
7653 | code,
|
7654 | createIdentifier,
|
7655 | resolveName,
|
7656 | c,
|
7657 | element.argument,
|
7658 | (value + ".slice(" + index + ")"),
|
7659 | inline,
|
7660 | statementGenerators
|
7661 | );
|
7662 | } else {
|
7663 | handleProperty(
|
7664 | code,
|
7665 | createIdentifier,
|
7666 | resolveName,
|
7667 | c,
|
7668 | element,
|
7669 | (value + "[" + index + "]"),
|
7670 | inline,
|
7671 | statementGenerators
|
7672 | );
|
7673 | }
|
7674 | c = element.end;
|
7675 | }
|
7676 |
|
7677 | code.remove(c, node.end);
|
7678 | break;
|
7679 | }
|
7680 |
|
7681 | default: {
|
7682 | throw new Error(("Unexpected node type in destructuring (" + (node.type) + ")"));
|
7683 | }
|
7684 | }
|
7685 | }
|
7686 |
|
7687 | function isUseStrict(node) {
|
7688 | if (!node) { return false; }
|
7689 | if (node.type !== 'ExpressionStatement') { return false; }
|
7690 | if (node.expression.type !== 'Literal') { return false; }
|
7691 | return node.expression.value === 'use strict';
|
7692 | }
|
7693 |
|
7694 | var BlockStatement = /*@__PURE__*/(function (Node) {
|
7695 | function BlockStatement () {
|
7696 | Node.apply(this, arguments);
|
7697 | }
|
7698 |
|
7699 | if ( Node ) BlockStatement.__proto__ = Node;
|
7700 | BlockStatement.prototype = Object.create( Node && Node.prototype );
|
7701 | BlockStatement.prototype.constructor = BlockStatement;
|
7702 |
|
7703 | BlockStatement.prototype.createScope = function createScope () {
|
7704 | var this$1 = this;
|
7705 |
|
7706 | this.parentIsFunction = /Function/.test(this.parent.type);
|
7707 | this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root';
|
7708 | this.scope = new Scope$1({
|
7709 | block: !this.isFunctionBlock,
|
7710 | parent: this.parent.findScope(false),
|
7711 | declare: function (id) { return this$1.createdDeclarations.push(id); }
|
7712 | });
|
7713 |
|
7714 | if (this.parentIsFunction) {
|
7715 | this.parent.params.forEach(function (node) {
|
7716 | this$1.scope.addDeclaration(node, 'param');
|
7717 | });
|
7718 | }
|
7719 | };
|
7720 |
|
7721 | BlockStatement.prototype.initialise = function initialise (transforms) {
|
7722 | this.thisAlias = null;
|
7723 | this.argumentsAlias = null;
|
7724 | this.defaultParameters = [];
|
7725 | this.createdDeclarations = [];
|
7726 |
|
7727 | // normally the scope gets created here, during initialisation,
|
7728 | // but in some cases (e.g. `for` statements), we need to create
|
7729 | // the scope early, as it pertains to both the init block and
|
7730 | // the body of the statement
|
7731 | if (!this.scope) { this.createScope(); }
|
7732 |
|
7733 | this.body.forEach(function (node) { return node.initialise(transforms); });
|
7734 |
|
7735 | this.scope.consolidate();
|
7736 | };
|
7737 |
|
7738 | BlockStatement.prototype.findLexicalBoundary = function findLexicalBoundary () {
|
7739 | if (this.type === 'Program') { return this; }
|
7740 | if (/^Function/.test(this.parent.type)) { return this; }
|
7741 |
|
7742 | return this.parent.findLexicalBoundary();
|
7743 | };
|
7744 |
|
7745 | BlockStatement.prototype.findScope = function findScope (functionScope) {
|
7746 | if (functionScope && !this.isFunctionBlock)
|
7747 | { return this.parent.findScope(functionScope); }
|
7748 | return this.scope;
|
7749 | };
|
7750 |
|
7751 | BlockStatement.prototype.getArgumentsAlias = function getArgumentsAlias () {
|
7752 | if (!this.argumentsAlias) {
|
7753 | this.argumentsAlias = this.scope.createIdentifier('arguments');
|
7754 | }
|
7755 |
|
7756 | return this.argumentsAlias;
|
7757 | };
|
7758 |
|
7759 | BlockStatement.prototype.getArgumentsArrayAlias = function getArgumentsArrayAlias () {
|
7760 | if (!this.argumentsArrayAlias) {
|
7761 | this.argumentsArrayAlias = this.scope.createIdentifier('argsArray');
|
7762 | }
|
7763 |
|
7764 | return this.argumentsArrayAlias;
|
7765 | };
|
7766 |
|
7767 | BlockStatement.prototype.getThisAlias = function getThisAlias () {
|
7768 | if (!this.thisAlias) {
|
7769 | this.thisAlias = this.scope.createIdentifier('this');
|
7770 | }
|
7771 |
|
7772 | return this.thisAlias;
|
7773 | };
|
7774 |
|
7775 | BlockStatement.prototype.getIndentation = function getIndentation () {
|
7776 | if (this.indentation === undefined) {
|
7777 | var source = this.program.magicString.original;
|
7778 |
|
7779 | var useOuter = this.synthetic || !this.body.length;
|
7780 | var c = useOuter ? this.start : this.body[0].start;
|
7781 |
|
7782 | while (c && source[c] !== '\n') { c -= 1; }
|
7783 |
|
7784 | this.indentation = '';
|
7785 |
|
7786 | // eslint-disable-next-line no-constant-condition
|
7787 | while (true) {
|
7788 | c += 1;
|
7789 | var char = source[c];
|
7790 |
|
7791 | if (char !== ' ' && char !== '\t') { break; }
|
7792 |
|
7793 | this.indentation += char;
|
7794 | }
|
7795 |
|
7796 | var indentString = this.program.magicString.getIndentString();
|
7797 |
|
7798 | // account for dedented class constructors
|
7799 | var parent = this.parent;
|
7800 | while (parent) {
|
7801 | if (parent.kind === 'constructor' && !parent.parent.parent.superClass) {
|
7802 | this.indentation = this.indentation.replace(indentString, '');
|
7803 | }
|
7804 |
|
7805 | parent = parent.parent;
|
7806 | }
|
7807 |
|
7808 | if (useOuter) { this.indentation += indentString; }
|
7809 | }
|
7810 |
|
7811 | return this.indentation;
|
7812 | };
|
7813 |
|
7814 | BlockStatement.prototype.transpile = function transpile (code, transforms) {
|
7815 | var this$1 = this;
|
7816 |
|
7817 | var indentation = this.getIndentation();
|
7818 |
|
7819 | var introStatementGenerators = [];
|
7820 |
|
7821 | if (this.argumentsAlias) {
|
7822 | introStatementGenerators.push(function (start, prefix, suffix) {
|
7823 | var assignment = prefix + "var " + (this$1.argumentsAlias) + " = arguments" + suffix;
|
7824 | code.appendLeft(start, assignment);
|
7825 | });
|
7826 | }
|
7827 |
|
7828 | if (this.thisAlias) {
|
7829 | introStatementGenerators.push(function (start, prefix, suffix) {
|
7830 | var assignment = prefix + "var " + (this$1.thisAlias) + " = this" + suffix;
|
7831 | code.appendLeft(start, assignment);
|
7832 | });
|
7833 | }
|
7834 |
|
7835 | if (this.argumentsArrayAlias) {
|
7836 | introStatementGenerators.push(function (start, prefix, suffix) {
|
7837 | var i = this$1.scope.createIdentifier('i');
|
7838 | var assignment = prefix + "var " + i + " = arguments.length, " + (this$1.argumentsArrayAlias) + " = Array(" + i + ");\n" + indentation + "while ( " + i + "-- ) " + (this$1.argumentsArrayAlias) + "[" + i + "] = arguments[" + i + "]" + suffix;
|
7839 | code.appendLeft(start, assignment);
|
7840 | });
|
7841 | }
|
7842 |
|
7843 | if (/Function/.test(this.parent.type)) {
|
7844 | this.transpileParameters(
|
7845 | this.parent.params,
|
7846 | code,
|
7847 | transforms,
|
7848 | indentation,
|
7849 | introStatementGenerators
|
7850 | );
|
7851 | } else if ('CatchClause' === this.parent.type) {
|
7852 | this.transpileParameters(
|
7853 | [this.parent.param],
|
7854 | code,
|
7855 | transforms,
|
7856 | indentation,
|
7857 | introStatementGenerators
|
7858 | );
|
7859 | }
|
7860 |
|
7861 | if (transforms.letConst && this.isFunctionBlock) {
|
7862 | this.transpileBlockScopedIdentifiers(code);
|
7863 | }
|
7864 |
|
7865 | Node.prototype.transpile.call(this, code, transforms);
|
7866 |
|
7867 | if (this.createdDeclarations.length) {
|
7868 | introStatementGenerators.push(function (start, prefix, suffix) {
|
7869 | var assignment = prefix + "var " + (this$1.createdDeclarations.join(', ')) + suffix;
|
7870 | code.appendLeft(start, assignment);
|
7871 | });
|
7872 | }
|
7873 |
|
7874 | if (this.synthetic) {
|
7875 | if (this.parent.type === 'ArrowFunctionExpression') {
|
7876 | var expr = this.body[0];
|
7877 |
|
7878 | if (introStatementGenerators.length) {
|
7879 | code
|
7880 | .appendLeft(this.start, "{")
|
7881 | .prependRight(this.end, ((this.parent.getIndentation()) + "}"));
|
7882 |
|
7883 | code.prependRight(expr.start, ("\n" + indentation + "return "));
|
7884 | code.appendLeft(expr.end, ";\n");
|
7885 | } else if (transforms.arrow) {
|
7886 | code.prependRight(expr.start, "{ return ");
|
7887 | code.appendLeft(expr.end, "; }");
|
7888 | }
|
7889 | } else if (introStatementGenerators.length) {
|
7890 | code.prependRight(this.start, "{").appendLeft(this.end, "}");
|
7891 | }
|
7892 | }
|
7893 |
|
7894 | var start;
|
7895 | if (isUseStrict(this.body[0])) {
|
7896 | start = this.body[0].end;
|
7897 | } else if (this.synthetic || this.parent.type === 'Root') {
|
7898 | start = this.start;
|
7899 | } else {
|
7900 | start = this.start + 1;
|
7901 | }
|
7902 |
|
7903 | var prefix = "\n" + indentation;
|
7904 | var suffix = ';';
|
7905 | introStatementGenerators.forEach(function (fn, i) {
|
7906 | if (i === introStatementGenerators.length - 1) { suffix = ";\n"; }
|
7907 | fn(start, prefix, suffix);
|
7908 | });
|
7909 | };
|
7910 |
|
7911 | BlockStatement.prototype.transpileParameters = function transpileParameters (params, code, transforms, indentation, introStatementGenerators) {
|
7912 | var this$1 = this;
|
7913 |
|
7914 | params.forEach(function (param) {
|
7915 | if (
|
7916 | param.type === 'AssignmentPattern' &&
|
7917 | param.left.type === 'Identifier'
|
7918 | ) {
|
7919 | if (transforms.defaultParameter) {
|
7920 | introStatementGenerators.push(function (start, prefix, suffix) {
|
7921 | var lhs = prefix + "if ( " + (param.left.name) + " === void 0 ) " + (param.left.name);
|
7922 |
|
7923 | code
|
7924 | .prependRight(param.left.end, lhs)
|
7925 | .move(param.left.end, param.right.end, start)
|
7926 | .appendLeft(param.right.end, suffix);
|
7927 | });
|
7928 | }
|
7929 | } else if (param.type === 'RestElement') {
|
7930 | if (transforms.spreadRest) {
|
7931 | introStatementGenerators.push(function (start, prefix, suffix) {
|
7932 | var penultimateParam = params[params.length - 2];
|
7933 |
|
7934 | if (penultimateParam) {
|
7935 | code.remove(
|
7936 | penultimateParam ? penultimateParam.end : param.start,
|
7937 | param.end
|
7938 | );
|
7939 | } else {
|
7940 | var start$1 = param.start,
|
7941 | end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8
|
7942 |
|
7943 | while (/\s/.test(code.original[start$1 - 1])) { start$1 -= 1; }
|
7944 | while (/\s/.test(code.original[end])) { end += 1; }
|
7945 |
|
7946 | code.remove(start$1, end);
|
7947 | }
|
7948 |
|
7949 | var name = param.argument.name;
|
7950 | var len = this$1.scope.createIdentifier('len');
|
7951 | var count = params.length - 1;
|
7952 |
|
7953 | if (count) {
|
7954 | code.prependRight(
|
7955 | start,
|
7956 | (prefix + "var " + name + " = [], " + len + " = arguments.length - " + count + ";\n" + indentation + "while ( " + len + "-- > 0 ) " + name + "[ " + len + " ] = arguments[ " + len + " + " + count + " ]" + suffix)
|
7957 | );
|
7958 | } else {
|
7959 | code.prependRight(
|
7960 | start,
|
7961 | (prefix + "var " + name + " = [], " + len + " = arguments.length;\n" + indentation + "while ( " + len + "-- ) " + name + "[ " + len + " ] = arguments[ " + len + " ]" + suffix)
|
7962 | );
|
7963 | }
|
7964 | });
|
7965 | }
|
7966 | } else if (param.type !== 'Identifier') {
|
7967 | if (transforms.parameterDestructuring) {
|
7968 | var ref = this$1.scope.createIdentifier('ref');
|
7969 | destructure(
|
7970 | code,
|
7971 | function (id) { return this$1.scope.createIdentifier(id); },
|
7972 | function (ref) {
|
7973 | var name = ref.name;
|
7974 |
|
7975 | return this$1.scope.resolveName(name);
|
7976 | },
|
7977 | param,
|
7978 | ref,
|
7979 | false,
|
7980 | introStatementGenerators
|
7981 | );
|
7982 | code.prependRight(param.start, ref);
|
7983 | }
|
7984 | }
|
7985 | });
|
7986 | };
|
7987 |
|
7988 | BlockStatement.prototype.transpileBlockScopedIdentifiers = function transpileBlockScopedIdentifiers (code) {
|
7989 | var this$1 = this;
|
7990 |
|
7991 | Object.keys(this.scope.blockScopedDeclarations).forEach(function (name) {
|
7992 | var declarations = this$1.scope.blockScopedDeclarations[name];
|
7993 |
|
7994 | for (var i$2 = 0, list$2 = declarations; i$2 < list$2.length; i$2 += 1) {
|
7995 | var declaration = list$2[i$2];
|
7996 |
|
7997 | var cont = false; // TODO implement proper continue...
|
7998 |
|
7999 | if (declaration.kind === 'for.let') {
|
8000 | // special case
|
8001 | var forStatement = declaration.node.findNearest('ForStatement');
|
8002 |
|
8003 | if (forStatement.shouldRewriteAsFunction) {
|
8004 | var outerAlias = this$1.scope.createIdentifier(name);
|
8005 | var innerAlias = forStatement.reassigned[name]
|
8006 | ? this$1.scope.createIdentifier(name)
|
8007 | : name;
|
8008 |
|
8009 | declaration.name = outerAlias;
|
8010 | code.overwrite(
|
8011 | declaration.node.start,
|
8012 | declaration.node.end,
|
8013 | outerAlias,
|
8014 | { storeName: true }
|
8015 | );
|
8016 |
|
8017 | forStatement.aliases[name] = {
|
8018 | outer: outerAlias,
|
8019 | inner: innerAlias
|
8020 | };
|
8021 |
|
8022 | for (var i = 0, list = declaration.instances; i < list.length; i += 1) {
|
8023 | var identifier = list[i];
|
8024 |
|
8025 | var alias = forStatement.body.contains(identifier)
|
8026 | ? innerAlias
|
8027 | : outerAlias;
|
8028 |
|
8029 | if (name !== alias) {
|
8030 | code.overwrite(identifier.start, identifier.end, alias, {
|
8031 | storeName: true
|
8032 | });
|
8033 | }
|
8034 | }
|
8035 |
|
8036 | cont = true;
|
8037 | }
|
8038 | }
|
8039 |
|
8040 | if (!cont) {
|
8041 | var alias$1 = this$1.scope.createIdentifier(name);
|
8042 |
|
8043 | if (name !== alias$1) {
|
8044 | var declarationParent = declaration.node.parent;
|
8045 | declaration.name = alias$1;
|
8046 | code.overwrite(
|
8047 | declaration.node.start,
|
8048 | declaration.node.end,
|
8049 | alias$1,
|
8050 | { storeName: true }
|
8051 | );
|
8052 | if (declarationParent.type === 'Property' && declarationParent.shorthand) {
|
8053 | declarationParent.shorthand = false;
|
8054 | code.prependLeft(declaration.node.start, (name + ": "));
|
8055 | }
|
8056 |
|
8057 | for (var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1) {
|
8058 | var identifier$1 = list$1[i$1];
|
8059 |
|
8060 | identifier$1.rewritten = true;
|
8061 | var identifierParent = identifier$1.parent;
|
8062 | code.overwrite(identifier$1.start, identifier$1.end, alias$1, {
|
8063 | storeName: true
|
8064 | });
|
8065 | if (identifierParent.type === 'Property' && identifierParent.shorthand) {
|
8066 | identifierParent.shorthand = false;
|
8067 | code.prependLeft(identifier$1.start, (name + ": "));
|
8068 | }
|
8069 | }
|
8070 | }
|
8071 | }
|
8072 | }
|
8073 | });
|
8074 | };
|
8075 |
|
8076 | return BlockStatement;
|
8077 | }(Node$1));
|
8078 |
|
8079 | function isArguments(node) {
|
8080 | return node.type === 'Identifier' && node.name === 'arguments';
|
8081 | }
|
8082 |
|
8083 | function inlineSpreads(
|
8084 | code,
|
8085 | node,
|
8086 | elements
|
8087 | ) {
|
8088 | var i = elements.length;
|
8089 |
|
8090 | while (i--) {
|
8091 | var element = elements[i];
|
8092 | if (!element || element.type !== 'SpreadElement') {
|
8093 | continue;
|
8094 | }
|
8095 | var argument = element.argument;
|
8096 | if (argument.type !== 'ArrayExpression') {
|
8097 | continue;
|
8098 | }
|
8099 | var subelements = argument.elements;
|
8100 | if (subelements.some(function (subelement) { return subelement === null; })) {
|
8101 | // Not even going to try inlining spread arrays with holes.
|
8102 | // It's a lot of work (got to be VERY careful in comma counting for
|
8103 | // ArrayExpression, and turn blanks into undefined for
|
8104 | // CallExpression and NewExpression), and probably literally no one
|
8105 | // would ever benefit from it.
|
8106 | continue;
|
8107 | }
|
8108 | // We can inline it: drop the `...[` and `]` and sort out any commas.
|
8109 | var isLast = i === elements.length - 1;
|
8110 | if (subelements.length === 0) {
|
8111 | code.remove(
|
8112 | isLast && i !== 0
|
8113 | ? elements[i - 1].end // Take the previous comma too
|
8114 | : element.start,
|
8115 | isLast
|
8116 | ? node.end - 1 // Must remove trailing comma; element.end wouldn’t
|
8117 | : elements[i + 1].start);
|
8118 | } else {
|
8119 | // Strip the `...[` and the `]` with a possible trailing comma before it,
|
8120 | // leaving just the possible trailing comma after it.
|
8121 | code.remove(element.start, subelements[0].start);
|
8122 | code.remove(
|
8123 | // Strip a possible trailing comma after the last element
|
8124 | subelements[subelements.length - 1].end,
|
8125 | // And also a possible trailing comma after the spread
|
8126 | isLast
|
8127 | ? node.end - 1
|
8128 | : element.end
|
8129 | );
|
8130 | }
|
8131 | elements.splice.apply(elements, [ i, 1 ].concat( subelements ));
|
8132 | i += subelements.length;
|
8133 | }
|
8134 | }
|
8135 |
|
8136 | // Returns false if it’s safe to simply append a method call to the node,
|
8137 | // e.g. `a` → `a.concat()`.
|
8138 | //
|
8139 | // Returns true if it may not be and so parentheses should be employed,
|
8140 | // e.g. `a ? b : c` → `a ? b : c.concat()` would be wrong.
|
8141 | //
|
8142 | // This test may be overcautious; if desired it can be refined over time.
|
8143 | function needsParentheses(node) {
|
8144 | switch (node.type) {
|
8145 | // Currently whitelisted are all relevant ES5 node types ('Literal' and
|
8146 | // 'ObjectExpression' are skipped as irrelevant for array/call spread.)
|
8147 | case 'ArrayExpression':
|
8148 | case 'CallExpression':
|
8149 | case 'Identifier':
|
8150 | case 'ParenthesizedExpression':
|
8151 | case 'ThisExpression':
|
8152 | return false;
|
8153 | default:
|
8154 | return true;
|
8155 | }
|
8156 | }
|
8157 |
|
8158 | function spread(
|
8159 | code,
|
8160 | elements,
|
8161 | start,
|
8162 | argumentsArrayAlias,
|
8163 | isNew
|
8164 | ) {
|
8165 | var i = elements.length;
|
8166 | var firstSpreadIndex = -1;
|
8167 |
|
8168 | while (i--) {
|
8169 | var element$1 = elements[i];
|
8170 | if (element$1 && element$1.type === 'SpreadElement') {
|
8171 | if (isArguments(element$1.argument)) {
|
8172 | code.overwrite(
|
8173 | element$1.argument.start,
|
8174 | element$1.argument.end,
|
8175 | argumentsArrayAlias
|
8176 | );
|
8177 | }
|
8178 |
|
8179 | firstSpreadIndex = i;
|
8180 | }
|
8181 | }
|
8182 |
|
8183 | if (firstSpreadIndex === -1) { return false; } // false indicates no spread elements
|
8184 |
|
8185 | if (isNew) {
|
8186 | for (i = 0; i < elements.length; i += 1) {
|
8187 | var element$2 = elements[i];
|
8188 | if (element$2.type === 'SpreadElement') {
|
8189 | code.remove(element$2.start, element$2.argument.start);
|
8190 | } else {
|
8191 | code.prependRight(element$2.start, '[');
|
8192 | code.prependRight(element$2.end, ']');
|
8193 | }
|
8194 | }
|
8195 |
|
8196 | return true; // true indicates some spread elements
|
8197 | }
|
8198 |
|
8199 | var element = elements[firstSpreadIndex];
|
8200 | var previousElement = elements[firstSpreadIndex - 1];
|
8201 |
|
8202 | if (!previousElement) {
|
8203 | // We may need to parenthesize it to handle ternaries like [...a ? b : c].
|
8204 | var addClosingParen;
|
8205 | if (start !== element.start) {
|
8206 | if ((addClosingParen = needsParentheses(element.argument))) {
|
8207 | code.overwrite(start, element.start, '( ');
|
8208 | } else {
|
8209 | code.remove(start, element.start);
|
8210 | }
|
8211 | } else if (element.parent.type === 'CallExpression') {
|
8212 | // CallExpression inserts `( ` itself, we add the ).
|
8213 | // (Yeah, CallExpression did the needsParentheses call already,
|
8214 | // but we don’t have its result handy, so do it again. It’s cheap.)
|
8215 | addClosingParen = needsParentheses(element.argument);
|
8216 | } else {
|
8217 | // Should be unreachable, but doing this is more robust.
|
8218 | throw new CompileError(
|
8219 | 'Unsupported spread construct, please raise an issue at https://github.com/bublejs/buble/issues',
|
8220 | element
|
8221 | );
|
8222 | }
|
8223 | code.overwrite(element.end, elements[1].start,
|
8224 | addClosingParen ? ' ).concat( ' : '.concat( ');
|
8225 | } else {
|
8226 | code.overwrite(previousElement.end, element.start, ' ].concat( ');
|
8227 | }
|
8228 |
|
8229 | for (i = firstSpreadIndex; i < elements.length; i += 1) {
|
8230 | element = elements[i];
|
8231 |
|
8232 | if (element) {
|
8233 | if (element.type === 'SpreadElement') {
|
8234 | code.remove(element.start, element.argument.start);
|
8235 | } else {
|
8236 | code.appendLeft(element.start, '[');
|
8237 | code.appendLeft(element.end, ']');
|
8238 | }
|
8239 | }
|
8240 | }
|
8241 |
|
8242 | return true; // true indicates some spread elements
|
8243 | }
|
8244 |
|
8245 | var ArrayExpression = /*@__PURE__*/(function (Node) {
|
8246 | function ArrayExpression () {
|
8247 | Node.apply(this, arguments);
|
8248 | }
|
8249 |
|
8250 | if ( Node ) ArrayExpression.__proto__ = Node;
|
8251 | ArrayExpression.prototype = Object.create( Node && Node.prototype );
|
8252 | ArrayExpression.prototype.constructor = ArrayExpression;
|
8253 |
|
8254 | ArrayExpression.prototype.initialise = function initialise (transforms) {
|
8255 | if (transforms.spreadRest && this.elements.length) {
|
8256 | var lexicalBoundary = this.findLexicalBoundary();
|
8257 |
|
8258 | var i = this.elements.length;
|
8259 | while (i--) {
|
8260 | var element = this.elements[i];
|
8261 | if (
|
8262 | element &&
|
8263 | element.type === 'SpreadElement' &&
|
8264 | isArguments(element.argument)
|
8265 | ) {
|
8266 | this.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
|
8267 | }
|
8268 | }
|
8269 | }
|
8270 |
|
8271 | Node.prototype.initialise.call(this, transforms);
|
8272 | };
|
8273 |
|
8274 | ArrayExpression.prototype.transpile = function transpile (code, transforms) {
|
8275 | Node.prototype.transpile.call(this, code, transforms);
|
8276 |
|
8277 | if (transforms.spreadRest) {
|
8278 | inlineSpreads(code, this, this.elements);
|
8279 | // erase trailing comma after last array element if not an array hole
|
8280 | if (this.elements.length) {
|
8281 | var lastElement = this.elements[this.elements.length - 1];
|
8282 | if (
|
8283 | lastElement &&
|
8284 | /\s*,/.test(code.original.slice(lastElement.end, this.end))
|
8285 | ) {
|
8286 | code.overwrite(lastElement.end, this.end - 1, ' ');
|
8287 | }
|
8288 | }
|
8289 |
|
8290 | if (this.elements.length === 1) {
|
8291 | var element = this.elements[0];
|
8292 |
|
8293 | if (element && element.type === 'SpreadElement') {
|
8294 | // special case – [ ...arguments ]
|
8295 | if (isArguments(element.argument)) {
|
8296 | code.overwrite(
|
8297 | this.start,
|
8298 | this.end,
|
8299 | ("[].concat( " + (this.argumentsArrayAlias) + " )")
|
8300 | ); // TODO if this is the only use of argsArray, don't bother concating
|
8301 | } else {
|
8302 | code.overwrite(this.start, element.argument.start, '[].concat( ');
|
8303 | code.overwrite(element.end, this.end, ' )');
|
8304 | }
|
8305 | }
|
8306 | } else {
|
8307 | var hasSpreadElements = spread(
|
8308 | code,
|
8309 | this.elements,
|
8310 | this.start,
|
8311 | this.argumentsArrayAlias
|
8312 | );
|
8313 |
|
8314 | if (hasSpreadElements) {
|
8315 | code.overwrite(this.end - 1, this.end, ')');
|
8316 | }
|
8317 | }
|
8318 | }
|
8319 | };
|
8320 |
|
8321 | return ArrayExpression;
|
8322 | }(Node$1));
|
8323 |
|
8324 | function removeTrailingComma(code, c) {
|
8325 | while (code.original[c] !== ')') {
|
8326 | if (code.original[c] === ',') {
|
8327 | code.remove(c, c + 1);
|
8328 | return;
|
8329 | }
|
8330 |
|
8331 | if (code.original[c] === '/') {
|
8332 | if (code.original[c + 1] === '/') {
|
8333 | c = code.original.indexOf('\n', c);
|
8334 | } else {
|
8335 | c = code.original.indexOf('*/', c) + 1;
|
8336 | }
|
8337 | }
|
8338 | c += 1;
|
8339 | }
|
8340 | }
|
8341 |
|
8342 | var ArrowFunctionExpression = /*@__PURE__*/(function (Node) {
|
8343 | function ArrowFunctionExpression () {
|
8344 | Node.apply(this, arguments);
|
8345 | }
|
8346 |
|
8347 | if ( Node ) ArrowFunctionExpression.__proto__ = Node;
|
8348 | ArrowFunctionExpression.prototype = Object.create( Node && Node.prototype );
|
8349 | ArrowFunctionExpression.prototype.constructor = ArrowFunctionExpression;
|
8350 |
|
8351 | ArrowFunctionExpression.prototype.initialise = function initialise (transforms) {
|
8352 | if (this.async && transforms.asyncAwait) {
|
8353 | CompileError.missingTransform("async arrow functions", "asyncAwait", this);
|
8354 | }
|
8355 | this.body.createScope();
|
8356 | Node.prototype.initialise.call(this, transforms);
|
8357 | };
|
8358 |
|
8359 | ArrowFunctionExpression.prototype.transpile = function transpile (code, transforms) {
|
8360 | var openParensPos = this.start;
|
8361 | for (var end = (this.body || this.params[0]).start - 1; code.original[openParensPos] !== '(' && openParensPos < end;) {
|
8362 | ++openParensPos;
|
8363 | }
|
8364 | if (code.original[openParensPos] !== '(') { openParensPos = -1; }
|
8365 | var naked = openParensPos === -1;
|
8366 |
|
8367 | if (transforms.arrow || this.needsArguments(transforms)) {
|
8368 | // remove arrow
|
8369 | var charIndex = this.body.start;
|
8370 | while (code.original[charIndex] !== '=') {
|
8371 | charIndex -= 1;
|
8372 | }
|
8373 | code.remove(charIndex, this.body.start);
|
8374 |
|
8375 | Node.prototype.transpile.call(this, code, transforms);
|
8376 |
|
8377 | // wrap naked parameter
|
8378 | if (naked) {
|
8379 | code.prependRight(this.params[0].start, '(');
|
8380 | code.appendLeft(this.params[0].end, ')');
|
8381 | }
|
8382 |
|
8383 | // standalone expression statement
|
8384 | var standalone = this.parent && this.parent.type === 'ExpressionStatement';
|
8385 | var start, text = standalone ? '!' : '';
|
8386 | if (this.async) { text += 'async '; }
|
8387 | text += 'function';
|
8388 | if (!standalone) { text += ' '; }
|
8389 | if (naked) {
|
8390 | start = this.params[0].start;
|
8391 | } else {
|
8392 | start = openParensPos;
|
8393 | }
|
8394 | // add function
|
8395 | if (start > this.start) {
|
8396 | code.overwrite(this.start, start, text);
|
8397 | } else {
|
8398 | code.prependRight(this.start, text);
|
8399 | }
|
8400 | } else {
|
8401 | Node.prototype.transpile.call(this, code, transforms);
|
8402 | }
|
8403 |
|
8404 | if (transforms.trailingFunctionCommas && this.params.length && !naked) {
|
8405 | removeTrailingComma(code, this.params[this.params.length - 1].end);
|
8406 | }
|
8407 | };
|
8408 |
|
8409 | // Returns whether any transforms that will happen use `arguments`
|
8410 | ArrowFunctionExpression.prototype.needsArguments = function needsArguments (transforms) {
|
8411 | return (
|
8412 | transforms.spreadRest &&
|
8413 | this.params.filter(function (param) { return param.type === 'RestElement'; }).length > 0
|
8414 | );
|
8415 | };
|
8416 |
|
8417 | return ArrowFunctionExpression;
|
8418 | }(Node$1));
|
8419 |
|
8420 | function checkConst(identifier, scope) {
|
8421 | var declaration = scope.findDeclaration(identifier.name);
|
8422 | if (declaration && declaration.kind === 'const') {
|
8423 | throw new CompileError(((identifier.name) + " is read-only"), identifier);
|
8424 | }
|
8425 | }
|
8426 |
|
8427 | var AssignmentExpression = /*@__PURE__*/(function (Node) {
|
8428 | function AssignmentExpression () {
|
8429 | Node.apply(this, arguments);
|
8430 | }
|
8431 |
|
8432 | if ( Node ) AssignmentExpression.__proto__ = Node;
|
8433 | AssignmentExpression.prototype = Object.create( Node && Node.prototype );
|
8434 | AssignmentExpression.prototype.constructor = AssignmentExpression;
|
8435 |
|
8436 | AssignmentExpression.prototype.initialise = function initialise (transforms) {
|
8437 | if (this.left.type === 'Identifier') {
|
8438 | var declaration = this.findScope(false).findDeclaration(this.left.name);
|
8439 | // special case – https://gitlab.com/Rich-Harris/buble/issues/11
|
8440 | var statement = declaration && declaration.node.ancestor(3);
|
8441 | if (
|
8442 | statement &&
|
8443 | statement.type === 'ForStatement' &&
|
8444 | statement.body.contains(this)
|
8445 | ) {
|
8446 | statement.reassigned[this.left.name] = true;
|
8447 | }
|
8448 | }
|
8449 |
|
8450 | Node.prototype.initialise.call(this, transforms);
|
8451 | };
|
8452 |
|
8453 | AssignmentExpression.prototype.transpile = function transpile (code, transforms) {
|
8454 | if (this.left.type === 'Identifier') {
|
8455 | // Do this check after everything has been initialized to find
|
8456 | // shadowing declarations after this expression
|
8457 | checkConst(this.left, this.findScope(false));
|
8458 | }
|
8459 |
|
8460 | if (this.operator === '**=' && transforms.exponentiation) {
|
8461 | this.transpileExponentiation(code, transforms);
|
8462 | } else if (/Pattern/.test(this.left.type) && transforms.destructuring) {
|
8463 | this.transpileDestructuring(code);
|
8464 | }
|
8465 |
|
8466 | Node.prototype.transpile.call(this, code, transforms);
|
8467 | };
|
8468 |
|
8469 | AssignmentExpression.prototype.transpileDestructuring = function transpileDestructuring (code) {
|
8470 | var this$1 = this;
|
8471 |
|
8472 | var writeScope = this.findScope(true);
|
8473 | var lookupScope = this.findScope(false);
|
8474 | var assign = writeScope.createDeclaration('assign');
|
8475 | code.appendRight(this.left.end, ("(" + assign));
|
8476 |
|
8477 | code.appendLeft(this.right.end, ', ');
|
8478 | var statementGenerators = [];
|
8479 | destructure(
|
8480 | code,
|
8481 | function (id) { return writeScope.createDeclaration(id); },
|
8482 | function (node) {
|
8483 | var name = lookupScope.resolveName(node.name);
|
8484 | checkConst(node, lookupScope);
|
8485 | return name;
|
8486 | },
|
8487 | this.left,
|
8488 | assign,
|
8489 | true,
|
8490 | statementGenerators
|
8491 | );
|
8492 |
|
8493 | var suffix = ', ';
|
8494 | statementGenerators.forEach(function (fn, j) {
|
8495 | if (j === statementGenerators.length - 1) {
|
8496 | suffix = '';
|
8497 | }
|
8498 |
|
8499 | fn(this$1.end, '', suffix);
|
8500 | });
|
8501 |
|
8502 | if (this.unparenthesizedParent().type === 'ExpressionStatement') {
|
8503 | // no rvalue needed for expression statement
|
8504 | code.prependRight(this.end, ")");
|
8505 | } else {
|
8506 | // destructuring is part of an expression - need an rvalue
|
8507 | code.appendRight(this.end, (", " + assign + ")"));
|
8508 | }
|
8509 | };
|
8510 |
|
8511 | AssignmentExpression.prototype.transpileExponentiation = function transpileExponentiation (code) {
|
8512 | var scope = this.findScope(false);
|
8513 |
|
8514 | // first, the easy part – `**=` -> `=`
|
8515 | var charIndex = this.left.end;
|
8516 | while (code.original[charIndex] !== '*') { charIndex += 1; }
|
8517 | code.remove(charIndex, charIndex + 2);
|
8518 |
|
8519 | // how we do the next part depends on a number of factors – whether
|
8520 | // this is a top-level statement, and whether we're updating a
|
8521 | // simple or complex reference
|
8522 | var base;
|
8523 |
|
8524 | var left = this.left.unparenthesize();
|
8525 |
|
8526 | if (left.type === 'Identifier') {
|
8527 | base = scope.resolveName(left.name);
|
8528 | } else if (left.type === 'MemberExpression') {
|
8529 | var object;
|
8530 | var needsObjectVar = false;
|
8531 | var property;
|
8532 | var needsPropertyVar = false;
|
8533 |
|
8534 | var statement = this.findNearest(/(?:Statement|Declaration)$/);
|
8535 | var i0 = statement.getIndentation();
|
8536 |
|
8537 | if (left.property.type === 'Identifier') {
|
8538 | property = left.computed
|
8539 | ? scope.resolveName(left.property.name)
|
8540 | : left.property.name;
|
8541 | } else {
|
8542 | property = scope.createDeclaration('property');
|
8543 | needsPropertyVar = true;
|
8544 | }
|
8545 |
|
8546 | if (left.object.type === 'Identifier') {
|
8547 | object = scope.resolveName(left.object.name);
|
8548 | } else {
|
8549 | object = scope.createDeclaration('object');
|
8550 | needsObjectVar = true;
|
8551 | }
|
8552 |
|
8553 | if (left.start === statement.start) {
|
8554 | if (needsObjectVar && needsPropertyVar) {
|
8555 | code.prependRight(statement.start, (object + " = "));
|
8556 | code.overwrite(
|
8557 | left.object.end,
|
8558 | left.property.start,
|
8559 | (";\n" + i0 + property + " = ")
|
8560 | );
|
8561 | code.overwrite(
|
8562 | left.property.end,
|
8563 | left.end,
|
8564 | (";\n" + i0 + object + "[" + property + "]")
|
8565 | );
|
8566 | } else if (needsObjectVar) {
|
8567 | code.prependRight(statement.start, (object + " = "));
|
8568 | code.appendLeft(left.object.end, (";\n" + i0));
|
8569 | code.appendLeft(left.object.end, object);
|
8570 | } else if (needsPropertyVar) {
|
8571 | code.prependRight(left.property.start, (property + " = "));
|
8572 | code.appendLeft(left.property.end, (";\n" + i0));
|
8573 | code.move(left.property.start, left.property.end, this.start);
|
8574 |
|
8575 | code.appendLeft(left.object.end, ("[" + property + "]"));
|
8576 | code.remove(left.object.end, left.property.start);
|
8577 | code.remove(left.property.end, left.end);
|
8578 | }
|
8579 | } else {
|
8580 | if (needsObjectVar && needsPropertyVar) {
|
8581 | code.prependRight(left.start, ("( " + object + " = "));
|
8582 | code.overwrite(
|
8583 | left.object.end,
|
8584 | left.property.start,
|
8585 | (", " + property + " = ")
|
8586 | );
|
8587 | code.overwrite(
|
8588 | left.property.end,
|
8589 | left.end,
|
8590 | (", " + object + "[" + property + "]")
|
8591 | );
|
8592 | } else if (needsObjectVar) {
|
8593 | code.prependRight(left.start, ("( " + object + " = "));
|
8594 | code.appendLeft(left.object.end, (", " + object));
|
8595 | } else if (needsPropertyVar) {
|
8596 | code.prependRight(left.property.start, ("( " + property + " = "));
|
8597 | code.appendLeft(left.property.end, ", ");
|
8598 | code.move(left.property.start, left.property.end, left.start);
|
8599 |
|
8600 | code.overwrite(left.object.end, left.property.start, ("[" + property + "]"));
|
8601 | code.remove(left.property.end, left.end);
|
8602 | }
|
8603 |
|
8604 | if (needsPropertyVar) {
|
8605 | code.appendLeft(this.end, " )");
|
8606 | }
|
8607 | }
|
8608 |
|
8609 | base =
|
8610 | object +
|
8611 | (left.computed || needsPropertyVar ? ("[" + property + "]") : ("." + property));
|
8612 | }
|
8613 |
|
8614 | code.prependRight(this.right.start, ("Math.pow( " + base + ", "));
|
8615 | code.appendLeft(this.right.end, " )");
|
8616 | };
|
8617 |
|
8618 | return AssignmentExpression;
|
8619 | }(Node$1));
|
8620 |
|
8621 | var AwaitExpression = /*@__PURE__*/(function (Node) {
|
8622 | function AwaitExpression () {
|
8623 | Node.apply(this, arguments);
|
8624 | }
|
8625 |
|
8626 | if ( Node ) AwaitExpression.__proto__ = Node;
|
8627 | AwaitExpression.prototype = Object.create( Node && Node.prototype );
|
8628 | AwaitExpression.prototype.constructor = AwaitExpression;
|
8629 |
|
8630 | AwaitExpression.prototype.initialise = function initialise (transforms) {
|
8631 | if (transforms.asyncAwait) {
|
8632 | CompileError.missingTransform("await", "asyncAwait", this);
|
8633 | }
|
8634 | Node.prototype.initialise.call(this, transforms);
|
8635 | };
|
8636 |
|
8637 | return AwaitExpression;
|
8638 | }(Node$1));
|
8639 |
|
8640 | var BinaryExpression = /*@__PURE__*/(function (Node) {
|
8641 | function BinaryExpression () {
|
8642 | Node.apply(this, arguments);
|
8643 | }
|
8644 |
|
8645 | if ( Node ) BinaryExpression.__proto__ = Node;
|
8646 | BinaryExpression.prototype = Object.create( Node && Node.prototype );
|
8647 | BinaryExpression.prototype.constructor = BinaryExpression;
|
8648 |
|
8649 | BinaryExpression.prototype.transpile = function transpile (code, transforms) {
|
8650 | if (this.operator === '**' && transforms.exponentiation) {
|
8651 | code.prependRight(this.start, "Math.pow( ");
|
8652 | code.overwrite(this.left.end, this.right.start, ", ");
|
8653 | code.appendLeft(this.end, " )");
|
8654 | }
|
8655 | Node.prototype.transpile.call(this, code, transforms);
|
8656 | };
|
8657 |
|
8658 | return BinaryExpression;
|
8659 | }(Node$1));
|
8660 |
|
8661 | var loopStatement = /(?:For(?:In|Of)?|While)Statement/;
|
8662 |
|
8663 | var BreakStatement = /*@__PURE__*/(function (Node) {
|
8664 | function BreakStatement () {
|
8665 | Node.apply(this, arguments);
|
8666 | }
|
8667 |
|
8668 | if ( Node ) BreakStatement.__proto__ = Node;
|
8669 | BreakStatement.prototype = Object.create( Node && Node.prototype );
|
8670 | BreakStatement.prototype.constructor = BreakStatement;
|
8671 |
|
8672 | BreakStatement.prototype.initialise = function initialise () {
|
8673 | var loop = this.findNearest(loopStatement);
|
8674 | var switchCase = this.findNearest('SwitchCase');
|
8675 |
|
8676 | if (loop && (!switchCase || loop.depth > switchCase.depth)) {
|
8677 | loop.canBreak = true;
|
8678 | this.loop = loop;
|
8679 | }
|
8680 | };
|
8681 |
|
8682 | BreakStatement.prototype.transpile = function transpile (code) {
|
8683 | if (this.loop && this.loop.shouldRewriteAsFunction) {
|
8684 | if (this.label)
|
8685 | { throw new CompileError(
|
8686 | 'Labels are not currently supported in a loop with locally-scoped variables',
|
8687 | this
|
8688 | ); }
|
8689 | code.overwrite(this.start, this.start + 5, "return 'break'");
|
8690 | }
|
8691 | };
|
8692 |
|
8693 | return BreakStatement;
|
8694 | }(Node$1));
|
8695 |
|
8696 | var CallExpression = /*@__PURE__*/(function (Node) {
|
8697 | function CallExpression () {
|
8698 | Node.apply(this, arguments);
|
8699 | }
|
8700 |
|
8701 | if ( Node ) CallExpression.__proto__ = Node;
|
8702 | CallExpression.prototype = Object.create( Node && Node.prototype );
|
8703 | CallExpression.prototype.constructor = CallExpression;
|
8704 |
|
8705 | CallExpression.prototype.initialise = function initialise (transforms) {
|
8706 | if (transforms.spreadRest && this.arguments.length > 1) {
|
8707 | var lexicalBoundary = this.findLexicalBoundary();
|
8708 |
|
8709 | var i = this.arguments.length;
|
8710 | while (i--) {
|
8711 | var arg = this.arguments[i];
|
8712 | if (arg.type === 'SpreadElement' && isArguments(arg.argument)) {
|
8713 | this.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
|
8714 | }
|
8715 | }
|
8716 | }
|
8717 |
|
8718 | Node.prototype.initialise.call(this, transforms);
|
8719 | };
|
8720 |
|
8721 | CallExpression.prototype.transpile = function transpile (code, transforms) {
|
8722 | if (transforms.spreadRest && this.arguments.length) {
|
8723 | inlineSpreads(code, this, this.arguments);
|
8724 | // this.arguments.length may have changed, must retest.
|
8725 | }
|
8726 |
|
8727 | if (transforms.spreadRest && this.arguments.length) {
|
8728 | var hasSpreadElements = false;
|
8729 | var context;
|
8730 |
|
8731 | var firstArgument = this.arguments[0];
|
8732 |
|
8733 | if (this.arguments.length === 1) {
|
8734 | if (firstArgument.type === 'SpreadElement') {
|
8735 | code.remove(firstArgument.start, firstArgument.argument.start);
|
8736 | hasSpreadElements = true;
|
8737 | }
|
8738 | } else {
|
8739 | hasSpreadElements = spread(
|
8740 | code,
|
8741 | this.arguments,
|
8742 | firstArgument.start,
|
8743 | this.argumentsArrayAlias
|
8744 | );
|
8745 | }
|
8746 |
|
8747 | if (hasSpreadElements) {
|
8748 | // we need to handle super() and super.method() differently
|
8749 | // due to its instance
|
8750 | var _super = null;
|
8751 | if (this.callee.type === 'Super') {
|
8752 | _super = this.callee;
|
8753 | } else if (
|
8754 | this.callee.type === 'MemberExpression' &&
|
8755 | this.callee.object.type === 'Super'
|
8756 | ) {
|
8757 | _super = this.callee.object;
|
8758 | }
|
8759 |
|
8760 | if (!_super && this.callee.type === 'MemberExpression') {
|
8761 | if (this.callee.object.type === 'Identifier') {
|
8762 | context = this.callee.object.name;
|
8763 | } else {
|
8764 | context = this.findScope(true).createDeclaration('ref');
|
8765 | var callExpression = this.callee.object;
|
8766 | code.prependRight(callExpression.start, ("(" + context + " = "));
|
8767 | code.appendLeft(callExpression.end, ")");
|
8768 | }
|
8769 | } else {
|
8770 | context = 'void 0';
|
8771 | }
|
8772 |
|
8773 | code.appendLeft(this.callee.end, '.apply');
|
8774 |
|
8775 | if (_super) {
|
8776 | _super.noCall = true; // bit hacky...
|
8777 |
|
8778 | if (this.arguments.length > 1) {
|
8779 | if (firstArgument.type === 'SpreadElement') {
|
8780 | if (needsParentheses(firstArgument.argument)) {
|
8781 | code.prependRight(firstArgument.start, "( ");
|
8782 | }
|
8783 | } else {
|
8784 | code.prependRight(firstArgument.start, "[ ");
|
8785 | }
|
8786 |
|
8787 | code.appendLeft(
|
8788 | this.arguments[this.arguments.length - 1].end,
|
8789 | ' )'
|
8790 | );
|
8791 | }
|
8792 | } else if (this.arguments.length === 1) {
|
8793 | code.prependRight(firstArgument.start, (context + ", "));
|
8794 | } else {
|
8795 | if (firstArgument.type === 'SpreadElement') {
|
8796 | if (needsParentheses(firstArgument.argument)) {
|
8797 | code.appendLeft(firstArgument.start, (context + ", ( "));
|
8798 | } else {
|
8799 | code.appendLeft(firstArgument.start, (context + ", "));
|
8800 | }
|
8801 | } else {
|
8802 | code.appendLeft(firstArgument.start, (context + ", [ "));
|
8803 | }
|
8804 |
|
8805 | code.appendLeft(this.arguments[this.arguments.length - 1].end, ' )');
|
8806 | }
|
8807 | }
|
8808 | }
|
8809 |
|
8810 | if (transforms.trailingFunctionCommas && this.arguments.length) {
|
8811 | removeTrailingComma(code, this.arguments[this.arguments.length - 1].end);
|
8812 | }
|
8813 |
|
8814 | Node.prototype.transpile.call(this, code, transforms);
|
8815 | };
|
8816 |
|
8817 | return CallExpression;
|
8818 | }(Node$1));
|
8819 |
|
8820 | var CatchClause = /*@__PURE__*/(function (Node) {
|
8821 | function CatchClause () {
|
8822 | Node.apply(this, arguments);
|
8823 | }
|
8824 |
|
8825 | if ( Node ) CatchClause.__proto__ = Node;
|
8826 | CatchClause.prototype = Object.create( Node && Node.prototype );
|
8827 | CatchClause.prototype.constructor = CatchClause;
|
8828 |
|
8829 | CatchClause.prototype.initialise = function initialise (transforms) {
|
8830 | var this$1 = this;
|
8831 |
|
8832 | this.createdDeclarations = [];
|
8833 | this.scope = new Scope$1({
|
8834 | block: true,
|
8835 | parent: this.parent.findScope(false),
|
8836 | declare: function (id) { return this$1.createdDeclarations.push(id); }
|
8837 | });
|
8838 |
|
8839 | this.scope.addDeclaration(this.param, 'catch');
|
8840 |
|
8841 | Node.prototype.initialise.call(this, transforms);
|
8842 | this.scope.consolidate();
|
8843 | };
|
8844 |
|
8845 | CatchClause.prototype.findScope = function findScope (functionScope) {
|
8846 | return functionScope
|
8847 | ? this.parent.findScope(functionScope)
|
8848 | : this.scope;
|
8849 | };
|
8850 |
|
8851 | return CatchClause;
|
8852 | }(Node$1));
|
8853 |
|
8854 | // TODO this code is pretty wild, tidy it up
|
8855 | var ClassBody = /*@__PURE__*/(function (Node) {
|
8856 | function ClassBody () {
|
8857 | Node.apply(this, arguments);
|
8858 | }
|
8859 |
|
8860 | if ( Node ) ClassBody.__proto__ = Node;
|
8861 | ClassBody.prototype = Object.create( Node && Node.prototype );
|
8862 | ClassBody.prototype.constructor = ClassBody;
|
8863 |
|
8864 | ClassBody.prototype.transpile = function transpile (code, transforms, inFunctionExpression, superName) {
|
8865 | var this$1 = this;
|
8866 |
|
8867 | if (transforms.classes) {
|
8868 | var name = this.parent.name;
|
8869 |
|
8870 | var indentStr = code.getIndentString();
|
8871 | var i0 =
|
8872 | this.getIndentation() + (inFunctionExpression ? indentStr : '');
|
8873 | var i1 = i0 + indentStr;
|
8874 |
|
8875 | var constructorIndex = findIndex(
|
8876 | this.body,
|
8877 | function (node) { return node.kind === 'constructor'; }
|
8878 | );
|
8879 | var constructor = this.body[constructorIndex];
|
8880 |
|
8881 | var introBlock = '';
|
8882 | var outroBlock = '';
|
8883 |
|
8884 | if (this.body.length) {
|
8885 | code.remove(this.start, this.body[0].start);
|
8886 | code.remove(this.body[this.body.length - 1].end, this.end);
|
8887 | } else {
|
8888 | code.remove(this.start, this.end);
|
8889 | }
|
8890 |
|
8891 | if (constructor) {
|
8892 | constructor.value.body.isConstructorBody = true;
|
8893 |
|
8894 | var previousMethod = this.body[constructorIndex - 1];
|
8895 | var nextMethod = this.body[constructorIndex + 1];
|
8896 |
|
8897 | // ensure constructor is first
|
8898 | if (constructorIndex > 0) {
|
8899 | code.remove(previousMethod.end, constructor.start);
|
8900 | code.move(
|
8901 | constructor.start,
|
8902 | nextMethod ? nextMethod.start : this.end - 1,
|
8903 | this.body[0].start
|
8904 | );
|
8905 | }
|
8906 |
|
8907 | if (!inFunctionExpression) { code.appendLeft(constructor.end, ';'); }
|
8908 | }
|
8909 |
|
8910 | var namedFunctions =
|
8911 | this.program.options.namedFunctionExpressions !== false;
|
8912 | var namedConstructor =
|
8913 | namedFunctions ||
|
8914 | this.parent.superClass ||
|
8915 | this.parent.type !== 'ClassDeclaration';
|
8916 | if (this.parent.superClass) {
|
8917 | var inheritanceBlock = "if ( " + superName + " ) " + name + ".__proto__ = " + superName + ";\n" + i0 + name + ".prototype = Object.create( " + superName + " && " + superName + ".prototype );\n" + i0 + name + ".prototype.constructor = " + name + ";";
|
8918 |
|
8919 | if (constructor) {
|
8920 | introBlock += "\n\n" + i0 + inheritanceBlock;
|
8921 | } else {
|
8922 | var fn =
|
8923 | "function " + name + " () {" +
|
8924 | (superName
|
8925 | ? ("\n" + i1 + superName + ".apply(this, arguments);\n" + i0 + "}")
|
8926 | : "}") +
|
8927 | (inFunctionExpression ? '' : ';') +
|
8928 | (this.body.length ? ("\n\n" + i0) : '');
|
8929 |
|
8930 | inheritanceBlock = fn + inheritanceBlock;
|
8931 | introBlock += inheritanceBlock + "\n\n" + i0;
|
8932 | }
|
8933 | } else if (!constructor) {
|
8934 | var fn$1 = 'function ' + (namedConstructor ? name + ' ' : '') + '() {}';
|
8935 | if (this.parent.type === 'ClassDeclaration') { fn$1 += ';'; }
|
8936 | if (this.body.length) { fn$1 += "\n\n" + i0; }
|
8937 |
|
8938 | introBlock += fn$1;
|
8939 | }
|
8940 |
|
8941 | var scope = this.findScope(false);
|
8942 |
|
8943 | var prototypeGettersAndSetters = [];
|
8944 | var staticGettersAndSetters = [];
|
8945 | var prototypeAccessors;
|
8946 | var staticAccessors;
|
8947 |
|
8948 | this.body.forEach(function (method, i) {
|
8949 | if ((method.kind === 'get' || method.kind === 'set') && transforms.getterSetter) {
|
8950 | CompileError.missingTransform("getters and setters", "getterSetter", method);
|
8951 | }
|
8952 |
|
8953 | if (method.kind === 'constructor') {
|
8954 | var constructorName = namedConstructor ? ' ' + name : '';
|
8955 | code.overwrite(
|
8956 | method.key.start,
|
8957 | method.key.end,
|
8958 | ("function" + constructorName)
|
8959 | );
|
8960 | return;
|
8961 | }
|
8962 |
|
8963 | if (method.static) {
|
8964 | var len = code.original[method.start + 6] == ' ' ? 7 : 6;
|
8965 | code.remove(method.start, method.start + len);
|
8966 | }
|
8967 |
|
8968 | var isAccessor = method.kind !== 'method';
|
8969 | var lhs;
|
8970 |
|
8971 | var methodName = method.key.name;
|
8972 | if (
|
8973 | reserved[methodName] ||
|
8974 | method.value.body.scope.references[methodName]
|
8975 | ) {
|
8976 | methodName = scope.createIdentifier(methodName);
|
8977 | }
|
8978 |
|
8979 | // when method name is a string or a number let's pretend it's a computed method
|
8980 |
|
8981 | var fake_computed = false;
|
8982 | if (!method.computed && method.key.type === 'Literal') {
|
8983 | fake_computed = true;
|
8984 | method.computed = true;
|
8985 | }
|
8986 |
|
8987 | if (isAccessor) {
|
8988 | if (method.computed) {
|
8989 | throw new Error(
|
8990 | 'Computed accessor properties are not currently supported'
|
8991 | );
|
8992 | }
|
8993 |
|
8994 | code.remove(method.start, method.key.start);
|
8995 |
|
8996 | if (method.static) {
|
8997 | if (!~staticGettersAndSetters.indexOf(method.key.name))
|
8998 | { staticGettersAndSetters.push(method.key.name); }
|
8999 | if (!staticAccessors)
|
9000 | { staticAccessors = scope.createIdentifier('staticAccessors'); }
|
9001 |
|
9002 | lhs = "" + staticAccessors;
|
9003 | } else {
|
9004 | if (!~prototypeGettersAndSetters.indexOf(method.key.name))
|
9005 | { prototypeGettersAndSetters.push(method.key.name); }
|
9006 | if (!prototypeAccessors)
|
9007 | { prototypeAccessors = scope.createIdentifier('prototypeAccessors'); }
|
9008 |
|
9009 | lhs = "" + prototypeAccessors;
|
9010 | }
|
9011 | } else {
|
9012 | lhs = method.static ? ("" + name) : (name + ".prototype");
|
9013 | }
|
9014 |
|
9015 | if (!method.computed) { lhs += '.'; }
|
9016 |
|
9017 | var insertNewlines =
|
9018 | (constructorIndex > 0 && i === constructorIndex + 1) ||
|
9019 | (i === 0 && constructorIndex === this$1.body.length - 1);
|
9020 |
|
9021 | if (insertNewlines) { lhs = "\n\n" + i0 + lhs; }
|
9022 |
|
9023 | var c = method.key.end;
|
9024 | if (method.computed) {
|
9025 | if (fake_computed) {
|
9026 | code.prependRight(method.key.start, '[');
|
9027 | code.appendLeft(method.key.end, ']');
|
9028 | } else {
|
9029 | while (code.original[c] !== ']') { c += 1; }
|
9030 | c += 1;
|
9031 | }
|
9032 | }
|
9033 |
|
9034 | var funcName =
|
9035 | method.computed || isAccessor || !namedFunctions
|
9036 | ? ''
|
9037 | : (methodName + " ");
|
9038 | var rhs =
|
9039 | (isAccessor ? ("." + (method.kind)) : '') +
|
9040 | " = " + (method.value.async ? 'async ' : '') + "function" +
|
9041 | (method.value.generator ? '* ' : ' ') +
|
9042 | funcName;
|
9043 | code.remove(c, method.value.start);
|
9044 | code.prependRight(method.value.start, rhs);
|
9045 | code.appendLeft(method.end, ';');
|
9046 |
|
9047 | if (method.value.generator) { code.remove(method.start, method.key.start); }
|
9048 |
|
9049 | var start = method.key.start;
|
9050 | if (method.computed && !fake_computed) {
|
9051 | while (code.original[start] != '[') {
|
9052 | --start;
|
9053 | }
|
9054 | }
|
9055 | if (method.start < start) {
|
9056 | code.overwrite(method.start, start, lhs);
|
9057 | } else {
|
9058 | code.prependRight(method.start, lhs);
|
9059 | }
|
9060 | });
|
9061 |
|
9062 | if (prototypeGettersAndSetters.length || staticGettersAndSetters.length) {
|
9063 | var intro = [];
|
9064 | var outro = [];
|
9065 |
|
9066 | if (prototypeGettersAndSetters.length) {
|
9067 | intro.push(
|
9068 | ("var " + prototypeAccessors + " = { " + (prototypeGettersAndSetters
|
9069 | .map(function (name) { return (name + ": { configurable: true }"); })
|
9070 | .join(',')) + " };")
|
9071 | );
|
9072 | outro.push(
|
9073 | ("Object.defineProperties( " + name + ".prototype, " + prototypeAccessors + " );")
|
9074 | );
|
9075 | }
|
9076 |
|
9077 | if (staticGettersAndSetters.length) {
|
9078 | intro.push(
|
9079 | ("var " + staticAccessors + " = { " + (staticGettersAndSetters
|
9080 | .map(function (name) { return (name + ": { configurable: true }"); })
|
9081 | .join(',')) + " };")
|
9082 | );
|
9083 | outro.push(("Object.defineProperties( " + name + ", " + staticAccessors + " );"));
|
9084 | }
|
9085 |
|
9086 | if (constructor) { introBlock += "\n\n" + i0; }
|
9087 | introBlock += intro.join(("\n" + i0));
|
9088 | if (!constructor) { introBlock += "\n\n" + i0; }
|
9089 |
|
9090 | outroBlock += "\n\n" + i0 + outro.join(("\n" + i0));
|
9091 | }
|
9092 |
|
9093 | if (constructor) {
|
9094 | code.appendLeft(constructor.end, introBlock);
|
9095 | } else {
|
9096 | code.prependRight(this.start, introBlock);
|
9097 | }
|
9098 |
|
9099 | code.appendLeft(this.end, outroBlock);
|
9100 | }
|
9101 |
|
9102 | Node.prototype.transpile.call(this, code, transforms);
|
9103 | };
|
9104 |
|
9105 | return ClassBody;
|
9106 | }(Node$1));
|
9107 |
|
9108 | // TODO this function is slightly flawed – it works on the original string,
|
9109 | // not its current edited state.
|
9110 | // That's not a problem for the way that it's currently used, but it could
|
9111 | // be in future...
|
9112 | function deindent(node, code) {
|
9113 | var start = node.start;
|
9114 | var end = node.end;
|
9115 |
|
9116 | var indentStr = code.getIndentString();
|
9117 | var indentStrLen = indentStr.length;
|
9118 | var indentStart = start - indentStrLen;
|
9119 |
|
9120 | if (
|
9121 | !node.program.indentExclusions[indentStart] &&
|
9122 | code.original.slice(indentStart, start) === indentStr
|
9123 | ) {
|
9124 | code.remove(indentStart, start);
|
9125 | }
|
9126 |
|
9127 | var pattern = new RegExp(indentStr + '\\S', 'g');
|
9128 | var slice = code.original.slice(start, end);
|
9129 | var match;
|
9130 |
|
9131 | while ((match = pattern.exec(slice))) {
|
9132 | var removeStart = start + match.index;
|
9133 | if (!node.program.indentExclusions[removeStart]) {
|
9134 | code.remove(removeStart, removeStart + indentStrLen);
|
9135 | }
|
9136 | }
|
9137 | }
|
9138 |
|
9139 | var ClassDeclaration = /*@__PURE__*/(function (Node) {
|
9140 | function ClassDeclaration () {
|
9141 | Node.apply(this, arguments);
|
9142 | }
|
9143 |
|
9144 | if ( Node ) ClassDeclaration.__proto__ = Node;
|
9145 | ClassDeclaration.prototype = Object.create( Node && Node.prototype );
|
9146 | ClassDeclaration.prototype.constructor = ClassDeclaration;
|
9147 |
|
9148 | ClassDeclaration.prototype.initialise = function initialise (transforms) {
|
9149 | if (this.id) {
|
9150 | this.name = this.id.name;
|
9151 | this.findScope(true).addDeclaration(this.id, 'class');
|
9152 | } else {
|
9153 | this.name = this.findScope(true).createIdentifier("defaultExport");
|
9154 | }
|
9155 |
|
9156 | Node.prototype.initialise.call(this, transforms);
|
9157 | };
|
9158 |
|
9159 | ClassDeclaration.prototype.transpile = function transpile (code, transforms) {
|
9160 | if (transforms.classes) {
|
9161 | if (!this.superClass) { deindent(this.body, code); }
|
9162 |
|
9163 | var superName =
|
9164 | this.superClass && (this.superClass.name || 'superclass');
|
9165 |
|
9166 | var i0 = this.getIndentation();
|
9167 | var i1 = i0 + code.getIndentString();
|
9168 |
|
9169 | // if this is an export default statement, we have to move the export to
|
9170 | // after the declaration, because `export default var Foo = ...` is illegal
|
9171 | var isExportDefaultDeclaration = this.parent.type === 'ExportDefaultDeclaration';
|
9172 |
|
9173 | if (isExportDefaultDeclaration) {
|
9174 | code.remove(this.parent.start, this.start);
|
9175 | }
|
9176 |
|
9177 | var c = this.start;
|
9178 | if (this.id) {
|
9179 | code.overwrite(c, this.id.start, 'var ');
|
9180 | c = this.id.end;
|
9181 | } else {
|
9182 | code.prependLeft(c, ("var " + (this.name)));
|
9183 | }
|
9184 |
|
9185 | if (this.superClass) {
|
9186 | if (this.superClass.end === this.body.start) {
|
9187 | code.remove(c, this.superClass.start);
|
9188 | code.appendLeft(c, (" = /*@__PURE__*/(function (" + superName + ") {\n" + i1));
|
9189 | } else {
|
9190 | code.overwrite(c, this.superClass.start, ' = ');
|
9191 | code.overwrite(
|
9192 | this.superClass.end,
|
9193 | this.body.start,
|
9194 | ("/*@__PURE__*/(function (" + superName + ") {\n" + i1)
|
9195 | );
|
9196 | }
|
9197 | } else {
|
9198 | if (c === this.body.start) {
|
9199 | code.appendLeft(c, ' = ');
|
9200 | } else {
|
9201 | code.overwrite(c, this.body.start, ' = ');
|
9202 | }
|
9203 | }
|
9204 |
|
9205 | this.body.transpile(code, transforms, !!this.superClass, superName);
|
9206 |
|
9207 | var syntheticDefaultExport =
|
9208 | isExportDefaultDeclaration
|
9209 | ? ("\n\n" + i0 + "export default " + (this.name) + ";")
|
9210 | : '';
|
9211 | if (this.superClass) {
|
9212 | code.appendLeft(this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}("));
|
9213 | code.move(this.superClass.start, this.superClass.end, this.end);
|
9214 | code.prependRight(this.end, ("));" + syntheticDefaultExport));
|
9215 | } else if (syntheticDefaultExport) {
|
9216 | code.prependRight(this.end, syntheticDefaultExport);
|
9217 | }
|
9218 | } else {
|
9219 | this.body.transpile(code, transforms, false, null);
|
9220 | }
|
9221 | };
|
9222 |
|
9223 | return ClassDeclaration;
|
9224 | }(Node$1));
|
9225 |
|
9226 | var ClassExpression = /*@__PURE__*/(function (Node) {
|
9227 | function ClassExpression () {
|
9228 | Node.apply(this, arguments);
|
9229 | }
|
9230 |
|
9231 | if ( Node ) ClassExpression.__proto__ = Node;
|
9232 | ClassExpression.prototype = Object.create( Node && Node.prototype );
|
9233 | ClassExpression.prototype.constructor = ClassExpression;
|
9234 |
|
9235 | ClassExpression.prototype.initialise = function initialise (transforms) {
|
9236 | this.name = (this.id
|
9237 | ? this.id.name
|
9238 | : this.parent.type === 'VariableDeclarator'
|
9239 | ? this.parent.id.name
|
9240 | : this.parent.type !== 'AssignmentExpression'
|
9241 | ? null
|
9242 | : this.parent.left.type === 'Identifier'
|
9243 | ? this.parent.left.name
|
9244 | : this.parent.left.type === 'MemberExpression'
|
9245 | ? this.parent.left.property.name
|
9246 | : null) || this.findScope(true).createIdentifier('anonymous');
|
9247 |
|
9248 | Node.prototype.initialise.call(this, transforms);
|
9249 | };
|
9250 |
|
9251 | ClassExpression.prototype.transpile = function transpile (code, transforms) {
|
9252 | if (transforms.classes) {
|
9253 | var superName = this.superClass && (this.superClass.name || 'superclass');
|
9254 | if (superName === this.name) {
|
9255 | superName = this.findScope(true).createIdentifier(this.name);
|
9256 | }
|
9257 |
|
9258 | var i0 = this.getIndentation();
|
9259 | var i1 = i0 + code.getIndentString();
|
9260 |
|
9261 | if (this.superClass) {
|
9262 | code.remove(this.start, this.superClass.start);
|
9263 | code.remove(this.superClass.end, this.body.start);
|
9264 | code.appendRight(this.start, ("/*@__PURE__*/(function (" + superName + ") {\n" + i1));
|
9265 | } else {
|
9266 | code.overwrite(this.start, this.body.start, ("/*@__PURE__*/(function () {\n" + i1));
|
9267 | }
|
9268 |
|
9269 | this.body.transpile(code, transforms, true, superName);
|
9270 |
|
9271 | var superClass = '';
|
9272 | if (this.superClass) {
|
9273 | superClass = code.slice(this.superClass.start, this.superClass.end);
|
9274 | code.remove(this.superClass.start, this.superClass.end);
|
9275 | }
|
9276 | code.appendLeft(this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(" + superClass + "))"));
|
9277 | } else {
|
9278 | this.body.transpile(code, transforms, false);
|
9279 | }
|
9280 | };
|
9281 |
|
9282 | return ClassExpression;
|
9283 | }(Node$1));
|
9284 |
|
9285 | var ContinueStatement = /*@__PURE__*/(function (Node) {
|
9286 | function ContinueStatement () {
|
9287 | Node.apply(this, arguments);
|
9288 | }
|
9289 |
|
9290 | if ( Node ) ContinueStatement.__proto__ = Node;
|
9291 | ContinueStatement.prototype = Object.create( Node && Node.prototype );
|
9292 | ContinueStatement.prototype.constructor = ContinueStatement;
|
9293 |
|
9294 | ContinueStatement.prototype.transpile = function transpile (code) {
|
9295 | var loop = this.findNearest(loopStatement);
|
9296 | if (loop.shouldRewriteAsFunction) {
|
9297 | if (this.label)
|
9298 | { throw new CompileError(
|
9299 | 'Labels are not currently supported in a loop with locally-scoped variables',
|
9300 | this
|
9301 | ); }
|
9302 | code.overwrite(this.start, this.start + 8, 'return');
|
9303 | }
|
9304 | };
|
9305 |
|
9306 | return ContinueStatement;
|
9307 | }(Node$1));
|
9308 |
|
9309 | var ExportDefaultDeclaration = /*@__PURE__*/(function (Node) {
|
9310 | function ExportDefaultDeclaration () {
|
9311 | Node.apply(this, arguments);
|
9312 | }
|
9313 |
|
9314 | if ( Node ) ExportDefaultDeclaration.__proto__ = Node;
|
9315 | ExportDefaultDeclaration.prototype = Object.create( Node && Node.prototype );
|
9316 | ExportDefaultDeclaration.prototype.constructor = ExportDefaultDeclaration;
|
9317 |
|
9318 | ExportDefaultDeclaration.prototype.initialise = function initialise (transforms) {
|
9319 | if (transforms.moduleExport)
|
9320 | { CompileError.missingTransform("export", "moduleExport", this); }
|
9321 | Node.prototype.initialise.call(this, transforms);
|
9322 | };
|
9323 |
|
9324 | return ExportDefaultDeclaration;
|
9325 | }(Node$1));
|
9326 |
|
9327 | var ExportNamedDeclaration = /*@__PURE__*/(function (Node) {
|
9328 | function ExportNamedDeclaration () {
|
9329 | Node.apply(this, arguments);
|
9330 | }
|
9331 |
|
9332 | if ( Node ) ExportNamedDeclaration.__proto__ = Node;
|
9333 | ExportNamedDeclaration.prototype = Object.create( Node && Node.prototype );
|
9334 | ExportNamedDeclaration.prototype.constructor = ExportNamedDeclaration;
|
9335 |
|
9336 | ExportNamedDeclaration.prototype.initialise = function initialise (transforms) {
|
9337 | if (transforms.moduleExport)
|
9338 | { CompileError.missingTransform("export", "moduleExport", this); }
|
9339 | Node.prototype.initialise.call(this, transforms);
|
9340 | };
|
9341 |
|
9342 | return ExportNamedDeclaration;
|
9343 | }(Node$1));
|
9344 |
|
9345 | var LoopStatement = /*@__PURE__*/(function (Node) {
|
9346 | function LoopStatement () {
|
9347 | Node.apply(this, arguments);
|
9348 | }
|
9349 |
|
9350 | if ( Node ) LoopStatement.__proto__ = Node;
|
9351 | LoopStatement.prototype = Object.create( Node && Node.prototype );
|
9352 | LoopStatement.prototype.constructor = LoopStatement;
|
9353 |
|
9354 | LoopStatement.prototype.findScope = function findScope (functionScope) {
|
9355 | return functionScope || !this.createdScope
|
9356 | ? this.parent.findScope(functionScope)
|
9357 | : this.body.scope;
|
9358 | };
|
9359 |
|
9360 | LoopStatement.prototype.initialise = function initialise (transforms) {
|
9361 | this.body.createScope();
|
9362 | this.createdScope = true;
|
9363 |
|
9364 | // this is populated as and when reassignments occur
|
9365 | this.reassigned = Object.create(null);
|
9366 | this.aliases = Object.create(null);
|
9367 |
|
9368 | this.thisRefs = [];
|
9369 |
|
9370 | Node.prototype.initialise.call(this, transforms);
|
9371 | if (this.scope) {
|
9372 | this.scope.consolidate();
|
9373 | }
|
9374 |
|
9375 | var declarations = Object.assign({}, this.body.scope.declarations);
|
9376 | if (this.scope) {
|
9377 | Object.assign(declarations, this.scope.declarations);
|
9378 | }
|
9379 |
|
9380 | if (transforms.letConst) {
|
9381 | // see if any block-scoped declarations are referenced
|
9382 | // inside function expressions
|
9383 | var names = Object.keys(declarations);
|
9384 |
|
9385 | var i = names.length;
|
9386 | while (i--) {
|
9387 | var name = names[i];
|
9388 | var declaration = declarations[name];
|
9389 |
|
9390 | var j = declaration.instances.length;
|
9391 | while (j--) {
|
9392 | var instance = declaration.instances[j];
|
9393 | var nearestFunctionExpression = instance.findNearest(/Function/);
|
9394 |
|
9395 | if (
|
9396 | nearestFunctionExpression &&
|
9397 | nearestFunctionExpression.depth > this.depth
|
9398 | ) {
|
9399 | this.shouldRewriteAsFunction = true;
|
9400 | for (var i$1 = 0, list = this.thisRefs; i$1 < list.length; i$1 += 1) {
|
9401 | var node = list[i$1];
|
9402 |
|
9403 | node.alias = node.alias || node.findLexicalBoundary().getThisAlias();
|
9404 | }
|
9405 | break;
|
9406 | }
|
9407 | }
|
9408 |
|
9409 | if (this.shouldRewriteAsFunction) { break; }
|
9410 | }
|
9411 | }
|
9412 | };
|
9413 |
|
9414 | LoopStatement.prototype.transpile = function transpile (code, transforms) {
|
9415 | var needsBlock =
|
9416 | this.type != 'ForOfStatement' &&
|
9417 | (this.body.type !== 'BlockStatement' ||
|
9418 | (this.body.type === 'BlockStatement' && this.body.synthetic));
|
9419 |
|
9420 | if (this.shouldRewriteAsFunction) {
|
9421 | var i0 = this.getIndentation();
|
9422 | var i1 = i0 + code.getIndentString();
|
9423 |
|
9424 | var argString = this.args ? (" " + (this.args.join(', ')) + " ") : '';
|
9425 | var paramString = this.params ? (" " + (this.params.join(', ')) + " ") : '';
|
9426 |
|
9427 | var functionScope = this.findScope(true);
|
9428 | var loop = functionScope.createIdentifier('loop');
|
9429 |
|
9430 | var before =
|
9431 | "var " + loop + " = function (" + paramString + ") " +
|
9432 | (this.body.synthetic ? ("{\n" + i0 + (code.getIndentString())) : '');
|
9433 | var after = (this.body.synthetic ? ("\n" + i0 + "}") : '') + ";\n\n" + i0;
|
9434 |
|
9435 | code.prependRight(this.body.start, before);
|
9436 | code.appendLeft(this.body.end, after);
|
9437 | code.move(this.start, this.body.start, this.body.end);
|
9438 |
|
9439 | if (this.canBreak || this.canReturn) {
|
9440 | var returned = functionScope.createIdentifier('returned');
|
9441 |
|
9442 | var insert = "{\n" + i1 + "var " + returned + " = " + loop + "(" + argString + ");\n";
|
9443 | if (this.canBreak)
|
9444 | { insert += "\n" + i1 + "if ( " + returned + " === 'break' ) break;"; }
|
9445 | if (this.canReturn)
|
9446 | { insert += "\n" + i1 + "if ( " + returned + " ) return " + returned + ".v;"; }
|
9447 | insert += "\n" + i0 + "}";
|
9448 |
|
9449 | code.prependRight(this.body.end, insert);
|
9450 | } else {
|
9451 | var callExpression = loop + "(" + argString + ");";
|
9452 |
|
9453 | if (this.type === 'DoWhileStatement') {
|
9454 | code.overwrite(
|
9455 | this.start,
|
9456 | this.body.start,
|
9457 | ("do {\n" + i1 + callExpression + "\n" + i0 + "}")
|
9458 | );
|
9459 | } else {
|
9460 | code.prependRight(this.body.end, callExpression);
|
9461 | }
|
9462 | }
|
9463 | } else if (needsBlock) {
|
9464 | code.appendLeft(this.body.start, '{ ');
|
9465 | code.prependRight(this.body.end, ' }');
|
9466 | }
|
9467 |
|
9468 | Node.prototype.transpile.call(this, code, transforms);
|
9469 | };
|
9470 |
|
9471 | return LoopStatement;
|
9472 | }(Node$1));
|
9473 |
|
9474 | var ForStatement = /*@__PURE__*/(function (LoopStatement) {
|
9475 | function ForStatement () {
|
9476 | LoopStatement.apply(this, arguments);
|
9477 | }
|
9478 |
|
9479 | if ( LoopStatement ) ForStatement.__proto__ = LoopStatement;
|
9480 | ForStatement.prototype = Object.create( LoopStatement && LoopStatement.prototype );
|
9481 | ForStatement.prototype.constructor = ForStatement;
|
9482 |
|
9483 | ForStatement.prototype.initialise = function initialise (transforms) {
|
9484 | var this$1 = this;
|
9485 |
|
9486 | this.createdDeclarations = [];
|
9487 |
|
9488 | this.scope = new Scope$1({
|
9489 | block: true,
|
9490 | parent: this.parent.findScope(false),
|
9491 | declare: function (id) { return this$1.createdDeclarations.push(id); }
|
9492 | });
|
9493 |
|
9494 | LoopStatement.prototype.initialise.call(this, transforms);
|
9495 | };
|
9496 |
|
9497 | ForStatement.prototype.findScope = function findScope (functionScope) {
|
9498 | return functionScope
|
9499 | ? this.parent.findScope(functionScope)
|
9500 | : this.scope;
|
9501 | };
|
9502 |
|
9503 | ForStatement.prototype.transpile = function transpile (code, transforms) {
|
9504 | var this$1 = this;
|
9505 |
|
9506 | var i1 = this.getIndentation() + code.getIndentString();
|
9507 |
|
9508 | if (this.shouldRewriteAsFunction) {
|
9509 | // which variables are declared in the init statement?
|
9510 | var names = this.init && this.init.type === 'VariableDeclaration'
|
9511 | ? this.init.declarations.map(function (declarator) { return extractNames(declarator.id); })
|
9512 | : [];
|
9513 |
|
9514 | var aliases = this.aliases;
|
9515 |
|
9516 | this.args = names.map(
|
9517 | function (name) { return (name in this$1.aliases ? this$1.aliases[name].outer : name); }
|
9518 | );
|
9519 | this.params = names.map(
|
9520 | function (name) { return (name in this$1.aliases ? this$1.aliases[name].inner : name); }
|
9521 | );
|
9522 |
|
9523 | var updates = Object.keys(this.reassigned).map(
|
9524 | function (name) { return ((aliases[name].outer) + " = " + (aliases[name].inner) + ";"); }
|
9525 | );
|
9526 |
|
9527 | if (updates.length) {
|
9528 | if (this.body.synthetic) {
|
9529 | code.appendLeft(this.body.body[0].end, ("; " + (updates.join(" "))));
|
9530 | } else {
|
9531 | var lastStatement = this.body.body[this.body.body.length - 1];
|
9532 | code.appendLeft(
|
9533 | lastStatement.end,
|
9534 | ("\n\n" + i1 + (updates.join(("\n" + i1))))
|
9535 | );
|
9536 | }
|
9537 | }
|
9538 | }
|
9539 |
|
9540 | LoopStatement.prototype.transpile.call(this, code, transforms);
|
9541 | };
|
9542 |
|
9543 | return ForStatement;
|
9544 | }(LoopStatement));
|
9545 |
|
9546 | var ForInStatement = /*@__PURE__*/(function (LoopStatement) {
|
9547 | function ForInStatement () {
|
9548 | LoopStatement.apply(this, arguments);
|
9549 | }
|
9550 |
|
9551 | if ( LoopStatement ) ForInStatement.__proto__ = LoopStatement;
|
9552 | ForInStatement.prototype = Object.create( LoopStatement && LoopStatement.prototype );
|
9553 | ForInStatement.prototype.constructor = ForInStatement;
|
9554 |
|
9555 | ForInStatement.prototype.initialise = function initialise (transforms) {
|
9556 | var this$1 = this;
|
9557 |
|
9558 | this.createdDeclarations = [];
|
9559 |
|
9560 | this.scope = new Scope$1({
|
9561 | block: true,
|
9562 | parent: this.parent.findScope(false),
|
9563 | declare: function (id) { return this$1.createdDeclarations.push(id); }
|
9564 | });
|
9565 |
|
9566 | LoopStatement.prototype.initialise.call(this, transforms);
|
9567 | };
|
9568 |
|
9569 | ForInStatement.prototype.findScope = function findScope (functionScope) {
|
9570 | return functionScope
|
9571 | ? this.parent.findScope(functionScope)
|
9572 | : this.scope;
|
9573 | };
|
9574 |
|
9575 | ForInStatement.prototype.transpile = function transpile (code, transforms) {
|
9576 | var this$1 = this;
|
9577 |
|
9578 | var hasDeclaration = this.left.type === 'VariableDeclaration';
|
9579 |
|
9580 | if (this.shouldRewriteAsFunction) {
|
9581 | // which variables are declared in the init statement?
|
9582 | var names = hasDeclaration
|
9583 | ? this.left.declarations.map(function (declarator) { return extractNames(declarator.id); })
|
9584 | : [];
|
9585 |
|
9586 | this.args = names.map(
|
9587 | function (name) { return (name in this$1.aliases ? this$1.aliases[name].outer : name); }
|
9588 | );
|
9589 | this.params = names.map(
|
9590 | function (name) { return (name in this$1.aliases ? this$1.aliases[name].inner : name); }
|
9591 | );
|
9592 | }
|
9593 |
|
9594 | LoopStatement.prototype.transpile.call(this, code, transforms);
|
9595 |
|
9596 | var maybePattern = hasDeclaration ? this.left.declarations[0].id : this.left;
|
9597 | if (maybePattern.type !== 'Identifier' && maybePattern.type !== 'MemberExpression') {
|
9598 | this.destructurePattern(code, maybePattern, hasDeclaration);
|
9599 | }
|
9600 | };
|
9601 |
|
9602 | ForInStatement.prototype.destructurePattern = function destructurePattern (code, pattern, isDeclaration) {
|
9603 | var scope = this.findScope(true);
|
9604 | var i0 = this.getIndentation();
|
9605 | var i1 = i0 + code.getIndentString();
|
9606 |
|
9607 | var ref = scope.createIdentifier('ref');
|
9608 |
|
9609 | var bodyStart = this.body.body.length ? this.body.body[0].start : this.body.start + 1;
|
9610 |
|
9611 | code.move(pattern.start, pattern.end, bodyStart);
|
9612 |
|
9613 | code.prependRight(pattern.end, isDeclaration ? ref : ("var " + ref));
|
9614 |
|
9615 | var statementGenerators = [];
|
9616 | destructure(
|
9617 | code,
|
9618 | function (id) { return scope.createIdentifier(id); },
|
9619 | function (ref) {
|
9620 | var name = ref.name;
|
9621 |
|
9622 | return scope.resolveName(name);
|
9623 | },
|
9624 | pattern,
|
9625 | ref,
|
9626 | false,
|
9627 | statementGenerators
|
9628 | );
|
9629 |
|
9630 | var suffix = ";\n" + i1;
|
9631 | statementGenerators.forEach(function (fn, i) {
|
9632 | if (i === statementGenerators.length - 1) {
|
9633 | suffix = ";\n\n" + i1;
|
9634 | }
|
9635 |
|
9636 | fn(bodyStart, '', suffix);
|
9637 | });
|
9638 | };
|
9639 |
|
9640 | return ForInStatement;
|
9641 | }(LoopStatement));
|
9642 |
|
9643 | var ForOfStatement = /*@__PURE__*/(function (LoopStatement) {
|
9644 | function ForOfStatement () {
|
9645 | LoopStatement.apply(this, arguments);
|
9646 | }
|
9647 |
|
9648 | if ( LoopStatement ) ForOfStatement.__proto__ = LoopStatement;
|
9649 | ForOfStatement.prototype = Object.create( LoopStatement && LoopStatement.prototype );
|
9650 | ForOfStatement.prototype.constructor = ForOfStatement;
|
9651 |
|
9652 | ForOfStatement.prototype.initialise = function initialise (transforms) {
|
9653 | var this$1 = this;
|
9654 |
|
9655 | if (transforms.forOf && !transforms.dangerousForOf)
|
9656 | { CompileError.missingTransform("for-of statements", "forOf", this, "dangerousForOf"); }
|
9657 | if (this.await && transforms.asyncAwait)
|
9658 | { CompileError.missingTransform("for-await-of statements", "asyncAwait", this); }
|
9659 |
|
9660 | this.createdDeclarations = [];
|
9661 |
|
9662 | this.scope = new Scope$1({
|
9663 | block: true,
|
9664 | parent: this.parent.findScope(false),
|
9665 | declare: function (id) { return this$1.createdDeclarations.push(id); }
|
9666 | });
|
9667 |
|
9668 | LoopStatement.prototype.initialise.call(this, transforms);
|
9669 | };
|
9670 |
|
9671 | ForOfStatement.prototype.findScope = function findScope (functionScope) {
|
9672 | return functionScope
|
9673 | ? this.parent.findScope(functionScope)
|
9674 | : this.scope;
|
9675 | };
|
9676 |
|
9677 | ForOfStatement.prototype.transpile = function transpile (code, transforms) {
|
9678 | LoopStatement.prototype.transpile.call(this, code, transforms);
|
9679 | if (!transforms.dangerousForOf) { return; }
|
9680 |
|
9681 | // edge case (#80)
|
9682 | if (!this.body.body[0]) {
|
9683 | if (
|
9684 | this.left.type === 'VariableDeclaration' &&
|
9685 | this.left.kind === 'var'
|
9686 | ) {
|
9687 | code.remove(this.start, this.left.start);
|
9688 | code.appendLeft(this.left.end, ';');
|
9689 | code.remove(this.left.end, this.end);
|
9690 | } else {
|
9691 | code.remove(this.start, this.end);
|
9692 | }
|
9693 |
|
9694 | return;
|
9695 | }
|
9696 |
|
9697 | var scope = this.findScope(true);
|
9698 | var i0 = this.getIndentation();
|
9699 | var i1 = i0 + code.getIndentString();
|
9700 |
|
9701 | var key = scope.createIdentifier('i');
|
9702 | var list = scope.createIdentifier('list');
|
9703 |
|
9704 | if (this.body.synthetic) {
|
9705 | code.prependRight(this.left.start, ("{\n" + i1));
|
9706 | code.appendLeft(this.body.body[0].end, ("\n" + i0 + "}"));
|
9707 | }
|
9708 |
|
9709 | var bodyStart = this.body.body[0].start;
|
9710 |
|
9711 | code.remove(this.left.end, this.right.start);
|
9712 | code.move(this.left.start, this.left.end, bodyStart);
|
9713 |
|
9714 | code.prependRight(this.right.start, ("var " + key + " = 0, " + list + " = "));
|
9715 | code.appendLeft(this.right.end, ("; " + key + " < " + list + ".length; " + key + " += 1"));
|
9716 |
|
9717 | var isDeclaration = this.left.type === 'VariableDeclaration';
|
9718 | var maybeDestructuring = isDeclaration ? this.left.declarations[0].id : this.left;
|
9719 | if (maybeDestructuring.type !== 'Identifier') {
|
9720 | var statementGenerators = [];
|
9721 | var ref = scope.createIdentifier('ref');
|
9722 | destructure(
|
9723 | code,
|
9724 | function (id) { return scope.createIdentifier(id); },
|
9725 | function (ref) {
|
9726 | var name = ref.name;
|
9727 |
|
9728 | return scope.resolveName(name);
|
9729 | },
|
9730 | maybeDestructuring,
|
9731 | ref,
|
9732 | !isDeclaration,
|
9733 | statementGenerators
|
9734 | );
|
9735 |
|
9736 | var suffix = ";\n" + i1;
|
9737 | statementGenerators.forEach(function (fn, i) {
|
9738 | if (i === statementGenerators.length - 1) {
|
9739 | suffix = ";\n\n" + i1;
|
9740 | }
|
9741 |
|
9742 | fn(bodyStart, '', suffix);
|
9743 | });
|
9744 |
|
9745 | if (isDeclaration) {
|
9746 | code.appendLeft(this.left.start + this.left.kind.length + 1, ref);
|
9747 | code.appendLeft(this.left.end, (" = " + list + "[" + key + "];\n" + i1));
|
9748 | } else {
|
9749 | code.appendLeft(this.left.end, ("var " + ref + " = " + list + "[" + key + "];\n" + i1));
|
9750 | }
|
9751 | } else {
|
9752 | code.appendLeft(this.left.end, (" = " + list + "[" + key + "];\n\n" + i1));
|
9753 | }
|
9754 | };
|
9755 |
|
9756 | return ForOfStatement;
|
9757 | }(LoopStatement));
|
9758 |
|
9759 | var FunctionDeclaration = /*@__PURE__*/(function (Node) {
|
9760 | function FunctionDeclaration () {
|
9761 | Node.apply(this, arguments);
|
9762 | }
|
9763 |
|
9764 | if ( Node ) FunctionDeclaration.__proto__ = Node;
|
9765 | FunctionDeclaration.prototype = Object.create( Node && Node.prototype );
|
9766 | FunctionDeclaration.prototype.constructor = FunctionDeclaration;
|
9767 |
|
9768 | FunctionDeclaration.prototype.initialise = function initialise (transforms) {
|
9769 | if (this.generator && transforms.generator) {
|
9770 | CompileError.missingTransform("generators", "generator", this);
|
9771 | }
|
9772 | if (this.async && transforms.asyncAwait) {
|
9773 | CompileError.missingTransform("async functions", "asyncAwait", this);
|
9774 | }
|
9775 |
|
9776 | this.body.createScope();
|
9777 |
|
9778 | if (this.id) {
|
9779 | this.findScope(true).addDeclaration(this.id, 'function');
|
9780 | }
|
9781 | Node.prototype.initialise.call(this, transforms);
|
9782 | };
|
9783 |
|
9784 | FunctionDeclaration.prototype.transpile = function transpile (code, transforms) {
|
9785 | Node.prototype.transpile.call(this, code, transforms);
|
9786 | if (transforms.trailingFunctionCommas && this.params.length) {
|
9787 | removeTrailingComma(code, this.params[this.params.length - 1].end);
|
9788 | }
|
9789 | };
|
9790 |
|
9791 | return FunctionDeclaration;
|
9792 | }(Node$1));
|
9793 |
|
9794 | var FunctionExpression = /*@__PURE__*/(function (Node) {
|
9795 | function FunctionExpression () {
|
9796 | Node.apply(this, arguments);
|
9797 | }
|
9798 |
|
9799 | if ( Node ) FunctionExpression.__proto__ = Node;
|
9800 | FunctionExpression.prototype = Object.create( Node && Node.prototype );
|
9801 | FunctionExpression.prototype.constructor = FunctionExpression;
|
9802 |
|
9803 | FunctionExpression.prototype.initialise = function initialise (transforms) {
|
9804 | if (this.generator && transforms.generator) {
|
9805 | CompileError.missingTransform("generators", "generator", this);
|
9806 | }
|
9807 | if (this.async && transforms.asyncAwait) {
|
9808 | CompileError.missingTransform("async functions", "asyncAwait", this);
|
9809 | }
|
9810 |
|
9811 | this.body.createScope();
|
9812 |
|
9813 | if (this.id) {
|
9814 | // function expression IDs belong to the child scope...
|
9815 | this.body.scope.addDeclaration(this.id, 'function');
|
9816 | }
|
9817 |
|
9818 | Node.prototype.initialise.call(this, transforms);
|
9819 |
|
9820 | var parent = this.parent;
|
9821 | var methodName;
|
9822 |
|
9823 | if (
|
9824 | transforms.conciseMethodProperty &&
|
9825 | parent.type === 'Property' &&
|
9826 | parent.kind === 'init' &&
|
9827 | parent.method &&
|
9828 | parent.key.type === 'Identifier'
|
9829 | ) {
|
9830 | // object literal concise method
|
9831 | methodName = parent.key.name;
|
9832 | } else if (
|
9833 | transforms.classes &&
|
9834 | parent.type === 'MethodDefinition' &&
|
9835 | parent.kind === 'method' &&
|
9836 | parent.key.type === 'Identifier'
|
9837 | ) {
|
9838 | // method definition in a class
|
9839 | methodName = parent.key.name;
|
9840 | } else if (this.id && this.id.type === 'Identifier') {
|
9841 | // naked function expression
|
9842 | methodName = this.id.alias || this.id.name;
|
9843 | }
|
9844 |
|
9845 | if (methodName) {
|
9846 | for (var i$1 = 0, list$1 = this.params; i$1 < list$1.length; i$1 += 1) {
|
9847 | var param = list$1[i$1];
|
9848 |
|
9849 | if (param.type === 'Identifier' && methodName === param.name) {
|
9850 | // workaround for Safari 9/WebKit bug:
|
9851 | // https://gitlab.com/Rich-Harris/buble/issues/154
|
9852 | // change parameter name when same as method name
|
9853 |
|
9854 | var scope = this.body.scope;
|
9855 | var declaration = scope.declarations[methodName];
|
9856 |
|
9857 | var alias = scope.createIdentifier(methodName);
|
9858 | param.alias = alias;
|
9859 |
|
9860 | for (var i = 0, list = declaration.instances; i < list.length; i += 1) {
|
9861 | var identifier = list[i];
|
9862 |
|
9863 | identifier.alias = alias;
|
9864 | }
|
9865 |
|
9866 | break;
|
9867 | }
|
9868 | }
|
9869 | }
|
9870 | };
|
9871 |
|
9872 | FunctionExpression.prototype.transpile = function transpile (code, transforms) {
|
9873 | Node.prototype.transpile.call(this, code, transforms);
|
9874 | if (transforms.trailingFunctionCommas && this.params.length) {
|
9875 | removeTrailingComma(code, this.params[this.params.length - 1].end);
|
9876 | }
|
9877 | };
|
9878 |
|
9879 | return FunctionExpression;
|
9880 | }(Node$1));
|
9881 |
|
9882 | function isReference(node, parent) {
|
9883 | if (node.type === 'MemberExpression') {
|
9884 | return !node.computed && isReference(node.object, node);
|
9885 | }
|
9886 |
|
9887 | if (node.type === 'Identifier') {
|
9888 | // the only time we could have an identifier node without a parent is
|
9889 | // if it's the entire body of a function without a block statement –
|
9890 | // i.e. an arrow function expression like `a => a`
|
9891 | if (!parent) { return true; }
|
9892 |
|
9893 | if (/(Function|Class)Expression/.test(parent.type)) { return false; }
|
9894 |
|
9895 | if (parent.type === 'VariableDeclarator') { return node === parent.init; }
|
9896 |
|
9897 | // TODO is this right?
|
9898 | if (
|
9899 | parent.type === 'MemberExpression' ||
|
9900 | parent.type === 'MethodDefinition'
|
9901 | ) {
|
9902 | return parent.computed || node === parent.object;
|
9903 | }
|
9904 |
|
9905 | if (parent.type === 'ArrayPattern') { return false; }
|
9906 |
|
9907 | // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
9908 | if (parent.type === 'Property') {
|
9909 | if (parent.parent.type === 'ObjectPattern') { return false; }
|
9910 | return parent.computed || node === parent.value;
|
9911 | }
|
9912 |
|
9913 | // disregard the `bar` in `class Foo { bar () {...} }`
|
9914 | if (parent.type === 'MethodDefinition') { return false; }
|
9915 |
|
9916 | // disregard the `bar` in `export { foo as bar }`
|
9917 | if (parent.type === 'ExportSpecifier' && node !== parent.local)
|
9918 | { return false; }
|
9919 |
|
9920 | return true;
|
9921 | }
|
9922 | }
|
9923 |
|
9924 | var Identifier = /*@__PURE__*/(function (Node) {
|
9925 | function Identifier () {
|
9926 | Node.apply(this, arguments);
|
9927 | }
|
9928 |
|
9929 | if ( Node ) Identifier.__proto__ = Node;
|
9930 | Identifier.prototype = Object.create( Node && Node.prototype );
|
9931 | Identifier.prototype.constructor = Identifier;
|
9932 |
|
9933 | Identifier.prototype.findScope = function findScope (functionScope) {
|
9934 | if (this.parent.params && ~this.parent.params.indexOf(this)) {
|
9935 | return this.parent.body.scope;
|
9936 | }
|
9937 |
|
9938 | if (this.parent.type === 'FunctionExpression' && this === this.parent.id) {
|
9939 | return this.parent.body.scope;
|
9940 | }
|
9941 |
|
9942 | return this.parent.findScope(functionScope);
|
9943 | };
|
9944 |
|
9945 | Identifier.prototype.initialise = function initialise (transforms) {
|
9946 | if (this.isLabel()) {
|
9947 | return;
|
9948 | }
|
9949 |
|
9950 | if (isReference(this, this.parent)) {
|
9951 | if (
|
9952 | transforms.arrow &&
|
9953 | this.name === 'arguments' &&
|
9954 | !this.findScope(false).contains(this.name)
|
9955 | ) {
|
9956 | var lexicalBoundary = this.findLexicalBoundary();
|
9957 | var arrowFunction = this.findNearest('ArrowFunctionExpression');
|
9958 | var loop = this.findNearest(loopStatement);
|
9959 |
|
9960 | if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) {
|
9961 | this.alias = lexicalBoundary.getArgumentsAlias();
|
9962 | }
|
9963 |
|
9964 | if (
|
9965 | loop &&
|
9966 | loop.body.contains(this) &&
|
9967 | loop.depth > lexicalBoundary.depth
|
9968 | ) {
|
9969 | this.alias = lexicalBoundary.getArgumentsAlias();
|
9970 | }
|
9971 | }
|
9972 |
|
9973 | this.findScope(false).addReference(this);
|
9974 | }
|
9975 | };
|
9976 |
|
9977 | Identifier.prototype.isLabel = function isLabel () {
|
9978 | switch (this.parent.type) {
|
9979 | case 'BreakStatement': return true;
|
9980 | case 'ContinueStatement': return true;
|
9981 | case 'LabeledStatement': return true;
|
9982 | default: return false;
|
9983 | }
|
9984 | };
|
9985 |
|
9986 | Identifier.prototype.transpile = function transpile (code) {
|
9987 | if (this.alias) {
|
9988 | code.overwrite(this.start, this.end, this.alias, {
|
9989 | storeName: true,
|
9990 | contentOnly: true
|
9991 | });
|
9992 | }
|
9993 | };
|
9994 |
|
9995 | return Identifier;
|
9996 | }(Node$1));
|
9997 |
|
9998 | var IfStatement = /*@__PURE__*/(function (Node) {
|
9999 | function IfStatement () {
|
10000 | Node.apply(this, arguments);
|
10001 | }
|
10002 |
|
10003 | if ( Node ) IfStatement.__proto__ = Node;
|
10004 | IfStatement.prototype = Object.create( Node && Node.prototype );
|
10005 | IfStatement.prototype.constructor = IfStatement;
|
10006 |
|
10007 | IfStatement.prototype.initialise = function initialise (transforms) {
|
10008 | Node.prototype.initialise.call(this, transforms);
|
10009 | };
|
10010 |
|
10011 | IfStatement.prototype.transpile = function transpile (code, transforms) {
|
10012 | if (
|
10013 | this.consequent.type !== 'BlockStatement' ||
|
10014 | (this.consequent.type === 'BlockStatement' && this.consequent.synthetic)
|
10015 | ) {
|
10016 | code.appendLeft(this.consequent.start, '{ ');
|
10017 | code.prependRight(this.consequent.end, ' }');
|
10018 | }
|
10019 |
|
10020 | if (
|
10021 | this.alternate &&
|
10022 | this.alternate.type !== 'IfStatement' &&
|
10023 | (this.alternate.type !== 'BlockStatement' ||
|
10024 | (this.alternate.type === 'BlockStatement' && this.alternate.synthetic))
|
10025 | ) {
|
10026 | code.appendLeft(this.alternate.start, '{ ');
|
10027 | code.prependRight(this.alternate.end, ' }');
|
10028 | }
|
10029 |
|
10030 | Node.prototype.transpile.call(this, code, transforms);
|
10031 | };
|
10032 |
|
10033 | return IfStatement;
|
10034 | }(Node$1));
|
10035 |
|
10036 | var Import = /*@__PURE__*/(function (Node) {
|
10037 | function Import () {
|
10038 | Node.apply(this, arguments);
|
10039 | }
|
10040 |
|
10041 | if ( Node ) Import.__proto__ = Node;
|
10042 | Import.prototype = Object.create( Node && Node.prototype );
|
10043 | Import.prototype.constructor = Import;
|
10044 |
|
10045 | Import.prototype.initialise = function initialise (transforms) {
|
10046 | if (transforms.moduleImport) {
|
10047 | CompileError.missingTransform("dynamic import expressions", "moduleImport", this);
|
10048 | }
|
10049 | Node.prototype.initialise.call(this, transforms);
|
10050 | };
|
10051 |
|
10052 | return Import;
|
10053 | }(Node$1));
|
10054 |
|
10055 | var ImportDeclaration = /*@__PURE__*/(function (Node) {
|
10056 | function ImportDeclaration () {
|
10057 | Node.apply(this, arguments);
|
10058 | }
|
10059 |
|
10060 | if ( Node ) ImportDeclaration.__proto__ = Node;
|
10061 | ImportDeclaration.prototype = Object.create( Node && Node.prototype );
|
10062 | ImportDeclaration.prototype.constructor = ImportDeclaration;
|
10063 |
|
10064 | ImportDeclaration.prototype.initialise = function initialise (transforms) {
|
10065 | if (transforms.moduleImport)
|
10066 | { CompileError.missingTransform("import", "moduleImport", this); }
|
10067 | Node.prototype.initialise.call(this, transforms);
|
10068 | };
|
10069 |
|
10070 | return ImportDeclaration;
|
10071 | }(Node$1));
|
10072 |
|
10073 | var ImportDefaultSpecifier = /*@__PURE__*/(function (Node) {
|
10074 | function ImportDefaultSpecifier () {
|
10075 | Node.apply(this, arguments);
|
10076 | }
|
10077 |
|
10078 | if ( Node ) ImportDefaultSpecifier.__proto__ = Node;
|
10079 | ImportDefaultSpecifier.prototype = Object.create( Node && Node.prototype );
|
10080 | ImportDefaultSpecifier.prototype.constructor = ImportDefaultSpecifier;
|
10081 |
|
10082 | ImportDefaultSpecifier.prototype.initialise = function initialise (transforms) {
|
10083 | this.findScope(true).addDeclaration(this.local, 'import');
|
10084 | Node.prototype.initialise.call(this, transforms);
|
10085 | };
|
10086 |
|
10087 | return ImportDefaultSpecifier;
|
10088 | }(Node$1));
|
10089 |
|
10090 | var ImportSpecifier = /*@__PURE__*/(function (Node) {
|
10091 | function ImportSpecifier () {
|
10092 | Node.apply(this, arguments);
|
10093 | }
|
10094 |
|
10095 | if ( Node ) ImportSpecifier.__proto__ = Node;
|
10096 | ImportSpecifier.prototype = Object.create( Node && Node.prototype );
|
10097 | ImportSpecifier.prototype.constructor = ImportSpecifier;
|
10098 |
|
10099 | ImportSpecifier.prototype.initialise = function initialise (transforms) {
|
10100 | this.findScope(true).addDeclaration(this.local, 'import');
|
10101 | Node.prototype.initialise.call(this, transforms);
|
10102 | };
|
10103 |
|
10104 | return ImportSpecifier;
|
10105 | }(Node$1));
|
10106 |
|
10107 | var hasDashes = function (val) { return /-/.test(val); };
|
10108 |
|
10109 | var formatKey = function (key) { return (hasDashes(key) ? ("'" + key + "'") : key); };
|
10110 |
|
10111 | var formatVal = function (val) { return (val ? '' : 'true'); };
|
10112 |
|
10113 | var JSXAttribute = /*@__PURE__*/(function (Node) {
|
10114 | function JSXAttribute () {
|
10115 | Node.apply(this, arguments);
|
10116 | }
|
10117 |
|
10118 | if ( Node ) JSXAttribute.__proto__ = Node;
|
10119 | JSXAttribute.prototype = Object.create( Node && Node.prototype );
|
10120 | JSXAttribute.prototype.constructor = JSXAttribute;
|
10121 |
|
10122 | JSXAttribute.prototype.transpile = function transpile (code, transforms) {
|
10123 | var ref = this.name;
|
10124 | var start = ref.start;
|
10125 | var name = ref.name;
|
10126 |
|
10127 | // Overwrite equals sign if value is present.
|
10128 | var end = this.value ? this.value.start : this.name.end;
|
10129 |
|
10130 | code.overwrite(start, end, ((formatKey(name)) + ": " + (formatVal(this.value))));
|
10131 |
|
10132 | Node.prototype.transpile.call(this, code, transforms);
|
10133 | };
|
10134 |
|
10135 | return JSXAttribute;
|
10136 | }(Node$1));
|
10137 |
|
10138 | function containsNewLine(node) {
|
10139 | return (
|
10140 | node.type === 'JSXText' && !/\S/.test(node.value) && /\n/.test(node.value)
|
10141 | );
|
10142 | }
|
10143 |
|
10144 | var JSXClosingElement = /*@__PURE__*/(function (Node) {
|
10145 | function JSXClosingElement () {
|
10146 | Node.apply(this, arguments);
|
10147 | }
|
10148 |
|
10149 | if ( Node ) JSXClosingElement.__proto__ = Node;
|
10150 | JSXClosingElement.prototype = Object.create( Node && Node.prototype );
|
10151 | JSXClosingElement.prototype.constructor = JSXClosingElement;
|
10152 |
|
10153 | JSXClosingElement.prototype.transpile = function transpile (code) {
|
10154 | var spaceBeforeParen = true;
|
10155 |
|
10156 | var lastChild = this.parent.children[this.parent.children.length - 1];
|
10157 |
|
10158 | // omit space before closing paren if
|
10159 | // a) this is on a separate line, or
|
10160 | // b) there are no children but there are attributes
|
10161 | if (
|
10162 | (lastChild && containsNewLine(lastChild)) ||
|
10163 | this.parent.openingElement.attributes.length
|
10164 | ) {
|
10165 | spaceBeforeParen = false;
|
10166 | }
|
10167 |
|
10168 | code.overwrite(this.start, this.end, spaceBeforeParen ? ' )' : ')');
|
10169 | };
|
10170 |
|
10171 | return JSXClosingElement;
|
10172 | }(Node$1));
|
10173 |
|
10174 | function containsNewLine$1(node) {
|
10175 | return (
|
10176 | node.type === 'JSXText' && !/\S/.test(node.value) && /\n/.test(node.value)
|
10177 | );
|
10178 | }
|
10179 |
|
10180 | var JSXClosingFragment = /*@__PURE__*/(function (Node) {
|
10181 | function JSXClosingFragment () {
|
10182 | Node.apply(this, arguments);
|
10183 | }
|
10184 |
|
10185 | if ( Node ) JSXClosingFragment.__proto__ = Node;
|
10186 | JSXClosingFragment.prototype = Object.create( Node && Node.prototype );
|
10187 | JSXClosingFragment.prototype.constructor = JSXClosingFragment;
|
10188 |
|
10189 | JSXClosingFragment.prototype.transpile = function transpile (code) {
|
10190 | var spaceBeforeParen = true;
|
10191 |
|
10192 | var lastChild = this.parent.children[this.parent.children.length - 1];
|
10193 |
|
10194 | // omit space before closing paren if this is on a separate line
|
10195 | if (lastChild && containsNewLine$1(lastChild)) {
|
10196 | spaceBeforeParen = false;
|
10197 | }
|
10198 |
|
10199 | code.overwrite(this.start, this.end, spaceBeforeParen ? ' )' : ')');
|
10200 | };
|
10201 |
|
10202 | return JSXClosingFragment;
|
10203 | }(Node$1));
|
10204 |
|
10205 | function normalise(str, removeTrailingWhitespace) {
|
10206 |
|
10207 | if (removeTrailingWhitespace && /\n/.test(str)) {
|
10208 | str = str.replace(/[ \f\n\r\t\v]+$/, '');
|
10209 | }
|
10210 |
|
10211 | str = str
|
10212 | .replace(/^\n\r?[ \f\n\r\t\v]+/, '') // remove leading newline + space
|
10213 | .replace(/[ \f\n\r\t\v]*\n\r?[ \f\n\r\t\v]*/gm, ' '); // replace newlines with spaces
|
10214 |
|
10215 | // TODO prefer single quotes?
|
10216 | return JSON.stringify(str);
|
10217 | }
|
10218 |
|
10219 | var JSXElement = /*@__PURE__*/(function (Node) {
|
10220 | function JSXElement () {
|
10221 | Node.apply(this, arguments);
|
10222 | }
|
10223 |
|
10224 | if ( Node ) JSXElement.__proto__ = Node;
|
10225 | JSXElement.prototype = Object.create( Node && Node.prototype );
|
10226 | JSXElement.prototype.constructor = JSXElement;
|
10227 |
|
10228 | JSXElement.prototype.transpile = function transpile (code, transforms) {
|
10229 | Node.prototype.transpile.call(this, code, transforms);
|
10230 |
|
10231 | var children = this.children.filter(function (child) {
|
10232 | if (child.type !== 'JSXText') { return true; }
|
10233 |
|
10234 | // remove whitespace-only literals, unless on a single line
|
10235 | return /[^ \f\n\r\t\v]/.test(child.raw) || !/\n/.test(child.raw);
|
10236 | });
|
10237 |
|
10238 | if (children.length) {
|
10239 | var c = (this.openingElement || this.openingFragment).end;
|
10240 |
|
10241 | var i;
|
10242 | for (i = 0; i < children.length; i += 1) {
|
10243 | var child = children[i];
|
10244 |
|
10245 | if (
|
10246 | child.type === 'JSXExpressionContainer' &&
|
10247 | child.expression.type === 'JSXEmptyExpression'
|
10248 | ) ; else {
|
10249 | var tail =
|
10250 | code.original[c] === '\n' && child.type !== 'JSXText' ? '' : ' ';
|
10251 | code.appendLeft(c, ("," + tail));
|
10252 | }
|
10253 |
|
10254 | if (child.type === 'JSXText') {
|
10255 | var str = normalise(child.value, i === children.length - 1);
|
10256 | code.overwrite(child.start, child.end, str);
|
10257 | }
|
10258 |
|
10259 | c = child.end;
|
10260 | }
|
10261 | }
|
10262 | };
|
10263 |
|
10264 | return JSXElement;
|
10265 | }(Node$1));
|
10266 |
|
10267 | var JSXExpressionContainer = /*@__PURE__*/(function (Node) {
|
10268 | function JSXExpressionContainer () {
|
10269 | Node.apply(this, arguments);
|
10270 | }
|
10271 |
|
10272 | if ( Node ) JSXExpressionContainer.__proto__ = Node;
|
10273 | JSXExpressionContainer.prototype = Object.create( Node && Node.prototype );
|
10274 | JSXExpressionContainer.prototype.constructor = JSXExpressionContainer;
|
10275 |
|
10276 | JSXExpressionContainer.prototype.transpile = function transpile (code, transforms) {
|
10277 | code.remove(this.start, this.expression.start);
|
10278 | code.remove(this.expression.end, this.end);
|
10279 |
|
10280 | Node.prototype.transpile.call(this, code, transforms);
|
10281 | };
|
10282 |
|
10283 | return JSXExpressionContainer;
|
10284 | }(Node$1));
|
10285 |
|
10286 | var JSXFragment = /*@__PURE__*/(function (JSXElement) {
|
10287 | function JSXFragment () {
|
10288 | JSXElement.apply(this, arguments);
|
10289 | }if ( JSXElement ) JSXFragment.__proto__ = JSXElement;
|
10290 | JSXFragment.prototype = Object.create( JSXElement && JSXElement.prototype );
|
10291 | JSXFragment.prototype.constructor = JSXFragment;
|
10292 |
|
10293 |
|
10294 |
|
10295 | return JSXFragment;
|
10296 | }(JSXElement));
|
10297 |
|
10298 | var JSXOpeningElement = /*@__PURE__*/(function (Node) {
|
10299 | function JSXOpeningElement () {
|
10300 | Node.apply(this, arguments);
|
10301 | }
|
10302 |
|
10303 | if ( Node ) JSXOpeningElement.__proto__ = Node;
|
10304 | JSXOpeningElement.prototype = Object.create( Node && Node.prototype );
|
10305 | JSXOpeningElement.prototype.constructor = JSXOpeningElement;
|
10306 |
|
10307 | JSXOpeningElement.prototype.transpile = function transpile (code, transforms) {
|
10308 | Node.prototype.transpile.call(this, code, transforms);
|
10309 |
|
10310 | code.overwrite(this.start, this.name.start, ((this.program.jsx) + "( "));
|
10311 |
|
10312 | var html =
|
10313 | this.name.type === 'JSXIdentifier' &&
|
10314 | this.name.name[0] === this.name.name[0].toLowerCase();
|
10315 | if (html) { code.prependRight(this.name.start, "'"); }
|
10316 |
|
10317 | var len = this.attributes.length;
|
10318 | var c = this.name.end;
|
10319 |
|
10320 | if (len) {
|
10321 | var i;
|
10322 |
|
10323 | var hasSpread = false;
|
10324 | for (i = 0; i < len; i += 1) {
|
10325 | if (this.attributes[i].type === 'JSXSpreadAttribute') {
|
10326 | hasSpread = true;
|
10327 | break;
|
10328 | }
|
10329 | }
|
10330 |
|
10331 | c = this.attributes[0].end;
|
10332 |
|
10333 | for (i = 0; i < len; i += 1) {
|
10334 | var attr = this.attributes[i];
|
10335 |
|
10336 | if (i > 0) {
|
10337 | if (attr.start === c) { code.prependRight(c, ', '); }
|
10338 | else { code.overwrite(c, attr.start, ', '); }
|
10339 | }
|
10340 |
|
10341 | if (hasSpread && attr.type !== 'JSXSpreadAttribute') {
|
10342 | var lastAttr = this.attributes[i - 1];
|
10343 | var nextAttr = this.attributes[i + 1];
|
10344 |
|
10345 | if (!lastAttr || lastAttr.type === 'JSXSpreadAttribute') {
|
10346 | code.prependRight(attr.start, '{ ');
|
10347 | }
|
10348 |
|
10349 | if (!nextAttr || nextAttr.type === 'JSXSpreadAttribute') {
|
10350 | code.appendLeft(attr.end, ' }');
|
10351 | }
|
10352 | }
|
10353 |
|
10354 | c = attr.end;
|
10355 | }
|
10356 |
|
10357 | var after;
|
10358 | var before;
|
10359 | if (hasSpread) {
|
10360 | if (len === 1) {
|
10361 | before = html ? "'," : ',';
|
10362 | } else {
|
10363 | if (!this.program.options.objectAssign) {
|
10364 | throw new CompileError(
|
10365 | "Mixed JSX attributes ending in spread requires specified objectAssign option with 'Object.assign' or polyfill helper.",
|
10366 | this
|
10367 | );
|
10368 | }
|
10369 | before = html
|
10370 | ? ("', " + (this.program.options.objectAssign) + "({},")
|
10371 | : (", " + (this.program.options.objectAssign) + "({},");
|
10372 | after = ')';
|
10373 | }
|
10374 | } else {
|
10375 | before = html ? "', {" : ', {';
|
10376 | after = ' }';
|
10377 | }
|
10378 |
|
10379 | code.prependRight(this.name.end, before);
|
10380 |
|
10381 | if (after) {
|
10382 | code.appendLeft(this.attributes[len - 1].end, after);
|
10383 | }
|
10384 | } else {
|
10385 | code.appendLeft(this.name.end, html ? "', null" : ", null");
|
10386 | c = this.name.end;
|
10387 | }
|
10388 |
|
10389 | if (this.selfClosing) {
|
10390 | code.overwrite(c, this.end, this.attributes.length ? ")" : " )");
|
10391 | } else {
|
10392 | code.remove(c, this.end);
|
10393 | }
|
10394 | };
|
10395 |
|
10396 | return JSXOpeningElement;
|
10397 | }(Node$1));
|
10398 |
|
10399 | var JSXOpeningFragment = /*@__PURE__*/(function (Node) {
|
10400 | function JSXOpeningFragment () {
|
10401 | Node.apply(this, arguments);
|
10402 | }
|
10403 |
|
10404 | if ( Node ) JSXOpeningFragment.__proto__ = Node;
|
10405 | JSXOpeningFragment.prototype = Object.create( Node && Node.prototype );
|
10406 | JSXOpeningFragment.prototype.constructor = JSXOpeningFragment;
|
10407 |
|
10408 | JSXOpeningFragment.prototype.transpile = function transpile (code) {
|
10409 | code.overwrite(this.start, this.end, ((this.program.jsx) + "( " + (this.program.jsxFragment) + ", null"));
|
10410 | };
|
10411 |
|
10412 | return JSXOpeningFragment;
|
10413 | }(Node$1));
|
10414 |
|
10415 | var JSXSpreadAttribute = /*@__PURE__*/(function (Node) {
|
10416 | function JSXSpreadAttribute () {
|
10417 | Node.apply(this, arguments);
|
10418 | }
|
10419 |
|
10420 | if ( Node ) JSXSpreadAttribute.__proto__ = Node;
|
10421 | JSXSpreadAttribute.prototype = Object.create( Node && Node.prototype );
|
10422 | JSXSpreadAttribute.prototype.constructor = JSXSpreadAttribute;
|
10423 |
|
10424 | JSXSpreadAttribute.prototype.transpile = function transpile (code, transforms) {
|
10425 | code.remove(this.start, this.argument.start);
|
10426 | code.remove(this.argument.end, this.end);
|
10427 |
|
10428 | Node.prototype.transpile.call(this, code, transforms);
|
10429 | };
|
10430 |
|
10431 | return JSXSpreadAttribute;
|
10432 | }(Node$1));
|
10433 |
|
10434 | var regjsgen = createCommonjsModule(function (module, exports) {
|
10435 | (function() {
|
10436 |
|
10437 | // Used to determine if values are of the language type `Object`.
|
10438 | var objectTypes = {
|
10439 | 'function': true,
|
10440 | 'object': true
|
10441 | };
|
10442 |
|
10443 | // Used as a reference to the global object.
|
10444 | var root = (objectTypes[typeof window] && window) || this;
|
10445 |
|
10446 | // Detect free variable `exports`.
|
10447 | var freeExports = objectTypes['object'] && exports && !exports.nodeType && exports;
|
10448 |
|
10449 | // Detect free variable `module`.
|
10450 | var hasFreeModule = objectTypes['object'] && module && !module.nodeType;
|
10451 |
|
10452 | // Detect free variable `global` from Node.js or Browserified code and use it as `root`.
|
10453 | var freeGlobal = freeExports && hasFreeModule && typeof commonjsGlobal == 'object' && commonjsGlobal;
|
10454 | if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
|
10455 | root = freeGlobal;
|
10456 | }
|
10457 |
|
10458 | // Used to check objects for own properties.
|
10459 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
10460 |
|
10461 | /*--------------------------------------------------------------------------*/
|
10462 |
|
10463 | // Generates a string based on the given code point.
|
10464 | // Based on https://mths.be/fromcodepoint by @mathias.
|
10465 | function fromCodePoint() {
|
10466 | var codePoint = Number(arguments[0]);
|
10467 |
|
10468 | if (
|
10469 | !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
10470 | codePoint < 0 || // not a valid Unicode code point
|
10471 | codePoint > 0x10FFFF || // not a valid Unicode code point
|
10472 | Math.floor(codePoint) != codePoint // not an integer
|
10473 | ) {
|
10474 | throw RangeError('Invalid code point: ' + codePoint);
|
10475 | }
|
10476 |
|
10477 | if (codePoint <= 0xFFFF) {
|
10478 | // BMP code point
|
10479 | return String.fromCharCode(codePoint);
|
10480 | } else {
|
10481 | // Astral code point; split in surrogate halves
|
10482 | // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
10483 | codePoint -= 0x10000;
|
10484 | var highSurrogate = (codePoint >> 10) + 0xD800;
|
10485 | var lowSurrogate = (codePoint % 0x400) + 0xDC00;
|
10486 | return String.fromCharCode(highSurrogate, lowSurrogate);
|
10487 | }
|
10488 | }
|
10489 |
|
10490 | /*--------------------------------------------------------------------------*/
|
10491 |
|
10492 | // Ensures that nodes have the correct types.
|
10493 | var assertTypeRegexMap = {};
|
10494 | function assertType(type, expected) {
|
10495 | if (expected.indexOf('|') == -1) {
|
10496 | if (type == expected) {
|
10497 | return;
|
10498 | }
|
10499 |
|
10500 | throw Error('Invalid node type: ' + type + '; expected type: ' + expected);
|
10501 | }
|
10502 |
|
10503 | expected = hasOwnProperty.call(assertTypeRegexMap, expected)
|
10504 | ? assertTypeRegexMap[expected]
|
10505 | : (assertTypeRegexMap[expected] = RegExp('^(?:' + expected + ')$'));
|
10506 |
|
10507 | if (expected.test(type)) {
|
10508 | return;
|
10509 | }
|
10510 |
|
10511 | throw Error('Invalid node type: ' + type + '; expected types: ' + expected);
|
10512 | }
|
10513 |
|
10514 | /*--------------------------------------------------------------------------*/
|
10515 |
|
10516 | // Generates a regular expression string based on an AST.
|
10517 | function generate(node) {
|
10518 | var type = node.type;
|
10519 |
|
10520 | if (hasOwnProperty.call(generators, type)) {
|
10521 | return generators[type](node);
|
10522 | }
|
10523 |
|
10524 | throw Error('Invalid node type: ' + type);
|
10525 | }
|
10526 |
|
10527 | /*--------------------------------------------------------------------------*/
|
10528 |
|
10529 | function generateAlternative(node) {
|
10530 | assertType(node.type, 'alternative');
|
10531 |
|
10532 | var terms = node.body,
|
10533 | i = -1,
|
10534 | length = terms.length,
|
10535 | result = '';
|
10536 |
|
10537 | while (++i < length) {
|
10538 | result += generateTerm(terms[i]);
|
10539 | }
|
10540 |
|
10541 | return result;
|
10542 | }
|
10543 |
|
10544 | function generateAnchor(node) {
|
10545 | assertType(node.type, 'anchor');
|
10546 |
|
10547 | switch (node.kind) {
|
10548 | case 'start':
|
10549 | return '^';
|
10550 | case 'end':
|
10551 | return '$';
|
10552 | case 'boundary':
|
10553 | return '\\b';
|
10554 | case 'not-boundary':
|
10555 | return '\\B';
|
10556 | default:
|
10557 | throw Error('Invalid assertion');
|
10558 | }
|
10559 | }
|
10560 |
|
10561 | function generateAtom(node) {
|
10562 | assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
|
10563 |
|
10564 | return generate(node);
|
10565 | }
|
10566 |
|
10567 | function generateCharacterClass(node) {
|
10568 | assertType(node.type, 'characterClass');
|
10569 |
|
10570 | var classRanges = node.body,
|
10571 | i = -1,
|
10572 | length = classRanges.length,
|
10573 | result = '';
|
10574 |
|
10575 | if (node.negative) {
|
10576 | result += '^';
|
10577 | }
|
10578 |
|
10579 | while (++i < length) {
|
10580 | result += generateClassAtom(classRanges[i]);
|
10581 | }
|
10582 |
|
10583 | return '[' + result + ']';
|
10584 | }
|
10585 |
|
10586 | function generateCharacterClassEscape(node) {
|
10587 | assertType(node.type, 'characterClassEscape');
|
10588 |
|
10589 | return '\\' + node.value;
|
10590 | }
|
10591 |
|
10592 | function generateUnicodePropertyEscape(node) {
|
10593 | assertType(node.type, 'unicodePropertyEscape');
|
10594 |
|
10595 | return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
|
10596 | }
|
10597 |
|
10598 | function generateCharacterClassRange(node) {
|
10599 | assertType(node.type, 'characterClassRange');
|
10600 |
|
10601 | var min = node.min,
|
10602 | max = node.max;
|
10603 |
|
10604 | if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
|
10605 | throw Error('Invalid character class range');
|
10606 | }
|
10607 |
|
10608 | return generateClassAtom(min) + '-' + generateClassAtom(max);
|
10609 | }
|
10610 |
|
10611 | function generateClassAtom(node) {
|
10612 | assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value');
|
10613 |
|
10614 | return generate(node);
|
10615 | }
|
10616 |
|
10617 | function generateDisjunction(node) {
|
10618 | assertType(node.type, 'disjunction');
|
10619 |
|
10620 | var body = node.body,
|
10621 | i = -1,
|
10622 | length = body.length,
|
10623 | result = '';
|
10624 |
|
10625 | while (++i < length) {
|
10626 | if (i != 0) {
|
10627 | result += '|';
|
10628 | }
|
10629 | result += generate(body[i]);
|
10630 | }
|
10631 |
|
10632 | return result;
|
10633 | }
|
10634 |
|
10635 | function generateDot(node) {
|
10636 | assertType(node.type, 'dot');
|
10637 |
|
10638 | return '.';
|
10639 | }
|
10640 |
|
10641 | function generateGroup(node) {
|
10642 | assertType(node.type, 'group');
|
10643 |
|
10644 | var result = '';
|
10645 |
|
10646 | switch (node.behavior) {
|
10647 | case 'normal':
|
10648 | if (node.name) {
|
10649 | result += '?<' + generateIdentifier(node.name) + '>';
|
10650 | }
|
10651 | break;
|
10652 | case 'ignore':
|
10653 | result += '?:';
|
10654 | break;
|
10655 | case 'lookahead':
|
10656 | result += '?=';
|
10657 | break;
|
10658 | case 'negativeLookahead':
|
10659 | result += '?!';
|
10660 | break;
|
10661 | case 'lookbehind':
|
10662 | result += '?<=';
|
10663 | break;
|
10664 | case 'negativeLookbehind':
|
10665 | result += '?<!';
|
10666 | break;
|
10667 | default:
|
10668 | throw Error('Invalid behaviour: ' + node.behaviour);
|
10669 | }
|
10670 |
|
10671 | var body = node.body,
|
10672 | i = -1,
|
10673 | length = body.length;
|
10674 |
|
10675 | while (++i < length) {
|
10676 | result += generate(body[i]);
|
10677 | }
|
10678 |
|
10679 | return '(' + result + ')';
|
10680 | }
|
10681 |
|
10682 | function generateIdentifier(node) {
|
10683 | assertType(node.type, 'identifier');
|
10684 |
|
10685 | return node.value;
|
10686 | }
|
10687 |
|
10688 | function generateQuantifier(node) {
|
10689 | assertType(node.type, 'quantifier');
|
10690 |
|
10691 | var quantifier = '',
|
10692 | min = node.min,
|
10693 | max = node.max;
|
10694 |
|
10695 | if (max == null) {
|
10696 | if (min == 0) {
|
10697 | quantifier = '*';
|
10698 | } else if (min == 1) {
|
10699 | quantifier = '+';
|
10700 | } else {
|
10701 | quantifier = '{' + min + ',}';
|
10702 | }
|
10703 | } else if (min == max) {
|
10704 | quantifier = '{' + min + '}';
|
10705 | } else if (min == 0 && max == 1) {
|
10706 | quantifier = '?';
|
10707 | } else {
|
10708 | quantifier = '{' + min + ',' + max + '}';
|
10709 | }
|
10710 |
|
10711 | if (!node.greedy) {
|
10712 | quantifier += '?';
|
10713 | }
|
10714 |
|
10715 | return generateAtom(node.body[0]) + quantifier;
|
10716 | }
|
10717 |
|
10718 | function generateReference(node) {
|
10719 | assertType(node.type, 'reference');
|
10720 |
|
10721 | if (node.matchIndex) {
|
10722 | return '\\' + node.matchIndex;
|
10723 | }
|
10724 | if (node.name) {
|
10725 | return '\\k<' + generateIdentifier(node.name) + '>';
|
10726 | }
|
10727 |
|
10728 | throw new Error('Unknown reference type');
|
10729 | }
|
10730 |
|
10731 | function generateTerm(node) {
|
10732 | assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value');
|
10733 |
|
10734 | return generate(node);
|
10735 | }
|
10736 |
|
10737 | function generateValue(node) {
|
10738 | assertType(node.type, 'value');
|
10739 |
|
10740 | var kind = node.kind,
|
10741 | codePoint = node.codePoint;
|
10742 |
|
10743 | if (typeof codePoint != 'number') {
|
10744 | throw new Error('Invalid code point: ' + codePoint);
|
10745 | }
|
10746 |
|
10747 | switch (kind) {
|
10748 | case 'controlLetter':
|
10749 | return '\\c' + fromCodePoint(codePoint + 64);
|
10750 | case 'hexadecimalEscape':
|
10751 | return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
|
10752 | case 'identifier':
|
10753 | return '\\' + fromCodePoint(codePoint);
|
10754 | case 'null':
|
10755 | return '\\' + codePoint;
|
10756 | case 'octal':
|
10757 | return '\\' + codePoint.toString(8);
|
10758 | case 'singleEscape':
|
10759 | switch (codePoint) {
|
10760 | case 0x0008:
|
10761 | return '\\b';
|
10762 | case 0x0009:
|
10763 | return '\\t';
|
10764 | case 0x000A:
|
10765 | return '\\n';
|
10766 | case 0x000B:
|
10767 | return '\\v';
|
10768 | case 0x000C:
|
10769 | return '\\f';
|
10770 | case 0x000D:
|
10771 | return '\\r';
|
10772 | default:
|
10773 | throw Error('Invalid code point: ' + codePoint);
|
10774 | }
|
10775 | case 'symbol':
|
10776 | return fromCodePoint(codePoint);
|
10777 | case 'unicodeEscape':
|
10778 | return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
|
10779 | case 'unicodeCodePointEscape':
|
10780 | return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
|
10781 | default:
|
10782 | throw Error('Unsupported node kind: ' + kind);
|
10783 | }
|
10784 | }
|
10785 |
|
10786 | /*--------------------------------------------------------------------------*/
|
10787 |
|
10788 | // Used to generate strings for each node type.
|
10789 | var generators = {
|
10790 | 'alternative': generateAlternative,
|
10791 | 'anchor': generateAnchor,
|
10792 | 'characterClass': generateCharacterClass,
|
10793 | 'characterClassEscape': generateCharacterClassEscape,
|
10794 | 'characterClassRange': generateCharacterClassRange,
|
10795 | 'unicodePropertyEscape': generateUnicodePropertyEscape,
|
10796 | 'disjunction': generateDisjunction,
|
10797 | 'dot': generateDot,
|
10798 | 'group': generateGroup,
|
10799 | 'quantifier': generateQuantifier,
|
10800 | 'reference': generateReference,
|
10801 | 'value': generateValue
|
10802 | };
|
10803 |
|
10804 | /*--------------------------------------------------------------------------*/
|
10805 |
|
10806 | // Export regjsgen.
|
10807 | var regjsgen = {
|
10808 | 'generate': generate
|
10809 | };
|
10810 |
|
10811 | // Some AMD build optimizers, like r.js, check for condition patterns like the following:
|
10812 | if (freeExports && hasFreeModule) {
|
10813 | // Export for CommonJS support.
|
10814 | freeExports.generate = generate;
|
10815 | }
|
10816 | else {
|
10817 | // Export to the global object.
|
10818 | root.regjsgen = regjsgen;
|
10819 | }
|
10820 | }.call(commonjsGlobal));
|
10821 | });
|
10822 |
|
10823 | var parser = createCommonjsModule(function (module) {
|
10824 | // regjsparser
|
10825 | //
|
10826 | // ==================================================================
|
10827 | //
|
10828 | // See ECMA-262 Standard: 15.10.1
|
10829 | //
|
10830 | // NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the
|
10831 | // term "Anchor" is used.
|
10832 | //
|
10833 | // Pattern ::
|
10834 | // Disjunction
|
10835 | //
|
10836 | // Disjunction ::
|
10837 | // Alternative
|
10838 | // Alternative | Disjunction
|
10839 | //
|
10840 | // Alternative ::
|
10841 | // [empty]
|
10842 | // Alternative Term
|
10843 | //
|
10844 | // Term ::
|
10845 | // Anchor
|
10846 | // Atom
|
10847 | // Atom Quantifier
|
10848 | //
|
10849 | // Anchor ::
|
10850 | // ^
|
10851 | // $
|
10852 | // \ b
|
10853 | // \ B
|
10854 | // ( ? = Disjunction )
|
10855 | // ( ? ! Disjunction )
|
10856 | // ( ? < = Disjunction )
|
10857 | // ( ? < ! Disjunction )
|
10858 | //
|
10859 | // Quantifier ::
|
10860 | // QuantifierPrefix
|
10861 | // QuantifierPrefix ?
|
10862 | //
|
10863 | // QuantifierPrefix ::
|
10864 | // *
|
10865 | // +
|
10866 | // ?
|
10867 | // { DecimalDigits }
|
10868 | // { DecimalDigits , }
|
10869 | // { DecimalDigits , DecimalDigits }
|
10870 | //
|
10871 | // Atom ::
|
10872 | // PatternCharacter
|
10873 | // .
|
10874 | // \ AtomEscape
|
10875 | // CharacterClass
|
10876 | // ( GroupSpecifier Disjunction )
|
10877 | // ( ? : Disjunction )
|
10878 | //
|
10879 | // PatternCharacter ::
|
10880 | // SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |
|
10881 | //
|
10882 | // AtomEscape ::
|
10883 | // DecimalEscape
|
10884 | // CharacterEscape
|
10885 | // CharacterClassEscape
|
10886 | // k GroupName
|
10887 | //
|
10888 | // CharacterEscape[U] ::
|
10889 | // ControlEscape
|
10890 | // c ControlLetter
|
10891 | // HexEscapeSequence
|
10892 | // RegExpUnicodeEscapeSequence[?U] (ES6)
|
10893 | // IdentityEscape[?U]
|
10894 | //
|
10895 | // ControlEscape ::
|
10896 | // one of f n r t v
|
10897 | // ControlLetter ::
|
10898 | // one of
|
10899 | // 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
|
10900 | // 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
|
10901 | //
|
10902 | // IdentityEscape ::
|
10903 | // SourceCharacter but not c
|
10904 | //
|
10905 | // DecimalEscape ::
|
10906 | // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
|
10907 | //
|
10908 | // CharacterClassEscape ::
|
10909 | // one of d D s S w W
|
10910 | //
|
10911 | // CharacterClass ::
|
10912 | // [ [lookahead ∉ {^}] ClassRanges ]
|
10913 | // [ ^ ClassRanges ]
|
10914 | //
|
10915 | // ClassRanges ::
|
10916 | // [empty]
|
10917 | // NonemptyClassRanges
|
10918 | //
|
10919 | // NonemptyClassRanges ::
|
10920 | // ClassAtom
|
10921 | // ClassAtom NonemptyClassRangesNoDash
|
10922 | // ClassAtom - ClassAtom ClassRanges
|
10923 | //
|
10924 | // NonemptyClassRangesNoDash ::
|
10925 | // ClassAtom
|
10926 | // ClassAtomNoDash NonemptyClassRangesNoDash
|
10927 | // ClassAtomNoDash - ClassAtom ClassRanges
|
10928 | //
|
10929 | // ClassAtom ::
|
10930 | // -
|
10931 | // ClassAtomNoDash
|
10932 | //
|
10933 | // ClassAtomNoDash ::
|
10934 | // SourceCharacter but not one of \ or ] or -
|
10935 | // \ ClassEscape
|
10936 | //
|
10937 | // ClassEscape ::
|
10938 | // DecimalEscape
|
10939 | // b
|
10940 | // CharacterEscape
|
10941 | // CharacterClassEscape
|
10942 | //
|
10943 | // GroupSpecifier ::
|
10944 | // [empty]
|
10945 | // ? GroupName
|
10946 | //
|
10947 | // GroupName ::
|
10948 | // < RegExpIdentifierName >
|
10949 | //
|
10950 | // RegExpIdentifierName ::
|
10951 | // RegExpIdentifierStart
|
10952 | // RegExpIdentifierName RegExpIdentifierContinue
|
10953 | //
|
10954 | // RegExpIdentifierStart ::
|
10955 | // UnicodeIDStart
|
10956 | // $
|
10957 | // _
|
10958 | // \ RegExpUnicodeEscapeSequence
|
10959 | //
|
10960 | // RegExpIdentifierContinue ::
|
10961 | // UnicodeIDContinue
|
10962 | // $
|
10963 | // _
|
10964 | // \ RegExpUnicodeEscapeSequence
|
10965 | // <ZWNJ>
|
10966 | // <ZWJ>
|
10967 |
|
10968 | (function() {
|
10969 |
|
10970 | var fromCodePoint = String.fromCodePoint || (function() {
|
10971 | // Implementation taken from
|
10972 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
|
10973 |
|
10974 | var stringFromCharCode = String.fromCharCode;
|
10975 | var floor = Math.floor;
|
10976 |
|
10977 | return function fromCodePoint() {
|
10978 | var MAX_SIZE = 0x4000;
|
10979 | var codeUnits = [];
|
10980 | var highSurrogate;
|
10981 | var lowSurrogate;
|
10982 | var index = -1;
|
10983 | var length = arguments.length;
|
10984 | if (!length) {
|
10985 | return '';
|
10986 | }
|
10987 | var result = '';
|
10988 | while (++index < length) {
|
10989 | var codePoint = Number(arguments[index]);
|
10990 | if (
|
10991 | !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
10992 | codePoint < 0 || // not a valid Unicode code point
|
10993 | codePoint > 0x10FFFF || // not a valid Unicode code point
|
10994 | floor(codePoint) != codePoint // not an integer
|
10995 | ) {
|
10996 | throw RangeError('Invalid code point: ' + codePoint);
|
10997 | }
|
10998 | if (codePoint <= 0xFFFF) { // BMP code point
|
10999 | codeUnits.push(codePoint);
|
11000 | } else { // Astral code point; split in surrogate halves
|
11001 | // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
11002 | codePoint -= 0x10000;
|
11003 | highSurrogate = (codePoint >> 10) + 0xD800;
|
11004 | lowSurrogate = (codePoint % 0x400) + 0xDC00;
|
11005 | codeUnits.push(highSurrogate, lowSurrogate);
|
11006 | }
|
11007 | if (index + 1 == length || codeUnits.length > MAX_SIZE) {
|
11008 | result += stringFromCharCode.apply(null, codeUnits);
|
11009 | codeUnits.length = 0;
|
11010 | }
|
11011 | }
|
11012 | return result;
|
11013 | };
|
11014 | }());
|
11015 |
|
11016 | function parse(str, flags, features) {
|
11017 | if (!features) {
|
11018 | features = {};
|
11019 | }
|
11020 | function addRaw(node) {
|
11021 | node.raw = str.substring(node.range[0], node.range[1]);
|
11022 | return node;
|
11023 | }
|
11024 |
|
11025 | function updateRawStart(node, start) {
|
11026 | node.range[0] = start;
|
11027 | return addRaw(node);
|
11028 | }
|
11029 |
|
11030 | function createAnchor(kind, rawLength) {
|
11031 | return addRaw({
|
11032 | type: 'anchor',
|
11033 | kind: kind,
|
11034 | range: [
|
11035 | pos - rawLength,
|
11036 | pos
|
11037 | ]
|
11038 | });
|
11039 | }
|
11040 |
|
11041 | function createValue(kind, codePoint, from, to) {
|
11042 | return addRaw({
|
11043 | type: 'value',
|
11044 | kind: kind,
|
11045 | codePoint: codePoint,
|
11046 | range: [from, to]
|
11047 | });
|
11048 | }
|
11049 |
|
11050 | function createEscaped(kind, codePoint, value, fromOffset) {
|
11051 | fromOffset = fromOffset || 0;
|
11052 | return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);
|
11053 | }
|
11054 |
|
11055 | function createCharacter(matches) {
|
11056 | var _char = matches[0];
|
11057 | var first = _char.charCodeAt(0);
|
11058 | if (hasUnicodeFlag) {
|
11059 | var second;
|
11060 | if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
|
11061 | second = lookahead().charCodeAt(0);
|
11062 | if (second >= 0xDC00 && second <= 0xDFFF) {
|
11063 | // Unicode surrogate pair
|
11064 | pos++;
|
11065 | return createValue(
|
11066 | 'symbol',
|
11067 | (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,
|
11068 | pos - 2, pos);
|
11069 | }
|
11070 | }
|
11071 | }
|
11072 | return createValue('symbol', first, pos - 1, pos);
|
11073 | }
|
11074 |
|
11075 | function createDisjunction(alternatives, from, to) {
|
11076 | return addRaw({
|
11077 | type: 'disjunction',
|
11078 | body: alternatives,
|
11079 | range: [
|
11080 | from,
|
11081 | to
|
11082 | ]
|
11083 | });
|
11084 | }
|
11085 |
|
11086 | function createDot() {
|
11087 | return addRaw({
|
11088 | type: 'dot',
|
11089 | range: [
|
11090 | pos - 1,
|
11091 | pos
|
11092 | ]
|
11093 | });
|
11094 | }
|
11095 |
|
11096 | function createCharacterClassEscape(value) {
|
11097 | return addRaw({
|
11098 | type: 'characterClassEscape',
|
11099 | value: value,
|
11100 | range: [
|
11101 | pos - 2,
|
11102 | pos
|
11103 | ]
|
11104 | });
|
11105 | }
|
11106 |
|
11107 | function createReference(matchIndex) {
|
11108 | return addRaw({
|
11109 | type: 'reference',
|
11110 | matchIndex: parseInt(matchIndex, 10),
|
11111 | range: [
|
11112 | pos - 1 - matchIndex.length,
|
11113 | pos
|
11114 | ]
|
11115 | });
|
11116 | }
|
11117 |
|
11118 | function createNamedReference(name) {
|
11119 | return addRaw({
|
11120 | type: 'reference',
|
11121 | name: name,
|
11122 | range: [
|
11123 | name.range[0] - 3,
|
11124 | pos
|
11125 | ]
|
11126 | });
|
11127 | }
|
11128 |
|
11129 | function createGroup(behavior, disjunction, from, to) {
|
11130 | return addRaw({
|
11131 | type: 'group',
|
11132 | behavior: behavior,
|
11133 | body: disjunction,
|
11134 | range: [
|
11135 | from,
|
11136 | to
|
11137 | ]
|
11138 | });
|
11139 | }
|
11140 |
|
11141 | function createQuantifier(min, max, from, to) {
|
11142 | if (to == null) {
|
11143 | from = pos - 1;
|
11144 | to = pos;
|
11145 | }
|
11146 |
|
11147 | return addRaw({
|
11148 | type: 'quantifier',
|
11149 | min: min,
|
11150 | max: max,
|
11151 | greedy: true,
|
11152 | body: null, // set later on
|
11153 | range: [
|
11154 | from,
|
11155 | to
|
11156 | ]
|
11157 | });
|
11158 | }
|
11159 |
|
11160 | function createAlternative(terms, from, to) {
|
11161 | return addRaw({
|
11162 | type: 'alternative',
|
11163 | body: terms,
|
11164 | range: [
|
11165 | from,
|
11166 | to
|
11167 | ]
|
11168 | });
|
11169 | }
|
11170 |
|
11171 | function createCharacterClass(classRanges, negative, from, to) {
|
11172 | return addRaw({
|
11173 | type: 'characterClass',
|
11174 | body: classRanges,
|
11175 | negative: negative,
|
11176 | range: [
|
11177 | from,
|
11178 | to
|
11179 | ]
|
11180 | });
|
11181 | }
|
11182 |
|
11183 | function createClassRange(min, max, from, to) {
|
11184 | // See 15.10.2.15:
|
11185 | if (min.codePoint > max.codePoint) {
|
11186 | bail('invalid range in character class', min.raw + '-' + max.raw, from, to);
|
11187 | }
|
11188 |
|
11189 | return addRaw({
|
11190 | type: 'characterClassRange',
|
11191 | min: min,
|
11192 | max: max,
|
11193 | range: [
|
11194 | from,
|
11195 | to
|
11196 | ]
|
11197 | });
|
11198 | }
|
11199 |
|
11200 | function flattenBody(body) {
|
11201 | if (body.type === 'alternative') {
|
11202 | return body.body;
|
11203 | } else {
|
11204 | return [body];
|
11205 | }
|
11206 | }
|
11207 |
|
11208 | function incr(amount) {
|
11209 | amount = (amount || 1);
|
11210 | var res = str.substring(pos, pos + amount);
|
11211 | pos += (amount || 1);
|
11212 | return res;
|
11213 | }
|
11214 |
|
11215 | function skip(value) {
|
11216 | if (!match(value)) {
|
11217 | bail('character', value);
|
11218 | }
|
11219 | }
|
11220 |
|
11221 | function match(value) {
|
11222 | if (str.indexOf(value, pos) === pos) {
|
11223 | return incr(value.length);
|
11224 | }
|
11225 | }
|
11226 |
|
11227 | function lookahead() {
|
11228 | return str[pos];
|
11229 | }
|
11230 |
|
11231 | function current(value) {
|
11232 | return str.indexOf(value, pos) === pos;
|
11233 | }
|
11234 |
|
11235 | function next(value) {
|
11236 | return str[pos + 1] === value;
|
11237 | }
|
11238 |
|
11239 | function matchReg(regExp) {
|
11240 | var subStr = str.substring(pos);
|
11241 | var res = subStr.match(regExp);
|
11242 | if (res) {
|
11243 | res.range = [];
|
11244 | res.range[0] = pos;
|
11245 | incr(res[0].length);
|
11246 | res.range[1] = pos;
|
11247 | }
|
11248 | return res;
|
11249 | }
|
11250 |
|
11251 | function parseDisjunction() {
|
11252 | // Disjunction ::
|
11253 | // Alternative
|
11254 | // Alternative | Disjunction
|
11255 | var res = [], from = pos;
|
11256 | res.push(parseAlternative());
|
11257 |
|
11258 | while (match('|')) {
|
11259 | res.push(parseAlternative());
|
11260 | }
|
11261 |
|
11262 | if (res.length === 1) {
|
11263 | return res[0];
|
11264 | }
|
11265 |
|
11266 | return createDisjunction(res, from, pos);
|
11267 | }
|
11268 |
|
11269 | function parseAlternative() {
|
11270 | var res = [], from = pos;
|
11271 | var term;
|
11272 |
|
11273 | // Alternative ::
|
11274 | // [empty]
|
11275 | // Alternative Term
|
11276 | while (term = parseTerm()) {
|
11277 | res.push(term);
|
11278 | }
|
11279 |
|
11280 | if (res.length === 1) {
|
11281 | return res[0];
|
11282 | }
|
11283 |
|
11284 | return createAlternative(res, from, pos);
|
11285 | }
|
11286 |
|
11287 | function parseTerm() {
|
11288 | // Term ::
|
11289 | // Anchor
|
11290 | // Atom
|
11291 | // Atom Quantifier
|
11292 |
|
11293 | if (pos >= str.length || current('|') || current(')')) {
|
11294 | return null; /* Means: The term is empty */
|
11295 | }
|
11296 |
|
11297 | var anchor = parseAnchor();
|
11298 |
|
11299 | if (anchor) {
|
11300 | return anchor;
|
11301 | }
|
11302 |
|
11303 | var atom = parseAtom();
|
11304 | if (!atom) {
|
11305 | bail('Expected atom');
|
11306 | }
|
11307 | var quantifier = parseQuantifier() || false;
|
11308 | if (quantifier) {
|
11309 | quantifier.body = flattenBody(atom);
|
11310 | // The quantifier contains the atom. Therefore, the beginning of the
|
11311 | // quantifier range is given by the beginning of the atom.
|
11312 | updateRawStart(quantifier, atom.range[0]);
|
11313 | return quantifier;
|
11314 | }
|
11315 | return atom;
|
11316 | }
|
11317 |
|
11318 | function parseGroup(matchA, typeA, matchB, typeB) {
|
11319 | var type = null, from = pos;
|
11320 |
|
11321 | if (match(matchA)) {
|
11322 | type = typeA;
|
11323 | } else if (match(matchB)) {
|
11324 | type = typeB;
|
11325 | } else {
|
11326 | return false;
|
11327 | }
|
11328 |
|
11329 | return finishGroup(type, from);
|
11330 | }
|
11331 |
|
11332 | function finishGroup(type, from) {
|
11333 | var body = parseDisjunction();
|
11334 | if (!body) {
|
11335 | bail('Expected disjunction');
|
11336 | }
|
11337 | skip(')');
|
11338 | var group = createGroup(type, flattenBody(body), from, pos);
|
11339 |
|
11340 | if (type == 'normal') {
|
11341 | // Keep track of the number of closed groups. This is required for
|
11342 | // parseDecimalEscape(). In case the string is parsed a second time the
|
11343 | // value already holds the total count and no incrementation is required.
|
11344 | if (firstIteration) {
|
11345 | closedCaptureCounter++;
|
11346 | }
|
11347 | }
|
11348 | return group;
|
11349 | }
|
11350 |
|
11351 | function parseAnchor() {
|
11352 |
|
11353 | if (match('^')) {
|
11354 | return createAnchor('start', 1 /* rawLength */);
|
11355 | } else if (match('$')) {
|
11356 | return createAnchor('end', 1 /* rawLength */);
|
11357 | } else if (match('\\b')) {
|
11358 | return createAnchor('boundary', 2 /* rawLength */);
|
11359 | } else if (match('\\B')) {
|
11360 | return createAnchor('not-boundary', 2 /* rawLength */);
|
11361 | } else {
|
11362 | return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');
|
11363 | }
|
11364 | }
|
11365 |
|
11366 | function parseQuantifier() {
|
11367 | // Quantifier ::
|
11368 | // QuantifierPrefix
|
11369 | // QuantifierPrefix ?
|
11370 | //
|
11371 | // QuantifierPrefix ::
|
11372 | // *
|
11373 | // +
|
11374 | // ?
|
11375 | // { DecimalDigits }
|
11376 | // { DecimalDigits , }
|
11377 | // { DecimalDigits , DecimalDigits }
|
11378 |
|
11379 | var res, from = pos;
|
11380 | var quantifier;
|
11381 | var min, max;
|
11382 |
|
11383 | if (match('*')) {
|
11384 | quantifier = createQuantifier(0);
|
11385 | }
|
11386 | else if (match('+')) {
|
11387 | quantifier = createQuantifier(1);
|
11388 | }
|
11389 | else if (match('?')) {
|
11390 | quantifier = createQuantifier(0, 1);
|
11391 | }
|
11392 | else if (res = matchReg(/^\{([0-9]+)\}/)) {
|
11393 | min = parseInt(res[1], 10);
|
11394 | quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
|
11395 | }
|
11396 | else if (res = matchReg(/^\{([0-9]+),\}/)) {
|
11397 | min = parseInt(res[1], 10);
|
11398 | quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
|
11399 | }
|
11400 | else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
|
11401 | min = parseInt(res[1], 10);
|
11402 | max = parseInt(res[2], 10);
|
11403 | if (min > max) {
|
11404 | bail('numbers out of order in {} quantifier', '', from, pos);
|
11405 | }
|
11406 | quantifier = createQuantifier(min, max, res.range[0], res.range[1]);
|
11407 | }
|
11408 |
|
11409 | if (quantifier) {
|
11410 | if (match('?')) {
|
11411 | quantifier.greedy = false;
|
11412 | quantifier.range[1] += 1;
|
11413 | }
|
11414 | }
|
11415 |
|
11416 | return quantifier;
|
11417 | }
|
11418 |
|
11419 | function parseAtom() {
|
11420 | // Atom ::
|
11421 | // PatternCharacter
|
11422 | // .
|
11423 | // \ AtomEscape
|
11424 | // CharacterClass
|
11425 | // ( GroupSpecifier Disjunction )
|
11426 | // ( ? : Disjunction )
|
11427 |
|
11428 | var res;
|
11429 |
|
11430 | // jviereck: allow ']', '}' here as well to be compatible with browser's
|
11431 | // implementations: ']'.match(/]/);
|
11432 | // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) {
|
11433 | if (res = matchReg(/^[^^$\\.*+?(){[|]/)) {
|
11434 | // PatternCharacter
|
11435 | return createCharacter(res);
|
11436 | }
|
11437 | else if (match('.')) {
|
11438 | // .
|
11439 | return createDot();
|
11440 | }
|
11441 | else if (match('\\')) {
|
11442 | // \ AtomEscape
|
11443 | res = parseAtomEscape();
|
11444 | if (!res) {
|
11445 | if (!hasUnicodeFlag && lookahead() == 'c') {
|
11446 | // B.1.4 ExtendedAtom
|
11447 | // \[lookahead = c]
|
11448 | return createValue('symbol', 92, pos - 1, pos);
|
11449 | }
|
11450 | bail('atomEscape');
|
11451 | }
|
11452 | return res;
|
11453 | }
|
11454 | else if (res = parseCharacterClass()) {
|
11455 | return res;
|
11456 | }
|
11457 | else if (features.lookbehind && (res = parseGroup('(?<=', 'lookbehind', '(?<!', 'negativeLookbehind'))) {
|
11458 | return res;
|
11459 | }
|
11460 | else if (features.namedGroups && match("(?<")) {
|
11461 | var name = parseIdentifier();
|
11462 | skip(">");
|
11463 | var group = finishGroup("normal", name.range[0] - 3);
|
11464 | group.name = name;
|
11465 | return group;
|
11466 | }
|
11467 | else {
|
11468 | // ( Disjunction )
|
11469 | // ( ? : Disjunction )
|
11470 | return parseGroup('(?:', 'ignore', '(', 'normal');
|
11471 | }
|
11472 | }
|
11473 |
|
11474 | function parseUnicodeSurrogatePairEscape(firstEscape) {
|
11475 | if (hasUnicodeFlag) {
|
11476 | var first, second;
|
11477 | if (firstEscape.kind == 'unicodeEscape' &&
|
11478 | (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&
|
11479 | current('\\') && next('u') ) {
|
11480 | var prevPos = pos;
|
11481 | pos++;
|
11482 | var secondEscape = parseClassEscape();
|
11483 | if (secondEscape.kind == 'unicodeEscape' &&
|
11484 | (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {
|
11485 | // Unicode surrogate pair
|
11486 | firstEscape.range[1] = secondEscape.range[1];
|
11487 | firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
|
11488 | firstEscape.type = 'value';
|
11489 | firstEscape.kind = 'unicodeCodePointEscape';
|
11490 | addRaw(firstEscape);
|
11491 | }
|
11492 | else {
|
11493 | pos = prevPos;
|
11494 | }
|
11495 | }
|
11496 | }
|
11497 | return firstEscape;
|
11498 | }
|
11499 |
|
11500 | function parseClassEscape() {
|
11501 | return parseAtomEscape(true);
|
11502 | }
|
11503 |
|
11504 | function parseAtomEscape(insideCharacterClass) {
|
11505 | // AtomEscape ::
|
11506 | // DecimalEscape
|
11507 | // CharacterEscape
|
11508 | // CharacterClassEscape
|
11509 | // k GroupName
|
11510 |
|
11511 | var res, from = pos;
|
11512 |
|
11513 | res = parseDecimalEscape() || parseNamedReference();
|
11514 | if (res) {
|
11515 | return res;
|
11516 | }
|
11517 |
|
11518 | // For ClassEscape
|
11519 | if (insideCharacterClass) {
|
11520 | if (match('b')) {
|
11521 | // 15.10.2.19
|
11522 | // The production ClassEscape :: b evaluates by returning the
|
11523 | // CharSet containing the one character <BS> (Unicode value 0008).
|
11524 | return createEscaped('singleEscape', 0x0008, '\\b');
|
11525 | } else if (match('B')) {
|
11526 | bail('\\B not possible inside of CharacterClass', '', from);
|
11527 | } else if (!hasUnicodeFlag && (res = matchReg(/^c([0-9])/))) {
|
11528 | // B.1.4
|
11529 | // c ClassControlLetter
|
11530 | return createEscaped('controlLetter', res[1] + 16, res[1], 2);
|
11531 | }
|
11532 | }
|
11533 |
|
11534 | res = parseCharacterEscape();
|
11535 |
|
11536 | return res;
|
11537 | }
|
11538 |
|
11539 |
|
11540 | function parseDecimalEscape() {
|
11541 | // DecimalEscape ::
|
11542 | // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
|
11543 | // CharacterClassEscape :: one of d D s S w W
|
11544 |
|
11545 | var res, match;
|
11546 |
|
11547 | if (res = matchReg(/^(?!0)\d+/)) {
|
11548 | match = res[0];
|
11549 | var refIdx = parseInt(res[0], 10);
|
11550 | if (refIdx <= closedCaptureCounter) {
|
11551 | // If the number is smaller than the normal-groups found so
|
11552 | // far, then it is a reference...
|
11553 | return createReference(res[0]);
|
11554 | } else {
|
11555 | // ... otherwise it needs to be interpreted as a octal (if the
|
11556 | // number is in an octal format). If it is NOT octal format,
|
11557 | // then the slash is ignored and the number is matched later
|
11558 | // as normal characters.
|
11559 |
|
11560 | // Recall the negative decision to decide if the input must be parsed
|
11561 | // a second time with the total normal-groups.
|
11562 | backrefDenied.push(refIdx);
|
11563 |
|
11564 | // Reset the position again, as maybe only parts of the previous
|
11565 | // matched numbers are actual octal numbers. E.g. in '019' only
|
11566 | // the '01' should be matched.
|
11567 | incr(-res[0].length);
|
11568 | if (res = matchReg(/^[0-7]{1,3}/)) {
|
11569 | return createEscaped('octal', parseInt(res[0], 8), res[0], 1);
|
11570 | } else {
|
11571 | // If we end up here, we have a case like /\91/. Then the
|
11572 | // first slash is to be ignored and the 9 & 1 to be treated
|
11573 | // like ordinary characters. Create a character for the
|
11574 | // first number only here - other number-characters
|
11575 | // (if available) will be matched later.
|
11576 | res = createCharacter(matchReg(/^[89]/));
|
11577 | return updateRawStart(res, res.range[0] - 1);
|
11578 | }
|
11579 | }
|
11580 | }
|
11581 | // Only allow octal numbers in the following. All matched numbers start
|
11582 | // with a zero (if the do not, the previous if-branch is executed).
|
11583 | // If the number is not octal format and starts with zero (e.g. `091`)
|
11584 | // then only the zeros `0` is treated here and the `91` are ordinary
|
11585 | // characters.
|
11586 | // Example:
|
11587 | // /\091/.exec('\091')[0].length === 3
|
11588 | else if (res = matchReg(/^[0-7]{1,3}/)) {
|
11589 | match = res[0];
|
11590 | if (/^0{1,3}$/.test(match)) {
|
11591 | // If they are all zeros, then only take the first one.
|
11592 | return createEscaped('null', 0x0000, '0', match.length + 1);
|
11593 | } else {
|
11594 | return createEscaped('octal', parseInt(match, 8), match, 1);
|
11595 | }
|
11596 | } else if (res = matchReg(/^[dDsSwW]/)) {
|
11597 | return createCharacterClassEscape(res[0]);
|
11598 | }
|
11599 | return false;
|
11600 | }
|
11601 |
|
11602 | function parseNamedReference() {
|
11603 | if (features.namedGroups && matchReg(/^k<(?=.*?>)/)) {
|
11604 | var name = parseIdentifier();
|
11605 | skip('>');
|
11606 | return createNamedReference(name);
|
11607 | }
|
11608 | }
|
11609 |
|
11610 | function parseRegExpUnicodeEscapeSequence() {
|
11611 | var res;
|
11612 | if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {
|
11613 | // UnicodeEscapeSequence
|
11614 | return parseUnicodeSurrogatePairEscape(
|
11615 | createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2)
|
11616 | );
|
11617 | } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {
|
11618 | // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)
|
11619 | return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);
|
11620 | }
|
11621 | }
|
11622 |
|
11623 | function parseCharacterEscape() {
|
11624 | // CharacterEscape ::
|
11625 | // ControlEscape
|
11626 | // c ControlLetter
|
11627 | // HexEscapeSequence
|
11628 | // UnicodeEscapeSequence
|
11629 | // IdentityEscape
|
11630 |
|
11631 | var res;
|
11632 | var from = pos;
|
11633 | if (res = matchReg(/^[fnrtv]/)) {
|
11634 | // ControlEscape
|
11635 | var codePoint = 0;
|
11636 | switch (res[0]) {
|
11637 | case 't': codePoint = 0x009; break;
|
11638 | case 'n': codePoint = 0x00A; break;
|
11639 | case 'v': codePoint = 0x00B; break;
|
11640 | case 'f': codePoint = 0x00C; break;
|
11641 | case 'r': codePoint = 0x00D; break;
|
11642 | }
|
11643 | return createEscaped('singleEscape', codePoint, '\\' + res[0]);
|
11644 | } else if (res = matchReg(/^c([a-zA-Z])/)) {
|
11645 | // c ControlLetter
|
11646 | return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);
|
11647 | } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) {
|
11648 | // HexEscapeSequence
|
11649 | return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2);
|
11650 | } else if (res = parseRegExpUnicodeEscapeSequence()) {
|
11651 | if (!res || res.codePoint > 0x10FFFF) {
|
11652 | bail('Invalid escape sequence', null, from, pos);
|
11653 | }
|
11654 | return res;
|
11655 | } else if (features.unicodePropertyEscape && hasUnicodeFlag && (res = matchReg(/^([pP])\{([^\}]+)\}/))) {
|
11656 | // https://github.com/jviereck/regjsparser/issues/77
|
11657 | return addRaw({
|
11658 | type: 'unicodePropertyEscape',
|
11659 | negative: res[1] === 'P',
|
11660 | value: res[2],
|
11661 | range: [res.range[0] - 1, res.range[1]],
|
11662 | raw: res[0]
|
11663 | });
|
11664 | } else {
|
11665 | // IdentityEscape
|
11666 | return parseIdentityEscape();
|
11667 | }
|
11668 | }
|
11669 |
|
11670 | function parseIdentifierAtom(check) {
|
11671 | var ch = lookahead();
|
11672 | var from = pos;
|
11673 | if (ch === '\\') {
|
11674 | incr();
|
11675 | var esc = parseRegExpUnicodeEscapeSequence();
|
11676 | if (!esc || !check(esc.codePoint)) {
|
11677 | bail('Invalid escape sequence', null, from, pos);
|
11678 | }
|
11679 | return fromCodePoint(esc.codePoint);
|
11680 | }
|
11681 | var code = ch.charCodeAt(0);
|
11682 | if (code >= 0xD800 && code <= 0xDBFF) {
|
11683 | ch += str[pos + 1];
|
11684 | var second = ch.charCodeAt(1);
|
11685 | if (second >= 0xDC00 && second <= 0xDFFF) {
|
11686 | // Unicode surrogate pair
|
11687 | code = (code - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
|
11688 | }
|
11689 | }
|
11690 | if (!check(code)) return;
|
11691 | incr();
|
11692 | if (code > 0xFFFF) incr();
|
11693 | return ch;
|
11694 | }
|
11695 |
|
11696 | function parseIdentifier() {
|
11697 | // RegExpIdentifierName ::
|
11698 | // RegExpIdentifierStart
|
11699 | // RegExpIdentifierName RegExpIdentifierContinue
|
11700 | //
|
11701 | // RegExpIdentifierStart ::
|
11702 | // UnicodeIDStart
|
11703 | // $
|
11704 | // _
|
11705 | // \ RegExpUnicodeEscapeSequence
|
11706 | //
|
11707 | // RegExpIdentifierContinue ::
|
11708 | // UnicodeIDContinue
|
11709 | // $
|
11710 | // _
|
11711 | // \ RegExpUnicodeEscapeSequence
|
11712 | // <ZWNJ>
|
11713 | // <ZWJ>
|
11714 |
|
11715 | var start = pos;
|
11716 | var res = parseIdentifierAtom(isIdentifierStart);
|
11717 | if (!res) {
|
11718 | bail('Invalid identifier');
|
11719 | }
|
11720 |
|
11721 | var ch;
|
11722 | while (ch = parseIdentifierAtom(isIdentifierPart)) {
|
11723 | res += ch;
|
11724 | }
|
11725 |
|
11726 | return addRaw({
|
11727 | type: 'identifier',
|
11728 | value: res,
|
11729 | range: [start, pos]
|
11730 | });
|
11731 | }
|
11732 |
|
11733 | function isIdentifierStart(ch) {
|
11734 | // Generated by `tools/generate-identifier-regex.js`.
|
11735 | var NonAsciiIdentifierStart = /[\$A-Z_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEF\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7B9\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\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]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDF00-\uDF1C\uDF27\uDF30-\uDF45]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF1A]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDE9D\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFF1]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/;
|
11736 |
|
11737 | return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
|
11738 | (ch >= 65 && ch <= 90) || // A..Z
|
11739 | (ch >= 97 && ch <= 122) || // a..z
|
11740 | ((ch >= 0x80) && NonAsciiIdentifierStart.test(fromCodePoint(ch)));
|
11741 | }
|
11742 |
|
11743 | // Taken from the Esprima parser.
|
11744 | function isIdentifierPart(ch) {
|
11745 | // Generated by `tools/generate-identifier-regex.js`.
|
11746 | var NonAsciiIdentifierPartOnly = /[0-9_\xB7\u0300-\u036F\u0387\u0483-\u0487\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u0669\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u06F0-\u06F9\u0711\u0730-\u074A\u07A6-\u07B0\u07C0-\u07C9\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0966-\u096F\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09E6-\u09EF\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A66-\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AE6-\u0AEF\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B66-\u0B6F\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0BE6-\u0BEF\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0CE6-\u0CEF\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D66-\u0D6F\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0E50-\u0E59\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0ED0-\u0ED9\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1040-\u1049\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F-\u109D\u135D-\u135F\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u18A9\u1920-\u192B\u1930-\u193B\u1946-\u194F\u19D0-\u19DA\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AB0-\u1ABD\u1B00-\u1B04\u1B34-\u1B44\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BB0-\u1BB9\u1BE6-\u1BF3\u1C24-\u1C37\u1C40-\u1C49\u1C50-\u1C59\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u200C\u200D\u203F\u2040\u2054\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA620-\uA629\uA66F\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F1\uA8FF-\uA909\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9D0-\uA9D9\uA9E5\uA9F0-\uA9F9\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA50-\uAA59\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uABF0-\uABF9\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFF10-\uFF19\uFF3F]|\uD800[\uDDFD\uDEE0\uDF76-\uDF7A]|\uD801[\uDCA0-\uDCA9]|\uD802[\uDE01-\uDE03\uDE05\uDE06\uDE0C-\uDE0F\uDE38-\uDE3A\uDE3F\uDEE5\uDEE6]|\uD803[\uDD24-\uDD27\uDD30-\uDD39\uDF46-\uDF50]|\uD804[\uDC00-\uDC02\uDC38-\uDC46\uDC66-\uDC6F\uDC7F-\uDC82\uDCB0-\uDCBA\uDCF0-\uDCF9\uDD00-\uDD02\uDD27-\uDD34\uDD36-\uDD3F\uDD45\uDD46\uDD73\uDD80-\uDD82\uDDB3-\uDDC0\uDDC9-\uDDCC\uDDD0-\uDDD9\uDE2C-\uDE37\uDE3E\uDEDF-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF3B\uDF3C\uDF3E-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF57\uDF62\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC35-\uDC46\uDC50-\uDC59\uDC5E\uDCB0-\uDCC3\uDCD0-\uDCD9\uDDAF-\uDDB5\uDDB8-\uDDC0\uDDDC\uDDDD\uDE30-\uDE40\uDE50-\uDE59\uDEAB-\uDEB7\uDEC0-\uDEC9\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDC2C-\uDC3A\uDCE0-\uDCE9\uDE01-\uDE0A\uDE33-\uDE39\uDE3B-\uDE3E\uDE47\uDE51-\uDE5B\uDE8A-\uDE99]|\uD807[\uDC2F-\uDC36\uDC38-\uDC3F\uDC50-\uDC59\uDC92-\uDCA7\uDCA9-\uDCB6\uDD31-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD45\uDD47\uDD50-\uDD59\uDD8A-\uDD8E\uDD90\uDD91\uDD93-\uDD97\uDDA0-\uDDA9\uDEF3-\uDEF6]|\uD81A[\uDE60-\uDE69\uDEF0-\uDEF4\uDF30-\uDF36\uDF50-\uDF59]|\uD81B[\uDF51-\uDF7E\uDF8F-\uDF92]|\uD82F[\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDCD0-\uDCD6\uDD44-\uDD4A\uDD50-\uDD59]|\uDB40[\uDD00-\uDDEF]/;
|
11747 |
|
11748 | return isIdentifierStart(ch) ||
|
11749 | (ch >= 48 && ch <= 57) || // 0..9
|
11750 | ((ch >= 0x80) && NonAsciiIdentifierPartOnly.test(fromCodePoint(ch)));
|
11751 | }
|
11752 |
|
11753 | function parseIdentityEscape() {
|
11754 | // IdentityEscape ::
|
11755 | // SourceCharacter but not c
|
11756 |
|
11757 | var tmp;
|
11758 |
|
11759 | if (lookahead() !== 'c') {
|
11760 | tmp = incr();
|
11761 | return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1);
|
11762 | }
|
11763 |
|
11764 | return null;
|
11765 | }
|
11766 |
|
11767 | function parseCharacterClass() {
|
11768 | // CharacterClass ::
|
11769 | // [ [lookahead ∉ {^}] ClassRanges ]
|
11770 | // [ ^ ClassRanges ]
|
11771 |
|
11772 | var res, from = pos;
|
11773 | if (res = matchReg(/^\[\^/)) {
|
11774 | res = parseClassRanges();
|
11775 | skip(']');
|
11776 | return createCharacterClass(res, true, from, pos);
|
11777 | } else if (match('[')) {
|
11778 | res = parseClassRanges();
|
11779 | skip(']');
|
11780 | return createCharacterClass(res, false, from, pos);
|
11781 | }
|
11782 |
|
11783 | return null;
|
11784 | }
|
11785 |
|
11786 | function parseClassRanges() {
|
11787 | // ClassRanges ::
|
11788 | // [empty]
|
11789 | // NonemptyClassRanges
|
11790 |
|
11791 | var res;
|
11792 | if (current(']')) {
|
11793 | // Empty array means nothing insinde of the ClassRange.
|
11794 | return [];
|
11795 | } else {
|
11796 | res = parseNonemptyClassRanges();
|
11797 | if (!res) {
|
11798 | bail('nonEmptyClassRanges');
|
11799 | }
|
11800 | return res;
|
11801 | }
|
11802 | }
|
11803 |
|
11804 | function parseHelperClassRanges(atom) {
|
11805 | var from, to, res;
|
11806 | if (current('-') && !next(']')) {
|
11807 | // ClassAtom - ClassAtom ClassRanges
|
11808 | skip('-');
|
11809 |
|
11810 | res = parseClassAtom();
|
11811 | if (!res) {
|
11812 | bail('classAtom');
|
11813 | }
|
11814 | to = pos;
|
11815 | var classRanges = parseClassRanges();
|
11816 | if (!classRanges) {
|
11817 | bail('classRanges');
|
11818 | }
|
11819 | from = atom.range[0];
|
11820 | if (classRanges.type === 'empty') {
|
11821 | return [createClassRange(atom, res, from, to)];
|
11822 | }
|
11823 | return [createClassRange(atom, res, from, to)].concat(classRanges);
|
11824 | }
|
11825 |
|
11826 | res = parseNonemptyClassRangesNoDash();
|
11827 | if (!res) {
|
11828 | bail('nonEmptyClassRangesNoDash');
|
11829 | }
|
11830 |
|
11831 | return [atom].concat(res);
|
11832 | }
|
11833 |
|
11834 | function parseNonemptyClassRanges() {
|
11835 | // NonemptyClassRanges ::
|
11836 | // ClassAtom
|
11837 | // ClassAtom NonemptyClassRangesNoDash
|
11838 | // ClassAtom - ClassAtom ClassRanges
|
11839 |
|
11840 | var atom = parseClassAtom();
|
11841 | if (!atom) {
|
11842 | bail('classAtom');
|
11843 | }
|
11844 |
|
11845 | if (current(']')) {
|
11846 | // ClassAtom
|
11847 | return [atom];
|
11848 | }
|
11849 |
|
11850 | // ClassAtom NonemptyClassRangesNoDash
|
11851 | // ClassAtom - ClassAtom ClassRanges
|
11852 | return parseHelperClassRanges(atom);
|
11853 | }
|
11854 |
|
11855 | function parseNonemptyClassRangesNoDash() {
|
11856 | // NonemptyClassRangesNoDash ::
|
11857 | // ClassAtom
|
11858 | // ClassAtomNoDash NonemptyClassRangesNoDash
|
11859 | // ClassAtomNoDash - ClassAtom ClassRanges
|
11860 |
|
11861 | var res = parseClassAtom();
|
11862 | if (!res) {
|
11863 | bail('classAtom');
|
11864 | }
|
11865 | if (current(']')) {
|
11866 | // ClassAtom
|
11867 | return res;
|
11868 | }
|
11869 |
|
11870 | // ClassAtomNoDash NonemptyClassRangesNoDash
|
11871 | // ClassAtomNoDash - ClassAtom ClassRanges
|
11872 | return parseHelperClassRanges(res);
|
11873 | }
|
11874 |
|
11875 | function parseClassAtom() {
|
11876 | // ClassAtom ::
|
11877 | // -
|
11878 | // ClassAtomNoDash
|
11879 | if (match('-')) {
|
11880 | return createCharacter('-');
|
11881 | } else {
|
11882 | return parseClassAtomNoDash();
|
11883 | }
|
11884 | }
|
11885 |
|
11886 | function parseClassAtomNoDash() {
|
11887 | // ClassAtomNoDash ::
|
11888 | // SourceCharacter but not one of \ or ] or -
|
11889 | // \ ClassEscape
|
11890 |
|
11891 | var res;
|
11892 | if (res = matchReg(/^[^\\\]-]/)) {
|
11893 | return createCharacter(res[0]);
|
11894 | } else if (match('\\')) {
|
11895 | res = parseClassEscape();
|
11896 | if (!res) {
|
11897 | bail('classEscape');
|
11898 | }
|
11899 |
|
11900 | return parseUnicodeSurrogatePairEscape(res);
|
11901 | }
|
11902 | }
|
11903 |
|
11904 | function bail(message, details, from, to) {
|
11905 | from = from == null ? pos : from;
|
11906 | to = to == null ? from : to;
|
11907 |
|
11908 | var contextStart = Math.max(0, from - 10);
|
11909 | var contextEnd = Math.min(to + 10, str.length);
|
11910 |
|
11911 | // Output a bit of context and a line pointing to where our error is.
|
11912 | //
|
11913 | // We are assuming that there are no actual newlines in the content as this is a regular expression.
|
11914 | var context = ' ' + str.substring(contextStart, contextEnd);
|
11915 | var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^';
|
11916 |
|
11917 | throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer);
|
11918 | }
|
11919 |
|
11920 | var backrefDenied = [];
|
11921 | var closedCaptureCounter = 0;
|
11922 | var firstIteration = true;
|
11923 | var hasUnicodeFlag = (flags || "").indexOf("u") !== -1;
|
11924 | var pos = 0;
|
11925 |
|
11926 | // Convert the input to a string and treat the empty string special.
|
11927 | str = String(str);
|
11928 | if (str === '') {
|
11929 | str = '(?:)';
|
11930 | }
|
11931 |
|
11932 | var result = parseDisjunction();
|
11933 |
|
11934 | if (result.range[1] !== str.length) {
|
11935 | bail('Could not parse entire input - got stuck', '', result.range[1]);
|
11936 | }
|
11937 |
|
11938 | // The spec requires to interpret the `\2` in `/\2()()/` as backreference.
|
11939 | // As the parser collects the number of capture groups as the string is
|
11940 | // parsed it is impossible to make these decisions at the point when the
|
11941 | // `\2` is handled. In case the local decision turns out to be wrong after
|
11942 | // the parsing has finished, the input string is parsed a second time with
|
11943 | // the total number of capture groups set.
|
11944 | //
|
11945 | // SEE: https://github.com/jviereck/regjsparser/issues/70
|
11946 | for (var i = 0; i < backrefDenied.length; i++) {
|
11947 | if (backrefDenied[i] <= closedCaptureCounter) {
|
11948 | // Parse the input a second time.
|
11949 | pos = 0;
|
11950 | firstIteration = false;
|
11951 | return parseDisjunction();
|
11952 | }
|
11953 | }
|
11954 |
|
11955 | return result;
|
11956 | }
|
11957 |
|
11958 | var regjsparser = {
|
11959 | parse: parse
|
11960 | };
|
11961 |
|
11962 | if ( module.exports) {
|
11963 | module.exports = regjsparser;
|
11964 | } else {
|
11965 | window.regjsparser = regjsparser;
|
11966 | }
|
11967 |
|
11968 | }());
|
11969 | });
|
11970 |
|
11971 | var regenerate = createCommonjsModule(function (module, exports) {
|
11972 | (function(root) {
|
11973 |
|
11974 | // Detect free variables `exports`.
|
11975 | var freeExports = exports;
|
11976 |
|
11977 | // Detect free variable `module`.
|
11978 | var freeModule = module &&
|
11979 | module.exports == freeExports && module;
|
11980 |
|
11981 | // Detect free variable `global`, from Node.js/io.js or Browserified code,
|
11982 | // and use it as `root`.
|
11983 | var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
|
11984 | if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
|
11985 | root = freeGlobal;
|
11986 | }
|
11987 |
|
11988 | /*--------------------------------------------------------------------------*/
|
11989 |
|
11990 | var ERRORS = {
|
11991 | 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
|
11992 | 'to the `start` value.',
|
11993 | 'codePointRange': 'Invalid code point value. Code points range from ' +
|
11994 | 'U+000000 to U+10FFFF.'
|
11995 | };
|
11996 |
|
11997 | // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
|
11998 | var HIGH_SURROGATE_MIN = 0xD800;
|
11999 | var HIGH_SURROGATE_MAX = 0xDBFF;
|
12000 | var LOW_SURROGATE_MIN = 0xDC00;
|
12001 | var LOW_SURROGATE_MAX = 0xDFFF;
|
12002 |
|
12003 | // In Regenerate output, `\0` is never preceded by `\` because we sort by
|
12004 | // code point value, so let’s keep this regular expression simple.
|
12005 | var regexNull = /\\x00([^0123456789]|$)/g;
|
12006 |
|
12007 | var object = {};
|
12008 | var hasOwnProperty = object.hasOwnProperty;
|
12009 | var extend = function(destination, source) {
|
12010 | var key;
|
12011 | for (key in source) {
|
12012 | if (hasOwnProperty.call(source, key)) {
|
12013 | destination[key] = source[key];
|
12014 | }
|
12015 | }
|
12016 | return destination;
|
12017 | };
|
12018 |
|
12019 | var forEach = function(array, callback) {
|
12020 | var index = -1;
|
12021 | var length = array.length;
|
12022 | while (++index < length) {
|
12023 | callback(array[index], index);
|
12024 | }
|
12025 | };
|
12026 |
|
12027 | var toString = object.toString;
|
12028 | var isArray = function(value) {
|
12029 | return toString.call(value) == '[object Array]';
|
12030 | };
|
12031 | var isNumber = function(value) {
|
12032 | return typeof value == 'number' ||
|
12033 | toString.call(value) == '[object Number]';
|
12034 | };
|
12035 |
|
12036 | // This assumes that `number` is a positive integer that `toString()`s nicely
|
12037 | // (which is the case for all code point values).
|
12038 | var zeroes = '0000';
|
12039 | var pad = function(number, totalCharacters) {
|
12040 | var string = String(number);
|
12041 | return string.length < totalCharacters
|
12042 | ? (zeroes + string).slice(-totalCharacters)
|
12043 | : string;
|
12044 | };
|
12045 |
|
12046 | var hex = function(number) {
|
12047 | return Number(number).toString(16).toUpperCase();
|
12048 | };
|
12049 |
|
12050 | var slice = [].slice;
|
12051 |
|
12052 | /*--------------------------------------------------------------------------*/
|
12053 |
|
12054 | var dataFromCodePoints = function(codePoints) {
|
12055 | var index = -1;
|
12056 | var length = codePoints.length;
|
12057 | var max = length - 1;
|
12058 | var result = [];
|
12059 | var isStart = true;
|
12060 | var tmp;
|
12061 | var previous = 0;
|
12062 | while (++index < length) {
|
12063 | tmp = codePoints[index];
|
12064 | if (isStart) {
|
12065 | result.push(tmp);
|
12066 | previous = tmp;
|
12067 | isStart = false;
|
12068 | } else {
|
12069 | if (tmp == previous + 1) {
|
12070 | if (index != max) {
|
12071 | previous = tmp;
|
12072 | continue;
|
12073 | } else {
|
12074 | isStart = true;
|
12075 | result.push(tmp + 1);
|
12076 | }
|
12077 | } else {
|
12078 | // End the previous range and start a new one.
|
12079 | result.push(previous + 1, tmp);
|
12080 | previous = tmp;
|
12081 | }
|
12082 | }
|
12083 | }
|
12084 | if (!isStart) {
|
12085 | result.push(tmp + 1);
|
12086 | }
|
12087 | return result;
|
12088 | };
|
12089 |
|
12090 | var dataRemove = function(data, codePoint) {
|
12091 | // Iterate over the data per `(start, end)` pair.
|
12092 | var index = 0;
|
12093 | var start;
|
12094 | var end;
|
12095 | var length = data.length;
|
12096 | while (index < length) {
|
12097 | start = data[index];
|
12098 | end = data[index + 1];
|
12099 | if (codePoint >= start && codePoint < end) {
|
12100 | // Modify this pair.
|
12101 | if (codePoint == start) {
|
12102 | if (end == start + 1) {
|
12103 | // Just remove `start` and `end`.
|
12104 | data.splice(index, 2);
|
12105 | return data;
|
12106 | } else {
|
12107 | // Just replace `start` with a new value.
|
12108 | data[index] = codePoint + 1;
|
12109 | return data;
|
12110 | }
|
12111 | } else if (codePoint == end - 1) {
|
12112 | // Just replace `end` with a new value.
|
12113 | data[index + 1] = codePoint;
|
12114 | return data;
|
12115 | } else {
|
12116 | // Replace `[start, end]` with `[startA, endA, startB, endB]`.
|
12117 | data.splice(index, 2, start, codePoint, codePoint + 1, end);
|
12118 | return data;
|
12119 | }
|
12120 | }
|
12121 | index += 2;
|
12122 | }
|
12123 | return data;
|
12124 | };
|
12125 |
|
12126 | var dataRemoveRange = function(data, rangeStart, rangeEnd) {
|
12127 | if (rangeEnd < rangeStart) {
|
12128 | throw Error(ERRORS.rangeOrder);
|
12129 | }
|
12130 | // Iterate over the data per `(start, end)` pair.
|
12131 | var index = 0;
|
12132 | var start;
|
12133 | var end;
|
12134 | while (index < data.length) {
|
12135 | start = data[index];
|
12136 | end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
|
12137 |
|
12138 | // Exit as soon as no more matching pairs can be found.
|
12139 | if (start > rangeEnd) {
|
12140 | return data;
|
12141 | }
|
12142 |
|
12143 | // Check if this range pair is equal to, or forms a subset of, the range
|
12144 | // to be removed.
|
12145 | // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
|
12146 | // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
|
12147 | if (rangeStart <= start && rangeEnd >= end) {
|
12148 | // Remove this pair.
|
12149 | data.splice(index, 2);
|
12150 | continue;
|
12151 | }
|
12152 |
|
12153 | // Check if both `rangeStart` and `rangeEnd` are within the bounds of
|
12154 | // this pair.
|
12155 | // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
|
12156 | if (rangeStart >= start && rangeEnd < end) {
|
12157 | if (rangeStart == start) {
|
12158 | // Replace `[start, end]` with `[startB, endB]`.
|
12159 | data[index] = rangeEnd + 1;
|
12160 | data[index + 1] = end + 1;
|
12161 | return data;
|
12162 | }
|
12163 | // Replace `[start, end]` with `[startA, endA, startB, endB]`.
|
12164 | data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
|
12165 | return data;
|
12166 | }
|
12167 |
|
12168 | // Check if only `rangeStart` is within the bounds of this pair.
|
12169 | // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
|
12170 | if (rangeStart >= start && rangeStart <= end) {
|
12171 | // Replace `end` with `rangeStart`.
|
12172 | data[index + 1] = rangeStart;
|
12173 | // Note: we cannot `return` just yet, in case any following pairs still
|
12174 | // contain matching code points.
|
12175 | // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
|
12176 | // → `[0, 4, 21, 31]`.
|
12177 | }
|
12178 |
|
12179 | // Check if only `rangeEnd` is within the bounds of this pair.
|
12180 | // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
|
12181 | else if (rangeEnd >= start && rangeEnd <= end) {
|
12182 | // Just replace `start`.
|
12183 | data[index] = rangeEnd + 1;
|
12184 | return data;
|
12185 | }
|
12186 |
|
12187 | index += 2;
|
12188 | }
|
12189 | return data;
|
12190 | };
|
12191 |
|
12192 | var dataAdd = function(data, codePoint) {
|
12193 | // Iterate over the data per `(start, end)` pair.
|
12194 | var index = 0;
|
12195 | var start;
|
12196 | var end;
|
12197 | var lastIndex = null;
|
12198 | var length = data.length;
|
12199 | if (codePoint < 0x0 || codePoint > 0x10FFFF) {
|
12200 | throw RangeError(ERRORS.codePointRange);
|
12201 | }
|
12202 | while (index < length) {
|
12203 | start = data[index];
|
12204 | end = data[index + 1];
|
12205 |
|
12206 | // Check if the code point is already in the set.
|
12207 | if (codePoint >= start && codePoint < end) {
|
12208 | return data;
|
12209 | }
|
12210 |
|
12211 | if (codePoint == start - 1) {
|
12212 | // Just replace `start` with a new value.
|
12213 | data[index] = codePoint;
|
12214 | return data;
|
12215 | }
|
12216 |
|
12217 | // At this point, if `start` is `greater` than `codePoint`, insert a new
|
12218 | // `[start, end]` pair before the current pair, or after the current pair
|
12219 | // if there is a known `lastIndex`.
|
12220 | if (start > codePoint) {
|
12221 | data.splice(
|
12222 | lastIndex != null ? lastIndex + 2 : 0,
|
12223 | 0,
|
12224 | codePoint,
|
12225 | codePoint + 1
|
12226 | );
|
12227 | return data;
|
12228 | }
|
12229 |
|
12230 | if (codePoint == end) {
|
12231 | // Check if adding this code point causes two separate ranges to become
|
12232 | // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
|
12233 | if (codePoint + 1 == data[index + 2]) {
|
12234 | data.splice(index, 4, start, data[index + 3]);
|
12235 | return data;
|
12236 | }
|
12237 | // Else, just replace `end` with a new value.
|
12238 | data[index + 1] = codePoint + 1;
|
12239 | return data;
|
12240 | }
|
12241 | lastIndex = index;
|
12242 | index += 2;
|
12243 | }
|
12244 | // The loop has finished; add the new pair to the end of the data set.
|
12245 | data.push(codePoint, codePoint + 1);
|
12246 | return data;
|
12247 | };
|
12248 |
|
12249 | var dataAddData = function(dataA, dataB) {
|
12250 | // Iterate over the data per `(start, end)` pair.
|
12251 | var index = 0;
|
12252 | var start;
|
12253 | var end;
|
12254 | var data = dataA.slice();
|
12255 | var length = dataB.length;
|
12256 | while (index < length) {
|
12257 | start = dataB[index];
|
12258 | end = dataB[index + 1] - 1;
|
12259 | if (start == end) {
|
12260 | data = dataAdd(data, start);
|
12261 | } else {
|
12262 | data = dataAddRange(data, start, end);
|
12263 | }
|
12264 | index += 2;
|
12265 | }
|
12266 | return data;
|
12267 | };
|
12268 |
|
12269 | var dataRemoveData = function(dataA, dataB) {
|
12270 | // Iterate over the data per `(start, end)` pair.
|
12271 | var index = 0;
|
12272 | var start;
|
12273 | var end;
|
12274 | var data = dataA.slice();
|
12275 | var length = dataB.length;
|
12276 | while (index < length) {
|
12277 | start = dataB[index];
|
12278 | end = dataB[index + 1] - 1;
|
12279 | if (start == end) {
|
12280 | data = dataRemove(data, start);
|
12281 | } else {
|
12282 | data = dataRemoveRange(data, start, end);
|
12283 | }
|
12284 | index += 2;
|
12285 | }
|
12286 | return data;
|
12287 | };
|
12288 |
|
12289 | var dataAddRange = function(data, rangeStart, rangeEnd) {
|
12290 | if (rangeEnd < rangeStart) {
|
12291 | throw Error(ERRORS.rangeOrder);
|
12292 | }
|
12293 | if (
|
12294 | rangeStart < 0x0 || rangeStart > 0x10FFFF ||
|
12295 | rangeEnd < 0x0 || rangeEnd > 0x10FFFF
|
12296 | ) {
|
12297 | throw RangeError(ERRORS.codePointRange);
|
12298 | }
|
12299 | // Iterate over the data per `(start, end)` pair.
|
12300 | var index = 0;
|
12301 | var start;
|
12302 | var end;
|
12303 | var added = false;
|
12304 | var length = data.length;
|
12305 | while (index < length) {
|
12306 | start = data[index];
|
12307 | end = data[index + 1];
|
12308 |
|
12309 | if (added) {
|
12310 | // The range has already been added to the set; at this point, we just
|
12311 | // need to get rid of the following ranges in case they overlap.
|
12312 |
|
12313 | // Check if this range can be combined with the previous range.
|
12314 | if (start == rangeEnd + 1) {
|
12315 | data.splice(index - 1, 2);
|
12316 | return data;
|
12317 | }
|
12318 |
|
12319 | // Exit as soon as no more possibly overlapping pairs can be found.
|
12320 | if (start > rangeEnd) {
|
12321 | return data;
|
12322 | }
|
12323 |
|
12324 | // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
|
12325 | // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
|
12326 | // `0,16` range that was previously added.
|
12327 | if (start >= rangeStart && start <= rangeEnd) {
|
12328 | // `start` lies within the range that was previously added.
|
12329 |
|
12330 | if (end > rangeStart && end - 1 <= rangeEnd) {
|
12331 | // `end` lies within the range that was previously added as well,
|
12332 | // so remove this pair.
|
12333 | data.splice(index, 2);
|
12334 | index -= 2;
|
12335 | // Note: we cannot `return` just yet, as there may still be other
|
12336 | // overlapping pairs.
|
12337 | } else {
|
12338 | // `start` lies within the range that was previously added, but
|
12339 | // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
|
12340 | // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
|
12341 | // Remove the previously added `end` and the current `start`.
|
12342 | data.splice(index - 1, 2);
|
12343 | index -= 2;
|
12344 | }
|
12345 |
|
12346 | // Note: we cannot return yet.
|
12347 | }
|
12348 |
|
12349 | }
|
12350 |
|
12351 | else if (start == rangeEnd + 1) {
|
12352 | data[index] = rangeStart;
|
12353 | return data;
|
12354 | }
|
12355 |
|
12356 | // Check if a new pair must be inserted *before* the current one.
|
12357 | else if (start > rangeEnd) {
|
12358 | data.splice(index, 0, rangeStart, rangeEnd + 1);
|
12359 | return data;
|
12360 | }
|
12361 |
|
12362 | else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
|
12363 | // The new range lies entirely within an existing range pair. No action
|
12364 | // needed.
|
12365 | return data;
|
12366 | }
|
12367 |
|
12368 | else if (
|
12369 | // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
|
12370 | (rangeStart >= start && rangeStart < end) ||
|
12371 | // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
|
12372 | end == rangeStart
|
12373 | ) {
|
12374 | // Replace `end` with the new value.
|
12375 | data[index + 1] = rangeEnd + 1;
|
12376 | // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
|
12377 | // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
|
12378 | added = true;
|
12379 | // Note: we cannot `return` just yet.
|
12380 | }
|
12381 |
|
12382 | else if (rangeStart <= start && rangeEnd + 1 >= end) {
|
12383 | // The new range is a superset of the old range.
|
12384 | data[index] = rangeStart;
|
12385 | data[index + 1] = rangeEnd + 1;
|
12386 | added = true;
|
12387 | }
|
12388 |
|
12389 | index += 2;
|
12390 | }
|
12391 | // The loop has finished without doing anything; add the new pair to the end
|
12392 | // of the data set.
|
12393 | if (!added) {
|
12394 | data.push(rangeStart, rangeEnd + 1);
|
12395 | }
|
12396 | return data;
|
12397 | };
|
12398 |
|
12399 | var dataContains = function(data, codePoint) {
|
12400 | var index = 0;
|
12401 | var length = data.length;
|
12402 | // Exit early if `codePoint` is not within `data`’s overall range.
|
12403 | var start = data[index];
|
12404 | var end = data[length - 1];
|
12405 | if (length >= 2) {
|
12406 | if (codePoint < start || codePoint > end) {
|
12407 | return false;
|
12408 | }
|
12409 | }
|
12410 | // Iterate over the data per `(start, end)` pair.
|
12411 | while (index < length) {
|
12412 | start = data[index];
|
12413 | end = data[index + 1];
|
12414 | if (codePoint >= start && codePoint < end) {
|
12415 | return true;
|
12416 | }
|
12417 | index += 2;
|
12418 | }
|
12419 | return false;
|
12420 | };
|
12421 |
|
12422 | var dataIntersection = function(data, codePoints) {
|
12423 | var index = 0;
|
12424 | var length = codePoints.length;
|
12425 | var codePoint;
|
12426 | var result = [];
|
12427 | while (index < length) {
|
12428 | codePoint = codePoints[index];
|
12429 | if (dataContains(data, codePoint)) {
|
12430 | result.push(codePoint);
|
12431 | }
|
12432 | ++index;
|
12433 | }
|
12434 | return dataFromCodePoints(result);
|
12435 | };
|
12436 |
|
12437 | var dataIsEmpty = function(data) {
|
12438 | return !data.length;
|
12439 | };
|
12440 |
|
12441 | var dataIsSingleton = function(data) {
|
12442 | // Check if the set only represents a single code point.
|
12443 | return data.length == 2 && data[0] + 1 == data[1];
|
12444 | };
|
12445 |
|
12446 | var dataToArray = function(data) {
|
12447 | // Iterate over the data per `(start, end)` pair.
|
12448 | var index = 0;
|
12449 | var start;
|
12450 | var end;
|
12451 | var result = [];
|
12452 | var length = data.length;
|
12453 | while (index < length) {
|
12454 | start = data[index];
|
12455 | end = data[index + 1];
|
12456 | while (start < end) {
|
12457 | result.push(start);
|
12458 | ++start;
|
12459 | }
|
12460 | index += 2;
|
12461 | }
|
12462 | return result;
|
12463 | };
|
12464 |
|
12465 | /*--------------------------------------------------------------------------*/
|
12466 |
|
12467 | // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
12468 | var floor = Math.floor;
|
12469 | var highSurrogate = function(codePoint) {
|
12470 | return parseInt(
|
12471 | floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
|
12472 | 10
|
12473 | );
|
12474 | };
|
12475 |
|
12476 | var lowSurrogate = function(codePoint) {
|
12477 | return parseInt(
|
12478 | (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
|
12479 | 10
|
12480 | );
|
12481 | };
|
12482 |
|
12483 | var stringFromCharCode = String.fromCharCode;
|
12484 | var codePointToString = function(codePoint) {
|
12485 | var string;
|
12486 | // https://mathiasbynens.be/notes/javascript-escapes#single
|
12487 | // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
|
12488 | // different meaning in regular expressions (word boundary), so it cannot
|
12489 | // be used here.
|
12490 | if (codePoint == 0x09) {
|
12491 | string = '\\t';
|
12492 | }
|
12493 | // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
|
12494 | // else if (codePoint == 0x0B) {
|
12495 | // string = '\\v';
|
12496 | // }
|
12497 | else if (codePoint == 0x0A) {
|
12498 | string = '\\n';
|
12499 | }
|
12500 | else if (codePoint == 0x0C) {
|
12501 | string = '\\f';
|
12502 | }
|
12503 | else if (codePoint == 0x0D) {
|
12504 | string = '\\r';
|
12505 | }
|
12506 | else if (codePoint == 0x2D) {
|
12507 | // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
|
12508 | // Note: `-` (U+002D HYPHEN-MINUS) is escaped in this way rather
|
12509 | // than by backslash-escaping, in case the output is used outside
|
12510 | // of a character class in a `u` RegExp. /\-/u throws, but
|
12511 | // /\x2D/u is fine.
|
12512 | string = '\\x2D';
|
12513 | }
|
12514 | else if (codePoint == 0x5C) {
|
12515 | string = '\\\\';
|
12516 | }
|
12517 | else if (
|
12518 | codePoint == 0x24 ||
|
12519 | (codePoint >= 0x28 && codePoint <= 0x2B) ||
|
12520 | codePoint == 0x2E || codePoint == 0x2F ||
|
12521 | codePoint == 0x3F ||
|
12522 | (codePoint >= 0x5B && codePoint <= 0x5E) ||
|
12523 | (codePoint >= 0x7B && codePoint <= 0x7D)
|
12524 | ) {
|
12525 | // The code point maps to an unsafe printable ASCII character;
|
12526 | // backslash-escape it. Here’s the list of those symbols:
|
12527 | //
|
12528 | // $()*+./?[\]^{|}
|
12529 | //
|
12530 | // This matches SyntaxCharacters as well as `/` (U+002F SOLIDUS).
|
12531 | // https://tc39.github.io/ecma262/#prod-SyntaxCharacter
|
12532 | string = '\\' + stringFromCharCode(codePoint);
|
12533 | }
|
12534 | else if (codePoint >= 0x20 && codePoint <= 0x7E) {
|
12535 | // The code point maps to one of these printable ASCII symbols
|
12536 | // (including the space character):
|
12537 | //
|
12538 | // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
|
12539 | // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
|
12540 | //
|
12541 | // These can safely be used directly.
|
12542 | string = stringFromCharCode(codePoint);
|
12543 | }
|
12544 | else if (codePoint <= 0xFF) {
|
12545 | string = '\\x' + pad(hex(codePoint), 2);
|
12546 | }
|
12547 | else { // `codePoint <= 0xFFFF` holds true.
|
12548 | // https://mathiasbynens.be/notes/javascript-escapes#unicode
|
12549 | string = '\\u' + pad(hex(codePoint), 4);
|
12550 | }
|
12551 |
|
12552 | // There’s no need to account for astral symbols / surrogate pairs here,
|
12553 | // since `codePointToString` is private and only used for BMP code points.
|
12554 | // But if that’s what you need, just add an `else` block with this code:
|
12555 | //
|
12556 | // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
|
12557 | // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
|
12558 |
|
12559 | return string;
|
12560 | };
|
12561 |
|
12562 | var codePointToStringUnicode = function(codePoint) {
|
12563 | if (codePoint <= 0xFFFF) {
|
12564 | return codePointToString(codePoint);
|
12565 | }
|
12566 | return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
|
12567 | };
|
12568 |
|
12569 | var symbolToCodePoint = function(symbol) {
|
12570 | var length = symbol.length;
|
12571 | var first = symbol.charCodeAt(0);
|
12572 | var second;
|
12573 | if (
|
12574 | first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
|
12575 | length > 1 // There is a next code unit.
|
12576 | ) {
|
12577 | // `first` is a high surrogate, and there is a next character. Assume
|
12578 | // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
|
12579 | second = symbol.charCodeAt(1);
|
12580 | // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
12581 | return (first - HIGH_SURROGATE_MIN) * 0x400 +
|
12582 | second - LOW_SURROGATE_MIN + 0x10000;
|
12583 | }
|
12584 | return first;
|
12585 | };
|
12586 |
|
12587 | var createBMPCharacterClasses = function(data) {
|
12588 | // Iterate over the data per `(start, end)` pair.
|
12589 | var result = '';
|
12590 | var index = 0;
|
12591 | var start;
|
12592 | var end;
|
12593 | var length = data.length;
|
12594 | if (dataIsSingleton(data)) {
|
12595 | return codePointToString(data[0]);
|
12596 | }
|
12597 | while (index < length) {
|
12598 | start = data[index];
|
12599 | end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
|
12600 | if (start == end) {
|
12601 | result += codePointToString(start);
|
12602 | } else if (start + 1 == end) {
|
12603 | result += codePointToString(start) + codePointToString(end);
|
12604 | } else {
|
12605 | result += codePointToString(start) + '-' + codePointToString(end);
|
12606 | }
|
12607 | index += 2;
|
12608 | }
|
12609 | return '[' + result + ']';
|
12610 | };
|
12611 |
|
12612 | var createUnicodeCharacterClasses = function(data) {
|
12613 | // Iterate over the data per `(start, end)` pair.
|
12614 | var result = '';
|
12615 | var index = 0;
|
12616 | var start;
|
12617 | var end;
|
12618 | var length = data.length;
|
12619 | if (dataIsSingleton(data)) {
|
12620 | return codePointToStringUnicode(data[0]);
|
12621 | }
|
12622 | while (index < length) {
|
12623 | start = data[index];
|
12624 | end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
|
12625 | if (start == end) {
|
12626 | result += codePointToStringUnicode(start);
|
12627 | } else if (start + 1 == end) {
|
12628 | result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
|
12629 | } else {
|
12630 | result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
|
12631 | }
|
12632 | index += 2;
|
12633 | }
|
12634 | return '[' + result + ']';
|
12635 | };
|
12636 |
|
12637 | var splitAtBMP = function(data) {
|
12638 | // Iterate over the data per `(start, end)` pair.
|
12639 | var loneHighSurrogates = [];
|
12640 | var loneLowSurrogates = [];
|
12641 | var bmp = [];
|
12642 | var astral = [];
|
12643 | var index = 0;
|
12644 | var start;
|
12645 | var end;
|
12646 | var length = data.length;
|
12647 | while (index < length) {
|
12648 | start = data[index];
|
12649 | end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
|
12650 |
|
12651 | if (start < HIGH_SURROGATE_MIN) {
|
12652 |
|
12653 | // The range starts and ends before the high surrogate range.
|
12654 | // E.g. (0, 0x10).
|
12655 | if (end < HIGH_SURROGATE_MIN) {
|
12656 | bmp.push(start, end + 1);
|
12657 | }
|
12658 |
|
12659 | // The range starts before the high surrogate range and ends within it.
|
12660 | // E.g. (0, 0xD855).
|
12661 | if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
|
12662 | bmp.push(start, HIGH_SURROGATE_MIN);
|
12663 | loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
|
12664 | }
|
12665 |
|
12666 | // The range starts before the high surrogate range and ends in the low
|
12667 | // surrogate range. E.g. (0, 0xDCFF).
|
12668 | if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
|
12669 | bmp.push(start, HIGH_SURROGATE_MIN);
|
12670 | loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
|
12671 | loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
|
12672 | }
|
12673 |
|
12674 | // The range starts before the high surrogate range and ends after the
|
12675 | // low surrogate range. E.g. (0, 0x10FFFF).
|
12676 | if (end > LOW_SURROGATE_MAX) {
|
12677 | bmp.push(start, HIGH_SURROGATE_MIN);
|
12678 | loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
|
12679 | loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
|
12680 | if (end <= 0xFFFF) {
|
12681 | bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
|
12682 | } else {
|
12683 | bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
|
12684 | astral.push(0xFFFF + 1, end + 1);
|
12685 | }
|
12686 | }
|
12687 |
|
12688 | } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
|
12689 |
|
12690 | // The range starts and ends in the high surrogate range.
|
12691 | // E.g. (0xD855, 0xD866).
|
12692 | if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
|
12693 | loneHighSurrogates.push(start, end + 1);
|
12694 | }
|
12695 |
|
12696 | // The range starts in the high surrogate range and ends in the low
|
12697 | // surrogate range. E.g. (0xD855, 0xDCFF).
|
12698 | if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
|
12699 | loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
|
12700 | loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
|
12701 | }
|
12702 |
|
12703 | // The range starts in the high surrogate range and ends after the low
|
12704 | // surrogate range. E.g. (0xD855, 0x10FFFF).
|
12705 | if (end > LOW_SURROGATE_MAX) {
|
12706 | loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
|
12707 | loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
|
12708 | if (end <= 0xFFFF) {
|
12709 | bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
|
12710 | } else {
|
12711 | bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
|
12712 | astral.push(0xFFFF + 1, end + 1);
|
12713 | }
|
12714 | }
|
12715 |
|
12716 | } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
|
12717 |
|
12718 | // The range starts and ends in the low surrogate range.
|
12719 | // E.g. (0xDCFF, 0xDDFF).
|
12720 | if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
|
12721 | loneLowSurrogates.push(start, end + 1);
|
12722 | }
|
12723 |
|
12724 | // The range starts in the low surrogate range and ends after the low
|
12725 | // surrogate range. E.g. (0xDCFF, 0x10FFFF).
|
12726 | if (end > LOW_SURROGATE_MAX) {
|
12727 | loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
|
12728 | if (end <= 0xFFFF) {
|
12729 | bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
|
12730 | } else {
|
12731 | bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
|
12732 | astral.push(0xFFFF + 1, end + 1);
|
12733 | }
|
12734 | }
|
12735 |
|
12736 | } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
|
12737 |
|
12738 | // The range starts and ends after the low surrogate range.
|
12739 | // E.g. (0xFFAA, 0x10FFFF).
|
12740 | if (end <= 0xFFFF) {
|
12741 | bmp.push(start, end + 1);
|
12742 | } else {
|
12743 | bmp.push(start, 0xFFFF + 1);
|
12744 | astral.push(0xFFFF + 1, end + 1);
|
12745 | }
|
12746 |
|
12747 | } else {
|
12748 |
|
12749 | // The range starts and ends in the astral range.
|
12750 | astral.push(start, end + 1);
|
12751 |
|
12752 | }
|
12753 |
|
12754 | index += 2;
|
12755 | }
|
12756 | return {
|
12757 | 'loneHighSurrogates': loneHighSurrogates,
|
12758 | 'loneLowSurrogates': loneLowSurrogates,
|
12759 | 'bmp': bmp,
|
12760 | 'astral': astral
|
12761 | };
|
12762 | };
|
12763 |
|
12764 | var optimizeSurrogateMappings = function(surrogateMappings) {
|
12765 | var result = [];
|
12766 | var tmpLow = [];
|
12767 | var addLow = false;
|
12768 | var mapping;
|
12769 | var nextMapping;
|
12770 | var highSurrogates;
|
12771 | var lowSurrogates;
|
12772 | var nextHighSurrogates;
|
12773 | var nextLowSurrogates;
|
12774 | var index = -1;
|
12775 | var length = surrogateMappings.length;
|
12776 | while (++index < length) {
|
12777 | mapping = surrogateMappings[index];
|
12778 | nextMapping = surrogateMappings[index + 1];
|
12779 | if (!nextMapping) {
|
12780 | result.push(mapping);
|
12781 | continue;
|
12782 | }
|
12783 | highSurrogates = mapping[0];
|
12784 | lowSurrogates = mapping[1];
|
12785 | nextHighSurrogates = nextMapping[0];
|
12786 | nextLowSurrogates = nextMapping[1];
|
12787 |
|
12788 | // Check for identical high surrogate ranges.
|
12789 | tmpLow = lowSurrogates;
|
12790 | while (
|
12791 | nextHighSurrogates &&
|
12792 | highSurrogates[0] == nextHighSurrogates[0] &&
|
12793 | highSurrogates[1] == nextHighSurrogates[1]
|
12794 | ) {
|
12795 | // Merge with the next item.
|
12796 | if (dataIsSingleton(nextLowSurrogates)) {
|
12797 | tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
|
12798 | } else {
|
12799 | tmpLow = dataAddRange(
|
12800 | tmpLow,
|
12801 | nextLowSurrogates[0],
|
12802 | nextLowSurrogates[1] - 1
|
12803 | );
|
12804 | }
|
12805 | ++index;
|
12806 | mapping = surrogateMappings[index];
|
12807 | highSurrogates = mapping[0];
|
12808 | lowSurrogates = mapping[1];
|
12809 | nextMapping = surrogateMappings[index + 1];
|
12810 | nextHighSurrogates = nextMapping && nextMapping[0];
|
12811 | nextLowSurrogates = nextMapping && nextMapping[1];
|
12812 | addLow = true;
|
12813 | }
|
12814 | result.push([
|
12815 | highSurrogates,
|
12816 | addLow ? tmpLow : lowSurrogates
|
12817 | ]);
|
12818 | addLow = false;
|
12819 | }
|
12820 | return optimizeByLowSurrogates(result);
|
12821 | };
|
12822 |
|
12823 | var optimizeByLowSurrogates = function(surrogateMappings) {
|
12824 | if (surrogateMappings.length == 1) {
|
12825 | return surrogateMappings;
|
12826 | }
|
12827 | var index = -1;
|
12828 | var innerIndex = -1;
|
12829 | while (++index < surrogateMappings.length) {
|
12830 | var mapping = surrogateMappings[index];
|
12831 | var lowSurrogates = mapping[1];
|
12832 | var lowSurrogateStart = lowSurrogates[0];
|
12833 | var lowSurrogateEnd = lowSurrogates[1];
|
12834 | innerIndex = index; // Note: the loop starts at the next index.
|
12835 | while (++innerIndex < surrogateMappings.length) {
|
12836 | var otherMapping = surrogateMappings[innerIndex];
|
12837 | var otherLowSurrogates = otherMapping[1];
|
12838 | var otherLowSurrogateStart = otherLowSurrogates[0];
|
12839 | var otherLowSurrogateEnd = otherLowSurrogates[1];
|
12840 | if (
|
12841 | lowSurrogateStart == otherLowSurrogateStart &&
|
12842 | lowSurrogateEnd == otherLowSurrogateEnd
|
12843 | ) {
|
12844 | // Add the code points in the other item to this one.
|
12845 | if (dataIsSingleton(otherMapping[0])) {
|
12846 | mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
|
12847 | } else {
|
12848 | mapping[0] = dataAddRange(
|
12849 | mapping[0],
|
12850 | otherMapping[0][0],
|
12851 | otherMapping[0][1] - 1
|
12852 | );
|
12853 | }
|
12854 | // Remove the other, now redundant, item.
|
12855 | surrogateMappings.splice(innerIndex, 1);
|
12856 | --innerIndex;
|
12857 | }
|
12858 | }
|
12859 | }
|
12860 | return surrogateMappings;
|
12861 | };
|
12862 |
|
12863 | var surrogateSet = function(data) {
|
12864 | // Exit early if `data` is an empty set.
|
12865 | if (!data.length) {
|
12866 | return [];
|
12867 | }
|
12868 |
|
12869 | // Iterate over the data per `(start, end)` pair.
|
12870 | var index = 0;
|
12871 | var start;
|
12872 | var end;
|
12873 | var startHigh;
|
12874 | var startLow;
|
12875 | var endHigh;
|
12876 | var endLow;
|
12877 | var surrogateMappings = [];
|
12878 | var length = data.length;
|
12879 | while (index < length) {
|
12880 | start = data[index];
|
12881 | end = data[index + 1] - 1;
|
12882 |
|
12883 | startHigh = highSurrogate(start);
|
12884 | startLow = lowSurrogate(start);
|
12885 | endHigh = highSurrogate(end);
|
12886 | endLow = lowSurrogate(end);
|
12887 |
|
12888 | var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
|
12889 | var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
|
12890 | var complete = false;
|
12891 |
|
12892 | // Append the previous high-surrogate-to-low-surrogate mappings.
|
12893 | // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
|
12894 | if (
|
12895 | startHigh == endHigh ||
|
12896 | startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
|
12897 | ) {
|
12898 | surrogateMappings.push([
|
12899 | [startHigh, endHigh + 1],
|
12900 | [startLow, endLow + 1]
|
12901 | ]);
|
12902 | complete = true;
|
12903 | } else {
|
12904 | surrogateMappings.push([
|
12905 | [startHigh, startHigh + 1],
|
12906 | [startLow, LOW_SURROGATE_MAX + 1]
|
12907 | ]);
|
12908 | }
|
12909 |
|
12910 | // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
|
12911 | // `(endHigh - 1, LOW_SURROGATE_MAX)`.
|
12912 | if (!complete && startHigh + 1 < endHigh) {
|
12913 | if (endsWithHighestLowSurrogate) {
|
12914 | // Combine step 2 and step 3.
|
12915 | surrogateMappings.push([
|
12916 | [startHigh + 1, endHigh + 1],
|
12917 | [LOW_SURROGATE_MIN, endLow + 1]
|
12918 | ]);
|
12919 | complete = true;
|
12920 | } else {
|
12921 | surrogateMappings.push([
|
12922 | [startHigh + 1, endHigh],
|
12923 | [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
|
12924 | ]);
|
12925 | }
|
12926 | }
|
12927 |
|
12928 | // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
|
12929 | if (!complete) {
|
12930 | surrogateMappings.push([
|
12931 | [endHigh, endHigh + 1],
|
12932 | [LOW_SURROGATE_MIN, endLow + 1]
|
12933 | ]);
|
12934 | }
|
12935 |
|
12936 | index += 2;
|
12937 | }
|
12938 |
|
12939 | // The format of `surrogateMappings` is as follows:
|
12940 | //
|
12941 | // [ surrogateMapping1, surrogateMapping2 ]
|
12942 | //
|
12943 | // i.e.:
|
12944 | //
|
12945 | // [
|
12946 | // [ highSurrogates1, lowSurrogates1 ],
|
12947 | // [ highSurrogates2, lowSurrogates2 ]
|
12948 | // ]
|
12949 | return optimizeSurrogateMappings(surrogateMappings);
|
12950 | };
|
12951 |
|
12952 | var createSurrogateCharacterClasses = function(surrogateMappings) {
|
12953 | var result = [];
|
12954 | forEach(surrogateMappings, function(surrogateMapping) {
|
12955 | var highSurrogates = surrogateMapping[0];
|
12956 | var lowSurrogates = surrogateMapping[1];
|
12957 | result.push(
|
12958 | createBMPCharacterClasses(highSurrogates) +
|
12959 | createBMPCharacterClasses(lowSurrogates)
|
12960 | );
|
12961 | });
|
12962 | return result.join('|');
|
12963 | };
|
12964 |
|
12965 | var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
|
12966 | if (hasUnicodeFlag) {
|
12967 | return createUnicodeCharacterClasses(data);
|
12968 | }
|
12969 | var result = [];
|
12970 |
|
12971 | var parts = splitAtBMP(data);
|
12972 | var loneHighSurrogates = parts.loneHighSurrogates;
|
12973 | var loneLowSurrogates = parts.loneLowSurrogates;
|
12974 | var bmp = parts.bmp;
|
12975 | var astral = parts.astral;
|
12976 | var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
|
12977 | var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
|
12978 |
|
12979 | var surrogateMappings = surrogateSet(astral);
|
12980 |
|
12981 | if (bmpOnly) {
|
12982 | bmp = dataAddData(bmp, loneHighSurrogates);
|
12983 | hasLoneHighSurrogates = false;
|
12984 | bmp = dataAddData(bmp, loneLowSurrogates);
|
12985 | hasLoneLowSurrogates = false;
|
12986 | }
|
12987 |
|
12988 | if (!dataIsEmpty(bmp)) {
|
12989 | // The data set contains BMP code points that are not high surrogates
|
12990 | // needed for astral code points in the set.
|
12991 | result.push(createBMPCharacterClasses(bmp));
|
12992 | }
|
12993 | if (surrogateMappings.length) {
|
12994 | // The data set contains astral code points; append character classes
|
12995 | // based on their surrogate pairs.
|
12996 | result.push(createSurrogateCharacterClasses(surrogateMappings));
|
12997 | }
|
12998 | // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
|
12999 | if (hasLoneHighSurrogates) {
|
13000 | result.push(
|
13001 | createBMPCharacterClasses(loneHighSurrogates) +
|
13002 | // Make sure the high surrogates aren’t part of a surrogate pair.
|
13003 | '(?![\\uDC00-\\uDFFF])'
|
13004 | );
|
13005 | }
|
13006 | if (hasLoneLowSurrogates) {
|
13007 | result.push(
|
13008 | // It is not possible to accurately assert the low surrogates aren’t
|
13009 | // part of a surrogate pair, since JavaScript regular expressions do
|
13010 | // not support lookbehind.
|
13011 | '(?:[^\\uD800-\\uDBFF]|^)' +
|
13012 | createBMPCharacterClasses(loneLowSurrogates)
|
13013 | );
|
13014 | }
|
13015 | return result.join('|');
|
13016 | };
|
13017 |
|
13018 | /*--------------------------------------------------------------------------*/
|
13019 |
|
13020 | // `regenerate` can be used as a constructor (and new methods can be added to
|
13021 | // its prototype) but also as a regular function, the latter of which is the
|
13022 | // documented and most common usage. For that reason, it’s not capitalized.
|
13023 | var regenerate = function(value) {
|
13024 | if (arguments.length > 1) {
|
13025 | value = slice.call(arguments);
|
13026 | }
|
13027 | if (this instanceof regenerate) {
|
13028 | this.data = [];
|
13029 | return value ? this.add(value) : this;
|
13030 | }
|
13031 | return (new regenerate).add(value);
|
13032 | };
|
13033 |
|
13034 | regenerate.version = '1.3.3';
|
13035 |
|
13036 | var proto = regenerate.prototype;
|
13037 | extend(proto, {
|
13038 | 'add': function(value) {
|
13039 | var $this = this;
|
13040 | if (value == null) {
|
13041 | return $this;
|
13042 | }
|
13043 | if (value instanceof regenerate) {
|
13044 | // Allow passing other Regenerate instances.
|
13045 | $this.data = dataAddData($this.data, value.data);
|
13046 | return $this;
|
13047 | }
|
13048 | if (arguments.length > 1) {
|
13049 | value = slice.call(arguments);
|
13050 | }
|
13051 | if (isArray(value)) {
|
13052 | forEach(value, function(item) {
|
13053 | $this.add(item);
|
13054 | });
|
13055 | return $this;
|
13056 | }
|
13057 | $this.data = dataAdd(
|
13058 | $this.data,
|
13059 | isNumber(value) ? value : symbolToCodePoint(value)
|
13060 | );
|
13061 | return $this;
|
13062 | },
|
13063 | 'remove': function(value) {
|
13064 | var $this = this;
|
13065 | if (value == null) {
|
13066 | return $this;
|
13067 | }
|
13068 | if (value instanceof regenerate) {
|
13069 | // Allow passing other Regenerate instances.
|
13070 | $this.data = dataRemoveData($this.data, value.data);
|
13071 | return $this;
|
13072 | }
|
13073 | if (arguments.length > 1) {
|
13074 | value = slice.call(arguments);
|
13075 | }
|
13076 | if (isArray(value)) {
|
13077 | forEach(value, function(item) {
|
13078 | $this.remove(item);
|
13079 | });
|
13080 | return $this;
|
13081 | }
|
13082 | $this.data = dataRemove(
|
13083 | $this.data,
|
13084 | isNumber(value) ? value : symbolToCodePoint(value)
|
13085 | );
|
13086 | return $this;
|
13087 | },
|
13088 | 'addRange': function(start, end) {
|
13089 | var $this = this;
|
13090 | $this.data = dataAddRange($this.data,
|
13091 | isNumber(start) ? start : symbolToCodePoint(start),
|
13092 | isNumber(end) ? end : symbolToCodePoint(end)
|
13093 | );
|
13094 | return $this;
|
13095 | },
|
13096 | 'removeRange': function(start, end) {
|
13097 | var $this = this;
|
13098 | var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
|
13099 | var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
|
13100 | $this.data = dataRemoveRange(
|
13101 | $this.data,
|
13102 | startCodePoint,
|
13103 | endCodePoint
|
13104 | );
|
13105 | return $this;
|
13106 | },
|
13107 | 'intersection': function(argument) {
|
13108 | var $this = this;
|
13109 | // Allow passing other Regenerate instances.
|
13110 | // TODO: Optimize this by writing and using `dataIntersectionData()`.
|
13111 | var array = argument instanceof regenerate ?
|
13112 | dataToArray(argument.data) :
|
13113 | argument;
|
13114 | $this.data = dataIntersection($this.data, array);
|
13115 | return $this;
|
13116 | },
|
13117 | 'contains': function(codePoint) {
|
13118 | return dataContains(
|
13119 | this.data,
|
13120 | isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
|
13121 | );
|
13122 | },
|
13123 | 'clone': function() {
|
13124 | var set = new regenerate;
|
13125 | set.data = this.data.slice(0);
|
13126 | return set;
|
13127 | },
|
13128 | 'toString': function(options) {
|
13129 | var result = createCharacterClassesFromData(
|
13130 | this.data,
|
13131 | options ? options.bmpOnly : false,
|
13132 | options ? options.hasUnicodeFlag : false
|
13133 | );
|
13134 | if (!result) {
|
13135 | // For an empty set, return something that can be inserted `/here/` to
|
13136 | // form a valid regular expression. Avoid `(?:)` since that matches the
|
13137 | // empty string.
|
13138 | return '[]';
|
13139 | }
|
13140 | // Use `\0` instead of `\x00` where possible.
|
13141 | return result.replace(regexNull, '\\0$1');
|
13142 | },
|
13143 | 'toRegExp': function(flags) {
|
13144 | var pattern = this.toString(
|
13145 | flags && flags.indexOf('u') != -1 ?
|
13146 | { 'hasUnicodeFlag': true } :
|
13147 | null
|
13148 | );
|
13149 | return RegExp(pattern, flags || '');
|
13150 | },
|
13151 | 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
|
13152 | return dataToArray(this.data);
|
13153 | }
|
13154 | });
|
13155 |
|
13156 | proto.toArray = proto.valueOf;
|
13157 |
|
13158 | // Some AMD build optimizers, like r.js, check for specific condition patterns
|
13159 | // like the following:
|
13160 | if (freeExports && !freeExports.nodeType) {
|
13161 | if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
|
13162 | freeModule.exports = regenerate;
|
13163 | } else { // in Narwhal or RingoJS v0.7.0-
|
13164 | freeExports.regenerate = regenerate;
|
13165 | }
|
13166 | } else { // in Rhino or a web browser
|
13167 | root.regenerate = regenerate;
|
13168 | }
|
13169 |
|
13170 | }(commonjsGlobal));
|
13171 | });
|
13172 |
|
13173 | var unicodeCanonicalPropertyNamesEcmascript = new Set([
|
13174 | // Non-binary properties:
|
13175 | 'General_Category',
|
13176 | 'Script',
|
13177 | 'Script_Extensions',
|
13178 | // Binary properties:
|
13179 | 'Alphabetic',
|
13180 | 'Any',
|
13181 | 'ASCII',
|
13182 | 'ASCII_Hex_Digit',
|
13183 | 'Assigned',
|
13184 | 'Bidi_Control',
|
13185 | 'Bidi_Mirrored',
|
13186 | 'Case_Ignorable',
|
13187 | 'Cased',
|
13188 | 'Changes_When_Casefolded',
|
13189 | 'Changes_When_Casemapped',
|
13190 | 'Changes_When_Lowercased',
|
13191 | 'Changes_When_NFKC_Casefolded',
|
13192 | 'Changes_When_Titlecased',
|
13193 | 'Changes_When_Uppercased',
|
13194 | 'Dash',
|
13195 | 'Default_Ignorable_Code_Point',
|
13196 | 'Deprecated',
|
13197 | 'Diacritic',
|
13198 | 'Emoji',
|
13199 | 'Emoji_Component',
|
13200 | 'Emoji_Modifier',
|
13201 | 'Emoji_Modifier_Base',
|
13202 | 'Emoji_Presentation',
|
13203 | 'Extended_Pictographic',
|
13204 | 'Extender',
|
13205 | 'Grapheme_Base',
|
13206 | 'Grapheme_Extend',
|
13207 | 'Hex_Digit',
|
13208 | 'ID_Continue',
|
13209 | 'ID_Start',
|
13210 | 'Ideographic',
|
13211 | 'IDS_Binary_Operator',
|
13212 | 'IDS_Trinary_Operator',
|
13213 | 'Join_Control',
|
13214 | 'Logical_Order_Exception',
|
13215 | 'Lowercase',
|
13216 | 'Math',
|
13217 | 'Noncharacter_Code_Point',
|
13218 | 'Pattern_Syntax',
|
13219 | 'Pattern_White_Space',
|
13220 | 'Quotation_Mark',
|
13221 | 'Radical',
|
13222 | 'Regional_Indicator',
|
13223 | 'Sentence_Terminal',
|
13224 | 'Soft_Dotted',
|
13225 | 'Terminal_Punctuation',
|
13226 | 'Unified_Ideograph',
|
13227 | 'Uppercase',
|
13228 | 'Variation_Selector',
|
13229 | 'White_Space',
|
13230 | 'XID_Continue',
|
13231 | 'XID_Start'
|
13232 | ]);
|
13233 |
|
13234 | // Generated using `npm run build`. Do not edit!
|
13235 | var unicodePropertyAliasesEcmascript = new Map([
|
13236 | ['scx', 'Script_Extensions'],
|
13237 | ['sc', 'Script'],
|
13238 | ['gc', 'General_Category'],
|
13239 | ['AHex', 'ASCII_Hex_Digit'],
|
13240 | ['Alpha', 'Alphabetic'],
|
13241 | ['Bidi_C', 'Bidi_Control'],
|
13242 | ['Bidi_M', 'Bidi_Mirrored'],
|
13243 | ['Cased', 'Cased'],
|
13244 | ['CI', 'Case_Ignorable'],
|
13245 | ['CWCF', 'Changes_When_Casefolded'],
|
13246 | ['CWCM', 'Changes_When_Casemapped'],
|
13247 | ['CWKCF', 'Changes_When_NFKC_Casefolded'],
|
13248 | ['CWL', 'Changes_When_Lowercased'],
|
13249 | ['CWT', 'Changes_When_Titlecased'],
|
13250 | ['CWU', 'Changes_When_Uppercased'],
|
13251 | ['Dash', 'Dash'],
|
13252 | ['Dep', 'Deprecated'],
|
13253 | ['DI', 'Default_Ignorable_Code_Point'],
|
13254 | ['Dia', 'Diacritic'],
|
13255 | ['EBase', 'Emoji_Modifier_Base'],
|
13256 | ['EComp', 'Emoji_Component'],
|
13257 | ['EMod', 'Emoji_Modifier'],
|
13258 | ['Emoji', 'Emoji'],
|
13259 | ['EPres', 'Emoji_Presentation'],
|
13260 | ['Ext', 'Extender'],
|
13261 | ['ExtPict', 'Extended_Pictographic'],
|
13262 | ['Gr_Base', 'Grapheme_Base'],
|
13263 | ['Gr_Ext', 'Grapheme_Extend'],
|
13264 | ['Hex', 'Hex_Digit'],
|
13265 | ['IDC', 'ID_Continue'],
|
13266 | ['Ideo', 'Ideographic'],
|
13267 | ['IDS', 'ID_Start'],
|
13268 | ['IDSB', 'IDS_Binary_Operator'],
|
13269 | ['IDST', 'IDS_Trinary_Operator'],
|
13270 | ['Join_C', 'Join_Control'],
|
13271 | ['LOE', 'Logical_Order_Exception'],
|
13272 | ['Lower', 'Lowercase'],
|
13273 | ['Math', 'Math'],
|
13274 | ['NChar', 'Noncharacter_Code_Point'],
|
13275 | ['Pat_Syn', 'Pattern_Syntax'],
|
13276 | ['Pat_WS', 'Pattern_White_Space'],
|
13277 | ['QMark', 'Quotation_Mark'],
|
13278 | ['Radical', 'Radical'],
|
13279 | ['RI', 'Regional_Indicator'],
|
13280 | ['SD', 'Soft_Dotted'],
|
13281 | ['STerm', 'Sentence_Terminal'],
|
13282 | ['Term', 'Terminal_Punctuation'],
|
13283 | ['UIdeo', 'Unified_Ideograph'],
|
13284 | ['Upper', 'Uppercase'],
|
13285 | ['VS', 'Variation_Selector'],
|
13286 | ['WSpace', 'White_Space'],
|
13287 | ['space', 'White_Space'],
|
13288 | ['XIDC', 'XID_Continue'],
|
13289 | ['XIDS', 'XID_Start']
|
13290 | ]);
|
13291 |
|
13292 | var matchProperty = function(property) {
|
13293 | if (unicodeCanonicalPropertyNamesEcmascript.has(property)) {
|
13294 | return property;
|
13295 | }
|
13296 | if (unicodePropertyAliasesEcmascript.has(property)) {
|
13297 | return unicodePropertyAliasesEcmascript.get(property);
|
13298 | }
|
13299 | throw new Error(("Unknown property: " + property));
|
13300 | };
|
13301 |
|
13302 | var unicodeMatchPropertyEcmascript = matchProperty;
|
13303 |
|
13304 | var mappings = new Map([
|
13305 | ['General_Category', new Map([
|
13306 | ['C', 'Other'],
|
13307 | ['Cc', 'Control'],
|
13308 | ['cntrl', 'Control'],
|
13309 | ['Cf', 'Format'],
|
13310 | ['Cn', 'Unassigned'],
|
13311 | ['Co', 'Private_Use'],
|
13312 | ['Cs', 'Surrogate'],
|
13313 | ['L', 'Letter'],
|
13314 | ['LC', 'Cased_Letter'],
|
13315 | ['Ll', 'Lowercase_Letter'],
|
13316 | ['Lm', 'Modifier_Letter'],
|
13317 | ['Lo', 'Other_Letter'],
|
13318 | ['Lt', 'Titlecase_Letter'],
|
13319 | ['Lu', 'Uppercase_Letter'],
|
13320 | ['M', 'Mark'],
|
13321 | ['Combining_Mark', 'Mark'],
|
13322 | ['Mc', 'Spacing_Mark'],
|
13323 | ['Me', 'Enclosing_Mark'],
|
13324 | ['Mn', 'Nonspacing_Mark'],
|
13325 | ['N', 'Number'],
|
13326 | ['Nd', 'Decimal_Number'],
|
13327 | ['digit', 'Decimal_Number'],
|
13328 | ['Nl', 'Letter_Number'],
|
13329 | ['No', 'Other_Number'],
|
13330 | ['P', 'Punctuation'],
|
13331 | ['punct', 'Punctuation'],
|
13332 | ['Pc', 'Connector_Punctuation'],
|
13333 | ['Pd', 'Dash_Punctuation'],
|
13334 | ['Pe', 'Close_Punctuation'],
|
13335 | ['Pf', 'Final_Punctuation'],
|
13336 | ['Pi', 'Initial_Punctuation'],
|
13337 | ['Po', 'Other_Punctuation'],
|
13338 | ['Ps', 'Open_Punctuation'],
|
13339 | ['S', 'Symbol'],
|
13340 | ['Sc', 'Currency_Symbol'],
|
13341 | ['Sk', 'Modifier_Symbol'],
|
13342 | ['Sm', 'Math_Symbol'],
|
13343 | ['So', 'Other_Symbol'],
|
13344 | ['Z', 'Separator'],
|
13345 | ['Zl', 'Line_Separator'],
|
13346 | ['Zp', 'Paragraph_Separator'],
|
13347 | ['Zs', 'Space_Separator'],
|
13348 | ['Other', 'Other'],
|
13349 | ['Control', 'Control'],
|
13350 | ['Format', 'Format'],
|
13351 | ['Unassigned', 'Unassigned'],
|
13352 | ['Private_Use', 'Private_Use'],
|
13353 | ['Surrogate', 'Surrogate'],
|
13354 | ['Letter', 'Letter'],
|
13355 | ['Cased_Letter', 'Cased_Letter'],
|
13356 | ['Lowercase_Letter', 'Lowercase_Letter'],
|
13357 | ['Modifier_Letter', 'Modifier_Letter'],
|
13358 | ['Other_Letter', 'Other_Letter'],
|
13359 | ['Titlecase_Letter', 'Titlecase_Letter'],
|
13360 | ['Uppercase_Letter', 'Uppercase_Letter'],
|
13361 | ['Mark', 'Mark'],
|
13362 | ['Spacing_Mark', 'Spacing_Mark'],
|
13363 | ['Enclosing_Mark', 'Enclosing_Mark'],
|
13364 | ['Nonspacing_Mark', 'Nonspacing_Mark'],
|
13365 | ['Number', 'Number'],
|
13366 | ['Decimal_Number', 'Decimal_Number'],
|
13367 | ['Letter_Number', 'Letter_Number'],
|
13368 | ['Other_Number', 'Other_Number'],
|
13369 | ['Punctuation', 'Punctuation'],
|
13370 | ['Connector_Punctuation', 'Connector_Punctuation'],
|
13371 | ['Dash_Punctuation', 'Dash_Punctuation'],
|
13372 | ['Close_Punctuation', 'Close_Punctuation'],
|
13373 | ['Final_Punctuation', 'Final_Punctuation'],
|
13374 | ['Initial_Punctuation', 'Initial_Punctuation'],
|
13375 | ['Other_Punctuation', 'Other_Punctuation'],
|
13376 | ['Open_Punctuation', 'Open_Punctuation'],
|
13377 | ['Symbol', 'Symbol'],
|
13378 | ['Currency_Symbol', 'Currency_Symbol'],
|
13379 | ['Modifier_Symbol', 'Modifier_Symbol'],
|
13380 | ['Math_Symbol', 'Math_Symbol'],
|
13381 | ['Other_Symbol', 'Other_Symbol'],
|
13382 | ['Separator', 'Separator'],
|
13383 | ['Line_Separator', 'Line_Separator'],
|
13384 | ['Paragraph_Separator', 'Paragraph_Separator'],
|
13385 | ['Space_Separator', 'Space_Separator']
|
13386 | ])],
|
13387 | ['Script', new Map([
|
13388 | ['Adlm', 'Adlam'],
|
13389 | ['Aghb', 'Caucasian_Albanian'],
|
13390 | ['Ahom', 'Ahom'],
|
13391 | ['Arab', 'Arabic'],
|
13392 | ['Armi', 'Imperial_Aramaic'],
|
13393 | ['Armn', 'Armenian'],
|
13394 | ['Avst', 'Avestan'],
|
13395 | ['Bali', 'Balinese'],
|
13396 | ['Bamu', 'Bamum'],
|
13397 | ['Bass', 'Bassa_Vah'],
|
13398 | ['Batk', 'Batak'],
|
13399 | ['Beng', 'Bengali'],
|
13400 | ['Bhks', 'Bhaiksuki'],
|
13401 | ['Bopo', 'Bopomofo'],
|
13402 | ['Brah', 'Brahmi'],
|
13403 | ['Brai', 'Braille'],
|
13404 | ['Bugi', 'Buginese'],
|
13405 | ['Buhd', 'Buhid'],
|
13406 | ['Cakm', 'Chakma'],
|
13407 | ['Cans', 'Canadian_Aboriginal'],
|
13408 | ['Cari', 'Carian'],
|
13409 | ['Cham', 'Cham'],
|
13410 | ['Cher', 'Cherokee'],
|
13411 | ['Chrs', 'Chorasmian'],
|
13412 | ['Copt', 'Coptic'],
|
13413 | ['Qaac', 'Coptic'],
|
13414 | ['Cprt', 'Cypriot'],
|
13415 | ['Cyrl', 'Cyrillic'],
|
13416 | ['Deva', 'Devanagari'],
|
13417 | ['Diak', 'Dives_Akuru'],
|
13418 | ['Dogr', 'Dogra'],
|
13419 | ['Dsrt', 'Deseret'],
|
13420 | ['Dupl', 'Duployan'],
|
13421 | ['Egyp', 'Egyptian_Hieroglyphs'],
|
13422 | ['Elba', 'Elbasan'],
|
13423 | ['Elym', 'Elymaic'],
|
13424 | ['Ethi', 'Ethiopic'],
|
13425 | ['Geor', 'Georgian'],
|
13426 | ['Glag', 'Glagolitic'],
|
13427 | ['Gong', 'Gunjala_Gondi'],
|
13428 | ['Gonm', 'Masaram_Gondi'],
|
13429 | ['Goth', 'Gothic'],
|
13430 | ['Gran', 'Grantha'],
|
13431 | ['Grek', 'Greek'],
|
13432 | ['Gujr', 'Gujarati'],
|
13433 | ['Guru', 'Gurmukhi'],
|
13434 | ['Hang', 'Hangul'],
|
13435 | ['Hani', 'Han'],
|
13436 | ['Hano', 'Hanunoo'],
|
13437 | ['Hatr', 'Hatran'],
|
13438 | ['Hebr', 'Hebrew'],
|
13439 | ['Hira', 'Hiragana'],
|
13440 | ['Hluw', 'Anatolian_Hieroglyphs'],
|
13441 | ['Hmng', 'Pahawh_Hmong'],
|
13442 | ['Hmnp', 'Nyiakeng_Puachue_Hmong'],
|
13443 | ['Hrkt', 'Katakana_Or_Hiragana'],
|
13444 | ['Hung', 'Old_Hungarian'],
|
13445 | ['Ital', 'Old_Italic'],
|
13446 | ['Java', 'Javanese'],
|
13447 | ['Kali', 'Kayah_Li'],
|
13448 | ['Kana', 'Katakana'],
|
13449 | ['Khar', 'Kharoshthi'],
|
13450 | ['Khmr', 'Khmer'],
|
13451 | ['Khoj', 'Khojki'],
|
13452 | ['Kits', 'Khitan_Small_Script'],
|
13453 | ['Knda', 'Kannada'],
|
13454 | ['Kthi', 'Kaithi'],
|
13455 | ['Lana', 'Tai_Tham'],
|
13456 | ['Laoo', 'Lao'],
|
13457 | ['Latn', 'Latin'],
|
13458 | ['Lepc', 'Lepcha'],
|
13459 | ['Limb', 'Limbu'],
|
13460 | ['Lina', 'Linear_A'],
|
13461 | ['Linb', 'Linear_B'],
|
13462 | ['Lisu', 'Lisu'],
|
13463 | ['Lyci', 'Lycian'],
|
13464 | ['Lydi', 'Lydian'],
|
13465 | ['Mahj', 'Mahajani'],
|
13466 | ['Maka', 'Makasar'],
|
13467 | ['Mand', 'Mandaic'],
|
13468 | ['Mani', 'Manichaean'],
|
13469 | ['Marc', 'Marchen'],
|
13470 | ['Medf', 'Medefaidrin'],
|
13471 | ['Mend', 'Mende_Kikakui'],
|
13472 | ['Merc', 'Meroitic_Cursive'],
|
13473 | ['Mero', 'Meroitic_Hieroglyphs'],
|
13474 | ['Mlym', 'Malayalam'],
|
13475 | ['Modi', 'Modi'],
|
13476 | ['Mong', 'Mongolian'],
|
13477 | ['Mroo', 'Mro'],
|
13478 | ['Mtei', 'Meetei_Mayek'],
|
13479 | ['Mult', 'Multani'],
|
13480 | ['Mymr', 'Myanmar'],
|
13481 | ['Nand', 'Nandinagari'],
|
13482 | ['Narb', 'Old_North_Arabian'],
|
13483 | ['Nbat', 'Nabataean'],
|
13484 | ['Newa', 'Newa'],
|
13485 | ['Nkoo', 'Nko'],
|
13486 | ['Nshu', 'Nushu'],
|
13487 | ['Ogam', 'Ogham'],
|
13488 | ['Olck', 'Ol_Chiki'],
|
13489 | ['Orkh', 'Old_Turkic'],
|
13490 | ['Orya', 'Oriya'],
|
13491 | ['Osge', 'Osage'],
|
13492 | ['Osma', 'Osmanya'],
|
13493 | ['Palm', 'Palmyrene'],
|
13494 | ['Pauc', 'Pau_Cin_Hau'],
|
13495 | ['Perm', 'Old_Permic'],
|
13496 | ['Phag', 'Phags_Pa'],
|
13497 | ['Phli', 'Inscriptional_Pahlavi'],
|
13498 | ['Phlp', 'Psalter_Pahlavi'],
|
13499 | ['Phnx', 'Phoenician'],
|
13500 | ['Plrd', 'Miao'],
|
13501 | ['Prti', 'Inscriptional_Parthian'],
|
13502 | ['Rjng', 'Rejang'],
|
13503 | ['Rohg', 'Hanifi_Rohingya'],
|
13504 | ['Runr', 'Runic'],
|
13505 | ['Samr', 'Samaritan'],
|
13506 | ['Sarb', 'Old_South_Arabian'],
|
13507 | ['Saur', 'Saurashtra'],
|
13508 | ['Sgnw', 'SignWriting'],
|
13509 | ['Shaw', 'Shavian'],
|
13510 | ['Shrd', 'Sharada'],
|
13511 | ['Sidd', 'Siddham'],
|
13512 | ['Sind', 'Khudawadi'],
|
13513 | ['Sinh', 'Sinhala'],
|
13514 | ['Sogd', 'Sogdian'],
|
13515 | ['Sogo', 'Old_Sogdian'],
|
13516 | ['Sora', 'Sora_Sompeng'],
|
13517 | ['Soyo', 'Soyombo'],
|
13518 | ['Sund', 'Sundanese'],
|
13519 | ['Sylo', 'Syloti_Nagri'],
|
13520 | ['Syrc', 'Syriac'],
|
13521 | ['Tagb', 'Tagbanwa'],
|
13522 | ['Takr', 'Takri'],
|
13523 | ['Tale', 'Tai_Le'],
|
13524 | ['Talu', 'New_Tai_Lue'],
|
13525 | ['Taml', 'Tamil'],
|
13526 | ['Tang', 'Tangut'],
|
13527 | ['Tavt', 'Tai_Viet'],
|
13528 | ['Telu', 'Telugu'],
|
13529 | ['Tfng', 'Tifinagh'],
|
13530 | ['Tglg', 'Tagalog'],
|
13531 | ['Thaa', 'Thaana'],
|
13532 | ['Thai', 'Thai'],
|
13533 | ['Tibt', 'Tibetan'],
|
13534 | ['Tirh', 'Tirhuta'],
|
13535 | ['Ugar', 'Ugaritic'],
|
13536 | ['Vaii', 'Vai'],
|
13537 | ['Wara', 'Warang_Citi'],
|
13538 | ['Wcho', 'Wancho'],
|
13539 | ['Xpeo', 'Old_Persian'],
|
13540 | ['Xsux', 'Cuneiform'],
|
13541 | ['Yezi', 'Yezidi'],
|
13542 | ['Yiii', 'Yi'],
|
13543 | ['Zanb', 'Zanabazar_Square'],
|
13544 | ['Zinh', 'Inherited'],
|
13545 | ['Qaai', 'Inherited'],
|
13546 | ['Zyyy', 'Common'],
|
13547 | ['Zzzz', 'Unknown'],
|
13548 | ['Adlam', 'Adlam'],
|
13549 | ['Caucasian_Albanian', 'Caucasian_Albanian'],
|
13550 | ['Arabic', 'Arabic'],
|
13551 | ['Imperial_Aramaic', 'Imperial_Aramaic'],
|
13552 | ['Armenian', 'Armenian'],
|
13553 | ['Avestan', 'Avestan'],
|
13554 | ['Balinese', 'Balinese'],
|
13555 | ['Bamum', 'Bamum'],
|
13556 | ['Bassa_Vah', 'Bassa_Vah'],
|
13557 | ['Batak', 'Batak'],
|
13558 | ['Bengali', 'Bengali'],
|
13559 | ['Bhaiksuki', 'Bhaiksuki'],
|
13560 | ['Bopomofo', 'Bopomofo'],
|
13561 | ['Brahmi', 'Brahmi'],
|
13562 | ['Braille', 'Braille'],
|
13563 | ['Buginese', 'Buginese'],
|
13564 | ['Buhid', 'Buhid'],
|
13565 | ['Chakma', 'Chakma'],
|
13566 | ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
|
13567 | ['Carian', 'Carian'],
|
13568 | ['Cherokee', 'Cherokee'],
|
13569 | ['Chorasmian', 'Chorasmian'],
|
13570 | ['Coptic', 'Coptic'],
|
13571 | ['Cypriot', 'Cypriot'],
|
13572 | ['Cyrillic', 'Cyrillic'],
|
13573 | ['Devanagari', 'Devanagari'],
|
13574 | ['Dives_Akuru', 'Dives_Akuru'],
|
13575 | ['Dogra', 'Dogra'],
|
13576 | ['Deseret', 'Deseret'],
|
13577 | ['Duployan', 'Duployan'],
|
13578 | ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
|
13579 | ['Elbasan', 'Elbasan'],
|
13580 | ['Elymaic', 'Elymaic'],
|
13581 | ['Ethiopic', 'Ethiopic'],
|
13582 | ['Georgian', 'Georgian'],
|
13583 | ['Glagolitic', 'Glagolitic'],
|
13584 | ['Gunjala_Gondi', 'Gunjala_Gondi'],
|
13585 | ['Masaram_Gondi', 'Masaram_Gondi'],
|
13586 | ['Gothic', 'Gothic'],
|
13587 | ['Grantha', 'Grantha'],
|
13588 | ['Greek', 'Greek'],
|
13589 | ['Gujarati', 'Gujarati'],
|
13590 | ['Gurmukhi', 'Gurmukhi'],
|
13591 | ['Hangul', 'Hangul'],
|
13592 | ['Han', 'Han'],
|
13593 | ['Hanunoo', 'Hanunoo'],
|
13594 | ['Hatran', 'Hatran'],
|
13595 | ['Hebrew', 'Hebrew'],
|
13596 | ['Hiragana', 'Hiragana'],
|
13597 | ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
|
13598 | ['Pahawh_Hmong', 'Pahawh_Hmong'],
|
13599 | ['Nyiakeng_Puachue_Hmong', 'Nyiakeng_Puachue_Hmong'],
|
13600 | ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
|
13601 | ['Old_Hungarian', 'Old_Hungarian'],
|
13602 | ['Old_Italic', 'Old_Italic'],
|
13603 | ['Javanese', 'Javanese'],
|
13604 | ['Kayah_Li', 'Kayah_Li'],
|
13605 | ['Katakana', 'Katakana'],
|
13606 | ['Kharoshthi', 'Kharoshthi'],
|
13607 | ['Khmer', 'Khmer'],
|
13608 | ['Khojki', 'Khojki'],
|
13609 | ['Khitan_Small_Script', 'Khitan_Small_Script'],
|
13610 | ['Kannada', 'Kannada'],
|
13611 | ['Kaithi', 'Kaithi'],
|
13612 | ['Tai_Tham', 'Tai_Tham'],
|
13613 | ['Lao', 'Lao'],
|
13614 | ['Latin', 'Latin'],
|
13615 | ['Lepcha', 'Lepcha'],
|
13616 | ['Limbu', 'Limbu'],
|
13617 | ['Linear_A', 'Linear_A'],
|
13618 | ['Linear_B', 'Linear_B'],
|
13619 | ['Lycian', 'Lycian'],
|
13620 | ['Lydian', 'Lydian'],
|
13621 | ['Mahajani', 'Mahajani'],
|
13622 | ['Makasar', 'Makasar'],
|
13623 | ['Mandaic', 'Mandaic'],
|
13624 | ['Manichaean', 'Manichaean'],
|
13625 | ['Marchen', 'Marchen'],
|
13626 | ['Medefaidrin', 'Medefaidrin'],
|
13627 | ['Mende_Kikakui', 'Mende_Kikakui'],
|
13628 | ['Meroitic_Cursive', 'Meroitic_Cursive'],
|
13629 | ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
|
13630 | ['Malayalam', 'Malayalam'],
|
13631 | ['Mongolian', 'Mongolian'],
|
13632 | ['Mro', 'Mro'],
|
13633 | ['Meetei_Mayek', 'Meetei_Mayek'],
|
13634 | ['Multani', 'Multani'],
|
13635 | ['Myanmar', 'Myanmar'],
|
13636 | ['Nandinagari', 'Nandinagari'],
|
13637 | ['Old_North_Arabian', 'Old_North_Arabian'],
|
13638 | ['Nabataean', 'Nabataean'],
|
13639 | ['Nko', 'Nko'],
|
13640 | ['Nushu', 'Nushu'],
|
13641 | ['Ogham', 'Ogham'],
|
13642 | ['Ol_Chiki', 'Ol_Chiki'],
|
13643 | ['Old_Turkic', 'Old_Turkic'],
|
13644 | ['Oriya', 'Oriya'],
|
13645 | ['Osage', 'Osage'],
|
13646 | ['Osmanya', 'Osmanya'],
|
13647 | ['Palmyrene', 'Palmyrene'],
|
13648 | ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
|
13649 | ['Old_Permic', 'Old_Permic'],
|
13650 | ['Phags_Pa', 'Phags_Pa'],
|
13651 | ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
|
13652 | ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
|
13653 | ['Phoenician', 'Phoenician'],
|
13654 | ['Miao', 'Miao'],
|
13655 | ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
|
13656 | ['Rejang', 'Rejang'],
|
13657 | ['Hanifi_Rohingya', 'Hanifi_Rohingya'],
|
13658 | ['Runic', 'Runic'],
|
13659 | ['Samaritan', 'Samaritan'],
|
13660 | ['Old_South_Arabian', 'Old_South_Arabian'],
|
13661 | ['Saurashtra', 'Saurashtra'],
|
13662 | ['SignWriting', 'SignWriting'],
|
13663 | ['Shavian', 'Shavian'],
|
13664 | ['Sharada', 'Sharada'],
|
13665 | ['Siddham', 'Siddham'],
|
13666 | ['Khudawadi', 'Khudawadi'],
|
13667 | ['Sinhala', 'Sinhala'],
|
13668 | ['Sogdian', 'Sogdian'],
|
13669 | ['Old_Sogdian', 'Old_Sogdian'],
|
13670 | ['Sora_Sompeng', 'Sora_Sompeng'],
|
13671 | ['Soyombo', 'Soyombo'],
|
13672 | ['Sundanese', 'Sundanese'],
|
13673 | ['Syloti_Nagri', 'Syloti_Nagri'],
|
13674 | ['Syriac', 'Syriac'],
|
13675 | ['Tagbanwa', 'Tagbanwa'],
|
13676 | ['Takri', 'Takri'],
|
13677 | ['Tai_Le', 'Tai_Le'],
|
13678 | ['New_Tai_Lue', 'New_Tai_Lue'],
|
13679 | ['Tamil', 'Tamil'],
|
13680 | ['Tangut', 'Tangut'],
|
13681 | ['Tai_Viet', 'Tai_Viet'],
|
13682 | ['Telugu', 'Telugu'],
|
13683 | ['Tifinagh', 'Tifinagh'],
|
13684 | ['Tagalog', 'Tagalog'],
|
13685 | ['Thaana', 'Thaana'],
|
13686 | ['Tibetan', 'Tibetan'],
|
13687 | ['Tirhuta', 'Tirhuta'],
|
13688 | ['Ugaritic', 'Ugaritic'],
|
13689 | ['Vai', 'Vai'],
|
13690 | ['Warang_Citi', 'Warang_Citi'],
|
13691 | ['Wancho', 'Wancho'],
|
13692 | ['Old_Persian', 'Old_Persian'],
|
13693 | ['Cuneiform', 'Cuneiform'],
|
13694 | ['Yezidi', 'Yezidi'],
|
13695 | ['Yi', 'Yi'],
|
13696 | ['Zanabazar_Square', 'Zanabazar_Square'],
|
13697 | ['Inherited', 'Inherited'],
|
13698 | ['Common', 'Common'],
|
13699 | ['Unknown', 'Unknown']
|
13700 | ])],
|
13701 | ['Script_Extensions', new Map([
|
13702 | ['Adlm', 'Adlam'],
|
13703 | ['Aghb', 'Caucasian_Albanian'],
|
13704 | ['Ahom', 'Ahom'],
|
13705 | ['Arab', 'Arabic'],
|
13706 | ['Armi', 'Imperial_Aramaic'],
|
13707 | ['Armn', 'Armenian'],
|
13708 | ['Avst', 'Avestan'],
|
13709 | ['Bali', 'Balinese'],
|
13710 | ['Bamu', 'Bamum'],
|
13711 | ['Bass', 'Bassa_Vah'],
|
13712 | ['Batk', 'Batak'],
|
13713 | ['Beng', 'Bengali'],
|
13714 | ['Bhks', 'Bhaiksuki'],
|
13715 | ['Bopo', 'Bopomofo'],
|
13716 | ['Brah', 'Brahmi'],
|
13717 | ['Brai', 'Braille'],
|
13718 | ['Bugi', 'Buginese'],
|
13719 | ['Buhd', 'Buhid'],
|
13720 | ['Cakm', 'Chakma'],
|
13721 | ['Cans', 'Canadian_Aboriginal'],
|
13722 | ['Cari', 'Carian'],
|
13723 | ['Cham', 'Cham'],
|
13724 | ['Cher', 'Cherokee'],
|
13725 | ['Chrs', 'Chorasmian'],
|
13726 | ['Copt', 'Coptic'],
|
13727 | ['Qaac', 'Coptic'],
|
13728 | ['Cprt', 'Cypriot'],
|
13729 | ['Cyrl', 'Cyrillic'],
|
13730 | ['Deva', 'Devanagari'],
|
13731 | ['Diak', 'Dives_Akuru'],
|
13732 | ['Dogr', 'Dogra'],
|
13733 | ['Dsrt', 'Deseret'],
|
13734 | ['Dupl', 'Duployan'],
|
13735 | ['Egyp', 'Egyptian_Hieroglyphs'],
|
13736 | ['Elba', 'Elbasan'],
|
13737 | ['Elym', 'Elymaic'],
|
13738 | ['Ethi', 'Ethiopic'],
|
13739 | ['Geor', 'Georgian'],
|
13740 | ['Glag', 'Glagolitic'],
|
13741 | ['Gong', 'Gunjala_Gondi'],
|
13742 | ['Gonm', 'Masaram_Gondi'],
|
13743 | ['Goth', 'Gothic'],
|
13744 | ['Gran', 'Grantha'],
|
13745 | ['Grek', 'Greek'],
|
13746 | ['Gujr', 'Gujarati'],
|
13747 | ['Guru', 'Gurmukhi'],
|
13748 | ['Hang', 'Hangul'],
|
13749 | ['Hani', 'Han'],
|
13750 | ['Hano', 'Hanunoo'],
|
13751 | ['Hatr', 'Hatran'],
|
13752 | ['Hebr', 'Hebrew'],
|
13753 | ['Hira', 'Hiragana'],
|
13754 | ['Hluw', 'Anatolian_Hieroglyphs'],
|
13755 | ['Hmng', 'Pahawh_Hmong'],
|
13756 | ['Hmnp', 'Nyiakeng_Puachue_Hmong'],
|
13757 | ['Hrkt', 'Katakana_Or_Hiragana'],
|
13758 | ['Hung', 'Old_Hungarian'],
|
13759 | ['Ital', 'Old_Italic'],
|
13760 | ['Java', 'Javanese'],
|
13761 | ['Kali', 'Kayah_Li'],
|
13762 | ['Kana', 'Katakana'],
|
13763 | ['Khar', 'Kharoshthi'],
|
13764 | ['Khmr', 'Khmer'],
|
13765 | ['Khoj', 'Khojki'],
|
13766 | ['Kits', 'Khitan_Small_Script'],
|
13767 | ['Knda', 'Kannada'],
|
13768 | ['Kthi', 'Kaithi'],
|
13769 | ['Lana', 'Tai_Tham'],
|
13770 | ['Laoo', 'Lao'],
|
13771 | ['Latn', 'Latin'],
|
13772 | ['Lepc', 'Lepcha'],
|
13773 | ['Limb', 'Limbu'],
|
13774 | ['Lina', 'Linear_A'],
|
13775 | ['Linb', 'Linear_B'],
|
13776 | ['Lisu', 'Lisu'],
|
13777 | ['Lyci', 'Lycian'],
|
13778 | ['Lydi', 'Lydian'],
|
13779 | ['Mahj', 'Mahajani'],
|
13780 | ['Maka', 'Makasar'],
|
13781 | ['Mand', 'Mandaic'],
|
13782 | ['Mani', 'Manichaean'],
|
13783 | ['Marc', 'Marchen'],
|
13784 | ['Medf', 'Medefaidrin'],
|
13785 | ['Mend', 'Mende_Kikakui'],
|
13786 | ['Merc', 'Meroitic_Cursive'],
|
13787 | ['Mero', 'Meroitic_Hieroglyphs'],
|
13788 | ['Mlym', 'Malayalam'],
|
13789 | ['Modi', 'Modi'],
|
13790 | ['Mong', 'Mongolian'],
|
13791 | ['Mroo', 'Mro'],
|
13792 | ['Mtei', 'Meetei_Mayek'],
|
13793 | ['Mult', 'Multani'],
|
13794 | ['Mymr', 'Myanmar'],
|
13795 | ['Nand', 'Nandinagari'],
|
13796 | ['Narb', 'Old_North_Arabian'],
|
13797 | ['Nbat', 'Nabataean'],
|
13798 | ['Newa', 'Newa'],
|
13799 | ['Nkoo', 'Nko'],
|
13800 | ['Nshu', 'Nushu'],
|
13801 | ['Ogam', 'Ogham'],
|
13802 | ['Olck', 'Ol_Chiki'],
|
13803 | ['Orkh', 'Old_Turkic'],
|
13804 | ['Orya', 'Oriya'],
|
13805 | ['Osge', 'Osage'],
|
13806 | ['Osma', 'Osmanya'],
|
13807 | ['Palm', 'Palmyrene'],
|
13808 | ['Pauc', 'Pau_Cin_Hau'],
|
13809 | ['Perm', 'Old_Permic'],
|
13810 | ['Phag', 'Phags_Pa'],
|
13811 | ['Phli', 'Inscriptional_Pahlavi'],
|
13812 | ['Phlp', 'Psalter_Pahlavi'],
|
13813 | ['Phnx', 'Phoenician'],
|
13814 | ['Plrd', 'Miao'],
|
13815 | ['Prti', 'Inscriptional_Parthian'],
|
13816 | ['Rjng', 'Rejang'],
|
13817 | ['Rohg', 'Hanifi_Rohingya'],
|
13818 | ['Runr', 'Runic'],
|
13819 | ['Samr', 'Samaritan'],
|
13820 | ['Sarb', 'Old_South_Arabian'],
|
13821 | ['Saur', 'Saurashtra'],
|
13822 | ['Sgnw', 'SignWriting'],
|
13823 | ['Shaw', 'Shavian'],
|
13824 | ['Shrd', 'Sharada'],
|
13825 | ['Sidd', 'Siddham'],
|
13826 | ['Sind', 'Khudawadi'],
|
13827 | ['Sinh', 'Sinhala'],
|
13828 | ['Sogd', 'Sogdian'],
|
13829 | ['Sogo', 'Old_Sogdian'],
|
13830 | ['Sora', 'Sora_Sompeng'],
|
13831 | ['Soyo', 'Soyombo'],
|
13832 | ['Sund', 'Sundanese'],
|
13833 | ['Sylo', 'Syloti_Nagri'],
|
13834 | ['Syrc', 'Syriac'],
|
13835 | ['Tagb', 'Tagbanwa'],
|
13836 | ['Takr', 'Takri'],
|
13837 | ['Tale', 'Tai_Le'],
|
13838 | ['Talu', 'New_Tai_Lue'],
|
13839 | ['Taml', 'Tamil'],
|
13840 | ['Tang', 'Tangut'],
|
13841 | ['Tavt', 'Tai_Viet'],
|
13842 | ['Telu', 'Telugu'],
|
13843 | ['Tfng', 'Tifinagh'],
|
13844 | ['Tglg', 'Tagalog'],
|
13845 | ['Thaa', 'Thaana'],
|
13846 | ['Thai', 'Thai'],
|
13847 | ['Tibt', 'Tibetan'],
|
13848 | ['Tirh', 'Tirhuta'],
|
13849 | ['Ugar', 'Ugaritic'],
|
13850 | ['Vaii', 'Vai'],
|
13851 | ['Wara', 'Warang_Citi'],
|
13852 | ['Wcho', 'Wancho'],
|
13853 | ['Xpeo', 'Old_Persian'],
|
13854 | ['Xsux', 'Cuneiform'],
|
13855 | ['Yezi', 'Yezidi'],
|
13856 | ['Yiii', 'Yi'],
|
13857 | ['Zanb', 'Zanabazar_Square'],
|
13858 | ['Zinh', 'Inherited'],
|
13859 | ['Qaai', 'Inherited'],
|
13860 | ['Zyyy', 'Common'],
|
13861 | ['Zzzz', 'Unknown'],
|
13862 | ['Adlam', 'Adlam'],
|
13863 | ['Caucasian_Albanian', 'Caucasian_Albanian'],
|
13864 | ['Arabic', 'Arabic'],
|
13865 | ['Imperial_Aramaic', 'Imperial_Aramaic'],
|
13866 | ['Armenian', 'Armenian'],
|
13867 | ['Avestan', 'Avestan'],
|
13868 | ['Balinese', 'Balinese'],
|
13869 | ['Bamum', 'Bamum'],
|
13870 | ['Bassa_Vah', 'Bassa_Vah'],
|
13871 | ['Batak', 'Batak'],
|
13872 | ['Bengali', 'Bengali'],
|
13873 | ['Bhaiksuki', 'Bhaiksuki'],
|
13874 | ['Bopomofo', 'Bopomofo'],
|
13875 | ['Brahmi', 'Brahmi'],
|
13876 | ['Braille', 'Braille'],
|
13877 | ['Buginese', 'Buginese'],
|
13878 | ['Buhid', 'Buhid'],
|
13879 | ['Chakma', 'Chakma'],
|
13880 | ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
|
13881 | ['Carian', 'Carian'],
|
13882 | ['Cherokee', 'Cherokee'],
|
13883 | ['Chorasmian', 'Chorasmian'],
|
13884 | ['Coptic', 'Coptic'],
|
13885 | ['Cypriot', 'Cypriot'],
|
13886 | ['Cyrillic', 'Cyrillic'],
|
13887 | ['Devanagari', 'Devanagari'],
|
13888 | ['Dives_Akuru', 'Dives_Akuru'],
|
13889 | ['Dogra', 'Dogra'],
|
13890 | ['Deseret', 'Deseret'],
|
13891 | ['Duployan', 'Duployan'],
|
13892 | ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
|
13893 | ['Elbasan', 'Elbasan'],
|
13894 | ['Elymaic', 'Elymaic'],
|
13895 | ['Ethiopic', 'Ethiopic'],
|
13896 | ['Georgian', 'Georgian'],
|
13897 | ['Glagolitic', 'Glagolitic'],
|
13898 | ['Gunjala_Gondi', 'Gunjala_Gondi'],
|
13899 | ['Masaram_Gondi', 'Masaram_Gondi'],
|
13900 | ['Gothic', 'Gothic'],
|
13901 | ['Grantha', 'Grantha'],
|
13902 | ['Greek', 'Greek'],
|
13903 | ['Gujarati', 'Gujarati'],
|
13904 | ['Gurmukhi', 'Gurmukhi'],
|
13905 | ['Hangul', 'Hangul'],
|
13906 | ['Han', 'Han'],
|
13907 | ['Hanunoo', 'Hanunoo'],
|
13908 | ['Hatran', 'Hatran'],
|
13909 | ['Hebrew', 'Hebrew'],
|
13910 | ['Hiragana', 'Hiragana'],
|
13911 | ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
|
13912 | ['Pahawh_Hmong', 'Pahawh_Hmong'],
|
13913 | ['Nyiakeng_Puachue_Hmong', 'Nyiakeng_Puachue_Hmong'],
|
13914 | ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
|
13915 | ['Old_Hungarian', 'Old_Hungarian'],
|
13916 | ['Old_Italic', 'Old_Italic'],
|
13917 | ['Javanese', 'Javanese'],
|
13918 | ['Kayah_Li', 'Kayah_Li'],
|
13919 | ['Katakana', 'Katakana'],
|
13920 | ['Kharoshthi', 'Kharoshthi'],
|
13921 | ['Khmer', 'Khmer'],
|
13922 | ['Khojki', 'Khojki'],
|
13923 | ['Khitan_Small_Script', 'Khitan_Small_Script'],
|
13924 | ['Kannada', 'Kannada'],
|
13925 | ['Kaithi', 'Kaithi'],
|
13926 | ['Tai_Tham', 'Tai_Tham'],
|
13927 | ['Lao', 'Lao'],
|
13928 | ['Latin', 'Latin'],
|
13929 | ['Lepcha', 'Lepcha'],
|
13930 | ['Limbu', 'Limbu'],
|
13931 | ['Linear_A', 'Linear_A'],
|
13932 | ['Linear_B', 'Linear_B'],
|
13933 | ['Lycian', 'Lycian'],
|
13934 | ['Lydian', 'Lydian'],
|
13935 | ['Mahajani', 'Mahajani'],
|
13936 | ['Makasar', 'Makasar'],
|
13937 | ['Mandaic', 'Mandaic'],
|
13938 | ['Manichaean', 'Manichaean'],
|
13939 | ['Marchen', 'Marchen'],
|
13940 | ['Medefaidrin', 'Medefaidrin'],
|
13941 | ['Mende_Kikakui', 'Mende_Kikakui'],
|
13942 | ['Meroitic_Cursive', 'Meroitic_Cursive'],
|
13943 | ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
|
13944 | ['Malayalam', 'Malayalam'],
|
13945 | ['Mongolian', 'Mongolian'],
|
13946 | ['Mro', 'Mro'],
|
13947 | ['Meetei_Mayek', 'Meetei_Mayek'],
|
13948 | ['Multani', 'Multani'],
|
13949 | ['Myanmar', 'Myanmar'],
|
13950 | ['Nandinagari', 'Nandinagari'],
|
13951 | ['Old_North_Arabian', 'Old_North_Arabian'],
|
13952 | ['Nabataean', 'Nabataean'],
|
13953 | ['Nko', 'Nko'],
|
13954 | ['Nushu', 'Nushu'],
|
13955 | ['Ogham', 'Ogham'],
|
13956 | ['Ol_Chiki', 'Ol_Chiki'],
|
13957 | ['Old_Turkic', 'Old_Turkic'],
|
13958 | ['Oriya', 'Oriya'],
|
13959 | ['Osage', 'Osage'],
|
13960 | ['Osmanya', 'Osmanya'],
|
13961 | ['Palmyrene', 'Palmyrene'],
|
13962 | ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
|
13963 | ['Old_Permic', 'Old_Permic'],
|
13964 | ['Phags_Pa', 'Phags_Pa'],
|
13965 | ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
|
13966 | ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
|
13967 | ['Phoenician', 'Phoenician'],
|
13968 | ['Miao', 'Miao'],
|
13969 | ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
|
13970 | ['Rejang', 'Rejang'],
|
13971 | ['Hanifi_Rohingya', 'Hanifi_Rohingya'],
|
13972 | ['Runic', 'Runic'],
|
13973 | ['Samaritan', 'Samaritan'],
|
13974 | ['Old_South_Arabian', 'Old_South_Arabian'],
|
13975 | ['Saurashtra', 'Saurashtra'],
|
13976 | ['SignWriting', 'SignWriting'],
|
13977 | ['Shavian', 'Shavian'],
|
13978 | ['Sharada', 'Sharada'],
|
13979 | ['Siddham', 'Siddham'],
|
13980 | ['Khudawadi', 'Khudawadi'],
|
13981 | ['Sinhala', 'Sinhala'],
|
13982 | ['Sogdian', 'Sogdian'],
|
13983 | ['Old_Sogdian', 'Old_Sogdian'],
|
13984 | ['Sora_Sompeng', 'Sora_Sompeng'],
|
13985 | ['Soyombo', 'Soyombo'],
|
13986 | ['Sundanese', 'Sundanese'],
|
13987 | ['Syloti_Nagri', 'Syloti_Nagri'],
|
13988 | ['Syriac', 'Syriac'],
|
13989 | ['Tagbanwa', 'Tagbanwa'],
|
13990 | ['Takri', 'Takri'],
|
13991 | ['Tai_Le', 'Tai_Le'],
|
13992 | ['New_Tai_Lue', 'New_Tai_Lue'],
|
13993 | ['Tamil', 'Tamil'],
|
13994 | ['Tangut', 'Tangut'],
|
13995 | ['Tai_Viet', 'Tai_Viet'],
|
13996 | ['Telugu', 'Telugu'],
|
13997 | ['Tifinagh', 'Tifinagh'],
|
13998 | ['Tagalog', 'Tagalog'],
|
13999 | ['Thaana', 'Thaana'],
|
14000 | ['Tibetan', 'Tibetan'],
|
14001 | ['Tirhuta', 'Tirhuta'],
|
14002 | ['Ugaritic', 'Ugaritic'],
|
14003 | ['Vai', 'Vai'],
|
14004 | ['Warang_Citi', 'Warang_Citi'],
|
14005 | ['Wancho', 'Wancho'],
|
14006 | ['Old_Persian', 'Old_Persian'],
|
14007 | ['Cuneiform', 'Cuneiform'],
|
14008 | ['Yezidi', 'Yezidi'],
|
14009 | ['Yi', 'Yi'],
|
14010 | ['Zanabazar_Square', 'Zanabazar_Square'],
|
14011 | ['Inherited', 'Inherited'],
|
14012 | ['Common', 'Common'],
|
14013 | ['Unknown', 'Unknown']
|
14014 | ])]
|
14015 | ]);
|
14016 |
|
14017 | var matchPropertyValue = function(property, value) {
|
14018 | var aliasToValue = mappings.get(property);
|
14019 | if (!aliasToValue) {
|
14020 | throw new Error(("Unknown property `" + property + "`."));
|
14021 | }
|
14022 | var canonicalValue = aliasToValue.get(value);
|
14023 | if (canonicalValue) {
|
14024 | return canonicalValue;
|
14025 | }
|
14026 | throw new Error(
|
14027 | ("Unknown value `" + value + "` for property `" + property + "`.")
|
14028 | );
|
14029 | };
|
14030 |
|
14031 | var unicodeMatchPropertyValueEcmascript = matchPropertyValue;
|
14032 |
|
14033 | var iuMappings = new Map([
|
14034 | [0x4B, 0x212A],
|
14035 | [0x53, 0x17F],
|
14036 | [0x6B, 0x212A],
|
14037 | [0x73, 0x17F],
|
14038 | [0xB5, 0x39C],
|
14039 | [0xC5, 0x212B],
|
14040 | [0xDF, 0x1E9E],
|
14041 | [0xE5, 0x212B],
|
14042 | [0x17F, 0x53],
|
14043 | [0x1C4, 0x1C5],
|
14044 | [0x1C5, 0x1C4],
|
14045 | [0x1C7, 0x1C8],
|
14046 | [0x1C8, 0x1C7],
|
14047 | [0x1CA, 0x1CB],
|
14048 | [0x1CB, 0x1CA],
|
14049 | [0x1F1, 0x1F2],
|
14050 | [0x1F2, 0x1F1],
|
14051 | [0x26A, 0xA7AE],
|
14052 | [0x282, 0xA7C5],
|
14053 | [0x29D, 0xA7B2],
|
14054 | [0x345, 0x1FBE],
|
14055 | [0x392, 0x3D0],
|
14056 | [0x395, 0x3F5],
|
14057 | [0x398, 0x3F4],
|
14058 | [0x399, 0x1FBE],
|
14059 | [0x39A, 0x3F0],
|
14060 | [0x39C, 0xB5],
|
14061 | [0x3A0, 0x3D6],
|
14062 | [0x3A1, 0x3F1],
|
14063 | [0x3A3, 0x3C2],
|
14064 | [0x3A6, 0x3D5],
|
14065 | [0x3A9, 0x2126],
|
14066 | [0x3B8, 0x3F4],
|
14067 | [0x3C2, 0x3A3],
|
14068 | [0x3C9, 0x2126],
|
14069 | [0x3D0, 0x392],
|
14070 | [0x3D1, 0x3F4],
|
14071 | [0x3D5, 0x3A6],
|
14072 | [0x3D6, 0x3A0],
|
14073 | [0x3F0, 0x39A],
|
14074 | [0x3F1, 0x3A1],
|
14075 | [0x3F4, [
|
14076 | 0x398,
|
14077 | 0x3D1,
|
14078 | 0x3B8
|
14079 | ]],
|
14080 | [0x3F5, 0x395],
|
14081 | [0x412, 0x1C80],
|
14082 | [0x414, 0x1C81],
|
14083 | [0x41E, 0x1C82],
|
14084 | [0x421, 0x1C83],
|
14085 | [0x422, 0x1C85],
|
14086 | [0x42A, 0x1C86],
|
14087 | [0x432, 0x1C80],
|
14088 | [0x434, 0x1C81],
|
14089 | [0x43E, 0x1C82],
|
14090 | [0x441, 0x1C83],
|
14091 | [0x442, [
|
14092 | 0x1C84,
|
14093 | 0x1C85
|
14094 | ]],
|
14095 | [0x44A, 0x1C86],
|
14096 | [0x462, 0x1C87],
|
14097 | [0x463, 0x1C87],
|
14098 | [0x10D0, 0x1C90],
|
14099 | [0x10D1, 0x1C91],
|
14100 | [0x10D2, 0x1C92],
|
14101 | [0x10D3, 0x1C93],
|
14102 | [0x10D4, 0x1C94],
|
14103 | [0x10D5, 0x1C95],
|
14104 | [0x10D6, 0x1C96],
|
14105 | [0x10D7, 0x1C97],
|
14106 | [0x10D8, 0x1C98],
|
14107 | [0x10D9, 0x1C99],
|
14108 | [0x10DA, 0x1C9A],
|
14109 | [0x10DB, 0x1C9B],
|
14110 | [0x10DC, 0x1C9C],
|
14111 | [0x10DD, 0x1C9D],
|
14112 | [0x10DE, 0x1C9E],
|
14113 | [0x10DF, 0x1C9F],
|
14114 | [0x10E0, 0x1CA0],
|
14115 | [0x10E1, 0x1CA1],
|
14116 | [0x10E2, 0x1CA2],
|
14117 | [0x10E3, 0x1CA3],
|
14118 | [0x10E4, 0x1CA4],
|
14119 | [0x10E5, 0x1CA5],
|
14120 | [0x10E6, 0x1CA6],
|
14121 | [0x10E7, 0x1CA7],
|
14122 | [0x10E8, 0x1CA8],
|
14123 | [0x10E9, 0x1CA9],
|
14124 | [0x10EA, 0x1CAA],
|
14125 | [0x10EB, 0x1CAB],
|
14126 | [0x10EC, 0x1CAC],
|
14127 | [0x10ED, 0x1CAD],
|
14128 | [0x10EE, 0x1CAE],
|
14129 | [0x10EF, 0x1CAF],
|
14130 | [0x10F0, 0x1CB0],
|
14131 | [0x10F1, 0x1CB1],
|
14132 | [0x10F2, 0x1CB2],
|
14133 | [0x10F3, 0x1CB3],
|
14134 | [0x10F4, 0x1CB4],
|
14135 | [0x10F5, 0x1CB5],
|
14136 | [0x10F6, 0x1CB6],
|
14137 | [0x10F7, 0x1CB7],
|
14138 | [0x10F8, 0x1CB8],
|
14139 | [0x10F9, 0x1CB9],
|
14140 | [0x10FA, 0x1CBA],
|
14141 | [0x10FD, 0x1CBD],
|
14142 | [0x10FE, 0x1CBE],
|
14143 | [0x10FF, 0x1CBF],
|
14144 | [0x13A0, 0xAB70],
|
14145 | [0x13A1, 0xAB71],
|
14146 | [0x13A2, 0xAB72],
|
14147 | [0x13A3, 0xAB73],
|
14148 | [0x13A4, 0xAB74],
|
14149 | [0x13A5, 0xAB75],
|
14150 | [0x13A6, 0xAB76],
|
14151 | [0x13A7, 0xAB77],
|
14152 | [0x13A8, 0xAB78],
|
14153 | [0x13A9, 0xAB79],
|
14154 | [0x13AA, 0xAB7A],
|
14155 | [0x13AB, 0xAB7B],
|
14156 | [0x13AC, 0xAB7C],
|
14157 | [0x13AD, 0xAB7D],
|
14158 | [0x13AE, 0xAB7E],
|
14159 | [0x13AF, 0xAB7F],
|
14160 | [0x13B0, 0xAB80],
|
14161 | [0x13B1, 0xAB81],
|
14162 | [0x13B2, 0xAB82],
|
14163 | [0x13B3, 0xAB83],
|
14164 | [0x13B4, 0xAB84],
|
14165 | [0x13B5, 0xAB85],
|
14166 | [0x13B6, 0xAB86],
|
14167 | [0x13B7, 0xAB87],
|
14168 | [0x13B8, 0xAB88],
|
14169 | [0x13B9, 0xAB89],
|
14170 | [0x13BA, 0xAB8A],
|
14171 | [0x13BB, 0xAB8B],
|
14172 | [0x13BC, 0xAB8C],
|
14173 | [0x13BD, 0xAB8D],
|
14174 | [0x13BE, 0xAB8E],
|
14175 | [0x13BF, 0xAB8F],
|
14176 | [0x13C0, 0xAB90],
|
14177 | [0x13C1, 0xAB91],
|
14178 | [0x13C2, 0xAB92],
|
14179 | [0x13C3, 0xAB93],
|
14180 | [0x13C4, 0xAB94],
|
14181 | [0x13C5, 0xAB95],
|
14182 | [0x13C6, 0xAB96],
|
14183 | [0x13C7, 0xAB97],
|
14184 | [0x13C8, 0xAB98],
|
14185 | [0x13C9, 0xAB99],
|
14186 | [0x13CA, 0xAB9A],
|
14187 | [0x13CB, 0xAB9B],
|
14188 | [0x13CC, 0xAB9C],
|
14189 | [0x13CD, 0xAB9D],
|
14190 | [0x13CE, 0xAB9E],
|
14191 | [0x13CF, 0xAB9F],
|
14192 | [0x13D0, 0xABA0],
|
14193 | [0x13D1, 0xABA1],
|
14194 | [0x13D2, 0xABA2],
|
14195 | [0x13D3, 0xABA3],
|
14196 | [0x13D4, 0xABA4],
|
14197 | [0x13D5, 0xABA5],
|
14198 | [0x13D6, 0xABA6],
|
14199 | [0x13D7, 0xABA7],
|
14200 | [0x13D8, 0xABA8],
|
14201 | [0x13D9, 0xABA9],
|
14202 | [0x13DA, 0xABAA],
|
14203 | [0x13DB, 0xABAB],
|
14204 | [0x13DC, 0xABAC],
|
14205 | [0x13DD, 0xABAD],
|
14206 | [0x13DE, 0xABAE],
|
14207 | [0x13DF, 0xABAF],
|
14208 | [0x13E0, 0xABB0],
|
14209 | [0x13E1, 0xABB1],
|
14210 | [0x13E2, 0xABB2],
|
14211 | [0x13E3, 0xABB3],
|
14212 | [0x13E4, 0xABB4],
|
14213 | [0x13E5, 0xABB5],
|
14214 | [0x13E6, 0xABB6],
|
14215 | [0x13E7, 0xABB7],
|
14216 | [0x13E8, 0xABB8],
|
14217 | [0x13E9, 0xABB9],
|
14218 | [0x13EA, 0xABBA],
|
14219 | [0x13EB, 0xABBB],
|
14220 | [0x13EC, 0xABBC],
|
14221 | [0x13ED, 0xABBD],
|
14222 | [0x13EE, 0xABBE],
|
14223 | [0x13EF, 0xABBF],
|
14224 | [0x13F0, 0x13F8],
|
14225 | [0x13F1, 0x13F9],
|
14226 | [0x13F2, 0x13FA],
|
14227 | [0x13F3, 0x13FB],
|
14228 | [0x13F4, 0x13FC],
|
14229 | [0x13F5, 0x13FD],
|
14230 | [0x13F8, 0x13F0],
|
14231 | [0x13F9, 0x13F1],
|
14232 | [0x13FA, 0x13F2],
|
14233 | [0x13FB, 0x13F3],
|
14234 | [0x13FC, 0x13F4],
|
14235 | [0x13FD, 0x13F5],
|
14236 | [0x1C80, [
|
14237 | 0x412,
|
14238 | 0x432
|
14239 | ]],
|
14240 | [0x1C81, [
|
14241 | 0x414,
|
14242 | 0x434
|
14243 | ]],
|
14244 | [0x1C82, [
|
14245 | 0x41E,
|
14246 | 0x43E
|
14247 | ]],
|
14248 | [0x1C83, [
|
14249 | 0x421,
|
14250 | 0x441
|
14251 | ]],
|
14252 | [0x1C84, [
|
14253 | 0x1C85,
|
14254 | 0x442
|
14255 | ]],
|
14256 | [0x1C85, [
|
14257 | 0x422,
|
14258 | 0x1C84,
|
14259 | 0x442
|
14260 | ]],
|
14261 | [0x1C86, [
|
14262 | 0x42A,
|
14263 | 0x44A
|
14264 | ]],
|
14265 | [0x1C87, [
|
14266 | 0x462,
|
14267 | 0x463
|
14268 | ]],
|
14269 | [0x1C88, [
|
14270 | 0xA64A,
|
14271 | 0xA64B
|
14272 | ]],
|
14273 | [0x1C90, 0x10D0],
|
14274 | [0x1C91, 0x10D1],
|
14275 | [0x1C92, 0x10D2],
|
14276 | [0x1C93, 0x10D3],
|
14277 | [0x1C94, 0x10D4],
|
14278 | [0x1C95, 0x10D5],
|
14279 | [0x1C96, 0x10D6],
|
14280 | [0x1C97, 0x10D7],
|
14281 | [0x1C98, 0x10D8],
|
14282 | [0x1C99, 0x10D9],
|
14283 | [0x1C9A, 0x10DA],
|
14284 | [0x1C9B, 0x10DB],
|
14285 | [0x1C9C, 0x10DC],
|
14286 | [0x1C9D, 0x10DD],
|
14287 | [0x1C9E, 0x10DE],
|
14288 | [0x1C9F, 0x10DF],
|
14289 | [0x1CA0, 0x10E0],
|
14290 | [0x1CA1, 0x10E1],
|
14291 | [0x1CA2, 0x10E2],
|
14292 | [0x1CA3, 0x10E3],
|
14293 | [0x1CA4, 0x10E4],
|
14294 | [0x1CA5, 0x10E5],
|
14295 | [0x1CA6, 0x10E6],
|
14296 | [0x1CA7, 0x10E7],
|
14297 | [0x1CA8, 0x10E8],
|
14298 | [0x1CA9, 0x10E9],
|
14299 | [0x1CAA, 0x10EA],
|
14300 | [0x1CAB, 0x10EB],
|
14301 | [0x1CAC, 0x10EC],
|
14302 | [0x1CAD, 0x10ED],
|
14303 | [0x1CAE, 0x10EE],
|
14304 | [0x1CAF, 0x10EF],
|
14305 | [0x1CB0, 0x10F0],
|
14306 | [0x1CB1, 0x10F1],
|
14307 | [0x1CB2, 0x10F2],
|
14308 | [0x1CB3, 0x10F3],
|
14309 | [0x1CB4, 0x10F4],
|
14310 | [0x1CB5, 0x10F5],
|
14311 | [0x1CB6, 0x10F6],
|
14312 | [0x1CB7, 0x10F7],
|
14313 | [0x1CB8, 0x10F8],
|
14314 | [0x1CB9, 0x10F9],
|
14315 | [0x1CBA, 0x10FA],
|
14316 | [0x1CBD, 0x10FD],
|
14317 | [0x1CBE, 0x10FE],
|
14318 | [0x1CBF, 0x10FF],
|
14319 | [0x1D8E, 0xA7C6],
|
14320 | [0x1E60, 0x1E9B],
|
14321 | [0x1E9B, 0x1E60],
|
14322 | [0x1E9E, 0xDF],
|
14323 | [0x1F80, 0x1F88],
|
14324 | [0x1F81, 0x1F89],
|
14325 | [0x1F82, 0x1F8A],
|
14326 | [0x1F83, 0x1F8B],
|
14327 | [0x1F84, 0x1F8C],
|
14328 | [0x1F85, 0x1F8D],
|
14329 | [0x1F86, 0x1F8E],
|
14330 | [0x1F87, 0x1F8F],
|
14331 | [0x1F88, 0x1F80],
|
14332 | [0x1F89, 0x1F81],
|
14333 | [0x1F8A, 0x1F82],
|
14334 | [0x1F8B, 0x1F83],
|
14335 | [0x1F8C, 0x1F84],
|
14336 | [0x1F8D, 0x1F85],
|
14337 | [0x1F8E, 0x1F86],
|
14338 | [0x1F8F, 0x1F87],
|
14339 | [0x1F90, 0x1F98],
|
14340 | [0x1F91, 0x1F99],
|
14341 | [0x1F92, 0x1F9A],
|
14342 | [0x1F93, 0x1F9B],
|
14343 | [0x1F94, 0x1F9C],
|
14344 | [0x1F95, 0x1F9D],
|
14345 | [0x1F96, 0x1F9E],
|
14346 | [0x1F97, 0x1F9F],
|
14347 | [0x1F98, 0x1F90],
|
14348 | [0x1F99, 0x1F91],
|
14349 | [0x1F9A, 0x1F92],
|
14350 | [0x1F9B, 0x1F93],
|
14351 | [0x1F9C, 0x1F94],
|
14352 | [0x1F9D, 0x1F95],
|
14353 | [0x1F9E, 0x1F96],
|
14354 | [0x1F9F, 0x1F97],
|
14355 | [0x1FA0, 0x1FA8],
|
14356 | [0x1FA1, 0x1FA9],
|
14357 | [0x1FA2, 0x1FAA],
|
14358 | [0x1FA3, 0x1FAB],
|
14359 | [0x1FA4, 0x1FAC],
|
14360 | [0x1FA5, 0x1FAD],
|
14361 | [0x1FA6, 0x1FAE],
|
14362 | [0x1FA7, 0x1FAF],
|
14363 | [0x1FA8, 0x1FA0],
|
14364 | [0x1FA9, 0x1FA1],
|
14365 | [0x1FAA, 0x1FA2],
|
14366 | [0x1FAB, 0x1FA3],
|
14367 | [0x1FAC, 0x1FA4],
|
14368 | [0x1FAD, 0x1FA5],
|
14369 | [0x1FAE, 0x1FA6],
|
14370 | [0x1FAF, 0x1FA7],
|
14371 | [0x1FB3, 0x1FBC],
|
14372 | [0x1FBC, 0x1FB3],
|
14373 | [0x1FBE, [
|
14374 | 0x345,
|
14375 | 0x399
|
14376 | ]],
|
14377 | [0x1FC3, 0x1FCC],
|
14378 | [0x1FCC, 0x1FC3],
|
14379 | [0x1FF3, 0x1FFC],
|
14380 | [0x1FFC, 0x1FF3],
|
14381 | [0x2126, [
|
14382 | 0x3A9,
|
14383 | 0x3C9
|
14384 | ]],
|
14385 | [0x212A, 0x4B],
|
14386 | [0x212B, [
|
14387 | 0xC5,
|
14388 | 0xE5
|
14389 | ]],
|
14390 | [0xA64A, 0x1C88],
|
14391 | [0xA64B, 0x1C88],
|
14392 | [0xA794, 0xA7C4],
|
14393 | [0xA7AE, 0x26A],
|
14394 | [0xA7B2, 0x29D],
|
14395 | [0xA7B3, 0xAB53],
|
14396 | [0xA7B4, 0xA7B5],
|
14397 | [0xA7B5, 0xA7B4],
|
14398 | [0xA7B6, 0xA7B7],
|
14399 | [0xA7B7, 0xA7B6],
|
14400 | [0xA7B8, 0xA7B9],
|
14401 | [0xA7B9, 0xA7B8],
|
14402 | [0xA7BA, 0xA7BB],
|
14403 | [0xA7BB, 0xA7BA],
|
14404 | [0xA7BC, 0xA7BD],
|
14405 | [0xA7BD, 0xA7BC],
|
14406 | [0xA7BE, 0xA7BF],
|
14407 | [0xA7BF, 0xA7BE],
|
14408 | [0xA7C2, 0xA7C3],
|
14409 | [0xA7C3, 0xA7C2],
|
14410 | [0xA7C4, 0xA794],
|
14411 | [0xA7C5, 0x282],
|
14412 | [0xA7C6, 0x1D8E],
|
14413 | [0xAB53, 0xA7B3],
|
14414 | [0xAB70, 0x13A0],
|
14415 | [0xAB71, 0x13A1],
|
14416 | [0xAB72, 0x13A2],
|
14417 | [0xAB73, 0x13A3],
|
14418 | [0xAB74, 0x13A4],
|
14419 | [0xAB75, 0x13A5],
|
14420 | [0xAB76, 0x13A6],
|
14421 | [0xAB77, 0x13A7],
|
14422 | [0xAB78, 0x13A8],
|
14423 | [0xAB79, 0x13A9],
|
14424 | [0xAB7A, 0x13AA],
|
14425 | [0xAB7B, 0x13AB],
|
14426 | [0xAB7C, 0x13AC],
|
14427 | [0xAB7D, 0x13AD],
|
14428 | [0xAB7E, 0x13AE],
|
14429 | [0xAB7F, 0x13AF],
|
14430 | [0xAB80, 0x13B0],
|
14431 | [0xAB81, 0x13B1],
|
14432 | [0xAB82, 0x13B2],
|
14433 | [0xAB83, 0x13B3],
|
14434 | [0xAB84, 0x13B4],
|
14435 | [0xAB85, 0x13B5],
|
14436 | [0xAB86, 0x13B6],
|
14437 | [0xAB87, 0x13B7],
|
14438 | [0xAB88, 0x13B8],
|
14439 | [0xAB89, 0x13B9],
|
14440 | [0xAB8A, 0x13BA],
|
14441 | [0xAB8B, 0x13BB],
|
14442 | [0xAB8C, 0x13BC],
|
14443 | [0xAB8D, 0x13BD],
|
14444 | [0xAB8E, 0x13BE],
|
14445 | [0xAB8F, 0x13BF],
|
14446 | [0xAB90, 0x13C0],
|
14447 | [0xAB91, 0x13C1],
|
14448 | [0xAB92, 0x13C2],
|
14449 | [0xAB93, 0x13C3],
|
14450 | [0xAB94, 0x13C4],
|
14451 | [0xAB95, 0x13C5],
|
14452 | [0xAB96, 0x13C6],
|
14453 | [0xAB97, 0x13C7],
|
14454 | [0xAB98, 0x13C8],
|
14455 | [0xAB99, 0x13C9],
|
14456 | [0xAB9A, 0x13CA],
|
14457 | [0xAB9B, 0x13CB],
|
14458 | [0xAB9C, 0x13CC],
|
14459 | [0xAB9D, 0x13CD],
|
14460 | [0xAB9E, 0x13CE],
|
14461 | [0xAB9F, 0x13CF],
|
14462 | [0xABA0, 0x13D0],
|
14463 | [0xABA1, 0x13D1],
|
14464 | [0xABA2, 0x13D2],
|
14465 | [0xABA3, 0x13D3],
|
14466 | [0xABA4, 0x13D4],
|
14467 | [0xABA5, 0x13D5],
|
14468 | [0xABA6, 0x13D6],
|
14469 | [0xABA7, 0x13D7],
|
14470 | [0xABA8, 0x13D8],
|
14471 | [0xABA9, 0x13D9],
|
14472 | [0xABAA, 0x13DA],
|
14473 | [0xABAB, 0x13DB],
|
14474 | [0xABAC, 0x13DC],
|
14475 | [0xABAD, 0x13DD],
|
14476 | [0xABAE, 0x13DE],
|
14477 | [0xABAF, 0x13DF],
|
14478 | [0xABB0, 0x13E0],
|
14479 | [0xABB1, 0x13E1],
|
14480 | [0xABB2, 0x13E2],
|
14481 | [0xABB3, 0x13E3],
|
14482 | [0xABB4, 0x13E4],
|
14483 | [0xABB5, 0x13E5],
|
14484 | [0xABB6, 0x13E6],
|
14485 | [0xABB7, 0x13E7],
|
14486 | [0xABB8, 0x13E8],
|
14487 | [0xABB9, 0x13E9],
|
14488 | [0xABBA, 0x13EA],
|
14489 | [0xABBB, 0x13EB],
|
14490 | [0xABBC, 0x13EC],
|
14491 | [0xABBD, 0x13ED],
|
14492 | [0xABBE, 0x13EE],
|
14493 | [0xABBF, 0x13EF],
|
14494 | [0x10400, 0x10428],
|
14495 | [0x10401, 0x10429],
|
14496 | [0x10402, 0x1042A],
|
14497 | [0x10403, 0x1042B],
|
14498 | [0x10404, 0x1042C],
|
14499 | [0x10405, 0x1042D],
|
14500 | [0x10406, 0x1042E],
|
14501 | [0x10407, 0x1042F],
|
14502 | [0x10408, 0x10430],
|
14503 | [0x10409, 0x10431],
|
14504 | [0x1040A, 0x10432],
|
14505 | [0x1040B, 0x10433],
|
14506 | [0x1040C, 0x10434],
|
14507 | [0x1040D, 0x10435],
|
14508 | [0x1040E, 0x10436],
|
14509 | [0x1040F, 0x10437],
|
14510 | [0x10410, 0x10438],
|
14511 | [0x10411, 0x10439],
|
14512 | [0x10412, 0x1043A],
|
14513 | [0x10413, 0x1043B],
|
14514 | [0x10414, 0x1043C],
|
14515 | [0x10415, 0x1043D],
|
14516 | [0x10416, 0x1043E],
|
14517 | [0x10417, 0x1043F],
|
14518 | [0x10418, 0x10440],
|
14519 | [0x10419, 0x10441],
|
14520 | [0x1041A, 0x10442],
|
14521 | [0x1041B, 0x10443],
|
14522 | [0x1041C, 0x10444],
|
14523 | [0x1041D, 0x10445],
|
14524 | [0x1041E, 0x10446],
|
14525 | [0x1041F, 0x10447],
|
14526 | [0x10420, 0x10448],
|
14527 | [0x10421, 0x10449],
|
14528 | [0x10422, 0x1044A],
|
14529 | [0x10423, 0x1044B],
|
14530 | [0x10424, 0x1044C],
|
14531 | [0x10425, 0x1044D],
|
14532 | [0x10426, 0x1044E],
|
14533 | [0x10427, 0x1044F],
|
14534 | [0x10428, 0x10400],
|
14535 | [0x10429, 0x10401],
|
14536 | [0x1042A, 0x10402],
|
14537 | [0x1042B, 0x10403],
|
14538 | [0x1042C, 0x10404],
|
14539 | [0x1042D, 0x10405],
|
14540 | [0x1042E, 0x10406],
|
14541 | [0x1042F, 0x10407],
|
14542 | [0x10430, 0x10408],
|
14543 | [0x10431, 0x10409],
|
14544 | [0x10432, 0x1040A],
|
14545 | [0x10433, 0x1040B],
|
14546 | [0x10434, 0x1040C],
|
14547 | [0x10435, 0x1040D],
|
14548 | [0x10436, 0x1040E],
|
14549 | [0x10437, 0x1040F],
|
14550 | [0x10438, 0x10410],
|
14551 | [0x10439, 0x10411],
|
14552 | [0x1043A, 0x10412],
|
14553 | [0x1043B, 0x10413],
|
14554 | [0x1043C, 0x10414],
|
14555 | [0x1043D, 0x10415],
|
14556 | [0x1043E, 0x10416],
|
14557 | [0x1043F, 0x10417],
|
14558 | [0x10440, 0x10418],
|
14559 | [0x10441, 0x10419],
|
14560 | [0x10442, 0x1041A],
|
14561 | [0x10443, 0x1041B],
|
14562 | [0x10444, 0x1041C],
|
14563 | [0x10445, 0x1041D],
|
14564 | [0x10446, 0x1041E],
|
14565 | [0x10447, 0x1041F],
|
14566 | [0x10448, 0x10420],
|
14567 | [0x10449, 0x10421],
|
14568 | [0x1044A, 0x10422],
|
14569 | [0x1044B, 0x10423],
|
14570 | [0x1044C, 0x10424],
|
14571 | [0x1044D, 0x10425],
|
14572 | [0x1044E, 0x10426],
|
14573 | [0x1044F, 0x10427],
|
14574 | [0x104B0, 0x104D8],
|
14575 | [0x104B1, 0x104D9],
|
14576 | [0x104B2, 0x104DA],
|
14577 | [0x104B3, 0x104DB],
|
14578 | [0x104B4, 0x104DC],
|
14579 | [0x104B5, 0x104DD],
|
14580 | [0x104B6, 0x104DE],
|
14581 | [0x104B7, 0x104DF],
|
14582 | [0x104B8, 0x104E0],
|
14583 | [0x104B9, 0x104E1],
|
14584 | [0x104BA, 0x104E2],
|
14585 | [0x104BB, 0x104E3],
|
14586 | [0x104BC, 0x104E4],
|
14587 | [0x104BD, 0x104E5],
|
14588 | [0x104BE, 0x104E6],
|
14589 | [0x104BF, 0x104E7],
|
14590 | [0x104C0, 0x104E8],
|
14591 | [0x104C1, 0x104E9],
|
14592 | [0x104C2, 0x104EA],
|
14593 | [0x104C3, 0x104EB],
|
14594 | [0x104C4, 0x104EC],
|
14595 | [0x104C5, 0x104ED],
|
14596 | [0x104C6, 0x104EE],
|
14597 | [0x104C7, 0x104EF],
|
14598 | [0x104C8, 0x104F0],
|
14599 | [0x104C9, 0x104F1],
|
14600 | [0x104CA, 0x104F2],
|
14601 | [0x104CB, 0x104F3],
|
14602 | [0x104CC, 0x104F4],
|
14603 | [0x104CD, 0x104F5],
|
14604 | [0x104CE, 0x104F6],
|
14605 | [0x104CF, 0x104F7],
|
14606 | [0x104D0, 0x104F8],
|
14607 | [0x104D1, 0x104F9],
|
14608 | [0x104D2, 0x104FA],
|
14609 | [0x104D3, 0x104FB],
|
14610 | [0x104D8, 0x104B0],
|
14611 | [0x104D9, 0x104B1],
|
14612 | [0x104DA, 0x104B2],
|
14613 | [0x104DB, 0x104B3],
|
14614 | [0x104DC, 0x104B4],
|
14615 | [0x104DD, 0x104B5],
|
14616 | [0x104DE, 0x104B6],
|
14617 | [0x104DF, 0x104B7],
|
14618 | [0x104E0, 0x104B8],
|
14619 | [0x104E1, 0x104B9],
|
14620 | [0x104E2, 0x104BA],
|
14621 | [0x104E3, 0x104BB],
|
14622 | [0x104E4, 0x104BC],
|
14623 | [0x104E5, 0x104BD],
|
14624 | [0x104E6, 0x104BE],
|
14625 | [0x104E7, 0x104BF],
|
14626 | [0x104E8, 0x104C0],
|
14627 | [0x104E9, 0x104C1],
|
14628 | [0x104EA, 0x104C2],
|
14629 | [0x104EB, 0x104C3],
|
14630 | [0x104EC, 0x104C4],
|
14631 | [0x104ED, 0x104C5],
|
14632 | [0x104EE, 0x104C6],
|
14633 | [0x104EF, 0x104C7],
|
14634 | [0x104F0, 0x104C8],
|
14635 | [0x104F1, 0x104C9],
|
14636 | [0x104F2, 0x104CA],
|
14637 | [0x104F3, 0x104CB],
|
14638 | [0x104F4, 0x104CC],
|
14639 | [0x104F5, 0x104CD],
|
14640 | [0x104F6, 0x104CE],
|
14641 | [0x104F7, 0x104CF],
|
14642 | [0x104F8, 0x104D0],
|
14643 | [0x104F9, 0x104D1],
|
14644 | [0x104FA, 0x104D2],
|
14645 | [0x104FB, 0x104D3],
|
14646 | [0x10C80, 0x10CC0],
|
14647 | [0x10C81, 0x10CC1],
|
14648 | [0x10C82, 0x10CC2],
|
14649 | [0x10C83, 0x10CC3],
|
14650 | [0x10C84, 0x10CC4],
|
14651 | [0x10C85, 0x10CC5],
|
14652 | [0x10C86, 0x10CC6],
|
14653 | [0x10C87, 0x10CC7],
|
14654 | [0x10C88, 0x10CC8],
|
14655 | [0x10C89, 0x10CC9],
|
14656 | [0x10C8A, 0x10CCA],
|
14657 | [0x10C8B, 0x10CCB],
|
14658 | [0x10C8C, 0x10CCC],
|
14659 | [0x10C8D, 0x10CCD],
|
14660 | [0x10C8E, 0x10CCE],
|
14661 | [0x10C8F, 0x10CCF],
|
14662 | [0x10C90, 0x10CD0],
|
14663 | [0x10C91, 0x10CD1],
|
14664 | [0x10C92, 0x10CD2],
|
14665 | [0x10C93, 0x10CD3],
|
14666 | [0x10C94, 0x10CD4],
|
14667 | [0x10C95, 0x10CD5],
|
14668 | [0x10C96, 0x10CD6],
|
14669 | [0x10C97, 0x10CD7],
|
14670 | [0x10C98, 0x10CD8],
|
14671 | [0x10C99, 0x10CD9],
|
14672 | [0x10C9A, 0x10CDA],
|
14673 | [0x10C9B, 0x10CDB],
|
14674 | [0x10C9C, 0x10CDC],
|
14675 | [0x10C9D, 0x10CDD],
|
14676 | [0x10C9E, 0x10CDE],
|
14677 | [0x10C9F, 0x10CDF],
|
14678 | [0x10CA0, 0x10CE0],
|
14679 | [0x10CA1, 0x10CE1],
|
14680 | [0x10CA2, 0x10CE2],
|
14681 | [0x10CA3, 0x10CE3],
|
14682 | [0x10CA4, 0x10CE4],
|
14683 | [0x10CA5, 0x10CE5],
|
14684 | [0x10CA6, 0x10CE6],
|
14685 | [0x10CA7, 0x10CE7],
|
14686 | [0x10CA8, 0x10CE8],
|
14687 | [0x10CA9, 0x10CE9],
|
14688 | [0x10CAA, 0x10CEA],
|
14689 | [0x10CAB, 0x10CEB],
|
14690 | [0x10CAC, 0x10CEC],
|
14691 | [0x10CAD, 0x10CED],
|
14692 | [0x10CAE, 0x10CEE],
|
14693 | [0x10CAF, 0x10CEF],
|
14694 | [0x10CB0, 0x10CF0],
|
14695 | [0x10CB1, 0x10CF1],
|
14696 | [0x10CB2, 0x10CF2],
|
14697 | [0x10CC0, 0x10C80],
|
14698 | [0x10CC1, 0x10C81],
|
14699 | [0x10CC2, 0x10C82],
|
14700 | [0x10CC3, 0x10C83],
|
14701 | [0x10CC4, 0x10C84],
|
14702 | [0x10CC5, 0x10C85],
|
14703 | [0x10CC6, 0x10C86],
|
14704 | [0x10CC7, 0x10C87],
|
14705 | [0x10CC8, 0x10C88],
|
14706 | [0x10CC9, 0x10C89],
|
14707 | [0x10CCA, 0x10C8A],
|
14708 | [0x10CCB, 0x10C8B],
|
14709 | [0x10CCC, 0x10C8C],
|
14710 | [0x10CCD, 0x10C8D],
|
14711 | [0x10CCE, 0x10C8E],
|
14712 | [0x10CCF, 0x10C8F],
|
14713 | [0x10CD0, 0x10C90],
|
14714 | [0x10CD1, 0x10C91],
|
14715 | [0x10CD2, 0x10C92],
|
14716 | [0x10CD3, 0x10C93],
|
14717 | [0x10CD4, 0x10C94],
|
14718 | [0x10CD5, 0x10C95],
|
14719 | [0x10CD6, 0x10C96],
|
14720 | [0x10CD7, 0x10C97],
|
14721 | [0x10CD8, 0x10C98],
|
14722 | [0x10CD9, 0x10C99],
|
14723 | [0x10CDA, 0x10C9A],
|
14724 | [0x10CDB, 0x10C9B],
|
14725 | [0x10CDC, 0x10C9C],
|
14726 | [0x10CDD, 0x10C9D],
|
14727 | [0x10CDE, 0x10C9E],
|
14728 | [0x10CDF, 0x10C9F],
|
14729 | [0x10CE0, 0x10CA0],
|
14730 | [0x10CE1, 0x10CA1],
|
14731 | [0x10CE2, 0x10CA2],
|
14732 | [0x10CE3, 0x10CA3],
|
14733 | [0x10CE4, 0x10CA4],
|
14734 | [0x10CE5, 0x10CA5],
|
14735 | [0x10CE6, 0x10CA6],
|
14736 | [0x10CE7, 0x10CA7],
|
14737 | [0x10CE8, 0x10CA8],
|
14738 | [0x10CE9, 0x10CA9],
|
14739 | [0x10CEA, 0x10CAA],
|
14740 | [0x10CEB, 0x10CAB],
|
14741 | [0x10CEC, 0x10CAC],
|
14742 | [0x10CED, 0x10CAD],
|
14743 | [0x10CEE, 0x10CAE],
|
14744 | [0x10CEF, 0x10CAF],
|
14745 | [0x10CF0, 0x10CB0],
|
14746 | [0x10CF1, 0x10CB1],
|
14747 | [0x10CF2, 0x10CB2],
|
14748 | [0x118A0, 0x118C0],
|
14749 | [0x118A1, 0x118C1],
|
14750 | [0x118A2, 0x118C2],
|
14751 | [0x118A3, 0x118C3],
|
14752 | [0x118A4, 0x118C4],
|
14753 | [0x118A5, 0x118C5],
|
14754 | [0x118A6, 0x118C6],
|
14755 | [0x118A7, 0x118C7],
|
14756 | [0x118A8, 0x118C8],
|
14757 | [0x118A9, 0x118C9],
|
14758 | [0x118AA, 0x118CA],
|
14759 | [0x118AB, 0x118CB],
|
14760 | [0x118AC, 0x118CC],
|
14761 | [0x118AD, 0x118CD],
|
14762 | [0x118AE, 0x118CE],
|
14763 | [0x118AF, 0x118CF],
|
14764 | [0x118B0, 0x118D0],
|
14765 | [0x118B1, 0x118D1],
|
14766 | [0x118B2, 0x118D2],
|
14767 | [0x118B3, 0x118D3],
|
14768 | [0x118B4, 0x118D4],
|
14769 | [0x118B5, 0x118D5],
|
14770 | [0x118B6, 0x118D6],
|
14771 | [0x118B7, 0x118D7],
|
14772 | [0x118B8, 0x118D8],
|
14773 | [0x118B9, 0x118D9],
|
14774 | [0x118BA, 0x118DA],
|
14775 | [0x118BB, 0x118DB],
|
14776 | [0x118BC, 0x118DC],
|
14777 | [0x118BD, 0x118DD],
|
14778 | [0x118BE, 0x118DE],
|
14779 | [0x118BF, 0x118DF],
|
14780 | [0x118C0, 0x118A0],
|
14781 | [0x118C1, 0x118A1],
|
14782 | [0x118C2, 0x118A2],
|
14783 | [0x118C3, 0x118A3],
|
14784 | [0x118C4, 0x118A4],
|
14785 | [0x118C5, 0x118A5],
|
14786 | [0x118C6, 0x118A6],
|
14787 | [0x118C7, 0x118A7],
|
14788 | [0x118C8, 0x118A8],
|
14789 | [0x118C9, 0x118A9],
|
14790 | [0x118CA, 0x118AA],
|
14791 | [0x118CB, 0x118AB],
|
14792 | [0x118CC, 0x118AC],
|
14793 | [0x118CD, 0x118AD],
|
14794 | [0x118CE, 0x118AE],
|
14795 | [0x118CF, 0x118AF],
|
14796 | [0x118D0, 0x118B0],
|
14797 | [0x118D1, 0x118B1],
|
14798 | [0x118D2, 0x118B2],
|
14799 | [0x118D3, 0x118B3],
|
14800 | [0x118D4, 0x118B4],
|
14801 | [0x118D5, 0x118B5],
|
14802 | [0x118D6, 0x118B6],
|
14803 | [0x118D7, 0x118B7],
|
14804 | [0x118D8, 0x118B8],
|
14805 | [0x118D9, 0x118B9],
|
14806 | [0x118DA, 0x118BA],
|
14807 | [0x118DB, 0x118BB],
|
14808 | [0x118DC, 0x118BC],
|
14809 | [0x118DD, 0x118BD],
|
14810 | [0x118DE, 0x118BE],
|
14811 | [0x118DF, 0x118BF],
|
14812 | [0x16E40, 0x16E60],
|
14813 | [0x16E41, 0x16E61],
|
14814 | [0x16E42, 0x16E62],
|
14815 | [0x16E43, 0x16E63],
|
14816 | [0x16E44, 0x16E64],
|
14817 | [0x16E45, 0x16E65],
|
14818 | [0x16E46, 0x16E66],
|
14819 | [0x16E47, 0x16E67],
|
14820 | [0x16E48, 0x16E68],
|
14821 | [0x16E49, 0x16E69],
|
14822 | [0x16E4A, 0x16E6A],
|
14823 | [0x16E4B, 0x16E6B],
|
14824 | [0x16E4C, 0x16E6C],
|
14825 | [0x16E4D, 0x16E6D],
|
14826 | [0x16E4E, 0x16E6E],
|
14827 | [0x16E4F, 0x16E6F],
|
14828 | [0x16E50, 0x16E70],
|
14829 | [0x16E51, 0x16E71],
|
14830 | [0x16E52, 0x16E72],
|
14831 | [0x16E53, 0x16E73],
|
14832 | [0x16E54, 0x16E74],
|
14833 | [0x16E55, 0x16E75],
|
14834 | [0x16E56, 0x16E76],
|
14835 | [0x16E57, 0x16E77],
|
14836 | [0x16E58, 0x16E78],
|
14837 | [0x16E59, 0x16E79],
|
14838 | [0x16E5A, 0x16E7A],
|
14839 | [0x16E5B, 0x16E7B],
|
14840 | [0x16E5C, 0x16E7C],
|
14841 | [0x16E5D, 0x16E7D],
|
14842 | [0x16E5E, 0x16E7E],
|
14843 | [0x16E5F, 0x16E7F],
|
14844 | [0x16E60, 0x16E40],
|
14845 | [0x16E61, 0x16E41],
|
14846 | [0x16E62, 0x16E42],
|
14847 | [0x16E63, 0x16E43],
|
14848 | [0x16E64, 0x16E44],
|
14849 | [0x16E65, 0x16E45],
|
14850 | [0x16E66, 0x16E46],
|
14851 | [0x16E67, 0x16E47],
|
14852 | [0x16E68, 0x16E48],
|
14853 | [0x16E69, 0x16E49],
|
14854 | [0x16E6A, 0x16E4A],
|
14855 | [0x16E6B, 0x16E4B],
|
14856 | [0x16E6C, 0x16E4C],
|
14857 | [0x16E6D, 0x16E4D],
|
14858 | [0x16E6E, 0x16E4E],
|
14859 | [0x16E6F, 0x16E4F],
|
14860 | [0x16E70, 0x16E50],
|
14861 | [0x16E71, 0x16E51],
|
14862 | [0x16E72, 0x16E52],
|
14863 | [0x16E73, 0x16E53],
|
14864 | [0x16E74, 0x16E54],
|
14865 | [0x16E75, 0x16E55],
|
14866 | [0x16E76, 0x16E56],
|
14867 | [0x16E77, 0x16E57],
|
14868 | [0x16E78, 0x16E58],
|
14869 | [0x16E79, 0x16E59],
|
14870 | [0x16E7A, 0x16E5A],
|
14871 | [0x16E7B, 0x16E5B],
|
14872 | [0x16E7C, 0x16E5C],
|
14873 | [0x16E7D, 0x16E5D],
|
14874 | [0x16E7E, 0x16E5E],
|
14875 | [0x16E7F, 0x16E5F],
|
14876 | [0x1E900, 0x1E922],
|
14877 | [0x1E901, 0x1E923],
|
14878 | [0x1E902, 0x1E924],
|
14879 | [0x1E903, 0x1E925],
|
14880 | [0x1E904, 0x1E926],
|
14881 | [0x1E905, 0x1E927],
|
14882 | [0x1E906, 0x1E928],
|
14883 | [0x1E907, 0x1E929],
|
14884 | [0x1E908, 0x1E92A],
|
14885 | [0x1E909, 0x1E92B],
|
14886 | [0x1E90A, 0x1E92C],
|
14887 | [0x1E90B, 0x1E92D],
|
14888 | [0x1E90C, 0x1E92E],
|
14889 | [0x1E90D, 0x1E92F],
|
14890 | [0x1E90E, 0x1E930],
|
14891 | [0x1E90F, 0x1E931],
|
14892 | [0x1E910, 0x1E932],
|
14893 | [0x1E911, 0x1E933],
|
14894 | [0x1E912, 0x1E934],
|
14895 | [0x1E913, 0x1E935],
|
14896 | [0x1E914, 0x1E936],
|
14897 | [0x1E915, 0x1E937],
|
14898 | [0x1E916, 0x1E938],
|
14899 | [0x1E917, 0x1E939],
|
14900 | [0x1E918, 0x1E93A],
|
14901 | [0x1E919, 0x1E93B],
|
14902 | [0x1E91A, 0x1E93C],
|
14903 | [0x1E91B, 0x1E93D],
|
14904 | [0x1E91C, 0x1E93E],
|
14905 | [0x1E91D, 0x1E93F],
|
14906 | [0x1E91E, 0x1E940],
|
14907 | [0x1E91F, 0x1E941],
|
14908 | [0x1E920, 0x1E942],
|
14909 | [0x1E921, 0x1E943],
|
14910 | [0x1E922, 0x1E900],
|
14911 | [0x1E923, 0x1E901],
|
14912 | [0x1E924, 0x1E902],
|
14913 | [0x1E925, 0x1E903],
|
14914 | [0x1E926, 0x1E904],
|
14915 | [0x1E927, 0x1E905],
|
14916 | [0x1E928, 0x1E906],
|
14917 | [0x1E929, 0x1E907],
|
14918 | [0x1E92A, 0x1E908],
|
14919 | [0x1E92B, 0x1E909],
|
14920 | [0x1E92C, 0x1E90A],
|
14921 | [0x1E92D, 0x1E90B],
|
14922 | [0x1E92E, 0x1E90C],
|
14923 | [0x1E92F, 0x1E90D],
|
14924 | [0x1E930, 0x1E90E],
|
14925 | [0x1E931, 0x1E90F],
|
14926 | [0x1E932, 0x1E910],
|
14927 | [0x1E933, 0x1E911],
|
14928 | [0x1E934, 0x1E912],
|
14929 | [0x1E935, 0x1E913],
|
14930 | [0x1E936, 0x1E914],
|
14931 | [0x1E937, 0x1E915],
|
14932 | [0x1E938, 0x1E916],
|
14933 | [0x1E939, 0x1E917],
|
14934 | [0x1E93A, 0x1E918],
|
14935 | [0x1E93B, 0x1E919],
|
14936 | [0x1E93C, 0x1E91A],
|
14937 | [0x1E93D, 0x1E91B],
|
14938 | [0x1E93E, 0x1E91C],
|
14939 | [0x1E93F, 0x1E91D],
|
14940 | [0x1E940, 0x1E91E],
|
14941 | [0x1E941, 0x1E91F],
|
14942 | [0x1E942, 0x1E920],
|
14943 | [0x1E943, 0x1E921]
|
14944 | ]);
|
14945 |
|
14946 | var REGULAR = new Map([
|
14947 | ['d', regenerate()
|
14948 | .addRange(0x30, 0x39)],
|
14949 | ['D', regenerate()
|
14950 | .addRange(0x0, 0x2F)
|
14951 | .addRange(0x3A, 0xFFFF)],
|
14952 | ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
|
14953 | .addRange(0x9, 0xD)
|
14954 | .addRange(0x2000, 0x200A)
|
14955 | .addRange(0x2028, 0x2029)],
|
14956 | ['S', regenerate()
|
14957 | .addRange(0x0, 0x8)
|
14958 | .addRange(0xE, 0x1F)
|
14959 | .addRange(0x21, 0x9F)
|
14960 | .addRange(0xA1, 0x167F)
|
14961 | .addRange(0x1681, 0x1FFF)
|
14962 | .addRange(0x200B, 0x2027)
|
14963 | .addRange(0x202A, 0x202E)
|
14964 | .addRange(0x2030, 0x205E)
|
14965 | .addRange(0x2060, 0x2FFF)
|
14966 | .addRange(0x3001, 0xFEFE)
|
14967 | .addRange(0xFF00, 0xFFFF)],
|
14968 | ['w', regenerate(0x5F)
|
14969 | .addRange(0x30, 0x39)
|
14970 | .addRange(0x41, 0x5A)
|
14971 | .addRange(0x61, 0x7A)],
|
14972 | ['W', regenerate(0x60)
|
14973 | .addRange(0x0, 0x2F)
|
14974 | .addRange(0x3A, 0x40)
|
14975 | .addRange(0x5B, 0x5E)
|
14976 | .addRange(0x7B, 0xFFFF)]
|
14977 | ]);
|
14978 |
|
14979 | var UNICODE = new Map([
|
14980 | ['d', regenerate()
|
14981 | .addRange(0x30, 0x39)],
|
14982 | ['D', regenerate()
|
14983 | .addRange(0x0, 0x2F)
|
14984 | .addRange(0x3A, 0x10FFFF)],
|
14985 | ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
|
14986 | .addRange(0x9, 0xD)
|
14987 | .addRange(0x2000, 0x200A)
|
14988 | .addRange(0x2028, 0x2029)],
|
14989 | ['S', regenerate()
|
14990 | .addRange(0x0, 0x8)
|
14991 | .addRange(0xE, 0x1F)
|
14992 | .addRange(0x21, 0x9F)
|
14993 | .addRange(0xA1, 0x167F)
|
14994 | .addRange(0x1681, 0x1FFF)
|
14995 | .addRange(0x200B, 0x2027)
|
14996 | .addRange(0x202A, 0x202E)
|
14997 | .addRange(0x2030, 0x205E)
|
14998 | .addRange(0x2060, 0x2FFF)
|
14999 | .addRange(0x3001, 0xFEFE)
|
15000 | .addRange(0xFF00, 0x10FFFF)],
|
15001 | ['w', regenerate(0x5F)
|
15002 | .addRange(0x30, 0x39)
|
15003 | .addRange(0x41, 0x5A)
|
15004 | .addRange(0x61, 0x7A)],
|
15005 | ['W', regenerate(0x60)
|
15006 | .addRange(0x0, 0x2F)
|
15007 | .addRange(0x3A, 0x40)
|
15008 | .addRange(0x5B, 0x5E)
|
15009 | .addRange(0x7B, 0x10FFFF)]
|
15010 | ]);
|
15011 |
|
15012 | var UNICODE_IGNORE_CASE = new Map([
|
15013 | ['d', regenerate()
|
15014 | .addRange(0x30, 0x39)],
|
15015 | ['D', regenerate()
|
15016 | .addRange(0x0, 0x2F)
|
15017 | .addRange(0x3A, 0x10FFFF)],
|
15018 | ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
|
15019 | .addRange(0x9, 0xD)
|
15020 | .addRange(0x2000, 0x200A)
|
15021 | .addRange(0x2028, 0x2029)],
|
15022 | ['S', regenerate()
|
15023 | .addRange(0x0, 0x8)
|
15024 | .addRange(0xE, 0x1F)
|
15025 | .addRange(0x21, 0x9F)
|
15026 | .addRange(0xA1, 0x167F)
|
15027 | .addRange(0x1681, 0x1FFF)
|
15028 | .addRange(0x200B, 0x2027)
|
15029 | .addRange(0x202A, 0x202E)
|
15030 | .addRange(0x2030, 0x205E)
|
15031 | .addRange(0x2060, 0x2FFF)
|
15032 | .addRange(0x3001, 0xFEFE)
|
15033 | .addRange(0xFF00, 0x10FFFF)],
|
15034 | ['w', regenerate(0x5F, 0x17F, 0x212A)
|
15035 | .addRange(0x30, 0x39)
|
15036 | .addRange(0x41, 0x5A)
|
15037 | .addRange(0x61, 0x7A)],
|
15038 | ['W', regenerate(0x60)
|
15039 | .addRange(0x0, 0x2F)
|
15040 | .addRange(0x3A, 0x40)
|
15041 | .addRange(0x5B, 0x5E)
|
15042 | .addRange(0x7B, 0x17E)
|
15043 | .addRange(0x180, 0x2129)
|
15044 | .addRange(0x212B, 0x10FFFF)]
|
15045 | ]);
|
15046 |
|
15047 | var characterClassEscapeSets = {
|
15048 | REGULAR: REGULAR,
|
15049 | UNICODE: UNICODE,
|
15050 | UNICODE_IGNORE_CASE: UNICODE_IGNORE_CASE
|
15051 | };
|
15052 |
|
15053 | var generate = regjsgen.generate;
|
15054 | var parse$1 = parser.parse;
|
15055 |
|
15056 |
|
15057 |
|
15058 |
|
15059 |
|
15060 |
|
15061 | // Prepare a Regenerate set containing all code points, used for negative
|
15062 | // character classes (if any).
|
15063 | var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
|
15064 | // Without the `u` flag, the range stops at 0xFFFF.
|
15065 | // https://mths.be/es6#sec-pattern-semantics
|
15066 | var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
|
15067 |
|
15068 | // Prepare a Regenerate set containing all code points that are supposed to be
|
15069 | // matched by `/./u`. https://mths.be/es6#sec-atom
|
15070 | var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
|
15071 | .remove(
|
15072 | // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
|
15073 | 0x000A, // Line Feed <LF>
|
15074 | 0x000D, // Carriage Return <CR>
|
15075 | 0x2028, // Line Separator <LS>
|
15076 | 0x2029 // Paragraph Separator <PS>
|
15077 | );
|
15078 | // Prepare a Regenerate set containing all code points that are supposed to be
|
15079 | // matched by `/./` (only BMP code points).
|
15080 | var DOT_SET = DOT_SET_UNICODE.clone()
|
15081 | .intersection(BMP_SET);
|
15082 |
|
15083 | var getCharacterClassEscapeSet = function (character, unicode, ignoreCase) {
|
15084 | if (unicode) {
|
15085 | if (ignoreCase) {
|
15086 | return characterClassEscapeSets.UNICODE_IGNORE_CASE.get(character);
|
15087 | }
|
15088 | return characterClassEscapeSets.UNICODE.get(character);
|
15089 | }
|
15090 | return characterClassEscapeSets.REGULAR.get(character);
|
15091 | };
|
15092 |
|
15093 | var getDotSet = function (unicode, dotAll) {
|
15094 | if (dotAll) {
|
15095 | return unicode ? UNICODE_SET : BMP_SET;
|
15096 | }
|
15097 | return unicode ? DOT_SET_UNICODE : DOT_SET;
|
15098 | };
|
15099 |
|
15100 | var getUnicodePropertyValueSet = function (property, value) {
|
15101 | var path = value ?
|
15102 | (property + "/" + value) :
|
15103 | ("Binary_Property/" + property);
|
15104 | try {
|
15105 | return commonjsRequire(("regenerate-unicode-properties/" + path + ".js"));
|
15106 | } catch (exception) {
|
15107 | throw new Error(
|
15108 | "Failed to recognize value `" + value + "` for property " +
|
15109 | "`" + property + "`."
|
15110 | );
|
15111 | }
|
15112 | };
|
15113 |
|
15114 | var handleLoneUnicodePropertyNameOrValue = function (value) {
|
15115 | // It could be a `General_Category` value or a binary property.
|
15116 | // Note: `unicodeMatchPropertyValue` throws on invalid values.
|
15117 | try {
|
15118 | var property$1 = 'General_Category';
|
15119 | var category = unicodeMatchPropertyValueEcmascript(property$1, value);
|
15120 | return getUnicodePropertyValueSet(property$1, category);
|
15121 | } catch (exception) {}
|
15122 | // It’s not a `General_Category` value, so check if it’s a binary
|
15123 | // property. Note: `unicodeMatchProperty` throws on invalid properties.
|
15124 | var property = unicodeMatchPropertyEcmascript(value);
|
15125 | return getUnicodePropertyValueSet(property);
|
15126 | };
|
15127 |
|
15128 | var getUnicodePropertyEscapeSet = function (value, isNegative) {
|
15129 | var parts = value.split('=');
|
15130 | var firstPart = parts[0];
|
15131 | var set;
|
15132 | if (parts.length == 1) {
|
15133 | set = handleLoneUnicodePropertyNameOrValue(firstPart);
|
15134 | } else {
|
15135 | // The pattern consists of two parts, i.e. `Property=Value`.
|
15136 | var property = unicodeMatchPropertyEcmascript(firstPart);
|
15137 | var value$1 = unicodeMatchPropertyValueEcmascript(property, parts[1]);
|
15138 | set = getUnicodePropertyValueSet(property, value$1);
|
15139 | }
|
15140 | if (isNegative) {
|
15141 | return UNICODE_SET.clone().remove(set);
|
15142 | }
|
15143 | return set.clone();
|
15144 | };
|
15145 |
|
15146 | // Given a range of code points, add any case-folded code points in that range
|
15147 | // to a set.
|
15148 | regenerate.prototype.iuAddRange = function(min, max) {
|
15149 | var $this = this;
|
15150 | do {
|
15151 | var folded = caseFold(min);
|
15152 | if (folded) {
|
15153 | $this.add(folded);
|
15154 | }
|
15155 | } while (++min <= max);
|
15156 | return $this;
|
15157 | };
|
15158 |
|
15159 | var update = function (item, pattern) {
|
15160 | var tree = parse$1(pattern, config.useUnicodeFlag ? 'u' : '');
|
15161 | switch (tree.type) {
|
15162 | case 'characterClass':
|
15163 | case 'group':
|
15164 | case 'value':
|
15165 | // No wrapping needed.
|
15166 | break;
|
15167 | default:
|
15168 | // Wrap the pattern in a non-capturing group.
|
15169 | tree = wrap(tree, pattern);
|
15170 | }
|
15171 | Object.assign(item, tree);
|
15172 | };
|
15173 |
|
15174 | var wrap = function (tree, pattern) {
|
15175 | // Wrap the pattern in a non-capturing group.
|
15176 | return {
|
15177 | 'type': 'group',
|
15178 | 'behavior': 'ignore',
|
15179 | 'body': [tree],
|
15180 | 'raw': ("(?:" + pattern + ")")
|
15181 | };
|
15182 | };
|
15183 |
|
15184 | var caseFold = function (codePoint) {
|
15185 | return iuMappings.get(codePoint) || false;
|
15186 | };
|
15187 |
|
15188 | var processCharacterClass = function (characterClassItem, regenerateOptions) {
|
15189 | var set = regenerate();
|
15190 | for (var i = 0, list = characterClassItem.body; i < list.length; i += 1) {
|
15191 | var item = list[i];
|
15192 |
|
15193 | switch (item.type) {
|
15194 | case 'value':
|
15195 | set.add(item.codePoint);
|
15196 | if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
|
15197 | var folded = caseFold(item.codePoint);
|
15198 | if (folded) {
|
15199 | set.add(folded);
|
15200 | }
|
15201 | }
|
15202 | break;
|
15203 | case 'characterClassRange':
|
15204 | var min = item.min.codePoint;
|
15205 | var max = item.max.codePoint;
|
15206 | set.addRange(min, max);
|
15207 | if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
|
15208 | set.iuAddRange(min, max);
|
15209 | }
|
15210 | break;
|
15211 | case 'characterClassEscape':
|
15212 | set.add(getCharacterClassEscapeSet(
|
15213 | item.value,
|
15214 | config.unicode,
|
15215 | config.ignoreCase
|
15216 | ));
|
15217 | break;
|
15218 | case 'unicodePropertyEscape':
|
15219 | set.add(getUnicodePropertyEscapeSet(item.value, item.negative));
|
15220 | break;
|
15221 | // The `default` clause is only here as a safeguard; it should never be
|
15222 | // reached. Code coverage tools should ignore it.
|
15223 | /* istanbul ignore next */
|
15224 | default:
|
15225 | throw new Error(("Unknown term type: " + (item.type)));
|
15226 | }
|
15227 | }
|
15228 | if (characterClassItem.negative) {
|
15229 | set = (config.unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
|
15230 | }
|
15231 | update(characterClassItem, set.toString(regenerateOptions));
|
15232 | return characterClassItem;
|
15233 | };
|
15234 |
|
15235 | var updateNamedReference = function (item, index) {
|
15236 | delete item.name;
|
15237 | item.matchIndex = index;
|
15238 | };
|
15239 |
|
15240 | var assertNoUnmatchedReferences = function (groups) {
|
15241 | var unmatchedReferencesNames = Object.keys(groups.unmatchedReferences);
|
15242 | if (unmatchedReferencesNames.length > 0) {
|
15243 | throw new Error(("Unknown group names: " + unmatchedReferencesNames));
|
15244 | }
|
15245 | };
|
15246 |
|
15247 | var processTerm = function (item, regenerateOptions, groups) {
|
15248 | switch (item.type) {
|
15249 | case 'dot':
|
15250 | update(
|
15251 | item,
|
15252 | getDotSet(config.unicode, config.dotAll).toString(regenerateOptions)
|
15253 | );
|
15254 | break;
|
15255 | case 'characterClass':
|
15256 | item = processCharacterClass(item, regenerateOptions);
|
15257 | break;
|
15258 | case 'unicodePropertyEscape':
|
15259 | update(
|
15260 | item,
|
15261 | getUnicodePropertyEscapeSet(item.value, item.negative)
|
15262 | .toString(regenerateOptions)
|
15263 | );
|
15264 | break;
|
15265 | case 'characterClassEscape':
|
15266 | update(
|
15267 | item,
|
15268 | getCharacterClassEscapeSet(
|
15269 | item.value,
|
15270 | config.unicode,
|
15271 | config.ignoreCase
|
15272 | ).toString(regenerateOptions)
|
15273 | );
|
15274 | break;
|
15275 | case 'group':
|
15276 | groups.lastIndex++;
|
15277 | if (item.name) {
|
15278 | var name = item.name.value;
|
15279 |
|
15280 | if (groups.names[name]) {
|
15281 | throw new Error(
|
15282 | ("Multiple groups with the same name (" + name + ") are not allowed.")
|
15283 | );
|
15284 | }
|
15285 |
|
15286 | var index = groups.lastIndex;
|
15287 | delete item.name;
|
15288 |
|
15289 | groups.names[name] = index;
|
15290 | if (groups.onNamedGroup) {
|
15291 | groups.onNamedGroup.call(null, name, index);
|
15292 | }
|
15293 |
|
15294 | if (groups.unmatchedReferences[name]) {
|
15295 | groups.unmatchedReferences[name].forEach(function (reference) {
|
15296 | updateNamedReference(reference, index);
|
15297 | });
|
15298 | delete groups.unmatchedReferences[name];
|
15299 | }
|
15300 | }
|
15301 | /* falls through */
|
15302 | case 'alternative':
|
15303 | case 'disjunction':
|
15304 | case 'quantifier':
|
15305 | item.body = item.body.map(function (term) {
|
15306 | return processTerm(term, regenerateOptions, groups);
|
15307 | });
|
15308 | break;
|
15309 | case 'value':
|
15310 | var codePoint = item.codePoint;
|
15311 | var set = regenerate(codePoint);
|
15312 | if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
|
15313 | var folded = caseFold(codePoint);
|
15314 | if (folded) {
|
15315 | set.add(folded);
|
15316 | }
|
15317 | }
|
15318 | update(item, set.toString(regenerateOptions));
|
15319 | break;
|
15320 | case 'reference':
|
15321 | if (item.name) {
|
15322 | var name$1 = item.name.value;
|
15323 | var index$1 = groups.names[name$1];
|
15324 | if (index$1) {
|
15325 | updateNamedReference(item, index$1);
|
15326 | break;
|
15327 | }
|
15328 |
|
15329 | if (!groups.unmatchedReferences[name$1]) {
|
15330 | groups.unmatchedReferences[name$1] = [];
|
15331 | }
|
15332 | // Keep track of references used before the corresponding group.
|
15333 | groups.unmatchedReferences[name$1].push(item);
|
15334 | }
|
15335 | break;
|
15336 | case 'anchor':
|
15337 | case 'empty':
|
15338 | case 'group':
|
15339 | // Nothing to do here.
|
15340 | break;
|
15341 | // The `default` clause is only here as a safeguard; it should never be
|
15342 | // reached. Code coverage tools should ignore it.
|
15343 | /* istanbul ignore next */
|
15344 | default:
|
15345 | throw new Error(("Unknown term type: " + (item.type)));
|
15346 | }
|
15347 | return item;
|
15348 | };
|
15349 |
|
15350 | var config = {
|
15351 | 'ignoreCase': false,
|
15352 | 'unicode': false,
|
15353 | 'dotAll': false,
|
15354 | 'useUnicodeFlag': false
|
15355 | };
|
15356 | var rewritePattern = function (pattern, flags, options) {
|
15357 | var regjsparserFeatures = {
|
15358 | 'unicodePropertyEscape': options && options.unicodePropertyEscape,
|
15359 | 'namedGroups': options && options.namedGroup,
|
15360 | 'lookbehind': options && options.lookbehind
|
15361 | };
|
15362 | config.ignoreCase = flags && flags.includes('i');
|
15363 | config.unicode = flags && flags.includes('u');
|
15364 | var supportDotAllFlag = options && options.dotAllFlag;
|
15365 | config.dotAll = supportDotAllFlag && flags && flags.includes('s');
|
15366 | config.useUnicodeFlag = options && options.useUnicodeFlag;
|
15367 | var regenerateOptions = {
|
15368 | 'hasUnicodeFlag': config.useUnicodeFlag,
|
15369 | 'bmpOnly': !config.unicode
|
15370 | };
|
15371 | var groups = {
|
15372 | 'onNamedGroup': options && options.onNamedGroup,
|
15373 | 'lastIndex': 0,
|
15374 | 'names': Object.create(null), // { [name]: index }
|
15375 | 'unmatchedReferences': Object.create(null) // { [name]: Array<reference> }
|
15376 | };
|
15377 | var tree = parse$1(pattern, flags, regjsparserFeatures);
|
15378 | // Note: `processTerm` mutates `tree` and `groups`.
|
15379 | processTerm(tree, regenerateOptions, groups);
|
15380 | assertNoUnmatchedReferences(groups);
|
15381 | return generate(tree);
|
15382 | };
|
15383 |
|
15384 | var rewritePattern_1 = rewritePattern;
|
15385 |
|
15386 | var nonAsciiLsOrPs = /[\u2028-\u2029]/g;
|
15387 |
|
15388 | var Literal = /*@__PURE__*/(function (Node) {
|
15389 | function Literal () {
|
15390 | Node.apply(this, arguments);
|
15391 | }
|
15392 |
|
15393 | if ( Node ) Literal.__proto__ = Node;
|
15394 | Literal.prototype = Object.create( Node && Node.prototype );
|
15395 | Literal.prototype.constructor = Literal;
|
15396 |
|
15397 | Literal.prototype.initialise = function initialise () {
|
15398 | if (typeof this.value === 'string') {
|
15399 | this.program.indentExclusionElements.push(this);
|
15400 | }
|
15401 | };
|
15402 |
|
15403 | Literal.prototype.transpile = function transpile (code, transforms) {
|
15404 | if (transforms.numericLiteral) {
|
15405 | if (this.raw.match(/^0[bo]/i)) {
|
15406 | code.overwrite(this.start, this.end, String(this.value), {
|
15407 | storeName: true,
|
15408 | contentOnly: true
|
15409 | });
|
15410 | }
|
15411 | }
|
15412 |
|
15413 | if (this.regex) {
|
15414 | var ref = this.regex;
|
15415 | var pattern = ref.pattern;
|
15416 | var flags = ref.flags;
|
15417 |
|
15418 | if (transforms.stickyRegExp && /y/.test(flags))
|
15419 | { CompileError.missingTransform('the regular expression sticky flag', 'stickyRegExp', this); }
|
15420 | if (transforms.unicodeRegExp && /u/.test(flags)) {
|
15421 | code.overwrite(
|
15422 | this.start,
|
15423 | this.end,
|
15424 | ("/" + (rewritePattern_1(pattern, flags)) + "/" + (flags.replace('u', ''))),
|
15425 | {
|
15426 | contentOnly: true
|
15427 | }
|
15428 | );
|
15429 | }
|
15430 | } else if (typeof this.value === "string" && this.value.match(nonAsciiLsOrPs)) {
|
15431 | code.overwrite(
|
15432 | this.start,
|
15433 | this.end,
|
15434 | this.raw.replace(nonAsciiLsOrPs, function (m) { return m == '\u2028' ? '\\u2028' : '\\u2029'; }),
|
15435 | {
|
15436 | contentOnly: true
|
15437 | }
|
15438 | );
|
15439 | }
|
15440 | };
|
15441 |
|
15442 | return Literal;
|
15443 | }(Node$1));
|
15444 |
|
15445 | var MemberExpression = /*@__PURE__*/(function (Node) {
|
15446 | function MemberExpression () {
|
15447 | Node.apply(this, arguments);
|
15448 | }
|
15449 |
|
15450 | if ( Node ) MemberExpression.__proto__ = Node;
|
15451 | MemberExpression.prototype = Object.create( Node && Node.prototype );
|
15452 | MemberExpression.prototype.constructor = MemberExpression;
|
15453 |
|
15454 | MemberExpression.prototype.transpile = function transpile (code, transforms) {
|
15455 | if (transforms.reservedProperties && reserved[this.property.name]) {
|
15456 | code.overwrite(this.object.end, this.property.start, "['");
|
15457 | code.appendLeft(this.property.end, "']");
|
15458 | }
|
15459 |
|
15460 | Node.prototype.transpile.call(this, code, transforms);
|
15461 | };
|
15462 |
|
15463 | return MemberExpression;
|
15464 | }(Node$1));
|
15465 |
|
15466 | var NewExpression = /*@__PURE__*/(function (Node) {
|
15467 | function NewExpression () {
|
15468 | Node.apply(this, arguments);
|
15469 | }
|
15470 |
|
15471 | if ( Node ) NewExpression.__proto__ = Node;
|
15472 | NewExpression.prototype = Object.create( Node && Node.prototype );
|
15473 | NewExpression.prototype.constructor = NewExpression;
|
15474 |
|
15475 | NewExpression.prototype.initialise = function initialise (transforms) {
|
15476 | if (transforms.spreadRest && this.arguments.length) {
|
15477 | var lexicalBoundary = this.findLexicalBoundary();
|
15478 |
|
15479 | var i = this.arguments.length;
|
15480 | while (i--) {
|
15481 | var arg = this.arguments[i];
|
15482 | if (arg.type === 'SpreadElement' && isArguments(arg.argument)) {
|
15483 | this.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
|
15484 | break;
|
15485 | }
|
15486 | }
|
15487 | }
|
15488 |
|
15489 | Node.prototype.initialise.call(this, transforms);
|
15490 | };
|
15491 |
|
15492 | NewExpression.prototype.transpile = function transpile (code, transforms) {
|
15493 | Node.prototype.transpile.call(this, code, transforms);
|
15494 |
|
15495 | if (transforms.spreadRest && this.arguments.length) {
|
15496 | inlineSpreads(code, this, this.arguments);
|
15497 | // this.arguments.length may have changed, must retest.
|
15498 | }
|
15499 |
|
15500 | if (transforms.spreadRest && this.arguments.length) {
|
15501 | var firstArgument = this.arguments[0];
|
15502 | var isNew = true;
|
15503 | var hasSpreadElements = spread(
|
15504 | code,
|
15505 | this.arguments,
|
15506 | firstArgument.start,
|
15507 | this.argumentsArrayAlias,
|
15508 | isNew
|
15509 | );
|
15510 |
|
15511 | if (hasSpreadElements) {
|
15512 | code.prependRight(
|
15513 | this.start + 'new'.length,
|
15514 | ' (Function.prototype.bind.apply('
|
15515 | );
|
15516 | code.overwrite(
|
15517 | this.callee.end,
|
15518 | firstArgument.start,
|
15519 | ', [ null ].concat( '
|
15520 | );
|
15521 | code.appendLeft(this.end, ' ))');
|
15522 | }
|
15523 | }
|
15524 |
|
15525 | if (this.arguments.length) {
|
15526 | removeTrailingComma(code, this.arguments[this.arguments.length - 1].end);
|
15527 | }
|
15528 | };
|
15529 |
|
15530 | return NewExpression;
|
15531 | }(Node$1));
|
15532 |
|
15533 | var ObjectExpression = /*@__PURE__*/(function (Node) {
|
15534 | function ObjectExpression () {
|
15535 | Node.apply(this, arguments);
|
15536 | }
|
15537 |
|
15538 | if ( Node ) ObjectExpression.__proto__ = Node;
|
15539 | ObjectExpression.prototype = Object.create( Node && Node.prototype );
|
15540 | ObjectExpression.prototype.constructor = ObjectExpression;
|
15541 |
|
15542 | ObjectExpression.prototype.transpile = function transpile (code, transforms) {
|
15543 | var ref;
|
15544 |
|
15545 | Node.prototype.transpile.call(this, code, transforms);
|
15546 |
|
15547 | var firstPropertyStart = this.start + 1;
|
15548 | var spreadPropertyCount = 0;
|
15549 | var computedPropertyCount = 0;
|
15550 | var firstSpreadProperty = null;
|
15551 | var firstComputedProperty = null;
|
15552 |
|
15553 | for (var i = 0; i < this.properties.length; ++i) {
|
15554 | var prop = this.properties[i];
|
15555 | if (prop.type === 'SpreadElement') {
|
15556 | // First see if we can inline the spread, to save needing objectAssign.
|
15557 | var argument = prop.argument;
|
15558 | if (
|
15559 | argument.type === 'ObjectExpression' || (
|
15560 | argument.type === 'Literal' &&
|
15561 | typeof argument.value !== 'string'
|
15562 | )
|
15563 | ) {
|
15564 | if (argument.type === 'ObjectExpression' && argument.properties.length > 0) {
|
15565 | // Strip the `...{` and the `}` with a possible trailing comma before it,
|
15566 | // leaving just the possible trailing comma after it.
|
15567 | code.remove(prop.start, argument.properties[0].start);
|
15568 | code.remove(argument.properties[argument.properties.length - 1].end, prop.end);
|
15569 | (ref = this.properties).splice.apply(ref, [ i, 1 ].concat( argument.properties ));
|
15570 | i--;
|
15571 | } else {
|
15572 | // An empty object, boolean, null, undefined, number or regexp (but NOT
|
15573 | // string) will spread to nothing, so just remove the element altogether,
|
15574 | // including a possible trailing comma.
|
15575 | code.remove(prop.start, i === this.properties.length - 1
|
15576 | ? prop.end
|
15577 | : this.properties[i + 1].start);
|
15578 | this.properties.splice(i, 1);
|
15579 | i--;
|
15580 | }
|
15581 | } else {
|
15582 | spreadPropertyCount += 1;
|
15583 | if (firstSpreadProperty === null) { firstSpreadProperty = i; }
|
15584 | }
|
15585 | } else if (prop.computed && transforms.computedProperty) {
|
15586 | computedPropertyCount += 1;
|
15587 | if (firstComputedProperty === null) { firstComputedProperty = i; }
|
15588 | }
|
15589 | }
|
15590 |
|
15591 | if (spreadPropertyCount && !transforms.objectRestSpread && !(computedPropertyCount && transforms.computedProperty)) {
|
15592 | spreadPropertyCount = 0;
|
15593 | firstSpreadProperty = null;
|
15594 | } else if (spreadPropertyCount) {
|
15595 | if (!this.program.options.objectAssign) {
|
15596 | throw new CompileError(
|
15597 | "Object spread operator requires specified objectAssign option with 'Object.assign' or polyfill helper.",
|
15598 | this
|
15599 | );
|
15600 | }
|
15601 | var i$1 = this.properties.length;
|
15602 | while (i$1--) {
|
15603 | var prop$1 = this.properties[i$1];
|
15604 |
|
15605 | // enclose run of non-spread properties in curlies
|
15606 | if (prop$1.type === 'Property' && !computedPropertyCount) {
|
15607 | var lastProp = this.properties[i$1 - 1];
|
15608 | var nextProp = this.properties[i$1 + 1];
|
15609 |
|
15610 | if (!lastProp || lastProp.type !== 'Property') {
|
15611 | code.prependRight(prop$1.start, '{');
|
15612 | }
|
15613 |
|
15614 | if (!nextProp || nextProp.type !== 'Property') {
|
15615 | code.appendLeft(prop$1.end, '}');
|
15616 | }
|
15617 | }
|
15618 |
|
15619 | // Remove ellipsis on spread property
|
15620 | if (prop$1.type === 'SpreadElement') {
|
15621 | code.remove(prop$1.start, prop$1.argument.start);
|
15622 | code.remove(prop$1.argument.end, prop$1.end);
|
15623 | }
|
15624 | }
|
15625 |
|
15626 | // wrap the whole thing in Object.assign
|
15627 | firstPropertyStart = this.properties[0].start;
|
15628 | if (!computedPropertyCount) {
|
15629 | code.overwrite(
|
15630 | this.start,
|
15631 | firstPropertyStart,
|
15632 | ((this.program.options.objectAssign) + "({}, ")
|
15633 | );
|
15634 | code.overwrite(
|
15635 | this.properties[this.properties.length - 1].end,
|
15636 | this.end,
|
15637 | ')'
|
15638 | );
|
15639 | } else if (this.properties[0].type === 'SpreadElement') {
|
15640 | code.overwrite(
|
15641 | this.start,
|
15642 | firstPropertyStart,
|
15643 | ((this.program.options.objectAssign) + "({}, ")
|
15644 | );
|
15645 | code.remove(this.end - 1, this.end);
|
15646 | code.appendRight(this.end, ')');
|
15647 | } else {
|
15648 | code.prependLeft(this.start, ((this.program.options.objectAssign) + "("));
|
15649 | code.appendRight(this.end, ')');
|
15650 | }
|
15651 | }
|
15652 |
|
15653 | if (computedPropertyCount && transforms.computedProperty) {
|
15654 | var i0 = this.getIndentation();
|
15655 |
|
15656 | var isSimpleAssignment;
|
15657 | var name;
|
15658 |
|
15659 | if (
|
15660 | this.parent.type === 'VariableDeclarator' &&
|
15661 | this.parent.parent.declarations.length === 1 &&
|
15662 | this.parent.id.type === 'Identifier'
|
15663 | ) {
|
15664 | isSimpleAssignment = true;
|
15665 | name = this.parent.id.alias || this.parent.id.name; // TODO is this right?
|
15666 | } else if (
|
15667 | this.parent.type === 'AssignmentExpression' &&
|
15668 | this.parent.parent.type === 'ExpressionStatement' &&
|
15669 | this.parent.left.type === 'Identifier'
|
15670 | ) {
|
15671 | isSimpleAssignment = true;
|
15672 | name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
|
15673 | } else if (
|
15674 | this.parent.type === 'AssignmentPattern' &&
|
15675 | this.parent.left.type === 'Identifier'
|
15676 | ) {
|
15677 | isSimpleAssignment = true;
|
15678 | name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
|
15679 | }
|
15680 |
|
15681 | if (spreadPropertyCount) { isSimpleAssignment = false; }
|
15682 |
|
15683 | // handle block scoping
|
15684 | name = this.findScope(false).resolveName(name);
|
15685 |
|
15686 | var start = firstPropertyStart;
|
15687 | var end = this.end;
|
15688 |
|
15689 | if (isSimpleAssignment) ; else {
|
15690 | if (
|
15691 | firstSpreadProperty === null ||
|
15692 | firstComputedProperty < firstSpreadProperty
|
15693 | ) {
|
15694 | name = this.findScope(true).createDeclaration('obj');
|
15695 |
|
15696 | code.prependRight(this.start, ("( " + name + " = "));
|
15697 | } else { name = null; } // We don't actually need this variable
|
15698 | }
|
15699 |
|
15700 | var len = this.properties.length;
|
15701 | var lastComputedProp;
|
15702 | var sawNonComputedProperty = false;
|
15703 | var isFirst = true;
|
15704 |
|
15705 | for (var i$2 = 0; i$2 < len; i$2 += 1) {
|
15706 | var prop$2 = this.properties[i$2];
|
15707 | var moveStart = i$2 > 0 ? this.properties[i$2 - 1].end : start;
|
15708 |
|
15709 | if (
|
15710 | prop$2.type === 'Property' &&
|
15711 | (prop$2.computed || (lastComputedProp && !spreadPropertyCount))
|
15712 | ) {
|
15713 | if (i$2 === 0) { moveStart = this.start + 1; } // Trim leading whitespace
|
15714 | lastComputedProp = prop$2;
|
15715 |
|
15716 | if (!name) {
|
15717 | name = this.findScope(true).createDeclaration('obj');
|
15718 |
|
15719 | var propId = name + (prop$2.computed ? '' : '.');
|
15720 | code.appendRight(prop$2.start, ("( " + name + " = {}, " + propId));
|
15721 | } else {
|
15722 | var propId$1 =
|
15723 | (isSimpleAssignment ? (";\n" + i0 + name) : (", " + name)) +
|
15724 | (prop$2.key.type === 'Literal' || prop$2.computed ? '' : '.');
|
15725 |
|
15726 | if (moveStart < prop$2.start) {
|
15727 | code.overwrite(moveStart, prop$2.start, propId$1);
|
15728 | } else {
|
15729 | code.prependRight(prop$2.start, propId$1);
|
15730 | }
|
15731 | }
|
15732 |
|
15733 | var c = prop$2.key.end;
|
15734 | if (prop$2.computed) {
|
15735 | while (code.original[c] !== ']') { c += 1; }
|
15736 | c += 1;
|
15737 | }
|
15738 | if (prop$2.key.type === 'Literal' && !prop$2.computed) {
|
15739 | code.overwrite(
|
15740 | prop$2.start,
|
15741 | prop$2.value.start,
|
15742 | '[' + code.slice(prop$2.start, prop$2.key.end) + '] = '
|
15743 | );
|
15744 | } else if (prop$2.shorthand || (prop$2.method && !prop$2.computed && transforms.conciseMethodProperty)) {
|
15745 | // Replace : with = if Property::transpile inserted the :
|
15746 | code.overwrite(
|
15747 | prop$2.key.start,
|
15748 | prop$2.key.end,
|
15749 | code.slice(prop$2.key.start, prop$2.key.end).replace(/:/, ' =')
|
15750 | );
|
15751 | } else {
|
15752 | if (prop$2.value.start > c) { code.remove(c, prop$2.value.start); }
|
15753 | code.prependLeft(c, ' = ');
|
15754 | }
|
15755 |
|
15756 | // This duplicates behavior from Property::transpile which is disabled
|
15757 | // for computed properties or if conciseMethodProperty is false
|
15758 | if (prop$2.method && (prop$2.computed || !transforms.conciseMethodProperty)) {
|
15759 | if (prop$2.value.generator) { code.remove(prop$2.start, prop$2.key.start); }
|
15760 | code.prependRight(prop$2.value.start, ("function" + (prop$2.value.generator ? '*' : '') + " "));
|
15761 | }
|
15762 | } else if (prop$2.type === 'SpreadElement') {
|
15763 | if (name && i$2 > 0) {
|
15764 | if (!lastComputedProp) {
|
15765 | lastComputedProp = this.properties[i$2 - 1];
|
15766 | }
|
15767 | code.appendLeft(lastComputedProp.end, (", " + name + " )"));
|
15768 |
|
15769 | lastComputedProp = null;
|
15770 | name = null;
|
15771 | }
|
15772 | } else {
|
15773 | if (!isFirst && spreadPropertyCount) {
|
15774 | // We are in an Object.assign context, so we need to wrap regular properties
|
15775 | code.prependRight(prop$2.start, '{');
|
15776 | code.appendLeft(prop$2.end, '}');
|
15777 | }
|
15778 | sawNonComputedProperty = true;
|
15779 | }
|
15780 | if (isFirst && (prop$2.type === 'SpreadElement' || prop$2.computed)) {
|
15781 | var beginEnd = sawNonComputedProperty
|
15782 | ? this.properties[this.properties.length - 1].end
|
15783 | : this.end - 1;
|
15784 | // Trim trailing comma because it can easily become a leading comma which is illegal
|
15785 | if (code.original[beginEnd] == ',') { ++beginEnd; }
|
15786 | var closing = code.slice(beginEnd, end);
|
15787 | code.prependLeft(moveStart, closing);
|
15788 | code.remove(beginEnd, end);
|
15789 | isFirst = false;
|
15790 | }
|
15791 |
|
15792 | // Clean up some extranous whitespace
|
15793 | var c$1 = prop$2.end;
|
15794 | if (i$2 < len - 1 && !sawNonComputedProperty) {
|
15795 | while (code.original[c$1] !== ',') { c$1 += 1; }
|
15796 | } else if (i$2 == len - 1) { c$1 = this.end; }
|
15797 | if (prop$2.end != c$1) { code.overwrite(prop$2.end, c$1, '', {contentOnly: true}); }
|
15798 | }
|
15799 |
|
15800 | if (!isSimpleAssignment && name) {
|
15801 | code.appendLeft(lastComputedProp.end, (", " + name + " )"));
|
15802 | }
|
15803 | }
|
15804 | };
|
15805 |
|
15806 | return ObjectExpression;
|
15807 | }(Node$1));
|
15808 |
|
15809 | var Property = /*@__PURE__*/(function (Node) {
|
15810 | function Property () {
|
15811 | Node.apply(this, arguments);
|
15812 | }
|
15813 |
|
15814 | if ( Node ) Property.__proto__ = Node;
|
15815 | Property.prototype = Object.create( Node && Node.prototype );
|
15816 | Property.prototype.constructor = Property;
|
15817 |
|
15818 | Property.prototype.initialise = function initialise (transforms) {
|
15819 | if ((this.kind === 'get' || this.kind === 'set') && transforms.getterSetter) {
|
15820 | CompileError.missingTransform("getters and setters", "getterSetter", this);
|
15821 | }
|
15822 | Node.prototype.initialise.call(this, transforms);
|
15823 | };
|
15824 |
|
15825 | Property.prototype.transpile = function transpile (code, transforms) {
|
15826 | Node.prototype.transpile.call(this, code, transforms);
|
15827 |
|
15828 | if (
|
15829 | transforms.conciseMethodProperty &&
|
15830 | !this.computed &&
|
15831 | this.parent.type !== 'ObjectPattern'
|
15832 | ) {
|
15833 | if (this.shorthand) {
|
15834 | code.prependRight(this.start, ((this.key.name) + ": "));
|
15835 | } else if (this.method) {
|
15836 | var name = '';
|
15837 | if (this.program.options.namedFunctionExpressions !== false) {
|
15838 | if (
|
15839 | this.key.type === 'Literal' &&
|
15840 | typeof this.key.value === 'number'
|
15841 | ) {
|
15842 | name = '';
|
15843 | } else if (this.key.type === 'Identifier') {
|
15844 | if (
|
15845 | reserved[this.key.name] ||
|
15846 | !/^[a-z_$][a-z0-9_$]*$/i.test(this.key.name) ||
|
15847 | this.value.body.scope.references[this.key.name]
|
15848 | ) {
|
15849 | name = this.findScope(true).createIdentifier(this.key.name);
|
15850 | } else {
|
15851 | name = this.key.name;
|
15852 | }
|
15853 | } else {
|
15854 | name = this.findScope(true).createIdentifier(this.key.value);
|
15855 | }
|
15856 | name = ' ' + name;
|
15857 | }
|
15858 |
|
15859 | if (this.start < this.key.start) { code.remove(this.start, this.key.start); }
|
15860 | code.appendLeft(
|
15861 | this.key.end,
|
15862 | (": " + (this.value.async ? 'async ' : '') + "function" + (this.value.generator ? '*' : '') + name)
|
15863 | );
|
15864 | }
|
15865 | }
|
15866 |
|
15867 | if (transforms.reservedProperties && reserved[this.key.name]) {
|
15868 | code.prependRight(this.key.start, "'");
|
15869 | code.appendLeft(this.key.end, "'");
|
15870 | }
|
15871 | };
|
15872 |
|
15873 | return Property;
|
15874 | }(Node$1));
|
15875 |
|
15876 | var ReturnStatement = /*@__PURE__*/(function (Node) {
|
15877 | function ReturnStatement () {
|
15878 | Node.apply(this, arguments);
|
15879 | }
|
15880 |
|
15881 | if ( Node ) ReturnStatement.__proto__ = Node;
|
15882 | ReturnStatement.prototype = Object.create( Node && Node.prototype );
|
15883 | ReturnStatement.prototype.constructor = ReturnStatement;
|
15884 |
|
15885 | ReturnStatement.prototype.initialise = function initialise (transforms) {
|
15886 | this.loop = this.findNearest(loopStatement);
|
15887 | this.nearestFunction = this.findNearest(/Function/);
|
15888 |
|
15889 | if (
|
15890 | this.loop &&
|
15891 | (!this.nearestFunction || this.loop.depth > this.nearestFunction.depth)
|
15892 | ) {
|
15893 | this.loop.canReturn = true;
|
15894 | this.shouldWrap = true;
|
15895 | }
|
15896 |
|
15897 | if (this.argument) { this.argument.initialise(transforms); }
|
15898 | };
|
15899 |
|
15900 | ReturnStatement.prototype.transpile = function transpile (code, transforms) {
|
15901 | var shouldWrap =
|
15902 | this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;
|
15903 |
|
15904 | if (this.argument) {
|
15905 | if (shouldWrap) { code.prependRight(this.argument.start, "{ v: "); }
|
15906 | this.argument.transpile(code, transforms);
|
15907 | if (shouldWrap) { code.appendLeft(this.argument.end, " }"); }
|
15908 | } else if (shouldWrap) {
|
15909 | code.appendLeft(this.start + 6, ' {}');
|
15910 | }
|
15911 | };
|
15912 |
|
15913 | return ReturnStatement;
|
15914 | }(Node$1));
|
15915 |
|
15916 | var Super = /*@__PURE__*/(function (Node) {
|
15917 | function Super () {
|
15918 | Node.apply(this, arguments);
|
15919 | }
|
15920 |
|
15921 | if ( Node ) Super.__proto__ = Node;
|
15922 | Super.prototype = Object.create( Node && Node.prototype );
|
15923 | Super.prototype.constructor = Super;
|
15924 |
|
15925 | Super.prototype.initialise = function initialise (transforms) {
|
15926 | if (transforms.classes) {
|
15927 | this.method = this.findNearest('MethodDefinition');
|
15928 | if (!this.method)
|
15929 | { throw new CompileError('use of super outside class method', this); }
|
15930 |
|
15931 | var parentClass = this.findNearest('ClassBody').parent;
|
15932 | this.superClassName =
|
15933 | parentClass.superClass && (parentClass.superClass.name || 'superclass');
|
15934 |
|
15935 | if (!this.superClassName)
|
15936 | { throw new CompileError('super used in base class', this); }
|
15937 |
|
15938 | this.isCalled =
|
15939 | this.parent.type === 'CallExpression' && this === this.parent.callee;
|
15940 |
|
15941 | if (this.method.kind !== 'constructor' && this.isCalled) {
|
15942 | throw new CompileError(
|
15943 | 'super() not allowed outside class constructor',
|
15944 | this
|
15945 | );
|
15946 | }
|
15947 |
|
15948 | this.isMember = this.parent.type === 'MemberExpression';
|
15949 |
|
15950 | if (!this.isCalled && !this.isMember) {
|
15951 | throw new CompileError(
|
15952 | 'Unexpected use of `super` (expected `super(...)` or `super.*`)',
|
15953 | this
|
15954 | );
|
15955 | }
|
15956 | }
|
15957 |
|
15958 | if (transforms.arrow) {
|
15959 | var lexicalBoundary = this.findLexicalBoundary();
|
15960 | var arrowFunction = this.findNearest('ArrowFunctionExpression');
|
15961 | var loop = this.findNearest(loopStatement);
|
15962 |
|
15963 | if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) {
|
15964 | this.thisAlias = lexicalBoundary.getThisAlias();
|
15965 | }
|
15966 |
|
15967 | if (
|
15968 | loop &&
|
15969 | loop.body.contains(this) &&
|
15970 | loop.depth > lexicalBoundary.depth
|
15971 | ) {
|
15972 | this.thisAlias = lexicalBoundary.getThisAlias();
|
15973 | }
|
15974 | }
|
15975 | };
|
15976 |
|
15977 | Super.prototype.transpile = function transpile (code, transforms) {
|
15978 | if (transforms.classes) {
|
15979 | var expression =
|
15980 | this.isCalled || this.method.static
|
15981 | ? this.superClassName
|
15982 | : ((this.superClassName) + ".prototype");
|
15983 |
|
15984 | code.overwrite(this.start, this.end, expression, {
|
15985 | storeName: true,
|
15986 | contentOnly: true
|
15987 | });
|
15988 |
|
15989 | var callExpression = this.isCalled ? this.parent : this.parent.parent;
|
15990 |
|
15991 | if (callExpression && callExpression.type === 'CallExpression') {
|
15992 | if (!this.noCall) {
|
15993 | // special case – `super( ...args )`
|
15994 | code.appendLeft(callExpression.callee.end, '.call');
|
15995 | }
|
15996 |
|
15997 | var thisAlias = this.thisAlias || 'this';
|
15998 |
|
15999 | if (callExpression.arguments.length) {
|
16000 | code.appendLeft(callExpression.arguments[0].start, (thisAlias + ", "));
|
16001 | } else {
|
16002 | code.appendLeft(callExpression.end - 1, ("" + thisAlias));
|
16003 | }
|
16004 | }
|
16005 | }
|
16006 | };
|
16007 |
|
16008 | return Super;
|
16009 | }(Node$1));
|
16010 |
|
16011 | var TaggedTemplateExpression = /*@__PURE__*/(function (Node) {
|
16012 | function TaggedTemplateExpression () {
|
16013 | Node.apply(this, arguments);
|
16014 | }
|
16015 |
|
16016 | if ( Node ) TaggedTemplateExpression.__proto__ = Node;
|
16017 | TaggedTemplateExpression.prototype = Object.create( Node && Node.prototype );
|
16018 | TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
|
16019 |
|
16020 | TaggedTemplateExpression.prototype.initialise = function initialise (transforms) {
|
16021 | if (
|
16022 | transforms.templateString &&
|
16023 | !transforms.dangerousTaggedTemplateString
|
16024 | ) {
|
16025 | CompileError.missingTransform(
|
16026 | "tagged template strings", "templateString", this, "dangerousTaggedTemplateString"
|
16027 | );
|
16028 | }
|
16029 |
|
16030 | Node.prototype.initialise.call(this, transforms);
|
16031 | };
|
16032 |
|
16033 | TaggedTemplateExpression.prototype.transpile = function transpile (code, transforms) {
|
16034 | if (transforms.templateString && transforms.dangerousTaggedTemplateString) {
|
16035 | var ordered = this.quasi.expressions
|
16036 | .concat(this.quasi.quasis)
|
16037 | .sort(function (a, b) { return a.start - b.start; });
|
16038 |
|
16039 | var program = this.program;
|
16040 | var rootScope = program.body.scope;
|
16041 |
|
16042 | // insert strings at start
|
16043 | var templateStrings = this.quasi.quasis.map(function (quasi) { return JSON.stringify(quasi.value.cooked); }
|
16044 | ).join(', ');
|
16045 |
|
16046 | var templateObject = this.program.templateLiteralQuasis[templateStrings];
|
16047 | if (!templateObject) {
|
16048 | templateObject = rootScope.createIdentifier('templateObject');
|
16049 | code.prependLeft(this.program.prependAt, ("var " + templateObject + " = Object.freeze([" + templateStrings + "]);\n"));
|
16050 |
|
16051 | this.program.templateLiteralQuasis[templateStrings] = templateObject;
|
16052 | }
|
16053 |
|
16054 | code.overwrite(
|
16055 | this.tag.end,
|
16056 | ordered[0].start,
|
16057 | ("(" + templateObject)
|
16058 | );
|
16059 |
|
16060 | var lastIndex = ordered[0].start;
|
16061 | ordered.forEach(function (node) {
|
16062 | if (node.type === 'TemplateElement') {
|
16063 | code.remove(lastIndex, node.end);
|
16064 | } else {
|
16065 | code.overwrite(lastIndex, node.start, ', ');
|
16066 | }
|
16067 |
|
16068 | lastIndex = node.end;
|
16069 | });
|
16070 |
|
16071 | code.overwrite(lastIndex, this.end, ')');
|
16072 | }
|
16073 |
|
16074 | Node.prototype.transpile.call(this, code, transforms);
|
16075 | };
|
16076 |
|
16077 | return TaggedTemplateExpression;
|
16078 | }(Node$1));
|
16079 |
|
16080 | var TemplateElement = /*@__PURE__*/(function (Node) {
|
16081 | function TemplateElement () {
|
16082 | Node.apply(this, arguments);
|
16083 | }
|
16084 |
|
16085 | if ( Node ) TemplateElement.__proto__ = Node;
|
16086 | TemplateElement.prototype = Object.create( Node && Node.prototype );
|
16087 | TemplateElement.prototype.constructor = TemplateElement;
|
16088 |
|
16089 | TemplateElement.prototype.initialise = function initialise () {
|
16090 | this.program.indentExclusionElements.push(this);
|
16091 | };
|
16092 |
|
16093 | return TemplateElement;
|
16094 | }(Node$1));
|
16095 |
|
16096 | var TemplateLiteral = /*@__PURE__*/(function (Node) {
|
16097 | function TemplateLiteral () {
|
16098 | Node.apply(this, arguments);
|
16099 | }
|
16100 |
|
16101 | if ( Node ) TemplateLiteral.__proto__ = Node;
|
16102 | TemplateLiteral.prototype = Object.create( Node && Node.prototype );
|
16103 | TemplateLiteral.prototype.constructor = TemplateLiteral;
|
16104 |
|
16105 | TemplateLiteral.prototype.transpile = function transpile (code, transforms) {
|
16106 | Node.prototype.transpile.call(this, code, transforms);
|
16107 |
|
16108 | if (
|
16109 | transforms.templateString &&
|
16110 | this.parent.type !== 'TaggedTemplateExpression'
|
16111 | ) {
|
16112 | var ordered = this.expressions
|
16113 | .concat(this.quasis)
|
16114 | .sort(function (a, b) { return a.start - b.start || a.end - b.end; })
|
16115 | .filter(function (node, i) {
|
16116 | // include all expressions
|
16117 | if (node.type !== 'TemplateElement') { return true; }
|
16118 |
|
16119 | // include all non-empty strings
|
16120 | if (node.value.raw) { return true; }
|
16121 |
|
16122 | // exclude all empty strings not at the head
|
16123 | return !i;
|
16124 | });
|
16125 |
|
16126 | // special case – we may be able to skip the first element,
|
16127 | // if it's the empty string, but only if the second and
|
16128 | // third elements aren't both expressions (since they maybe
|
16129 | // be numeric, and `1 + 2 + '3' === '33'`)
|
16130 | if (ordered.length >= 3) {
|
16131 | var first = ordered[0];
|
16132 | var third = ordered[2];
|
16133 | if (
|
16134 | first.type === 'TemplateElement' &&
|
16135 | first.value.raw === '' &&
|
16136 | third.type === 'TemplateElement'
|
16137 | ) {
|
16138 | ordered.shift();
|
16139 | }
|
16140 | }
|
16141 |
|
16142 | var parenthesise =
|
16143 | (this.quasis.length !== 1 || this.expressions.length !== 0) &&
|
16144 | this.parent.type !== 'TemplateLiteral' &&
|
16145 | this.parent.type !== 'AssignmentExpression' &&
|
16146 | this.parent.type !== 'AssignmentPattern' &&
|
16147 | this.parent.type !== 'VariableDeclarator' &&
|
16148 | (this.parent.type !== 'BinaryExpression' ||
|
16149 | this.parent.operator !== '+');
|
16150 |
|
16151 | if (parenthesise) { code.appendRight(this.start, '('); }
|
16152 |
|
16153 | var lastIndex = this.start;
|
16154 |
|
16155 | ordered.forEach(function (node, i) {
|
16156 | var prefix = i === 0 ? (parenthesise ? '(' : '') : ' + ';
|
16157 |
|
16158 | if (node.type === 'TemplateElement') {
|
16159 | code.overwrite(
|
16160 | lastIndex,
|
16161 | node.end,
|
16162 | prefix + JSON.stringify(node.value.cooked)
|
16163 | );
|
16164 | } else {
|
16165 | var parenthesise$1 = node.type !== 'Identifier'; // TODO other cases where it's safe
|
16166 |
|
16167 | if (parenthesise$1) { prefix += '('; }
|
16168 |
|
16169 | code.remove(lastIndex, node.start);
|
16170 |
|
16171 | if (prefix) { code.prependRight(node.start, prefix); }
|
16172 | if (parenthesise$1) { code.appendLeft(node.end, ')'); }
|
16173 | }
|
16174 |
|
16175 | lastIndex = node.end;
|
16176 | });
|
16177 |
|
16178 | if (parenthesise) { code.appendLeft(lastIndex, ')'); }
|
16179 | code.overwrite(lastIndex, this.end, "", { contentOnly: true });
|
16180 | }
|
16181 | };
|
16182 |
|
16183 | return TemplateLiteral;
|
16184 | }(Node$1));
|
16185 |
|
16186 | var ThisExpression = /*@__PURE__*/(function (Node) {
|
16187 | function ThisExpression () {
|
16188 | Node.apply(this, arguments);
|
16189 | }
|
16190 |
|
16191 | if ( Node ) ThisExpression.__proto__ = Node;
|
16192 | ThisExpression.prototype = Object.create( Node && Node.prototype );
|
16193 | ThisExpression.prototype.constructor = ThisExpression;
|
16194 |
|
16195 | ThisExpression.prototype.initialise = function initialise (transforms) {
|
16196 | var lexicalBoundary = this.findLexicalBoundary();
|
16197 |
|
16198 | if (transforms.letConst) {
|
16199 | // save all loops up to the lexical boundary in case we need
|
16200 | // to alias them later for block-scoped declarations
|
16201 | var node = this.findNearest(loopStatement);
|
16202 | while (node && node.depth > lexicalBoundary.depth) {
|
16203 | node.thisRefs.push(this);
|
16204 | node = node.parent.findNearest(loopStatement);
|
16205 | }
|
16206 | }
|
16207 |
|
16208 | if (transforms.arrow) {
|
16209 | var arrowFunction = this.findNearest('ArrowFunctionExpression');
|
16210 |
|
16211 | if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) {
|
16212 | this.alias = lexicalBoundary.getThisAlias();
|
16213 | }
|
16214 | }
|
16215 | };
|
16216 |
|
16217 | ThisExpression.prototype.transpile = function transpile (code) {
|
16218 | if (this.alias) {
|
16219 | code.overwrite(this.start, this.end, this.alias, {
|
16220 | storeName: true,
|
16221 | contentOnly: true
|
16222 | });
|
16223 | }
|
16224 | };
|
16225 |
|
16226 | return ThisExpression;
|
16227 | }(Node$1));
|
16228 |
|
16229 | var UpdateExpression = /*@__PURE__*/(function (Node) {
|
16230 | function UpdateExpression () {
|
16231 | Node.apply(this, arguments);
|
16232 | }
|
16233 |
|
16234 | if ( Node ) UpdateExpression.__proto__ = Node;
|
16235 | UpdateExpression.prototype = Object.create( Node && Node.prototype );
|
16236 | UpdateExpression.prototype.constructor = UpdateExpression;
|
16237 |
|
16238 | UpdateExpression.prototype.initialise = function initialise (transforms) {
|
16239 | if (this.argument.type === 'Identifier') {
|
16240 | var declaration = this.findScope(false).findDeclaration(
|
16241 | this.argument.name
|
16242 | );
|
16243 | // special case – https://gitlab.com/Rich-Harris/buble/issues/150
|
16244 | var statement = declaration && declaration.node.ancestor(3);
|
16245 | if (
|
16246 | statement &&
|
16247 | statement.type === 'ForStatement' &&
|
16248 | statement.body.contains(this)
|
16249 | ) {
|
16250 | statement.reassigned[this.argument.name] = true;
|
16251 | }
|
16252 | }
|
16253 |
|
16254 | Node.prototype.initialise.call(this, transforms);
|
16255 | };
|
16256 |
|
16257 | UpdateExpression.prototype.transpile = function transpile (code, transforms) {
|
16258 | if (this.argument.type === 'Identifier') {
|
16259 | // Do this check after everything has been initialized to find
|
16260 | // shadowing declarations after this expression
|
16261 | checkConst(this.argument, this.findScope(false));
|
16262 | }
|
16263 | Node.prototype.transpile.call(this, code, transforms);
|
16264 | };
|
16265 |
|
16266 | return UpdateExpression;
|
16267 | }(Node$1));
|
16268 |
|
16269 | var VariableDeclaration = /*@__PURE__*/(function (Node) {
|
16270 | function VariableDeclaration () {
|
16271 | Node.apply(this, arguments);
|
16272 | }
|
16273 |
|
16274 | if ( Node ) VariableDeclaration.__proto__ = Node;
|
16275 | VariableDeclaration.prototype = Object.create( Node && Node.prototype );
|
16276 | VariableDeclaration.prototype.constructor = VariableDeclaration;
|
16277 |
|
16278 | VariableDeclaration.prototype.initialise = function initialise (transforms) {
|
16279 | this.scope = this.findScope(this.kind === 'var');
|
16280 | this.declarations.forEach(function (declarator) { return declarator.initialise(transforms); });
|
16281 | };
|
16282 |
|
16283 | VariableDeclaration.prototype.transpile = function transpile (code, transforms) {
|
16284 | var this$1 = this;
|
16285 |
|
16286 | var i0 = this.getIndentation();
|
16287 | var kind = this.kind;
|
16288 |
|
16289 | if (transforms.letConst && kind !== 'var') {
|
16290 | kind = 'var';
|
16291 | code.overwrite(this.start, this.start + this.kind.length, kind, {
|
16292 | contentOnly: true,
|
16293 | storeName: true
|
16294 | });
|
16295 | }
|
16296 |
|
16297 | if (transforms.destructuring && this.parent.type !== 'ForOfStatement' && this.parent.type !== 'ForInStatement') {
|
16298 | var c = this.start;
|
16299 | var lastDeclaratorIsPattern;
|
16300 |
|
16301 | this.declarations.forEach(function (declarator, i) {
|
16302 | declarator.transpile(code, transforms);
|
16303 |
|
16304 | if (declarator.id.type === 'Identifier') {
|
16305 | if (i > 0 && this$1.declarations[i - 1].id.type !== 'Identifier') {
|
16306 | code.overwrite(c, declarator.id.start, "var ");
|
16307 | }
|
16308 | } else {
|
16309 | var inline = loopStatement.test(this$1.parent.type);
|
16310 |
|
16311 | if (i === 0) {
|
16312 | code.remove(c, declarator.id.start);
|
16313 | } else {
|
16314 | code.overwrite(c, declarator.id.start, (";\n" + i0));
|
16315 | }
|
16316 |
|
16317 | var simple =
|
16318 | declarator.init.type === 'Identifier' && !declarator.init.rewritten;
|
16319 |
|
16320 | var name = simple
|
16321 | ? (declarator.init.alias || declarator.init.name)
|
16322 | : declarator.findScope(true).createIdentifier('ref');
|
16323 |
|
16324 | c = declarator.start;
|
16325 |
|
16326 | var statementGenerators = [];
|
16327 |
|
16328 | if (simple) {
|
16329 | code.remove(declarator.id.end, declarator.end);
|
16330 | } else {
|
16331 | statementGenerators.push(function (start, prefix, suffix) {
|
16332 | code.prependRight(declarator.id.end, ("var " + name));
|
16333 | code.appendLeft(declarator.init.end, ("" + suffix));
|
16334 | code.move(declarator.id.end, declarator.end, start);
|
16335 | });
|
16336 | }
|
16337 |
|
16338 | var scope = declarator.findScope(false);
|
16339 | destructure(
|
16340 | code,
|
16341 | function (id) { return scope.createIdentifier(id); },
|
16342 | function (ref) {
|
16343 | var name = ref.name;
|
16344 |
|
16345 | return scope.resolveName(name);
|
16346 | },
|
16347 | declarator.id,
|
16348 | name,
|
16349 | inline,
|
16350 | statementGenerators
|
16351 | );
|
16352 |
|
16353 | var prefix = inline ? 'var ' : '';
|
16354 | var suffix = inline ? ", " : (";\n" + i0);
|
16355 | statementGenerators.forEach(function (fn, j) {
|
16356 | if (
|
16357 | i === this$1.declarations.length - 1 &&
|
16358 | j === statementGenerators.length - 1
|
16359 | ) {
|
16360 | suffix = inline ? '' : ';';
|
16361 | }
|
16362 |
|
16363 | fn(declarator.start, j === 0 ? prefix : '', suffix);
|
16364 | });
|
16365 | }
|
16366 |
|
16367 | c = declarator.end;
|
16368 | lastDeclaratorIsPattern = declarator.id.type !== 'Identifier';
|
16369 | });
|
16370 |
|
16371 | if (lastDeclaratorIsPattern && this.end > c) {
|
16372 | code.overwrite(c, this.end, '', { contentOnly: true });
|
16373 | }
|
16374 | } else {
|
16375 | this.declarations.forEach(function (declarator) {
|
16376 | declarator.transpile(code, transforms);
|
16377 | });
|
16378 | }
|
16379 | };
|
16380 |
|
16381 | return VariableDeclaration;
|
16382 | }(Node$1));
|
16383 |
|
16384 | var VariableDeclarator = /*@__PURE__*/(function (Node) {
|
16385 | function VariableDeclarator () {
|
16386 | Node.apply(this, arguments);
|
16387 | }
|
16388 |
|
16389 | if ( Node ) VariableDeclarator.__proto__ = Node;
|
16390 | VariableDeclarator.prototype = Object.create( Node && Node.prototype );
|
16391 | VariableDeclarator.prototype.constructor = VariableDeclarator;
|
16392 |
|
16393 | VariableDeclarator.prototype.initialise = function initialise (transforms) {
|
16394 | var kind = this.parent.kind;
|
16395 | if (kind === 'let' && this.parent.parent.type === 'ForStatement') {
|
16396 | kind = 'for.let'; // special case...
|
16397 | }
|
16398 |
|
16399 | this.parent.scope.addDeclaration(this.id, kind);
|
16400 | Node.prototype.initialise.call(this, transforms);
|
16401 | };
|
16402 |
|
16403 | VariableDeclarator.prototype.transpile = function transpile (code, transforms) {
|
16404 | if (!this.init && transforms.letConst && this.parent.kind !== 'var') {
|
16405 | var inLoop = this.findNearest(
|
16406 | /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/
|
16407 | );
|
16408 | if (
|
16409 | inLoop &&
|
16410 | !/Function/.test(inLoop.type) &&
|
16411 | !this.isLeftDeclaratorOfLoop()
|
16412 | ) {
|
16413 | code.appendLeft(this.id.end, ' = (void 0)');
|
16414 | }
|
16415 | }
|
16416 |
|
16417 | if (this.id) { this.id.transpile(code, transforms); }
|
16418 | if (this.init) { this.init.transpile(code, transforms); }
|
16419 | };
|
16420 |
|
16421 | VariableDeclarator.prototype.isLeftDeclaratorOfLoop = function isLeftDeclaratorOfLoop () {
|
16422 | return (
|
16423 | this.parent &&
|
16424 | this.parent.type === 'VariableDeclaration' &&
|
16425 | this.parent.parent &&
|
16426 | (this.parent.parent.type === 'ForInStatement' ||
|
16427 | this.parent.parent.type === 'ForOfStatement') &&
|
16428 | this.parent.parent.left &&
|
16429 | this.parent.parent.left.declarations[0] === this
|
16430 | );
|
16431 | };
|
16432 |
|
16433 | return VariableDeclarator;
|
16434 | }(Node$1));
|
16435 |
|
16436 | var types$2 = {
|
16437 | ArrayExpression: ArrayExpression,
|
16438 | ArrowFunctionExpression: ArrowFunctionExpression,
|
16439 | AssignmentExpression: AssignmentExpression,
|
16440 | AwaitExpression: AwaitExpression,
|
16441 | BinaryExpression: BinaryExpression,
|
16442 | BreakStatement: BreakStatement,
|
16443 | CallExpression: CallExpression,
|
16444 | CatchClause: CatchClause,
|
16445 | ClassBody: ClassBody,
|
16446 | ClassDeclaration: ClassDeclaration,
|
16447 | ClassExpression: ClassExpression,
|
16448 | ContinueStatement: ContinueStatement,
|
16449 | DoWhileStatement: LoopStatement,
|
16450 | ExportNamedDeclaration: ExportNamedDeclaration,
|
16451 | ExportDefaultDeclaration: ExportDefaultDeclaration,
|
16452 | ForStatement: ForStatement,
|
16453 | ForInStatement: ForInStatement,
|
16454 | ForOfStatement: ForOfStatement,
|
16455 | FunctionDeclaration: FunctionDeclaration,
|
16456 | FunctionExpression: FunctionExpression,
|
16457 | Identifier: Identifier,
|
16458 | IfStatement: IfStatement,
|
16459 | Import: Import,
|
16460 | ImportDeclaration: ImportDeclaration,
|
16461 | ImportDefaultSpecifier: ImportDefaultSpecifier,
|
16462 | ImportSpecifier: ImportSpecifier,
|
16463 | JSXAttribute: JSXAttribute,
|
16464 | JSXClosingElement: JSXClosingElement,
|
16465 | JSXClosingFragment: JSXClosingFragment,
|
16466 | JSXElement: JSXElement,
|
16467 | JSXExpressionContainer: JSXExpressionContainer,
|
16468 | JSXFragment: JSXFragment,
|
16469 | JSXOpeningElement: JSXOpeningElement,
|
16470 | JSXOpeningFragment: JSXOpeningFragment,
|
16471 | JSXSpreadAttribute: JSXSpreadAttribute,
|
16472 | Literal: Literal,
|
16473 | MemberExpression: MemberExpression,
|
16474 | NewExpression: NewExpression,
|
16475 | ObjectExpression: ObjectExpression,
|
16476 | Property: Property,
|
16477 | ReturnStatement: ReturnStatement,
|
16478 | Super: Super,
|
16479 | TaggedTemplateExpression: TaggedTemplateExpression,
|
16480 | TemplateElement: TemplateElement,
|
16481 | TemplateLiteral: TemplateLiteral,
|
16482 | ThisExpression: ThisExpression,
|
16483 | UpdateExpression: UpdateExpression,
|
16484 | VariableDeclaration: VariableDeclaration,
|
16485 | VariableDeclarator: VariableDeclarator,
|
16486 | WhileStatement: LoopStatement
|
16487 | };
|
16488 |
|
16489 | var keys = {
|
16490 | Program: ['body'],
|
16491 | Literal: []
|
16492 | };
|
16493 |
|
16494 | var statementsWithBlocks = {
|
16495 | IfStatement: 'consequent',
|
16496 | ForStatement: 'body',
|
16497 | ForInStatement: 'body',
|
16498 | ForOfStatement: 'body',
|
16499 | WhileStatement: 'body',
|
16500 | DoWhileStatement: 'body',
|
16501 | ArrowFunctionExpression: 'body'
|
16502 | };
|
16503 |
|
16504 | function wrap$1(raw, parent) {
|
16505 | if (!raw) { return; }
|
16506 |
|
16507 | if ('length' in raw) {
|
16508 | var i = raw.length;
|
16509 | while (i--) { wrap$1(raw[i], parent); }
|
16510 | return;
|
16511 | }
|
16512 |
|
16513 | // with e.g. shorthand properties, key and value are
|
16514 | // the same node. We don't want to wrap an object twice
|
16515 | if (raw.__wrapped) { return; }
|
16516 | raw.__wrapped = true;
|
16517 |
|
16518 | if (!keys[raw.type]) {
|
16519 | keys[raw.type] = Object.keys(raw).filter(
|
16520 | function (key) { return typeof raw[key] === 'object'; }
|
16521 | );
|
16522 | }
|
16523 |
|
16524 | // special case – body-less if/for/while statements. TODO others?
|
16525 | var bodyType = statementsWithBlocks[raw.type];
|
16526 | if (bodyType && raw[bodyType].type !== 'BlockStatement') {
|
16527 | var expression = raw[bodyType];
|
16528 |
|
16529 | // create a synthetic block statement, otherwise all hell
|
16530 | // breaks loose when it comes to block scoping
|
16531 | raw[bodyType] = {
|
16532 | start: expression.start,
|
16533 | end: expression.end,
|
16534 | type: 'BlockStatement',
|
16535 | body: [expression],
|
16536 | synthetic: true
|
16537 | };
|
16538 | }
|
16539 |
|
16540 | raw.parent = parent;
|
16541 | raw.program = parent.program || parent;
|
16542 | raw.depth = parent.depth + 1;
|
16543 | raw.keys = keys[raw.type];
|
16544 | raw.indentation = undefined;
|
16545 |
|
16546 | for (var i$1 = 0, list = keys[raw.type]; i$1 < list.length; i$1 += 1) {
|
16547 | var key = list[i$1];
|
16548 |
|
16549 | wrap$1(raw[key], raw);
|
16550 | }
|
16551 |
|
16552 | raw.program.magicString.addSourcemapLocation(raw.start);
|
16553 | raw.program.magicString.addSourcemapLocation(raw.end);
|
16554 |
|
16555 | var type =
|
16556 | (raw.type === 'BlockStatement' ? BlockStatement : types$2[raw.type]) || Node$1;
|
16557 | raw.__proto__ = type.prototype;
|
16558 | }
|
16559 |
|
16560 | function Program(source, ast, transforms, options) {
|
16561 | this.type = 'Root';
|
16562 |
|
16563 | // options
|
16564 | this.jsx = options.jsx || 'React.createElement';
|
16565 | this.jsxFragment = options.jsxFragment || 'React.Fragment';
|
16566 | this.options = options;
|
16567 |
|
16568 | this.source = source;
|
16569 | this.magicString = new MagicString(source);
|
16570 |
|
16571 | this.ast = ast;
|
16572 | this.depth = 0;
|
16573 |
|
16574 | wrap$1((this.body = ast), this);
|
16575 | this.body.__proto__ = BlockStatement.prototype;
|
16576 |
|
16577 | this.templateLiteralQuasis = Object.create(null);
|
16578 | for (var i = 0; i < this.body.body.length; ++i) {
|
16579 | if (!this.body.body[i].directive) {
|
16580 | this.prependAt = this.body.body[i].start;
|
16581 | break;
|
16582 | }
|
16583 | }
|
16584 | this.objectWithoutPropertiesHelper = null;
|
16585 |
|
16586 | this.indentExclusionElements = [];
|
16587 | this.body.initialise(transforms);
|
16588 |
|
16589 | this.indentExclusions = Object.create(null);
|
16590 | for (var i$2 = 0, list = this.indentExclusionElements; i$2 < list.length; i$2 += 1) {
|
16591 | var node = list[i$2];
|
16592 |
|
16593 | for (var i$1 = node.start; i$1 < node.end; i$1 += 1) {
|
16594 | this.indentExclusions[i$1] = true;
|
16595 | }
|
16596 | }
|
16597 |
|
16598 | this.body.transpile(this.magicString, transforms);
|
16599 | }
|
16600 |
|
16601 | Program.prototype = {
|
16602 | export: function export$1(options) {
|
16603 | if ( options === void 0 ) options = {};
|
16604 |
|
16605 | return {
|
16606 | code: this.magicString.toString(),
|
16607 | map: this.magicString.generateMap({
|
16608 | file: options.file,
|
16609 | source: options.source,
|
16610 | includeContent: options.includeContent !== false
|
16611 | })
|
16612 | };
|
16613 | },
|
16614 |
|
16615 | findNearest: function findNearest() {
|
16616 | return null;
|
16617 | },
|
16618 |
|
16619 | findScope: function findScope() {
|
16620 | return null;
|
16621 | },
|
16622 |
|
16623 | getObjectWithoutPropertiesHelper: function getObjectWithoutPropertiesHelper(code) {
|
16624 | if (!this.objectWithoutPropertiesHelper) {
|
16625 | this.objectWithoutPropertiesHelper = this.body.scope.createIdentifier('objectWithoutProperties');
|
16626 | code.prependLeft(this.prependAt, "function " + (this.objectWithoutPropertiesHelper) + " (obj, exclude) { " +
|
16627 | "var target = {}; for (var k in obj) " +
|
16628 | "if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) " +
|
16629 | "target[k] = obj[k]; return target; }\n"
|
16630 | );
|
16631 | }
|
16632 | return this.objectWithoutPropertiesHelper;
|
16633 | }
|
16634 | };
|
16635 |
|
16636 | var matrix = {
|
16637 | chrome: {
|
16638 | 48: 610719,
|
16639 | 49: 652287,
|
16640 | 50: 783359,
|
16641 | 51: 783359,
|
16642 | 52: 1045503,
|
16643 | 53: 1045503,
|
16644 | 54: 1045503,
|
16645 | 55: 3142655,
|
16646 | 56: 3142655,
|
16647 | 57: 3142655,
|
16648 | 58: 4191231,
|
16649 | 59: 4191231,
|
16650 | 60: 8385535,
|
16651 | 61: 8385535,
|
16652 | 62: 8385535,
|
16653 | 63: 8385535,
|
16654 | 64: 8385535,
|
16655 | 65: 8385535,
|
16656 | 66: 8385535,
|
16657 | 67: 8385535,
|
16658 | 68: 8385535,
|
16659 | 69: 8385535,
|
16660 | 70: 8385535,
|
16661 | 71: 8385535
|
16662 | },
|
16663 | firefox: {
|
16664 | 43: 643515,
|
16665 | 44: 643515,
|
16666 | 45: 643519,
|
16667 | 46: 774591,
|
16668 | 47: 774655,
|
16669 | 48: 774655,
|
16670 | 49: 774655,
|
16671 | 50: 774655,
|
16672 | 51: 775167,
|
16673 | 52: 4191231,
|
16674 | 53: 4191231,
|
16675 | 54: 4191231,
|
16676 | 55: 8385535,
|
16677 | 56: 8385535,
|
16678 | 57: 8385535,
|
16679 | 58: 8385535,
|
16680 | 59: 8385535,
|
16681 | 60: 8385535,
|
16682 | 61: 8385535,
|
16683 | 62: 8385535,
|
16684 | 63: 8385535,
|
16685 | 64: 8385535
|
16686 | },
|
16687 | safari: {
|
16688 | 8: 524297,
|
16689 | 9: 594141,
|
16690 | 10: 1831935,
|
16691 | '10.1': 4191231,
|
16692 | 11: 4191231,
|
16693 | '11.1': 8385535,
|
16694 | 12: 8385535
|
16695 | },
|
16696 | ie: {
|
16697 | 8: 0,
|
16698 | 9: 524289,
|
16699 | 10: 524289,
|
16700 | 11: 524289 // no let/const in for loops
|
16701 | },
|
16702 | edge: {
|
16703 | 12: 610459,
|
16704 | 13: 774559,
|
16705 | 14: 2085887,
|
16706 | 15: 4183039,
|
16707 | 16: 4183039,
|
16708 | 17: 4183039,
|
16709 | 18: 4183039,
|
16710 | 19: 4183039
|
16711 | },
|
16712 | node: {
|
16713 | '0.10': 524289,
|
16714 | '0.12': 524417,
|
16715 | 4: 594335,
|
16716 | 5: 594335,
|
16717 | 6: 783359,
|
16718 | 8: 4191231,
|
16719 | '8.3': 8385535,
|
16720 | '8.7': 8385535,
|
16721 | '8.10': 8385535
|
16722 | }
|
16723 | };
|
16724 |
|
16725 | var features = [
|
16726 | 'getterSetter',
|
16727 | 'arrow',
|
16728 | 'classes',
|
16729 | 'computedProperty',
|
16730 | 'conciseMethodProperty',
|
16731 | 'defaultParameter',
|
16732 | 'destructuring',
|
16733 | 'forOf',
|
16734 | 'generator',
|
16735 | 'letConst',
|
16736 | 'moduleExport',
|
16737 | 'moduleImport',
|
16738 | 'numericLiteral',
|
16739 | 'parameterDestructuring',
|
16740 | 'spreadRest',
|
16741 | 'stickyRegExp',
|
16742 | 'templateString',
|
16743 | 'unicodeRegExp',
|
16744 |
|
16745 | // ES2016
|
16746 | 'exponentiation',
|
16747 |
|
16748 | // additional transforms, not from
|
16749 | // https://featuretests.io
|
16750 | 'reservedProperties',
|
16751 |
|
16752 | 'trailingFunctionCommas',
|
16753 | 'asyncAwait',
|
16754 | 'objectRestSpread'
|
16755 | ];
|
16756 |
|
16757 | var version$1 = "0.20.0";
|
16758 |
|
16759 | var parser$1 = Parser.extend(acornDynamicImport, acornJsx());
|
16760 |
|
16761 | var dangerousTransforms = ['dangerousTaggedTemplateString', 'dangerousForOf'];
|
16762 |
|
16763 | function target(target) {
|
16764 | var targets = Object.keys(target);
|
16765 | var bitmask = targets.length
|
16766 | ? 8388607
|
16767 | : 524289;
|
16768 |
|
16769 | Object.keys(target).forEach(function (environment) {
|
16770 | var versions = matrix[environment];
|
16771 | if (!versions)
|
16772 | { throw new Error(
|
16773 | ("Unknown environment '" + environment + "'. Please raise an issue at https://github.com/bublejs/buble/issues")
|
16774 | ); }
|
16775 |
|
16776 | var targetVersion = target[environment];
|
16777 | if (!(targetVersion in versions))
|
16778 | { throw new Error(
|
16779 | ("Support data exists for the following versions of " + environment + ": " + (Object.keys(
|
16780 | versions
|
16781 | ).join(
|
16782 | ', '
|
16783 | )) + ". Please raise an issue at https://github.com/bublejs/buble/issues")
|
16784 | ); }
|
16785 | var support = versions[targetVersion];
|
16786 |
|
16787 | bitmask &= support;
|
16788 | });
|
16789 |
|
16790 | var transforms = Object.create(null);
|
16791 | features.forEach(function (name, i) {
|
16792 | transforms[name] = !(bitmask & (1 << i));
|
16793 | });
|
16794 |
|
16795 | dangerousTransforms.forEach(function (name) {
|
16796 | transforms[name] = false;
|
16797 | });
|
16798 |
|
16799 | return transforms;
|
16800 | }
|
16801 |
|
16802 | function transform(source, options) {
|
16803 | if ( options === void 0 ) options = {};
|
16804 |
|
16805 | var ast;
|
16806 | var jsx = null;
|
16807 |
|
16808 | try {
|
16809 | ast = parser$1.parse(source, {
|
16810 | ecmaVersion: 10,
|
16811 | preserveParens: true,
|
16812 | sourceType: 'module',
|
16813 | allowAwaitOutsideFunction: true,
|
16814 | allowReturnOutsideFunction: true,
|
16815 | allowHashBang: true,
|
16816 | onComment: function (block, text) {
|
16817 | if (!jsx) {
|
16818 | var match = /@jsx\s+([^\s]+)/.exec(text);
|
16819 | if (match) { jsx = match[1]; }
|
16820 | }
|
16821 | }
|
16822 | });
|
16823 | options.jsx = jsx || options.jsx;
|
16824 | } catch (err) {
|
16825 | err.snippet = getSnippet(source, err.loc);
|
16826 | err.toString = function () { return ((err.name) + ": " + (err.message) + "\n" + (err.snippet)); };
|
16827 | throw err;
|
16828 | }
|
16829 |
|
16830 | var transforms = target(options.target || {});
|
16831 | Object.keys(options.transforms || {}).forEach(function (name) {
|
16832 | if (name === 'modules') {
|
16833 | if (!('moduleImport' in options.transforms))
|
16834 | { transforms.moduleImport = options.transforms.modules; }
|
16835 | if (!('moduleExport' in options.transforms))
|
16836 | { transforms.moduleExport = options.transforms.modules; }
|
16837 | return;
|
16838 | }
|
16839 |
|
16840 | if (!(name in transforms)) { throw new Error(("Unknown transform '" + name + "'")); }
|
16841 | transforms[name] = options.transforms[name];
|
16842 | });
|
16843 | if (options.objectAssign === true) { options.objectAssign = 'Object.assign'; }
|
16844 | return new Program(source, ast, transforms, options).export(options);
|
16845 | }
|
16846 |
|
16847 | exports.VERSION = version$1;
|
16848 | exports.target = target;
|
16849 | exports.transform = transform;
|
16850 |
|
16851 | Object.defineProperty(exports, '__esModule', { value: true });
|
16852 |
|
16853 | })));
|
16854 | //# sourceMappingURL=buble-browser-deps.umd.js.map
|