Projekt

Obecné

Profil

Stáhnout (179 KB) Statistiky
| Větev: | Revize:
1
// Reserved word lists for various dialects of the language
2

    
3
var reservedWords = {
4
  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",
5
  5: "class enum extends super const export import",
6
  6: "enum",
7
  strict: "implements interface let package private protected public static yield",
8
  strictBind: "eval arguments"
9
};
10

    
11
// And the keywords
12

    
13
var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
14

    
15
var keywords = {
16
  5: ecma5AndLessKeywords,
17
  "5module": ecma5AndLessKeywords + " export import",
18
  6: ecma5AndLessKeywords + " const class extends export import super"
19
};
20

    
21
var keywordRelationalOperator = /^in(stanceof)?$/;
22

    
23
// ## Character categories
24

    
25
// Big ugly regular expressions that match characters in the
26
// whitespace, identifier, and identifier-start categories. These
27
// are only applied when a character is found to actually have a
28
// code point above 128.
29
// Generated by `bin/generate-identifier-regex.js`.
30
var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7c6\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab67\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
31
var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
32

    
33
var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
34
var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
35

    
36
nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
37

    
38
// These are a run-length and offset encoded representation of the
39
// >0xffff code points that are a valid part of identifiers. The
40
// offset starts at 0x10000, and each pair of numbers represents an
41
// offset to the next range, and then a size of the range. They were
42
// generated by bin/generate-identifier-regex.js
43

    
44
// eslint-disable-next-line comma-spacing
45
var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,155,22,13,52,76,44,33,24,27,35,30,0,12,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,21,0,33,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,230,43,117,63,32,0,161,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,754,9486,286,50,2,18,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,2357,44,11,6,17,0,370,43,1301,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541];
46

    
47
// eslint-disable-next-line comma-spacing
48
var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,232,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1014,0,2,54,8,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,262,6,10,9,419,13,1495,6,110,6,6,9,792487,239];
49

    
50
// This has a complexity linear to the value of the code. The
51
// assumption is that looking up astral identifier characters is
52
// rare.
53
function isInAstralSet(code, set) {
54
  var pos = 0x10000;
55
  for (var i = 0; i < set.length; i += 2) {
56
    pos += set[i];
57
    if (pos > code) { return false }
58
    pos += set[i + 1];
59
    if (pos >= code) { return true }
60
  }
61
}
62

    
63
// Test whether a given character code starts an identifier.
64

    
65
function isIdentifierStart(code, astral) {
66
  if (code < 65) { return code === 36 }
67
  if (code < 91) { return true }
68
  if (code < 97) { return code === 95 }
69
  if (code < 123) { return true }
70
  if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
71
  if (astral === false) { return false }
72
  return isInAstralSet(code, astralIdentifierStartCodes)
73
}
74

    
75
// Test whether a given character is part of an identifier.
76

    
77
function isIdentifierChar(code, astral) {
78
  if (code < 48) { return code === 36 }
79
  if (code < 58) { return true }
80
  if (code < 65) { return false }
81
  if (code < 91) { return true }
82
  if (code < 97) { return code === 95 }
83
  if (code < 123) { return true }
84
  if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
85
  if (astral === false) { return false }
86
  return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
87
}
88

    
89
// ## Token types
90

    
91
// The assignment of fine-grained, information-carrying type objects
92
// allows the tokenizer to store the information it has about a
93
// token in a way that is very cheap for the parser to look up.
94

    
95
// All token type variables start with an underscore, to make them
96
// easy to recognize.
97

    
98
// The `beforeExpr` property is used to disambiguate between regular
99
// expressions and divisions. It is set on all token types that can
100
// be followed by an expression (thus, a slash after them would be a
101
// regular expression).
102
//
103
// The `startsExpr` property is used to check if the token ends a
104
// `yield` expression. It is set on all token types that either can
105
// directly start an expression (like a quotation mark) or can
106
// continue an expression (like the body of a string).
107
//
108
// `isLoop` marks a keyword as starting a loop, which is important
109
// to know when parsing a label, in order to allow or disallow
110
// continue jumps to that label.
111

    
112
var TokenType = function TokenType(label, conf) {
113
  if ( conf === void 0 ) conf = {};
114

    
115
  this.label = label;
116
  this.keyword = conf.keyword;
117
  this.beforeExpr = !!conf.beforeExpr;
118
  this.startsExpr = !!conf.startsExpr;
119
  this.isLoop = !!conf.isLoop;
120
  this.isAssign = !!conf.isAssign;
121
  this.prefix = !!conf.prefix;
122
  this.postfix = !!conf.postfix;
123
  this.binop = conf.binop || null;
124
  this.updateContext = null;
125
};
126

    
127
function binop(name, prec) {
128
  return new TokenType(name, {beforeExpr: true, binop: prec})
129
}
130
var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};
131

    
132
// Map keyword names to token types.
133

    
134
var keywords$1 = {};
135

    
136
// Succinct definitions of keyword token types
137
function kw(name, options) {
138
  if ( options === void 0 ) options = {};
139

    
140
  options.keyword = name;
141
  return keywords$1[name] = new TokenType(name, options)
142
}
143

    
144
var types = {
145
  num: new TokenType("num", startsExpr),
146
  regexp: new TokenType("regexp", startsExpr),
147
  string: new TokenType("string", startsExpr),
148
  name: new TokenType("name", startsExpr),
149
  eof: new TokenType("eof"),
150

    
151
  // Punctuation token types.
152
  bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
153
  bracketR: new TokenType("]"),
154
  braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
155
  braceR: new TokenType("}"),
156
  parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
157
  parenR: new TokenType(")"),
158
  comma: new TokenType(",", beforeExpr),
159
  semi: new TokenType(";", beforeExpr),
160
  colon: new TokenType(":", beforeExpr),
161
  dot: new TokenType("."),
162
  question: new TokenType("?", beforeExpr),
163
  arrow: new TokenType("=>", beforeExpr),
164
  template: new TokenType("template"),
165
  invalidTemplate: new TokenType("invalidTemplate"),
166
  ellipsis: new TokenType("...", beforeExpr),
167
  backQuote: new TokenType("`", startsExpr),
168
  dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
169

    
170
  // Operators. These carry several kinds of properties to help the
171
  // parser use them properly (the presence of these properties is
172
  // what categorizes them as operators).
173
  //
174
  // `binop`, when present, specifies that this operator is a binary
175
  // operator, and will refer to its precedence.
176
  //
177
  // `prefix` and `postfix` mark the operator as a prefix or postfix
178
  // unary operator.
179
  //
180
  // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
181
  // binary operators with a very low precedence, that should result
182
  // in AssignmentExpression nodes.
183

    
184
  eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
185
  assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
186
  incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
187
  prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
188
  logicalOR: binop("||", 1),
189
  logicalAND: binop("&&", 2),
190
  bitwiseOR: binop("|", 3),
191
  bitwiseXOR: binop("^", 4),
192
  bitwiseAND: binop("&", 5),
193
  equality: binop("==/!=/===/!==", 6),
194
  relational: binop("</>/<=/>=", 7),
195
  bitShift: binop("<</>>/>>>", 8),
196
  plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
197
  modulo: binop("%", 10),
198
  star: binop("*", 10),
199
  slash: binop("/", 10),
200
  starstar: new TokenType("**", {beforeExpr: true}),
201

    
202
  // Keyword token types.
203
  _break: kw("break"),
204
  _case: kw("case", beforeExpr),
205
  _catch: kw("catch"),
206
  _continue: kw("continue"),
207
  _debugger: kw("debugger"),
208
  _default: kw("default", beforeExpr),
209
  _do: kw("do", {isLoop: true, beforeExpr: true}),
210
  _else: kw("else", beforeExpr),
211
  _finally: kw("finally"),
212
  _for: kw("for", {isLoop: true}),
213
  _function: kw("function", startsExpr),
214
  _if: kw("if"),
215
  _return: kw("return", beforeExpr),
216
  _switch: kw("switch"),
217
  _throw: kw("throw", beforeExpr),
218
  _try: kw("try"),
219
  _var: kw("var"),
220
  _const: kw("const"),
221
  _while: kw("while", {isLoop: true}),
222
  _with: kw("with"),
223
  _new: kw("new", {beforeExpr: true, startsExpr: true}),
224
  _this: kw("this", startsExpr),
225
  _super: kw("super", startsExpr),
226
  _class: kw("class", startsExpr),
227
  _extends: kw("extends", beforeExpr),
228
  _export: kw("export"),
229
  _import: kw("import", startsExpr),
230
  _null: kw("null", startsExpr),
231
  _true: kw("true", startsExpr),
232
  _false: kw("false", startsExpr),
233
  _in: kw("in", {beforeExpr: true, binop: 7}),
234
  _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
235
  _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
236
  _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
237
  _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
238
};
239

    
240
// Matches a whole line break (where CRLF is considered a single
241
// line break). Used to count lines.
242

    
243
var lineBreak = /\r\n?|\n|\u2028|\u2029/;
244
var lineBreakG = new RegExp(lineBreak.source, "g");
245

    
246
function isNewLine(code, ecma2019String) {
247
  return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029))
248
}
249

    
250
var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
251

    
252
var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
253

    
254
var ref = Object.prototype;
255
var hasOwnProperty = ref.hasOwnProperty;
256
var toString = ref.toString;
257

    
258
// Checks if an object has a property.
259

    
260
function has(obj, propName) {
261
  return hasOwnProperty.call(obj, propName)
262
}
263

    
264
var isArray = Array.isArray || (function (obj) { return (
265
  toString.call(obj) === "[object Array]"
266
); });
267

    
268
function wordsRegexp(words) {
269
  return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
270
}
271

    
272
// These are used when `options.locations` is on, for the
273
// `startLoc` and `endLoc` properties.
274

    
275
var Position = function Position(line, col) {
276
  this.line = line;
277
  this.column = col;
278
};
279

    
280
Position.prototype.offset = function offset (n) {
281
  return new Position(this.line, this.column + n)
282
};
283

    
284
var SourceLocation = function SourceLocation(p, start, end) {
285
  this.start = start;
286
  this.end = end;
287
  if (p.sourceFile !== null) { this.source = p.sourceFile; }
288
};
289

    
290
// The `getLineInfo` function is mostly useful when the
291
// `locations` option is off (for performance reasons) and you
292
// want to find the line/column position for a given character
293
// offset. `input` should be the code string that the offset refers
294
// into.
295

    
296
function getLineInfo(input, offset) {
297
  for (var line = 1, cur = 0;;) {
298
    lineBreakG.lastIndex = cur;
299
    var match = lineBreakG.exec(input);
300
    if (match && match.index < offset) {
301
      ++line;
302
      cur = match.index + match[0].length;
303
    } else {
304
      return new Position(line, offset - cur)
305
    }
306
  }
307
}
308

    
309
// A second optional argument can be given to further configure
310
// the parser process. These options are recognized:
311

    
312
var defaultOptions = {
313
  // `ecmaVersion` indicates the ECMAScript version to parse. Must be
314
  // either 3, 5, 6 (2015), 7 (2016), 8 (2017), 9 (2018), or 10
315
  // (2019). This influences support for strict mode, the set of
316
  // reserved words, and support for new syntax features. The default
317
  // is 9.
318
  ecmaVersion: 9,
319
  // `sourceType` indicates the mode the code should be parsed in.
320
  // Can be either `"script"` or `"module"`. This influences global
321
  // strict mode and parsing of `import` and `export` declarations.
322
  sourceType: "script",
323
  // `onInsertedSemicolon` can be a callback that will be called
324
  // when a semicolon is automatically inserted. It will be passed
325
  // the position of the comma as an offset, and if `locations` is
326
  // enabled, it is given the location as a `{line, column}` object
327
  // as second argument.
328
  onInsertedSemicolon: null,
329
  // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
330
  // trailing commas.
331
  onTrailingComma: null,
332
  // By default, reserved words are only enforced if ecmaVersion >= 5.
333
  // Set `allowReserved` to a boolean value to explicitly turn this on
334
  // an off. When this option has the value "never", reserved words
335
  // and keywords can also not be used as property names.
336
  allowReserved: null,
337
  // When enabled, a return at the top level is not considered an
338
  // error.
339
  allowReturnOutsideFunction: false,
340
  // When enabled, import/export statements are not constrained to
341
  // appearing at the top of the program.
342
  allowImportExportEverywhere: false,
343
  // When enabled, await identifiers are allowed to appear at the top-level scope,
344
  // but they are still not allowed in non-async functions.
345
  allowAwaitOutsideFunction: false,
346
  // When enabled, hashbang directive in the beginning of file
347
  // is allowed and treated as a line comment.
348
  allowHashBang: false,
349
  // When `locations` is on, `loc` properties holding objects with
350
  // `start` and `end` properties in `{line, column}` form (with
351
  // line being 1-based and column 0-based) will be attached to the
352
  // nodes.
353
  locations: false,
354
  // A function can be passed as `onToken` option, which will
355
  // cause Acorn to call that function with object in the same
356
  // format as tokens returned from `tokenizer().getToken()`. Note
357
  // that you are not allowed to call the parser from the
358
  // callback—that will corrupt its internal state.
359
  onToken: null,
360
  // A function can be passed as `onComment` option, which will
361
  // cause Acorn to call that function with `(block, text, start,
362
  // end)` parameters whenever a comment is skipped. `block` is a
363
  // boolean indicating whether this is a block (`/* */`) comment,
364
  // `text` is the content of the comment, and `start` and `end` are
365
  // character offsets that denote the start and end of the comment.
366
  // When the `locations` option is on, two more parameters are
367
  // passed, the full `{line, column}` locations of the start and
368
  // end of the comments. Note that you are not allowed to call the
369
  // parser from the callback—that will corrupt its internal state.
370
  onComment: null,
371
  // Nodes have their start and end characters offsets recorded in
372
  // `start` and `end` properties (directly on the node, rather than
373
  // the `loc` object, which holds line/column data. To also add a
374
  // [semi-standardized][range] `range` property holding a `[start,
375
  // end]` array with the same numbers, set the `ranges` option to
376
  // `true`.
377
  //
378
  // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
379
  ranges: false,
380
  // It is possible to parse multiple files into a single AST by
381
  // passing the tree produced by parsing the first file as
382
  // `program` option in subsequent parses. This will add the
383
  // toplevel forms of the parsed file to the `Program` (top) node
384
  // of an existing parse tree.
385
  program: null,
386
  // When `locations` is on, you can pass this to record the source
387
  // file in every node's `loc` object.
388
  sourceFile: null,
389
  // This value, if given, is stored in every node, whether
390
  // `locations` is on or off.
391
  directSourceFile: null,
392
  // When enabled, parenthesized expressions are represented by
393
  // (non-standard) ParenthesizedExpression nodes
394
  preserveParens: false
395
};
396

    
397
// Interpret and default an options object
398

    
399
function 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

    
421
function 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
// Each scope gets a bitset that may contain these flags
438
var
439
    SCOPE_TOP = 1,
440
    SCOPE_FUNCTION = 2,
441
    SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION,
442
    SCOPE_ASYNC = 4,
443
    SCOPE_GENERATOR = 8,
444
    SCOPE_ARROW = 16,
445
    SCOPE_SIMPLE_CATCH = 32,
446
    SCOPE_SUPER = 64,
447
    SCOPE_DIRECT_SUPER = 128;
448

    
449
function functionFlags(async, generator) {
450
  return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
451
}
452

    
453
// Used in checkLVal and declareName to determine the type of a binding
454
var
455
    BIND_NONE = 0, // Not a binding
456
    BIND_VAR = 1, // Var-style binding
457
    BIND_LEXICAL = 2, // Let- or const-style binding
458
    BIND_FUNCTION = 3, // Function declaration
459
    BIND_SIMPLE_CATCH = 4, // Simple (identifier pattern) catch binding
460
    BIND_OUTSIDE = 5; // Special case for function names as bound inside the function
461

    
462
var Parser = function Parser(options, input, startPos) {
463
  this.options = options = getOptions(options);
464
  this.sourceFile = options.sourceFile;
465
  this.keywords = wordsRegexp(keywords[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]);
466
  var reserved = "";
467
  if (options.allowReserved !== true) {
468
    for (var v = options.ecmaVersion;; v--)
469
      { if (reserved = reservedWords[v]) { break } }
470
    if (options.sourceType === "module") { reserved += " await"; }
471
  }
472
  this.reservedWords = wordsRegexp(reserved);
473
  var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
474
  this.reservedWordsStrict = wordsRegexp(reservedStrict);
475
  this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
476
  this.input = String(input);
477

    
478
  // Used to signal to callers of `readWord1` whether the word
479
  // contained any escape sequences. This is needed because words with
480
  // escape sequences must not be interpreted as keywords.
481
  this.containsEsc = false;
482

    
483
  // Set up token state
484

    
485
  // The current position of the tokenizer in the input.
486
  if (startPos) {
487
    this.pos = startPos;
488
    this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
489
    this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
490
  } else {
491
    this.pos = this.lineStart = 0;
492
    this.curLine = 1;
493
  }
494

    
495
  // Properties of the current token:
496
  // Its type
497
  this.type = types.eof;
498
  // For tokens that include more information than their type, the value
499
  this.value = null;
500
  // Its start and end offset
501
  this.start = this.end = this.pos;
502
  // And, if locations are used, the {line, column} object
503
  // corresponding to those offsets
504
  this.startLoc = this.endLoc = this.curPosition();
505

    
506
  // Position information for the previous token
507
  this.lastTokEndLoc = this.lastTokStartLoc = null;
508
  this.lastTokStart = this.lastTokEnd = this.pos;
509

    
510
  // The context stack is used to superficially track syntactic
511
  // context to predict whether a regular expression is allowed in a
512
  // given position.
513
  this.context = this.initialContext();
514
  this.exprAllowed = true;
515

    
516
  // Figure out if it's a module code.
517
  this.inModule = options.sourceType === "module";
518
  this.strict = this.inModule || this.strictDirective(this.pos);
519

    
520
  // Used to signify the start of a potential arrow function
521
  this.potentialArrowAt = -1;
522

    
523
  // Positions to delayed-check that yield/await does not exist in default parameters.
524
  this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
525
  // Labels in scope.
526
  this.labels = [];
527
  // Thus-far undefined exports.
528
  this.undefinedExports = {};
529

    
530
  // If enabled, skip leading hashbang line.
531
  if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
532
    { this.skipLineComment(2); }
533

    
534
  // Scope tracking for duplicate variable names (see scope.js)
535
  this.scopeStack = [];
536
  this.enterScope(SCOPE_TOP);
537

    
538
  // For RegExp validation
539
  this.regexpState = null;
540
};
541

    
542
var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true } };
543

    
544
Parser.prototype.parse = function parse () {
545
  var node = this.options.program || this.startNode();
546
  this.nextToken();
547
  return this.parseTopLevel(node)
548
};
549

    
550
prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
551
prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 };
552
prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 };
553
prototypeAccessors.allowSuper.get = function () { return (this.currentThisScope().flags & SCOPE_SUPER) > 0 };
554
prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
555
prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
556

    
557
// Switch to a getter for 7.0.0.
558
Parser.prototype.inNonArrowFunction = function inNonArrowFunction () { return (this.currentThisScope().flags & SCOPE_FUNCTION) > 0 };
559

    
560
Parser.extend = function extend () {
561
    var plugins = [], len = arguments.length;
562
    while ( len-- ) plugins[ len ] = arguments[ len ];
563

    
564
  var cls = this;
565
  for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
566
  return cls
567
};
568

    
569
Parser.parse = function parse (input, options) {
570
  return new this(options, input).parse()
571
};
572

    
573
Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
574
  var parser = new this(options, input, pos);
575
  parser.nextToken();
576
  return parser.parseExpression()
577
};
578

    
579
Parser.tokenizer = function tokenizer (input, options) {
580
  return new this(options, input)
581
};
582

    
583
Object.defineProperties( Parser.prototype, prototypeAccessors );
584

    
585
var pp = Parser.prototype;
586

    
587
// ## Parser utilities
588

    
589
var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)")/;
590
pp.strictDirective = function(start) {
591
  for (;;) {
592
    // Try to find string literal.
593
    skipWhiteSpace.lastIndex = start;
594
    start += skipWhiteSpace.exec(this.input)[0].length;
595
    var match = literal.exec(this.input.slice(start));
596
    if (!match) { return false }
597
    if ((match[1] || match[2]) === "use strict") { return true }
598
    start += match[0].length;
599

    
600
    // Skip semicolon, if any.
601
    skipWhiteSpace.lastIndex = start;
602
    start += skipWhiteSpace.exec(this.input)[0].length;
603
    if (this.input[start] === ";")
604
      { start++; }
605
  }
606
};
607

    
608
// Predicate that tests whether the next token is of the given
609
// type, and if yes, consumes it as a side effect.
610

    
611
pp.eat = function(type) {
612
  if (this.type === type) {
613
    this.next();
614
    return true
615
  } else {
616
    return false
617
  }
618
};
619

    
620
// Tests whether parsed token is a contextual keyword.
621

    
622
pp.isContextual = function(name) {
623
  return this.type === types.name && this.value === name && !this.containsEsc
624
};
625

    
626
// Consumes contextual keyword if possible.
627

    
628
pp.eatContextual = function(name) {
629
  if (!this.isContextual(name)) { return false }
630
  this.next();
631
  return true
632
};
633

    
634
// Asserts that following token is given contextual keyword.
635

    
636
pp.expectContextual = function(name) {
637
  if (!this.eatContextual(name)) { this.unexpected(); }
638
};
639

    
640
// Test whether a semicolon can be inserted at the current position.
641

    
642
pp.canInsertSemicolon = function() {
643
  return this.type === types.eof ||
644
    this.type === types.braceR ||
645
    lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
646
};
647

    
648
pp.insertSemicolon = function() {
649
  if (this.canInsertSemicolon()) {
650
    if (this.options.onInsertedSemicolon)
651
      { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
652
    return true
653
  }
654
};
655

    
656
// Consume a semicolon, or, failing that, see if we are allowed to
657
// pretend that there is a semicolon at this position.
658

    
659
pp.semicolon = function() {
660
  if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
661
};
662

    
663
pp.afterTrailingComma = function(tokType, notNext) {
664
  if (this.type === tokType) {
665
    if (this.options.onTrailingComma)
666
      { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
667
    if (!notNext)
668
      { this.next(); }
669
    return true
670
  }
671
};
672

    
673
// Expect a token of a given type. If found, consume it, otherwise,
674
// raise an unexpected token error.
675

    
676
pp.expect = function(type) {
677
  this.eat(type) || this.unexpected();
678
};
679

    
680
// Raise an unexpected token error.
681

    
682
pp.unexpected = function(pos) {
683
  this.raise(pos != null ? pos : this.start, "Unexpected token");
684
};
685

    
686
function DestructuringErrors() {
687
  this.shorthandAssign =
688
  this.trailingComma =
689
  this.parenthesizedAssign =
690
  this.parenthesizedBind =
691
  this.doubleProto =
692
    -1;
693
}
694

    
695
pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
696
  if (!refDestructuringErrors) { return }
697
  if (refDestructuringErrors.trailingComma > -1)
698
    { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
699
  var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
700
  if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
701
};
702

    
703
pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
704
  if (!refDestructuringErrors) { return false }
705
  var shorthandAssign = refDestructuringErrors.shorthandAssign;
706
  var doubleProto = refDestructuringErrors.doubleProto;
707
  if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
708
  if (shorthandAssign >= 0)
709
    { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
710
  if (doubleProto >= 0)
711
    { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
712
};
713

    
714
pp.checkYieldAwaitInDefaultParams = function() {
715
  if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
716
    { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
717
  if (this.awaitPos)
718
    { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
719
};
720

    
721
pp.isSimpleAssignTarget = function(expr) {
722
  if (expr.type === "ParenthesizedExpression")
723
    { return this.isSimpleAssignTarget(expr.expression) }
724
  return expr.type === "Identifier" || expr.type === "MemberExpression"
725
};
726

    
727
var pp$1 = Parser.prototype;
728

    
729
// ### Statement parsing
730

    
731
// Parse a program. Initializes the parser, reads any number of
732
// statements, and wraps them in a Program node.  Optionally takes a
733
// `program` argument.  If present, the statements will be appended
734
// to its body instead of creating a new node.
735

    
736
pp$1.parseTopLevel = function(node) {
737
  var exports = {};
738
  if (!node.body) { node.body = []; }
739
  while (this.type !== types.eof) {
740
    var stmt = this.parseStatement(null, true, exports);
741
    node.body.push(stmt);
742
  }
743
  if (this.inModule)
744
    { for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1)
745
      {
746
        var name = list[i];
747

    
748
        this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
749
      } }
750
  this.adaptDirectivePrologue(node.body);
751
  this.next();
752
  node.sourceType = this.options.sourceType;
753
  return this.finishNode(node, "Program")
754
};
755

    
756
var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
757

    
758
pp$1.isLet = function(context) {
759
  if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
760
  skipWhiteSpace.lastIndex = this.pos;
761
  var skip = skipWhiteSpace.exec(this.input);
762
  var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
763
  // For ambiguous cases, determine if a LexicalDeclaration (or only a
764
  // Statement) is allowed here. If context is not empty then only a Statement
765
  // is allowed. However, `let [` is an explicit negative lookahead for
766
  // ExpressionStatement, so special-case it first.
767
  if (nextCh === 91) { return true } // '['
768
  if (context) { return false }
769

    
770
  if (nextCh === 123) { return true } // '{'
771
  if (isIdentifierStart(nextCh, true)) {
772
    var pos = next + 1;
773
    while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
774
    var ident = this.input.slice(next, pos);
775
    if (!keywordRelationalOperator.test(ident)) { return true }
776
  }
777
  return false
778
};
779

    
780
// check 'async [no LineTerminator here] function'
781
// - 'async /*foo*/ function' is OK.
782
// - 'async /*\n*/ function' is invalid.
783
pp$1.isAsyncFunction = function() {
784
  if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
785
    { return false }
786

    
787
  skipWhiteSpace.lastIndex = this.pos;
788
  var skip = skipWhiteSpace.exec(this.input);
789
  var next = this.pos + skip[0].length;
790
  return !lineBreak.test(this.input.slice(this.pos, next)) &&
791
    this.input.slice(next, next + 8) === "function" &&
792
    (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
793
};
794

    
795
// Parse a single statement.
796
//
797
// If expecting a statement and finding a slash operator, parse a
798
// regular expression literal. This is to handle cases like
799
// `if (foo) /blah/.exec(foo)`, where looking at the previous token
800
// does not help.
801

    
802
pp$1.parseStatement = function(context, topLevel, exports) {
803
  var starttype = this.type, node = this.startNode(), kind;
804

    
805
  if (this.isLet(context)) {
806
    starttype = types._var;
807
    kind = "let";
808
  }
809

    
810
  // Most types of statements are recognized by the keyword they
811
  // start with. Many are trivial to parse, some require a bit of
812
  // complexity.
813

    
814
  switch (starttype) {
815
  case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
816
  case types._debugger: return this.parseDebuggerStatement(node)
817
  case types._do: return this.parseDoStatement(node)
818
  case types._for: return this.parseForStatement(node)
819
  case types._function:
820
    // Function as sole body of either an if statement or a labeled statement
821
    // works, but not when it is part of a labeled statement that is the sole
822
    // body of an if statement.
823
    if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
824
    return this.parseFunctionStatement(node, false, !context)
825
  case types._class:
826
    if (context) { this.unexpected(); }
827
    return this.parseClass(node, true)
828
  case types._if: return this.parseIfStatement(node)
829
  case types._return: return this.parseReturnStatement(node)
830
  case types._switch: return this.parseSwitchStatement(node)
831
  case types._throw: return this.parseThrowStatement(node)
832
  case types._try: return this.parseTryStatement(node)
833
  case types._const: case types._var:
834
    kind = kind || this.value;
835
    if (context && kind !== "var") { this.unexpected(); }
836
    return this.parseVarStatement(node, kind)
837
  case types._while: return this.parseWhileStatement(node)
838
  case types._with: return this.parseWithStatement(node)
839
  case types.braceL: return this.parseBlock(true, node)
840
  case types.semi: return this.parseEmptyStatement(node)
841
  case types._export:
842
  case types._import:
843
    if (this.options.ecmaVersion > 10 && starttype === types._import) {
844
      skipWhiteSpace.lastIndex = this.pos;
845
      var skip = skipWhiteSpace.exec(this.input);
846
      var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
847
      if (nextCh === 40) // '('
848
        { return this.parseExpressionStatement(node, this.parseExpression()) }
849
    }
850

    
851
    if (!this.options.allowImportExportEverywhere) {
852
      if (!topLevel)
853
        { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
854
      if (!this.inModule)
855
        { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
856
    }
857
    return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
858

    
859
    // If the statement does not start with a statement keyword or a
860
    // brace, it's an ExpressionStatement or LabeledStatement. We
861
    // simply start parsing an expression, and afterwards, if the
862
    // next token is a colon and the expression was a simple
863
    // Identifier node, we switch to interpreting it as a label.
864
  default:
865
    if (this.isAsyncFunction()) {
866
      if (context) { this.unexpected(); }
867
      this.next();
868
      return this.parseFunctionStatement(node, true, !context)
869
    }
870

    
871
    var maybeName = this.value, expr = this.parseExpression();
872
    if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
873
      { return this.parseLabeledStatement(node, maybeName, expr, context) }
874
    else { return this.parseExpressionStatement(node, expr) }
875
  }
876
};
877

    
878
pp$1.parseBreakContinueStatement = function(node, keyword) {
879
  var isBreak = keyword === "break";
880
  this.next();
881
  if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
882
  else if (this.type !== types.name) { this.unexpected(); }
883
  else {
884
    node.label = this.parseIdent();
885
    this.semicolon();
886
  }
887

    
888
  // Verify that there is an actual destination to break or
889
  // continue to.
890
  var i = 0;
891
  for (; i < this.labels.length; ++i) {
892
    var lab = this.labels[i];
893
    if (node.label == null || lab.name === node.label.name) {
894
      if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
895
      if (node.label && isBreak) { break }
896
    }
897
  }
898
  if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
899
  return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
900
};
901

    
902
pp$1.parseDebuggerStatement = function(node) {
903
  this.next();
904
  this.semicolon();
905
  return this.finishNode(node, "DebuggerStatement")
906
};
907

    
908
pp$1.parseDoStatement = function(node) {
909
  this.next();
910
  this.labels.push(loopLabel);
911
  node.body = this.parseStatement("do");
912
  this.labels.pop();
913
  this.expect(types._while);
914
  node.test = this.parseParenExpression();
915
  if (this.options.ecmaVersion >= 6)
916
    { this.eat(types.semi); }
917
  else
918
    { this.semicolon(); }
919
  return this.finishNode(node, "DoWhileStatement")
920
};
921

    
922
// Disambiguating between a `for` and a `for`/`in` or `for`/`of`
923
// loop is non-trivial. Basically, we have to parse the init `var`
924
// statement or expression, disallowing the `in` operator (see
925
// the second parameter to `parseExpression`), and then check
926
// whether the next token is `in` or `of`. When there is no init
927
// part (semicolon immediately after the opening parenthesis), it
928
// is a regular `for` loop.
929

    
930
pp$1.parseForStatement = function(node) {
931
  this.next();
932
  var awaitAt = (this.options.ecmaVersion >= 9 && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction)) && this.eatContextual("await")) ? this.lastTokStart : -1;
933
  this.labels.push(loopLabel);
934
  this.enterScope(0);
935
  this.expect(types.parenL);
936
  if (this.type === types.semi) {
937
    if (awaitAt > -1) { this.unexpected(awaitAt); }
938
    return this.parseFor(node, null)
939
  }
940
  var isLet = this.isLet();
941
  if (this.type === types._var || this.type === types._const || isLet) {
942
    var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
943
    this.next();
944
    this.parseVar(init$1, true, kind);
945
    this.finishNode(init$1, "VariableDeclaration");
946
    if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1) {
947
      if (this.options.ecmaVersion >= 9) {
948
        if (this.type === types._in) {
949
          if (awaitAt > -1) { this.unexpected(awaitAt); }
950
        } else { node.await = awaitAt > -1; }
951
      }
952
      return this.parseForIn(node, init$1)
953
    }
954
    if (awaitAt > -1) { this.unexpected(awaitAt); }
955
    return this.parseFor(node, init$1)
956
  }
957
  var refDestructuringErrors = new DestructuringErrors;
958
  var init = this.parseExpression(true, refDestructuringErrors);
959
  if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
960
    if (this.options.ecmaVersion >= 9) {
961
      if (this.type === types._in) {
962
        if (awaitAt > -1) { this.unexpected(awaitAt); }
963
      } else { node.await = awaitAt > -1; }
964
    }
965
    this.toAssignable(init, false, refDestructuringErrors);
966
    this.checkLVal(init);
967
    return this.parseForIn(node, init)
968
  } else {
969
    this.checkExpressionErrors(refDestructuringErrors, true);
970
  }
971
  if (awaitAt > -1) { this.unexpected(awaitAt); }
972
  return this.parseFor(node, init)
973
};
974

    
975
pp$1.parseFunctionStatement = function(node, isAsync, declarationPosition) {
976
  this.next();
977
  return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
978
};
979

    
980
pp$1.parseIfStatement = function(node) {
981
  this.next();
982
  node.test = this.parseParenExpression();
983
  // allow function declarations in branches, but only in non-strict mode
984
  node.consequent = this.parseStatement("if");
985
  node.alternate = this.eat(types._else) ? this.parseStatement("if") : null;
986
  return this.finishNode(node, "IfStatement")
987
};
988

    
989
pp$1.parseReturnStatement = function(node) {
990
  if (!this.inFunction && !this.options.allowReturnOutsideFunction)
991
    { this.raise(this.start, "'return' outside of function"); }
992
  this.next();
993

    
994
  // In `return` (and `break`/`continue`), the keywords with
995
  // optional arguments, we eagerly look for a semicolon or the
996
  // possibility to insert one.
997

    
998
  if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
999
  else { node.argument = this.parseExpression(); this.semicolon(); }
1000
  return this.finishNode(node, "ReturnStatement")
1001
};
1002

    
1003
pp$1.parseSwitchStatement = function(node) {
1004
  this.next();
1005
  node.discriminant = this.parseParenExpression();
1006
  node.cases = [];
1007
  this.expect(types.braceL);
1008
  this.labels.push(switchLabel);
1009
  this.enterScope(0);
1010

    
1011
  // Statements under must be grouped (by label) in SwitchCase
1012
  // nodes. `cur` is used to keep the node that we are currently
1013
  // adding statements to.
1014

    
1015
  var cur;
1016
  for (var sawDefault = false; this.type !== types.braceR;) {
1017
    if (this.type === types._case || this.type === types._default) {
1018
      var isCase = this.type === types._case;
1019
      if (cur) { this.finishNode(cur, "SwitchCase"); }
1020
      node.cases.push(cur = this.startNode());
1021
      cur.consequent = [];
1022
      this.next();
1023
      if (isCase) {
1024
        cur.test = this.parseExpression();
1025
      } else {
1026
        if (sawDefault) { this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); }
1027
        sawDefault = true;
1028
        cur.test = null;
1029
      }
1030
      this.expect(types.colon);
1031
    } else {
1032
      if (!cur) { this.unexpected(); }
1033
      cur.consequent.push(this.parseStatement(null));
1034
    }
1035
  }
1036
  this.exitScope();
1037
  if (cur) { this.finishNode(cur, "SwitchCase"); }
1038
  this.next(); // Closing brace
1039
  this.labels.pop();
1040
  return this.finishNode(node, "SwitchStatement")
1041
};
1042

    
1043
pp$1.parseThrowStatement = function(node) {
1044
  this.next();
1045
  if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
1046
    { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
1047
  node.argument = this.parseExpression();
1048
  this.semicolon();
1049
  return this.finishNode(node, "ThrowStatement")
1050
};
1051

    
1052
// Reused empty array added for node fields that are always empty.
1053

    
1054
var empty = [];
1055

    
1056
pp$1.parseTryStatement = function(node) {
1057
  this.next();
1058
  node.block = this.parseBlock();
1059
  node.handler = null;
1060
  if (this.type === types._catch) {
1061
    var clause = this.startNode();
1062
    this.next();
1063
    if (this.eat(types.parenL)) {
1064
      clause.param = this.parseBindingAtom();
1065
      var simple = clause.param.type === "Identifier";
1066
      this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0);
1067
      this.checkLVal(clause.param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL);
1068
      this.expect(types.parenR);
1069
    } else {
1070
      if (this.options.ecmaVersion < 10) { this.unexpected(); }
1071
      clause.param = null;
1072
      this.enterScope(0);
1073
    }
1074
    clause.body = this.parseBlock(false);
1075
    this.exitScope();
1076
    node.handler = this.finishNode(clause, "CatchClause");
1077
  }
1078
  node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
1079
  if (!node.handler && !node.finalizer)
1080
    { this.raise(node.start, "Missing catch or finally clause"); }
1081
  return this.finishNode(node, "TryStatement")
1082
};
1083

    
1084
pp$1.parseVarStatement = function(node, kind) {
1085
  this.next();
1086
  this.parseVar(node, false, kind);
1087
  this.semicolon();
1088
  return this.finishNode(node, "VariableDeclaration")
1089
};
1090

    
1091
pp$1.parseWhileStatement = function(node) {
1092
  this.next();
1093
  node.test = this.parseParenExpression();
1094
  this.labels.push(loopLabel);
1095
  node.body = this.parseStatement("while");
1096
  this.labels.pop();
1097
  return this.finishNode(node, "WhileStatement")
1098
};
1099

    
1100
pp$1.parseWithStatement = function(node) {
1101
  if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
1102
  this.next();
1103
  node.object = this.parseParenExpression();
1104
  node.body = this.parseStatement("with");
1105
  return this.finishNode(node, "WithStatement")
1106
};
1107

    
1108
pp$1.parseEmptyStatement = function(node) {
1109
  this.next();
1110
  return this.finishNode(node, "EmptyStatement")
1111
};
1112

    
1113
pp$1.parseLabeledStatement = function(node, maybeName, expr, context) {
1114
  for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
1115
    {
1116
    var label = list[i$1];
1117

    
1118
    if (label.name === maybeName)
1119
      { this.raise(expr.start, "Label '" + maybeName + "' is already declared");
1120
  } }
1121
  var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
1122
  for (var i = this.labels.length - 1; i >= 0; i--) {
1123
    var label$1 = this.labels[i];
1124
    if (label$1.statementStart === node.start) {
1125
      // Update information about previous labels on this node
1126
      label$1.statementStart = this.start;
1127
      label$1.kind = kind;
1128
    } else { break }
1129
  }
1130
  this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
1131
  node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
1132
  this.labels.pop();
1133
  node.label = expr;
1134
  return this.finishNode(node, "LabeledStatement")
1135
};
1136

    
1137
pp$1.parseExpressionStatement = function(node, expr) {
1138
  node.expression = expr;
1139
  this.semicolon();
1140
  return this.finishNode(node, "ExpressionStatement")
1141
};
1142

    
1143
// Parse a semicolon-enclosed block of statements, handling `"use
1144
// strict"` declarations when `allowStrict` is true (used for
1145
// function bodies).
1146

    
1147
pp$1.parseBlock = function(createNewLexicalScope, node) {
1148
  if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
1149
  if ( node === void 0 ) node = this.startNode();
1150

    
1151
  node.body = [];
1152
  this.expect(types.braceL);
1153
  if (createNewLexicalScope) { this.enterScope(0); }
1154
  while (!this.eat(types.braceR)) {
1155
    var stmt = this.parseStatement(null);
1156
    node.body.push(stmt);
1157
  }
1158
  if (createNewLexicalScope) { this.exitScope(); }
1159
  return this.finishNode(node, "BlockStatement")
1160
};
1161

    
1162
// Parse a regular `for` loop. The disambiguation code in
1163
// `parseStatement` will already have parsed the init statement or
1164
// expression.
1165

    
1166
pp$1.parseFor = function(node, init) {
1167
  node.init = init;
1168
  this.expect(types.semi);
1169
  node.test = this.type === types.semi ? null : this.parseExpression();
1170
  this.expect(types.semi);
1171
  node.update = this.type === types.parenR ? null : this.parseExpression();
1172
  this.expect(types.parenR);
1173
  node.body = this.parseStatement("for");
1174
  this.exitScope();
1175
  this.labels.pop();
1176
  return this.finishNode(node, "ForStatement")
1177
};
1178

    
1179
// Parse a `for`/`in` and `for`/`of` loop, which are almost
1180
// same from parser's perspective.
1181

    
1182
pp$1.parseForIn = function(node, init) {
1183
  var isForIn = this.type === types._in;
1184
  this.next();
1185

    
1186
  if (
1187
    init.type === "VariableDeclaration" &&
1188
    init.declarations[0].init != null &&
1189
    (
1190
      !isForIn ||
1191
      this.options.ecmaVersion < 8 ||
1192
      this.strict ||
1193
      init.kind !== "var" ||
1194
      init.declarations[0].id.type !== "Identifier"
1195
    )
1196
  ) {
1197
    this.raise(
1198
      init.start,
1199
      ((isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer")
1200
    );
1201
  } else if (init.type === "AssignmentPattern") {
1202
    this.raise(init.start, "Invalid left-hand side in for-loop");
1203
  }
1204
  node.left = init;
1205
  node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
1206
  this.expect(types.parenR);
1207
  node.body = this.parseStatement("for");
1208
  this.exitScope();
1209
  this.labels.pop();
1210
  return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement")
1211
};
1212

    
1213
// Parse a list of variable declarations.
1214

    
1215
pp$1.parseVar = function(node, isFor, kind) {
1216
  node.declarations = [];
1217
  node.kind = kind;
1218
  for (;;) {
1219
    var decl = this.startNode();
1220
    this.parseVarId(decl, kind);
1221
    if (this.eat(types.eq)) {
1222
      decl.init = this.parseMaybeAssign(isFor);
1223
    } else if (kind === "const" && !(this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
1224
      this.unexpected();
1225
    } else if (decl.id.type !== "Identifier" && !(isFor && (this.type === types._in || this.isContextual("of")))) {
1226
      this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
1227
    } else {
1228
      decl.init = null;
1229
    }
1230
    node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
1231
    if (!this.eat(types.comma)) { break }
1232
  }
1233
  return node
1234
};
1235

    
1236
pp$1.parseVarId = function(decl, kind) {
1237
  decl.id = this.parseBindingAtom();
1238
  this.checkLVal(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
1239
};
1240

    
1241
var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
1242

    
1243
// Parse a function declaration or literal (depending on the
1244
// `statement & FUNC_STATEMENT`).
1245

    
1246
// Remove `allowExpressionBody` for 7.0.0, as it is only called with false
1247
pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync) {
1248
  this.initFunction(node);
1249
  if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
1250
    if (this.type === types.star && (statement & FUNC_HANGING_STATEMENT))
1251
      { this.unexpected(); }
1252
    node.generator = this.eat(types.star);
1253
  }
1254
  if (this.options.ecmaVersion >= 8)
1255
    { node.async = !!isAsync; }
1256

    
1257
  if (statement & FUNC_STATEMENT) {
1258
    node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types.name ? null : this.parseIdent();
1259
    if (node.id && !(statement & FUNC_HANGING_STATEMENT))
1260
      // If it is a regular function declaration in sloppy mode, then it is
1261
      // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
1262
      // mode depends on properties of the current scope (see
1263
      // treatFunctionsAsVar).
1264
      { this.checkLVal(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
1265
  }
1266

    
1267
  var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
1268
  this.yieldPos = 0;
1269
  this.awaitPos = 0;
1270
  this.awaitIdentPos = 0;
1271
  this.enterScope(functionFlags(node.async, node.generator));
1272

    
1273
  if (!(statement & FUNC_STATEMENT))
1274
    { node.id = this.type === types.name ? this.parseIdent() : null; }
1275

    
1276
  this.parseFunctionParams(node);
1277
  this.parseFunctionBody(node, allowExpressionBody, false);
1278

    
1279
  this.yieldPos = oldYieldPos;
1280
  this.awaitPos = oldAwaitPos;
1281
  this.awaitIdentPos = oldAwaitIdentPos;
1282
  return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
1283
};
1284

    
1285
pp$1.parseFunctionParams = function(node) {
1286
  this.expect(types.parenL);
1287
  node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
1288
  this.checkYieldAwaitInDefaultParams();
1289
};
1290

    
1291
// Parse a class declaration or literal (depending on the
1292
// `isStatement` parameter).
1293

    
1294
pp$1.parseClass = function(node, isStatement) {
1295
  this.next();
1296

    
1297
  // ecma-262 14.6 Class Definitions
1298
  // A class definition is always strict mode code.
1299
  var oldStrict = this.strict;
1300
  this.strict = true;
1301

    
1302
  this.parseClassId(node, isStatement);
1303
  this.parseClassSuper(node);
1304
  var classBody = this.startNode();
1305
  var hadConstructor = false;
1306
  classBody.body = [];
1307
  this.expect(types.braceL);
1308
  while (!this.eat(types.braceR)) {
1309
    var element = this.parseClassElement(node.superClass !== null);
1310
    if (element) {
1311
      classBody.body.push(element);
1312
      if (element.type === "MethodDefinition" && element.kind === "constructor") {
1313
        if (hadConstructor) { this.raise(element.start, "Duplicate constructor in the same class"); }
1314
        hadConstructor = true;
1315
      }
1316
    }
1317
  }
1318
  node.body = this.finishNode(classBody, "ClassBody");
1319
  this.strict = oldStrict;
1320
  return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
1321
};
1322

    
1323
pp$1.parseClassElement = function(constructorAllowsSuper) {
1324
  var this$1 = this;
1325

    
1326
  if (this.eat(types.semi)) { return null }
1327

    
1328
  var method = this.startNode();
1329
  var tryContextual = function (k, noLineBreak) {
1330
    if ( noLineBreak === void 0 ) noLineBreak = false;
1331

    
1332
    var start = this$1.start, startLoc = this$1.startLoc;
1333
    if (!this$1.eatContextual(k)) { return false }
1334
    if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
1335
    if (method.key) { this$1.unexpected(); }
1336
    method.computed = false;
1337
    method.key = this$1.startNodeAt(start, startLoc);
1338
    method.key.name = k;
1339
    this$1.finishNode(method.key, "Identifier");
1340
    return false
1341
  };
1342

    
1343
  method.kind = "method";
1344
  method.static = tryContextual("static");
1345
  var isGenerator = this.eat(types.star);
1346
  var isAsync = false;
1347
  if (!isGenerator) {
1348
    if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
1349
      isAsync = true;
1350
      isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
1351
    } else if (tryContextual("get")) {
1352
      method.kind = "get";
1353
    } else if (tryContextual("set")) {
1354
      method.kind = "set";
1355
    }
1356
  }
1357
  if (!method.key) { this.parsePropertyName(method); }
1358
  var key = method.key;
1359
  var allowsDirectSuper = false;
1360
  if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
1361
      key.type === "Literal" && key.value === "constructor")) {
1362
    if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
1363
    if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
1364
    if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
1365
    method.kind = "constructor";
1366
    allowsDirectSuper = constructorAllowsSuper;
1367
  } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
1368
    this.raise(key.start, "Classes may not have a static property named prototype");
1369
  }
1370
  this.parseClassMethod(method, isGenerator, isAsync, allowsDirectSuper);
1371
  if (method.kind === "get" && method.value.params.length !== 0)
1372
    { this.raiseRecoverable(method.value.start, "getter should have no params"); }
1373
  if (method.kind === "set" && method.value.params.length !== 1)
1374
    { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
1375
  if (method.kind === "set" && method.value.params[0].type === "RestElement")
1376
    { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
1377
  return method
1378
};
1379

    
1380
pp$1.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
1381
  method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
1382
  return this.finishNode(method, "MethodDefinition")
1383
};
1384

    
1385
pp$1.parseClassId = function(node, isStatement) {
1386
  if (this.type === types.name) {
1387
    node.id = this.parseIdent();
1388
    if (isStatement)
1389
      { this.checkLVal(node.id, BIND_LEXICAL, false); }
1390
  } else {
1391
    if (isStatement === true)
1392
      { this.unexpected(); }
1393
    node.id = null;
1394
  }
1395
};
1396

    
1397
pp$1.parseClassSuper = function(node) {
1398
  node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
1399
};
1400

    
1401
// Parses module export declaration.
1402

    
1403
pp$1.parseExport = function(node, exports) {
1404
  this.next();
1405
  // export * from '...'
1406
  if (this.eat(types.star)) {
1407
    this.expectContextual("from");
1408
    if (this.type !== types.string) { this.unexpected(); }
1409
    node.source = this.parseExprAtom();
1410
    this.semicolon();
1411
    return this.finishNode(node, "ExportAllDeclaration")
1412
  }
1413
  if (this.eat(types._default)) { // export default ...
1414
    this.checkExport(exports, "default", this.lastTokStart);
1415
    var isAsync;
1416
    if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
1417
      var fNode = this.startNode();
1418
      this.next();
1419
      if (isAsync) { this.next(); }
1420
      node.declaration = this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync);
1421
    } else if (this.type === types._class) {
1422
      var cNode = this.startNode();
1423
      node.declaration = this.parseClass(cNode, "nullableID");
1424
    } else {
1425
      node.declaration = this.parseMaybeAssign();
1426
      this.semicolon();
1427
    }
1428
    return this.finishNode(node, "ExportDefaultDeclaration")
1429
  }
1430
  // export var|const|let|function|class ...
1431
  if (this.shouldParseExportStatement()) {
1432
    node.declaration = this.parseStatement(null);
1433
    if (node.declaration.type === "VariableDeclaration")
1434
      { this.checkVariableExport(exports, node.declaration.declarations); }
1435
    else
1436
      { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
1437
    node.specifiers = [];
1438
    node.source = null;
1439
  } else { // export { x, y as z } [from '...']
1440
    node.declaration = null;
1441
    node.specifiers = this.parseExportSpecifiers(exports);
1442
    if (this.eatContextual("from")) {
1443
      if (this.type !== types.string) { this.unexpected(); }
1444
      node.source = this.parseExprAtom();
1445
    } else {
1446
      for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
1447
        // check for keywords used as local names
1448
        var spec = list[i];
1449

    
1450
        this.checkUnreserved(spec.local);
1451
        // check if export is defined
1452
        this.checkLocalExport(spec.local);
1453
      }
1454

    
1455
      node.source = null;
1456
    }
1457
    this.semicolon();
1458
  }
1459
  return this.finishNode(node, "ExportNamedDeclaration")
1460
};
1461

    
1462
pp$1.checkExport = function(exports, name, pos) {
1463
  if (!exports) { return }
1464
  if (has(exports, name))
1465
    { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
1466
  exports[name] = true;
1467
};
1468

    
1469
pp$1.checkPatternExport = function(exports, pat) {
1470
  var type = pat.type;
1471
  if (type === "Identifier")
1472
    { this.checkExport(exports, pat.name, pat.start); }
1473
  else if (type === "ObjectPattern")
1474
    { for (var i = 0, list = pat.properties; i < list.length; i += 1)
1475
      {
1476
        var prop = list[i];
1477

    
1478
        this.checkPatternExport(exports, prop);
1479
      } }
1480
  else if (type === "ArrayPattern")
1481
    { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
1482
      var elt = list$1[i$1];
1483

    
1484
        if (elt) { this.checkPatternExport(exports, elt); }
1485
    } }
1486
  else if (type === "Property")
1487
    { this.checkPatternExport(exports, pat.value); }
1488
  else if (type === "AssignmentPattern")
1489
    { this.checkPatternExport(exports, pat.left); }
1490
  else if (type === "RestElement")
1491
    { this.checkPatternExport(exports, pat.argument); }
1492
  else if (type === "ParenthesizedExpression")
1493
    { this.checkPatternExport(exports, pat.expression); }
1494
};
1495

    
1496
pp$1.checkVariableExport = function(exports, decls) {
1497
  if (!exports) { return }
1498
  for (var i = 0, list = decls; i < list.length; i += 1)
1499
    {
1500
    var decl = list[i];
1501

    
1502
    this.checkPatternExport(exports, decl.id);
1503
  }
1504
};
1505

    
1506
pp$1.shouldParseExportStatement = function() {
1507
  return this.type.keyword === "var" ||
1508
    this.type.keyword === "const" ||
1509
    this.type.keyword === "class" ||
1510
    this.type.keyword === "function" ||
1511
    this.isLet() ||
1512
    this.isAsyncFunction()
1513
};
1514

    
1515
// Parses a comma-separated list of module exports.
1516

    
1517
pp$1.parseExportSpecifiers = function(exports) {
1518
  var nodes = [], first = true;
1519
  // export { x, y as z } [from '...']
1520
  this.expect(types.braceL);
1521
  while (!this.eat(types.braceR)) {
1522
    if (!first) {
1523
      this.expect(types.comma);
1524
      if (this.afterTrailingComma(types.braceR)) { break }
1525
    } else { first = false; }
1526

    
1527
    var node = this.startNode();
1528
    node.local = this.parseIdent(true);
1529
    node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
1530
    this.checkExport(exports, node.exported.name, node.exported.start);
1531
    nodes.push(this.finishNode(node, "ExportSpecifier"));
1532
  }
1533
  return nodes
1534
};
1535

    
1536
// Parses import declaration.
1537

    
1538
pp$1.parseImport = function(node) {
1539
  this.next();
1540
  // import '...'
1541
  if (this.type === types.string) {
1542
    node.specifiers = empty;
1543
    node.source = this.parseExprAtom();
1544
  } else {
1545
    node.specifiers = this.parseImportSpecifiers();
1546
    this.expectContextual("from");
1547
    node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
1548
  }
1549
  this.semicolon();
1550
  return this.finishNode(node, "ImportDeclaration")
1551
};
1552

    
1553
// Parses a comma-separated list of module imports.
1554

    
1555
pp$1.parseImportSpecifiers = function() {
1556
  var nodes = [], first = true;
1557
  if (this.type === types.name) {
1558
    // import defaultObj, { x, y as z } from '...'
1559
    var node = this.startNode();
1560
    node.local = this.parseIdent();
1561
    this.checkLVal(node.local, BIND_LEXICAL);
1562
    nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
1563
    if (!this.eat(types.comma)) { return nodes }
1564
  }
1565
  if (this.type === types.star) {
1566
    var node$1 = this.startNode();
1567
    this.next();
1568
    this.expectContextual("as");
1569
    node$1.local = this.parseIdent();
1570
    this.checkLVal(node$1.local, BIND_LEXICAL);
1571
    nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
1572
    return nodes
1573
  }
1574
  this.expect(types.braceL);
1575
  while (!this.eat(types.braceR)) {
1576
    if (!first) {
1577
      this.expect(types.comma);
1578
      if (this.afterTrailingComma(types.braceR)) { break }
1579
    } else { first = false; }
1580

    
1581
    var node$2 = this.startNode();
1582
    node$2.imported = this.parseIdent(true);
1583
    if (this.eatContextual("as")) {
1584
      node$2.local = this.parseIdent();
1585
    } else {
1586
      this.checkUnreserved(node$2.imported);
1587
      node$2.local = node$2.imported;
1588
    }
1589
    this.checkLVal(node$2.local, BIND_LEXICAL);
1590
    nodes.push(this.finishNode(node$2, "ImportSpecifier"));
1591
  }
1592
  return nodes
1593
};
1594

    
1595
// Set `ExpressionStatement#directive` property for directive prologues.
1596
pp$1.adaptDirectivePrologue = function(statements) {
1597
  for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
1598
    statements[i].directive = statements[i].expression.raw.slice(1, -1);
1599
  }
1600
};
1601
pp$1.isDirectiveCandidate = function(statement) {
1602
  return (
1603
    statement.type === "ExpressionStatement" &&
1604
    statement.expression.type === "Literal" &&
1605
    typeof statement.expression.value === "string" &&
1606
    // Reject parenthesized strings.
1607
    (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
1608
  )
1609
};
1610

    
1611
var pp$2 = Parser.prototype;
1612

    
1613
// Convert existing expression atom to assignable pattern
1614
// if possible.
1615

    
1616
pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
1617
  if (this.options.ecmaVersion >= 6 && node) {
1618
    switch (node.type) {
1619
    case "Identifier":
1620
      if (this.inAsync && node.name === "await")
1621
        { this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
1622
      break
1623

    
1624
    case "ObjectPattern":
1625
    case "ArrayPattern":
1626
    case "RestElement":
1627
      break
1628

    
1629
    case "ObjectExpression":
1630
      node.type = "ObjectPattern";
1631
      if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1632
      for (var i = 0, list = node.properties; i < list.length; i += 1) {
1633
        var prop = list[i];
1634

    
1635
      this.toAssignable(prop, isBinding);
1636
        // Early error:
1637
        //   AssignmentRestProperty[Yield, Await] :
1638
        //     `...` DestructuringAssignmentTarget[Yield, Await]
1639
        //
1640
        //   It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
1641
        if (
1642
          prop.type === "RestElement" &&
1643
          (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
1644
        ) {
1645
          this.raise(prop.argument.start, "Unexpected token");
1646
        }
1647
      }
1648
      break
1649

    
1650
    case "Property":
1651
      // AssignmentProperty has type === "Property"
1652
      if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
1653
      this.toAssignable(node.value, isBinding);
1654
      break
1655

    
1656
    case "ArrayExpression":
1657
      node.type = "ArrayPattern";
1658
      if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1659
      this.toAssignableList(node.elements, isBinding);
1660
      break
1661

    
1662
    case "SpreadElement":
1663
      node.type = "RestElement";
1664
      this.toAssignable(node.argument, isBinding);
1665
      if (node.argument.type === "AssignmentPattern")
1666
        { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
1667
      break
1668

    
1669
    case "AssignmentExpression":
1670
      if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
1671
      node.type = "AssignmentPattern";
1672
      delete node.operator;
1673
      this.toAssignable(node.left, isBinding);
1674
      // falls through to AssignmentPattern
1675

    
1676
    case "AssignmentPattern":
1677
      break
1678

    
1679
    case "ParenthesizedExpression":
1680
      this.toAssignable(node.expression, isBinding, refDestructuringErrors);
1681
      break
1682

    
1683
    case "MemberExpression":
1684
      if (!isBinding) { break }
1685

    
1686
    default:
1687
      this.raise(node.start, "Assigning to rvalue");
1688
    }
1689
  } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1690
  return node
1691
};
1692

    
1693
// Convert list of expression atoms to binding list.
1694

    
1695
pp$2.toAssignableList = function(exprList, isBinding) {
1696
  var end = exprList.length;
1697
  for (var i = 0; i < end; i++) {
1698
    var elt = exprList[i];
1699
    if (elt) { this.toAssignable(elt, isBinding); }
1700
  }
1701
  if (end) {
1702
    var last = exprList[end - 1];
1703
    if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
1704
      { this.unexpected(last.argument.start); }
1705
  }
1706
  return exprList
1707
};
1708

    
1709
// Parses spread element.
1710

    
1711
pp$2.parseSpread = function(refDestructuringErrors) {
1712
  var node = this.startNode();
1713
  this.next();
1714
  node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
1715
  return this.finishNode(node, "SpreadElement")
1716
};
1717

    
1718
pp$2.parseRestBinding = function() {
1719
  var node = this.startNode();
1720
  this.next();
1721

    
1722
  // RestElement inside of a function parameter must be an identifier
1723
  if (this.options.ecmaVersion === 6 && this.type !== types.name)
1724
    { this.unexpected(); }
1725

    
1726
  node.argument = this.parseBindingAtom();
1727

    
1728
  return this.finishNode(node, "RestElement")
1729
};
1730

    
1731
// Parses lvalue (assignable) atom.
1732

    
1733
pp$2.parseBindingAtom = function() {
1734
  if (this.options.ecmaVersion >= 6) {
1735
    switch (this.type) {
1736
    case types.bracketL:
1737
      var node = this.startNode();
1738
      this.next();
1739
      node.elements = this.parseBindingList(types.bracketR, true, true);
1740
      return this.finishNode(node, "ArrayPattern")
1741

    
1742
    case types.braceL:
1743
      return this.parseObj(true)
1744
    }
1745
  }
1746
  return this.parseIdent()
1747
};
1748

    
1749
pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
1750
  var elts = [], first = true;
1751
  while (!this.eat(close)) {
1752
    if (first) { first = false; }
1753
    else { this.expect(types.comma); }
1754
    if (allowEmpty && this.type === types.comma) {
1755
      elts.push(null);
1756
    } else if (allowTrailingComma && this.afterTrailingComma(close)) {
1757
      break
1758
    } else if (this.type === types.ellipsis) {
1759
      var rest = this.parseRestBinding();
1760
      this.parseBindingListItem(rest);
1761
      elts.push(rest);
1762
      if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
1763
      this.expect(close);
1764
      break
1765
    } else {
1766
      var elem = this.parseMaybeDefault(this.start, this.startLoc);
1767
      this.parseBindingListItem(elem);
1768
      elts.push(elem);
1769
    }
1770
  }
1771
  return elts
1772
};
1773

    
1774
pp$2.parseBindingListItem = function(param) {
1775
  return param
1776
};
1777

    
1778
// Parses assignment pattern around given atom if possible.
1779

    
1780
pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
1781
  left = left || this.parseBindingAtom();
1782
  if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
1783
  var node = this.startNodeAt(startPos, startLoc);
1784
  node.left = left;
1785
  node.right = this.parseMaybeAssign();
1786
  return this.finishNode(node, "AssignmentPattern")
1787
};
1788

    
1789
// Verify that a node is an lval — something that can be assigned
1790
// to.
1791
// bindingType can be either:
1792
// 'var' indicating that the lval creates a 'var' binding
1793
// 'let' indicating that the lval creates a lexical ('let' or 'const') binding
1794
// 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
1795

    
1796
pp$2.checkLVal = function(expr, bindingType, checkClashes) {
1797
  if ( bindingType === void 0 ) bindingType = BIND_NONE;
1798

    
1799
  switch (expr.type) {
1800
  case "Identifier":
1801
    if (bindingType === BIND_LEXICAL && expr.name === "let")
1802
      { this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); }
1803
    if (this.strict && this.reservedWordsStrictBind.test(expr.name))
1804
      { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
1805
    if (checkClashes) {
1806
      if (has(checkClashes, expr.name))
1807
        { this.raiseRecoverable(expr.start, "Argument name clash"); }
1808
      checkClashes[expr.name] = true;
1809
    }
1810
    if (bindingType !== BIND_NONE && bindingType !== BIND_OUTSIDE) { this.declareName(expr.name, bindingType, expr.start); }
1811
    break
1812

    
1813
  case "MemberExpression":
1814
    if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
1815
    break
1816

    
1817
  case "ObjectPattern":
1818
    for (var i = 0, list = expr.properties; i < list.length; i += 1)
1819
      {
1820
    var prop = list[i];
1821

    
1822
    this.checkLVal(prop, bindingType, checkClashes);
1823
  }
1824
    break
1825

    
1826
  case "Property":
1827
    // AssignmentProperty has type === "Property"
1828
    this.checkLVal(expr.value, bindingType, checkClashes);
1829
    break
1830

    
1831
  case "ArrayPattern":
1832
    for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
1833
      var elem = list$1[i$1];
1834

    
1835
    if (elem) { this.checkLVal(elem, bindingType, checkClashes); }
1836
    }
1837
    break
1838

    
1839
  case "AssignmentPattern":
1840
    this.checkLVal(expr.left, bindingType, checkClashes);
1841
    break
1842

    
1843
  case "RestElement":
1844
    this.checkLVal(expr.argument, bindingType, checkClashes);
1845
    break
1846

    
1847
  case "ParenthesizedExpression":
1848
    this.checkLVal(expr.expression, bindingType, checkClashes);
1849
    break
1850

    
1851
  default:
1852
    this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
1853
  }
1854
};
1855

    
1856
// A recursive descent parser operates by defining functions for all
1857

    
1858
var pp$3 = Parser.prototype;
1859

    
1860
// Check if property name clashes with already added.
1861
// Object/class getters and setters are not allowed to clash —
1862
// either with each other or with an init property — and in
1863
// strict mode, init properties are also not allowed to be repeated.
1864

    
1865
pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
1866
  if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
1867
    { return }
1868
  if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
1869
    { return }
1870
  var key = prop.key;
1871
  var name;
1872
  switch (key.type) {
1873
  case "Identifier": name = key.name; break
1874
  case "Literal": name = String(key.value); break
1875
  default: return
1876
  }
1877
  var kind = prop.kind;
1878
  if (this.options.ecmaVersion >= 6) {
1879
    if (name === "__proto__" && kind === "init") {
1880
      if (propHash.proto) {
1881
        if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) { refDestructuringErrors.doubleProto = key.start; }
1882
        // Backwards-compat kludge. Can be removed in version 6.0
1883
        else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
1884
      }
1885
      propHash.proto = true;
1886
    }
1887
    return
1888
  }
1889
  name = "$" + name;
1890
  var other = propHash[name];
1891
  if (other) {
1892
    var redefinition;
1893
    if (kind === "init") {
1894
      redefinition = this.strict && other.init || other.get || other.set;
1895
    } else {
1896
      redefinition = other.init || other[kind];
1897
    }
1898
    if (redefinition)
1899
      { this.raiseRecoverable(key.start, "Redefinition of property"); }
1900
  } else {
1901
    other = propHash[name] = {
1902
      init: false,
1903
      get: false,
1904
      set: false
1905
    };
1906
  }
1907
  other[kind] = true;
1908
};
1909

    
1910
// ### Expression parsing
1911

    
1912
// These nest, from the most general expression type at the top to
1913
// 'atomic', nondivisible expression types at the bottom. Most of
1914
// the functions will simply let the function(s) below them parse,
1915
// and, *if* the syntactic construct they handle is present, wrap
1916
// the AST node that the inner parser gave them in another node.
1917

    
1918
// Parse a full expression. The optional arguments are used to
1919
// forbid the `in` operator (in for loops initalization expressions)
1920
// and provide reference for storing '=' operator inside shorthand
1921
// property assignment in contexts where both object expression
1922
// and object pattern might appear (so it's possible to raise
1923
// delayed syntax error at correct position).
1924

    
1925
pp$3.parseExpression = function(noIn, refDestructuringErrors) {
1926
  var startPos = this.start, startLoc = this.startLoc;
1927
  var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
1928
  if (this.type === types.comma) {
1929
    var node = this.startNodeAt(startPos, startLoc);
1930
    node.expressions = [expr];
1931
    while (this.eat(types.comma)) { node.expressions.push(this.parseMaybeAssign(noIn, refDestructuringErrors)); }
1932
    return this.finishNode(node, "SequenceExpression")
1933
  }
1934
  return expr
1935
};
1936

    
1937
// Parse an assignment expression. This includes applications of
1938
// operators like `+=`.
1939

    
1940
pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
1941
  if (this.isContextual("yield")) {
1942
    if (this.inGenerator) { return this.parseYield(noIn) }
1943
    // The tokenizer will assume an expression is allowed after
1944
    // `yield`, but this isn't that kind of yield
1945
    else { this.exprAllowed = false; }
1946
  }
1947

    
1948
  var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldShorthandAssign = -1;
1949
  if (refDestructuringErrors) {
1950
    oldParenAssign = refDestructuringErrors.parenthesizedAssign;
1951
    oldTrailingComma = refDestructuringErrors.trailingComma;
1952
    oldShorthandAssign = refDestructuringErrors.shorthandAssign;
1953
    refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.shorthandAssign = -1;
1954
  } else {
1955
    refDestructuringErrors = new DestructuringErrors;
1956
    ownDestructuringErrors = true;
1957
  }
1958

    
1959
  var startPos = this.start, startLoc = this.startLoc;
1960
  if (this.type === types.parenL || this.type === types.name)
1961
    { this.potentialArrowAt = this.start; }
1962
  var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
1963
  if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
1964
  if (this.type.isAssign) {
1965
    var node = this.startNodeAt(startPos, startLoc);
1966
    node.operator = this.value;
1967
    node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left;
1968
    if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
1969
    refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
1970
    this.checkLVal(left);
1971
    this.next();
1972
    node.right = this.parseMaybeAssign(noIn);
1973
    return this.finishNode(node, "AssignmentExpression")
1974
  } else {
1975
    if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
1976
  }
1977
  if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
1978
  if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
1979
  if (oldShorthandAssign > -1) { refDestructuringErrors.shorthandAssign = oldShorthandAssign; }
1980
  return left
1981
};
1982

    
1983
// Parse a ternary conditional (`?:`) operator.
1984

    
1985
pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
1986
  var startPos = this.start, startLoc = this.startLoc;
1987
  var expr = this.parseExprOps(noIn, refDestructuringErrors);
1988
  if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
1989
  if (this.eat(types.question)) {
1990
    var node = this.startNodeAt(startPos, startLoc);
1991
    node.test = expr;
1992
    node.consequent = this.parseMaybeAssign();
1993
    this.expect(types.colon);
1994
    node.alternate = this.parseMaybeAssign(noIn);
1995
    return this.finishNode(node, "ConditionalExpression")
1996
  }
1997
  return expr
1998
};
1999

    
2000
// Start the precedence parser.
2001

    
2002
pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
2003
  var startPos = this.start, startLoc = this.startLoc;
2004
  var expr = this.parseMaybeUnary(refDestructuringErrors, false);
2005
  if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
2006
  return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
2007
};
2008

    
2009
// Parse binary operators with the operator precedence parsing
2010
// algorithm. `left` is the left-hand side of the operator.
2011
// `minPrec` provides context that allows the function to stop and
2012
// defer further parser to one of its callers when it encounters an
2013
// operator that has a lower precedence than the set it is parsing.
2014

    
2015
pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
2016
  var prec = this.type.binop;
2017
  if (prec != null && (!noIn || this.type !== types._in)) {
2018
    if (prec > minPrec) {
2019
      var logical = this.type === types.logicalOR || this.type === types.logicalAND;
2020
      var op = this.value;
2021
      this.next();
2022
      var startPos = this.start, startLoc = this.startLoc;
2023
      var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
2024
      var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
2025
      return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
2026
    }
2027
  }
2028
  return left
2029
};
2030

    
2031
pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
2032
  var node = this.startNodeAt(startPos, startLoc);
2033
  node.left = left;
2034
  node.operator = op;
2035
  node.right = right;
2036
  return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
2037
};
2038

    
2039
// Parse unary operators, both prefix and postfix.
2040

    
2041
pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
2042
  var startPos = this.start, startLoc = this.startLoc, expr;
2043
  if (this.isContextual("await") && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction))) {
2044
    expr = this.parseAwait();
2045
    sawUnary = true;
2046
  } else if (this.type.prefix) {
2047
    var node = this.startNode(), update = this.type === types.incDec;
2048
    node.operator = this.value;
2049
    node.prefix = true;
2050
    this.next();
2051
    node.argument = this.parseMaybeUnary(null, true);
2052
    this.checkExpressionErrors(refDestructuringErrors, true);
2053
    if (update) { this.checkLVal(node.argument); }
2054
    else if (this.strict && node.operator === "delete" &&
2055
             node.argument.type === "Identifier")
2056
      { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
2057
    else { sawUnary = true; }
2058
    expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
2059
  } else {
2060
    expr = this.parseExprSubscripts(refDestructuringErrors);
2061
    if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
2062
    while (this.type.postfix && !this.canInsertSemicolon()) {
2063
      var node$1 = this.startNodeAt(startPos, startLoc);
2064
      node$1.operator = this.value;
2065
      node$1.prefix = false;
2066
      node$1.argument = expr;
2067
      this.checkLVal(expr);
2068
      this.next();
2069
      expr = this.finishNode(node$1, "UpdateExpression");
2070
    }
2071
  }
2072

    
2073
  if (!sawUnary && this.eat(types.starstar))
2074
    { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
2075
  else
2076
    { return expr }
2077
};
2078

    
2079
// Parse call, dot, and `[]`-subscript expressions.
2080

    
2081
pp$3.parseExprSubscripts = function(refDestructuringErrors) {
2082
  var startPos = this.start, startLoc = this.startLoc;
2083
  var expr = this.parseExprAtom(refDestructuringErrors);
2084
  var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
2085
  if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
2086
  var result = this.parseSubscripts(expr, startPos, startLoc);
2087
  if (refDestructuringErrors && result.type === "MemberExpression") {
2088
    if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
2089
    if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
2090
  }
2091
  return result
2092
};
2093

    
2094
pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
2095
  var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
2096
      this.lastTokEnd === base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async";
2097
  while (true) {
2098
    var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow);
2099
    if (element === base || element.type === "ArrowFunctionExpression") { return element }
2100
    base = element;
2101
  }
2102
};
2103

    
2104
pp$3.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow) {
2105
  var computed = this.eat(types.bracketL);
2106
  if (computed || this.eat(types.dot)) {
2107
    var node = this.startNodeAt(startPos, startLoc);
2108
    node.object = base;
2109
    node.property = computed ? this.parseExpression() : this.parseIdent(this.options.allowReserved !== "never");
2110
    node.computed = !!computed;
2111
    if (computed) { this.expect(types.bracketR); }
2112
    base = this.finishNode(node, "MemberExpression");
2113
  } else if (!noCalls && this.eat(types.parenL)) {
2114
    var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
2115
    this.yieldPos = 0;
2116
    this.awaitPos = 0;
2117
    this.awaitIdentPos = 0;
2118
    var exprList = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8 && base.type !== "Import", false, refDestructuringErrors);
2119
    if (maybeAsyncArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2120
      this.checkPatternErrors(refDestructuringErrors, false);
2121
      this.checkYieldAwaitInDefaultParams();
2122
      if (this.awaitIdentPos > 0)
2123
        { this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); }
2124
      this.yieldPos = oldYieldPos;
2125
      this.awaitPos = oldAwaitPos;
2126
      this.awaitIdentPos = oldAwaitIdentPos;
2127
      return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true)
2128
    }
2129
    this.checkExpressionErrors(refDestructuringErrors, true);
2130
    this.yieldPos = oldYieldPos || this.yieldPos;
2131
    this.awaitPos = oldAwaitPos || this.awaitPos;
2132
    this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos;
2133
    var node$1 = this.startNodeAt(startPos, startLoc);
2134
    node$1.callee = base;
2135
    node$1.arguments = exprList;
2136
    if (node$1.callee.type === "Import") {
2137
      if (node$1.arguments.length !== 1) {
2138
        this.raise(node$1.start, "import() requires exactly one argument");
2139
      }
2140

    
2141
      var importArg = node$1.arguments[0];
2142
      if (importArg && importArg.type === "SpreadElement") {
2143
        this.raise(importArg.start, "... is not allowed in import()");
2144
      }
2145
    }
2146
    base = this.finishNode(node$1, "CallExpression");
2147
  } else if (this.type === types.backQuote) {
2148
    var node$2 = this.startNodeAt(startPos, startLoc);
2149
    node$2.tag = base;
2150
    node$2.quasi = this.parseTemplate({isTagged: true});
2151
    base = this.finishNode(node$2, "TaggedTemplateExpression");
2152
  }
2153
  return base
2154
};
2155

    
2156
// Parse an atomic expression — either a single token that is an
2157
// expression, an expression started by a keyword like `function` or
2158
// `new`, or an expression wrapped in punctuation like `()`, `[]`,
2159
// or `{}`.
2160

    
2161
pp$3.parseExprAtom = function(refDestructuringErrors) {
2162
  // If a division operator appears in an expression position, the
2163
  // tokenizer got confused, and we force it to read a regexp instead.
2164
  if (this.type === types.slash) { this.readRegexp(); }
2165

    
2166
  var node, canBeArrow = this.potentialArrowAt === this.start;
2167
  switch (this.type) {
2168
  case types._super:
2169
    if (!this.allowSuper)
2170
      { this.raise(this.start, "'super' keyword outside a method"); }
2171
    node = this.startNode();
2172
    this.next();
2173
    if (this.type === types.parenL && !this.allowDirectSuper)
2174
      { this.raise(node.start, "super() call outside constructor of a subclass"); }
2175
    // The `super` keyword can appear at below:
2176
    // SuperProperty:
2177
    //     super [ Expression ]
2178
    //     super . IdentifierName
2179
    // SuperCall:
2180
    //     super Arguments
2181
    if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
2182
      { this.unexpected(); }
2183
    return this.finishNode(node, "Super")
2184

    
2185
  case types._this:
2186
    node = this.startNode();
2187
    this.next();
2188
    return this.finishNode(node, "ThisExpression")
2189

    
2190
  case types.name:
2191
    var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
2192
    var id = this.parseIdent(false);
2193
    if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
2194
      { return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true) }
2195
    if (canBeArrow && !this.canInsertSemicolon()) {
2196
      if (this.eat(types.arrow))
2197
        { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
2198
      if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
2199
        id = this.parseIdent(false);
2200
        if (this.canInsertSemicolon() || !this.eat(types.arrow))
2201
          { this.unexpected(); }
2202
        return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
2203
      }
2204
    }
2205
    return id
2206

    
2207
  case types.regexp:
2208
    var value = this.value;
2209
    node = this.parseLiteral(value.value);
2210
    node.regex = {pattern: value.pattern, flags: value.flags};
2211
    return node
2212

    
2213
  case types.num: case types.string:
2214
    return this.parseLiteral(this.value)
2215

    
2216
  case types._null: case types._true: case types._false:
2217
    node = this.startNode();
2218
    node.value = this.type === types._null ? null : this.type === types._true;
2219
    node.raw = this.type.keyword;
2220
    this.next();
2221
    return this.finishNode(node, "Literal")
2222

    
2223
  case types.parenL:
2224
    var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
2225
    if (refDestructuringErrors) {
2226
      if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
2227
        { refDestructuringErrors.parenthesizedAssign = start; }
2228
      if (refDestructuringErrors.parenthesizedBind < 0)
2229
        { refDestructuringErrors.parenthesizedBind = start; }
2230
    }
2231
    return expr
2232

    
2233
  case types.bracketL:
2234
    node = this.startNode();
2235
    this.next();
2236
    node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
2237
    return this.finishNode(node, "ArrayExpression")
2238

    
2239
  case types.braceL:
2240
    return this.parseObj(false, refDestructuringErrors)
2241

    
2242
  case types._function:
2243
    node = this.startNode();
2244
    this.next();
2245
    return this.parseFunction(node, 0)
2246

    
2247
  case types._class:
2248
    return this.parseClass(this.startNode(), false)
2249

    
2250
  case types._new:
2251
    return this.parseNew()
2252

    
2253
  case types.backQuote:
2254
    return this.parseTemplate()
2255

    
2256
  case types._import:
2257
    if (this.options.ecmaVersion > 10) {
2258
      return this.parseDynamicImport()
2259
    } else {
2260
      return this.unexpected()
2261
    }
2262

    
2263
  default:
2264
    this.unexpected();
2265
  }
2266
};
2267

    
2268
pp$3.parseDynamicImport = function() {
2269
  var node = this.startNode();
2270
  this.next();
2271
  if (this.type !== types.parenL) {
2272
    this.unexpected();
2273
  }
2274
  return this.finishNode(node, "Import")
2275
};
2276

    
2277
pp$3.parseLiteral = function(value) {
2278
  var node = this.startNode();
2279
  node.value = value;
2280
  node.raw = this.input.slice(this.start, this.end);
2281
  if (node.raw.charCodeAt(node.raw.length - 1) === 110) { node.bigint = node.raw.slice(0, -1); }
2282
  this.next();
2283
  return this.finishNode(node, "Literal")
2284
};
2285

    
2286
pp$3.parseParenExpression = function() {
2287
  this.expect(types.parenL);
2288
  var val = this.parseExpression();
2289
  this.expect(types.parenR);
2290
  return val
2291
};
2292

    
2293
pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
2294
  var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
2295
  if (this.options.ecmaVersion >= 6) {
2296
    this.next();
2297

    
2298
    var innerStartPos = this.start, innerStartLoc = this.startLoc;
2299
    var exprList = [], first = true, lastIsComma = false;
2300
    var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
2301
    this.yieldPos = 0;
2302
    this.awaitPos = 0;
2303
    // Do not save awaitIdentPos to allow checking awaits nested in parameters
2304
    while (this.type !== types.parenR) {
2305
      first ? first = false : this.expect(types.comma);
2306
      if (allowTrailingComma && this.afterTrailingComma(types.parenR, true)) {
2307
        lastIsComma = true;
2308
        break
2309
      } else if (this.type === types.ellipsis) {
2310
        spreadStart = this.start;
2311
        exprList.push(this.parseParenItem(this.parseRestBinding()));
2312
        if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
2313
        break
2314
      } else {
2315
        exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
2316
      }
2317
    }
2318
    var innerEndPos = this.start, innerEndLoc = this.startLoc;
2319
    this.expect(types.parenR);
2320

    
2321
    if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2322
      this.checkPatternErrors(refDestructuringErrors, false);
2323
      this.checkYieldAwaitInDefaultParams();
2324
      this.yieldPos = oldYieldPos;
2325
      this.awaitPos = oldAwaitPos;
2326
      return this.parseParenArrowList(startPos, startLoc, exprList)
2327
    }
2328

    
2329
    if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
2330
    if (spreadStart) { this.unexpected(spreadStart); }
2331
    this.checkExpressionErrors(refDestructuringErrors, true);
2332
    this.yieldPos = oldYieldPos || this.yieldPos;
2333
    this.awaitPos = oldAwaitPos || this.awaitPos;
2334

    
2335
    if (exprList.length > 1) {
2336
      val = this.startNodeAt(innerStartPos, innerStartLoc);
2337
      val.expressions = exprList;
2338
      this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
2339
    } else {
2340
      val = exprList[0];
2341
    }
2342
  } else {
2343
    val = this.parseParenExpression();
2344
  }
2345

    
2346
  if (this.options.preserveParens) {
2347
    var par = this.startNodeAt(startPos, startLoc);
2348
    par.expression = val;
2349
    return this.finishNode(par, "ParenthesizedExpression")
2350
  } else {
2351
    return val
2352
  }
2353
};
2354

    
2355
pp$3.parseParenItem = function(item) {
2356
  return item
2357
};
2358

    
2359
pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
2360
  return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
2361
};
2362

    
2363
// New's precedence is slightly tricky. It must allow its argument to
2364
// be a `[]` or dot subscript expression, but not a call — at least,
2365
// not without wrapping it in parentheses. Thus, it uses the noCalls
2366
// argument to parseSubscripts to prevent it from consuming the
2367
// argument list.
2368

    
2369
var empty$1 = [];
2370

    
2371
pp$3.parseNew = function() {
2372
  var node = this.startNode();
2373
  var meta = this.parseIdent(true);
2374
  if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
2375
    node.meta = meta;
2376
    var containsEsc = this.containsEsc;
2377
    node.property = this.parseIdent(true);
2378
    if (node.property.name !== "target" || containsEsc)
2379
      { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
2380
    if (!this.inNonArrowFunction())
2381
      { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
2382
    return this.finishNode(node, "MetaProperty")
2383
  }
2384
  var startPos = this.start, startLoc = this.startLoc;
2385
  node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
2386
  if (this.options.ecmaVersion > 10 && node.callee.type === "Import") {
2387
    this.raise(node.callee.start, "Cannot use new with import(...)");
2388
  }
2389
  if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8 && node.callee.type !== "Import", false); }
2390
  else { node.arguments = empty$1; }
2391
  return this.finishNode(node, "NewExpression")
2392
};
2393

    
2394
// Parse template expression.
2395

    
2396
pp$3.parseTemplateElement = function(ref) {
2397
  var isTagged = ref.isTagged;
2398

    
2399
  var elem = this.startNode();
2400
  if (this.type === types.invalidTemplate) {
2401
    if (!isTagged) {
2402
      this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
2403
    }
2404
    elem.value = {
2405
      raw: this.value,
2406
      cooked: null
2407
    };
2408
  } else {
2409
    elem.value = {
2410
      raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
2411
      cooked: this.value
2412
    };
2413
  }
2414
  this.next();
2415
  elem.tail = this.type === types.backQuote;
2416
  return this.finishNode(elem, "TemplateElement")
2417
};
2418

    
2419
pp$3.parseTemplate = function(ref) {
2420
  if ( ref === void 0 ) ref = {};
2421
  var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
2422

    
2423
  var node = this.startNode();
2424
  this.next();
2425
  node.expressions = [];
2426
  var curElt = this.parseTemplateElement({isTagged: isTagged});
2427
  node.quasis = [curElt];
2428
  while (!curElt.tail) {
2429
    if (this.type === types.eof) { this.raise(this.pos, "Unterminated template literal"); }
2430
    this.expect(types.dollarBraceL);
2431
    node.expressions.push(this.parseExpression());
2432
    this.expect(types.braceR);
2433
    node.quasis.push(curElt = this.parseTemplateElement({isTagged: isTagged}));
2434
  }
2435
  this.next();
2436
  return this.finishNode(node, "TemplateLiteral")
2437
};
2438

    
2439
pp$3.isAsyncProp = function(prop) {
2440
  return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
2441
    (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)) &&
2442
    !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
2443
};
2444

    
2445
// Parse an object literal or binding pattern.
2446

    
2447
pp$3.parseObj = function(isPattern, refDestructuringErrors) {
2448
  var node = this.startNode(), first = true, propHash = {};
2449
  node.properties = [];
2450
  this.next();
2451
  while (!this.eat(types.braceR)) {
2452
    if (!first) {
2453
      this.expect(types.comma);
2454
      if (this.afterTrailingComma(types.braceR)) { break }
2455
    } else { first = false; }
2456

    
2457
    var prop = this.parseProperty(isPattern, refDestructuringErrors);
2458
    if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
2459
    node.properties.push(prop);
2460
  }
2461
  return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
2462
};
2463

    
2464
pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
2465
  var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
2466
  if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
2467
    if (isPattern) {
2468
      prop.argument = this.parseIdent(false);
2469
      if (this.type === types.comma) {
2470
        this.raise(this.start, "Comma is not permitted after the rest element");
2471
      }
2472
      return this.finishNode(prop, "RestElement")
2473
    }
2474
    // To disallow parenthesized identifier via `this.toAssignable()`.
2475
    if (this.type === types.parenL && refDestructuringErrors) {
2476
      if (refDestructuringErrors.parenthesizedAssign < 0) {
2477
        refDestructuringErrors.parenthesizedAssign = this.start;
2478
      }
2479
      if (refDestructuringErrors.parenthesizedBind < 0) {
2480
        refDestructuringErrors.parenthesizedBind = this.start;
2481
      }
2482
    }
2483
    // Parse argument.
2484
    prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
2485
    // To disallow trailing comma via `this.toAssignable()`.
2486
    if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
2487
      refDestructuringErrors.trailingComma = this.start;
2488
    }
2489
    // Finish
2490
    return this.finishNode(prop, "SpreadElement")
2491
  }
2492
  if (this.options.ecmaVersion >= 6) {
2493
    prop.method = false;
2494
    prop.shorthand = false;
2495
    if (isPattern || refDestructuringErrors) {
2496
      startPos = this.start;
2497
      startLoc = this.startLoc;
2498
    }
2499
    if (!isPattern)
2500
      { isGenerator = this.eat(types.star); }
2501
  }
2502
  var containsEsc = this.containsEsc;
2503
  this.parsePropertyName(prop);
2504
  if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
2505
    isAsync = true;
2506
    isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
2507
    this.parsePropertyName(prop, refDestructuringErrors);
2508
  } else {
2509
    isAsync = false;
2510
  }
2511
  this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
2512
  return this.finishNode(prop, "Property")
2513
};
2514

    
2515
pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
2516
  if ((isGenerator || isAsync) && this.type === types.colon)
2517
    { this.unexpected(); }
2518

    
2519
  if (this.eat(types.colon)) {
2520
    prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
2521
    prop.kind = "init";
2522
  } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
2523
    if (isPattern) { this.unexpected(); }
2524
    prop.kind = "init";
2525
    prop.method = true;
2526
    prop.value = this.parseMethod(isGenerator, isAsync);
2527
  } else if (!isPattern && !containsEsc &&
2528
             this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
2529
             (prop.key.name === "get" || prop.key.name === "set") &&
2530
             (this.type !== types.comma && this.type !== types.braceR)) {
2531
    if (isGenerator || isAsync) { this.unexpected(); }
2532
    prop.kind = prop.key.name;
2533
    this.parsePropertyName(prop);
2534
    prop.value = this.parseMethod(false);
2535
    var paramCount = prop.kind === "get" ? 0 : 1;
2536
    if (prop.value.params.length !== paramCount) {
2537
      var start = prop.value.start;
2538
      if (prop.kind === "get")
2539
        { this.raiseRecoverable(start, "getter should have no params"); }
2540
      else
2541
        { this.raiseRecoverable(start, "setter should have exactly one param"); }
2542
    } else {
2543
      if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
2544
        { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
2545
    }
2546
  } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
2547
    if (isGenerator || isAsync) { this.unexpected(); }
2548
    this.checkUnreserved(prop.key);
2549
    if (prop.key.name === "await" && !this.awaitIdentPos)
2550
      { this.awaitIdentPos = startPos; }
2551
    prop.kind = "init";
2552
    if (isPattern) {
2553
      prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2554
    } else if (this.type === types.eq && refDestructuringErrors) {
2555
      if (refDestructuringErrors.shorthandAssign < 0)
2556
        { refDestructuringErrors.shorthandAssign = this.start; }
2557
      prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
2558
    } else {
2559
      prop.value = prop.key;
2560
    }
2561
    prop.shorthand = true;
2562
  } else { this.unexpected(); }
2563
};
2564

    
2565
pp$3.parsePropertyName = function(prop) {
2566
  if (this.options.ecmaVersion >= 6) {
2567
    if (this.eat(types.bracketL)) {
2568
      prop.computed = true;
2569
      prop.key = this.parseMaybeAssign();
2570
      this.expect(types.bracketR);
2571
      return prop.key
2572
    } else {
2573
      prop.computed = false;
2574
    }
2575
  }
2576
  return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
2577
};
2578

    
2579
// Initialize empty function node.
2580

    
2581
pp$3.initFunction = function(node) {
2582
  node.id = null;
2583
  if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
2584
  if (this.options.ecmaVersion >= 8) { node.async = false; }
2585
};
2586

    
2587
// Parse object or class method.
2588

    
2589
pp$3.parseMethod = function(isGenerator, isAsync, allowDirectSuper) {
2590
  var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
2591

    
2592
  this.initFunction(node);
2593
  if (this.options.ecmaVersion >= 6)
2594
    { node.generator = isGenerator; }
2595
  if (this.options.ecmaVersion >= 8)
2596
    { node.async = !!isAsync; }
2597

    
2598
  this.yieldPos = 0;
2599
  this.awaitPos = 0;
2600
  this.awaitIdentPos = 0;
2601
  this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
2602

    
2603
  this.expect(types.parenL);
2604
  node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
2605
  this.checkYieldAwaitInDefaultParams();
2606
  this.parseFunctionBody(node, false, true);
2607

    
2608
  this.yieldPos = oldYieldPos;
2609
  this.awaitPos = oldAwaitPos;
2610
  this.awaitIdentPos = oldAwaitIdentPos;
2611
  return this.finishNode(node, "FunctionExpression")
2612
};
2613

    
2614
// Parse arrow function expression with given parameters.
2615

    
2616
pp$3.parseArrowExpression = function(node, params, isAsync) {
2617
  var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
2618

    
2619
  this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
2620
  this.initFunction(node);
2621
  if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
2622

    
2623
  this.yieldPos = 0;
2624
  this.awaitPos = 0;
2625
  this.awaitIdentPos = 0;
2626

    
2627
  node.params = this.toAssignableList(params, true);
2628
  this.parseFunctionBody(node, true, false);
2629

    
2630
  this.yieldPos = oldYieldPos;
2631
  this.awaitPos = oldAwaitPos;
2632
  this.awaitIdentPos = oldAwaitIdentPos;
2633
  return this.finishNode(node, "ArrowFunctionExpression")
2634
};
2635

    
2636
// Parse function body and check parameters.
2637

    
2638
pp$3.parseFunctionBody = function(node, isArrowFunction, isMethod) {
2639
  var isExpression = isArrowFunction && this.type !== types.braceL;
2640
  var oldStrict = this.strict, useStrict = false;
2641

    
2642
  if (isExpression) {
2643
    node.body = this.parseMaybeAssign();
2644
    node.expression = true;
2645
    this.checkParams(node, false);
2646
  } else {
2647
    var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
2648
    if (!oldStrict || nonSimple) {
2649
      useStrict = this.strictDirective(this.end);
2650
      // If this is a strict mode function, verify that argument names
2651
      // are not repeated, and it does not try to bind the words `eval`
2652
      // or `arguments`.
2653
      if (useStrict && nonSimple)
2654
        { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
2655
    }
2656
    // Start a new scope with regard to labels and the `inFunction`
2657
    // flag (restore them to their old value afterwards).
2658
    var oldLabels = this.labels;
2659
    this.labels = [];
2660
    if (useStrict) { this.strict = true; }
2661

    
2662
    // Add the params to varDeclaredNames to ensure that an error is thrown
2663
    // if a let/const declaration in the function clashes with one of the params.
2664
    this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params));
2665
    node.body = this.parseBlock(false);
2666
    node.expression = false;
2667
    this.adaptDirectivePrologue(node.body.body);
2668
    this.labels = oldLabels;
2669
  }
2670
  this.exitScope();
2671

    
2672
  // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
2673
  if (this.strict && node.id) { this.checkLVal(node.id, BIND_OUTSIDE); }
2674
  this.strict = oldStrict;
2675
};
2676

    
2677
pp$3.isSimpleParamList = function(params) {
2678
  for (var i = 0, list = params; i < list.length; i += 1)
2679
    {
2680
    var param = list[i];
2681

    
2682
    if (param.type !== "Identifier") { return false
2683
  } }
2684
  return true
2685
};
2686

    
2687
// Checks function params for various disallowed patterns such as using "eval"
2688
// or "arguments" and duplicate parameters.
2689

    
2690
pp$3.checkParams = function(node, allowDuplicates) {
2691
  var nameHash = {};
2692
  for (var i = 0, list = node.params; i < list.length; i += 1)
2693
    {
2694
    var param = list[i];
2695

    
2696
    this.checkLVal(param, BIND_VAR, allowDuplicates ? null : nameHash);
2697
  }
2698
};
2699

    
2700
// Parses a comma-separated list of expressions, and returns them as
2701
// an array. `close` is the token type that ends the list, and
2702
// `allowEmpty` can be turned on to allow subsequent commas with
2703
// nothing in between them to be parsed as `null` (which is needed
2704
// for array literals).
2705

    
2706
pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
2707
  var elts = [], first = true;
2708
  while (!this.eat(close)) {
2709
    if (!first) {
2710
      this.expect(types.comma);
2711
      if (allowTrailingComma && this.afterTrailingComma(close)) { break }
2712
    } else { first = false; }
2713

    
2714
    var elt = (void 0);
2715
    if (allowEmpty && this.type === types.comma)
2716
      { elt = null; }
2717
    else if (this.type === types.ellipsis) {
2718
      elt = this.parseSpread(refDestructuringErrors);
2719
      if (refDestructuringErrors && this.type === types.comma && refDestructuringErrors.trailingComma < 0)
2720
        { refDestructuringErrors.trailingComma = this.start; }
2721
    } else {
2722
      elt = this.parseMaybeAssign(false, refDestructuringErrors);
2723
    }
2724
    elts.push(elt);
2725
  }
2726
  return elts
2727
};
2728

    
2729
pp$3.checkUnreserved = function(ref) {
2730
  var start = ref.start;
2731
  var end = ref.end;
2732
  var name = ref.name;
2733

    
2734
  if (this.inGenerator && name === "yield")
2735
    { this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); }
2736
  if (this.inAsync && name === "await")
2737
    { this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); }
2738
  if (this.keywords.test(name))
2739
    { this.raise(start, ("Unexpected keyword '" + name + "'")); }
2740
  if (this.options.ecmaVersion < 6 &&
2741
    this.input.slice(start, end).indexOf("\\") !== -1) { return }
2742
  var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
2743
  if (re.test(name)) {
2744
    if (!this.inAsync && name === "await")
2745
      { this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); }
2746
    this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
2747
  }
2748
};
2749

    
2750
// Parse the next token as an identifier. If `liberal` is true (used
2751
// when parsing properties), it will also convert keywords into
2752
// identifiers.
2753

    
2754
pp$3.parseIdent = function(liberal, isBinding) {
2755
  var node = this.startNode();
2756
  if (this.type === types.name) {
2757
    node.name = this.value;
2758
  } else if (this.type.keyword) {
2759
    node.name = this.type.keyword;
2760

    
2761
    // To fix https://github.com/acornjs/acorn/issues/575
2762
    // `class` and `function` keywords push new context into this.context.
2763
    // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
2764
    // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
2765
    if ((node.name === "class" || node.name === "function") &&
2766
        (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
2767
      this.context.pop();
2768
    }
2769
  } else {
2770
    this.unexpected();
2771
  }
2772
  this.next();
2773
  this.finishNode(node, "Identifier");
2774
  if (!liberal) {
2775
    this.checkUnreserved(node);
2776
    if (node.name === "await" && !this.awaitIdentPos)
2777
      { this.awaitIdentPos = node.start; }
2778
  }
2779
  return node
2780
};
2781

    
2782
// Parses yield expression inside generator.
2783

    
2784
pp$3.parseYield = function(noIn) {
2785
  if (!this.yieldPos) { this.yieldPos = this.start; }
2786

    
2787
  var node = this.startNode();
2788
  this.next();
2789
  if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) {
2790
    node.delegate = false;
2791
    node.argument = null;
2792
  } else {
2793
    node.delegate = this.eat(types.star);
2794
    node.argument = this.parseMaybeAssign(noIn);
2795
  }
2796
  return this.finishNode(node, "YieldExpression")
2797
};
2798

    
2799
pp$3.parseAwait = function() {
2800
  if (!this.awaitPos) { this.awaitPos = this.start; }
2801

    
2802
  var node = this.startNode();
2803
  this.next();
2804
  node.argument = this.parseMaybeUnary(null, true);
2805
  return this.finishNode(node, "AwaitExpression")
2806
};
2807

    
2808
var pp$4 = Parser.prototype;
2809

    
2810
// This function is used to raise exceptions on parse errors. It
2811
// takes an offset integer (into the current `input`) to indicate
2812
// the location of the error, attaches the position to the end
2813
// of the error message, and then raises a `SyntaxError` with that
2814
// message.
2815

    
2816
pp$4.raise = function(pos, message) {
2817
  var loc = getLineInfo(this.input, pos);
2818
  message += " (" + loc.line + ":" + loc.column + ")";
2819
  var err = new SyntaxError(message);
2820
  err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
2821
  throw err
2822
};
2823

    
2824
pp$4.raiseRecoverable = pp$4.raise;
2825

    
2826
pp$4.curPosition = function() {
2827
  if (this.options.locations) {
2828
    return new Position(this.curLine, this.pos - this.lineStart)
2829
  }
2830
};
2831

    
2832
var pp$5 = Parser.prototype;
2833

    
2834
var Scope = function Scope(flags) {
2835
  this.flags = flags;
2836
  // A list of var-declared names in the current lexical scope
2837
  this.var = [];
2838
  // A list of lexically-declared names in the current lexical scope
2839
  this.lexical = [];
2840
  // A list of lexically-declared FunctionDeclaration names in the current lexical scope
2841
  this.functions = [];
2842
};
2843

    
2844
// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
2845

    
2846
pp$5.enterScope = function(flags) {
2847
  this.scopeStack.push(new Scope(flags));
2848
};
2849

    
2850
pp$5.exitScope = function() {
2851
  this.scopeStack.pop();
2852
};
2853

    
2854
// The spec says:
2855
// > At the top level of a function, or script, function declarations are
2856
// > treated like var declarations rather than like lexical declarations.
2857
pp$5.treatFunctionsAsVarInScope = function(scope) {
2858
  return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
2859
};
2860

    
2861
pp$5.declareName = function(name, bindingType, pos) {
2862
  var redeclared = false;
2863
  if (bindingType === BIND_LEXICAL) {
2864
    var scope = this.currentScope();
2865
    redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
2866
    scope.lexical.push(name);
2867
    if (this.inModule && (scope.flags & SCOPE_TOP))
2868
      { delete this.undefinedExports[name]; }
2869
  } else if (bindingType === BIND_SIMPLE_CATCH) {
2870
    var scope$1 = this.currentScope();
2871
    scope$1.lexical.push(name);
2872
  } else if (bindingType === BIND_FUNCTION) {
2873
    var scope$2 = this.currentScope();
2874
    if (this.treatFunctionsAsVar)
2875
      { redeclared = scope$2.lexical.indexOf(name) > -1; }
2876
    else
2877
      { redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
2878
    scope$2.functions.push(name);
2879
  } else {
2880
    for (var i = this.scopeStack.length - 1; i >= 0; --i) {
2881
      var scope$3 = this.scopeStack[i];
2882
      if (scope$3.lexical.indexOf(name) > -1 && !((scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) ||
2883
          !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
2884
        redeclared = true;
2885
        break
2886
      }
2887
      scope$3.var.push(name);
2888
      if (this.inModule && (scope$3.flags & SCOPE_TOP))
2889
        { delete this.undefinedExports[name]; }
2890
      if (scope$3.flags & SCOPE_VAR) { break }
2891
    }
2892
  }
2893
  if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); }
2894
};
2895

    
2896
pp$5.checkLocalExport = function(id) {
2897
  // scope.functions must be empty as Module code is always strict.
2898
  if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
2899
      this.scopeStack[0].var.indexOf(id.name) === -1) {
2900
    this.undefinedExports[id.name] = id;
2901
  }
2902
};
2903

    
2904
pp$5.currentScope = function() {
2905
  return this.scopeStack[this.scopeStack.length - 1]
2906
};
2907

    
2908
pp$5.currentVarScope = function() {
2909
  for (var i = this.scopeStack.length - 1;; i--) {
2910
    var scope = this.scopeStack[i];
2911
    if (scope.flags & SCOPE_VAR) { return scope }
2912
  }
2913
};
2914

    
2915
// Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
2916
pp$5.currentThisScope = function() {
2917
  for (var i = this.scopeStack.length - 1;; i--) {
2918
    var scope = this.scopeStack[i];
2919
    if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope }
2920
  }
2921
};
2922

    
2923
var Node = function Node(parser, pos, loc) {
2924
  this.type = "";
2925
  this.start = pos;
2926
  this.end = 0;
2927
  if (parser.options.locations)
2928
    { this.loc = new SourceLocation(parser, loc); }
2929
  if (parser.options.directSourceFile)
2930
    { this.sourceFile = parser.options.directSourceFile; }
2931
  if (parser.options.ranges)
2932
    { this.range = [pos, 0]; }
2933
};
2934

    
2935
// Start an AST node, attaching a start offset.
2936

    
2937
var pp$6 = Parser.prototype;
2938

    
2939
pp$6.startNode = function() {
2940
  return new Node(this, this.start, this.startLoc)
2941
};
2942

    
2943
pp$6.startNodeAt = function(pos, loc) {
2944
  return new Node(this, pos, loc)
2945
};
2946

    
2947
// Finish an AST node, adding `type` and `end` properties.
2948

    
2949
function finishNodeAt(node, type, pos, loc) {
2950
  node.type = type;
2951
  node.end = pos;
2952
  if (this.options.locations)
2953
    { node.loc.end = loc; }
2954
  if (this.options.ranges)
2955
    { node.range[1] = pos; }
2956
  return node
2957
}
2958

    
2959
pp$6.finishNode = function(node, type) {
2960
  return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
2961
};
2962

    
2963
// Finish node at given position
2964

    
2965
pp$6.finishNodeAt = function(node, type, pos, loc) {
2966
  return finishNodeAt.call(this, node, type, pos, loc)
2967
};
2968

    
2969
// The algorithm used to determine whether a regexp can appear at a
2970

    
2971
var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
2972
  this.token = token;
2973
  this.isExpr = !!isExpr;
2974
  this.preserveSpace = !!preserveSpace;
2975
  this.override = override;
2976
  this.generator = !!generator;
2977
};
2978

    
2979
var types$1 = {
2980
  b_stat: new TokContext("{", false),
2981
  b_expr: new TokContext("{", true),
2982
  b_tmpl: new TokContext("${", false),
2983
  p_stat: new TokContext("(", false),
2984
  p_expr: new TokContext("(", true),
2985
  q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
2986
  f_stat: new TokContext("function", false),
2987
  f_expr: new TokContext("function", true),
2988
  f_expr_gen: new TokContext("function", true, false, null, true),
2989
  f_gen: new TokContext("function", false, false, null, true)
2990
};
2991

    
2992
var pp$7 = Parser.prototype;
2993

    
2994
pp$7.initialContext = function() {
2995
  return [types$1.b_stat]
2996
};
2997

    
2998
pp$7.braceIsBlock = function(prevType) {
2999
  var parent = this.curContext();
3000
  if (parent === types$1.f_expr || parent === types$1.f_stat)
3001
    { return true }
3002
  if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
3003
    { return !parent.isExpr }
3004

    
3005
  // The check for `tt.name && exprAllowed` detects whether we are
3006
  // after a `yield` or `of` construct. See the `updateContext` for
3007
  // `tt.name`.
3008
  if (prevType === types._return || prevType === types.name && this.exprAllowed)
3009
    { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
3010
  if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow)
3011
    { return true }
3012
  if (prevType === types.braceL)
3013
    { return parent === types$1.b_stat }
3014
  if (prevType === types._var || prevType === types._const || prevType === types.name)
3015
    { return false }
3016
  return !this.exprAllowed
3017
};
3018

    
3019
pp$7.inGeneratorContext = function() {
3020
  for (var i = this.context.length - 1; i >= 1; i--) {
3021
    var context = this.context[i];
3022
    if (context.token === "function")
3023
      { return context.generator }
3024
  }
3025
  return false
3026
};
3027

    
3028
pp$7.updateContext = function(prevType) {
3029
  var update, type = this.type;
3030
  if (type.keyword && prevType === types.dot)
3031
    { this.exprAllowed = false; }
3032
  else if (update = type.updateContext)
3033
    { update.call(this, prevType); }
3034
  else
3035
    { this.exprAllowed = type.beforeExpr; }
3036
};
3037

    
3038
// Token-specific context update code
3039

    
3040
types.parenR.updateContext = types.braceR.updateContext = function() {
3041
  if (this.context.length === 1) {
3042
    this.exprAllowed = true;
3043
    return
3044
  }
3045
  var out = this.context.pop();
3046
  if (out === types$1.b_stat && this.curContext().token === "function") {
3047
    out = this.context.pop();
3048
  }
3049
  this.exprAllowed = !out.isExpr;
3050
};
3051

    
3052
types.braceL.updateContext = function(prevType) {
3053
  this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
3054
  this.exprAllowed = true;
3055
};
3056

    
3057
types.dollarBraceL.updateContext = function() {
3058
  this.context.push(types$1.b_tmpl);
3059
  this.exprAllowed = true;
3060
};
3061

    
3062
types.parenL.updateContext = function(prevType) {
3063
  var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
3064
  this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
3065
  this.exprAllowed = true;
3066
};
3067

    
3068
types.incDec.updateContext = function() {
3069
  // tokExprAllowed stays unchanged
3070
};
3071

    
3072
types._function.updateContext = types._class.updateContext = function(prevType) {
3073
  if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
3074
      !(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
3075
      !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
3076
    { this.context.push(types$1.f_expr); }
3077
  else
3078
    { this.context.push(types$1.f_stat); }
3079
  this.exprAllowed = false;
3080
};
3081

    
3082
types.backQuote.updateContext = function() {
3083
  if (this.curContext() === types$1.q_tmpl)
3084
    { this.context.pop(); }
3085
  else
3086
    { this.context.push(types$1.q_tmpl); }
3087
  this.exprAllowed = false;
3088
};
3089

    
3090
types.star.updateContext = function(prevType) {
3091
  if (prevType === types._function) {
3092
    var index = this.context.length - 1;
3093
    if (this.context[index] === types$1.f_expr)
3094
      { this.context[index] = types$1.f_expr_gen; }
3095
    else
3096
      { this.context[index] = types$1.f_gen; }
3097
  }
3098
  this.exprAllowed = true;
3099
};
3100

    
3101
types.name.updateContext = function(prevType) {
3102
  var allowed = false;
3103
  if (this.options.ecmaVersion >= 6 && prevType !== types.dot) {
3104
    if (this.value === "of" && !this.exprAllowed ||
3105
        this.value === "yield" && this.inGeneratorContext())
3106
      { allowed = true; }
3107
  }
3108
  this.exprAllowed = allowed;
3109
};
3110

    
3111
// This file contains Unicode properties extracted from the ECMAScript
3112
// specification. The lists are extracted like so:
3113
// $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText)
3114

    
3115
// #table-binary-unicode-properties
3116
var ecma9BinaryProperties = "ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS";
3117
var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
3118
var ecma11BinaryProperties = ecma10BinaryProperties;
3119
var unicodeBinaryProperties = {
3120
  9: ecma9BinaryProperties,
3121
  10: ecma10BinaryProperties,
3122
  11: ecma11BinaryProperties
3123
};
3124

    
3125
// #table-unicode-general-category-values
3126
var unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu";
3127

    
3128
// #table-unicode-script-values
3129
var ecma9ScriptValues = "Adlam Adlm Ahom Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb";
3130
var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd";
3131
var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
3132
var unicodeScriptValues = {
3133
  9: ecma9ScriptValues,
3134
  10: ecma10ScriptValues,
3135
  11: ecma11ScriptValues
3136
};
3137

    
3138
var data = {};
3139
function buildUnicodeData(ecmaVersion) {
3140
  var d = data[ecmaVersion] = {
3141
    binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues),
3142
    nonBinary: {
3143
      General_Category: wordsRegexp(unicodeGeneralCategoryValues),
3144
      Script: wordsRegexp(unicodeScriptValues[ecmaVersion])
3145
    }
3146
  };
3147
  d.nonBinary.Script_Extensions = d.nonBinary.Script;
3148

    
3149
  d.nonBinary.gc = d.nonBinary.General_Category;
3150
  d.nonBinary.sc = d.nonBinary.Script;
3151
  d.nonBinary.scx = d.nonBinary.Script_Extensions;
3152
}
3153
buildUnicodeData(9);
3154
buildUnicodeData(10);
3155
buildUnicodeData(11);
3156

    
3157
var pp$8 = Parser.prototype;
3158

    
3159
var RegExpValidationState = function RegExpValidationState(parser) {
3160
  this.parser = parser;
3161
  this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
3162
  this.unicodeProperties = data[parser.options.ecmaVersion >= 11 ? 11 : parser.options.ecmaVersion];
3163
  this.source = "";
3164
  this.flags = "";
3165
  this.start = 0;
3166
  this.switchU = false;
3167
  this.switchN = false;
3168
  this.pos = 0;
3169
  this.lastIntValue = 0;
3170
  this.lastStringValue = "";
3171
  this.lastAssertionIsQuantifiable = false;
3172
  this.numCapturingParens = 0;
3173
  this.maxBackReference = 0;
3174
  this.groupNames = [];
3175
  this.backReferenceNames = [];
3176
};
3177

    
3178
RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
3179
  var unicode = flags.indexOf("u") !== -1;
3180
  this.start = start | 0;
3181
  this.source = pattern + "";
3182
  this.flags = flags;
3183
  this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
3184
  this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
3185
};
3186

    
3187
RegExpValidationState.prototype.raise = function raise (message) {
3188
  this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
3189
};
3190

    
3191
// If u flag is given, this returns the code point at the index (it combines a surrogate pair).
3192
// Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
3193
RegExpValidationState.prototype.at = function at (i) {
3194
  var s = this.source;
3195
  var l = s.length;
3196
  if (i >= l) {
3197
    return -1
3198
  }
3199
  var c = s.charCodeAt(i);
3200
  if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
3201
    return c
3202
  }
3203
  var next = s.charCodeAt(i + 1);
3204
  return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c
3205
};
3206

    
3207
RegExpValidationState.prototype.nextIndex = function nextIndex (i) {
3208
  var s = this.source;
3209
  var l = s.length;
3210
  if (i >= l) {
3211
    return l
3212
  }
3213
  var c = s.charCodeAt(i), next;
3214
  if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
3215
      (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
3216
    return i + 1
3217
  }
3218
  return i + 2
3219
};
3220

    
3221
RegExpValidationState.prototype.current = function current () {
3222
  return this.at(this.pos)
3223
};
3224

    
3225
RegExpValidationState.prototype.lookahead = function lookahead () {
3226
  return this.at(this.nextIndex(this.pos))
3227
};
3228

    
3229
RegExpValidationState.prototype.advance = function advance () {
3230
  this.pos = this.nextIndex(this.pos);
3231
};
3232

    
3233
RegExpValidationState.prototype.eat = function eat (ch) {
3234
  if (this.current() === ch) {
3235
    this.advance();
3236
    return true
3237
  }
3238
  return false
3239
};
3240

    
3241
function codePointToString(ch) {
3242
  if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
3243
  ch -= 0x10000;
3244
  return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
3245
}
3246

    
3247
/**
3248
 * Validate the flags part of a given RegExpLiteral.
3249
 *
3250
 * @param {RegExpValidationState} state The state to validate RegExp.
3251
 * @returns {void}
3252
 */
3253
pp$8.validateRegExpFlags = function(state) {
3254
  var validFlags = state.validFlags;
3255
  var flags = state.flags;
3256

    
3257
  for (var i = 0; i < flags.length; i++) {
3258
    var flag = flags.charAt(i);
3259
    if (validFlags.indexOf(flag) === -1) {
3260
      this.raise(state.start, "Invalid regular expression flag");
3261
    }
3262
    if (flags.indexOf(flag, i + 1) > -1) {
3263
      this.raise(state.start, "Duplicate regular expression flag");
3264
    }
3265
  }
3266
};
3267

    
3268
/**
3269
 * Validate the pattern part of a given RegExpLiteral.
3270
 *
3271
 * @param {RegExpValidationState} state The state to validate RegExp.
3272
 * @returns {void}
3273
 */
3274
pp$8.validateRegExpPattern = function(state) {
3275
  this.regexp_pattern(state);
3276

    
3277
  // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
3278
  // parsing contains a |GroupName|, reparse with the goal symbol
3279
  // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
3280
  // exception if _P_ did not conform to the grammar, if any elements of _P_
3281
  // were not matched by the parse, or if any Early Error conditions exist.
3282
  if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
3283
    state.switchN = true;
3284
    this.regexp_pattern(state);
3285
  }
3286
};
3287

    
3288
// https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
3289
pp$8.regexp_pattern = function(state) {
3290
  state.pos = 0;
3291
  state.lastIntValue = 0;
3292
  state.lastStringValue = "";
3293
  state.lastAssertionIsQuantifiable = false;
3294
  state.numCapturingParens = 0;
3295
  state.maxBackReference = 0;
3296
  state.groupNames.length = 0;
3297
  state.backReferenceNames.length = 0;
3298

    
3299
  this.regexp_disjunction(state);
3300

    
3301
  if (state.pos !== state.source.length) {
3302
    // Make the same messages as V8.
3303
    if (state.eat(0x29 /* ) */)) {
3304
      state.raise("Unmatched ')'");
3305
    }
3306
    if (state.eat(0x5D /* [ */) || state.eat(0x7D /* } */)) {
3307
      state.raise("Lone quantifier brackets");
3308
    }
3309
  }
3310
  if (state.maxBackReference > state.numCapturingParens) {
3311
    state.raise("Invalid escape");
3312
  }
3313
  for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
3314
    var name = list[i];
3315

    
3316
    if (state.groupNames.indexOf(name) === -1) {
3317
      state.raise("Invalid named capture referenced");
3318
    }
3319
  }
3320
};
3321

    
3322
// https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
3323
pp$8.regexp_disjunction = function(state) {
3324
  this.regexp_alternative(state);
3325
  while (state.eat(0x7C /* | */)) {
3326
    this.regexp_alternative(state);
3327
  }
3328

    
3329
  // Make the same message as V8.
3330
  if (this.regexp_eatQuantifier(state, true)) {
3331
    state.raise("Nothing to repeat");
3332
  }
3333
  if (state.eat(0x7B /* { */)) {
3334
    state.raise("Lone quantifier brackets");
3335
  }
3336
};
3337

    
3338
// https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
3339
pp$8.regexp_alternative = function(state) {
3340
  while (state.pos < state.source.length && this.regexp_eatTerm(state))
3341
    { }
3342
};
3343

    
3344
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
3345
pp$8.regexp_eatTerm = function(state) {
3346
  if (this.regexp_eatAssertion(state)) {
3347
    // Handle `QuantifiableAssertion Quantifier` alternative.
3348
    // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
3349
    // is a QuantifiableAssertion.
3350
    if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
3351
      // Make the same message as V8.
3352
      if (state.switchU) {
3353
        state.raise("Invalid quantifier");
3354
      }
3355
    }
3356
    return true
3357
  }
3358

    
3359
  if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
3360
    this.regexp_eatQuantifier(state);
3361
    return true
3362
  }
3363

    
3364
  return false
3365
};
3366

    
3367
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
3368
pp$8.regexp_eatAssertion = function(state) {
3369
  var start = state.pos;
3370
  state.lastAssertionIsQuantifiable = false;
3371

    
3372
  // ^, $
3373
  if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
3374
    return true
3375
  }
3376

    
3377
  // \b \B
3378
  if (state.eat(0x5C /* \ */)) {
3379
    if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
3380
      return true
3381
    }
3382
    state.pos = start;
3383
  }
3384

    
3385
  // Lookahead / Lookbehind
3386
  if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
3387
    var lookbehind = false;
3388
    if (this.options.ecmaVersion >= 9) {
3389
      lookbehind = state.eat(0x3C /* < */);
3390
    }
3391
    if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
3392
      this.regexp_disjunction(state);
3393
      if (!state.eat(0x29 /* ) */)) {
3394
        state.raise("Unterminated group");
3395
      }
3396
      state.lastAssertionIsQuantifiable = !lookbehind;
3397
      return true
3398
    }
3399
  }
3400

    
3401
  state.pos = start;
3402
  return false
3403
};
3404

    
3405
// https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
3406
pp$8.regexp_eatQuantifier = function(state, noError) {
3407
  if ( noError === void 0 ) noError = false;
3408

    
3409
  if (this.regexp_eatQuantifierPrefix(state, noError)) {
3410
    state.eat(0x3F /* ? */);
3411
    return true
3412
  }
3413
  return false
3414
};
3415

    
3416
// https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
3417
pp$8.regexp_eatQuantifierPrefix = function(state, noError) {
3418
  return (
3419
    state.eat(0x2A /* * */) ||
3420
    state.eat(0x2B /* + */) ||
3421
    state.eat(0x3F /* ? */) ||
3422
    this.regexp_eatBracedQuantifier(state, noError)
3423
  )
3424
};
3425
pp$8.regexp_eatBracedQuantifier = function(state, noError) {
3426
  var start = state.pos;
3427
  if (state.eat(0x7B /* { */)) {
3428
    var min = 0, max = -1;
3429
    if (this.regexp_eatDecimalDigits(state)) {
3430
      min = state.lastIntValue;
3431
      if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
3432
        max = state.lastIntValue;
3433
      }
3434
      if (state.eat(0x7D /* } */)) {
3435
        // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
3436
        if (max !== -1 && max < min && !noError) {
3437
          state.raise("numbers out of order in {} quantifier");
3438
        }
3439
        return true
3440
      }
3441
    }
3442
    if (state.switchU && !noError) {
3443
      state.raise("Incomplete quantifier");
3444
    }
3445
    state.pos = start;
3446
  }
3447
  return false
3448
};
3449

    
3450
// https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
3451
pp$8.regexp_eatAtom = function(state) {
3452
  return (
3453
    this.regexp_eatPatternCharacters(state) ||
3454
    state.eat(0x2E /* . */) ||
3455
    this.regexp_eatReverseSolidusAtomEscape(state) ||
3456
    this.regexp_eatCharacterClass(state) ||
3457
    this.regexp_eatUncapturingGroup(state) ||
3458
    this.regexp_eatCapturingGroup(state)
3459
  )
3460
};
3461
pp$8.regexp_eatReverseSolidusAtomEscape = function(state) {
3462
  var start = state.pos;
3463
  if (state.eat(0x5C /* \ */)) {
3464
    if (this.regexp_eatAtomEscape(state)) {
3465
      return true
3466
    }
3467
    state.pos = start;
3468
  }
3469
  return false
3470
};
3471
pp$8.regexp_eatUncapturingGroup = function(state) {
3472
  var start = state.pos;
3473
  if (state.eat(0x28 /* ( */)) {
3474
    if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
3475
      this.regexp_disjunction(state);
3476
      if (state.eat(0x29 /* ) */)) {
3477
        return true
3478
      }
3479
      state.raise("Unterminated group");
3480
    }
3481
    state.pos = start;
3482
  }
3483
  return false
3484
};
3485
pp$8.regexp_eatCapturingGroup = function(state) {
3486
  if (state.eat(0x28 /* ( */)) {
3487
    if (this.options.ecmaVersion >= 9) {
3488
      this.regexp_groupSpecifier(state);
3489
    } else if (state.current() === 0x3F /* ? */) {
3490
      state.raise("Invalid group");
3491
    }
3492
    this.regexp_disjunction(state);
3493
    if (state.eat(0x29 /* ) */)) {
3494
      state.numCapturingParens += 1;
3495
      return true
3496
    }
3497
    state.raise("Unterminated group");
3498
  }
3499
  return false
3500
};
3501

    
3502
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
3503
pp$8.regexp_eatExtendedAtom = function(state) {
3504
  return (
3505
    state.eat(0x2E /* . */) ||
3506
    this.regexp_eatReverseSolidusAtomEscape(state) ||
3507
    this.regexp_eatCharacterClass(state) ||
3508
    this.regexp_eatUncapturingGroup(state) ||
3509
    this.regexp_eatCapturingGroup(state) ||
3510
    this.regexp_eatInvalidBracedQuantifier(state) ||
3511
    this.regexp_eatExtendedPatternCharacter(state)
3512
  )
3513
};
3514

    
3515
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
3516
pp$8.regexp_eatInvalidBracedQuantifier = function(state) {
3517
  if (this.regexp_eatBracedQuantifier(state, true)) {
3518
    state.raise("Nothing to repeat");
3519
  }
3520
  return false
3521
};
3522

    
3523
// https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
3524
pp$8.regexp_eatSyntaxCharacter = function(state) {
3525
  var ch = state.current();
3526
  if (isSyntaxCharacter(ch)) {
3527
    state.lastIntValue = ch;
3528
    state.advance();
3529
    return true
3530
  }
3531
  return false
3532
};
3533
function isSyntaxCharacter(ch) {
3534
  return (
3535
    ch === 0x24 /* $ */ ||
3536
    ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
3537
    ch === 0x2E /* . */ ||
3538
    ch === 0x3F /* ? */ ||
3539
    ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
3540
    ch >= 0x7B /* { */ && ch <= 0x7D /* } */
3541
  )
3542
}
3543

    
3544
// https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
3545
// But eat eager.
3546
pp$8.regexp_eatPatternCharacters = function(state) {
3547
  var start = state.pos;
3548
  var ch = 0;
3549
  while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
3550
    state.advance();
3551
  }
3552
  return state.pos !== start
3553
};
3554

    
3555
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
3556
pp$8.regexp_eatExtendedPatternCharacter = function(state) {
3557
  var ch = state.current();
3558
  if (
3559
    ch !== -1 &&
3560
    ch !== 0x24 /* $ */ &&
3561
    !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
3562
    ch !== 0x2E /* . */ &&
3563
    ch !== 0x3F /* ? */ &&
3564
    ch !== 0x5B /* [ */ &&
3565
    ch !== 0x5E /* ^ */ &&
3566
    ch !== 0x7C /* | */
3567
  ) {
3568
    state.advance();
3569
    return true
3570
  }
3571
  return false
3572
};
3573

    
3574
// GroupSpecifier[U] ::
3575
//   [empty]
3576
//   `?` GroupName[?U]
3577
pp$8.regexp_groupSpecifier = function(state) {
3578
  if (state.eat(0x3F /* ? */)) {
3579
    if (this.regexp_eatGroupName(state)) {
3580
      if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
3581
        state.raise("Duplicate capture group name");
3582
      }
3583
      state.groupNames.push(state.lastStringValue);
3584
      return
3585
    }
3586
    state.raise("Invalid group");
3587
  }
3588
};
3589

    
3590
// GroupName[U] ::
3591
//   `<` RegExpIdentifierName[?U] `>`
3592
// Note: this updates `state.lastStringValue` property with the eaten name.
3593
pp$8.regexp_eatGroupName = function(state) {
3594
  state.lastStringValue = "";
3595
  if (state.eat(0x3C /* < */)) {
3596
    if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
3597
      return true
3598
    }
3599
    state.raise("Invalid capture group name");
3600
  }
3601
  return false
3602
};
3603

    
3604
// RegExpIdentifierName[U] ::
3605
//   RegExpIdentifierStart[?U]
3606
//   RegExpIdentifierName[?U] RegExpIdentifierPart[?U]
3607
// Note: this updates `state.lastStringValue` property with the eaten name.
3608
pp$8.regexp_eatRegExpIdentifierName = function(state) {
3609
  state.lastStringValue = "";
3610
  if (this.regexp_eatRegExpIdentifierStart(state)) {
3611
    state.lastStringValue += codePointToString(state.lastIntValue);
3612
    while (this.regexp_eatRegExpIdentifierPart(state)) {
3613
      state.lastStringValue += codePointToString(state.lastIntValue);
3614
    }
3615
    return true
3616
  }
3617
  return false
3618
};
3619

    
3620
// RegExpIdentifierStart[U] ::
3621
//   UnicodeIDStart
3622
//   `$`
3623
//   `_`
3624
//   `\` RegExpUnicodeEscapeSequence[?U]
3625
pp$8.regexp_eatRegExpIdentifierStart = function(state) {
3626
  var start = state.pos;
3627
  var ch = state.current();
3628
  state.advance();
3629

    
3630
  if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
3631
    ch = state.lastIntValue;
3632
  }
3633
  if (isRegExpIdentifierStart(ch)) {
3634
    state.lastIntValue = ch;
3635
    return true
3636
  }
3637

    
3638
  state.pos = start;
3639
  return false
3640
};
3641
function isRegExpIdentifierStart(ch) {
3642
  return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
3643
}
3644

    
3645
// RegExpIdentifierPart[U] ::
3646
//   UnicodeIDContinue
3647
//   `$`
3648
//   `_`
3649
//   `\` RegExpUnicodeEscapeSequence[?U]
3650
//   <ZWNJ>
3651
//   <ZWJ>
3652
pp$8.regexp_eatRegExpIdentifierPart = function(state) {
3653
  var start = state.pos;
3654
  var ch = state.current();
3655
  state.advance();
3656

    
3657
  if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
3658
    ch = state.lastIntValue;
3659
  }
3660
  if (isRegExpIdentifierPart(ch)) {
3661
    state.lastIntValue = ch;
3662
    return true
3663
  }
3664

    
3665
  state.pos = start;
3666
  return false
3667
};
3668
function isRegExpIdentifierPart(ch) {
3669
  return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
3670
}
3671

    
3672
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
3673
pp$8.regexp_eatAtomEscape = function(state) {
3674
  if (
3675
    this.regexp_eatBackReference(state) ||
3676
    this.regexp_eatCharacterClassEscape(state) ||
3677
    this.regexp_eatCharacterEscape(state) ||
3678
    (state.switchN && this.regexp_eatKGroupName(state))
3679
  ) {
3680
    return true
3681
  }
3682
  if (state.switchU) {
3683
    // Make the same message as V8.
3684
    if (state.current() === 0x63 /* c */) {
3685
      state.raise("Invalid unicode escape");
3686
    }
3687
    state.raise("Invalid escape");
3688
  }
3689
  return false
3690
};
3691
pp$8.regexp_eatBackReference = function(state) {
3692
  var start = state.pos;
3693
  if (this.regexp_eatDecimalEscape(state)) {
3694
    var n = state.lastIntValue;
3695
    if (state.switchU) {
3696
      // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
3697
      if (n > state.maxBackReference) {
3698
        state.maxBackReference = n;
3699
      }
3700
      return true
3701
    }
3702
    if (n <= state.numCapturingParens) {
3703
      return true
3704
    }
3705
    state.pos = start;
3706
  }
3707
  return false
3708
};
3709
pp$8.regexp_eatKGroupName = function(state) {
3710
  if (state.eat(0x6B /* k */)) {
3711
    if (this.regexp_eatGroupName(state)) {
3712
      state.backReferenceNames.push(state.lastStringValue);
3713
      return true
3714
    }
3715
    state.raise("Invalid named reference");
3716
  }
3717
  return false
3718
};
3719

    
3720
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
3721
pp$8.regexp_eatCharacterEscape = function(state) {
3722
  return (
3723
    this.regexp_eatControlEscape(state) ||
3724
    this.regexp_eatCControlLetter(state) ||
3725
    this.regexp_eatZero(state) ||
3726
    this.regexp_eatHexEscapeSequence(state) ||
3727
    this.regexp_eatRegExpUnicodeEscapeSequence(state) ||
3728
    (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
3729
    this.regexp_eatIdentityEscape(state)
3730
  )
3731
};
3732
pp$8.regexp_eatCControlLetter = function(state) {
3733
  var start = state.pos;
3734
  if (state.eat(0x63 /* c */)) {
3735
    if (this.regexp_eatControlLetter(state)) {
3736
      return true
3737
    }
3738
    state.pos = start;
3739
  }
3740
  return false
3741
};
3742
pp$8.regexp_eatZero = function(state) {
3743
  if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
3744
    state.lastIntValue = 0;
3745
    state.advance();
3746
    return true
3747
  }
3748
  return false
3749
};
3750

    
3751
// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
3752
pp$8.regexp_eatControlEscape = function(state) {
3753
  var ch = state.current();
3754
  if (ch === 0x74 /* t */) {
3755
    state.lastIntValue = 0x09; /* \t */
3756
    state.advance();
3757
    return true
3758
  }
3759
  if (ch === 0x6E /* n */) {
3760
    state.lastIntValue = 0x0A; /* \n */
3761
    state.advance();
3762
    return true
3763
  }
3764
  if (ch === 0x76 /* v */) {
3765
    state.lastIntValue = 0x0B; /* \v */
3766
    state.advance();
3767
    return true
3768
  }
3769
  if (ch === 0x66 /* f */) {
3770
    state.lastIntValue = 0x0C; /* \f */
3771
    state.advance();
3772
    return true
3773
  }
3774
  if (ch === 0x72 /* r */) {
3775
    state.lastIntValue = 0x0D; /* \r */
3776
    state.advance();
3777
    return true
3778
  }
3779
  return false
3780
};
3781

    
3782
// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
3783
pp$8.regexp_eatControlLetter = function(state) {
3784
  var ch = state.current();
3785
  if (isControlLetter(ch)) {
3786
    state.lastIntValue = ch % 0x20;
3787
    state.advance();
3788
    return true
3789
  }
3790
  return false
3791
};
3792
function isControlLetter(ch) {
3793
  return (
3794
    (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
3795
    (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
3796
  )
3797
}
3798

    
3799
// https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
3800
pp$8.regexp_eatRegExpUnicodeEscapeSequence = function(state) {
3801
  var start = state.pos;
3802

    
3803
  if (state.eat(0x75 /* u */)) {
3804
    if (this.regexp_eatFixedHexDigits(state, 4)) {
3805
      var lead = state.lastIntValue;
3806
      if (state.switchU && lead >= 0xD800 && lead <= 0xDBFF) {
3807
        var leadSurrogateEnd = state.pos;
3808
        if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
3809
          var trail = state.lastIntValue;
3810
          if (trail >= 0xDC00 && trail <= 0xDFFF) {
3811
            state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
3812
            return true
3813
          }
3814
        }
3815
        state.pos = leadSurrogateEnd;
3816
        state.lastIntValue = lead;
3817
      }
3818
      return true
3819
    }
3820
    if (
3821
      state.switchU &&
3822
      state.eat(0x7B /* { */) &&
3823
      this.regexp_eatHexDigits(state) &&
3824
      state.eat(0x7D /* } */) &&
3825
      isValidUnicode(state.lastIntValue)
3826
    ) {
3827
      return true
3828
    }
3829
    if (state.switchU) {
3830
      state.raise("Invalid unicode escape");
3831
    }
3832
    state.pos = start;
3833
  }
3834

    
3835
  return false
3836
};
3837
function isValidUnicode(ch) {
3838
  return ch >= 0 && ch <= 0x10FFFF
3839
}
3840

    
3841
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
3842
pp$8.regexp_eatIdentityEscape = function(state) {
3843
  if (state.switchU) {
3844
    if (this.regexp_eatSyntaxCharacter(state)) {
3845
      return true
3846
    }
3847
    if (state.eat(0x2F /* / */)) {
3848
      state.lastIntValue = 0x2F; /* / */
3849
      return true
3850
    }
3851
    return false
3852
  }
3853

    
3854
  var ch = state.current();
3855
  if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
3856
    state.lastIntValue = ch;
3857
    state.advance();
3858
    return true
3859
  }
3860

    
3861
  return false
3862
};
3863

    
3864
// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
3865
pp$8.regexp_eatDecimalEscape = function(state) {
3866
  state.lastIntValue = 0;
3867
  var ch = state.current();
3868
  if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
3869
    do {
3870
      state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
3871
      state.advance();
3872
    } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
3873
    return true
3874
  }
3875
  return false
3876
};
3877

    
3878
// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
3879
pp$8.regexp_eatCharacterClassEscape = function(state) {
3880
  var ch = state.current();
3881

    
3882
  if (isCharacterClassEscape(ch)) {
3883
    state.lastIntValue = -1;
3884
    state.advance();
3885
    return true
3886
  }
3887

    
3888
  if (
3889
    state.switchU &&
3890
    this.options.ecmaVersion >= 9 &&
3891
    (ch === 0x50 /* P */ || ch === 0x70 /* p */)
3892
  ) {
3893
    state.lastIntValue = -1;
3894
    state.advance();
3895
    if (
3896
      state.eat(0x7B /* { */) &&
3897
      this.regexp_eatUnicodePropertyValueExpression(state) &&
3898
      state.eat(0x7D /* } */)
3899
    ) {
3900
      return true
3901
    }
3902
    state.raise("Invalid property name");
3903
  }
3904

    
3905
  return false
3906
};
3907
function isCharacterClassEscape(ch) {
3908
  return (
3909
    ch === 0x64 /* d */ ||
3910
    ch === 0x44 /* D */ ||
3911
    ch === 0x73 /* s */ ||
3912
    ch === 0x53 /* S */ ||
3913
    ch === 0x77 /* w */ ||
3914
    ch === 0x57 /* W */
3915
  )
3916
}
3917

    
3918
// UnicodePropertyValueExpression ::
3919
//   UnicodePropertyName `=` UnicodePropertyValue
3920
//   LoneUnicodePropertyNameOrValue
3921
pp$8.regexp_eatUnicodePropertyValueExpression = function(state) {
3922
  var start = state.pos;
3923

    
3924
  // UnicodePropertyName `=` UnicodePropertyValue
3925
  if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
3926
    var name = state.lastStringValue;
3927
    if (this.regexp_eatUnicodePropertyValue(state)) {
3928
      var value = state.lastStringValue;
3929
      this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
3930
      return true
3931
    }
3932
  }
3933
  state.pos = start;
3934

    
3935
  // LoneUnicodePropertyNameOrValue
3936
  if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
3937
    var nameOrValue = state.lastStringValue;
3938
    this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
3939
    return true
3940
  }
3941
  return false
3942
};
3943
pp$8.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
3944
  if (!has(state.unicodeProperties.nonBinary, name))
3945
    { state.raise("Invalid property name"); }
3946
  if (!state.unicodeProperties.nonBinary[name].test(value))
3947
    { state.raise("Invalid property value"); }
3948
};
3949
pp$8.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
3950
  if (!state.unicodeProperties.binary.test(nameOrValue))
3951
    { state.raise("Invalid property name"); }
3952
};
3953

    
3954
// UnicodePropertyName ::
3955
//   UnicodePropertyNameCharacters
3956
pp$8.regexp_eatUnicodePropertyName = function(state) {
3957
  var ch = 0;
3958
  state.lastStringValue = "";
3959
  while (isUnicodePropertyNameCharacter(ch = state.current())) {
3960
    state.lastStringValue += codePointToString(ch);
3961
    state.advance();
3962
  }
3963
  return state.lastStringValue !== ""
3964
};
3965
function isUnicodePropertyNameCharacter(ch) {
3966
  return isControlLetter(ch) || ch === 0x5F /* _ */
3967
}
3968

    
3969
// UnicodePropertyValue ::
3970
//   UnicodePropertyValueCharacters
3971
pp$8.regexp_eatUnicodePropertyValue = function(state) {
3972
  var ch = 0;
3973
  state.lastStringValue = "";
3974
  while (isUnicodePropertyValueCharacter(ch = state.current())) {
3975
    state.lastStringValue += codePointToString(ch);
3976
    state.advance();
3977
  }
3978
  return state.lastStringValue !== ""
3979
};
3980
function isUnicodePropertyValueCharacter(ch) {
3981
  return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
3982
}
3983

    
3984
// LoneUnicodePropertyNameOrValue ::
3985
//   UnicodePropertyValueCharacters
3986
pp$8.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
3987
  return this.regexp_eatUnicodePropertyValue(state)
3988
};
3989

    
3990
// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
3991
pp$8.regexp_eatCharacterClass = function(state) {
3992
  if (state.eat(0x5B /* [ */)) {
3993
    state.eat(0x5E /* ^ */);
3994
    this.regexp_classRanges(state);
3995
    if (state.eat(0x5D /* [ */)) {
3996
      return true
3997
    }
3998
    // Unreachable since it threw "unterminated regular expression" error before.
3999
    state.raise("Unterminated character class");
4000
  }
4001
  return false
4002
};
4003

    
4004
// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
4005
// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
4006
// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
4007
pp$8.regexp_classRanges = function(state) {
4008
  while (this.regexp_eatClassAtom(state)) {
4009
    var left = state.lastIntValue;
4010
    if (state.eat(0x2D /* - */) && this.regexp_eatClassAtom(state)) {
4011
      var right = state.lastIntValue;
4012
      if (state.switchU && (left === -1 || right === -1)) {
4013
        state.raise("Invalid character class");
4014
      }
4015
      if (left !== -1 && right !== -1 && left > right) {
4016
        state.raise("Range out of order in character class");
4017
      }
4018
    }
4019
  }
4020
};
4021

    
4022
// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
4023
// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
4024
pp$8.regexp_eatClassAtom = function(state) {
4025
  var start = state.pos;
4026

    
4027
  if (state.eat(0x5C /* \ */)) {
4028
    if (this.regexp_eatClassEscape(state)) {
4029
      return true
4030
    }
4031
    if (state.switchU) {
4032
      // Make the same message as V8.
4033
      var ch$1 = state.current();
4034
      if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
4035
        state.raise("Invalid class escape");
4036
      }
4037
      state.raise("Invalid escape");
4038
    }
4039
    state.pos = start;
4040
  }
4041

    
4042
  var ch = state.current();
4043
  if (ch !== 0x5D /* [ */) {
4044
    state.lastIntValue = ch;
4045
    state.advance();
4046
    return true
4047
  }
4048

    
4049
  return false
4050
};
4051

    
4052
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
4053
pp$8.regexp_eatClassEscape = function(state) {
4054
  var start = state.pos;
4055

    
4056
  if (state.eat(0x62 /* b */)) {
4057
    state.lastIntValue = 0x08; /* <BS> */
4058
    return true
4059
  }
4060

    
4061
  if (state.switchU && state.eat(0x2D /* - */)) {
4062
    state.lastIntValue = 0x2D; /* - */
4063
    return true
4064
  }
4065

    
4066
  if (!state.switchU && state.eat(0x63 /* c */)) {
4067
    if (this.regexp_eatClassControlLetter(state)) {
4068
      return true
4069
    }
4070
    state.pos = start;
4071
  }
4072

    
4073
  return (
4074
    this.regexp_eatCharacterClassEscape(state) ||
4075
    this.regexp_eatCharacterEscape(state)
4076
  )
4077
};
4078

    
4079
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
4080
pp$8.regexp_eatClassControlLetter = function(state) {
4081
  var ch = state.current();
4082
  if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
4083
    state.lastIntValue = ch % 0x20;
4084
    state.advance();
4085
    return true
4086
  }
4087
  return false
4088
};
4089

    
4090
// https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
4091
pp$8.regexp_eatHexEscapeSequence = function(state) {
4092
  var start = state.pos;
4093
  if (state.eat(0x78 /* x */)) {
4094
    if (this.regexp_eatFixedHexDigits(state, 2)) {
4095
      return true
4096
    }
4097
    if (state.switchU) {
4098
      state.raise("Invalid escape");
4099
    }
4100
    state.pos = start;
4101
  }
4102
  return false
4103
};
4104

    
4105
// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
4106
pp$8.regexp_eatDecimalDigits = function(state) {
4107
  var start = state.pos;
4108
  var ch = 0;
4109
  state.lastIntValue = 0;
4110
  while (isDecimalDigit(ch = state.current())) {
4111
    state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
4112
    state.advance();
4113
  }
4114
  return state.pos !== start
4115
};
4116
function isDecimalDigit(ch) {
4117
  return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
4118
}
4119

    
4120
// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
4121
pp$8.regexp_eatHexDigits = function(state) {
4122
  var start = state.pos;
4123
  var ch = 0;
4124
  state.lastIntValue = 0;
4125
  while (isHexDigit(ch = state.current())) {
4126
    state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
4127
    state.advance();
4128
  }
4129
  return state.pos !== start
4130
};
4131
function isHexDigit(ch) {
4132
  return (
4133
    (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
4134
    (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
4135
    (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
4136
  )
4137
}
4138
function hexToInt(ch) {
4139
  if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
4140
    return 10 + (ch - 0x41 /* A */)
4141
  }
4142
  if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
4143
    return 10 + (ch - 0x61 /* a */)
4144
  }
4145
  return ch - 0x30 /* 0 */
4146
}
4147

    
4148
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
4149
// Allows only 0-377(octal) i.e. 0-255(decimal).
4150
pp$8.regexp_eatLegacyOctalEscapeSequence = function(state) {
4151
  if (this.regexp_eatOctalDigit(state)) {
4152
    var n1 = state.lastIntValue;
4153
    if (this.regexp_eatOctalDigit(state)) {
4154
      var n2 = state.lastIntValue;
4155
      if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
4156
        state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
4157
      } else {
4158
        state.lastIntValue = n1 * 8 + n2;
4159
      }
4160
    } else {
4161
      state.lastIntValue = n1;
4162
    }
4163
    return true
4164
  }
4165
  return false
4166
};
4167

    
4168
// https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
4169
pp$8.regexp_eatOctalDigit = function(state) {
4170
  var ch = state.current();
4171
  if (isOctalDigit(ch)) {
4172
    state.lastIntValue = ch - 0x30; /* 0 */
4173
    state.advance();
4174
    return true
4175
  }
4176
  state.lastIntValue = 0;
4177
  return false
4178
};
4179
function isOctalDigit(ch) {
4180
  return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
4181
}
4182

    
4183
// https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
4184
// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
4185
// And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
4186
pp$8.regexp_eatFixedHexDigits = function(state, length) {
4187
  var start = state.pos;
4188
  state.lastIntValue = 0;
4189
  for (var i = 0; i < length; ++i) {
4190
    var ch = state.current();
4191
    if (!isHexDigit(ch)) {
4192
      state.pos = start;
4193
      return false
4194
    }
4195
    state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
4196
    state.advance();
4197
  }
4198
  return true
4199
};
4200

    
4201
// Object type used to represent tokens. Note that normally, tokens
4202
// simply exist as properties on the parser object. This is only
4203
// used for the onToken callback and the external tokenizer.
4204

    
4205
var Token = function Token(p) {
4206
  this.type = p.type;
4207
  this.value = p.value;
4208
  this.start = p.start;
4209
  this.end = p.end;
4210
  if (p.options.locations)
4211
    { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
4212
  if (p.options.ranges)
4213
    { this.range = [p.start, p.end]; }
4214
};
4215

    
4216
// ## Tokenizer
4217

    
4218
var pp$9 = Parser.prototype;
4219

    
4220
// Move to the next token
4221

    
4222
pp$9.next = function() {
4223
  if (this.options.onToken)
4224
    { this.options.onToken(new Token(this)); }
4225

    
4226
  this.lastTokEnd = this.end;
4227
  this.lastTokStart = this.start;
4228
  this.lastTokEndLoc = this.endLoc;
4229
  this.lastTokStartLoc = this.startLoc;
4230
  this.nextToken();
4231
};
4232

    
4233
pp$9.getToken = function() {
4234
  this.next();
4235
  return new Token(this)
4236
};
4237

    
4238
// If we're in an ES6 environment, make parsers iterable
4239
if (typeof Symbol !== "undefined")
4240
  { pp$9[Symbol.iterator] = function() {
4241
    var this$1 = this;
4242

    
4243
    return {
4244
      next: function () {
4245
        var token = this$1.getToken();
4246
        return {
4247
          done: token.type === types.eof,
4248
          value: token
4249
        }
4250
      }
4251
    }
4252
  }; }
4253

    
4254
// Toggle strict mode. Re-reads the next number or string to please
4255
// pedantic tests (`"use strict"; 010;` should fail).
4256

    
4257
pp$9.curContext = function() {
4258
  return this.context[this.context.length - 1]
4259
};
4260

    
4261
// Read a single token, updating the parser object's token-related
4262
// properties.
4263

    
4264
pp$9.nextToken = function() {
4265
  var curContext = this.curContext();
4266
  if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
4267

    
4268
  this.start = this.pos;
4269
  if (this.options.locations) { this.startLoc = this.curPosition(); }
4270
  if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
4271

    
4272
  if (curContext.override) { return curContext.override(this) }
4273
  else { this.readToken(this.fullCharCodeAtPos()); }
4274
};
4275

    
4276
pp$9.readToken = function(code) {
4277
  // Identifier or keyword. '\uXXXX' sequences are allowed in
4278
  // identifiers, so '\' also dispatches to that.
4279
  if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
4280
    { return this.readWord() }
4281

    
4282
  return this.getTokenFromCode(code)
4283
};
4284

    
4285
pp$9.fullCharCodeAtPos = function() {
4286
  var code = this.input.charCodeAt(this.pos);
4287
  if (code <= 0xd7ff || code >= 0xe000) { return code }
4288
  var next = this.input.charCodeAt(this.pos + 1);
4289
  return (code << 10) + next - 0x35fdc00
4290
};
4291

    
4292
pp$9.skipBlockComment = function() {
4293
  var startLoc = this.options.onComment && this.curPosition();
4294
  var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
4295
  if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
4296
  this.pos = end + 2;
4297
  if (this.options.locations) {
4298
    lineBreakG.lastIndex = start;
4299
    var match;
4300
    while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
4301
      ++this.curLine;
4302
      this.lineStart = match.index + match[0].length;
4303
    }
4304
  }
4305
  if (this.options.onComment)
4306
    { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
4307
                           startLoc, this.curPosition()); }
4308
};
4309

    
4310
pp$9.skipLineComment = function(startSkip) {
4311
  var start = this.pos;
4312
  var startLoc = this.options.onComment && this.curPosition();
4313
  var ch = this.input.charCodeAt(this.pos += startSkip);
4314
  while (this.pos < this.input.length && !isNewLine(ch)) {
4315
    ch = this.input.charCodeAt(++this.pos);
4316
  }
4317
  if (this.options.onComment)
4318
    { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
4319
                           startLoc, this.curPosition()); }
4320
};
4321

    
4322
// Called at the start of the parse and after every token. Skips
4323
// whitespace and comments, and.
4324

    
4325
pp$9.skipSpace = function() {
4326
  loop: while (this.pos < this.input.length) {
4327
    var ch = this.input.charCodeAt(this.pos);
4328
    switch (ch) {
4329
    case 32: case 160: // ' '
4330
      ++this.pos;
4331
      break
4332
    case 13:
4333
      if (this.input.charCodeAt(this.pos + 1) === 10) {
4334
        ++this.pos;
4335
      }
4336
    case 10: case 8232: case 8233:
4337
      ++this.pos;
4338
      if (this.options.locations) {
4339
        ++this.curLine;
4340
        this.lineStart = this.pos;
4341
      }
4342
      break
4343
    case 47: // '/'
4344
      switch (this.input.charCodeAt(this.pos + 1)) {
4345
      case 42: // '*'
4346
        this.skipBlockComment();
4347
        break
4348
      case 47:
4349
        this.skipLineComment(2);
4350
        break
4351
      default:
4352
        break loop
4353
      }
4354
      break
4355
    default:
4356
      if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
4357
        ++this.pos;
4358
      } else {
4359
        break loop
4360
      }
4361
    }
4362
  }
4363
};
4364

    
4365
// Called at the end of every token. Sets `end`, `val`, and
4366
// maintains `context` and `exprAllowed`, and skips the space after
4367
// the token, so that the next one's `start` will point at the
4368
// right position.
4369

    
4370
pp$9.finishToken = function(type, val) {
4371
  this.end = this.pos;
4372
  if (this.options.locations) { this.endLoc = this.curPosition(); }
4373
  var prevType = this.type;
4374
  this.type = type;
4375
  this.value = val;
4376

    
4377
  this.updateContext(prevType);
4378
};
4379

    
4380
// ### Token reading
4381

    
4382
// This is the function that is called to fetch the next token. It
4383
// is somewhat obscure, because it works in character codes rather
4384
// than characters, and because operator parsing has been inlined
4385
// into it.
4386
//
4387
// All in the name of speed.
4388
//
4389
pp$9.readToken_dot = function() {
4390
  var next = this.input.charCodeAt(this.pos + 1);
4391
  if (next >= 48 && next <= 57) { return this.readNumber(true) }
4392
  var next2 = this.input.charCodeAt(this.pos + 2);
4393
  if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
4394
    this.pos += 3;
4395
    return this.finishToken(types.ellipsis)
4396
  } else {
4397
    ++this.pos;
4398
    return this.finishToken(types.dot)
4399
  }
4400
};
4401

    
4402
pp$9.readToken_slash = function() { // '/'
4403
  var next = this.input.charCodeAt(this.pos + 1);
4404
  if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
4405
  if (next === 61) { return this.finishOp(types.assign, 2) }
4406
  return this.finishOp(types.slash, 1)
4407
};
4408

    
4409
pp$9.readToken_mult_modulo_exp = function(code) { // '%*'
4410
  var next = this.input.charCodeAt(this.pos + 1);
4411
  var size = 1;
4412
  var tokentype = code === 42 ? types.star : types.modulo;
4413

    
4414
  // exponentiation operator ** and **=
4415
  if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
4416
    ++size;
4417
    tokentype = types.starstar;
4418
    next = this.input.charCodeAt(this.pos + 2);
4419
  }
4420

    
4421
  if (next === 61) { return this.finishOp(types.assign, size + 1) }
4422
  return this.finishOp(tokentype, size)
4423
};
4424

    
4425
pp$9.readToken_pipe_amp = function(code) { // '|&'
4426
  var next = this.input.charCodeAt(this.pos + 1);
4427
  if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
4428
  if (next === 61) { return this.finishOp(types.assign, 2) }
4429
  return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
4430
};
4431

    
4432
pp$9.readToken_caret = function() { // '^'
4433
  var next = this.input.charCodeAt(this.pos + 1);
4434
  if (next === 61) { return this.finishOp(types.assign, 2) }
4435
  return this.finishOp(types.bitwiseXOR, 1)
4436
};
4437

    
4438
pp$9.readToken_plus_min = function(code) { // '+-'
4439
  var next = this.input.charCodeAt(this.pos + 1);
4440
  if (next === code) {
4441
    if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
4442
        (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
4443
      // A `-->` line comment
4444
      this.skipLineComment(3);
4445
      this.skipSpace();
4446
      return this.nextToken()
4447
    }
4448
    return this.finishOp(types.incDec, 2)
4449
  }
4450
  if (next === 61) { return this.finishOp(types.assign, 2) }
4451
  return this.finishOp(types.plusMin, 1)
4452
};
4453

    
4454
pp$9.readToken_lt_gt = function(code) { // '<>'
4455
  var next = this.input.charCodeAt(this.pos + 1);
4456
  var size = 1;
4457
  if (next === code) {
4458
    size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
4459
    if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
4460
    return this.finishOp(types.bitShift, size)
4461
  }
4462
  if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
4463
      this.input.charCodeAt(this.pos + 3) === 45) {
4464
    // `<!--`, an XML-style comment that should be interpreted as a line comment
4465
    this.skipLineComment(4);
4466
    this.skipSpace();
4467
    return this.nextToken()
4468
  }
4469
  if (next === 61) { size = 2; }
4470
  return this.finishOp(types.relational, size)
4471
};
4472

    
4473
pp$9.readToken_eq_excl = function(code) { // '=!'
4474
  var next = this.input.charCodeAt(this.pos + 1);
4475
  if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
4476
  if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
4477
    this.pos += 2;
4478
    return this.finishToken(types.arrow)
4479
  }
4480
  return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
4481
};
4482

    
4483
pp$9.getTokenFromCode = function(code) {
4484
  switch (code) {
4485
  // The interpretation of a dot depends on whether it is followed
4486
  // by a digit or another two dots.
4487
  case 46: // '.'
4488
    return this.readToken_dot()
4489

    
4490
  // Punctuation tokens.
4491
  case 40: ++this.pos; return this.finishToken(types.parenL)
4492
  case 41: ++this.pos; return this.finishToken(types.parenR)
4493
  case 59: ++this.pos; return this.finishToken(types.semi)
4494
  case 44: ++this.pos; return this.finishToken(types.comma)
4495
  case 91: ++this.pos; return this.finishToken(types.bracketL)
4496
  case 93: ++this.pos; return this.finishToken(types.bracketR)
4497
  case 123: ++this.pos; return this.finishToken(types.braceL)
4498
  case 125: ++this.pos; return this.finishToken(types.braceR)
4499
  case 58: ++this.pos; return this.finishToken(types.colon)
4500
  case 63: ++this.pos; return this.finishToken(types.question)
4501

    
4502
  case 96: // '`'
4503
    if (this.options.ecmaVersion < 6) { break }
4504
    ++this.pos;
4505
    return this.finishToken(types.backQuote)
4506

    
4507
  case 48: // '0'
4508
    var next = this.input.charCodeAt(this.pos + 1);
4509
    if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
4510
    if (this.options.ecmaVersion >= 6) {
4511
      if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
4512
      if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
4513
    }
4514

    
4515
  // Anything else beginning with a digit is an integer, octal
4516
  // number, or float.
4517
  case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
4518
    return this.readNumber(false)
4519

    
4520
  // Quotes produce strings.
4521
  case 34: case 39: // '"', "'"
4522
    return this.readString(code)
4523

    
4524
  // Operators are parsed inline in tiny state machines. '=' (61) is
4525
  // often referred to. `finishOp` simply skips the amount of
4526
  // characters it is given as second argument, and returns a token
4527
  // of the type given by its first argument.
4528

    
4529
  case 47: // '/'
4530
    return this.readToken_slash()
4531

    
4532
  case 37: case 42: // '%*'
4533
    return this.readToken_mult_modulo_exp(code)
4534

    
4535
  case 124: case 38: // '|&'
4536
    return this.readToken_pipe_amp(code)
4537

    
4538
  case 94: // '^'
4539
    return this.readToken_caret()
4540

    
4541
  case 43: case 45: // '+-'
4542
    return this.readToken_plus_min(code)
4543

    
4544
  case 60: case 62: // '<>'
4545
    return this.readToken_lt_gt(code)
4546

    
4547
  case 61: case 33: // '=!'
4548
    return this.readToken_eq_excl(code)
4549

    
4550
  case 126: // '~'
4551
    return this.finishOp(types.prefix, 1)
4552
  }
4553

    
4554
  this.raise(this.pos, "Unexpected character '" + codePointToString$1(code) + "'");
4555
};
4556

    
4557
pp$9.finishOp = function(type, size) {
4558
  var str = this.input.slice(this.pos, this.pos + size);
4559
  this.pos += size;
4560
  return this.finishToken(type, str)
4561
};
4562

    
4563
pp$9.readRegexp = function() {
4564
  var escaped, inClass, start = this.pos;
4565
  for (;;) {
4566
    if (this.pos >= this.input.length) { this.raise(start, "Unterminated regular expression"); }
4567
    var ch = this.input.charAt(this.pos);
4568
    if (lineBreak.test(ch)) { this.raise(start, "Unterminated regular expression"); }
4569
    if (!escaped) {
4570
      if (ch === "[") { inClass = true; }
4571
      else if (ch === "]" && inClass) { inClass = false; }
4572
      else if (ch === "/" && !inClass) { break }
4573
      escaped = ch === "\\";
4574
    } else { escaped = false; }
4575
    ++this.pos;
4576
  }
4577
  var pattern = this.input.slice(start, this.pos);
4578
  ++this.pos;
4579
  var flagsStart = this.pos;
4580
  var flags = this.readWord1();
4581
  if (this.containsEsc) { this.unexpected(flagsStart); }
4582

    
4583
  // Validate pattern
4584
  var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
4585
  state.reset(start, pattern, flags);
4586
  this.validateRegExpFlags(state);
4587
  this.validateRegExpPattern(state);
4588

    
4589
  // Create Literal#value property value.
4590
  var value = null;
4591
  try {
4592
    value = new RegExp(pattern, flags);
4593
  } catch (e) {
4594
    // ESTree requires null if it failed to instantiate RegExp object.
4595
    // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
4596
  }
4597

    
4598
  return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
4599
};
4600

    
4601
// Read an integer in the given radix. Return null if zero digits
4602
// were read, the integer value otherwise. When `len` is given, this
4603
// will return `null` unless the integer has exactly `len` digits.
4604

    
4605
pp$9.readInt = function(radix, len) {
4606
  var start = this.pos, total = 0;
4607
  for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
4608
    var code = this.input.charCodeAt(this.pos), val = (void 0);
4609
    if (code >= 97) { val = code - 97 + 10; } // a
4610
    else if (code >= 65) { val = code - 65 + 10; } // A
4611
    else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
4612
    else { val = Infinity; }
4613
    if (val >= radix) { break }
4614
    ++this.pos;
4615
    total = total * radix + val;
4616
  }
4617
  if (this.pos === start || len != null && this.pos - start !== len) { return null }
4618

    
4619
  return total
4620
};
4621

    
4622
pp$9.readRadixNumber = function(radix) {
4623
  var start = this.pos;
4624
  this.pos += 2; // 0x
4625
  var val = this.readInt(radix);
4626
  if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
4627
  if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
4628
    val = typeof BigInt !== "undefined" ? BigInt(this.input.slice(start, this.pos)) : null;
4629
    ++this.pos;
4630
  } else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
4631
  return this.finishToken(types.num, val)
4632
};
4633

    
4634
// Read an integer, octal integer, or floating-point number.
4635

    
4636
pp$9.readNumber = function(startsWithDot) {
4637
  var start = this.pos;
4638
  if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
4639
  var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
4640
  if (octal && this.strict) { this.raise(start, "Invalid number"); }
4641
  if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
4642
  var next = this.input.charCodeAt(this.pos);
4643
  if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
4644
    var str$1 = this.input.slice(start, this.pos);
4645
    var val$1 = typeof BigInt !== "undefined" ? BigInt(str$1) : null;
4646
    ++this.pos;
4647
    if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
4648
    return this.finishToken(types.num, val$1)
4649
  }
4650
  if (next === 46 && !octal) { // '.'
4651
    ++this.pos;
4652
    this.readInt(10);
4653
    next = this.input.charCodeAt(this.pos);
4654
  }
4655
  if ((next === 69 || next === 101) && !octal) { // 'eE'
4656
    next = this.input.charCodeAt(++this.pos);
4657
    if (next === 43 || next === 45) { ++this.pos; } // '+-'
4658
    if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
4659
  }
4660
  if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
4661

    
4662
  var str = this.input.slice(start, this.pos);
4663
  var val = octal ? parseInt(str, 8) : parseFloat(str);
4664
  return this.finishToken(types.num, val)
4665
};
4666

    
4667
// Read a string value, interpreting backslash-escapes.
4668

    
4669
pp$9.readCodePoint = function() {
4670
  var ch = this.input.charCodeAt(this.pos), code;
4671

    
4672
  if (ch === 123) { // '{'
4673
    if (this.options.ecmaVersion < 6) { this.unexpected(); }
4674
    var codePos = ++this.pos;
4675
    code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
4676
    ++this.pos;
4677
    if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
4678
  } else {
4679
    code = this.readHexChar(4);
4680
  }
4681
  return code
4682
};
4683

    
4684
function codePointToString$1(code) {
4685
  // UTF-16 Decoding
4686
  if (code <= 0xFFFF) { return String.fromCharCode(code) }
4687
  code -= 0x10000;
4688
  return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
4689
}
4690

    
4691
pp$9.readString = function(quote) {
4692
  var out = "", chunkStart = ++this.pos;
4693
  for (;;) {
4694
    if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated string constant"); }
4695
    var ch = this.input.charCodeAt(this.pos);
4696
    if (ch === quote) { break }
4697
    if (ch === 92) { // '\'
4698
      out += this.input.slice(chunkStart, this.pos);
4699
      out += this.readEscapedChar(false);
4700
      chunkStart = this.pos;
4701
    } else {
4702
      if (isNewLine(ch, this.options.ecmaVersion >= 10)) { this.raise(this.start, "Unterminated string constant"); }
4703
      ++this.pos;
4704
    }
4705
  }
4706
  out += this.input.slice(chunkStart, this.pos++);
4707
  return this.finishToken(types.string, out)
4708
};
4709

    
4710
// Reads template string tokens.
4711

    
4712
var INVALID_TEMPLATE_ESCAPE_ERROR = {};
4713

    
4714
pp$9.tryReadTemplateToken = function() {
4715
  this.inTemplateElement = true;
4716
  try {
4717
    this.readTmplToken();
4718
  } catch (err) {
4719
    if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
4720
      this.readInvalidTemplateToken();
4721
    } else {
4722
      throw err
4723
    }
4724
  }
4725

    
4726
  this.inTemplateElement = false;
4727
};
4728

    
4729
pp$9.invalidStringToken = function(position, message) {
4730
  if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
4731
    throw INVALID_TEMPLATE_ESCAPE_ERROR
4732
  } else {
4733
    this.raise(position, message);
4734
  }
4735
};
4736

    
4737
pp$9.readTmplToken = function() {
4738
  var out = "", chunkStart = this.pos;
4739
  for (;;) {
4740
    if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated template"); }
4741
    var ch = this.input.charCodeAt(this.pos);
4742
    if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) { // '`', '${'
4743
      if (this.pos === this.start && (this.type === types.template || this.type === types.invalidTemplate)) {
4744
        if (ch === 36) {
4745
          this.pos += 2;
4746
          return this.finishToken(types.dollarBraceL)
4747
        } else {
4748
          ++this.pos;
4749
          return this.finishToken(types.backQuote)
4750
        }
4751
      }
4752
      out += this.input.slice(chunkStart, this.pos);
4753
      return this.finishToken(types.template, out)
4754
    }
4755
    if (ch === 92) { // '\'
4756
      out += this.input.slice(chunkStart, this.pos);
4757
      out += this.readEscapedChar(true);
4758
      chunkStart = this.pos;
4759
    } else if (isNewLine(ch)) {
4760
      out += this.input.slice(chunkStart, this.pos);
4761
      ++this.pos;
4762
      switch (ch) {
4763
      case 13:
4764
        if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
4765
      case 10:
4766
        out += "\n";
4767
        break
4768
      default:
4769
        out += String.fromCharCode(ch);
4770
        break
4771
      }
4772
      if (this.options.locations) {
4773
        ++this.curLine;
4774
        this.lineStart = this.pos;
4775
      }
4776
      chunkStart = this.pos;
4777
    } else {
4778
      ++this.pos;
4779
    }
4780
  }
4781
};
4782

    
4783
// Reads a template token to search for the end, without validating any escape sequences
4784
pp$9.readInvalidTemplateToken = function() {
4785
  for (; this.pos < this.input.length; this.pos++) {
4786
    switch (this.input[this.pos]) {
4787
    case "\\":
4788
      ++this.pos;
4789
      break
4790

    
4791
    case "$":
4792
      if (this.input[this.pos + 1] !== "{") {
4793
        break
4794
      }
4795
    // falls through
4796

    
4797
    case "`":
4798
      return this.finishToken(types.invalidTemplate, this.input.slice(this.start, this.pos))
4799

    
4800
    // no default
4801
    }
4802
  }
4803
  this.raise(this.start, "Unterminated template");
4804
};
4805

    
4806
// Used to read escaped characters
4807

    
4808
pp$9.readEscapedChar = function(inTemplate) {
4809
  var ch = this.input.charCodeAt(++this.pos);
4810
  ++this.pos;
4811
  switch (ch) {
4812
  case 110: return "\n" // 'n' -> '\n'
4813
  case 114: return "\r" // 'r' -> '\r'
4814
  case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
4815
  case 117: return codePointToString$1(this.readCodePoint()) // 'u'
4816
  case 116: return "\t" // 't' -> '\t'
4817
  case 98: return "\b" // 'b' -> '\b'
4818
  case 118: return "\u000b" // 'v' -> '\u000b'
4819
  case 102: return "\f" // 'f' -> '\f'
4820
  case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
4821
  case 10: // ' \n'
4822
    if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
4823
    return ""
4824
  default:
4825
    if (ch >= 48 && ch <= 55) {
4826
      var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
4827
      var octal = parseInt(octalStr, 8);
4828
      if (octal > 255) {
4829
        octalStr = octalStr.slice(0, -1);
4830
        octal = parseInt(octalStr, 8);
4831
      }
4832
      this.pos += octalStr.length - 1;
4833
      ch = this.input.charCodeAt(this.pos);
4834
      if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
4835
        this.invalidStringToken(
4836
          this.pos - 1 - octalStr.length,
4837
          inTemplate
4838
            ? "Octal literal in template string"
4839
            : "Octal literal in strict mode"
4840
        );
4841
      }
4842
      return String.fromCharCode(octal)
4843
    }
4844
    if (isNewLine(ch)) {
4845
      // Unicode new line characters after \ get removed from output in both
4846
      // template literals and strings
4847
      return ""
4848
    }
4849
    return String.fromCharCode(ch)
4850
  }
4851
};
4852

    
4853
// Used to read character escape sequences ('\x', '\u', '\U').
4854

    
4855
pp$9.readHexChar = function(len) {
4856
  var codePos = this.pos;
4857
  var n = this.readInt(16, len);
4858
  if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
4859
  return n
4860
};
4861

    
4862
// Read an identifier, and return it as a string. Sets `this.containsEsc`
4863
// to whether the word contained a '\u' escape.
4864
//
4865
// Incrementally adds only escaped chars, adding other chunks as-is
4866
// as a micro-optimization.
4867

    
4868
pp$9.readWord1 = function() {
4869
  this.containsEsc = false;
4870
  var word = "", first = true, chunkStart = this.pos;
4871
  var astral = this.options.ecmaVersion >= 6;
4872
  while (this.pos < this.input.length) {
4873
    var ch = this.fullCharCodeAtPos();
4874
    if (isIdentifierChar(ch, astral)) {
4875
      this.pos += ch <= 0xffff ? 1 : 2;
4876
    } else if (ch === 92) { // "\"
4877
      this.containsEsc = true;
4878
      word += this.input.slice(chunkStart, this.pos);
4879
      var escStart = this.pos;
4880
      if (this.input.charCodeAt(++this.pos) !== 117) // "u"
4881
        { this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); }
4882
      ++this.pos;
4883
      var esc = this.readCodePoint();
4884
      if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
4885
        { this.invalidStringToken(escStart, "Invalid Unicode escape"); }
4886
      word += codePointToString$1(esc);
4887
      chunkStart = this.pos;
4888
    } else {
4889
      break
4890
    }
4891
    first = false;
4892
  }
4893
  return word + this.input.slice(chunkStart, this.pos)
4894
};
4895

    
4896
// Read an identifier or keyword token. Will check for reserved
4897
// words when necessary.
4898

    
4899
pp$9.readWord = function() {
4900
  var word = this.readWord1();
4901
  var type = types.name;
4902
  if (this.keywords.test(word)) {
4903
    if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
4904
    type = keywords$1[word];
4905
  }
4906
  return this.finishToken(type, word)
4907
};
4908

    
4909
// Acorn is a tiny, fast JavaScript parser written in JavaScript.
4910

    
4911
var version = "6.4.0";
4912

    
4913
Parser.acorn = {
4914
  Parser: Parser,
4915
  version: version,
4916
  defaultOptions: defaultOptions,
4917
  Position: Position,
4918
  SourceLocation: SourceLocation,
4919
  getLineInfo: getLineInfo,
4920
  Node: Node,
4921
  TokenType: TokenType,
4922
  tokTypes: types,
4923
  keywordTypes: keywords$1,
4924
  TokContext: TokContext,
4925
  tokContexts: types$1,
4926
  isIdentifierChar: isIdentifierChar,
4927
  isIdentifierStart: isIdentifierStart,
4928
  Token: Token,
4929
  isNewLine: isNewLine,
4930
  lineBreak: lineBreak,
4931
  lineBreakG: lineBreakG,
4932
  nonASCIIwhitespace: nonASCIIwhitespace
4933
};
4934

    
4935
// The main exported interface (under `self.acorn` when in the
4936
// browser) is a `parse` function that takes a code string and
4937
// returns an abstract syntax tree as specified by [Mozilla parser
4938
// API][api].
4939
//
4940
// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
4941

    
4942
function parse(input, options) {
4943
  return Parser.parse(input, options)
4944
}
4945

    
4946
// This function tries to parse a single expression at a given
4947
// offset in a string. Useful for parsing mixed-language formats
4948
// that embed JavaScript expressions.
4949

    
4950
function parseExpressionAt(input, pos, options) {
4951
  return Parser.parseExpressionAt(input, pos, options)
4952
}
4953

    
4954
// Acorn is organized as a tokenizer and a recursive-descent parser.
4955
// The `tokenizer` export provides an interface to the tokenizer.
4956

    
4957
function tokenizer(input, options) {
4958
  return Parser.tokenizer(input, options)
4959
}
4960

    
4961
export { Node, Parser, Position, SourceLocation, TokContext, Token, TokenType, defaultOptions, getLineInfo, isIdentifierChar, isIdentifierStart, isNewLine, keywords$1 as keywordTypes, lineBreak, lineBreakG, nonASCIIwhitespace, parse, parseExpressionAt, types$1 as tokContexts, types as tokTypes, tokenizer, version };
(4-4/6)