UNPKG

179 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3 typeof define === 'function' && define.amd ? define(['exports'], factory) :
4 (factory((global.acorn = {})));
5}(this, (function (exports) { 'use strict';
6
7// Reserved word lists for various dialects of the language
8
9var reservedWords = {
10 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
11 5: "class enum extends super const export import",
12 6: "enum",
13 strict: "implements interface let package private protected public static yield",
14 strictBind: "eval arguments"
15};
16
17// And the keywords
18
19var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
20
21var keywords = {
22 5: ecma5AndLessKeywords,
23 6: ecma5AndLessKeywords + " const class extends export import super"
24};
25
26var keywordRelationalOperator = /^in(stanceof)?$/;
27
28// ## Character categories
29
30// Big ugly regular expressions that match characters in the
31// whitespace, identifier, and identifier-start categories. These
32// are only applied when a character is found to actually have a
33// code point above 128.
34// Generated by `bin/generate-identifier-regex.js`.
35
36var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\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-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312e\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fea\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ae\ua7b0-\ua7b7\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
37var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d4-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\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-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\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\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
38
39var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
40var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
41
42nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
43
44// These are a run-length and offset encoded representation of the
45// >0xffff code points that are a valid part of identifiers. The
46// offset starts at 0x10000, and each pair of numbers represents an
47// offset to the next range, and then a size of the range. They were
48// generated by bin/generate-identifier-regex.js
49
50// eslint-disable-next-line comma-spacing
51var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,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,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,25,391,63,32,0,257,0,11,39,8,0,22,0,12,39,3,3,55,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,698,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,65,1,31,6124,20,754,9486,286,82,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,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541];
52
53// eslint-disable-next-line comma-spacing
54var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,7,0,161,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,87,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,9,280,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,19719,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239];
55
56// This has a complexity linear to the value of the code. The
57// assumption is that looking up astral identifier characters is
58// rare.
59function isInAstralSet(code, set) {
60 var pos = 0x10000;
61 for (var i = 0; i < set.length; i += 2) {
62 pos += set[i];
63 if (pos > code) { return false }
64 pos += set[i + 1];
65 if (pos >= code) { return true }
66 }
67}
68
69// Test whether a given character code starts an identifier.
70
71function isIdentifierStart(code, astral) {
72 if (code < 65) { return code === 36 }
73 if (code < 91) { return true }
74 if (code < 97) { return code === 95 }
75 if (code < 123) { return true }
76 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
77 if (astral === false) { return false }
78 return isInAstralSet(code, astralIdentifierStartCodes)
79}
80
81// Test whether a given character is part of an identifier.
82
83function isIdentifierChar(code, astral) {
84 if (code < 48) { return code === 36 }
85 if (code < 58) { return true }
86 if (code < 65) { return false }
87 if (code < 91) { return true }
88 if (code < 97) { return code === 95 }
89 if (code < 123) { return true }
90 if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
91 if (astral === false) { return false }
92 return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
93}
94
95// ## Token types
96
97// The assignment of fine-grained, information-carrying type objects
98// allows the tokenizer to store the information it has about a
99// token in a way that is very cheap for the parser to look up.
100
101// All token type variables start with an underscore, to make them
102// easy to recognize.
103
104// The `beforeExpr` property is used to disambiguate between regular
105// expressions and divisions. It is set on all token types that can
106// be followed by an expression (thus, a slash after them would be a
107// regular expression).
108//
109// The `startsExpr` property is used to check if the token ends a
110// `yield` expression. It is set on all token types that either can
111// directly start an expression (like a quotation mark) or can
112// continue an expression (like the body of a string).
113//
114// `isLoop` marks a keyword as starting a loop, which is important
115// to know when parsing a label, in order to allow or disallow
116// continue jumps to that label.
117
118var TokenType = function TokenType(label, conf) {
119 if ( conf === void 0 ) conf = {};
120
121 this.label = label;
122 this.keyword = conf.keyword;
123 this.beforeExpr = !!conf.beforeExpr;
124 this.startsExpr = !!conf.startsExpr;
125 this.isLoop = !!conf.isLoop;
126 this.isAssign = !!conf.isAssign;
127 this.prefix = !!conf.prefix;
128 this.postfix = !!conf.postfix;
129 this.binop = conf.binop || null;
130 this.updateContext = null;
131};
132
133function binop(name, prec) {
134 return new TokenType(name, {beforeExpr: true, binop: prec})
135}
136var beforeExpr = {beforeExpr: true};
137var startsExpr = {startsExpr: true};
138
139// Map keyword names to token types.
140
141var keywords$1 = {};
142
143// Succinct definitions of keyword token types
144function kw(name, options) {
145 if ( options === void 0 ) options = {};
146
147 options.keyword = name;
148 return keywords$1[name] = new TokenType(name, options)
149}
150
151var types = {
152 num: new TokenType("num", startsExpr),
153 regexp: new TokenType("regexp", startsExpr),
154 string: new TokenType("string", startsExpr),
155 name: new TokenType("name", startsExpr),
156 eof: new TokenType("eof"),
157
158 // Punctuation token types.
159 bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
160 bracketR: new TokenType("]"),
161 braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
162 braceR: new TokenType("}"),
163 parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
164 parenR: new TokenType(")"),
165 comma: new TokenType(",", beforeExpr),
166 semi: new TokenType(";", beforeExpr),
167 colon: new TokenType(":", beforeExpr),
168 dot: new TokenType("."),
169 question: new TokenType("?", beforeExpr),
170 arrow: new TokenType("=>", beforeExpr),
171 template: new TokenType("template"),
172 invalidTemplate: new TokenType("invalidTemplate"),
173 ellipsis: new TokenType("...", beforeExpr),
174 backQuote: new TokenType("`", startsExpr),
175 dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
176
177 // Operators. These carry several kinds of properties to help the
178 // parser use them properly (the presence of these properties is
179 // what categorizes them as operators).
180 //
181 // `binop`, when present, specifies that this operator is a binary
182 // operator, and will refer to its precedence.
183 //
184 // `prefix` and `postfix` mark the operator as a prefix or postfix
185 // unary operator.
186 //
187 // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
188 // binary operators with a very low precedence, that should result
189 // in AssignmentExpression nodes.
190
191 eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
192 assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
193 incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
194 prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
195 logicalOR: binop("||", 1),
196 logicalAND: binop("&&", 2),
197 bitwiseOR: binop("|", 3),
198 bitwiseXOR: binop("^", 4),
199 bitwiseAND: binop("&", 5),
200 equality: binop("==/!=/===/!==", 6),
201 relational: binop("</>/<=/>=", 7),
202 bitShift: binop("<</>>/>>>", 8),
203 plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
204 modulo: binop("%", 10),
205 star: binop("*", 10),
206 slash: binop("/", 10),
207 starstar: new TokenType("**", {beforeExpr: true}),
208
209 // Keyword token types.
210 _break: kw("break"),
211 _case: kw("case", beforeExpr),
212 _catch: kw("catch"),
213 _continue: kw("continue"),
214 _debugger: kw("debugger"),
215 _default: kw("default", beforeExpr),
216 _do: kw("do", {isLoop: true, beforeExpr: true}),
217 _else: kw("else", beforeExpr),
218 _finally: kw("finally"),
219 _for: kw("for", {isLoop: true}),
220 _function: kw("function", startsExpr),
221 _if: kw("if"),
222 _return: kw("return", beforeExpr),
223 _switch: kw("switch"),
224 _throw: kw("throw", beforeExpr),
225 _try: kw("try"),
226 _var: kw("var"),
227 _const: kw("const"),
228 _while: kw("while", {isLoop: true}),
229 _with: kw("with"),
230 _new: kw("new", {beforeExpr: true, startsExpr: true}),
231 _this: kw("this", startsExpr),
232 _super: kw("super", startsExpr),
233 _class: kw("class", startsExpr),
234 _extends: kw("extends", beforeExpr),
235 _export: kw("export"),
236 _import: kw("import"),
237 _null: kw("null", startsExpr),
238 _true: kw("true", startsExpr),
239 _false: kw("false", startsExpr),
240 _in: kw("in", {beforeExpr: true, binop: 7}),
241 _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
242 _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
243 _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
244 _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
245};
246
247// Matches a whole line break (where CRLF is considered a single
248// line break). Used to count lines.
249
250var lineBreak = /\r\n?|\n|\u2028|\u2029/;
251var lineBreakG = new RegExp(lineBreak.source, "g");
252
253function isNewLine(code) {
254 return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
255}
256
257var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
258
259var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
260
261var ref = Object.prototype;
262var hasOwnProperty = ref.hasOwnProperty;
263var toString = ref.toString;
264
265// Checks if an object has a property.
266
267function has(obj, propName) {
268 return hasOwnProperty.call(obj, propName)
269}
270
271var isArray = Array.isArray || (function (obj) { return (
272 toString.call(obj) === "[object Array]"
273); });
274
275// These are used when `options.locations` is on, for the
276// `startLoc` and `endLoc` properties.
277
278var Position = function Position(line, col) {
279 this.line = line;
280 this.column = col;
281};
282
283Position.prototype.offset = function offset (n) {
284 return new Position(this.line, this.column + n)
285};
286
287var SourceLocation = function SourceLocation(p, start, end) {
288 this.start = start;
289 this.end = end;
290 if (p.sourceFile !== null) { this.source = p.sourceFile; }
291};
292
293// The `getLineInfo` function is mostly useful when the
294// `locations` option is off (for performance reasons) and you
295// want to find the line/column position for a given character
296// offset. `input` should be the code string that the offset refers
297// into.
298
299function getLineInfo(input, offset) {
300 for (var line = 1, cur = 0;;) {
301 lineBreakG.lastIndex = cur;
302 var match = lineBreakG.exec(input);
303 if (match && match.index < offset) {
304 ++line;
305 cur = match.index + match[0].length;
306 } else {
307 return new Position(line, offset - cur)
308 }
309 }
310}
311
312// A second optional argument can be given to further configure
313// the parser process. These options are recognized:
314
315var defaultOptions = {
316 // `ecmaVersion` indicates the ECMAScript version to parse. Must
317 // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
318 // for strict mode, the set of reserved words, and support for
319 // new syntax features. The default is 7.
320 ecmaVersion: 7,
321 // `sourceType` indicates the mode the code should be parsed in.
322 // Can be either `"script"` or `"module"`. This influences global
323 // strict mode and parsing of `import` and `export` declarations.
324 sourceType: "script",
325 // `onInsertedSemicolon` can be a callback that will be called
326 // when a semicolon is automatically inserted. It will be passed
327 // th position of the comma as an offset, and if `locations` is
328 // enabled, it is given the location as a `{line, column}` object
329 // as second argument.
330 onInsertedSemicolon: null,
331 // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
332 // trailing commas.
333 onTrailingComma: null,
334 // By default, reserved words are only enforced if ecmaVersion >= 5.
335 // Set `allowReserved` to a boolean value to explicitly turn this on
336 // an off. When this option has the value "never", reserved words
337 // and keywords can also not be used as property names.
338 allowReserved: null,
339 // When enabled, a return at the top level is not considered an
340 // error.
341 allowReturnOutsideFunction: false,
342 // When enabled, import/export statements are not constrained to
343 // appearing at the top of the program.
344 allowImportExportEverywhere: false,
345 // When enabled, hashbang directive in the beginning of file
346 // is allowed and treated as a line comment.
347 allowHashBang: false,
348 // When `locations` is on, `loc` properties holding objects with
349 // `start` and `end` properties in `{line, column}` form (with
350 // line being 1-based and column 0-based) will be attached to the
351 // nodes.
352 locations: false,
353 // A function can be passed as `onToken` option, which will
354 // cause Acorn to call that function with object in the same
355 // format as tokens returned from `tokenizer().getToken()`. Note
356 // that you are not allowed to call the parser from the
357 // callback—that will corrupt its internal state.
358 onToken: null,
359 // A function can be passed as `onComment` option, which will
360 // cause Acorn to call that function with `(block, text, start,
361 // end)` parameters whenever a comment is skipped. `block` is a
362 // boolean indicating whether this is a block (`/* */`) comment,
363 // `text` is the content of the comment, and `start` and `end` are
364 // character offsets that denote the start and end of the comment.
365 // When the `locations` option is on, two more parameters are
366 // passed, the full `{line, column}` locations of the start and
367 // end of the comments. Note that you are not allowed to call the
368 // parser from the callback—that will corrupt its internal state.
369 onComment: null,
370 // Nodes have their start and end characters offsets recorded in
371 // `start` and `end` properties (directly on the node, rather than
372 // the `loc` object, which holds line/column data. To also add a
373 // [semi-standardized][range] `range` property holding a `[start,
374 // end]` array with the same numbers, set the `ranges` option to
375 // `true`.
376 //
377 // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
378 ranges: false,
379 // It is possible to parse multiple files into a single AST by
380 // passing the tree produced by parsing the first file as
381 // `program` option in subsequent parses. This will add the
382 // toplevel forms of the parsed file to the `Program` (top) node
383 // of an existing parse tree.
384 program: null,
385 // When `locations` is on, you can pass this to record the source
386 // file in every node's `loc` object.
387 sourceFile: null,
388 // This value, if given, is stored in every node, whether
389 // `locations` is on or off.
390 directSourceFile: null,
391 // When enabled, parenthesized expressions are represented by
392 // (non-standard) ParenthesizedExpression nodes
393 preserveParens: false,
394 plugins: {}
395};
396
397// Interpret and default an options object
398
399function getOptions(opts) {
400 var options = {};
401
402 for (var opt in defaultOptions)
403 { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
404
405 if (options.ecmaVersion >= 2015)
406 { options.ecmaVersion -= 2009; }
407
408 if (options.allowReserved == null)
409 { options.allowReserved = options.ecmaVersion < 5; }
410
411 if (isArray(options.onToken)) {
412 var tokens = options.onToken;
413 options.onToken = function (token) { return tokens.push(token); };
414 }
415 if (isArray(options.onComment))
416 { options.onComment = pushComment(options, options.onComment); }
417
418 return options
419}
420
421function pushComment(options, array) {
422 return function(block, text, start, end, startLoc, endLoc) {
423 var comment = {
424 type: block ? "Block" : "Line",
425 value: text,
426 start: start,
427 end: end
428 };
429 if (options.locations)
430 { comment.loc = new SourceLocation(this, startLoc, endLoc); }
431 if (options.ranges)
432 { comment.range = [start, end]; }
433 array.push(comment);
434 }
435}
436
437// Registered plugins
438var plugins = {};
439
440function keywordRegexp(words) {
441 return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
442}
443
444var Parser = function Parser(options, input, startPos) {
445 this.options = options = getOptions(options);
446 this.sourceFile = options.sourceFile;
447 this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
448 var reserved = "";
449 if (!options.allowReserved) {
450 for (var v = options.ecmaVersion;; v--)
451 { if (reserved = reservedWords[v]) { break } }
452 if (options.sourceType == "module") { reserved += " await"; }
453 }
454 this.reservedWords = keywordRegexp(reserved);
455 var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
456 this.reservedWordsStrict = keywordRegexp(reservedStrict);
457 this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
458 this.input = String(input);
459
460 // Used to signal to callers of `readWord1` whether the word
461 // contained any escape sequences. This is needed because words with
462 // escape sequences must not be interpreted as keywords.
463 this.containsEsc = false;
464
465 // Load plugins
466 this.loadPlugins(options.plugins);
467
468 // Set up token state
469
470 // The current position of the tokenizer in the input.
471 if (startPos) {
472 this.pos = startPos;
473 this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
474 this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
475 } else {
476 this.pos = this.lineStart = 0;
477 this.curLine = 1;
478 }
479
480 // Properties of the current token:
481 // Its type
482 this.type = types.eof;
483 // For tokens that include more information than their type, the value
484 this.value = null;
485 // Its start and end offset
486 this.start = this.end = this.pos;
487 // And, if locations are used, the {line, column} object
488 // corresponding to those offsets
489 this.startLoc = this.endLoc = this.curPosition();
490
491 // Position information for the previous token
492 this.lastTokEndLoc = this.lastTokStartLoc = null;
493 this.lastTokStart = this.lastTokEnd = this.pos;
494
495 // The context stack is used to superficially track syntactic
496 // context to predict whether a regular expression is allowed in a
497 // given position.
498 this.context = this.initialContext();
499 this.exprAllowed = true;
500
501 // Figure out if it's a module code.
502 this.inModule = options.sourceType === "module";
503 this.strict = this.inModule || this.strictDirective(this.pos);
504
505 // Used to signify the start of a potential arrow function
506 this.potentialArrowAt = -1;
507
508 // Flags to track whether we are in a function, a generator, an async function.
509 this.inFunction = this.inGenerator = this.inAsync = false;
510 // Positions to delayed-check that yield/await does not exist in default parameters.
511 this.yieldPos = this.awaitPos = 0;
512 // Labels in scope.
513 this.labels = [];
514
515 // If enabled, skip leading hashbang line.
516 if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
517 { this.skipLineComment(2); }
518
519 // Scope tracking for duplicate variable names (see scope.js)
520 this.scopeStack = [];
521 this.enterFunctionScope();
522
523 // For RegExp validation
524 this.regexpState = null;
525};
526
527// DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
528Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
529Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
530
531Parser.prototype.extend = function extend (name, f) {
532 this[name] = f(this[name]);
533};
534
535Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
536 var this$1 = this;
537
538 for (var name in pluginConfigs) {
539 var plugin = plugins[name];
540 if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
541 plugin(this$1, pluginConfigs[name]);
542 }
543};
544
545Parser.prototype.parse = function parse () {
546 var node = this.options.program || this.startNode();
547 this.nextToken();
548 return this.parseTopLevel(node)
549};
550
551var pp = Parser.prototype;
552
553// ## Parser utilities
554
555var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
556pp.strictDirective = function(start) {
557 var this$1 = this;
558
559 for (;;) {
560 skipWhiteSpace.lastIndex = start;
561 start += skipWhiteSpace.exec(this$1.input)[0].length;
562 var match = literal.exec(this$1.input.slice(start));
563 if (!match) { return false }
564 if ((match[1] || match[2]) == "use strict") { return true }
565 start += match[0].length;
566 }
567};
568
569// Predicate that tests whether the next token is of the given
570// type, and if yes, consumes it as a side effect.
571
572pp.eat = function(type) {
573 if (this.type === type) {
574 this.next();
575 return true
576 } else {
577 return false
578 }
579};
580
581// Tests whether parsed token is a contextual keyword.
582
583pp.isContextual = function(name) {
584 return this.type === types.name && this.value === name && !this.containsEsc
585};
586
587// Consumes contextual keyword if possible.
588
589pp.eatContextual = function(name) {
590 if (!this.isContextual(name)) { return false }
591 this.next();
592 return true
593};
594
595// Asserts that following token is given contextual keyword.
596
597pp.expectContextual = function(name) {
598 if (!this.eatContextual(name)) { this.unexpected(); }
599};
600
601// Test whether a semicolon can be inserted at the current position.
602
603pp.canInsertSemicolon = function() {
604 return this.type === types.eof ||
605 this.type === types.braceR ||
606 lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
607};
608
609pp.insertSemicolon = function() {
610 if (this.canInsertSemicolon()) {
611 if (this.options.onInsertedSemicolon)
612 { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
613 return true
614 }
615};
616
617// Consume a semicolon, or, failing that, see if we are allowed to
618// pretend that there is a semicolon at this position.
619
620pp.semicolon = function() {
621 if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
622};
623
624pp.afterTrailingComma = function(tokType, notNext) {
625 if (this.type == tokType) {
626 if (this.options.onTrailingComma)
627 { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
628 if (!notNext)
629 { this.next(); }
630 return true
631 }
632};
633
634// Expect a token of a given type. If found, consume it, otherwise,
635// raise an unexpected token error.
636
637pp.expect = function(type) {
638 this.eat(type) || this.unexpected();
639};
640
641// Raise an unexpected token error.
642
643pp.unexpected = function(pos) {
644 this.raise(pos != null ? pos : this.start, "Unexpected token");
645};
646
647function DestructuringErrors() {
648 this.shorthandAssign =
649 this.trailingComma =
650 this.parenthesizedAssign =
651 this.parenthesizedBind =
652 this.doubleProto =
653 -1;
654}
655
656pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
657 if (!refDestructuringErrors) { return }
658 if (refDestructuringErrors.trailingComma > -1)
659 { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
660 var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
661 if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
662};
663
664pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
665 if (!refDestructuringErrors) { return false }
666 var shorthandAssign = refDestructuringErrors.shorthandAssign;
667 var doubleProto = refDestructuringErrors.doubleProto;
668 if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
669 if (shorthandAssign >= 0)
670 { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
671 if (doubleProto >= 0)
672 { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
673};
674
675pp.checkYieldAwaitInDefaultParams = function() {
676 if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
677 { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
678 if (this.awaitPos)
679 { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
680};
681
682pp.isSimpleAssignTarget = function(expr) {
683 if (expr.type === "ParenthesizedExpression")
684 { return this.isSimpleAssignTarget(expr.expression) }
685 return expr.type === "Identifier" || expr.type === "MemberExpression"
686};
687
688var pp$1 = Parser.prototype;
689
690// ### Statement parsing
691
692// Parse a program. Initializes the parser, reads any number of
693// statements, and wraps them in a Program node. Optionally takes a
694// `program` argument. If present, the statements will be appended
695// to its body instead of creating a new node.
696
697pp$1.parseTopLevel = function(node) {
698 var this$1 = this;
699
700 var exports = {};
701 if (!node.body) { node.body = []; }
702 while (this.type !== types.eof) {
703 var stmt = this$1.parseStatement(true, true, exports);
704 node.body.push(stmt);
705 }
706 this.adaptDirectivePrologue(node.body);
707 this.next();
708 if (this.options.ecmaVersion >= 6) {
709 node.sourceType = this.options.sourceType;
710 }
711 return this.finishNode(node, "Program")
712};
713
714var loopLabel = {kind: "loop"};
715var switchLabel = {kind: "switch"};
716
717pp$1.isLet = function() {
718 if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
719 skipWhiteSpace.lastIndex = this.pos;
720 var skip = skipWhiteSpace.exec(this.input);
721 var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
722 if (nextCh === 91 || nextCh == 123) { return true } // '{' and '['
723 if (isIdentifierStart(nextCh, true)) {
724 var pos = next + 1;
725 while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
726 var ident = this.input.slice(next, pos);
727 if (!keywordRelationalOperator.test(ident)) { return true }
728 }
729 return false
730};
731
732// check 'async [no LineTerminator here] function'
733// - 'async /*foo*/ function' is OK.
734// - 'async /*\n*/ function' is invalid.
735pp$1.isAsyncFunction = function() {
736 if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
737 { return false }
738
739 skipWhiteSpace.lastIndex = this.pos;
740 var skip = skipWhiteSpace.exec(this.input);
741 var next = this.pos + skip[0].length;
742 return !lineBreak.test(this.input.slice(this.pos, next)) &&
743 this.input.slice(next, next + 8) === "function" &&
744 (next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
745};
746
747// Parse a single statement.
748//
749// If expecting a statement and finding a slash operator, parse a
750// regular expression literal. This is to handle cases like
751// `if (foo) /blah/.exec(foo)`, where looking at the previous token
752// does not help.
753
754pp$1.parseStatement = function(declaration, topLevel, exports) {
755 var starttype = this.type, node = this.startNode(), kind;
756
757 if (this.isLet()) {
758 starttype = types._var;
759 kind = "let";
760 }
761
762 // Most types of statements are recognized by the keyword they
763 // start with. Many are trivial to parse, some require a bit of
764 // complexity.
765
766 switch (starttype) {
767 case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
768 case types._debugger: return this.parseDebuggerStatement(node)
769 case types._do: return this.parseDoStatement(node)
770 case types._for: return this.parseForStatement(node)
771 case types._function:
772 if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
773 return this.parseFunctionStatement(node, false)
774 case types._class:
775 if (!declaration) { this.unexpected(); }
776 return this.parseClass(node, true)
777 case types._if: return this.parseIfStatement(node)
778 case types._return: return this.parseReturnStatement(node)
779 case types._switch: return this.parseSwitchStatement(node)
780 case types._throw: return this.parseThrowStatement(node)
781 case types._try: return this.parseTryStatement(node)
782 case types._const: case types._var:
783 kind = kind || this.value;
784 if (!declaration && kind != "var") { this.unexpected(); }
785 return this.parseVarStatement(node, kind)
786 case types._while: return this.parseWhileStatement(node)
787 case types._with: return this.parseWithStatement(node)
788 case types.braceL: return this.parseBlock()
789 case types.semi: return this.parseEmptyStatement(node)
790 case types._export:
791 case types._import:
792 if (!this.options.allowImportExportEverywhere) {
793 if (!topLevel)
794 { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
795 if (!this.inModule)
796 { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
797 }
798 return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
799
800 // If the statement does not start with a statement keyword or a
801 // brace, it's an ExpressionStatement or LabeledStatement. We
802 // simply start parsing an expression, and afterwards, if the
803 // next token is a colon and the expression was a simple
804 // Identifier node, we switch to interpreting it as a label.
805 default:
806 if (this.isAsyncFunction()) {
807 if (!declaration) { this.unexpected(); }
808 this.next();
809 return this.parseFunctionStatement(node, true)
810 }
811
812 var maybeName = this.value, expr = this.parseExpression();
813 if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
814 { return this.parseLabeledStatement(node, maybeName, expr) }
815 else { return this.parseExpressionStatement(node, expr) }
816 }
817};
818
819pp$1.parseBreakContinueStatement = function(node, keyword) {
820 var this$1 = this;
821
822 var isBreak = keyword == "break";
823 this.next();
824 if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
825 else if (this.type !== types.name) { this.unexpected(); }
826 else {
827 node.label = this.parseIdent();
828 this.semicolon();
829 }
830
831 // Verify that there is an actual destination to break or
832 // continue to.
833 var i = 0;
834 for (; i < this.labels.length; ++i) {
835 var lab = this$1.labels[i];
836 if (node.label == null || lab.name === node.label.name) {
837 if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
838 if (node.label && isBreak) { break }
839 }
840 }
841 if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
842 return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
843};
844
845pp$1.parseDebuggerStatement = function(node) {
846 this.next();
847 this.semicolon();
848 return this.finishNode(node, "DebuggerStatement")
849};
850
851pp$1.parseDoStatement = function(node) {
852 this.next();
853 this.labels.push(loopLabel);
854 node.body = this.parseStatement(false);
855 this.labels.pop();
856 this.expect(types._while);
857 node.test = this.parseParenExpression();
858 if (this.options.ecmaVersion >= 6)
859 { this.eat(types.semi); }
860 else
861 { this.semicolon(); }
862 return this.finishNode(node, "DoWhileStatement")
863};
864
865// Disambiguating between a `for` and a `for`/`in` or `for`/`of`
866// loop is non-trivial. Basically, we have to parse the init `var`
867// statement or expression, disallowing the `in` operator (see
868// the second parameter to `parseExpression`), and then check
869// whether the next token is `in` or `of`. When there is no init
870// part (semicolon immediately after the opening parenthesis), it
871// is a regular `for` loop.
872
873pp$1.parseForStatement = function(node) {
874 this.next();
875 var awaitAt = (this.options.ecmaVersion >= 9 && this.inAsync && this.eatContextual("await")) ? this.lastTokStart : -1;
876 this.labels.push(loopLabel);
877 this.enterLexicalScope();
878 this.expect(types.parenL);
879 if (this.type === types.semi) {
880 if (awaitAt > -1) { this.unexpected(awaitAt); }
881 return this.parseFor(node, null)
882 }
883 var isLet = this.isLet();
884 if (this.type === types._var || this.type === types._const || isLet) {
885 var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
886 this.next();
887 this.parseVar(init$1, true, kind);
888 this.finishNode(init$1, "VariableDeclaration");
889 if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
890 !(kind !== "var" && init$1.declarations[0].init)) {
891 if (this.options.ecmaVersion >= 9) {
892 if (this.type === types._in) {
893 if (awaitAt > -1) { this.unexpected(awaitAt); }
894 } else { node.await = awaitAt > -1; }
895 }
896 return this.parseForIn(node, init$1)
897 }
898 if (awaitAt > -1) { this.unexpected(awaitAt); }
899 return this.parseFor(node, init$1)
900 }
901 var refDestructuringErrors = new DestructuringErrors;
902 var init = this.parseExpression(true, refDestructuringErrors);
903 if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
904 if (this.options.ecmaVersion >= 9) {
905 if (this.type === types._in) {
906 if (awaitAt > -1) { this.unexpected(awaitAt); }
907 } else { node.await = awaitAt > -1; }
908 }
909 this.toAssignable(init, false, refDestructuringErrors);
910 this.checkLVal(init);
911 return this.parseForIn(node, init)
912 } else {
913 this.checkExpressionErrors(refDestructuringErrors, true);
914 }
915 if (awaitAt > -1) { this.unexpected(awaitAt); }
916 return this.parseFor(node, init)
917};
918
919pp$1.parseFunctionStatement = function(node, isAsync) {
920 this.next();
921 return this.parseFunction(node, true, false, isAsync)
922};
923
924pp$1.parseIfStatement = function(node) {
925 this.next();
926 node.test = this.parseParenExpression();
927 // allow function declarations in branches, but only in non-strict mode
928 node.consequent = this.parseStatement(!this.strict && this.type == types._function);
929 node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.type == types._function) : null;
930 return this.finishNode(node, "IfStatement")
931};
932
933pp$1.parseReturnStatement = function(node) {
934 if (!this.inFunction && !this.options.allowReturnOutsideFunction)
935 { this.raise(this.start, "'return' outside of function"); }
936 this.next();
937
938 // In `return` (and `break`/`continue`), the keywords with
939 // optional arguments, we eagerly look for a semicolon or the
940 // possibility to insert one.
941
942 if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
943 else { node.argument = this.parseExpression(); this.semicolon(); }
944 return this.finishNode(node, "ReturnStatement")
945};
946
947pp$1.parseSwitchStatement = function(node) {
948 var this$1 = this;
949
950 this.next();
951 node.discriminant = this.parseParenExpression();
952 node.cases = [];
953 this.expect(types.braceL);
954 this.labels.push(switchLabel);
955 this.enterLexicalScope();
956
957 // Statements under must be grouped (by label) in SwitchCase
958 // nodes. `cur` is used to keep the node that we are currently
959 // adding statements to.
960
961 var cur;
962 for (var sawDefault = false; this.type != types.braceR;) {
963 if (this$1.type === types._case || this$1.type === types._default) {
964 var isCase = this$1.type === types._case;
965 if (cur) { this$1.finishNode(cur, "SwitchCase"); }
966 node.cases.push(cur = this$1.startNode());
967 cur.consequent = [];
968 this$1.next();
969 if (isCase) {
970 cur.test = this$1.parseExpression();
971 } else {
972 if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
973 sawDefault = true;
974 cur.test = null;
975 }
976 this$1.expect(types.colon);
977 } else {
978 if (!cur) { this$1.unexpected(); }
979 cur.consequent.push(this$1.parseStatement(true));
980 }
981 }
982 this.exitLexicalScope();
983 if (cur) { this.finishNode(cur, "SwitchCase"); }
984 this.next(); // Closing brace
985 this.labels.pop();
986 return this.finishNode(node, "SwitchStatement")
987};
988
989pp$1.parseThrowStatement = function(node) {
990 this.next();
991 if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
992 { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
993 node.argument = this.parseExpression();
994 this.semicolon();
995 return this.finishNode(node, "ThrowStatement")
996};
997
998// Reused empty array added for node fields that are always empty.
999
1000var empty = [];
1001
1002pp$1.parseTryStatement = function(node) {
1003 this.next();
1004 node.block = this.parseBlock();
1005 node.handler = null;
1006 if (this.type === types._catch) {
1007 var clause = this.startNode();
1008 this.next();
1009 this.expect(types.parenL);
1010 clause.param = this.parseBindingAtom();
1011 this.enterLexicalScope();
1012 this.checkLVal(clause.param, "let");
1013 this.expect(types.parenR);
1014 clause.body = this.parseBlock(false);
1015 this.exitLexicalScope();
1016 node.handler = this.finishNode(clause, "CatchClause");
1017 }
1018 node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
1019 if (!node.handler && !node.finalizer)
1020 { this.raise(node.start, "Missing catch or finally clause"); }
1021 return this.finishNode(node, "TryStatement")
1022};
1023
1024pp$1.parseVarStatement = function(node, kind) {
1025 this.next();
1026 this.parseVar(node, false, kind);
1027 this.semicolon();
1028 return this.finishNode(node, "VariableDeclaration")
1029};
1030
1031pp$1.parseWhileStatement = function(node) {
1032 this.next();
1033 node.test = this.parseParenExpression();
1034 this.labels.push(loopLabel);
1035 node.body = this.parseStatement(false);
1036 this.labels.pop();
1037 return this.finishNode(node, "WhileStatement")
1038};
1039
1040pp$1.parseWithStatement = function(node) {
1041 if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
1042 this.next();
1043 node.object = this.parseParenExpression();
1044 node.body = this.parseStatement(false);
1045 return this.finishNode(node, "WithStatement")
1046};
1047
1048pp$1.parseEmptyStatement = function(node) {
1049 this.next();
1050 return this.finishNode(node, "EmptyStatement")
1051};
1052
1053pp$1.parseLabeledStatement = function(node, maybeName, expr) {
1054 var this$1 = this;
1055
1056 for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
1057 {
1058 var label = list[i$1];
1059
1060 if (label.name === maybeName)
1061 { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
1062 } }
1063 var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
1064 for (var i = this.labels.length - 1; i >= 0; i--) {
1065 var label$1 = this$1.labels[i];
1066 if (label$1.statementStart == node.start) {
1067 // Update information about previous labels on this node
1068 label$1.statementStart = this$1.start;
1069 label$1.kind = kind;
1070 } else { break }
1071 }
1072 this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
1073 node.body = this.parseStatement(true);
1074 if (node.body.type == "ClassDeclaration" ||
1075 node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
1076 node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator))
1077 { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
1078 this.labels.pop();
1079 node.label = expr;
1080 return this.finishNode(node, "LabeledStatement")
1081};
1082
1083pp$1.parseExpressionStatement = function(node, expr) {
1084 node.expression = expr;
1085 this.semicolon();
1086 return this.finishNode(node, "ExpressionStatement")
1087};
1088
1089// Parse a semicolon-enclosed block of statements, handling `"use
1090// strict"` declarations when `allowStrict` is true (used for
1091// function bodies).
1092
1093pp$1.parseBlock = function(createNewLexicalScope) {
1094 var this$1 = this;
1095 if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
1096
1097 var node = this.startNode();
1098 node.body = [];
1099 this.expect(types.braceL);
1100 if (createNewLexicalScope) {
1101 this.enterLexicalScope();
1102 }
1103 while (!this.eat(types.braceR)) {
1104 var stmt = this$1.parseStatement(true);
1105 node.body.push(stmt);
1106 }
1107 if (createNewLexicalScope) {
1108 this.exitLexicalScope();
1109 }
1110 return this.finishNode(node, "BlockStatement")
1111};
1112
1113// Parse a regular `for` loop. The disambiguation code in
1114// `parseStatement` will already have parsed the init statement or
1115// expression.
1116
1117pp$1.parseFor = function(node, init) {
1118 node.init = init;
1119 this.expect(types.semi);
1120 node.test = this.type === types.semi ? null : this.parseExpression();
1121 this.expect(types.semi);
1122 node.update = this.type === types.parenR ? null : this.parseExpression();
1123 this.expect(types.parenR);
1124 this.exitLexicalScope();
1125 node.body = this.parseStatement(false);
1126 this.labels.pop();
1127 return this.finishNode(node, "ForStatement")
1128};
1129
1130// Parse a `for`/`in` and `for`/`of` loop, which are almost
1131// same from parser's perspective.
1132
1133pp$1.parseForIn = function(node, init) {
1134 var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
1135 this.next();
1136 if (type == "ForInStatement") {
1137 if (init.type === "AssignmentPattern" ||
1138 (init.type === "VariableDeclaration" && init.declarations[0].init != null &&
1139 (this.strict || init.declarations[0].id.type !== "Identifier")))
1140 { this.raise(init.start, "Invalid assignment in for-in loop head"); }
1141 }
1142 node.left = init;
1143 node.right = type == "ForInStatement" ? this.parseExpression() : this.parseMaybeAssign();
1144 this.expect(types.parenR);
1145 this.exitLexicalScope();
1146 node.body = this.parseStatement(false);
1147 this.labels.pop();
1148 return this.finishNode(node, type)
1149};
1150
1151// Parse a list of variable declarations.
1152
1153pp$1.parseVar = function(node, isFor, kind) {
1154 var this$1 = this;
1155
1156 node.declarations = [];
1157 node.kind = kind;
1158 for (;;) {
1159 var decl = this$1.startNode();
1160 this$1.parseVarId(decl, kind);
1161 if (this$1.eat(types.eq)) {
1162 decl.init = this$1.parseMaybeAssign(isFor);
1163 } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
1164 this$1.unexpected();
1165 } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
1166 this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
1167 } else {
1168 decl.init = null;
1169 }
1170 node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
1171 if (!this$1.eat(types.comma)) { break }
1172 }
1173 return node
1174};
1175
1176pp$1.parseVarId = function(decl, kind) {
1177 decl.id = this.parseBindingAtom(kind);
1178 this.checkLVal(decl.id, kind, false);
1179};
1180
1181// Parse a function declaration or literal (depending on the
1182// `isStatement` parameter).
1183
1184pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
1185 this.initFunction(node);
1186 if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync)
1187 { node.generator = this.eat(types.star); }
1188 if (this.options.ecmaVersion >= 8)
1189 { node.async = !!isAsync; }
1190
1191 if (isStatement) {
1192 node.id = isStatement === "nullableID" && this.type != types.name ? null : this.parseIdent();
1193 if (node.id) {
1194 this.checkLVal(node.id, "var");
1195 }
1196 }
1197
1198 var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
1199 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
1200 this.inGenerator = node.generator;
1201 this.inAsync = node.async;
1202 this.yieldPos = 0;
1203 this.awaitPos = 0;
1204 this.inFunction = true;
1205 this.enterFunctionScope();
1206
1207 if (!isStatement)
1208 { node.id = this.type == types.name ? this.parseIdent() : null; }
1209
1210 this.parseFunctionParams(node);
1211 this.parseFunctionBody(node, allowExpressionBody);
1212
1213 this.inGenerator = oldInGen;
1214 this.inAsync = oldInAsync;
1215 this.yieldPos = oldYieldPos;
1216 this.awaitPos = oldAwaitPos;
1217 this.inFunction = oldInFunc;
1218 return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
1219};
1220
1221pp$1.parseFunctionParams = function(node) {
1222 this.expect(types.parenL);
1223 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
1224 this.checkYieldAwaitInDefaultParams();
1225};
1226
1227// Parse a class declaration or literal (depending on the
1228// `isStatement` parameter).
1229
1230pp$1.parseClass = function(node, isStatement) {
1231 var this$1 = this;
1232
1233 this.next();
1234
1235 this.parseClassId(node, isStatement);
1236 this.parseClassSuper(node);
1237 var classBody = this.startNode();
1238 var hadConstructor = false;
1239 classBody.body = [];
1240 this.expect(types.braceL);
1241 while (!this.eat(types.braceR)) {
1242 var member = this$1.parseClassMember(classBody);
1243 if (member && member.type === "MethodDefinition" && member.kind === "constructor") {
1244 if (hadConstructor) { this$1.raise(member.start, "Duplicate constructor in the same class"); }
1245 hadConstructor = true;
1246 }
1247 }
1248 node.body = this.finishNode(classBody, "ClassBody");
1249 return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
1250};
1251
1252pp$1.parseClassMember = function(classBody) {
1253 var this$1 = this;
1254
1255 if (this.eat(types.semi)) { return null }
1256
1257 var method = this.startNode();
1258 var tryContextual = function (k, noLineBreak) {
1259 if ( noLineBreak === void 0 ) noLineBreak = false;
1260
1261 var start = this$1.start, startLoc = this$1.startLoc;
1262 if (!this$1.eatContextual(k)) { return false }
1263 if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
1264 if (method.key) { this$1.unexpected(); }
1265 method.computed = false;
1266 method.key = this$1.startNodeAt(start, startLoc);
1267 method.key.name = k;
1268 this$1.finishNode(method.key, "Identifier");
1269 return false
1270 };
1271
1272 method.kind = "method";
1273 method.static = tryContextual("static");
1274 var isGenerator = this.eat(types.star);
1275 var isAsync = false;
1276 if (!isGenerator) {
1277 if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
1278 isAsync = true;
1279 isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
1280 } else if (tryContextual("get")) {
1281 method.kind = "get";
1282 } else if (tryContextual("set")) {
1283 method.kind = "set";
1284 }
1285 }
1286 if (!method.key) { this.parsePropertyName(method); }
1287 var key = method.key;
1288 if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
1289 key.type === "Literal" && key.value === "constructor")) {
1290 if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
1291 if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
1292 if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
1293 method.kind = "constructor";
1294 } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
1295 this.raise(key.start, "Classes may not have a static property named prototype");
1296 }
1297 this.parseClassMethod(classBody, method, isGenerator, isAsync);
1298 if (method.kind === "get" && method.value.params.length !== 0)
1299 { this.raiseRecoverable(method.value.start, "getter should have no params"); }
1300 if (method.kind === "set" && method.value.params.length !== 1)
1301 { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
1302 if (method.kind === "set" && method.value.params[0].type === "RestElement")
1303 { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
1304 return method
1305};
1306
1307pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
1308 method.value = this.parseMethod(isGenerator, isAsync);
1309 classBody.body.push(this.finishNode(method, "MethodDefinition"));
1310};
1311
1312pp$1.parseClassId = function(node, isStatement) {
1313 node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
1314};
1315
1316pp$1.parseClassSuper = function(node) {
1317 node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
1318};
1319
1320// Parses module export declaration.
1321
1322pp$1.parseExport = function(node, exports) {
1323 var this$1 = this;
1324
1325 this.next();
1326 // export * from '...'
1327 if (this.eat(types.star)) {
1328 this.expectContextual("from");
1329 if (this.type !== types.string) { this.unexpected(); }
1330 node.source = this.parseExprAtom();
1331 this.semicolon();
1332 return this.finishNode(node, "ExportAllDeclaration")
1333 }
1334 if (this.eat(types._default)) { // export default ...
1335 this.checkExport(exports, "default", this.lastTokStart);
1336 var isAsync;
1337 if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
1338 var fNode = this.startNode();
1339 this.next();
1340 if (isAsync) { this.next(); }
1341 node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
1342 } else if (this.type === types._class) {
1343 var cNode = this.startNode();
1344 node.declaration = this.parseClass(cNode, "nullableID");
1345 } else {
1346 node.declaration = this.parseMaybeAssign();
1347 this.semicolon();
1348 }
1349 return this.finishNode(node, "ExportDefaultDeclaration")
1350 }
1351 // export var|const|let|function|class ...
1352 if (this.shouldParseExportStatement()) {
1353 node.declaration = this.parseStatement(true);
1354 if (node.declaration.type === "VariableDeclaration")
1355 { this.checkVariableExport(exports, node.declaration.declarations); }
1356 else
1357 { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
1358 node.specifiers = [];
1359 node.source = null;
1360 } else { // export { x, y as z } [from '...']
1361 node.declaration = null;
1362 node.specifiers = this.parseExportSpecifiers(exports);
1363 if (this.eatContextual("from")) {
1364 if (this.type !== types.string) { this.unexpected(); }
1365 node.source = this.parseExprAtom();
1366 } else {
1367 // check for keywords used as local names
1368 for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
1369 var spec = list[i];
1370
1371 this$1.checkUnreserved(spec.local);
1372 }
1373
1374 node.source = null;
1375 }
1376 this.semicolon();
1377 }
1378 return this.finishNode(node, "ExportNamedDeclaration")
1379};
1380
1381pp$1.checkExport = function(exports, name, pos) {
1382 if (!exports) { return }
1383 if (has(exports, name))
1384 { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
1385 exports[name] = true;
1386};
1387
1388pp$1.checkPatternExport = function(exports, pat) {
1389 var this$1 = this;
1390
1391 var type = pat.type;
1392 if (type == "Identifier")
1393 { this.checkExport(exports, pat.name, pat.start); }
1394 else if (type == "ObjectPattern")
1395 { for (var i = 0, list = pat.properties; i < list.length; i += 1)
1396 {
1397 var prop = list[i];
1398
1399 this$1.checkPatternExport(exports, prop);
1400 } }
1401 else if (type == "ArrayPattern")
1402 { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
1403 var elt = list$1[i$1];
1404
1405 if (elt) { this$1.checkPatternExport(exports, elt); }
1406 } }
1407 else if (type == "Property")
1408 { this.checkPatternExport(exports, pat.value); }
1409 else if (type == "AssignmentPattern")
1410 { this.checkPatternExport(exports, pat.left); }
1411 else if (type == "RestElement")
1412 { this.checkPatternExport(exports, pat.argument); }
1413 else if (type == "ParenthesizedExpression")
1414 { this.checkPatternExport(exports, pat.expression); }
1415};
1416
1417pp$1.checkVariableExport = function(exports, decls) {
1418 var this$1 = this;
1419
1420 if (!exports) { return }
1421 for (var i = 0, list = decls; i < list.length; i += 1)
1422 {
1423 var decl = list[i];
1424
1425 this$1.checkPatternExport(exports, decl.id);
1426 }
1427};
1428
1429pp$1.shouldParseExportStatement = function() {
1430 return this.type.keyword === "var" ||
1431 this.type.keyword === "const" ||
1432 this.type.keyword === "class" ||
1433 this.type.keyword === "function" ||
1434 this.isLet() ||
1435 this.isAsyncFunction()
1436};
1437
1438// Parses a comma-separated list of module exports.
1439
1440pp$1.parseExportSpecifiers = function(exports) {
1441 var this$1 = this;
1442
1443 var nodes = [], first = true;
1444 // export { x, y as z } [from '...']
1445 this.expect(types.braceL);
1446 while (!this.eat(types.braceR)) {
1447 if (!first) {
1448 this$1.expect(types.comma);
1449 if (this$1.afterTrailingComma(types.braceR)) { break }
1450 } else { first = false; }
1451
1452 var node = this$1.startNode();
1453 node.local = this$1.parseIdent(true);
1454 node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
1455 this$1.checkExport(exports, node.exported.name, node.exported.start);
1456 nodes.push(this$1.finishNode(node, "ExportSpecifier"));
1457 }
1458 return nodes
1459};
1460
1461// Parses import declaration.
1462
1463pp$1.parseImport = function(node) {
1464 this.next();
1465 // import '...'
1466 if (this.type === types.string) {
1467 node.specifiers = empty;
1468 node.source = this.parseExprAtom();
1469 } else {
1470 node.specifiers = this.parseImportSpecifiers();
1471 this.expectContextual("from");
1472 node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1473 }
1474 this.semicolon();
1475 return this.finishNode(node, "ImportDeclaration")
1476};
1477
1478// Parses a comma-separated list of module imports.
1479
1480pp$1.parseImportSpecifiers = function() {
1481 var this$1 = this;
1482
1483 var nodes = [], first = true;
1484 if (this.type === types.name) {
1485 // import defaultObj, { x, y as z } from '...'
1486 var node = this.startNode();
1487 node.local = this.parseIdent();
1488 this.checkLVal(node.local, "let");
1489 nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
1490 if (!this.eat(types.comma)) { return nodes }
1491 }
1492 if (this.type === types.star) {
1493 var node$1 = this.startNode();
1494 this.next();
1495 this.expectContextual("as");
1496 node$1.local = this.parseIdent();
1497 this.checkLVal(node$1.local, "let");
1498 nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
1499 return nodes
1500 }
1501 this.expect(types.braceL);
1502 while (!this.eat(types.braceR)) {
1503 if (!first) {
1504 this$1.expect(types.comma);
1505 if (this$1.afterTrailingComma(types.braceR)) { break }
1506 } else { first = false; }
1507
1508 var node$2 = this$1.startNode();
1509 node$2.imported = this$1.parseIdent(true);
1510 if (this$1.eatContextual("as")) {
1511 node$2.local = this$1.parseIdent();
1512 } else {
1513 this$1.checkUnreserved(node$2.imported);
1514 node$2.local = node$2.imported;
1515 }
1516 this$1.checkLVal(node$2.local, "let");
1517 nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
1518 }
1519 return nodes
1520};
1521
1522// Set `ExpressionStatement#directive` property for directive prologues.
1523pp$1.adaptDirectivePrologue = function(statements) {
1524 for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
1525 statements[i].directive = statements[i].expression.raw.slice(1, -1);
1526 }
1527};
1528pp$1.isDirectiveCandidate = function(statement) {
1529 return (
1530 statement.type === "ExpressionStatement" &&
1531 statement.expression.type === "Literal" &&
1532 typeof statement.expression.value === "string" &&
1533 // Reject parenthesized strings.
1534 (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
1535 )
1536};
1537
1538var pp$2 = Parser.prototype;
1539
1540// Convert existing expression atom to assignable pattern
1541// if possible.
1542
1543pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
1544 var this$1 = this;
1545
1546 if (this.options.ecmaVersion >= 6 && node) {
1547 switch (node.type) {
1548 case "Identifier":
1549 if (this.inAsync && node.name === "await")
1550 { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
1551 break
1552
1553 case "ObjectPattern":
1554 case "ArrayPattern":
1555 case "RestElement":
1556 break
1557
1558 case "ObjectExpression":
1559 node.type = "ObjectPattern";
1560 if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1561 for (var i = 0, list = node.properties; i < list.length; i += 1) {
1562 var prop = list[i];
1563
1564 this$1.toAssignable(prop, isBinding);
1565 // Early error:
1566 // AssignmentRestProperty[Yield, Await] :
1567 // `...` DestructuringAssignmentTarget[Yield, Await]
1568 //
1569 // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
1570 if (
1571 prop.type === "RestElement" &&
1572 (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
1573 ) {
1574 this$1.raise(prop.argument.start, "Unexpected token");
1575 }
1576 }
1577 break
1578
1579 case "Property":
1580 // AssignmentProperty has type == "Property"
1581 if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
1582 this.toAssignable(node.value, isBinding);
1583 break
1584
1585 case "ArrayExpression":
1586 node.type = "ArrayPattern";
1587 if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1588 this.toAssignableList(node.elements, isBinding);
1589 break
1590
1591 case "SpreadElement":
1592 node.type = "RestElement";
1593 this.toAssignable(node.argument, isBinding);
1594 if (node.argument.type === "AssignmentPattern")
1595 { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
1596 break
1597
1598 case "AssignmentExpression":
1599 if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
1600 node.type = "AssignmentPattern";
1601 delete node.operator;
1602 this.toAssignable(node.left, isBinding);
1603 // falls through to AssignmentPattern
1604
1605 case "AssignmentPattern":
1606 break
1607
1608 case "ParenthesizedExpression":
1609 this.toAssignable(node.expression, isBinding);
1610 break
1611
1612 case "MemberExpression":
1613 if (!isBinding) { break }
1614
1615 default:
1616 this.raise(node.start, "Assigning to rvalue");
1617 }
1618 } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1619 return node
1620};
1621
1622// Convert list of expression atoms to binding list.
1623
1624pp$2.toAssignableList = function(exprList, isBinding) {
1625 var this$1 = this;
1626
1627 var end = exprList.length;
1628 for (var i = 0; i < end; i++) {
1629 var elt = exprList[i];
1630 if (elt) { this$1.toAssignable(elt, isBinding); }
1631 }
1632 if (end) {
1633 var last = exprList[end - 1];
1634 if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
1635 { this.unexpected(last.argument.start); }
1636 }
1637 return exprList
1638};
1639
1640// Parses spread element.
1641
1642pp$2.parseSpread = function(refDestructuringErrors) {
1643 var node = this.startNode();
1644 this.next();
1645 node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
1646 return this.finishNode(node, "SpreadElement")
1647};
1648
1649pp$2.parseRestBinding = function() {
1650 var node = this.startNode();
1651 this.next();
1652
1653 // RestElement inside of a function parameter must be an identifier
1654 if (this.options.ecmaVersion === 6 && this.type !== types.name)
1655 { this.unexpected(); }
1656
1657 node.argument = this.parseBindingAtom();
1658
1659 return this.finishNode(node, "RestElement")
1660};
1661
1662// Parses lvalue (assignable) atom.
1663
1664pp$2.parseBindingAtom = function() {
1665 if (this.options.ecmaVersion >= 6) {
1666 switch (this.type) {
1667 case types.bracketL:
1668 var node = this.startNode();
1669 this.next();
1670 node.elements = this.parseBindingList(types.bracketR, true, true);
1671 return this.finishNode(node, "ArrayPattern")
1672
1673 case types.braceL:
1674 return this.parseObj(true)
1675 }
1676 }
1677 return this.parseIdent()
1678};
1679
1680pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
1681 var this$1 = this;
1682
1683 var elts = [], first = true;
1684 while (!this.eat(close)) {
1685 if (first) { first = false; }
1686 else { this$1.expect(types.comma); }
1687 if (allowEmpty && this$1.type === types.comma) {
1688 elts.push(null);
1689 } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
1690 break
1691 } else if (this$1.type === types.ellipsis) {
1692 var rest = this$1.parseRestBinding();
1693 this$1.parseBindingListItem(rest);
1694 elts.push(rest);
1695 if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
1696 this$1.expect(close);
1697 break
1698 } else {
1699 var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
1700 this$1.parseBindingListItem(elem);
1701 elts.push(elem);
1702 }
1703 }
1704 return elts
1705};
1706
1707pp$2.parseBindingListItem = function(param) {
1708 return param
1709};
1710
1711// Parses assignment pattern around given atom if possible.
1712
1713pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
1714 left = left || this.parseBindingAtom();
1715 if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
1716 var node = this.startNodeAt(startPos, startLoc);
1717 node.left = left;
1718 node.right = this.parseMaybeAssign();
1719 return this.finishNode(node, "AssignmentPattern")
1720};
1721
1722// Verify that a node is an lval — something that can be assigned
1723// to.
1724// bindingType can be either:
1725// 'var' indicating that the lval creates a 'var' binding
1726// 'let' indicating that the lval creates a lexical ('let' or 'const') binding
1727// 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
1728
1729pp$2.checkLVal = function(expr, bindingType, checkClashes) {
1730 var this$1 = this;
1731
1732 switch (expr.type) {
1733 case "Identifier":
1734 if (this.strict && this.reservedWordsStrictBind.test(expr.name))
1735 { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
1736 if (checkClashes) {
1737 if (has(checkClashes, expr.name))
1738 { this.raiseRecoverable(expr.start, "Argument name clash"); }
1739 checkClashes[expr.name] = true;
1740 }
1741 if (bindingType && bindingType !== "none") {
1742 if (
1743 bindingType === "var" && !this.canDeclareVarName(expr.name) ||
1744 bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
1745 ) {
1746 this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
1747 }
1748 if (bindingType === "var") {
1749 this.declareVarName(expr.name);
1750 } else {
1751 this.declareLexicalName(expr.name);
1752 }
1753 }
1754 break
1755
1756 case "MemberExpression":
1757 if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
1758 break
1759
1760 case "ObjectPattern":
1761 for (var i = 0, list = expr.properties; i < list.length; i += 1)
1762 {
1763 var prop = list[i];
1764
1765 this$1.checkLVal(prop, bindingType, checkClashes);
1766 }
1767 break
1768
1769 case "Property":
1770 // AssignmentProperty has type == "Property"
1771 this.checkLVal(expr.value, bindingType, checkClashes);
1772 break
1773
1774 case "ArrayPattern":
1775 for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
1776 var elem = list$1[i$1];
1777
1778 if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
1779 }
1780 break
1781
1782 case "AssignmentPattern":
1783 this.checkLVal(expr.left, bindingType, checkClashes);
1784 break
1785
1786 case "RestElement":
1787 this.checkLVal(expr.argument, bindingType, checkClashes);
1788 break
1789
1790 case "ParenthesizedExpression":
1791 this.checkLVal(expr.expression, bindingType, checkClashes);
1792 break
1793
1794 default:
1795 this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
1796 }
1797};
1798
1799// A recursive descent parser operates by defining functions for all
1800// syntactic elements, and recursively calling those, each function
1801// advancing the input stream and returning an AST node. Precedence
1802// of constructs (for example, the fact that `!x[1]` means `!(x[1])`
1803// instead of `(!x)[1]` is handled by the fact that the parser
1804// function that parses unary prefix operators is called first, and
1805// in turn calls the function that parses `[]` subscripts — that
1806// way, it'll receive the node for `x[1]` already parsed, and wraps
1807// *that* in the unary operator node.
1808//
1809// Acorn uses an [operator precedence parser][opp] to handle binary
1810// operator precedence, because it is much more compact than using
1811// the technique outlined above, which uses different, nesting
1812// functions to specify precedence, for all of the ten binary
1813// precedence levels that JavaScript defines.
1814//
1815// [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
1816
1817var pp$3 = Parser.prototype;
1818
1819// Check if property name clashes with already added.
1820// Object/class getters and setters are not allowed to clash —
1821// either with each other or with an init property — and in
1822// strict mode, init properties are also not allowed to be repeated.
1823
1824pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
1825 if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
1826 { return }
1827 if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
1828 { return }
1829 var key = prop.key;
1830 var name;
1831 switch (key.type) {
1832 case "Identifier": name = key.name; break
1833 case "Literal": name = String(key.value); break
1834 default: return
1835 }
1836 var kind = prop.kind;
1837 if (this.options.ecmaVersion >= 6) {
1838 if (name === "__proto__" && kind === "init") {
1839 if (propHash.proto) {
1840 if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) { refDestructuringErrors.doubleProto = key.start; }
1841 // Backwards-compat kludge. Can be removed in version 6.0
1842 else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
1843 }
1844 propHash.proto = true;
1845 }
1846 return
1847 }
1848 name = "$" + name;
1849 var other = propHash[name];
1850 if (other) {
1851 var redefinition;
1852 if (kind === "init") {
1853 redefinition = this.strict && other.init || other.get || other.set;
1854 } else {
1855 redefinition = other.init || other[kind];
1856 }
1857 if (redefinition)
1858 { this.raiseRecoverable(key.start, "Redefinition of property"); }
1859 } else {
1860 other = propHash[name] = {
1861 init: false,
1862 get: false,
1863 set: false
1864 };
1865 }
1866 other[kind] = true;
1867};
1868
1869// ### Expression parsing
1870
1871// These nest, from the most general expression type at the top to
1872// 'atomic', nondivisible expression types at the bottom. Most of
1873// the functions will simply let the function(s) below them parse,
1874// and, *if* the syntactic construct they handle is present, wrap
1875// the AST node that the inner parser gave them in another node.
1876
1877// Parse a full expression. The optional arguments are used to
1878// forbid the `in` operator (in for loops initalization expressions)
1879// and provide reference for storing '=' operator inside shorthand
1880// property assignment in contexts where both object expression
1881// and object pattern might appear (so it's possible to raise
1882// delayed syntax error at correct position).
1883
1884pp$3.parseExpression = function(noIn, refDestructuringErrors) {
1885 var this$1 = this;
1886
1887 var startPos = this.start, startLoc = this.startLoc;
1888 var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
1889 if (this.type === types.comma) {
1890 var node = this.startNodeAt(startPos, startLoc);
1891 node.expressions = [expr];
1892 while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
1893 return this.finishNode(node, "SequenceExpression")
1894 }
1895 return expr
1896};
1897
1898// Parse an assignment expression. This includes applications of
1899// operators like `+=`.
1900
1901pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
1902 if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
1903
1904 var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
1905 if (refDestructuringErrors) {
1906 oldParenAssign = refDestructuringErrors.parenthesizedAssign;
1907 oldTrailingComma = refDestructuringErrors.trailingComma;
1908 refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
1909 } else {
1910 refDestructuringErrors = new DestructuringErrors;
1911 ownDestructuringErrors = true;
1912 }
1913
1914 var startPos = this.start, startLoc = this.startLoc;
1915 if (this.type == types.parenL || this.type == types.name)
1916 { this.potentialArrowAt = this.start; }
1917 var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
1918 if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
1919 if (this.type.isAssign) {
1920 var node = this.startNodeAt(startPos, startLoc);
1921 node.operator = this.value;
1922 node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left;
1923 if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
1924 refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
1925 this.checkLVal(left);
1926 this.next();
1927 node.right = this.parseMaybeAssign(noIn);
1928 return this.finishNode(node, "AssignmentExpression")
1929 } else {
1930 if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
1931 }
1932 if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
1933 if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
1934 return left
1935};
1936
1937// Parse a ternary conditional (`?:`) operator.
1938
1939pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
1940 var startPos = this.start, startLoc = this.startLoc;
1941 var expr = this.parseExprOps(noIn, refDestructuringErrors);
1942 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1943 if (this.eat(types.question)) {
1944 var node = this.startNodeAt(startPos, startLoc);
1945 node.test = expr;
1946 node.consequent = this.parseMaybeAssign();
1947 this.expect(types.colon);
1948 node.alternate = this.parseMaybeAssign(noIn);
1949 return this.finishNode(node, "ConditionalExpression")
1950 }
1951 return expr
1952};
1953
1954// Start the precedence parser.
1955
1956pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
1957 var startPos = this.start, startLoc = this.startLoc;
1958 var expr = this.parseMaybeUnary(refDestructuringErrors, false);
1959 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1960 return expr.start == startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
1961};
1962
1963// Parse binary operators with the operator precedence parsing
1964// algorithm. `left` is the left-hand side of the operator.
1965// `minPrec` provides context that allows the function to stop and
1966// defer further parser to one of its callers when it encounters an
1967// operator that has a lower precedence than the set it is parsing.
1968
1969pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
1970 var prec = this.type.binop;
1971 if (prec != null && (!noIn || this.type !== types._in)) {
1972 if (prec > minPrec) {
1973 var logical = this.type === types.logicalOR || this.type === types.logicalAND;
1974 var op = this.value;
1975 this.next();
1976 var startPos = this.start, startLoc = this.startLoc;
1977 var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
1978 var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
1979 return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
1980 }
1981 }
1982 return left
1983};
1984
1985pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
1986 var node = this.startNodeAt(startPos, startLoc);
1987 node.left = left;
1988 node.operator = op;
1989 node.right = right;
1990 return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
1991};
1992
1993// Parse unary operators, both prefix and postfix.
1994
1995pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
1996 var this$1 = this;
1997
1998 var startPos = this.start, startLoc = this.startLoc, expr;
1999 if (this.inAsync && this.isContextual("await")) {
2000 expr = this.parseAwait();
2001 sawUnary = true;
2002 } else if (this.type.prefix) {
2003 var node = this.startNode(), update = this.type === types.incDec;
2004 node.operator = this.value;
2005 node.prefix = true;
2006 this.next();
2007 node.argument = this.parseMaybeUnary(null, true);
2008 this.checkExpressionErrors(refDestructuringErrors, true);
2009 if (update) { this.checkLVal(node.argument); }
2010 else if (this.strict && node.operator === "delete" &&
2011 node.argument.type === "Identifier")
2012 { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
2013 else { sawUnary = true; }
2014 expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
2015 } else {
2016 expr = this.parseExprSubscripts(refDestructuringErrors);
2017 if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
2018 while (this.type.postfix && !this.canInsertSemicolon()) {
2019 var node$1 = this$1.startNodeAt(startPos, startLoc);
2020 node$1.operator = this$1.value;
2021 node$1.prefix = false;
2022 node$1.argument = expr;
2023 this$1.checkLVal(expr);
2024 this$1.next();
2025 expr = this$1.finishNode(node$1, "UpdateExpression");
2026 }
2027 }
2028
2029 if (!sawUnary && this.eat(types.starstar))
2030 { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
2031 else
2032 { return expr }
2033};
2034
2035// Parse call, dot, and `[]`-subscript expressions.
2036
2037pp$3.parseExprSubscripts = function(refDestructuringErrors) {
2038 var startPos = this.start, startLoc = this.startLoc;
2039 var expr = this.parseExprAtom(refDestructuringErrors);
2040 var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
2041 if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
2042 var result = this.parseSubscripts(expr, startPos, startLoc);
2043 if (refDestructuringErrors && result.type === "MemberExpression") {
2044 if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
2045 if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
2046 }
2047 return result
2048};
2049
2050pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
2051 var this$1 = this;
2052
2053 var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
2054 this.lastTokEnd == base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async";
2055 for (var computed = (void 0);;) {
2056 if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
2057 var node = this$1.startNodeAt(startPos, startLoc);
2058 node.object = base;
2059 node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
2060 node.computed = !!computed;
2061 if (computed) { this$1.expect(types.bracketR); }
2062 base = this$1.finishNode(node, "MemberExpression");
2063 } else if (!noCalls && this$1.eat(types.parenL)) {
2064 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
2065 this$1.yieldPos = 0;
2066 this$1.awaitPos = 0;
2067 var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
2068 if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
2069 this$1.checkPatternErrors(refDestructuringErrors, false);
2070 this$1.checkYieldAwaitInDefaultParams();
2071 this$1.yieldPos = oldYieldPos;
2072 this$1.awaitPos = oldAwaitPos;
2073 return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
2074 }
2075 this$1.checkExpressionErrors(refDestructuringErrors, true);
2076 this$1.yieldPos = oldYieldPos || this$1.yieldPos;
2077 this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
2078 var node$1 = this$1.startNodeAt(startPos, startLoc);
2079 node$1.callee = base;
2080 node$1.arguments = exprList;
2081 base = this$1.finishNode(node$1, "CallExpression");
2082 } else if (this$1.type === types.backQuote) {
2083 var node$2 = this$1.startNodeAt(startPos, startLoc);
2084 node$2.tag = base;
2085 node$2.quasi = this$1.parseTemplate({isTagged: true});
2086 base = this$1.finishNode(node$2, "TaggedTemplateExpression");
2087 } else {
2088 return base
2089 }
2090 }
2091};
2092
2093// Parse an atomic expression — either a single token that is an
2094// expression, an expression started by a keyword like `function` or
2095// `new`, or an expression wrapped in punctuation like `()`, `[]`,
2096// or `{}`.
2097
2098pp$3.parseExprAtom = function(refDestructuringErrors) {
2099 var node, canBeArrow = this.potentialArrowAt == this.start;
2100 switch (this.type) {
2101 case types._super:
2102 if (!this.inFunction)
2103 { this.raise(this.start, "'super' outside of function or class"); }
2104 node = this.startNode();
2105 this.next();
2106 // The `super` keyword can appear at below:
2107 // SuperProperty:
2108 // super [ Expression ]
2109 // super . IdentifierName
2110 // SuperCall:
2111 // super Arguments
2112 if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
2113 { this.unexpected(); }
2114 return this.finishNode(node, "Super")
2115
2116 case types._this:
2117 node = this.startNode();
2118 this.next();
2119 return this.finishNode(node, "ThisExpression")
2120
2121 case types.name:
2122 var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
2123 var id = this.parseIdent(this.type !== types.name);
2124 if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
2125 { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
2126 if (canBeArrow && !this.canInsertSemicolon()) {
2127 if (this.eat(types.arrow))
2128 { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
2129 if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
2130 id = this.parseIdent();
2131 if (this.canInsertSemicolon() || !this.eat(types.arrow))
2132 { this.unexpected(); }
2133 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
2134 }
2135 }
2136 return id
2137
2138 case types.regexp:
2139 var value = this.value;
2140 node = this.parseLiteral(value.value);
2141 node.regex = {pattern: value.pattern, flags: value.flags};
2142 return node
2143
2144 case types.num: case types.string:
2145 return this.parseLiteral(this.value)
2146
2147 case types._null: case types._true: case types._false:
2148 node = this.startNode();
2149 node.value = this.type === types._null ? null : this.type === types._true;
2150 node.raw = this.type.keyword;
2151 this.next();
2152 return this.finishNode(node, "Literal")
2153
2154 case types.parenL:
2155 var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
2156 if (refDestructuringErrors) {
2157 if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
2158 { refDestructuringErrors.parenthesizedAssign = start; }
2159 if (refDestructuringErrors.parenthesizedBind < 0)
2160 { refDestructuringErrors.parenthesizedBind = start; }
2161 }
2162 return expr
2163
2164 case types.bracketL:
2165 node = this.startNode();
2166 this.next();
2167 node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
2168 return this.finishNode(node, "ArrayExpression")
2169
2170 case types.braceL:
2171 return this.parseObj(false, refDestructuringErrors)
2172
2173 case types._function:
2174 node = this.startNode();
2175 this.next();
2176 return this.parseFunction(node, false)
2177
2178 case types._class:
2179 return this.parseClass(this.startNode(), false)
2180
2181 case types._new:
2182 return this.parseNew()
2183
2184 case types.backQuote:
2185 return this.parseTemplate()
2186
2187 default:
2188 this.unexpected();
2189 }
2190};
2191
2192pp$3.parseLiteral = function(value) {
2193 var node = this.startNode();
2194 node.value = value;
2195 node.raw = this.input.slice(this.start, this.end);
2196 this.next();
2197 return this.finishNode(node, "Literal")
2198};
2199
2200pp$3.parseParenExpression = function() {
2201 this.expect(types.parenL);
2202 var val = this.parseExpression();
2203 this.expect(types.parenR);
2204 return val
2205};
2206
2207pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
2208 var this$1 = this;
2209
2210 var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
2211 if (this.options.ecmaVersion >= 6) {
2212 this.next();
2213
2214 var innerStartPos = this.start, innerStartLoc = this.startLoc;
2215 var exprList = [], first = true, lastIsComma = false;
2216 var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
2217 this.yieldPos = 0;
2218 this.awaitPos = 0;
2219 while (this.type !== types.parenR) {
2220 first ? first = false : this$1.expect(types.comma);
2221 if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
2222 lastIsComma = true;
2223 break
2224 } else if (this$1.type === types.ellipsis) {
2225 spreadStart = this$1.start;
2226 exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
2227 if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
2228 break
2229 } else {
2230 exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
2231 }
2232 }
2233 var innerEndPos = this.start, innerEndLoc = this.startLoc;
2234 this.expect(types.parenR);
2235
2236 if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2237 this.checkPatternErrors(refDestructuringErrors, false);
2238 this.checkYieldAwaitInDefaultParams();
2239 this.yieldPos = oldYieldPos;
2240 this.awaitPos = oldAwaitPos;
2241 return this.parseParenArrowList(startPos, startLoc, exprList)
2242 }
2243
2244 if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
2245 if (spreadStart) { this.unexpected(spreadStart); }
2246 this.checkExpressionErrors(refDestructuringErrors, true);
2247 this.yieldPos = oldYieldPos || this.yieldPos;
2248 this.awaitPos = oldAwaitPos || this.awaitPos;
2249
2250 if (exprList.length > 1) {
2251 val = this.startNodeAt(innerStartPos, innerStartLoc);
2252 val.expressions = exprList;
2253 this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
2254 } else {
2255 val = exprList[0];
2256 }
2257 } else {
2258 val = this.parseParenExpression();
2259 }
2260
2261 if (this.options.preserveParens) {
2262 var par = this.startNodeAt(startPos, startLoc);
2263 par.expression = val;
2264 return this.finishNode(par, "ParenthesizedExpression")
2265 } else {
2266 return val
2267 }
2268};
2269
2270pp$3.parseParenItem = function(item) {
2271 return item
2272};
2273
2274pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
2275 return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
2276};
2277
2278// New's precedence is slightly tricky. It must allow its argument to
2279// be a `[]` or dot subscript expression, but not a call — at least,
2280// not without wrapping it in parentheses. Thus, it uses the noCalls
2281// argument to parseSubscripts to prevent it from consuming the
2282// argument list.
2283
2284var empty$1 = [];
2285
2286pp$3.parseNew = function() {
2287 var node = this.startNode();
2288 var meta = this.parseIdent(true);
2289 if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
2290 node.meta = meta;
2291 var containsEsc = this.containsEsc;
2292 node.property = this.parseIdent(true);
2293 if (node.property.name !== "target" || containsEsc)
2294 { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
2295 if (!this.inFunction)
2296 { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
2297 return this.finishNode(node, "MetaProperty")
2298 }
2299 var startPos = this.start, startLoc = this.startLoc;
2300 node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
2301 if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
2302 else { node.arguments = empty$1; }
2303 return this.finishNode(node, "NewExpression")
2304};
2305
2306// Parse template expression.
2307
2308pp$3.parseTemplateElement = function(ref) {
2309 var isTagged = ref.isTagged;
2310
2311 var elem = this.startNode();
2312 if (this.type === types.invalidTemplate) {
2313 if (!isTagged) {
2314 this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
2315 }
2316 elem.value = {
2317 raw: this.value,
2318 cooked: null
2319 };
2320 } else {
2321 elem.value = {
2322 raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
2323 cooked: this.value
2324 };
2325 }
2326 this.next();
2327 elem.tail = this.type === types.backQuote;
2328 return this.finishNode(elem, "TemplateElement")
2329};
2330
2331pp$3.parseTemplate = function(ref) {
2332 var this$1 = this;
2333 if ( ref === void 0 ) ref = {};
2334 var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
2335
2336 var node = this.startNode();
2337 this.next();
2338 node.expressions = [];
2339 var curElt = this.parseTemplateElement({isTagged: isTagged});
2340 node.quasis = [curElt];
2341 while (!curElt.tail) {
2342 this$1.expect(types.dollarBraceL);
2343 node.expressions.push(this$1.parseExpression());
2344 this$1.expect(types.braceR);
2345 node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
2346 }
2347 this.next();
2348 return this.finishNode(node, "TemplateLiteral")
2349};
2350
2351pp$3.isAsyncProp = function(prop) {
2352 return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
2353 (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)) &&
2354 !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
2355};
2356
2357// Parse an object literal or binding pattern.
2358
2359pp$3.parseObj = function(isPattern, refDestructuringErrors) {
2360 var this$1 = this;
2361
2362 var node = this.startNode(), first = true, propHash = {};
2363 node.properties = [];
2364 this.next();
2365 while (!this.eat(types.braceR)) {
2366 if (!first) {
2367 this$1.expect(types.comma);
2368 if (this$1.afterTrailingComma(types.braceR)) { break }
2369 } else { first = false; }
2370
2371 var prop = this$1.parseProperty(isPattern, refDestructuringErrors);
2372 if (!isPattern) { this$1.checkPropClash(prop, propHash, refDestructuringErrors); }
2373 node.properties.push(prop);
2374 }
2375 return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
2376};
2377
2378pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
2379 var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
2380 if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
2381 if (isPattern) {
2382 prop.argument = this.parseIdent(false);
2383 if (this.type === types.comma) {
2384 this.raise(this.start, "Comma is not permitted after the rest element");
2385 }
2386 return this.finishNode(prop, "RestElement")
2387 }
2388 // To disallow parenthesized identifier via `this.toAssignable()`.
2389 if (this.type === types.parenL && refDestructuringErrors) {
2390 if (refDestructuringErrors.parenthesizedAssign < 0) {
2391 refDestructuringErrors.parenthesizedAssign = this.start;
2392 }
2393 if (refDestructuringErrors.parenthesizedBind < 0) {
2394 refDestructuringErrors.parenthesizedBind = this.start;
2395 }
2396 }
2397 // Parse argument.
2398 prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
2399 // To disallow trailing comma via `this.toAssignable()`.
2400 if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
2401 refDestructuringErrors.trailingComma = this.start;
2402 }
2403 // Finish
2404 return this.finishNode(prop, "SpreadElement")
2405 }
2406 if (this.options.ecmaVersion >= 6) {
2407 prop.method = false;
2408 prop.shorthand = false;
2409 if (isPattern || refDestructuringErrors) {
2410 startPos = this.start;
2411 startLoc = this.startLoc;
2412 }
2413 if (!isPattern)
2414 { isGenerator = this.eat(types.star); }
2415 }
2416 var containsEsc = this.containsEsc;
2417 this.parsePropertyName(prop);
2418 if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
2419 isAsync = true;
2420 isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
2421 this.parsePropertyName(prop, refDestructuringErrors);
2422 } else {
2423 isAsync = false;
2424 }
2425 this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
2426 return this.finishNode(prop, "Property")
2427};
2428
2429pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
2430 if ((isGenerator || isAsync) && this.type === types.colon)
2431 { this.unexpected(); }
2432
2433 if (this.eat(types.colon)) {
2434 prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
2435 prop.kind = "init";
2436 } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
2437 if (isPattern) { this.unexpected(); }
2438 prop.kind = "init";
2439 prop.method = true;
2440 prop.value = this.parseMethod(isGenerator, isAsync);
2441 } else if (!isPattern && !containsEsc &&
2442 this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
2443 (prop.key.name === "get" || prop.key.name === "set") &&
2444 (this.type != types.comma && this.type != types.braceR)) {
2445 if (isGenerator || isAsync) { this.unexpected(); }
2446 prop.kind = prop.key.name;
2447 this.parsePropertyName(prop);
2448 prop.value = this.parseMethod(false);
2449 var paramCount = prop.kind === "get" ? 0 : 1;
2450 if (prop.value.params.length !== paramCount) {
2451 var start = prop.value.start;
2452 if (prop.kind === "get")
2453 { this.raiseRecoverable(start, "getter should have no params"); }
2454 else
2455 { this.raiseRecoverable(start, "setter should have exactly one param"); }
2456 } else {
2457 if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
2458 { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
2459 }
2460 } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
2461 this.checkUnreserved(prop.key);
2462 prop.kind = "init";
2463 if (isPattern) {
2464 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2465 } else if (this.type === types.eq && refDestructuringErrors) {
2466 if (refDestructuringErrors.shorthandAssign < 0)
2467 { refDestructuringErrors.shorthandAssign = this.start; }
2468 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2469 } else {
2470 prop.value = prop.key;
2471 }
2472 prop.shorthand = true;
2473 } else { this.unexpected(); }
2474};
2475
2476pp$3.parsePropertyName = function(prop) {
2477 if (this.options.ecmaVersion >= 6) {
2478 if (this.eat(types.bracketL)) {
2479 prop.computed = true;
2480 prop.key = this.parseMaybeAssign();
2481 this.expect(types.bracketR);
2482 return prop.key
2483 } else {
2484 prop.computed = false;
2485 }
2486 }
2487 return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
2488};
2489
2490// Initialize empty function node.
2491
2492pp$3.initFunction = function(node) {
2493 node.id = null;
2494 if (this.options.ecmaVersion >= 6) {
2495 node.generator = false;
2496 node.expression = false;
2497 }
2498 if (this.options.ecmaVersion >= 8)
2499 { node.async = false; }
2500};
2501
2502// Parse object or class method.
2503
2504pp$3.parseMethod = function(isGenerator, isAsync) {
2505 var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
2506 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
2507
2508 this.initFunction(node);
2509 if (this.options.ecmaVersion >= 6)
2510 { node.generator = isGenerator; }
2511 if (this.options.ecmaVersion >= 8)
2512 { node.async = !!isAsync; }
2513
2514 this.inGenerator = node.generator;
2515 this.inAsync = node.async;
2516 this.yieldPos = 0;
2517 this.awaitPos = 0;
2518 this.inFunction = true;
2519 this.enterFunctionScope();
2520
2521 this.expect(types.parenL);
2522 node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
2523 this.checkYieldAwaitInDefaultParams();
2524 this.parseFunctionBody(node, false);
2525
2526 this.inGenerator = oldInGen;
2527 this.inAsync = oldInAsync;
2528 this.yieldPos = oldYieldPos;
2529 this.awaitPos = oldAwaitPos;
2530 this.inFunction = oldInFunc;
2531 return this.finishNode(node, "FunctionExpression")
2532};
2533
2534// Parse arrow function expression with given parameters.
2535
2536pp$3.parseArrowExpression = function(node, params, isAsync) {
2537 var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
2538 oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
2539
2540 this.enterFunctionScope();
2541 this.initFunction(node);
2542 if (this.options.ecmaVersion >= 8)
2543 { node.async = !!isAsync; }
2544
2545 this.inGenerator = false;
2546 this.inAsync = node.async;
2547 this.yieldPos = 0;
2548 this.awaitPos = 0;
2549 this.inFunction = true;
2550
2551 node.params = this.toAssignableList(params, true);
2552 this.parseFunctionBody(node, true);
2553
2554 this.inGenerator = oldInGen;
2555 this.inAsync = oldInAsync;
2556 this.yieldPos = oldYieldPos;
2557 this.awaitPos = oldAwaitPos;
2558 this.inFunction = oldInFunc;
2559 return this.finishNode(node, "ArrowFunctionExpression")
2560};
2561
2562// Parse function body and check parameters.
2563
2564pp$3.parseFunctionBody = function(node, isArrowFunction) {
2565 var isExpression = isArrowFunction && this.type !== types.braceL;
2566 var oldStrict = this.strict, useStrict = false;
2567
2568 if (isExpression) {
2569 node.body = this.parseMaybeAssign();
2570 node.expression = true;
2571 this.checkParams(node, false);
2572 } else {
2573 var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
2574 if (!oldStrict || nonSimple) {
2575 useStrict = this.strictDirective(this.end);
2576 // If this is a strict mode function, verify that argument names
2577 // are not repeated, and it does not try to bind the words `eval`
2578 // or `arguments`.
2579 if (useStrict && nonSimple)
2580 { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
2581 }
2582 // Start a new scope with regard to labels and the `inFunction`
2583 // flag (restore them to their old value afterwards).
2584 var oldLabels = this.labels;
2585 this.labels = [];
2586 if (useStrict) { this.strict = true; }
2587
2588 // Add the params to varDeclaredNames to ensure that an error is thrown
2589 // if a let/const declaration in the function clashes with one of the params.
2590 this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
2591 node.body = this.parseBlock(false);
2592 node.expression = false;
2593 this.adaptDirectivePrologue(node.body.body);
2594 this.labels = oldLabels;
2595 }
2596 this.exitFunctionScope();
2597
2598 if (this.strict && node.id) {
2599 // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
2600 this.checkLVal(node.id, "none");
2601 }
2602 this.strict = oldStrict;
2603};
2604
2605pp$3.isSimpleParamList = function(params) {
2606 for (var i = 0, list = params; i < list.length; i += 1)
2607 {
2608 var param = list[i];
2609
2610 if (param.type !== "Identifier") { return false
2611 } }
2612 return true
2613};
2614
2615// Checks function params for various disallowed patterns such as using "eval"
2616// or "arguments" and duplicate parameters.
2617
2618pp$3.checkParams = function(node, allowDuplicates) {
2619 var this$1 = this;
2620
2621 var nameHash = {};
2622 for (var i = 0, list = node.params; i < list.length; i += 1)
2623 {
2624 var param = list[i];
2625
2626 this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
2627 }
2628};
2629
2630// Parses a comma-separated list of expressions, and returns them as
2631// an array. `close` is the token type that ends the list, and
2632// `allowEmpty` can be turned on to allow subsequent commas with
2633// nothing in between them to be parsed as `null` (which is needed
2634// for array literals).
2635
2636pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
2637 var this$1 = this;
2638
2639 var elts = [], first = true;
2640 while (!this.eat(close)) {
2641 if (!first) {
2642 this$1.expect(types.comma);
2643 if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
2644 } else { first = false; }
2645
2646 var elt = (void 0);
2647 if (allowEmpty && this$1.type === types.comma)
2648 { elt = null; }
2649 else if (this$1.type === types.ellipsis) {
2650 elt = this$1.parseSpread(refDestructuringErrors);
2651 if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
2652 { refDestructuringErrors.trailingComma = this$1.start; }
2653 } else {
2654 elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
2655 }
2656 elts.push(elt);
2657 }
2658 return elts
2659};
2660
2661pp$3.checkUnreserved = function(ref) {
2662 var start = ref.start;
2663 var end = ref.end;
2664 var name = ref.name;
2665
2666 if (this.inGenerator && name === "yield")
2667 { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
2668 if (this.inAsync && name === "await")
2669 { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
2670 if (this.isKeyword(name))
2671 { this.raise(start, ("Unexpected keyword '" + name + "'")); }
2672 if (this.options.ecmaVersion < 6 &&
2673 this.input.slice(start, end).indexOf("\\") != -1) { return }
2674 var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
2675 if (re.test(name)) {
2676 if (!this.inAsync && name === "await")
2677 { this.raiseRecoverable(start, "Can not use keyword 'await' outside an async function"); }
2678 this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
2679 }
2680};
2681
2682// Parse the next token as an identifier. If `liberal` is true (used
2683// when parsing properties), it will also convert keywords into
2684// identifiers.
2685
2686pp$3.parseIdent = function(liberal, isBinding) {
2687 var node = this.startNode();
2688 if (liberal && this.options.allowReserved == "never") { liberal = false; }
2689 if (this.type === types.name) {
2690 node.name = this.value;
2691 } else if (this.type.keyword) {
2692 node.name = this.type.keyword;
2693
2694 // To fix https://github.com/acornjs/acorn/issues/575
2695 // `class` and `function` keywords push new context into this.context.
2696 // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
2697 // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
2698 if ((node.name === "class" || node.name === "function") &&
2699 (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
2700 this.context.pop();
2701 }
2702 } else {
2703 this.unexpected();
2704 }
2705 this.next();
2706 this.finishNode(node, "Identifier");
2707 if (!liberal) { this.checkUnreserved(node); }
2708 return node
2709};
2710
2711// Parses yield expression inside generator.
2712
2713pp$3.parseYield = function() {
2714 if (!this.yieldPos) { this.yieldPos = this.start; }
2715
2716 var node = this.startNode();
2717 this.next();
2718 if (this.type == types.semi || this.canInsertSemicolon() || (this.type != types.star && !this.type.startsExpr)) {
2719 node.delegate = false;
2720 node.argument = null;
2721 } else {
2722 node.delegate = this.eat(types.star);
2723 node.argument = this.parseMaybeAssign();
2724 }
2725 return this.finishNode(node, "YieldExpression")
2726};
2727
2728pp$3.parseAwait = function() {
2729 if (!this.awaitPos) { this.awaitPos = this.start; }
2730
2731 var node = this.startNode();
2732 this.next();
2733 node.argument = this.parseMaybeUnary(null, true);
2734 return this.finishNode(node, "AwaitExpression")
2735};
2736
2737var pp$4 = Parser.prototype;
2738
2739// This function is used to raise exceptions on parse errors. It
2740// takes an offset integer (into the current `input`) to indicate
2741// the location of the error, attaches the position to the end
2742// of the error message, and then raises a `SyntaxError` with that
2743// message.
2744
2745pp$4.raise = function(pos, message) {
2746 var loc = getLineInfo(this.input, pos);
2747 message += " (" + loc.line + ":" + loc.column + ")";
2748 var err = new SyntaxError(message);
2749 err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
2750 throw err
2751};
2752
2753pp$4.raiseRecoverable = pp$4.raise;
2754
2755pp$4.curPosition = function() {
2756 if (this.options.locations) {
2757 return new Position(this.curLine, this.pos - this.lineStart)
2758 }
2759};
2760
2761var pp$5 = Parser.prototype;
2762
2763// Object.assign polyfill
2764var assign = Object.assign || function(target) {
2765 var sources = [], len = arguments.length - 1;
2766 while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
2767
2768 for (var i = 0, list = sources; i < list.length; i += 1) {
2769 var source = list[i];
2770
2771 for (var key in source) {
2772 if (has(source, key)) {
2773 target[key] = source[key];
2774 }
2775 }
2776 }
2777 return target
2778};
2779
2780// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
2781
2782pp$5.enterFunctionScope = function() {
2783 // var: a hash of var-declared names in the current lexical scope
2784 // lexical: a hash of lexically-declared names in the current lexical scope
2785 // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
2786 // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
2787 this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
2788};
2789
2790pp$5.exitFunctionScope = function() {
2791 this.scopeStack.pop();
2792};
2793
2794pp$5.enterLexicalScope = function() {
2795 var parentScope = this.scopeStack[this.scopeStack.length - 1];
2796 var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
2797
2798 this.scopeStack.push(childScope);
2799 assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
2800};
2801
2802pp$5.exitLexicalScope = function() {
2803 var childScope = this.scopeStack.pop();
2804 var parentScope = this.scopeStack[this.scopeStack.length - 1];
2805
2806 assign(parentScope.childVar, childScope.var, childScope.childVar);
2807};
2808
2809/**
2810 * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
2811 * in the current lexical scope or any of the parent lexical scopes in this function.
2812 */
2813pp$5.canDeclareVarName = function(name) {
2814 var currentScope = this.scopeStack[this.scopeStack.length - 1];
2815
2816 return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
2817};
2818
2819/**
2820 * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
2821 * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
2822 * any child lexical scopes in this function.
2823 */
2824pp$5.canDeclareLexicalName = function(name) {
2825 var currentScope = this.scopeStack[this.scopeStack.length - 1];
2826
2827 return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
2828};
2829
2830pp$5.declareVarName = function(name) {
2831 this.scopeStack[this.scopeStack.length - 1].var[name] = true;
2832};
2833
2834pp$5.declareLexicalName = function(name) {
2835 this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
2836};
2837
2838var Node = function Node(parser, pos, loc) {
2839 this.type = "";
2840 this.start = pos;
2841 this.end = 0;
2842 if (parser.options.locations)
2843 { this.loc = new SourceLocation(parser, loc); }
2844 if (parser.options.directSourceFile)
2845 { this.sourceFile = parser.options.directSourceFile; }
2846 if (parser.options.ranges)
2847 { this.range = [pos, 0]; }
2848};
2849
2850// Start an AST node, attaching a start offset.
2851
2852var pp$6 = Parser.prototype;
2853
2854pp$6.startNode = function() {
2855 return new Node(this, this.start, this.startLoc)
2856};
2857
2858pp$6.startNodeAt = function(pos, loc) {
2859 return new Node(this, pos, loc)
2860};
2861
2862// Finish an AST node, adding `type` and `end` properties.
2863
2864function finishNodeAt(node, type, pos, loc) {
2865 node.type = type;
2866 node.end = pos;
2867 if (this.options.locations)
2868 { node.loc.end = loc; }
2869 if (this.options.ranges)
2870 { node.range[1] = pos; }
2871 return node
2872}
2873
2874pp$6.finishNode = function(node, type) {
2875 return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
2876};
2877
2878// Finish node at given position
2879
2880pp$6.finishNodeAt = function(node, type, pos, loc) {
2881 return finishNodeAt.call(this, node, type, pos, loc)
2882};
2883
2884// The algorithm used to determine whether a regexp can appear at a
2885// given point in the program is loosely based on sweet.js' approach.
2886// See https://github.com/mozilla/sweet.js/wiki/design
2887
2888var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
2889 this.token = token;
2890 this.isExpr = !!isExpr;
2891 this.preserveSpace = !!preserveSpace;
2892 this.override = override;
2893 this.generator = !!generator;
2894};
2895
2896var types$1 = {
2897 b_stat: new TokContext("{", false),
2898 b_expr: new TokContext("{", true),
2899 b_tmpl: new TokContext("${", false),
2900 p_stat: new TokContext("(", false),
2901 p_expr: new TokContext("(", true),
2902 q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
2903 f_stat: new TokContext("function", false),
2904 f_expr: new TokContext("function", true),
2905 f_expr_gen: new TokContext("function", true, false, null, true),
2906 f_gen: new TokContext("function", false, false, null, true)
2907};
2908
2909var pp$7 = Parser.prototype;
2910
2911pp$7.initialContext = function() {
2912 return [types$1.b_stat]
2913};
2914
2915pp$7.braceIsBlock = function(prevType) {
2916 var parent = this.curContext();
2917 if (parent === types$1.f_expr || parent === types$1.f_stat)
2918 { return true }
2919 if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
2920 { return !parent.isExpr }
2921
2922 // The check for `tt.name && exprAllowed` detects whether we are
2923 // after a `yield` or `of` construct. See the `updateContext` for
2924 // `tt.name`.
2925 if (prevType === types._return || prevType == types.name && this.exprAllowed)
2926 { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
2927 if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType == types.arrow)
2928 { return true }
2929 if (prevType == types.braceL)
2930 { return parent === types$1.b_stat }
2931 if (prevType == types._var || prevType == types.name)
2932 { return false }
2933 return !this.exprAllowed
2934};
2935
2936pp$7.inGeneratorContext = function() {
2937 var this$1 = this;
2938
2939 for (var i = this.context.length - 1; i >= 1; i--) {
2940 var context = this$1.context[i];
2941 if (context.token === "function")
2942 { return context.generator }
2943 }
2944 return false
2945};
2946
2947pp$7.updateContext = function(prevType) {
2948 var update, type = this.type;
2949 if (type.keyword && prevType == types.dot)
2950 { this.exprAllowed = false; }
2951 else if (update = type.updateContext)
2952 { update.call(this, prevType); }
2953 else
2954 { this.exprAllowed = type.beforeExpr; }
2955};
2956
2957// Token-specific context update code
2958
2959types.parenR.updateContext = types.braceR.updateContext = function() {
2960 if (this.context.length == 1) {
2961 this.exprAllowed = true;
2962 return
2963 }
2964 var out = this.context.pop();
2965 if (out === types$1.b_stat && this.curContext().token === "function") {
2966 out = this.context.pop();
2967 }
2968 this.exprAllowed = !out.isExpr;
2969};
2970
2971types.braceL.updateContext = function(prevType) {
2972 this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
2973 this.exprAllowed = true;
2974};
2975
2976types.dollarBraceL.updateContext = function() {
2977 this.context.push(types$1.b_tmpl);
2978 this.exprAllowed = true;
2979};
2980
2981types.parenL.updateContext = function(prevType) {
2982 var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
2983 this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
2984 this.exprAllowed = true;
2985};
2986
2987types.incDec.updateContext = function() {
2988 // tokExprAllowed stays unchanged
2989};
2990
2991types._function.updateContext = types._class.updateContext = function(prevType) {
2992 if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
2993 !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
2994 { this.context.push(types$1.f_expr); }
2995 else
2996 { this.context.push(types$1.f_stat); }
2997 this.exprAllowed = false;
2998};
2999
3000types.backQuote.updateContext = function() {
3001 if (this.curContext() === types$1.q_tmpl)
3002 { this.context.pop(); }
3003 else
3004 { this.context.push(types$1.q_tmpl); }
3005 this.exprAllowed = false;
3006};
3007
3008types.star.updateContext = function(prevType) {
3009 if (prevType == types._function) {
3010 var index = this.context.length - 1;
3011 if (this.context[index] === types$1.f_expr)
3012 { this.context[index] = types$1.f_expr_gen; }
3013 else
3014 { this.context[index] = types$1.f_gen; }
3015 }
3016 this.exprAllowed = true;
3017};
3018
3019types.name.updateContext = function(prevType) {
3020 var allowed = false;
3021 if (this.options.ecmaVersion >= 6) {
3022 if (this.value == "of" && !this.exprAllowed ||
3023 this.value == "yield" && this.inGeneratorContext())
3024 { allowed = true; }
3025 }
3026 this.exprAllowed = allowed;
3027};
3028
3029var data = {
3030 "$LONE": [
3031 "ASCII",
3032 "ASCII_Hex_Digit",
3033 "AHex",
3034 "Alphabetic",
3035 "Alpha",
3036 "Any",
3037 "Assigned",
3038 "Bidi_Control",
3039 "Bidi_C",
3040 "Bidi_Mirrored",
3041 "Bidi_M",
3042 "Case_Ignorable",
3043 "CI",
3044 "Cased",
3045 "Changes_When_Casefolded",
3046 "CWCF",
3047 "Changes_When_Casemapped",
3048 "CWCM",
3049 "Changes_When_Lowercased",
3050 "CWL",
3051 "Changes_When_NFKC_Casefolded",
3052 "CWKCF",
3053 "Changes_When_Titlecased",
3054 "CWT",
3055 "Changes_When_Uppercased",
3056 "CWU",
3057 "Dash",
3058 "Default_Ignorable_Code_Point",
3059 "DI",
3060 "Deprecated",
3061 "Dep",
3062 "Diacritic",
3063 "Dia",
3064 "Emoji",
3065 "Emoji_Component",
3066 "Emoji_Modifier",
3067 "Emoji_Modifier_Base",
3068 "Emoji_Presentation",
3069 "Extender",
3070 "Ext",
3071 "Grapheme_Base",
3072 "Gr_Base",
3073 "Grapheme_Extend",
3074 "Gr_Ext",
3075 "Hex_Digit",
3076 "Hex",
3077 "IDS_Binary_Operator",
3078 "IDSB",
3079 "IDS_Trinary_Operator",
3080 "IDST",
3081 "ID_Continue",
3082 "IDC",
3083 "ID_Start",
3084 "IDS",
3085 "Ideographic",
3086 "Ideo",
3087 "Join_Control",
3088 "Join_C",
3089 "Logical_Order_Exception",
3090 "LOE",
3091 "Lowercase",
3092 "Lower",
3093 "Math",
3094 "Noncharacter_Code_Point",
3095 "NChar",
3096 "Pattern_Syntax",
3097 "Pat_Syn",
3098 "Pattern_White_Space",
3099 "Pat_WS",
3100 "Quotation_Mark",
3101 "QMark",
3102 "Radical",
3103 "Regional_Indicator",
3104 "RI",
3105 "Sentence_Terminal",
3106 "STerm",
3107 "Soft_Dotted",
3108 "SD",
3109 "Terminal_Punctuation",
3110 "Term",
3111 "Unified_Ideograph",
3112 "UIdeo",
3113 "Uppercase",
3114 "Upper",
3115 "Variation_Selector",
3116 "VS",
3117 "White_Space",
3118 "space",
3119 "XID_Continue",
3120 "XIDC",
3121 "XID_Start",
3122 "XIDS"
3123 ],
3124 "General_Category": [
3125 "Cased_Letter",
3126 "LC",
3127 "Close_Punctuation",
3128 "Pe",
3129 "Connector_Punctuation",
3130 "Pc",
3131 "Control",
3132 "Cc",
3133 "cntrl",
3134 "Currency_Symbol",
3135 "Sc",
3136 "Dash_Punctuation",
3137 "Pd",
3138 "Decimal_Number",
3139 "Nd",
3140 "digit",
3141 "Enclosing_Mark",
3142 "Me",
3143 "Final_Punctuation",
3144 "Pf",
3145 "Format",
3146 "Cf",
3147 "Initial_Punctuation",
3148 "Pi",
3149 "Letter",
3150 "L",
3151 "Letter_Number",
3152 "Nl",
3153 "Line_Separator",
3154 "Zl",
3155 "Lowercase_Letter",
3156 "Ll",
3157 "Mark",
3158 "M",
3159 "Combining_Mark",
3160 "Math_Symbol",
3161 "Sm",
3162 "Modifier_Letter",
3163 "Lm",
3164 "Modifier_Symbol",
3165 "Sk",
3166 "Nonspacing_Mark",
3167 "Mn",
3168 "Number",
3169 "N",
3170 "Open_Punctuation",
3171 "Ps",
3172 "Other",
3173 "C",
3174 "Other_Letter",
3175 "Lo",
3176 "Other_Number",
3177 "No",
3178 "Other_Punctuation",
3179 "Po",
3180 "Other_Symbol",
3181 "So",
3182 "Paragraph_Separator",
3183 "Zp",
3184 "Private_Use",
3185 "Co",
3186 "Punctuation",
3187 "P",
3188 "punct",
3189 "Separator",
3190 "Z",
3191 "Space_Separator",
3192 "Zs",
3193 "Spacing_Mark",
3194 "Mc",
3195 "Surrogate",
3196 "Cs",
3197 "Symbol",
3198 "S",
3199 "Titlecase_Letter",
3200 "Lt",
3201 "Unassigned",
3202 "Cn",
3203 "Uppercase_Letter",
3204 "Lu"
3205 ],
3206 "Script": [
3207 "Adlam",
3208 "Adlm",
3209 "Ahom",
3210 "Anatolian_Hieroglyphs",
3211 "Hluw",
3212 "Arabic",
3213 "Arab",
3214 "Armenian",
3215 "Armn",
3216 "Avestan",
3217 "Avst",
3218 "Balinese",
3219 "Bali",
3220 "Bamum",
3221 "Bamu",
3222 "Bassa_Vah",
3223 "Bass",
3224 "Batak",
3225 "Batk",
3226 "Bengali",
3227 "Beng",
3228 "Bhaiksuki",
3229 "Bhks",
3230 "Bopomofo",
3231 "Bopo",
3232 "Brahmi",
3233 "Brah",
3234 "Braille",
3235 "Brai",
3236 "Buginese",
3237 "Bugi",
3238 "Buhid",
3239 "Buhd",
3240 "Canadian_Aboriginal",
3241 "Cans",
3242 "Carian",
3243 "Cari",
3244 "Caucasian_Albanian",
3245 "Aghb",
3246 "Chakma",
3247 "Cakm",
3248 "Cham",
3249 "Cherokee",
3250 "Cher",
3251 "Common",
3252 "Zyyy",
3253 "Coptic",
3254 "Copt",
3255 "Qaac",
3256 "Cuneiform",
3257 "Xsux",
3258 "Cypriot",
3259 "Cprt",
3260 "Cyrillic",
3261 "Cyrl",
3262 "Deseret",
3263 "Dsrt",
3264 "Devanagari",
3265 "Deva",
3266 "Duployan",
3267 "Dupl",
3268 "Egyptian_Hieroglyphs",
3269 "Egyp",
3270 "Elbasan",
3271 "Elba",
3272 "Ethiopic",
3273 "Ethi",
3274 "Georgian",
3275 "Geor",
3276 "Glagolitic",
3277 "Glag",
3278 "Gothic",
3279 "Goth",
3280 "Grantha",
3281 "Gran",
3282 "Greek",
3283 "Grek",
3284 "Gujarati",
3285 "Gujr",
3286 "Gurmukhi",
3287 "Guru",
3288 "Han",
3289 "Hani",
3290 "Hangul",
3291 "Hang",
3292 "Hanunoo",
3293 "Hano",
3294 "Hatran",
3295 "Hatr",
3296 "Hebrew",
3297 "Hebr",
3298 "Hiragana",
3299 "Hira",
3300 "Imperial_Aramaic",
3301 "Armi",
3302 "Inherited",
3303 "Zinh",
3304 "Qaai",
3305 "Inscriptional_Pahlavi",
3306 "Phli",
3307 "Inscriptional_Parthian",
3308 "Prti",
3309 "Javanese",
3310 "Java",
3311 "Kaithi",
3312 "Kthi",
3313 "Kannada",
3314 "Knda",
3315 "Katakana",
3316 "Kana",
3317 "Kayah_Li",
3318 "Kali",
3319 "Kharoshthi",
3320 "Khar",
3321 "Khmer",
3322 "Khmr",
3323 "Khojki",
3324 "Khoj",
3325 "Khudawadi",
3326 "Sind",
3327 "Lao",
3328 "Laoo",
3329 "Latin",
3330 "Latn",
3331 "Lepcha",
3332 "Lepc",
3333 "Limbu",
3334 "Limb",
3335 "Linear_A",
3336 "Lina",
3337 "Linear_B",
3338 "Linb",
3339 "Lisu",
3340 "Lycian",
3341 "Lyci",
3342 "Lydian",
3343 "Lydi",
3344 "Mahajani",
3345 "Mahj",
3346 "Malayalam",
3347 "Mlym",
3348 "Mandaic",
3349 "Mand",
3350 "Manichaean",
3351 "Mani",
3352 "Marchen",
3353 "Marc",
3354 "Masaram_Gondi",
3355 "Gonm",
3356 "Meetei_Mayek",
3357 "Mtei",
3358 "Mende_Kikakui",
3359 "Mend",
3360 "Meroitic_Cursive",
3361 "Merc",
3362 "Meroitic_Hieroglyphs",
3363 "Mero",
3364 "Miao",
3365 "Plrd",
3366 "Modi",
3367 "Mongolian",
3368 "Mong",
3369 "Mro",
3370 "Mroo",
3371 "Multani",
3372 "Mult",
3373 "Myanmar",
3374 "Mymr",
3375 "Nabataean",
3376 "Nbat",
3377 "New_Tai_Lue",
3378 "Talu",
3379 "Newa",
3380 "Nko",
3381 "Nkoo",
3382 "Nushu",
3383 "Nshu",
3384 "Ogham",
3385 "Ogam",
3386 "Ol_Chiki",
3387 "Olck",
3388 "Old_Hungarian",
3389 "Hung",
3390 "Old_Italic",
3391 "Ital",
3392 "Old_North_Arabian",
3393 "Narb",
3394 "Old_Permic",
3395 "Perm",
3396 "Old_Persian",
3397 "Xpeo",
3398 "Old_South_Arabian",
3399 "Sarb",
3400 "Old_Turkic",
3401 "Orkh",
3402 "Oriya",
3403 "Orya",
3404 "Osage",
3405 "Osge",
3406 "Osmanya",
3407 "Osma",
3408 "Pahawh_Hmong",
3409 "Hmng",
3410 "Palmyrene",
3411 "Palm",
3412 "Pau_Cin_Hau",
3413 "Pauc",
3414 "Phags_Pa",
3415 "Phag",
3416 "Phoenician",
3417 "Phnx",
3418 "Psalter_Pahlavi",
3419 "Phlp",
3420 "Rejang",
3421 "Rjng",
3422 "Runic",
3423 "Runr",
3424 "Samaritan",
3425 "Samr",
3426 "Saurashtra",
3427 "Saur",
3428 "Sharada",
3429 "Shrd",
3430 "Shavian",
3431 "Shaw",
3432 "Siddham",
3433 "Sidd",
3434 "SignWriting",
3435 "Sgnw",
3436 "Sinhala",
3437 "Sinh",
3438 "Sora_Sompeng",
3439 "Sora",
3440 "Soyombo",
3441 "Soyo",
3442 "Sundanese",
3443 "Sund",
3444 "Syloti_Nagri",
3445 "Sylo",
3446 "Syriac",
3447 "Syrc",
3448 "Tagalog",
3449 "Tglg",
3450 "Tagbanwa",
3451 "Tagb",
3452 "Tai_Le",
3453 "Tale",
3454 "Tai_Tham",
3455 "Lana",
3456 "Tai_Viet",
3457 "Tavt",
3458 "Takri",
3459 "Takr",
3460 "Tamil",
3461 "Taml",
3462 "Tangut",
3463 "Tang",
3464 "Telugu",
3465 "Telu",
3466 "Thaana",
3467 "Thaa",
3468 "Thai",
3469 "Tibetan",
3470 "Tibt",
3471 "Tifinagh",
3472 "Tfng",
3473 "Tirhuta",
3474 "Tirh",
3475 "Ugaritic",
3476 "Ugar",
3477 "Vai",
3478 "Vaii",
3479 "Warang_Citi",
3480 "Wara",
3481 "Yi",
3482 "Yiii",
3483 "Zanabazar_Square",
3484 "Zanb"
3485 ]
3486};
3487Array.prototype.push.apply(data.$LONE, data.General_Category);
3488data.gc = data.General_Category;
3489data.sc = data.Script_Extensions = data.scx = data.Script;
3490
3491var pp$9 = Parser.prototype;
3492
3493var RegExpValidationState = function RegExpValidationState(parser) {
3494 this.parser = parser;
3495 this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
3496 this.source = "";
3497 this.flags = "";
3498 this.start = 0;
3499 this.switchU = false;
3500 this.switchN = false;
3501 this.pos = 0;
3502 this.lastIntValue = 0;
3503 this.lastStringValue = "";
3504 this.lastAssertionIsQuantifiable = false;
3505 this.numCapturingParens = 0;
3506 this.maxBackReference = 0;
3507 this.groupNames = [];
3508 this.backReferenceNames = [];
3509};
3510
3511RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
3512 var unicode = flags.indexOf("u") !== -1;
3513 this.start = start | 0;
3514 this.source = pattern + "";
3515 this.flags = flags;
3516 this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
3517 this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
3518};
3519
3520RegExpValidationState.prototype.raise = function raise (message) {
3521 this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
3522};
3523
3524// If u flag is given, this returns the code point at the index (it combines a surrogate pair).
3525// Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
3526RegExpValidationState.prototype.at = function at (i) {
3527 var s = this.source;
3528 var l = s.length;
3529 if (i >= l) {
3530 return -1
3531 }
3532 var c = s.charCodeAt(i);
3533 if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
3534 return c
3535 }
3536 return (c << 10) + s.charCodeAt(i + 1) - 0x35FDC00
3537};
3538
3539RegExpValidationState.prototype.nextIndex = function nextIndex (i) {
3540 var s = this.source;
3541 var l = s.length;
3542 if (i >= l) {
3543 return l
3544 }
3545 var c = s.charCodeAt(i);
3546 if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
3547 return i + 1
3548 }
3549 return i + 2
3550};
3551
3552RegExpValidationState.prototype.current = function current () {
3553 return this.at(this.pos)
3554};
3555
3556RegExpValidationState.prototype.lookahead = function lookahead () {
3557 return this.at(this.nextIndex(this.pos))
3558};
3559
3560RegExpValidationState.prototype.advance = function advance () {
3561 this.pos = this.nextIndex(this.pos);
3562};
3563
3564RegExpValidationState.prototype.eat = function eat (ch) {
3565 if (this.current() === ch) {
3566 this.advance();
3567 return true
3568 }
3569 return false
3570};
3571
3572function codePointToString$1(ch) {
3573 if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
3574 ch -= 0x10000;
3575 return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
3576}
3577
3578/**
3579 * Validate the flags part of a given RegExpLiteral.
3580 *
3581 * @param {RegExpValidationState} state The state to validate RegExp.
3582 * @returns {void}
3583 */
3584pp$9.validateRegExpFlags = function(state) {
3585 var this$1 = this;
3586
3587 var validFlags = state.validFlags;
3588 var flags = state.flags;
3589
3590 for (var i = 0; i < flags.length; i++) {
3591 var flag = flags.charAt(i);
3592 if (validFlags.indexOf(flag) == -1) {
3593 this$1.raise(state.start, "Invalid regular expression flag");
3594 }
3595 if (flags.indexOf(flag, i + 1) > -1) {
3596 this$1.raise(state.start, "Duplicate regular expression flag");
3597 }
3598 }
3599};
3600
3601/**
3602 * Validate the pattern part of a given RegExpLiteral.
3603 *
3604 * @param {RegExpValidationState} state The state to validate RegExp.
3605 * @returns {void}
3606 */
3607pp$9.validateRegExpPattern = function(state) {
3608 this.regexp_pattern(state);
3609
3610 // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
3611 // parsing contains a |GroupName|, reparse with the goal symbol
3612 // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
3613 // exception if _P_ did not conform to the grammar, if any elements of _P_
3614 // were not matched by the parse, or if any Early Error conditions exist.
3615 if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
3616 state.switchN = true;
3617 this.regexp_pattern(state);
3618 }
3619};
3620
3621// https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
3622pp$9.regexp_pattern = function(state) {
3623 state.pos = 0;
3624 state.lastIntValue = 0;
3625 state.lastStringValue = "";
3626 state.lastAssertionIsQuantifiable = false;
3627 state.numCapturingParens = 0;
3628 state.maxBackReference = 0;
3629 state.groupNames.length = 0;
3630 state.backReferenceNames.length = 0;
3631
3632 this.regexp_disjunction(state);
3633
3634 if (state.pos !== state.source.length) {
3635 // Make the same messages as V8.
3636 if (state.eat(0x29 /* ) */)) {
3637 state.raise("Unmatched ')'");
3638 }
3639 if (state.eat(0x5D /* [ */) || state.eat(0x7D /* } */)) {
3640 state.raise("Lone quantifier brackets");
3641 }
3642 }
3643 if (state.maxBackReference > state.numCapturingParens) {
3644 state.raise("Invalid escape");
3645 }
3646 for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
3647 var name = list[i];
3648
3649 if (state.groupNames.indexOf(name) === -1) {
3650 state.raise("Invalid named capture referenced");
3651 }
3652 }
3653};
3654
3655// https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
3656pp$9.regexp_disjunction = function(state) {
3657 var this$1 = this;
3658
3659 this.regexp_alternative(state);
3660 while (state.eat(0x7C /* | */)) {
3661 this$1.regexp_alternative(state);
3662 }
3663
3664 // Make the same message as V8.
3665 if (this.regexp_eatQuantifier(state, true)) {
3666 state.raise("Nothing to repeat");
3667 }
3668 if (state.eat(0x7B /* { */)) {
3669 state.raise("Lone quantifier brackets");
3670 }
3671};
3672
3673// https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
3674pp$9.regexp_alternative = function(state) {
3675 while (state.pos < state.source.length && this.regexp_eatTerm(state))
3676 { }
3677};
3678
3679// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
3680pp$9.regexp_eatTerm = function(state) {
3681 if (this.regexp_eatAssertion(state)) {
3682 // Handle `QuantifiableAssertion Quantifier` alternative.
3683 // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
3684 // is a QuantifiableAssertion.
3685 if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
3686 // Make the same message as V8.
3687 if (state.switchU) {
3688 state.raise("Invalid quantifier");
3689 }
3690 }
3691 return true
3692 }
3693
3694 if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
3695 this.regexp_eatQuantifier(state);
3696 return true
3697 }
3698
3699 return false
3700};
3701
3702// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
3703pp$9.regexp_eatAssertion = function(state) {
3704 var start = state.pos;
3705 state.lastAssertionIsQuantifiable = false;
3706
3707 // ^, $
3708 if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
3709 return true
3710 }
3711
3712 // \b \B
3713 if (state.eat(0x5C /* \ */)) {
3714 if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
3715 return true
3716 }
3717 state.pos = start;
3718 }
3719
3720 // Lookahead / Lookbehind
3721 if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
3722 var lookbehind = false;
3723 if (this.options.ecmaVersion >= 9) {
3724 lookbehind = state.eat(0x3C /* < */);
3725 }
3726 if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
3727 this.regexp_disjunction(state);
3728 if (!state.eat(0x29 /* ) */)) {
3729 state.raise("Unterminated group");
3730 }
3731 state.lastAssertionIsQuantifiable = !lookbehind;
3732 return true
3733 }
3734 }
3735
3736 state.pos = start;
3737 return false
3738};
3739
3740// https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
3741pp$9.regexp_eatQuantifier = function(state, noError) {
3742 if ( noError === void 0 ) noError = false;
3743
3744 if (this.regexp_eatQuantifierPrefix(state, noError)) {
3745 state.eat(0x3F /* ? */);
3746 return true
3747 }
3748 return false
3749};
3750
3751// https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
3752pp$9.regexp_eatQuantifierPrefix = function(state, noError) {
3753 return (
3754 state.eat(0x2A /* * */) ||
3755 state.eat(0x2B /* + */) ||
3756 state.eat(0x3F /* ? */) ||
3757 this.regexp_eatBracedQuantifier(state, noError)
3758 )
3759};
3760pp$9.regexp_eatBracedQuantifier = function(state, noError) {
3761 var start = state.pos;
3762 if (state.eat(0x7B /* { */)) {
3763 var min = 0, max = -1;
3764 if (this.regexp_eatDecimalDigits(state)) {
3765 min = state.lastIntValue;
3766 if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
3767 max = state.lastIntValue;
3768 }
3769 if (state.eat(0x7D /* } */)) {
3770 // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
3771 if (max !== -1 && max < min && !noError) {
3772 state.raise("numbers out of order in {} quantifier");
3773 }
3774 return true
3775 }
3776 }
3777 if (state.switchU && !noError) {
3778 state.raise("Incomplete quantifier");
3779 }
3780 state.pos = start;
3781 }
3782 return false
3783};
3784
3785// https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
3786pp$9.regexp_eatAtom = function(state) {
3787 return (
3788 this.regexp_eatPatternCharacters(state) ||
3789 state.eat(0x2E /* . */) ||
3790 this.regexp_eatReverseSolidusAtomEscape(state) ||
3791 this.regexp_eatCharacterClass(state) ||
3792 this.regexp_eatUncapturingGroup(state) ||
3793 this.regexp_eatCapturingGroup(state)
3794 )
3795};
3796pp$9.regexp_eatReverseSolidusAtomEscape = function(state) {
3797 var start = state.pos;
3798 if (state.eat(0x5C /* \ */)) {
3799 if (this.regexp_eatAtomEscape(state)) {
3800 return true
3801 }
3802 state.pos = start;
3803 }
3804 return false
3805};
3806pp$9.regexp_eatUncapturingGroup = function(state) {
3807 var start = state.pos;
3808 if (state.eat(0x28 /* ( */)) {
3809 if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
3810 this.regexp_disjunction(state);
3811 if (state.eat(0x29 /* ) */)) {
3812 return true
3813 }
3814 state.raise("Unterminated group");
3815 }
3816 state.pos = start;
3817 }
3818 return false
3819};
3820pp$9.regexp_eatCapturingGroup = function(state) {
3821 if (state.eat(0x28 /* ( */)) {
3822 if (this.options.ecmaVersion >= 9) {
3823 this.regexp_groupSpecifier(state);
3824 } else if (state.current() === 0x3F /* ? */) {
3825 state.raise("Invalid group");
3826 }
3827 this.regexp_disjunction(state);
3828 if (state.eat(0x29 /* ) */)) {
3829 state.numCapturingParens += 1;
3830 return true
3831 }
3832 state.raise("Unterminated group");
3833 }
3834 return false
3835};
3836
3837// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
3838pp$9.regexp_eatExtendedAtom = function(state) {
3839 return (
3840 state.eat(0x2E /* . */) ||
3841 this.regexp_eatReverseSolidusAtomEscape(state) ||
3842 this.regexp_eatCharacterClass(state) ||
3843 this.regexp_eatUncapturingGroup(state) ||
3844 this.regexp_eatCapturingGroup(state) ||
3845 this.regexp_eatInvalidBracedQuantifier(state) ||
3846 this.regexp_eatExtendedPatternCharacter(state)
3847 )
3848};
3849
3850// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
3851pp$9.regexp_eatInvalidBracedQuantifier = function(state) {
3852 if (this.regexp_eatBracedQuantifier(state, true)) {
3853 state.raise("Nothing to repeat");
3854 }
3855 return false
3856};
3857
3858// https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
3859pp$9.regexp_eatSyntaxCharacter = function(state) {
3860 var ch = state.current();
3861 if (isSyntaxCharacter(ch)) {
3862 state.lastIntValue = ch;
3863 state.advance();
3864 return true
3865 }
3866 return false
3867};
3868function isSyntaxCharacter(ch) {
3869 return (
3870 ch === 0x24 /* $ */ ||
3871 ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
3872 ch === 0x2E /* . */ ||
3873 ch === 0x3F /* ? */ ||
3874 ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
3875 ch >= 0x7B /* { */ && ch <= 0x7D /* } */
3876 )
3877}
3878
3879// https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
3880// But eat eager.
3881pp$9.regexp_eatPatternCharacters = function(state) {
3882 var start = state.pos;
3883 var ch = 0;
3884 while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
3885 state.advance();
3886 }
3887 return state.pos !== start
3888};
3889
3890// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
3891pp$9.regexp_eatExtendedPatternCharacter = function(state) {
3892 var ch = state.current();
3893 if (
3894 ch !== -1 &&
3895 ch !== 0x24 /* $ */ &&
3896 !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
3897 ch !== 0x2E /* . */ &&
3898 ch !== 0x3F /* ? */ &&
3899 ch !== 0x5B /* [ */ &&
3900 ch !== 0x5E /* ^ */ &&
3901 ch !== 0x7C /* | */
3902 ) {
3903 state.advance();
3904 return true
3905 }
3906 return false
3907};
3908
3909// GroupSpecifier[U] ::
3910// [empty]
3911// `?` GroupName[?U]
3912pp$9.regexp_groupSpecifier = function(state) {
3913 if (state.eat(0x3F /* ? */)) {
3914 if (this.regexp_eatGroupName(state)) {
3915 if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
3916 state.raise("Duplicate capture group name");
3917 }
3918 state.groupNames.push(state.lastStringValue);
3919 return
3920 }
3921 state.raise("Invalid group");
3922 }
3923};
3924
3925// GroupName[U] ::
3926// `<` RegExpIdentifierName[?U] `>`
3927// Note: this updates `state.lastStringValue` property with the eaten name.
3928pp$9.regexp_eatGroupName = function(state) {
3929 state.lastStringValue = "";
3930 if (state.eat(0x3C /* < */)) {
3931 if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
3932 return true
3933 }
3934 state.raise("Invalid capture group name");
3935 }
3936 return false
3937};
3938
3939// RegExpIdentifierName[U] ::
3940// RegExpIdentifierStart[?U]
3941// RegExpIdentifierName[?U] RegExpIdentifierPart[?U]
3942// Note: this updates `state.lastStringValue` property with the eaten name.
3943pp$9.regexp_eatRegExpIdentifierName = function(state) {
3944 state.lastStringValue = "";
3945 if (this.regexp_eatRegExpIdentifierStart(state)) {
3946 state.lastStringValue += codePointToString$1(state.lastIntValue);
3947 while (this.regexp_eatRegExpIdentifierPart(state)) {
3948 state.lastStringValue += codePointToString$1(state.lastIntValue);
3949 }
3950 return true
3951 }
3952 return false
3953};
3954
3955// RegExpIdentifierStart[U] ::
3956// UnicodeIDStart
3957// `$`
3958// `_`
3959// `\` RegExpUnicodeEscapeSequence[?U]
3960pp$9.regexp_eatRegExpIdentifierStart = function(state) {
3961 var start = state.pos;
3962 var ch = state.current();
3963 state.advance();
3964
3965 if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
3966 ch = state.lastIntValue;
3967 }
3968 if (isRegExpIdentifierStart(ch)) {
3969 state.lastIntValue = ch;
3970 return true
3971 }
3972
3973 state.pos = start;
3974 return false
3975};
3976function isRegExpIdentifierStart(ch) {
3977 return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
3978}
3979
3980// RegExpIdentifierPart[U] ::
3981// UnicodeIDContinue
3982// `$`
3983// `_`
3984// `\` RegExpUnicodeEscapeSequence[?U]
3985// <ZWNJ>
3986// <ZWJ>
3987pp$9.regexp_eatRegExpIdentifierPart = function(state) {
3988 var start = state.pos;
3989 var ch = state.current();
3990 state.advance();
3991
3992 if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
3993 ch = state.lastIntValue;
3994 }
3995 if (isRegExpIdentifierPart(ch)) {
3996 state.lastIntValue = ch;
3997 return true
3998 }
3999
4000 state.pos = start;
4001 return false
4002};
4003function isRegExpIdentifierPart(ch) {
4004 return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
4005}
4006
4007// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
4008pp$9.regexp_eatAtomEscape = function(state) {
4009 if (
4010 this.regexp_eatBackReference(state) ||
4011 this.regexp_eatCharacterClassEscape(state) ||
4012 this.regexp_eatCharacterEscape(state) ||
4013 (state.switchN && this.regexp_eatKGroupName(state))
4014 ) {
4015 return true
4016 }
4017 if (state.switchU) {
4018 // Make the same message as V8.
4019 if (state.current() === 0x63 /* c */) {
4020 state.raise("Invalid unicode escape");
4021 }
4022 state.raise("Invalid escape");
4023 }
4024 return false
4025};
4026pp$9.regexp_eatBackReference = function(state) {
4027 var start = state.pos;
4028 if (this.regexp_eatDecimalEscape(state)) {
4029 var n = state.lastIntValue;
4030 if (state.switchU) {
4031 // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
4032 if (n > state.maxBackReference) {
4033 state.maxBackReference = n;
4034 }
4035 return true
4036 }
4037 if (n <= state.numCapturingParens) {
4038 return true
4039 }
4040 state.pos = start;
4041 }
4042 return false
4043};
4044pp$9.regexp_eatKGroupName = function(state) {
4045 if (state.eat(0x6B /* k */)) {
4046 if (this.regexp_eatGroupName(state)) {
4047 state.backReferenceNames.push(state.lastStringValue);
4048 return true
4049 }
4050 state.raise("Invalid named reference");
4051 }
4052 return false
4053};
4054
4055// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
4056pp$9.regexp_eatCharacterEscape = function(state) {
4057 return (
4058 this.regexp_eatControlEscape(state) ||
4059 this.regexp_eatCControlLetter(state) ||
4060 this.regexp_eatZero(state) ||
4061 this.regexp_eatHexEscapeSequence(state) ||
4062 this.regexp_eatRegExpUnicodeEscapeSequence(state) ||
4063 (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
4064 this.regexp_eatIdentityEscape(state)
4065 )
4066};
4067pp$9.regexp_eatCControlLetter = function(state) {
4068 var start = state.pos;
4069 if (state.eat(0x63 /* c */)) {
4070 if (this.regexp_eatControlLetter(state)) {
4071 return true
4072 }
4073 state.pos = start;
4074 }
4075 return false
4076};
4077pp$9.regexp_eatZero = function(state) {
4078 if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
4079 state.lastIntValue = 0;
4080 state.advance();
4081 return true
4082 }
4083 return false
4084};
4085
4086// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
4087pp$9.regexp_eatControlEscape = function(state) {
4088 var ch = state.current();
4089 if (ch === 0x74 /* t */) {
4090 state.lastIntValue = 0x09; /* \t */
4091 state.advance();
4092 return true
4093 }
4094 if (ch === 0x6E /* n */) {
4095 state.lastIntValue = 0x0A; /* \n */
4096 state.advance();
4097 return true
4098 }
4099 if (ch === 0x76 /* v */) {
4100 state.lastIntValue = 0x0B; /* \v */
4101 state.advance();
4102 return true
4103 }
4104 if (ch === 0x66 /* f */) {
4105 state.lastIntValue = 0x0C; /* \f */
4106 state.advance();
4107 return true
4108 }
4109 if (ch === 0x72 /* r */) {
4110 state.lastIntValue = 0x0D; /* \r */
4111 state.advance();
4112 return true
4113 }
4114 return false
4115};
4116
4117// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
4118pp$9.regexp_eatControlLetter = function(state) {
4119 var ch = state.current();
4120 if (isControlLetter(ch)) {
4121 state.lastIntValue = ch % 0x20;
4122 state.advance();
4123 return true
4124 }
4125 return false
4126};
4127function isControlLetter(ch) {
4128 return (
4129 (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
4130 (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
4131 )
4132}
4133
4134// https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
4135pp$9.regexp_eatRegExpUnicodeEscapeSequence = function(state) {
4136 var start = state.pos;
4137
4138 if (state.eat(0x75 /* u */)) {
4139 if (this.regexp_eatFixedHexDigits(state, 4)) {
4140 var lead = state.lastIntValue;
4141 if (state.switchU && lead >= 0xD800 && lead <= 0xDBFF) {
4142 var leadSurrogateEnd = state.pos;
4143 if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
4144 var trail = state.lastIntValue;
4145 if (trail >= 0xDC00 && trail <= 0xDFFF) {
4146 state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
4147 return true
4148 }
4149 }
4150 state.pos = leadSurrogateEnd;
4151 state.lastIntValue = lead;
4152 }
4153 return true
4154 }
4155 if (
4156 state.switchU &&
4157 state.eat(0x7B /* { */) &&
4158 this.regexp_eatHexDigits(state) &&
4159 state.eat(0x7D /* } */) &&
4160 isValidUnicode(state.lastIntValue)
4161 ) {
4162 return true
4163 }
4164 if (state.switchU) {
4165 state.raise("Invalid unicode escape");
4166 }
4167 state.pos = start;
4168 }
4169
4170 return false
4171};
4172function isValidUnicode(ch) {
4173 return ch >= 0 && ch <= 0x10FFFF
4174}
4175
4176// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
4177pp$9.regexp_eatIdentityEscape = function(state) {
4178 if (state.switchU) {
4179 if (this.regexp_eatSyntaxCharacter(state)) {
4180 return true
4181 }
4182 if (state.eat(0x2F /* / */)) {
4183 state.lastIntValue = 0x2F; /* / */
4184 return true
4185 }
4186 return false
4187 }
4188
4189 var ch = state.current();
4190 if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
4191 state.lastIntValue = ch;
4192 state.advance();
4193 return true
4194 }
4195
4196 return false
4197};
4198
4199// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
4200pp$9.regexp_eatDecimalEscape = function(state) {
4201 state.lastIntValue = 0;
4202 var ch = state.current();
4203 if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
4204 do {
4205 state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
4206 state.advance();
4207 } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
4208 return true
4209 }
4210 return false
4211};
4212
4213// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
4214pp$9.regexp_eatCharacterClassEscape = function(state) {
4215 var ch = state.current();
4216
4217 if (isCharacterClassEscape(ch)) {
4218 state.lastIntValue = -1;
4219 state.advance();
4220 return true
4221 }
4222
4223 if (
4224 state.switchU &&
4225 this.options.ecmaVersion >= 9 &&
4226 (ch === 0x50 /* P */ || ch === 0x70 /* p */)
4227 ) {
4228 state.lastIntValue = -1;
4229 state.advance();
4230 if (
4231 state.eat(0x7B /* { */) &&
4232 this.regexp_eatUnicodePropertyValueExpression(state) &&
4233 state.eat(0x7D /* } */)
4234 ) {
4235 return true
4236 }
4237 state.raise("Invalid property name");
4238 }
4239
4240 return false
4241};
4242function isCharacterClassEscape(ch) {
4243 return (
4244 ch === 0x64 /* d */ ||
4245 ch === 0x44 /* D */ ||
4246 ch === 0x73 /* s */ ||
4247 ch === 0x53 /* S */ ||
4248 ch === 0x77 /* w */ ||
4249 ch === 0x57 /* W */
4250 )
4251}
4252
4253// UnicodePropertyValueExpression ::
4254// UnicodePropertyName `=` UnicodePropertyValue
4255// LoneUnicodePropertyNameOrValue
4256pp$9.regexp_eatUnicodePropertyValueExpression = function(state) {
4257 var start = state.pos;
4258
4259 // UnicodePropertyName `=` UnicodePropertyValue
4260 if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
4261 var name = state.lastStringValue;
4262 if (this.regexp_eatUnicodePropertyValue(state)) {
4263 var value = state.lastStringValue;
4264 this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
4265 return true
4266 }
4267 }
4268 state.pos = start;
4269
4270 // LoneUnicodePropertyNameOrValue
4271 if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
4272 var nameOrValue = state.lastStringValue;
4273 this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
4274 return true
4275 }
4276 return false
4277};
4278pp$9.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
4279 if (!data.hasOwnProperty(name) || data[name].indexOf(value) === -1) {
4280 state.raise("Invalid property name");
4281 }
4282};
4283pp$9.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
4284 if (data.$LONE.indexOf(nameOrValue) === -1) {
4285 state.raise("Invalid property name");
4286 }
4287};
4288
4289// UnicodePropertyName ::
4290// UnicodePropertyNameCharacters
4291pp$9.regexp_eatUnicodePropertyName = function(state) {
4292 var ch = 0;
4293 state.lastStringValue = "";
4294 while (isUnicodePropertyNameCharacter(ch = state.current())) {
4295 state.lastStringValue += codePointToString$1(ch);
4296 state.advance();
4297 }
4298 return state.lastStringValue !== ""
4299};
4300function isUnicodePropertyNameCharacter(ch) {
4301 return isControlLetter(ch) || ch === 0x5F /* _ */
4302}
4303
4304// UnicodePropertyValue ::
4305// UnicodePropertyValueCharacters
4306pp$9.regexp_eatUnicodePropertyValue = function(state) {
4307 var ch = 0;
4308 state.lastStringValue = "";
4309 while (isUnicodePropertyValueCharacter(ch = state.current())) {
4310 state.lastStringValue += codePointToString$1(ch);
4311 state.advance();
4312 }
4313 return state.lastStringValue !== ""
4314};
4315function isUnicodePropertyValueCharacter(ch) {
4316 return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
4317}
4318
4319// LoneUnicodePropertyNameOrValue ::
4320// UnicodePropertyValueCharacters
4321pp$9.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
4322 return this.regexp_eatUnicodePropertyValue(state)
4323};
4324
4325// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
4326pp$9.regexp_eatCharacterClass = function(state) {
4327 if (state.eat(0x5B /* [ */)) {
4328 state.eat(0x5E /* ^ */);
4329 this.regexp_classRanges(state);
4330 if (state.eat(0x5D /* [ */)) {
4331 return true
4332 }
4333 // Unreachable since it threw "unterminated regular expression" error before.
4334 state.raise("Unterminated character class");
4335 }
4336 return false
4337};
4338
4339// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
4340// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
4341// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
4342pp$9.regexp_classRanges = function(state) {
4343 var this$1 = this;
4344
4345 while (this.regexp_eatClassAtom(state)) {
4346 var left = state.lastIntValue;
4347 if (state.eat(0x2D /* - */) && this$1.regexp_eatClassAtom(state)) {
4348 var right = state.lastIntValue;
4349 if (state.switchU && (left === -1 || right === -1)) {
4350 state.raise("Invalid character class");
4351 }
4352 if (left !== -1 && right !== -1 && left > right) {
4353 state.raise("Range out of order in character class");
4354 }
4355 }
4356 }
4357};
4358
4359// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
4360// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
4361pp$9.regexp_eatClassAtom = function(state) {
4362 var start = state.pos;
4363
4364 if (state.eat(0x5C /* \ */)) {
4365 if (this.regexp_eatClassEscape(state)) {
4366 return true
4367 }
4368 if (state.switchU) {
4369 // Make the same message as V8.
4370 var ch$1 = state.current();
4371 if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
4372 state.raise("Invalid class escape");
4373 }
4374 state.raise("Invalid escape");
4375 }
4376 state.pos = start;
4377 }
4378
4379 var ch = state.current();
4380 if (ch !== 0x5D /* [ */) {
4381 state.lastIntValue = ch;
4382 state.advance();
4383 return true
4384 }
4385
4386 return false
4387};
4388
4389// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
4390pp$9.regexp_eatClassEscape = function(state) {
4391 var start = state.pos;
4392
4393 if (state.eat(0x62 /* b */)) {
4394 state.lastIntValue = 0x08; /* <BS> */
4395 return true
4396 }
4397
4398 if (state.switchU && state.eat(0x2D /* - */)) {
4399 state.lastIntValue = 0x2D; /* - */
4400 return true
4401 }
4402
4403 if (!state.switchU && state.eat(0x63 /* c */)) {
4404 if (this.regexp_eatClassControlLetter(state)) {
4405 return true
4406 }
4407 state.pos = start;
4408 }
4409
4410 return (
4411 this.regexp_eatCharacterClassEscape(state) ||
4412 this.regexp_eatCharacterEscape(state)
4413 )
4414};
4415
4416// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
4417pp$9.regexp_eatClassControlLetter = function(state) {
4418 var ch = state.current();
4419 if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
4420 state.lastIntValue = ch % 0x20;
4421 state.advance();
4422 return true
4423 }
4424 return false
4425};
4426
4427// https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
4428pp$9.regexp_eatHexEscapeSequence = function(state) {
4429 var start = state.pos;
4430 if (state.eat(0x78 /* x */)) {
4431 if (this.regexp_eatFixedHexDigits(state, 2)) {
4432 return true
4433 }
4434 if (state.switchU) {
4435 state.raise("Invalid escape");
4436 }
4437 state.pos = start;
4438 }
4439 return false
4440};
4441
4442// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
4443pp$9.regexp_eatDecimalDigits = function(state) {
4444 var start = state.pos;
4445 var ch = 0;
4446 state.lastIntValue = 0;
4447 while (isDecimalDigit(ch = state.current())) {
4448 state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
4449 state.advance();
4450 }
4451 return state.pos !== start
4452};
4453function isDecimalDigit(ch) {
4454 return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
4455}
4456
4457// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
4458pp$9.regexp_eatHexDigits = function(state) {
4459 var start = state.pos;
4460 var ch = 0;
4461 state.lastIntValue = 0;
4462 while (isHexDigit(ch = state.current())) {
4463 state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
4464 state.advance();
4465 }
4466 return state.pos !== start
4467};
4468function isHexDigit(ch) {
4469 return (
4470 (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
4471 (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
4472 (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
4473 )
4474}
4475function hexToInt(ch) {
4476 if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
4477 return 10 + (ch - 0x41 /* A */)
4478 }
4479 if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
4480 return 10 + (ch - 0x61 /* a */)
4481 }
4482 return ch - 0x30 /* 0 */
4483}
4484
4485// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
4486// Allows only 0-377(octal) i.e. 0-255(decimal).
4487pp$9.regexp_eatLegacyOctalEscapeSequence = function(state) {
4488 if (this.regexp_eatOctalDigit(state)) {
4489 var n1 = state.lastIntValue;
4490 if (this.regexp_eatOctalDigit(state)) {
4491 var n2 = state.lastIntValue;
4492 if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
4493 state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
4494 } else {
4495 state.lastIntValue = n1 * 8 + n2;
4496 }
4497 } else {
4498 state.lastIntValue = n1;
4499 }
4500 return true
4501 }
4502 return false
4503};
4504
4505// https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
4506pp$9.regexp_eatOctalDigit = function(state) {
4507 var ch = state.current();
4508 if (isOctalDigit(ch)) {
4509 state.lastIntValue = ch - 0x30; /* 0 */
4510 state.advance();
4511 return true
4512 }
4513 state.lastIntValue = 0;
4514 return false
4515};
4516function isOctalDigit(ch) {
4517 return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
4518}
4519
4520// https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
4521// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
4522// And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
4523pp$9.regexp_eatFixedHexDigits = function(state, length) {
4524 var start = state.pos;
4525 state.lastIntValue = 0;
4526 for (var i = 0; i < length; ++i) {
4527 var ch = state.current();
4528 if (!isHexDigit(ch)) {
4529 state.pos = start;
4530 return false
4531 }
4532 state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
4533 state.advance();
4534 }
4535 return true
4536};
4537
4538// Object type used to represent tokens. Note that normally, tokens
4539// simply exist as properties on the parser object. This is only
4540// used for the onToken callback and the external tokenizer.
4541
4542var Token = function Token(p) {
4543 this.type = p.type;
4544 this.value = p.value;
4545 this.start = p.start;
4546 this.end = p.end;
4547 if (p.options.locations)
4548 { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
4549 if (p.options.ranges)
4550 { this.range = [p.start, p.end]; }
4551};
4552
4553// ## Tokenizer
4554
4555var pp$8 = Parser.prototype;
4556
4557// Move to the next token
4558
4559pp$8.next = function() {
4560 if (this.options.onToken)
4561 { this.options.onToken(new Token(this)); }
4562
4563 this.lastTokEnd = this.end;
4564 this.lastTokStart = this.start;
4565 this.lastTokEndLoc = this.endLoc;
4566 this.lastTokStartLoc = this.startLoc;
4567 this.nextToken();
4568};
4569
4570pp$8.getToken = function() {
4571 this.next();
4572 return new Token(this)
4573};
4574
4575// If we're in an ES6 environment, make parsers iterable
4576if (typeof Symbol !== "undefined")
4577 { pp$8[Symbol.iterator] = function() {
4578 var this$1 = this;
4579
4580 return {
4581 next: function () {
4582 var token = this$1.getToken();
4583 return {
4584 done: token.type === types.eof,
4585 value: token
4586 }
4587 }
4588 }
4589 }; }
4590
4591// Toggle strict mode. Re-reads the next number or string to please
4592// pedantic tests (`"use strict"; 010;` should fail).
4593
4594pp$8.curContext = function() {
4595 return this.context[this.context.length - 1]
4596};
4597
4598// Read a single token, updating the parser object's token-related
4599// properties.
4600
4601pp$8.nextToken = function() {
4602 var curContext = this.curContext();
4603 if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
4604
4605 this.start = this.pos;
4606 if (this.options.locations) { this.startLoc = this.curPosition(); }
4607 if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
4608
4609 if (curContext.override) { return curContext.override(this) }
4610 else { this.readToken(this.fullCharCodeAtPos()); }
4611};
4612
4613pp$8.readToken = function(code) {
4614 // Identifier or keyword. '\uXXXX' sequences are allowed in
4615 // identifiers, so '\' also dispatches to that.
4616 if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
4617 { return this.readWord() }
4618
4619 return this.getTokenFromCode(code)
4620};
4621
4622pp$8.fullCharCodeAtPos = function() {
4623 var code = this.input.charCodeAt(this.pos);
4624 if (code <= 0xd7ff || code >= 0xe000) { return code }
4625 var next = this.input.charCodeAt(this.pos + 1);
4626 return (code << 10) + next - 0x35fdc00
4627};
4628
4629pp$8.skipBlockComment = function() {
4630 var this$1 = this;
4631
4632 var startLoc = this.options.onComment && this.curPosition();
4633 var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
4634 if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
4635 this.pos = end + 2;
4636 if (this.options.locations) {
4637 lineBreakG.lastIndex = start;
4638 var match;
4639 while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
4640 ++this$1.curLine;
4641 this$1.lineStart = match.index + match[0].length;
4642 }
4643 }
4644 if (this.options.onComment)
4645 { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
4646 startLoc, this.curPosition()); }
4647};
4648
4649pp$8.skipLineComment = function(startSkip) {
4650 var this$1 = this;
4651
4652 var start = this.pos;
4653 var startLoc = this.options.onComment && this.curPosition();
4654 var ch = this.input.charCodeAt(this.pos += startSkip);
4655 while (this.pos < this.input.length && !isNewLine(ch)) {
4656 ch = this$1.input.charCodeAt(++this$1.pos);
4657 }
4658 if (this.options.onComment)
4659 { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
4660 startLoc, this.curPosition()); }
4661};
4662
4663// Called at the start of the parse and after every token. Skips
4664// whitespace and comments, and.
4665
4666pp$8.skipSpace = function() {
4667 var this$1 = this;
4668
4669 loop: while (this.pos < this.input.length) {
4670 var ch = this$1.input.charCodeAt(this$1.pos);
4671 switch (ch) {
4672 case 32: case 160: // ' '
4673 ++this$1.pos;
4674 break
4675 case 13:
4676 if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
4677 ++this$1.pos;
4678 }
4679 case 10: case 8232: case 8233:
4680 ++this$1.pos;
4681 if (this$1.options.locations) {
4682 ++this$1.curLine;
4683 this$1.lineStart = this$1.pos;
4684 }
4685 break
4686 case 47: // '/'
4687 switch (this$1.input.charCodeAt(this$1.pos + 1)) {
4688 case 42: // '*'
4689 this$1.skipBlockComment();
4690 break
4691 case 47:
4692 this$1.skipLineComment(2);
4693 break
4694 default:
4695 break loop
4696 }
4697 break
4698 default:
4699 if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
4700 ++this$1.pos;
4701 } else {
4702 break loop
4703 }
4704 }
4705 }
4706};
4707
4708// Called at the end of every token. Sets `end`, `val`, and
4709// maintains `context` and `exprAllowed`, and skips the space after
4710// the token, so that the next one's `start` will point at the
4711// right position.
4712
4713pp$8.finishToken = function(type, val) {
4714 this.end = this.pos;
4715 if (this.options.locations) { this.endLoc = this.curPosition(); }
4716 var prevType = this.type;
4717 this.type = type;
4718 this.value = val;
4719
4720 this.updateContext(prevType);
4721};
4722
4723// ### Token reading
4724
4725// This is the function that is called to fetch the next token. It
4726// is somewhat obscure, because it works in character codes rather
4727// than characters, and because operator parsing has been inlined
4728// into it.
4729//
4730// All in the name of speed.
4731//
4732pp$8.readToken_dot = function() {
4733 var next = this.input.charCodeAt(this.pos + 1);
4734 if (next >= 48 && next <= 57) { return this.readNumber(true) }
4735 var next2 = this.input.charCodeAt(this.pos + 2);
4736 if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
4737 this.pos += 3;
4738 return this.finishToken(types.ellipsis)
4739 } else {
4740 ++this.pos;
4741 return this.finishToken(types.dot)
4742 }
4743};
4744
4745pp$8.readToken_slash = function() { // '/'
4746 var next = this.input.charCodeAt(this.pos + 1);
4747 if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
4748 if (next === 61) { return this.finishOp(types.assign, 2) }
4749 return this.finishOp(types.slash, 1)
4750};
4751
4752pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
4753 var next = this.input.charCodeAt(this.pos + 1);
4754 var size = 1;
4755 var tokentype = code === 42 ? types.star : types.modulo;
4756
4757 // exponentiation operator ** and **=
4758 if (this.options.ecmaVersion >= 7 && code == 42 && next === 42) {
4759 ++size;
4760 tokentype = types.starstar;
4761 next = this.input.charCodeAt(this.pos + 2);
4762 }
4763
4764 if (next === 61) { return this.finishOp(types.assign, size + 1) }
4765 return this.finishOp(tokentype, size)
4766};
4767
4768pp$8.readToken_pipe_amp = function(code) { // '|&'
4769 var next = this.input.charCodeAt(this.pos + 1);
4770 if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
4771 if (next === 61) { return this.finishOp(types.assign, 2) }
4772 return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
4773};
4774
4775pp$8.readToken_caret = function() { // '^'
4776 var next = this.input.charCodeAt(this.pos + 1);
4777 if (next === 61) { return this.finishOp(types.assign, 2) }
4778 return this.finishOp(types.bitwiseXOR, 1)
4779};
4780
4781pp$8.readToken_plus_min = function(code) { // '+-'
4782 var next = this.input.charCodeAt(this.pos + 1);
4783 if (next === code) {
4784 if (next == 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 62 &&
4785 (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
4786 // A `-->` line comment
4787 this.skipLineComment(3);
4788 this.skipSpace();
4789 return this.nextToken()
4790 }
4791 return this.finishOp(types.incDec, 2)
4792 }
4793 if (next === 61) { return this.finishOp(types.assign, 2) }
4794 return this.finishOp(types.plusMin, 1)
4795};
4796
4797pp$8.readToken_lt_gt = function(code) { // '<>'
4798 var next = this.input.charCodeAt(this.pos + 1);
4799 var size = 1;
4800 if (next === code) {
4801 size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
4802 if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
4803 return this.finishOp(types.bitShift, size)
4804 }
4805 if (next == 33 && code == 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 45 &&
4806 this.input.charCodeAt(this.pos + 3) == 45) {
4807 // `<!--`, an XML-style comment that should be interpreted as a line comment
4808 this.skipLineComment(4);
4809 this.skipSpace();
4810 return this.nextToken()
4811 }
4812 if (next === 61) { size = 2; }
4813 return this.finishOp(types.relational, size)
4814};
4815
4816pp$8.readToken_eq_excl = function(code) { // '=!'
4817 var next = this.input.charCodeAt(this.pos + 1);
4818 if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
4819 if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
4820 this.pos += 2;
4821 return this.finishToken(types.arrow)
4822 }
4823 return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
4824};
4825
4826pp$8.getTokenFromCode = function(code) {
4827 switch (code) {
4828 // The interpretation of a dot depends on whether it is followed
4829 // by a digit or another two dots.
4830 case 46: // '.'
4831 return this.readToken_dot()
4832
4833 // Punctuation tokens.
4834 case 40: ++this.pos; return this.finishToken(types.parenL)
4835 case 41: ++this.pos; return this.finishToken(types.parenR)
4836 case 59: ++this.pos; return this.finishToken(types.semi)
4837 case 44: ++this.pos; return this.finishToken(types.comma)
4838 case 91: ++this.pos; return this.finishToken(types.bracketL)
4839 case 93: ++this.pos; return this.finishToken(types.bracketR)
4840 case 123: ++this.pos; return this.finishToken(types.braceL)
4841 case 125: ++this.pos; return this.finishToken(types.braceR)
4842 case 58: ++this.pos; return this.finishToken(types.colon)
4843 case 63: ++this.pos; return this.finishToken(types.question)
4844
4845 case 96: // '`'
4846 if (this.options.ecmaVersion < 6) { break }
4847 ++this.pos;
4848 return this.finishToken(types.backQuote)
4849
4850 case 48: // '0'
4851 var next = this.input.charCodeAt(this.pos + 1);
4852 if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
4853 if (this.options.ecmaVersion >= 6) {
4854 if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
4855 if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
4856 }
4857
4858 // Anything else beginning with a digit is an integer, octal
4859 // number, or float.
4860 case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
4861 return this.readNumber(false)
4862
4863 // Quotes produce strings.
4864 case 34: case 39: // '"', "'"
4865 return this.readString(code)
4866
4867 // Operators are parsed inline in tiny state machines. '=' (61) is
4868 // often referred to. `finishOp` simply skips the amount of
4869 // characters it is given as second argument, and returns a token
4870 // of the type given by its first argument.
4871
4872 case 47: // '/'
4873 return this.readToken_slash()
4874
4875 case 37: case 42: // '%*'
4876 return this.readToken_mult_modulo_exp(code)
4877
4878 case 124: case 38: // '|&'
4879 return this.readToken_pipe_amp(code)
4880
4881 case 94: // '^'
4882 return this.readToken_caret()
4883
4884 case 43: case 45: // '+-'
4885 return this.readToken_plus_min(code)
4886
4887 case 60: case 62: // '<>'
4888 return this.readToken_lt_gt(code)
4889
4890 case 61: case 33: // '=!'
4891 return this.readToken_eq_excl(code)
4892
4893 case 126: // '~'
4894 return this.finishOp(types.prefix, 1)
4895 }
4896
4897 this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
4898};
4899
4900pp$8.finishOp = function(type, size) {
4901 var str = this.input.slice(this.pos, this.pos + size);
4902 this.pos += size;
4903 return this.finishToken(type, str)
4904};
4905
4906pp$8.readRegexp = function() {
4907 var this$1 = this;
4908
4909 var escaped, inClass, start = this.pos;
4910 for (;;) {
4911 if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
4912 var ch = this$1.input.charAt(this$1.pos);
4913 if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
4914 if (!escaped) {
4915 if (ch === "[") { inClass = true; }
4916 else if (ch === "]" && inClass) { inClass = false; }
4917 else if (ch === "/" && !inClass) { break }
4918 escaped = ch === "\\";
4919 } else { escaped = false; }
4920 ++this$1.pos;
4921 }
4922 var pattern = this.input.slice(start, this.pos);
4923 ++this.pos;
4924 var flagsStart = this.pos;
4925 var flags = this.readWord1();
4926 if (this.containsEsc) { this.unexpected(flagsStart); }
4927
4928 // Validate pattern
4929 var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
4930 state.reset(start, pattern, flags);
4931 this.validateRegExpFlags(state);
4932 this.validateRegExpPattern(state);
4933
4934 // Create Literal#value property value.
4935 var value = null;
4936 try {
4937 value = new RegExp(pattern, flags);
4938 } catch (e) {
4939 // ESTree requires null if it failed to instantiate RegExp object.
4940 // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
4941 }
4942
4943 return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
4944};
4945
4946// Read an integer in the given radix. Return null if zero digits
4947// were read, the integer value otherwise. When `len` is given, this
4948// will return `null` unless the integer has exactly `len` digits.
4949
4950pp$8.readInt = function(radix, len) {
4951 var this$1 = this;
4952
4953 var start = this.pos, total = 0;
4954 for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
4955 var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
4956 if (code >= 97) { val = code - 97 + 10; } // a
4957 else if (code >= 65) { val = code - 65 + 10; } // A
4958 else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
4959 else { val = Infinity; }
4960 if (val >= radix) { break }
4961 ++this$1.pos;
4962 total = total * radix + val;
4963 }
4964 if (this.pos === start || len != null && this.pos - start !== len) { return null }
4965
4966 return total
4967};
4968
4969pp$8.readRadixNumber = function(radix) {
4970 this.pos += 2; // 0x
4971 var val = this.readInt(radix);
4972 if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
4973 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
4974 return this.finishToken(types.num, val)
4975};
4976
4977// Read an integer, octal integer, or floating-point number.
4978
4979pp$8.readNumber = function(startsWithDot) {
4980 var start = this.pos;
4981 if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
4982 var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
4983 if (octal && this.strict) { this.raise(start, "Invalid number"); }
4984 if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
4985 var next = this.input.charCodeAt(this.pos);
4986 if (next === 46 && !octal) { // '.'
4987 ++this.pos;
4988 this.readInt(10);
4989 next = this.input.charCodeAt(this.pos);
4990 }
4991 if ((next === 69 || next === 101) && !octal) { // 'eE'
4992 next = this.input.charCodeAt(++this.pos);
4993 if (next === 43 || next === 45) { ++this.pos; } // '+-'
4994 if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
4995 }
4996 if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
4997
4998 var str = this.input.slice(start, this.pos);
4999 var val = octal ? parseInt(str, 8) : parseFloat(str);
5000 return this.finishToken(types.num, val)
5001};
5002
5003// Read a string value, interpreting backslash-escapes.
5004
5005pp$8.readCodePoint = function() {
5006 var ch = this.input.charCodeAt(this.pos), code;
5007
5008 if (ch === 123) { // '{'
5009 if (this.options.ecmaVersion < 6) { this.unexpected(); }
5010 var codePos = ++this.pos;
5011 code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
5012 ++this.pos;
5013 if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
5014 } else {
5015 code = this.readHexChar(4);
5016 }
5017 return code
5018};
5019
5020function codePointToString(code) {
5021 // UTF-16 Decoding
5022 if (code <= 0xFFFF) { return String.fromCharCode(code) }
5023 code -= 0x10000;
5024 return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
5025}
5026
5027pp$8.readString = function(quote) {
5028 var this$1 = this;
5029
5030 var out = "", chunkStart = ++this.pos;
5031 for (;;) {
5032 if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
5033 var ch = this$1.input.charCodeAt(this$1.pos);
5034 if (ch === quote) { break }
5035 if (ch === 92) { // '\'
5036 out += this$1.input.slice(chunkStart, this$1.pos);
5037 out += this$1.readEscapedChar(false);
5038 chunkStart = this$1.pos;
5039 } else {
5040 if (isNewLine(ch)) { this$1.raise(this$1.start, "Unterminated string constant"); }
5041 ++this$1.pos;
5042 }
5043 }
5044 out += this.input.slice(chunkStart, this.pos++);
5045 return this.finishToken(types.string, out)
5046};
5047
5048// Reads template string tokens.
5049
5050var INVALID_TEMPLATE_ESCAPE_ERROR = {};
5051
5052pp$8.tryReadTemplateToken = function() {
5053 this.inTemplateElement = true;
5054 try {
5055 this.readTmplToken();
5056 } catch (err) {
5057 if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
5058 this.readInvalidTemplateToken();
5059 } else {
5060 throw err
5061 }
5062 }
5063
5064 this.inTemplateElement = false;
5065};
5066
5067pp$8.invalidStringToken = function(position, message) {
5068 if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
5069 throw INVALID_TEMPLATE_ESCAPE_ERROR
5070 } else {
5071 this.raise(position, message);
5072 }
5073};
5074
5075pp$8.readTmplToken = function() {
5076 var this$1 = this;
5077
5078 var out = "", chunkStart = this.pos;
5079 for (;;) {
5080 if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
5081 var ch = this$1.input.charCodeAt(this$1.pos);
5082 if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
5083 if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
5084 if (ch === 36) {
5085 this$1.pos += 2;
5086 return this$1.finishToken(types.dollarBraceL)
5087 } else {
5088 ++this$1.pos;
5089 return this$1.finishToken(types.backQuote)
5090 }
5091 }
5092 out += this$1.input.slice(chunkStart, this$1.pos);
5093 return this$1.finishToken(types.template, out)
5094 }
5095 if (ch === 92) { // '\'
5096 out += this$1.input.slice(chunkStart, this$1.pos);
5097 out += this$1.readEscapedChar(true);
5098 chunkStart = this$1.pos;
5099 } else if (isNewLine(ch)) {
5100 out += this$1.input.slice(chunkStart, this$1.pos);
5101 ++this$1.pos;
5102 switch (ch) {
5103 case 13:
5104 if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
5105 case 10:
5106 out += "\n";
5107 break
5108 default:
5109 out += String.fromCharCode(ch);
5110 break
5111 }
5112 if (this$1.options.locations) {
5113 ++this$1.curLine;
5114 this$1.lineStart = this$1.pos;
5115 }
5116 chunkStart = this$1.pos;
5117 } else {
5118 ++this$1.pos;
5119 }
5120 }
5121};
5122
5123// Reads a template token to search for the end, without validating any escape sequences
5124pp$8.readInvalidTemplateToken = function() {
5125 var this$1 = this;
5126
5127 for (; this.pos < this.input.length; this.pos++) {
5128 switch (this$1.input[this$1.pos]) {
5129 case "\\":
5130 ++this$1.pos;
5131 break
5132
5133 case "$":
5134 if (this$1.input[this$1.pos + 1] !== "{") {
5135 break
5136 }
5137 // falls through
5138
5139 case "`":
5140 return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
5141
5142 // no default
5143 }
5144 }
5145 this.raise(this.start, "Unterminated template");
5146};
5147
5148// Used to read escaped characters
5149
5150pp$8.readEscapedChar = function(inTemplate) {
5151 var ch = this.input.charCodeAt(++this.pos);
5152 ++this.pos;
5153 switch (ch) {
5154 case 110: return "\n" // 'n' -> '\n'
5155 case 114: return "\r" // 'r' -> '\r'
5156 case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
5157 case 117: return codePointToString(this.readCodePoint()) // 'u'
5158 case 116: return "\t" // 't' -> '\t'
5159 case 98: return "\b" // 'b' -> '\b'
5160 case 118: return "\u000b" // 'v' -> '\u000b'
5161 case 102: return "\f" // 'f' -> '\f'
5162 case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
5163 case 10: // ' \n'
5164 if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
5165 return ""
5166 default:
5167 if (ch >= 48 && ch <= 55) {
5168 var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
5169 var octal = parseInt(octalStr, 8);
5170 if (octal > 255) {
5171 octalStr = octalStr.slice(0, -1);
5172 octal = parseInt(octalStr, 8);
5173 }
5174 this.pos += octalStr.length - 1;
5175 ch = this.input.charCodeAt(this.pos);
5176 if ((octalStr !== "0" || ch == 56 || ch == 57) && (this.strict || inTemplate)) {
5177 this.invalidStringToken(
5178 this.pos - 1 - octalStr.length,
5179 inTemplate
5180 ? "Octal literal in template string"
5181 : "Octal literal in strict mode"
5182 );
5183 }
5184 return String.fromCharCode(octal)
5185 }
5186 return String.fromCharCode(ch)
5187 }
5188};
5189
5190// Used to read character escape sequences ('\x', '\u', '\U').
5191
5192pp$8.readHexChar = function(len) {
5193 var codePos = this.pos;
5194 var n = this.readInt(16, len);
5195 if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
5196 return n
5197};
5198
5199// Read an identifier, and return it as a string. Sets `this.containsEsc`
5200// to whether the word contained a '\u' escape.
5201//
5202// Incrementally adds only escaped chars, adding other chunks as-is
5203// as a micro-optimization.
5204
5205pp$8.readWord1 = function() {
5206 var this$1 = this;
5207
5208 this.containsEsc = false;
5209 var word = "", first = true, chunkStart = this.pos;
5210 var astral = this.options.ecmaVersion >= 6;
5211 while (this.pos < this.input.length) {
5212 var ch = this$1.fullCharCodeAtPos();
5213 if (isIdentifierChar(ch, astral)) {
5214 this$1.pos += ch <= 0xffff ? 1 : 2;
5215 } else if (ch === 92) { // "\"
5216 this$1.containsEsc = true;
5217 word += this$1.input.slice(chunkStart, this$1.pos);
5218 var escStart = this$1.pos;
5219 if (this$1.input.charCodeAt(++this$1.pos) != 117) // "u"
5220 { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
5221 ++this$1.pos;
5222 var esc = this$1.readCodePoint();
5223 if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
5224 { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
5225 word += codePointToString(esc);
5226 chunkStart = this$1.pos;
5227 } else {
5228 break
5229 }
5230 first = false;
5231 }
5232 return word + this.input.slice(chunkStart, this.pos)
5233};
5234
5235// Read an identifier or keyword token. Will check for reserved
5236// words when necessary.
5237
5238pp$8.readWord = function() {
5239 var word = this.readWord1();
5240 var type = types.name;
5241 if (this.keywords.test(word)) {
5242 if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
5243 type = keywords$1[word];
5244 }
5245 return this.finishToken(type, word)
5246};
5247
5248// Acorn is a tiny, fast JavaScript parser written in JavaScript.
5249//
5250// Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
5251// various contributors and released under an MIT license.
5252//
5253// Git repositories for Acorn are available at
5254//
5255// http://marijnhaverbeke.nl/git/acorn
5256// https://github.com/acornjs/acorn.git
5257//
5258// Please use the [github bug tracker][ghbt] to report issues.
5259//
5260// [ghbt]: https://github.com/acornjs/acorn/issues
5261//
5262// This file defines the main parser interface. The library also comes
5263// with a [error-tolerant parser][dammit] and an
5264// [abstract syntax tree walker][walk], defined in other files.
5265//
5266// [dammit]: acorn_loose.js
5267// [walk]: util/walk.js
5268
5269var version = "5.5.1";
5270
5271// The main exported interface (under `self.acorn` when in the
5272// browser) is a `parse` function that takes a code string and
5273// returns an abstract syntax tree as specified by [Mozilla parser
5274// API][api].
5275//
5276// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
5277
5278function parse(input, options) {
5279 return new Parser(options, input).parse()
5280}
5281
5282// This function tries to parse a single expression at a given
5283// offset in a string. Useful for parsing mixed-language formats
5284// that embed JavaScript expressions.
5285
5286function parseExpressionAt(input, pos, options) {
5287 var p = new Parser(options, input, pos);
5288 p.nextToken();
5289 return p.parseExpression()
5290}
5291
5292// Acorn is organized as a tokenizer and a recursive-descent parser.
5293// The `tokenizer` export provides an interface to the tokenizer.
5294
5295function tokenizer(input, options) {
5296 return new Parser(options, input)
5297}
5298
5299// This is a terrible kludge to support the existing, pre-ES6
5300// interface where the loose parser module retroactively adds exports
5301// to this module.
5302 // eslint-disable-line camelcase
5303function addLooseExports(parse, Parser$$1, plugins$$1) {
5304 exports.parse_dammit = parse; // eslint-disable-line camelcase
5305 exports.LooseParser = Parser$$1;
5306 exports.pluginsLoose = plugins$$1;
5307}
5308
5309exports.version = version;
5310exports.parse = parse;
5311exports.parseExpressionAt = parseExpressionAt;
5312exports.tokenizer = tokenizer;
5313exports.addLooseExports = addLooseExports;
5314exports.Parser = Parser;
5315exports.plugins = plugins;
5316exports.defaultOptions = defaultOptions;
5317exports.Position = Position;
5318exports.SourceLocation = SourceLocation;
5319exports.getLineInfo = getLineInfo;
5320exports.Node = Node;
5321exports.TokenType = TokenType;
5322exports.tokTypes = types;
5323exports.keywordTypes = keywords$1;
5324exports.TokContext = TokContext;
5325exports.tokContexts = types$1;
5326exports.isIdentifierChar = isIdentifierChar;
5327exports.isIdentifierStart = isIdentifierStart;
5328exports.Token = Token;
5329exports.isNewLine = isNewLine;
5330exports.lineBreak = lineBreak;
5331exports.lineBreakG = lineBreakG;
5332exports.nonASCIIwhitespace = nonASCIIwhitespace;
5333
5334Object.defineProperty(exports, '__esModule', { value: true });
5335
5336})));