Projekt

Obecné

Profil

Stáhnout (188 KB) Statistiky
| Větev: | Revize:
1
(function (global, factory) {
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
  (global = global || self, factory(global.acorn = {}));
5
}(this, function (exports) { 'use strict';
6

    
7
  // Reserved word lists for various dialects of the language
8

    
9
  var reservedWords = {
10
    3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
11
    5: "class enum extends super const export import",
12
    6: "enum",
13
    strict: "implements interface let package private protected public static yield",
14
    strictBind: "eval arguments"
15
  };
16

    
17
  // And the keywords
18

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

    
21
  var keywords = {
22
    5: ecma5AndLessKeywords,
23
    "5module": ecma5AndLessKeywords + " export import",
24
    6: ecma5AndLessKeywords + " const class extends export import super"
25
  };
26

    
27
  var keywordRelationalOperator = /^in(stanceof)?$/;
28

    
29
  // ## Character categories
30

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

    
39
  var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
40
  var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
41

    
42
  nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
43

    
44
  // These are a run-length and offset encoded representation of the
45
  // >0xffff code points that are a valid part of identifiers. The
46
  // offset starts at 0x10000, and each pair of numbers represents an
47
  // offset to the next range, and then a size of the range. They were
48
  // generated by bin/generate-identifier-regex.js
49

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

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

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

    
69
  // Test whether a given character code starts an identifier.
70

    
71
  function isIdentifierStart(code, astral) {
72
    if (code < 65) { return code === 36 }
73
    if (code < 91) { return true }
74
    if (code < 97) { return code === 95 }
75
    if (code < 123) { return true }
76
    if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
77
    if (astral === false) { return false }
78
    return isInAstralSet(code, astralIdentifierStartCodes)
79
  }
80

    
81
  // Test whether a given character is part of an identifier.
82

    
83
  function isIdentifierChar(code, astral) {
84
    if (code < 48) { return code === 36 }
85
    if (code < 58) { return true }
86
    if (code < 65) { return false }
87
    if (code < 91) { return true }
88
    if (code < 97) { return code === 95 }
89
    if (code < 123) { return true }
90
    if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
91
    if (astral === false) { return false }
92
    return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
93
  }
94

    
95
  // ## Token types
96

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

    
101
  // All token type variables start with an underscore, to make them
102
  // easy to recognize.
103

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

    
118
  var TokenType = function TokenType(label, conf) {
119
    if ( conf === void 0 ) conf = {};
120

    
121
    this.label = label;
122
    this.keyword = conf.keyword;
123
    this.beforeExpr = !!conf.beforeExpr;
124
    this.startsExpr = !!conf.startsExpr;
125
    this.isLoop = !!conf.isLoop;
126
    this.isAssign = !!conf.isAssign;
127
    this.prefix = !!conf.prefix;
128
    this.postfix = !!conf.postfix;
129
    this.binop = conf.binop || null;
130
    this.updateContext = null;
131
  };
132

    
133
  function binop(name, prec) {
134
    return new TokenType(name, {beforeExpr: true, binop: prec})
135
  }
136
  var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};
137

    
138
  // Map keyword names to token types.
139

    
140
  var keywords$1 = {};
141

    
142
  // Succinct definitions of keyword token types
143
  function kw(name, options) {
144
    if ( options === void 0 ) options = {};
145

    
146
    options.keyword = name;
147
    return keywords$1[name] = new TokenType(name, options)
148
  }
149

    
150
  var types = {
151
    num: new TokenType("num", startsExpr),
152
    regexp: new TokenType("regexp", startsExpr),
153
    string: new TokenType("string", startsExpr),
154
    name: new TokenType("name", startsExpr),
155
    eof: new TokenType("eof"),
156

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

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

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

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

    
246
  // Matches a whole line break (where CRLF is considered a single
247
  // line break). Used to count lines.
248

    
249
  var lineBreak = /\r\n?|\n|\u2028|\u2029/;
250
  var lineBreakG = new RegExp(lineBreak.source, "g");
251

    
252
  function isNewLine(code, ecma2019String) {
253
    return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029))
254
  }
255

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

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

    
260
  var ref = Object.prototype;
261
  var hasOwnProperty = ref.hasOwnProperty;
262
  var toString = ref.toString;
263

    
264
  // Checks if an object has a property.
265

    
266
  function has(obj, propName) {
267
    return hasOwnProperty.call(obj, propName)
268
  }
269

    
270
  var isArray = Array.isArray || (function (obj) { return (
271
    toString.call(obj) === "[object Array]"
272
  ); });
273

    
274
  function wordsRegexp(words) {
275
    return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
276
  }
277

    
278
  // These are used when `options.locations` is on, for the
279
  // `startLoc` and `endLoc` properties.
280

    
281
  var Position = function Position(line, col) {
282
    this.line = line;
283
    this.column = col;
284
  };
285

    
286
  Position.prototype.offset = function offset (n) {
287
    return new Position(this.line, this.column + n)
288
  };
289

    
290
  var SourceLocation = function SourceLocation(p, start, end) {
291
    this.start = start;
292
    this.end = end;
293
    if (p.sourceFile !== null) { this.source = p.sourceFile; }
294
  };
295

    
296
  // The `getLineInfo` function is mostly useful when the
297
  // `locations` option is off (for performance reasons) and you
298
  // want to find the line/column position for a given character
299
  // offset. `input` should be the code string that the offset refers
300
  // into.
301

    
302
  function getLineInfo(input, offset) {
303
    for (var line = 1, cur = 0;;) {
304
      lineBreakG.lastIndex = cur;
305
      var match = lineBreakG.exec(input);
306
      if (match && match.index < offset) {
307
        ++line;
308
        cur = match.index + match[0].length;
309
      } else {
310
        return new Position(line, offset - cur)
311
      }
312
    }
313
  }
314

    
315
  // A second optional argument can be given to further configure
316
  // the parser process. These options are recognized:
317

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

    
403
  // Interpret and default an options object
404

    
405
  function getOptions(opts) {
406
    var options = {};
407

    
408
    for (var opt in defaultOptions)
409
      { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
410

    
411
    if (options.ecmaVersion >= 2015)
412
      { options.ecmaVersion -= 2009; }
413

    
414
    if (options.allowReserved == null)
415
      { options.allowReserved = options.ecmaVersion < 5; }
416

    
417
    if (isArray(options.onToken)) {
418
      var tokens = options.onToken;
419
      options.onToken = function (token) { return tokens.push(token); };
420
    }
421
    if (isArray(options.onComment))
422
      { options.onComment = pushComment(options, options.onComment); }
423

    
424
    return options
425
  }
426

    
427
  function pushComment(options, array) {
428
    return function(block, text, start, end, startLoc, endLoc) {
429
      var comment = {
430
        type: block ? "Block" : "Line",
431
        value: text,
432
        start: start,
433
        end: end
434
      };
435
      if (options.locations)
436
        { comment.loc = new SourceLocation(this, startLoc, endLoc); }
437
      if (options.ranges)
438
        { comment.range = [start, end]; }
439
      array.push(comment);
440
    }
441
  }
442

    
443
  // Each scope gets a bitset that may contain these flags
444
  var
445
      SCOPE_TOP = 1,
446
      SCOPE_FUNCTION = 2,
447
      SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION,
448
      SCOPE_ASYNC = 4,
449
      SCOPE_GENERATOR = 8,
450
      SCOPE_ARROW = 16,
451
      SCOPE_SIMPLE_CATCH = 32,
452
      SCOPE_SUPER = 64,
453
      SCOPE_DIRECT_SUPER = 128;
454

    
455
  function functionFlags(async, generator) {
456
    return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
457
  }
458

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

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

    
484
    // Used to signal to callers of `readWord1` whether the word
485
    // contained any escape sequences. This is needed because words with
486
    // escape sequences must not be interpreted as keywords.
487
    this.containsEsc = false;
488

    
489
    // Set up token state
490

    
491
    // The current position of the tokenizer in the input.
492
    if (startPos) {
493
      this.pos = startPos;
494
      this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
495
      this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
496
    } else {
497
      this.pos = this.lineStart = 0;
498
      this.curLine = 1;
499
    }
500

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

    
512
    // Position information for the previous token
513
    this.lastTokEndLoc = this.lastTokStartLoc = null;
514
    this.lastTokStart = this.lastTokEnd = this.pos;
515

    
516
    // The context stack is used to superficially track syntactic
517
    // context to predict whether a regular expression is allowed in a
518
    // given position.
519
    this.context = this.initialContext();
520
    this.exprAllowed = true;
521

    
522
    // Figure out if it's a module code.
523
    this.inModule = options.sourceType === "module";
524
    this.strict = this.inModule || this.strictDirective(this.pos);
525

    
526
    // Used to signify the start of a potential arrow function
527
    this.potentialArrowAt = -1;
528

    
529
    // Positions to delayed-check that yield/await does not exist in default parameters.
530
    this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
531
    // Labels in scope.
532
    this.labels = [];
533
    // Thus-far undefined exports.
534
    this.undefinedExports = {};
535

    
536
    // If enabled, skip leading hashbang line.
537
    if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
538
      { this.skipLineComment(2); }
539

    
540
    // Scope tracking for duplicate variable names (see scope.js)
541
    this.scopeStack = [];
542
    this.enterScope(SCOPE_TOP);
543

    
544
    // For RegExp validation
545
    this.regexpState = null;
546
  };
547

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

    
550
  Parser.prototype.parse = function parse () {
551
    var node = this.options.program || this.startNode();
552
    this.nextToken();
553
    return this.parseTopLevel(node)
554
  };
555

    
556
  prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
557
  prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 };
558
  prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 };
559
  prototypeAccessors.allowSuper.get = function () { return (this.currentThisScope().flags & SCOPE_SUPER) > 0 };
560
  prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
561
  prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
562

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

    
566
  Parser.extend = function extend () {
567
      var plugins = [], len = arguments.length;
568
      while ( len-- ) plugins[ len ] = arguments[ len ];
569

    
570
    var cls = this;
571
    for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
572
    return cls
573
  };
574

    
575
  Parser.parse = function parse (input, options) {
576
    return new this(options, input).parse()
577
  };
578

    
579
  Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
580
    var parser = new this(options, input, pos);
581
    parser.nextToken();
582
    return parser.parseExpression()
583
  };
584

    
585
  Parser.tokenizer = function tokenizer (input, options) {
586
    return new this(options, input)
587
  };
588

    
589
  Object.defineProperties( Parser.prototype, prototypeAccessors );
590

    
591
  var pp = Parser.prototype;
592

    
593
  // ## Parser utilities
594

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

    
606
      // Skip semicolon, if any.
607
      skipWhiteSpace.lastIndex = start;
608
      start += skipWhiteSpace.exec(this.input)[0].length;
609
      if (this.input[start] === ";")
610
        { start++; }
611
    }
612
  };
613

    
614
  // Predicate that tests whether the next token is of the given
615
  // type, and if yes, consumes it as a side effect.
616

    
617
  pp.eat = function(type) {
618
    if (this.type === type) {
619
      this.next();
620
      return true
621
    } else {
622
      return false
623
    }
624
  };
625

    
626
  // Tests whether parsed token is a contextual keyword.
627

    
628
  pp.isContextual = function(name) {
629
    return this.type === types.name && this.value === name && !this.containsEsc
630
  };
631

    
632
  // Consumes contextual keyword if possible.
633

    
634
  pp.eatContextual = function(name) {
635
    if (!this.isContextual(name)) { return false }
636
    this.next();
637
    return true
638
  };
639

    
640
  // Asserts that following token is given contextual keyword.
641

    
642
  pp.expectContextual = function(name) {
643
    if (!this.eatContextual(name)) { this.unexpected(); }
644
  };
645

    
646
  // Test whether a semicolon can be inserted at the current position.
647

    
648
  pp.canInsertSemicolon = function() {
649
    return this.type === types.eof ||
650
      this.type === types.braceR ||
651
      lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
652
  };
653

    
654
  pp.insertSemicolon = function() {
655
    if (this.canInsertSemicolon()) {
656
      if (this.options.onInsertedSemicolon)
657
        { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
658
      return true
659
    }
660
  };
661

    
662
  // Consume a semicolon, or, failing that, see if we are allowed to
663
  // pretend that there is a semicolon at this position.
664

    
665
  pp.semicolon = function() {
666
    if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
667
  };
668

    
669
  pp.afterTrailingComma = function(tokType, notNext) {
670
    if (this.type === tokType) {
671
      if (this.options.onTrailingComma)
672
        { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
673
      if (!notNext)
674
        { this.next(); }
675
      return true
676
    }
677
  };
678

    
679
  // Expect a token of a given type. If found, consume it, otherwise,
680
  // raise an unexpected token error.
681

    
682
  pp.expect = function(type) {
683
    this.eat(type) || this.unexpected();
684
  };
685

    
686
  // Raise an unexpected token error.
687

    
688
  pp.unexpected = function(pos) {
689
    this.raise(pos != null ? pos : this.start, "Unexpected token");
690
  };
691

    
692
  function DestructuringErrors() {
693
    this.shorthandAssign =
694
    this.trailingComma =
695
    this.parenthesizedAssign =
696
    this.parenthesizedBind =
697
    this.doubleProto =
698
      -1;
699
  }
700

    
701
  pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
702
    if (!refDestructuringErrors) { return }
703
    if (refDestructuringErrors.trailingComma > -1)
704
      { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
705
    var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
706
    if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
707
  };
708

    
709
  pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
710
    if (!refDestructuringErrors) { return false }
711
    var shorthandAssign = refDestructuringErrors.shorthandAssign;
712
    var doubleProto = refDestructuringErrors.doubleProto;
713
    if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
714
    if (shorthandAssign >= 0)
715
      { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
716
    if (doubleProto >= 0)
717
      { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
718
  };
719

    
720
  pp.checkYieldAwaitInDefaultParams = function() {
721
    if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
722
      { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
723
    if (this.awaitPos)
724
      { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
725
  };
726

    
727
  pp.isSimpleAssignTarget = function(expr) {
728
    if (expr.type === "ParenthesizedExpression")
729
      { return this.isSimpleAssignTarget(expr.expression) }
730
    return expr.type === "Identifier" || expr.type === "MemberExpression"
731
  };
732

    
733
  var pp$1 = Parser.prototype;
734

    
735
  // ### Statement parsing
736

    
737
  // Parse a program. Initializes the parser, reads any number of
738
  // statements, and wraps them in a Program node.  Optionally takes a
739
  // `program` argument.  If present, the statements will be appended
740
  // to its body instead of creating a new node.
741

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

    
754
          this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
755
        } }
756
    this.adaptDirectivePrologue(node.body);
757
    this.next();
758
    node.sourceType = this.options.sourceType;
759
    return this.finishNode(node, "Program")
760
  };
761

    
762
  var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
763

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

    
776
    if (nextCh === 123) { return true } // '{'
777
    if (isIdentifierStart(nextCh, true)) {
778
      var pos = next + 1;
779
      while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
780
      var ident = this.input.slice(next, pos);
781
      if (!keywordRelationalOperator.test(ident)) { return true }
782
    }
783
    return false
784
  };
785

    
786
  // check 'async [no LineTerminator here] function'
787
  // - 'async /*foo*/ function' is OK.
788
  // - 'async /*\n*/ function' is invalid.
789
  pp$1.isAsyncFunction = function() {
790
    if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
791
      { return false }
792

    
793
    skipWhiteSpace.lastIndex = this.pos;
794
    var skip = skipWhiteSpace.exec(this.input);
795
    var next = this.pos + skip[0].length;
796
    return !lineBreak.test(this.input.slice(this.pos, next)) &&
797
      this.input.slice(next, next + 8) === "function" &&
798
      (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
799
  };
800

    
801
  // Parse a single statement.
802
  //
803
  // If expecting a statement and finding a slash operator, parse a
804
  // regular expression literal. This is to handle cases like
805
  // `if (foo) /blah/.exec(foo)`, where looking at the previous token
806
  // does not help.
807

    
808
  pp$1.parseStatement = function(context, topLevel, exports) {
809
    var starttype = this.type, node = this.startNode(), kind;
810

    
811
    if (this.isLet(context)) {
812
      starttype = types._var;
813
      kind = "let";
814
    }
815

    
816
    // Most types of statements are recognized by the keyword they
817
    // start with. Many are trivial to parse, some require a bit of
818
    // complexity.
819

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

    
857
      if (!this.options.allowImportExportEverywhere) {
858
        if (!topLevel)
859
          { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
860
        if (!this.inModule)
861
          { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
862
      }
863
      return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
864

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

    
877
      var maybeName = this.value, expr = this.parseExpression();
878
      if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
879
        { return this.parseLabeledStatement(node, maybeName, expr, context) }
880
      else { return this.parseExpressionStatement(node, expr) }
881
    }
882
  };
883

    
884
  pp$1.parseBreakContinueStatement = function(node, keyword) {
885
    var isBreak = keyword === "break";
886
    this.next();
887
    if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
888
    else if (this.type !== types.name) { this.unexpected(); }
889
    else {
890
      node.label = this.parseIdent();
891
      this.semicolon();
892
    }
893

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

    
908
  pp$1.parseDebuggerStatement = function(node) {
909
    this.next();
910
    this.semicolon();
911
    return this.finishNode(node, "DebuggerStatement")
912
  };
913

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

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

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

    
981
  pp$1.parseFunctionStatement = function(node, isAsync, declarationPosition) {
982
    this.next();
983
    return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
984
  };
985

    
986
  pp$1.parseIfStatement = function(node) {
987
    this.next();
988
    node.test = this.parseParenExpression();
989
    // allow function declarations in branches, but only in non-strict mode
990
    node.consequent = this.parseStatement("if");
991
    node.alternate = this.eat(types._else) ? this.parseStatement("if") : null;
992
    return this.finishNode(node, "IfStatement")
993
  };
994

    
995
  pp$1.parseReturnStatement = function(node) {
996
    if (!this.inFunction && !this.options.allowReturnOutsideFunction)
997
      { this.raise(this.start, "'return' outside of function"); }
998
    this.next();
999

    
1000
    // In `return` (and `break`/`continue`), the keywords with
1001
    // optional arguments, we eagerly look for a semicolon or the
1002
    // possibility to insert one.
1003

    
1004
    if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
1005
    else { node.argument = this.parseExpression(); this.semicolon(); }
1006
    return this.finishNode(node, "ReturnStatement")
1007
  };
1008

    
1009
  pp$1.parseSwitchStatement = function(node) {
1010
    this.next();
1011
    node.discriminant = this.parseParenExpression();
1012
    node.cases = [];
1013
    this.expect(types.braceL);
1014
    this.labels.push(switchLabel);
1015
    this.enterScope(0);
1016

    
1017
    // Statements under must be grouped (by label) in SwitchCase
1018
    // nodes. `cur` is used to keep the node that we are currently
1019
    // adding statements to.
1020

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

    
1049
  pp$1.parseThrowStatement = function(node) {
1050
    this.next();
1051
    if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
1052
      { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
1053
    node.argument = this.parseExpression();
1054
    this.semicolon();
1055
    return this.finishNode(node, "ThrowStatement")
1056
  };
1057

    
1058
  // Reused empty array added for node fields that are always empty.
1059

    
1060
  var empty = [];
1061

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

    
1090
  pp$1.parseVarStatement = function(node, kind) {
1091
    this.next();
1092
    this.parseVar(node, false, kind);
1093
    this.semicolon();
1094
    return this.finishNode(node, "VariableDeclaration")
1095
  };
1096

    
1097
  pp$1.parseWhileStatement = function(node) {
1098
    this.next();
1099
    node.test = this.parseParenExpression();
1100
    this.labels.push(loopLabel);
1101
    node.body = this.parseStatement("while");
1102
    this.labels.pop();
1103
    return this.finishNode(node, "WhileStatement")
1104
  };
1105

    
1106
  pp$1.parseWithStatement = function(node) {
1107
    if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
1108
    this.next();
1109
    node.object = this.parseParenExpression();
1110
    node.body = this.parseStatement("with");
1111
    return this.finishNode(node, "WithStatement")
1112
  };
1113

    
1114
  pp$1.parseEmptyStatement = function(node) {
1115
    this.next();
1116
    return this.finishNode(node, "EmptyStatement")
1117
  };
1118

    
1119
  pp$1.parseLabeledStatement = function(node, maybeName, expr, context) {
1120
    for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
1121
      {
1122
      var label = list[i$1];
1123

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

    
1143
  pp$1.parseExpressionStatement = function(node, expr) {
1144
    node.expression = expr;
1145
    this.semicolon();
1146
    return this.finishNode(node, "ExpressionStatement")
1147
  };
1148

    
1149
  // Parse a semicolon-enclosed block of statements, handling `"use
1150
  // strict"` declarations when `allowStrict` is true (used for
1151
  // function bodies).
1152

    
1153
  pp$1.parseBlock = function(createNewLexicalScope, node) {
1154
    if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
1155
    if ( node === void 0 ) node = this.startNode();
1156

    
1157
    node.body = [];
1158
    this.expect(types.braceL);
1159
    if (createNewLexicalScope) { this.enterScope(0); }
1160
    while (!this.eat(types.braceR)) {
1161
      var stmt = this.parseStatement(null);
1162
      node.body.push(stmt);
1163
    }
1164
    if (createNewLexicalScope) { this.exitScope(); }
1165
    return this.finishNode(node, "BlockStatement")
1166
  };
1167

    
1168
  // Parse a regular `for` loop. The disambiguation code in
1169
  // `parseStatement` will already have parsed the init statement or
1170
  // expression.
1171

    
1172
  pp$1.parseFor = function(node, init) {
1173
    node.init = init;
1174
    this.expect(types.semi);
1175
    node.test = this.type === types.semi ? null : this.parseExpression();
1176
    this.expect(types.semi);
1177
    node.update = this.type === types.parenR ? null : this.parseExpression();
1178
    this.expect(types.parenR);
1179
    node.body = this.parseStatement("for");
1180
    this.exitScope();
1181
    this.labels.pop();
1182
    return this.finishNode(node, "ForStatement")
1183
  };
1184

    
1185
  // Parse a `for`/`in` and `for`/`of` loop, which are almost
1186
  // same from parser's perspective.
1187

    
1188
  pp$1.parseForIn = function(node, init) {
1189
    var isForIn = this.type === types._in;
1190
    this.next();
1191

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

    
1219
  // Parse a list of variable declarations.
1220

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

    
1242
  pp$1.parseVarId = function(decl, kind) {
1243
    decl.id = this.parseBindingAtom();
1244
    this.checkLVal(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
1245
  };
1246

    
1247
  var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
1248

    
1249
  // Parse a function declaration or literal (depending on the
1250
  // `statement & FUNC_STATEMENT`).
1251

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

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

    
1273
    var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
1274
    this.yieldPos = 0;
1275
    this.awaitPos = 0;
1276
    this.awaitIdentPos = 0;
1277
    this.enterScope(functionFlags(node.async, node.generator));
1278

    
1279
    if (!(statement & FUNC_STATEMENT))
1280
      { node.id = this.type === types.name ? this.parseIdent() : null; }
1281

    
1282
    this.parseFunctionParams(node);
1283
    this.parseFunctionBody(node, allowExpressionBody, false);
1284

    
1285
    this.yieldPos = oldYieldPos;
1286
    this.awaitPos = oldAwaitPos;
1287
    this.awaitIdentPos = oldAwaitIdentPos;
1288
    return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
1289
  };
1290

    
1291
  pp$1.parseFunctionParams = function(node) {
1292
    this.expect(types.parenL);
1293
    node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
1294
    this.checkYieldAwaitInDefaultParams();
1295
  };
1296

    
1297
  // Parse a class declaration or literal (depending on the
1298
  // `isStatement` parameter).
1299

    
1300
  pp$1.parseClass = function(node, isStatement) {
1301
    this.next();
1302

    
1303
    // ecma-262 14.6 Class Definitions
1304
    // A class definition is always strict mode code.
1305
    var oldStrict = this.strict;
1306
    this.strict = true;
1307

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

    
1329
  pp$1.parseClassElement = function(constructorAllowsSuper) {
1330
    var this$1 = this;
1331

    
1332
    if (this.eat(types.semi)) { return null }
1333

    
1334
    var method = this.startNode();
1335
    var tryContextual = function (k, noLineBreak) {
1336
      if ( noLineBreak === void 0 ) noLineBreak = false;
1337

    
1338
      var start = this$1.start, startLoc = this$1.startLoc;
1339
      if (!this$1.eatContextual(k)) { return false }
1340
      if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
1341
      if (method.key) { this$1.unexpected(); }
1342
      method.computed = false;
1343
      method.key = this$1.startNodeAt(start, startLoc);
1344
      method.key.name = k;
1345
      this$1.finishNode(method.key, "Identifier");
1346
      return false
1347
    };
1348

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

    
1386
  pp$1.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
1387
    method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
1388
    return this.finishNode(method, "MethodDefinition")
1389
  };
1390

    
1391
  pp$1.parseClassId = function(node, isStatement) {
1392
    if (this.type === types.name) {
1393
      node.id = this.parseIdent();
1394
      if (isStatement)
1395
        { this.checkLVal(node.id, BIND_LEXICAL, false); }
1396
    } else {
1397
      if (isStatement === true)
1398
        { this.unexpected(); }
1399
      node.id = null;
1400
    }
1401
  };
1402

    
1403
  pp$1.parseClassSuper = function(node) {
1404
    node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
1405
  };
1406

    
1407
  // Parses module export declaration.
1408

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

    
1456
          this.checkUnreserved(spec.local);
1457
          // check if export is defined
1458
          this.checkLocalExport(spec.local);
1459
        }
1460

    
1461
        node.source = null;
1462
      }
1463
      this.semicolon();
1464
    }
1465
    return this.finishNode(node, "ExportNamedDeclaration")
1466
  };
1467

    
1468
  pp$1.checkExport = function(exports, name, pos) {
1469
    if (!exports) { return }
1470
    if (has(exports, name))
1471
      { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
1472
    exports[name] = true;
1473
  };
1474

    
1475
  pp$1.checkPatternExport = function(exports, pat) {
1476
    var type = pat.type;
1477
    if (type === "Identifier")
1478
      { this.checkExport(exports, pat.name, pat.start); }
1479
    else if (type === "ObjectPattern")
1480
      { for (var i = 0, list = pat.properties; i < list.length; i += 1)
1481
        {
1482
          var prop = list[i];
1483

    
1484
          this.checkPatternExport(exports, prop);
1485
        } }
1486
    else if (type === "ArrayPattern")
1487
      { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
1488
        var elt = list$1[i$1];
1489

    
1490
          if (elt) { this.checkPatternExport(exports, elt); }
1491
      } }
1492
    else if (type === "Property")
1493
      { this.checkPatternExport(exports, pat.value); }
1494
    else if (type === "AssignmentPattern")
1495
      { this.checkPatternExport(exports, pat.left); }
1496
    else if (type === "RestElement")
1497
      { this.checkPatternExport(exports, pat.argument); }
1498
    else if (type === "ParenthesizedExpression")
1499
      { this.checkPatternExport(exports, pat.expression); }
1500
  };
1501

    
1502
  pp$1.checkVariableExport = function(exports, decls) {
1503
    if (!exports) { return }
1504
    for (var i = 0, list = decls; i < list.length; i += 1)
1505
      {
1506
      var decl = list[i];
1507

    
1508
      this.checkPatternExport(exports, decl.id);
1509
    }
1510
  };
1511

    
1512
  pp$1.shouldParseExportStatement = function() {
1513
    return this.type.keyword === "var" ||
1514
      this.type.keyword === "const" ||
1515
      this.type.keyword === "class" ||
1516
      this.type.keyword === "function" ||
1517
      this.isLet() ||
1518
      this.isAsyncFunction()
1519
  };
1520

    
1521
  // Parses a comma-separated list of module exports.
1522

    
1523
  pp$1.parseExportSpecifiers = function(exports) {
1524
    var nodes = [], first = true;
1525
    // export { x, y as z } [from '...']
1526
    this.expect(types.braceL);
1527
    while (!this.eat(types.braceR)) {
1528
      if (!first) {
1529
        this.expect(types.comma);
1530
        if (this.afterTrailingComma(types.braceR)) { break }
1531
      } else { first = false; }
1532

    
1533
      var node = this.startNode();
1534
      node.local = this.parseIdent(true);
1535
      node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
1536
      this.checkExport(exports, node.exported.name, node.exported.start);
1537
      nodes.push(this.finishNode(node, "ExportSpecifier"));
1538
    }
1539
    return nodes
1540
  };
1541

    
1542
  // Parses import declaration.
1543

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

    
1559
  // Parses a comma-separated list of module imports.
1560

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

    
1587
      var node$2 = this.startNode();
1588
      node$2.imported = this.parseIdent(true);
1589
      if (this.eatContextual("as")) {
1590
        node$2.local = this.parseIdent();
1591
      } else {
1592
        this.checkUnreserved(node$2.imported);
1593
        node$2.local = node$2.imported;
1594
      }
1595
      this.checkLVal(node$2.local, BIND_LEXICAL);
1596
      nodes.push(this.finishNode(node$2, "ImportSpecifier"));
1597
    }
1598
    return nodes
1599
  };
1600

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

    
1617
  var pp$2 = Parser.prototype;
1618

    
1619
  // Convert existing expression atom to assignable pattern
1620
  // if possible.
1621

    
1622
  pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
1623
    if (this.options.ecmaVersion >= 6 && node) {
1624
      switch (node.type) {
1625
      case "Identifier":
1626
        if (this.inAsync && node.name === "await")
1627
          { this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
1628
        break
1629

    
1630
      case "ObjectPattern":
1631
      case "ArrayPattern":
1632
      case "RestElement":
1633
        break
1634

    
1635
      case "ObjectExpression":
1636
        node.type = "ObjectPattern";
1637
        if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1638
        for (var i = 0, list = node.properties; i < list.length; i += 1) {
1639
          var prop = list[i];
1640

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

    
1656
      case "Property":
1657
        // AssignmentProperty has type === "Property"
1658
        if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
1659
        this.toAssignable(node.value, isBinding);
1660
        break
1661

    
1662
      case "ArrayExpression":
1663
        node.type = "ArrayPattern";
1664
        if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1665
        this.toAssignableList(node.elements, isBinding);
1666
        break
1667

    
1668
      case "SpreadElement":
1669
        node.type = "RestElement";
1670
        this.toAssignable(node.argument, isBinding);
1671
        if (node.argument.type === "AssignmentPattern")
1672
          { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
1673
        break
1674

    
1675
      case "AssignmentExpression":
1676
        if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
1677
        node.type = "AssignmentPattern";
1678
        delete node.operator;
1679
        this.toAssignable(node.left, isBinding);
1680
        // falls through to AssignmentPattern
1681

    
1682
      case "AssignmentPattern":
1683
        break
1684

    
1685
      case "ParenthesizedExpression":
1686
        this.toAssignable(node.expression, isBinding, refDestructuringErrors);
1687
        break
1688

    
1689
      case "MemberExpression":
1690
        if (!isBinding) { break }
1691

    
1692
      default:
1693
        this.raise(node.start, "Assigning to rvalue");
1694
      }
1695
    } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
1696
    return node
1697
  };
1698

    
1699
  // Convert list of expression atoms to binding list.
1700

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

    
1715
  // Parses spread element.
1716

    
1717
  pp$2.parseSpread = function(refDestructuringErrors) {
1718
    var node = this.startNode();
1719
    this.next();
1720
    node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
1721
    return this.finishNode(node, "SpreadElement")
1722
  };
1723

    
1724
  pp$2.parseRestBinding = function() {
1725
    var node = this.startNode();
1726
    this.next();
1727

    
1728
    // RestElement inside of a function parameter must be an identifier
1729
    if (this.options.ecmaVersion === 6 && this.type !== types.name)
1730
      { this.unexpected(); }
1731

    
1732
    node.argument = this.parseBindingAtom();
1733

    
1734
    return this.finishNode(node, "RestElement")
1735
  };
1736

    
1737
  // Parses lvalue (assignable) atom.
1738

    
1739
  pp$2.parseBindingAtom = function() {
1740
    if (this.options.ecmaVersion >= 6) {
1741
      switch (this.type) {
1742
      case types.bracketL:
1743
        var node = this.startNode();
1744
        this.next();
1745
        node.elements = this.parseBindingList(types.bracketR, true, true);
1746
        return this.finishNode(node, "ArrayPattern")
1747

    
1748
      case types.braceL:
1749
        return this.parseObj(true)
1750
      }
1751
    }
1752
    return this.parseIdent()
1753
  };
1754

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

    
1780
  pp$2.parseBindingListItem = function(param) {
1781
    return param
1782
  };
1783

    
1784
  // Parses assignment pattern around given atom if possible.
1785

    
1786
  pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
1787
    left = left || this.parseBindingAtom();
1788
    if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
1789
    var node = this.startNodeAt(startPos, startLoc);
1790
    node.left = left;
1791
    node.right = this.parseMaybeAssign();
1792
    return this.finishNode(node, "AssignmentPattern")
1793
  };
1794

    
1795
  // Verify that a node is an lval — something that can be assigned
1796
  // to.
1797
  // bindingType can be either:
1798
  // 'var' indicating that the lval creates a 'var' binding
1799
  // 'let' indicating that the lval creates a lexical ('let' or 'const') binding
1800
  // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
1801

    
1802
  pp$2.checkLVal = function(expr, bindingType, checkClashes) {
1803
    if ( bindingType === void 0 ) bindingType = BIND_NONE;
1804

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

    
1819
    case "MemberExpression":
1820
      if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
1821
      break
1822

    
1823
    case "ObjectPattern":
1824
      for (var i = 0, list = expr.properties; i < list.length; i += 1)
1825
        {
1826
      var prop = list[i];
1827

    
1828
      this.checkLVal(prop, bindingType, checkClashes);
1829
    }
1830
      break
1831

    
1832
    case "Property":
1833
      // AssignmentProperty has type === "Property"
1834
      this.checkLVal(expr.value, bindingType, checkClashes);
1835
      break
1836

    
1837
    case "ArrayPattern":
1838
      for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
1839
        var elem = list$1[i$1];
1840

    
1841
      if (elem) { this.checkLVal(elem, bindingType, checkClashes); }
1842
      }
1843
      break
1844

    
1845
    case "AssignmentPattern":
1846
      this.checkLVal(expr.left, bindingType, checkClashes);
1847
      break
1848

    
1849
    case "RestElement":
1850
      this.checkLVal(expr.argument, bindingType, checkClashes);
1851
      break
1852

    
1853
    case "ParenthesizedExpression":
1854
      this.checkLVal(expr.expression, bindingType, checkClashes);
1855
      break
1856

    
1857
    default:
1858
      this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
1859
    }
1860
  };
1861

    
1862
  // A recursive descent parser operates by defining functions for all
1863

    
1864
  var pp$3 = Parser.prototype;
1865

    
1866
  // Check if property name clashes with already added.
1867
  // Object/class getters and setters are not allowed to clash —
1868
  // either with each other or with an init property — and in
1869
  // strict mode, init properties are also not allowed to be repeated.
1870

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

    
1916
  // ### Expression parsing
1917

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

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

    
1931
  pp$3.parseExpression = function(noIn, refDestructuringErrors) {
1932
    var startPos = this.start, startLoc = this.startLoc;
1933
    var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
1934
    if (this.type === types.comma) {
1935
      var node = this.startNodeAt(startPos, startLoc);
1936
      node.expressions = [expr];
1937
      while (this.eat(types.comma)) { node.expressions.push(this.parseMaybeAssign(noIn, refDestructuringErrors)); }
1938
      return this.finishNode(node, "SequenceExpression")
1939
    }
1940
    return expr
1941
  };
1942

    
1943
  // Parse an assignment expression. This includes applications of
1944
  // operators like `+=`.
1945

    
1946
  pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
1947
    if (this.isContextual("yield")) {
1948
      if (this.inGenerator) { return this.parseYield(noIn) }
1949
      // The tokenizer will assume an expression is allowed after
1950
      // `yield`, but this isn't that kind of yield
1951
      else { this.exprAllowed = false; }
1952
    }
1953

    
1954
    var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldShorthandAssign = -1;
1955
    if (refDestructuringErrors) {
1956
      oldParenAssign = refDestructuringErrors.parenthesizedAssign;
1957
      oldTrailingComma = refDestructuringErrors.trailingComma;
1958
      oldShorthandAssign = refDestructuringErrors.shorthandAssign;
1959
      refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.shorthandAssign = -1;
1960
    } else {
1961
      refDestructuringErrors = new DestructuringErrors;
1962
      ownDestructuringErrors = true;
1963
    }
1964

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

    
1989
  // Parse a ternary conditional (`?:`) operator.
1990

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

    
2006
  // Start the precedence parser.
2007

    
2008
  pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
2009
    var startPos = this.start, startLoc = this.startLoc;
2010
    var expr = this.parseMaybeUnary(refDestructuringErrors, false);
2011
    if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
2012
    return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
2013
  };
2014

    
2015
  // Parse binary operators with the operator precedence parsing
2016
  // algorithm. `left` is the left-hand side of the operator.
2017
  // `minPrec` provides context that allows the function to stop and
2018
  // defer further parser to one of its callers when it encounters an
2019
  // operator that has a lower precedence than the set it is parsing.
2020

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

    
2037
  pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
2038
    var node = this.startNodeAt(startPos, startLoc);
2039
    node.left = left;
2040
    node.operator = op;
2041
    node.right = right;
2042
    return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
2043
  };
2044

    
2045
  // Parse unary operators, both prefix and postfix.
2046

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

    
2079
    if (!sawUnary && this.eat(types.starstar))
2080
      { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
2081
    else
2082
      { return expr }
2083
  };
2084

    
2085
  // Parse call, dot, and `[]`-subscript expressions.
2086

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

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

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

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

    
2162
  // Parse an atomic expression — either a single token that is an
2163
  // expression, an expression started by a keyword like `function` or
2164
  // `new`, or an expression wrapped in punctuation like `()`, `[]`,
2165
  // or `{}`.
2166

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

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

    
2191
    case types._this:
2192
      node = this.startNode();
2193
      this.next();
2194
      return this.finishNode(node, "ThisExpression")
2195

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

    
2213
    case types.regexp:
2214
      var value = this.value;
2215
      node = this.parseLiteral(value.value);
2216
      node.regex = {pattern: value.pattern, flags: value.flags};
2217
      return node
2218

    
2219
    case types.num: case types.string:
2220
      return this.parseLiteral(this.value)
2221

    
2222
    case types._null: case types._true: case types._false:
2223
      node = this.startNode();
2224
      node.value = this.type === types._null ? null : this.type === types._true;
2225
      node.raw = this.type.keyword;
2226
      this.next();
2227
      return this.finishNode(node, "Literal")
2228

    
2229
    case types.parenL:
2230
      var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
2231
      if (refDestructuringErrors) {
2232
        if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
2233
          { refDestructuringErrors.parenthesizedAssign = start; }
2234
        if (refDestructuringErrors.parenthesizedBind < 0)
2235
          { refDestructuringErrors.parenthesizedBind = start; }
2236
      }
2237
      return expr
2238

    
2239
    case types.bracketL:
2240
      node = this.startNode();
2241
      this.next();
2242
      node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
2243
      return this.finishNode(node, "ArrayExpression")
2244

    
2245
    case types.braceL:
2246
      return this.parseObj(false, refDestructuringErrors)
2247

    
2248
    case types._function:
2249
      node = this.startNode();
2250
      this.next();
2251
      return this.parseFunction(node, 0)
2252

    
2253
    case types._class:
2254
      return this.parseClass(this.startNode(), false)
2255

    
2256
    case types._new:
2257
      return this.parseNew()
2258

    
2259
    case types.backQuote:
2260
      return this.parseTemplate()
2261

    
2262
    case types._import:
2263
      if (this.options.ecmaVersion > 10) {
2264
        return this.parseDynamicImport()
2265
      } else {
2266
        return this.unexpected()
2267
      }
2268

    
2269
    default:
2270
      this.unexpected();
2271
    }
2272
  };
2273

    
2274
  pp$3.parseDynamicImport = function() {
2275
    var node = this.startNode();
2276
    this.next();
2277
    if (this.type !== types.parenL) {
2278
      this.unexpected();
2279
    }
2280
    return this.finishNode(node, "Import")
2281
  };
2282

    
2283
  pp$3.parseLiteral = function(value) {
2284
    var node = this.startNode();
2285
    node.value = value;
2286
    node.raw = this.input.slice(this.start, this.end);
2287
    if (node.raw.charCodeAt(node.raw.length - 1) === 110) { node.bigint = node.raw.slice(0, -1); }
2288
    this.next();
2289
    return this.finishNode(node, "Literal")
2290
  };
2291

    
2292
  pp$3.parseParenExpression = function() {
2293
    this.expect(types.parenL);
2294
    var val = this.parseExpression();
2295
    this.expect(types.parenR);
2296
    return val
2297
  };
2298

    
2299
  pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
2300
    var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
2301
    if (this.options.ecmaVersion >= 6) {
2302
      this.next();
2303

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

    
2327
      if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
2328
        this.checkPatternErrors(refDestructuringErrors, false);
2329
        this.checkYieldAwaitInDefaultParams();
2330
        this.yieldPos = oldYieldPos;
2331
        this.awaitPos = oldAwaitPos;
2332
        return this.parseParenArrowList(startPos, startLoc, exprList)
2333
      }
2334

    
2335
      if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
2336
      if (spreadStart) { this.unexpected(spreadStart); }
2337
      this.checkExpressionErrors(refDestructuringErrors, true);
2338
      this.yieldPos = oldYieldPos || this.yieldPos;
2339
      this.awaitPos = oldAwaitPos || this.awaitPos;
2340

    
2341
      if (exprList.length > 1) {
2342
        val = this.startNodeAt(innerStartPos, innerStartLoc);
2343
        val.expressions = exprList;
2344
        this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
2345
      } else {
2346
        val = exprList[0];
2347
      }
2348
    } else {
2349
      val = this.parseParenExpression();
2350
    }
2351

    
2352
    if (this.options.preserveParens) {
2353
      var par = this.startNodeAt(startPos, startLoc);
2354
      par.expression = val;
2355
      return this.finishNode(par, "ParenthesizedExpression")
2356
    } else {
2357
      return val
2358
    }
2359
  };
2360

    
2361
  pp$3.parseParenItem = function(item) {
2362
    return item
2363
  };
2364

    
2365
  pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
2366
    return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
2367
  };
2368

    
2369
  // New's precedence is slightly tricky. It must allow its argument to
2370
  // be a `[]` or dot subscript expression, but not a call — at least,
2371
  // not without wrapping it in parentheses. Thus, it uses the noCalls
2372
  // argument to parseSubscripts to prevent it from consuming the
2373
  // argument list.
2374

    
2375
  var empty$1 = [];
2376

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

    
2400
  // Parse template expression.
2401

    
2402
  pp$3.parseTemplateElement = function(ref) {
2403
    var isTagged = ref.isTagged;
2404

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

    
2425
  pp$3.parseTemplate = function(ref) {
2426
    if ( ref === void 0 ) ref = {};
2427
    var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
2428

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

    
2445
  pp$3.isAsyncProp = function(prop) {
2446
    return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
2447
      (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types.star)) &&
2448
      !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
2449
  };
2450

    
2451
  // Parse an object literal or binding pattern.
2452

    
2453
  pp$3.parseObj = function(isPattern, refDestructuringErrors) {
2454
    var node = this.startNode(), first = true, propHash = {};
2455
    node.properties = [];
2456
    this.next();
2457
    while (!this.eat(types.braceR)) {
2458
      if (!first) {
2459
        this.expect(types.comma);
2460
        if (this.afterTrailingComma(types.braceR)) { break }
2461
      } else { first = false; }
2462

    
2463
      var prop = this.parseProperty(isPattern, refDestructuringErrors);
2464
      if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
2465
      node.properties.push(prop);
2466
    }
2467
    return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
2468
  };
2469

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

    
2521
  pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
2522
    if ((isGenerator || isAsync) && this.type === types.colon)
2523
      { this.unexpected(); }
2524

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

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

    
2585
  // Initialize empty function node.
2586

    
2587
  pp$3.initFunction = function(node) {
2588
    node.id = null;
2589
    if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
2590
    if (this.options.ecmaVersion >= 8) { node.async = false; }
2591
  };
2592

    
2593
  // Parse object or class method.
2594

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

    
2598
    this.initFunction(node);
2599
    if (this.options.ecmaVersion >= 6)
2600
      { node.generator = isGenerator; }
2601
    if (this.options.ecmaVersion >= 8)
2602
      { node.async = !!isAsync; }
2603

    
2604
    this.yieldPos = 0;
2605
    this.awaitPos = 0;
2606
    this.awaitIdentPos = 0;
2607
    this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
2608

    
2609
    this.expect(types.parenL);
2610
    node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
2611
    this.checkYieldAwaitInDefaultParams();
2612
    this.parseFunctionBody(node, false, true);
2613

    
2614
    this.yieldPos = oldYieldPos;
2615
    this.awaitPos = oldAwaitPos;
2616
    this.awaitIdentPos = oldAwaitIdentPos;
2617
    return this.finishNode(node, "FunctionExpression")
2618
  };
2619

    
2620
  // Parse arrow function expression with given parameters.
2621

    
2622
  pp$3.parseArrowExpression = function(node, params, isAsync) {
2623
    var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
2624

    
2625
    this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
2626
    this.initFunction(node);
2627
    if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
2628

    
2629
    this.yieldPos = 0;
2630
    this.awaitPos = 0;
2631
    this.awaitIdentPos = 0;
2632

    
2633
    node.params = this.toAssignableList(params, true);
2634
    this.parseFunctionBody(node, true, false);
2635

    
2636
    this.yieldPos = oldYieldPos;
2637
    this.awaitPos = oldAwaitPos;
2638
    this.awaitIdentPos = oldAwaitIdentPos;
2639
    return this.finishNode(node, "ArrowFunctionExpression")
2640
  };
2641

    
2642
  // Parse function body and check parameters.
2643

    
2644
  pp$3.parseFunctionBody = function(node, isArrowFunction, isMethod) {
2645
    var isExpression = isArrowFunction && this.type !== types.braceL;
2646
    var oldStrict = this.strict, useStrict = false;
2647

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

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

    
2678
    // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
2679
    if (this.strict && node.id) { this.checkLVal(node.id, BIND_OUTSIDE); }
2680
    this.strict = oldStrict;
2681
  };
2682

    
2683
  pp$3.isSimpleParamList = function(params) {
2684
    for (var i = 0, list = params; i < list.length; i += 1)
2685
      {
2686
      var param = list[i];
2687

    
2688
      if (param.type !== "Identifier") { return false
2689
    } }
2690
    return true
2691
  };
2692

    
2693
  // Checks function params for various disallowed patterns such as using "eval"
2694
  // or "arguments" and duplicate parameters.
2695

    
2696
  pp$3.checkParams = function(node, allowDuplicates) {
2697
    var nameHash = {};
2698
    for (var i = 0, list = node.params; i < list.length; i += 1)
2699
      {
2700
      var param = list[i];
2701

    
2702
      this.checkLVal(param, BIND_VAR, allowDuplicates ? null : nameHash);
2703
    }
2704
  };
2705

    
2706
  // Parses a comma-separated list of expressions, and returns them as
2707
  // an array. `close` is the token type that ends the list, and
2708
  // `allowEmpty` can be turned on to allow subsequent commas with
2709
  // nothing in between them to be parsed as `null` (which is needed
2710
  // for array literals).
2711

    
2712
  pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
2713
    var elts = [], first = true;
2714
    while (!this.eat(close)) {
2715
      if (!first) {
2716
        this.expect(types.comma);
2717
        if (allowTrailingComma && this.afterTrailingComma(close)) { break }
2718
      } else { first = false; }
2719

    
2720
      var elt = (void 0);
2721
      if (allowEmpty && this.type === types.comma)
2722
        { elt = null; }
2723
      else if (this.type === types.ellipsis) {
2724
        elt = this.parseSpread(refDestructuringErrors);
2725
        if (refDestructuringErrors && this.type === types.comma && refDestructuringErrors.trailingComma < 0)
2726
          { refDestructuringErrors.trailingComma = this.start; }
2727
      } else {
2728
        elt = this.parseMaybeAssign(false, refDestructuringErrors);
2729
      }
2730
      elts.push(elt);
2731
    }
2732
    return elts
2733
  };
2734

    
2735
  pp$3.checkUnreserved = function(ref) {
2736
    var start = ref.start;
2737
    var end = ref.end;
2738
    var name = ref.name;
2739

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

    
2756
  // Parse the next token as an identifier. If `liberal` is true (used
2757
  // when parsing properties), it will also convert keywords into
2758
  // identifiers.
2759

    
2760
  pp$3.parseIdent = function(liberal, isBinding) {
2761
    var node = this.startNode();
2762
    if (this.type === types.name) {
2763
      node.name = this.value;
2764
    } else if (this.type.keyword) {
2765
      node.name = this.type.keyword;
2766

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

    
2788
  // Parses yield expression inside generator.
2789

    
2790
  pp$3.parseYield = function(noIn) {
2791
    if (!this.yieldPos) { this.yieldPos = this.start; }
2792

    
2793
    var node = this.startNode();
2794
    this.next();
2795
    if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) {
2796
      node.delegate = false;
2797
      node.argument = null;
2798
    } else {
2799
      node.delegate = this.eat(types.star);
2800
      node.argument = this.parseMaybeAssign(noIn);
2801
    }
2802
    return this.finishNode(node, "YieldExpression")
2803
  };
2804

    
2805
  pp$3.parseAwait = function() {
2806
    if (!this.awaitPos) { this.awaitPos = this.start; }
2807

    
2808
    var node = this.startNode();
2809
    this.next();
2810
    node.argument = this.parseMaybeUnary(null, true);
2811
    return this.finishNode(node, "AwaitExpression")
2812
  };
2813

    
2814
  var pp$4 = Parser.prototype;
2815

    
2816
  // This function is used to raise exceptions on parse errors. It
2817
  // takes an offset integer (into the current `input`) to indicate
2818
  // the location of the error, attaches the position to the end
2819
  // of the error message, and then raises a `SyntaxError` with that
2820
  // message.
2821

    
2822
  pp$4.raise = function(pos, message) {
2823
    var loc = getLineInfo(this.input, pos);
2824
    message += " (" + loc.line + ":" + loc.column + ")";
2825
    var err = new SyntaxError(message);
2826
    err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
2827
    throw err
2828
  };
2829

    
2830
  pp$4.raiseRecoverable = pp$4.raise;
2831

    
2832
  pp$4.curPosition = function() {
2833
    if (this.options.locations) {
2834
      return new Position(this.curLine, this.pos - this.lineStart)
2835
    }
2836
  };
2837

    
2838
  var pp$5 = Parser.prototype;
2839

    
2840
  var Scope = function Scope(flags) {
2841
    this.flags = flags;
2842
    // A list of var-declared names in the current lexical scope
2843
    this.var = [];
2844
    // A list of lexically-declared names in the current lexical scope
2845
    this.lexical = [];
2846
    // A list of lexically-declared FunctionDeclaration names in the current lexical scope
2847
    this.functions = [];
2848
  };
2849

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

    
2852
  pp$5.enterScope = function(flags) {
2853
    this.scopeStack.push(new Scope(flags));
2854
  };
2855

    
2856
  pp$5.exitScope = function() {
2857
    this.scopeStack.pop();
2858
  };
2859

    
2860
  // The spec says:
2861
  // > At the top level of a function, or script, function declarations are
2862
  // > treated like var declarations rather than like lexical declarations.
2863
  pp$5.treatFunctionsAsVarInScope = function(scope) {
2864
    return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
2865
  };
2866

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

    
2902
  pp$5.checkLocalExport = function(id) {
2903
    // scope.functions must be empty as Module code is always strict.
2904
    if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
2905
        this.scopeStack[0].var.indexOf(id.name) === -1) {
2906
      this.undefinedExports[id.name] = id;
2907
    }
2908
  };
2909

    
2910
  pp$5.currentScope = function() {
2911
    return this.scopeStack[this.scopeStack.length - 1]
2912
  };
2913

    
2914
  pp$5.currentVarScope = function() {
2915
    for (var i = this.scopeStack.length - 1;; i--) {
2916
      var scope = this.scopeStack[i];
2917
      if (scope.flags & SCOPE_VAR) { return scope }
2918
    }
2919
  };
2920

    
2921
  // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
2922
  pp$5.currentThisScope = function() {
2923
    for (var i = this.scopeStack.length - 1;; i--) {
2924
      var scope = this.scopeStack[i];
2925
      if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope }
2926
    }
2927
  };
2928

    
2929
  var Node = function Node(parser, pos, loc) {
2930
    this.type = "";
2931
    this.start = pos;
2932
    this.end = 0;
2933
    if (parser.options.locations)
2934
      { this.loc = new SourceLocation(parser, loc); }
2935
    if (parser.options.directSourceFile)
2936
      { this.sourceFile = parser.options.directSourceFile; }
2937
    if (parser.options.ranges)
2938
      { this.range = [pos, 0]; }
2939
  };
2940

    
2941
  // Start an AST node, attaching a start offset.
2942

    
2943
  var pp$6 = Parser.prototype;
2944

    
2945
  pp$6.startNode = function() {
2946
    return new Node(this, this.start, this.startLoc)
2947
  };
2948

    
2949
  pp$6.startNodeAt = function(pos, loc) {
2950
    return new Node(this, pos, loc)
2951
  };
2952

    
2953
  // Finish an AST node, adding `type` and `end` properties.
2954

    
2955
  function finishNodeAt(node, type, pos, loc) {
2956
    node.type = type;
2957
    node.end = pos;
2958
    if (this.options.locations)
2959
      { node.loc.end = loc; }
2960
    if (this.options.ranges)
2961
      { node.range[1] = pos; }
2962
    return node
2963
  }
2964

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

    
2969
  // Finish node at given position
2970

    
2971
  pp$6.finishNodeAt = function(node, type, pos, loc) {
2972
    return finishNodeAt.call(this, node, type, pos, loc)
2973
  };
2974

    
2975
  // The algorithm used to determine whether a regexp can appear at a
2976

    
2977
  var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
2978
    this.token = token;
2979
    this.isExpr = !!isExpr;
2980
    this.preserveSpace = !!preserveSpace;
2981
    this.override = override;
2982
    this.generator = !!generator;
2983
  };
2984

    
2985
  var types$1 = {
2986
    b_stat: new TokContext("{", false),
2987
    b_expr: new TokContext("{", true),
2988
    b_tmpl: new TokContext("${", false),
2989
    p_stat: new TokContext("(", false),
2990
    p_expr: new TokContext("(", true),
2991
    q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
2992
    f_stat: new TokContext("function", false),
2993
    f_expr: new TokContext("function", true),
2994
    f_expr_gen: new TokContext("function", true, false, null, true),
2995
    f_gen: new TokContext("function", false, false, null, true)
2996
  };
2997

    
2998
  var pp$7 = Parser.prototype;
2999

    
3000
  pp$7.initialContext = function() {
3001
    return [types$1.b_stat]
3002
  };
3003

    
3004
  pp$7.braceIsBlock = function(prevType) {
3005
    var parent = this.curContext();
3006
    if (parent === types$1.f_expr || parent === types$1.f_stat)
3007
      { return true }
3008
    if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
3009
      { return !parent.isExpr }
3010

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

    
3025
  pp$7.inGeneratorContext = function() {
3026
    for (var i = this.context.length - 1; i >= 1; i--) {
3027
      var context = this.context[i];
3028
      if (context.token === "function")
3029
        { return context.generator }
3030
    }
3031
    return false
3032
  };
3033

    
3034
  pp$7.updateContext = function(prevType) {
3035
    var update, type = this.type;
3036
    if (type.keyword && prevType === types.dot)
3037
      { this.exprAllowed = false; }
3038
    else if (update = type.updateContext)
3039
      { update.call(this, prevType); }
3040
    else
3041
      { this.exprAllowed = type.beforeExpr; }
3042
  };
3043

    
3044
  // Token-specific context update code
3045

    
3046
  types.parenR.updateContext = types.braceR.updateContext = function() {
3047
    if (this.context.length === 1) {
3048
      this.exprAllowed = true;
3049
      return
3050
    }
3051
    var out = this.context.pop();
3052
    if (out === types$1.b_stat && this.curContext().token === "function") {
3053
      out = this.context.pop();
3054
    }
3055
    this.exprAllowed = !out.isExpr;
3056
  };
3057

    
3058
  types.braceL.updateContext = function(prevType) {
3059
    this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
3060
    this.exprAllowed = true;
3061
  };
3062

    
3063
  types.dollarBraceL.updateContext = function() {
3064
    this.context.push(types$1.b_tmpl);
3065
    this.exprAllowed = true;
3066
  };
3067

    
3068
  types.parenL.updateContext = function(prevType) {
3069
    var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
3070
    this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
3071
    this.exprAllowed = true;
3072
  };
3073

    
3074
  types.incDec.updateContext = function() {
3075
    // tokExprAllowed stays unchanged
3076
  };
3077

    
3078
  types._function.updateContext = types._class.updateContext = function(prevType) {
3079
    if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
3080
        !(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
3081
        !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
3082
      { this.context.push(types$1.f_expr); }
3083
    else
3084
      { this.context.push(types$1.f_stat); }
3085
    this.exprAllowed = false;
3086
  };
3087

    
3088
  types.backQuote.updateContext = function() {
3089
    if (this.curContext() === types$1.q_tmpl)
3090
      { this.context.pop(); }
3091
    else
3092
      { this.context.push(types$1.q_tmpl); }
3093
    this.exprAllowed = false;
3094
  };
3095

    
3096
  types.star.updateContext = function(prevType) {
3097
    if (prevType === types._function) {
3098
      var index = this.context.length - 1;
3099
      if (this.context[index] === types$1.f_expr)
3100
        { this.context[index] = types$1.f_expr_gen; }
3101
      else
3102
        { this.context[index] = types$1.f_gen; }
3103
    }
3104
    this.exprAllowed = true;
3105
  };
3106

    
3107
  types.name.updateContext = function(prevType) {
3108
    var allowed = false;
3109
    if (this.options.ecmaVersion >= 6 && prevType !== types.dot) {
3110
      if (this.value === "of" && !this.exprAllowed ||
3111
          this.value === "yield" && this.inGeneratorContext())
3112
        { allowed = true; }
3113
    }
3114
    this.exprAllowed = allowed;
3115
  };
3116

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

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

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

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

    
3144
  var data = {};
3145
  function buildUnicodeData(ecmaVersion) {
3146
    var d = data[ecmaVersion] = {
3147
      binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues),
3148
      nonBinary: {
3149
        General_Category: wordsRegexp(unicodeGeneralCategoryValues),
3150
        Script: wordsRegexp(unicodeScriptValues[ecmaVersion])
3151
      }
3152
    };
3153
    d.nonBinary.Script_Extensions = d.nonBinary.Script;
3154

    
3155
    d.nonBinary.gc = d.nonBinary.General_Category;
3156
    d.nonBinary.sc = d.nonBinary.Script;
3157
    d.nonBinary.scx = d.nonBinary.Script_Extensions;
3158
  }
3159
  buildUnicodeData(9);
3160
  buildUnicodeData(10);
3161
  buildUnicodeData(11);
3162

    
3163
  var pp$8 = Parser.prototype;
3164

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

    
3184
  RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
3185
    var unicode = flags.indexOf("u") !== -1;
3186
    this.start = start | 0;
3187
    this.source = pattern + "";
3188
    this.flags = flags;
3189
    this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
3190
    this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
3191
  };
3192

    
3193
  RegExpValidationState.prototype.raise = function raise (message) {
3194
    this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
3195
  };
3196

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

    
3213
  RegExpValidationState.prototype.nextIndex = function nextIndex (i) {
3214
    var s = this.source;
3215
    var l = s.length;
3216
    if (i >= l) {
3217
      return l
3218
    }
3219
    var c = s.charCodeAt(i), next;
3220
    if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
3221
        (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
3222
      return i + 1
3223
    }
3224
    return i + 2
3225
  };
3226

    
3227
  RegExpValidationState.prototype.current = function current () {
3228
    return this.at(this.pos)
3229
  };
3230

    
3231
  RegExpValidationState.prototype.lookahead = function lookahead () {
3232
    return this.at(this.nextIndex(this.pos))
3233
  };
3234

    
3235
  RegExpValidationState.prototype.advance = function advance () {
3236
    this.pos = this.nextIndex(this.pos);
3237
  };
3238

    
3239
  RegExpValidationState.prototype.eat = function eat (ch) {
3240
    if (this.current() === ch) {
3241
      this.advance();
3242
      return true
3243
    }
3244
    return false
3245
  };
3246

    
3247
  function codePointToString(ch) {
3248
    if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
3249
    ch -= 0x10000;
3250
    return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
3251
  }
3252

    
3253
  /**
3254
   * Validate the flags part of a given RegExpLiteral.
3255
   *
3256
   * @param {RegExpValidationState} state The state to validate RegExp.
3257
   * @returns {void}
3258
   */
3259
  pp$8.validateRegExpFlags = function(state) {
3260
    var validFlags = state.validFlags;
3261
    var flags = state.flags;
3262

    
3263
    for (var i = 0; i < flags.length; i++) {
3264
      var flag = flags.charAt(i);
3265
      if (validFlags.indexOf(flag) === -1) {
3266
        this.raise(state.start, "Invalid regular expression flag");
3267
      }
3268
      if (flags.indexOf(flag, i + 1) > -1) {
3269
        this.raise(state.start, "Duplicate regular expression flag");
3270
      }
3271
    }
3272
  };
3273

    
3274
  /**
3275
   * Validate the pattern part of a given RegExpLiteral.
3276
   *
3277
   * @param {RegExpValidationState} state The state to validate RegExp.
3278
   * @returns {void}
3279
   */
3280
  pp$8.validateRegExpPattern = function(state) {
3281
    this.regexp_pattern(state);
3282

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

    
3294
  // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
3295
  pp$8.regexp_pattern = function(state) {
3296
    state.pos = 0;
3297
    state.lastIntValue = 0;
3298
    state.lastStringValue = "";
3299
    state.lastAssertionIsQuantifiable = false;
3300
    state.numCapturingParens = 0;
3301
    state.maxBackReference = 0;
3302
    state.groupNames.length = 0;
3303
    state.backReferenceNames.length = 0;
3304

    
3305
    this.regexp_disjunction(state);
3306

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

    
3322
      if (state.groupNames.indexOf(name) === -1) {
3323
        state.raise("Invalid named capture referenced");
3324
      }
3325
    }
3326
  };
3327

    
3328
  // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
3329
  pp$8.regexp_disjunction = function(state) {
3330
    this.regexp_alternative(state);
3331
    while (state.eat(0x7C /* | */)) {
3332
      this.regexp_alternative(state);
3333
    }
3334

    
3335
    // Make the same message as V8.
3336
    if (this.regexp_eatQuantifier(state, true)) {
3337
      state.raise("Nothing to repeat");
3338
    }
3339
    if (state.eat(0x7B /* { */)) {
3340
      state.raise("Lone quantifier brackets");
3341
    }
3342
  };
3343

    
3344
  // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
3345
  pp$8.regexp_alternative = function(state) {
3346
    while (state.pos < state.source.length && this.regexp_eatTerm(state))
3347
      { }
3348
  };
3349

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

    
3365
    if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
3366
      this.regexp_eatQuantifier(state);
3367
      return true
3368
    }
3369

    
3370
    return false
3371
  };
3372

    
3373
  // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
3374
  pp$8.regexp_eatAssertion = function(state) {
3375
    var start = state.pos;
3376
    state.lastAssertionIsQuantifiable = false;
3377

    
3378
    // ^, $
3379
    if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
3380
      return true
3381
    }
3382

    
3383
    // \b \B
3384
    if (state.eat(0x5C /* \ */)) {
3385
      if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
3386
        return true
3387
      }
3388
      state.pos = start;
3389
    }
3390

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

    
3407
    state.pos = start;
3408
    return false
3409
  };
3410

    
3411
  // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
3412
  pp$8.regexp_eatQuantifier = function(state, noError) {
3413
    if ( noError === void 0 ) noError = false;
3414

    
3415
    if (this.regexp_eatQuantifierPrefix(state, noError)) {
3416
      state.eat(0x3F /* ? */);
3417
      return true
3418
    }
3419
    return false
3420
  };
3421

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

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

    
3508
  // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
3509
  pp$8.regexp_eatExtendedAtom = function(state) {
3510
    return (
3511
      state.eat(0x2E /* . */) ||
3512
      this.regexp_eatReverseSolidusAtomEscape(state) ||
3513
      this.regexp_eatCharacterClass(state) ||
3514
      this.regexp_eatUncapturingGroup(state) ||
3515
      this.regexp_eatCapturingGroup(state) ||
3516
      this.regexp_eatInvalidBracedQuantifier(state) ||
3517
      this.regexp_eatExtendedPatternCharacter(state)
3518
    )
3519
  };
3520

    
3521
  // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
3522
  pp$8.regexp_eatInvalidBracedQuantifier = function(state) {
3523
    if (this.regexp_eatBracedQuantifier(state, true)) {
3524
      state.raise("Nothing to repeat");
3525
    }
3526
    return false
3527
  };
3528

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

    
3550
  // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
3551
  // But eat eager.
3552
  pp$8.regexp_eatPatternCharacters = function(state) {
3553
    var start = state.pos;
3554
    var ch = 0;
3555
    while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
3556
      state.advance();
3557
    }
3558
    return state.pos !== start
3559
  };
3560

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

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

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

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

    
3626
  // RegExpIdentifierStart[U] ::
3627
  //   UnicodeIDStart
3628
  //   `$`
3629
  //   `_`
3630
  //   `\` RegExpUnicodeEscapeSequence[?U]
3631
  pp$8.regexp_eatRegExpIdentifierStart = function(state) {
3632
    var start = state.pos;
3633
    var ch = state.current();
3634
    state.advance();
3635

    
3636
    if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
3637
      ch = state.lastIntValue;
3638
    }
3639
    if (isRegExpIdentifierStart(ch)) {
3640
      state.lastIntValue = ch;
3641
      return true
3642
    }
3643

    
3644
    state.pos = start;
3645
    return false
3646
  };
3647
  function isRegExpIdentifierStart(ch) {
3648
    return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
3649
  }
3650

    
3651
  // RegExpIdentifierPart[U] ::
3652
  //   UnicodeIDContinue
3653
  //   `$`
3654
  //   `_`
3655
  //   `\` RegExpUnicodeEscapeSequence[?U]
3656
  //   <ZWNJ>
3657
  //   <ZWJ>
3658
  pp$8.regexp_eatRegExpIdentifierPart = function(state) {
3659
    var start = state.pos;
3660
    var ch = state.current();
3661
    state.advance();
3662

    
3663
    if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
3664
      ch = state.lastIntValue;
3665
    }
3666
    if (isRegExpIdentifierPart(ch)) {
3667
      state.lastIntValue = ch;
3668
      return true
3669
    }
3670

    
3671
    state.pos = start;
3672
    return false
3673
  };
3674
  function isRegExpIdentifierPart(ch) {
3675
    return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
3676
  }
3677

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

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

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

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

    
3805
  // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
3806
  pp$8.regexp_eatRegExpUnicodeEscapeSequence = function(state) {
3807
    var start = state.pos;
3808

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

    
3841
    return false
3842
  };
3843
  function isValidUnicode(ch) {
3844
    return ch >= 0 && ch <= 0x10FFFF
3845
  }
3846

    
3847
  // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
3848
  pp$8.regexp_eatIdentityEscape = function(state) {
3849
    if (state.switchU) {
3850
      if (this.regexp_eatSyntaxCharacter(state)) {
3851
        return true
3852
      }
3853
      if (state.eat(0x2F /* / */)) {
3854
        state.lastIntValue = 0x2F; /* / */
3855
        return true
3856
      }
3857
      return false
3858
    }
3859

    
3860
    var ch = state.current();
3861
    if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
3862
      state.lastIntValue = ch;
3863
      state.advance();
3864
      return true
3865
    }
3866

    
3867
    return false
3868
  };
3869

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

    
3884
  // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
3885
  pp$8.regexp_eatCharacterClassEscape = function(state) {
3886
    var ch = state.current();
3887

    
3888
    if (isCharacterClassEscape(ch)) {
3889
      state.lastIntValue = -1;
3890
      state.advance();
3891
      return true
3892
    }
3893

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

    
3911
    return false
3912
  };
3913
  function isCharacterClassEscape(ch) {
3914
    return (
3915
      ch === 0x64 /* d */ ||
3916
      ch === 0x44 /* D */ ||
3917
      ch === 0x73 /* s */ ||
3918
      ch === 0x53 /* S */ ||
3919
      ch === 0x77 /* w */ ||
3920
      ch === 0x57 /* W */
3921
    )
3922
  }
3923

    
3924
  // UnicodePropertyValueExpression ::
3925
  //   UnicodePropertyName `=` UnicodePropertyValue
3926
  //   LoneUnicodePropertyNameOrValue
3927
  pp$8.regexp_eatUnicodePropertyValueExpression = function(state) {
3928
    var start = state.pos;
3929

    
3930
    // UnicodePropertyName `=` UnicodePropertyValue
3931
    if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
3932
      var name = state.lastStringValue;
3933
      if (this.regexp_eatUnicodePropertyValue(state)) {
3934
        var value = state.lastStringValue;
3935
        this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
3936
        return true
3937
      }
3938
    }
3939
    state.pos = start;
3940

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

    
3960
  // UnicodePropertyName ::
3961
  //   UnicodePropertyNameCharacters
3962
  pp$8.regexp_eatUnicodePropertyName = function(state) {
3963
    var ch = 0;
3964
    state.lastStringValue = "";
3965
    while (isUnicodePropertyNameCharacter(ch = state.current())) {
3966
      state.lastStringValue += codePointToString(ch);
3967
      state.advance();
3968
    }
3969
    return state.lastStringValue !== ""
3970
  };
3971
  function isUnicodePropertyNameCharacter(ch) {
3972
    return isControlLetter(ch) || ch === 0x5F /* _ */
3973
  }
3974

    
3975
  // UnicodePropertyValue ::
3976
  //   UnicodePropertyValueCharacters
3977
  pp$8.regexp_eatUnicodePropertyValue = function(state) {
3978
    var ch = 0;
3979
    state.lastStringValue = "";
3980
    while (isUnicodePropertyValueCharacter(ch = state.current())) {
3981
      state.lastStringValue += codePointToString(ch);
3982
      state.advance();
3983
    }
3984
    return state.lastStringValue !== ""
3985
  };
3986
  function isUnicodePropertyValueCharacter(ch) {
3987
    return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
3988
  }
3989

    
3990
  // LoneUnicodePropertyNameOrValue ::
3991
  //   UnicodePropertyValueCharacters
3992
  pp$8.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
3993
    return this.regexp_eatUnicodePropertyValue(state)
3994
  };
3995

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

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

    
4028
  // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
4029
  // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
4030
  pp$8.regexp_eatClassAtom = function(state) {
4031
    var start = state.pos;
4032

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

    
4048
    var ch = state.current();
4049
    if (ch !== 0x5D /* [ */) {
4050
      state.lastIntValue = ch;
4051
      state.advance();
4052
      return true
4053
    }
4054

    
4055
    return false
4056
  };
4057

    
4058
  // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
4059
  pp$8.regexp_eatClassEscape = function(state) {
4060
    var start = state.pos;
4061

    
4062
    if (state.eat(0x62 /* b */)) {
4063
      state.lastIntValue = 0x08; /* <BS> */
4064
      return true
4065
    }
4066

    
4067
    if (state.switchU && state.eat(0x2D /* - */)) {
4068
      state.lastIntValue = 0x2D; /* - */
4069
      return true
4070
    }
4071

    
4072
    if (!state.switchU && state.eat(0x63 /* c */)) {
4073
      if (this.regexp_eatClassControlLetter(state)) {
4074
        return true
4075
      }
4076
      state.pos = start;
4077
    }
4078

    
4079
    return (
4080
      this.regexp_eatCharacterClassEscape(state) ||
4081
      this.regexp_eatCharacterEscape(state)
4082
    )
4083
  };
4084

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

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

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

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

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

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

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

    
4207
  // Object type used to represent tokens. Note that normally, tokens
4208
  // simply exist as properties on the parser object. This is only
4209
  // used for the onToken callback and the external tokenizer.
4210

    
4211
  var Token = function Token(p) {
4212
    this.type = p.type;
4213
    this.value = p.value;
4214
    this.start = p.start;
4215
    this.end = p.end;
4216
    if (p.options.locations)
4217
      { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
4218
    if (p.options.ranges)
4219
      { this.range = [p.start, p.end]; }
4220
  };
4221

    
4222
  // ## Tokenizer
4223

    
4224
  var pp$9 = Parser.prototype;
4225

    
4226
  // Move to the next token
4227

    
4228
  pp$9.next = function() {
4229
    if (this.options.onToken)
4230
      { this.options.onToken(new Token(this)); }
4231

    
4232
    this.lastTokEnd = this.end;
4233
    this.lastTokStart = this.start;
4234
    this.lastTokEndLoc = this.endLoc;
4235
    this.lastTokStartLoc = this.startLoc;
4236
    this.nextToken();
4237
  };
4238

    
4239
  pp$9.getToken = function() {
4240
    this.next();
4241
    return new Token(this)
4242
  };
4243

    
4244
  // If we're in an ES6 environment, make parsers iterable
4245
  if (typeof Symbol !== "undefined")
4246
    { pp$9[Symbol.iterator] = function() {
4247
      var this$1 = this;
4248

    
4249
      return {
4250
        next: function () {
4251
          var token = this$1.getToken();
4252
          return {
4253
            done: token.type === types.eof,
4254
            value: token
4255
          }
4256
        }
4257
      }
4258
    }; }
4259

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

    
4263
  pp$9.curContext = function() {
4264
    return this.context[this.context.length - 1]
4265
  };
4266

    
4267
  // Read a single token, updating the parser object's token-related
4268
  // properties.
4269

    
4270
  pp$9.nextToken = function() {
4271
    var curContext = this.curContext();
4272
    if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
4273

    
4274
    this.start = this.pos;
4275
    if (this.options.locations) { this.startLoc = this.curPosition(); }
4276
    if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
4277

    
4278
    if (curContext.override) { return curContext.override(this) }
4279
    else { this.readToken(this.fullCharCodeAtPos()); }
4280
  };
4281

    
4282
  pp$9.readToken = function(code) {
4283
    // Identifier or keyword. '\uXXXX' sequences are allowed in
4284
    // identifiers, so '\' also dispatches to that.
4285
    if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
4286
      { return this.readWord() }
4287

    
4288
    return this.getTokenFromCode(code)
4289
  };
4290

    
4291
  pp$9.fullCharCodeAtPos = function() {
4292
    var code = this.input.charCodeAt(this.pos);
4293
    if (code <= 0xd7ff || code >= 0xe000) { return code }
4294
    var next = this.input.charCodeAt(this.pos + 1);
4295
    return (code << 10) + next - 0x35fdc00
4296
  };
4297

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

    
4316
  pp$9.skipLineComment = function(startSkip) {
4317
    var start = this.pos;
4318
    var startLoc = this.options.onComment && this.curPosition();
4319
    var ch = this.input.charCodeAt(this.pos += startSkip);
4320
    while (this.pos < this.input.length && !isNewLine(ch)) {
4321
      ch = this.input.charCodeAt(++this.pos);
4322
    }
4323
    if (this.options.onComment)
4324
      { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
4325
                             startLoc, this.curPosition()); }
4326
  };
4327

    
4328
  // Called at the start of the parse and after every token. Skips
4329
  // whitespace and comments, and.
4330

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

    
4371
  // Called at the end of every token. Sets `end`, `val`, and
4372
  // maintains `context` and `exprAllowed`, and skips the space after
4373
  // the token, so that the next one's `start` will point at the
4374
  // right position.
4375

    
4376
  pp$9.finishToken = function(type, val) {
4377
    this.end = this.pos;
4378
    if (this.options.locations) { this.endLoc = this.curPosition(); }
4379
    var prevType = this.type;
4380
    this.type = type;
4381
    this.value = val;
4382

    
4383
    this.updateContext(prevType);
4384
  };
4385

    
4386
  // ### Token reading
4387

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

    
4408
  pp$9.readToken_slash = function() { // '/'
4409
    var next = this.input.charCodeAt(this.pos + 1);
4410
    if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
4411
    if (next === 61) { return this.finishOp(types.assign, 2) }
4412
    return this.finishOp(types.slash, 1)
4413
  };
4414

    
4415
  pp$9.readToken_mult_modulo_exp = function(code) { // '%*'
4416
    var next = this.input.charCodeAt(this.pos + 1);
4417
    var size = 1;
4418
    var tokentype = code === 42 ? types.star : types.modulo;
4419

    
4420
    // exponentiation operator ** and **=
4421
    if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
4422
      ++size;
4423
      tokentype = types.starstar;
4424
      next = this.input.charCodeAt(this.pos + 2);
4425
    }
4426

    
4427
    if (next === 61) { return this.finishOp(types.assign, size + 1) }
4428
    return this.finishOp(tokentype, size)
4429
  };
4430

    
4431
  pp$9.readToken_pipe_amp = function(code) { // '|&'
4432
    var next = this.input.charCodeAt(this.pos + 1);
4433
    if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
4434
    if (next === 61) { return this.finishOp(types.assign, 2) }
4435
    return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
4436
  };
4437

    
4438
  pp$9.readToken_caret = function() { // '^'
4439
    var next = this.input.charCodeAt(this.pos + 1);
4440
    if (next === 61) { return this.finishOp(types.assign, 2) }
4441
    return this.finishOp(types.bitwiseXOR, 1)
4442
  };
4443

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

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

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

    
4489
  pp$9.getTokenFromCode = function(code) {
4490
    switch (code) {
4491
    // The interpretation of a dot depends on whether it is followed
4492
    // by a digit or another two dots.
4493
    case 46: // '.'
4494
      return this.readToken_dot()
4495

    
4496
    // Punctuation tokens.
4497
    case 40: ++this.pos; return this.finishToken(types.parenL)
4498
    case 41: ++this.pos; return this.finishToken(types.parenR)
4499
    case 59: ++this.pos; return this.finishToken(types.semi)
4500
    case 44: ++this.pos; return this.finishToken(types.comma)
4501
    case 91: ++this.pos; return this.finishToken(types.bracketL)
4502
    case 93: ++this.pos; return this.finishToken(types.bracketR)
4503
    case 123: ++this.pos; return this.finishToken(types.braceL)
4504
    case 125: ++this.pos; return this.finishToken(types.braceR)
4505
    case 58: ++this.pos; return this.finishToken(types.colon)
4506
    case 63: ++this.pos; return this.finishToken(types.question)
4507

    
4508
    case 96: // '`'
4509
      if (this.options.ecmaVersion < 6) { break }
4510
      ++this.pos;
4511
      return this.finishToken(types.backQuote)
4512

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

    
4521
    // Anything else beginning with a digit is an integer, octal
4522
    // number, or float.
4523
    case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
4524
      return this.readNumber(false)
4525

    
4526
    // Quotes produce strings.
4527
    case 34: case 39: // '"', "'"
4528
      return this.readString(code)
4529

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

    
4535
    case 47: // '/'
4536
      return this.readToken_slash()
4537

    
4538
    case 37: case 42: // '%*'
4539
      return this.readToken_mult_modulo_exp(code)
4540

    
4541
    case 124: case 38: // '|&'
4542
      return this.readToken_pipe_amp(code)
4543

    
4544
    case 94: // '^'
4545
      return this.readToken_caret()
4546

    
4547
    case 43: case 45: // '+-'
4548
      return this.readToken_plus_min(code)
4549

    
4550
    case 60: case 62: // '<>'
4551
      return this.readToken_lt_gt(code)
4552

    
4553
    case 61: case 33: // '=!'
4554
      return this.readToken_eq_excl(code)
4555

    
4556
    case 126: // '~'
4557
      return this.finishOp(types.prefix, 1)
4558
    }
4559

    
4560
    this.raise(this.pos, "Unexpected character '" + codePointToString$1(code) + "'");
4561
  };
4562

    
4563
  pp$9.finishOp = function(type, size) {
4564
    var str = this.input.slice(this.pos, this.pos + size);
4565
    this.pos += size;
4566
    return this.finishToken(type, str)
4567
  };
4568

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

    
4589
    // Validate pattern
4590
    var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
4591
    state.reset(start, pattern, flags);
4592
    this.validateRegExpFlags(state);
4593
    this.validateRegExpPattern(state);
4594

    
4595
    // Create Literal#value property value.
4596
    var value = null;
4597
    try {
4598
      value = new RegExp(pattern, flags);
4599
    } catch (e) {
4600
      // ESTree requires null if it failed to instantiate RegExp object.
4601
      // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
4602
    }
4603

    
4604
    return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
4605
  };
4606

    
4607
  // Read an integer in the given radix. Return null if zero digits
4608
  // were read, the integer value otherwise. When `len` is given, this
4609
  // will return `null` unless the integer has exactly `len` digits.
4610

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

    
4625
    return total
4626
  };
4627

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

    
4640
  // Read an integer, octal integer, or floating-point number.
4641

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

    
4668
    var str = this.input.slice(start, this.pos);
4669
    var val = octal ? parseInt(str, 8) : parseFloat(str);
4670
    return this.finishToken(types.num, val)
4671
  };
4672

    
4673
  // Read a string value, interpreting backslash-escapes.
4674

    
4675
  pp$9.readCodePoint = function() {
4676
    var ch = this.input.charCodeAt(this.pos), code;
4677

    
4678
    if (ch === 123) { // '{'
4679
      if (this.options.ecmaVersion < 6) { this.unexpected(); }
4680
      var codePos = ++this.pos;
4681
      code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
4682
      ++this.pos;
4683
      if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
4684
    } else {
4685
      code = this.readHexChar(4);
4686
    }
4687
    return code
4688
  };
4689

    
4690
  function codePointToString$1(code) {
4691
    // UTF-16 Decoding
4692
    if (code <= 0xFFFF) { return String.fromCharCode(code) }
4693
    code -= 0x10000;
4694
    return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
4695
  }
4696

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

    
4716
  // Reads template string tokens.
4717

    
4718
  var INVALID_TEMPLATE_ESCAPE_ERROR = {};
4719

    
4720
  pp$9.tryReadTemplateToken = function() {
4721
    this.inTemplateElement = true;
4722
    try {
4723
      this.readTmplToken();
4724
    } catch (err) {
4725
      if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
4726
        this.readInvalidTemplateToken();
4727
      } else {
4728
        throw err
4729
      }
4730
    }
4731

    
4732
    this.inTemplateElement = false;
4733
  };
4734

    
4735
  pp$9.invalidStringToken = function(position, message) {
4736
    if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
4737
      throw INVALID_TEMPLATE_ESCAPE_ERROR
4738
    } else {
4739
      this.raise(position, message);
4740
    }
4741
  };
4742

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

    
4789
  // Reads a template token to search for the end, without validating any escape sequences
4790
  pp$9.readInvalidTemplateToken = function() {
4791
    for (; this.pos < this.input.length; this.pos++) {
4792
      switch (this.input[this.pos]) {
4793
      case "\\":
4794
        ++this.pos;
4795
        break
4796

    
4797
      case "$":
4798
        if (this.input[this.pos + 1] !== "{") {
4799
          break
4800
        }
4801
      // falls through
4802

    
4803
      case "`":
4804
        return this.finishToken(types.invalidTemplate, this.input.slice(this.start, this.pos))
4805

    
4806
      // no default
4807
      }
4808
    }
4809
    this.raise(this.start, "Unterminated template");
4810
  };
4811

    
4812
  // Used to read escaped characters
4813

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

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

    
4861
  pp$9.readHexChar = function(len) {
4862
    var codePos = this.pos;
4863
    var n = this.readInt(16, len);
4864
    if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
4865
    return n
4866
  };
4867

    
4868
  // Read an identifier, and return it as a string. Sets `this.containsEsc`
4869
  // to whether the word contained a '\u' escape.
4870
  //
4871
  // Incrementally adds only escaped chars, adding other chunks as-is
4872
  // as a micro-optimization.
4873

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

    
4902
  // Read an identifier or keyword token. Will check for reserved
4903
  // words when necessary.
4904

    
4905
  pp$9.readWord = function() {
4906
    var word = this.readWord1();
4907
    var type = types.name;
4908
    if (this.keywords.test(word)) {
4909
      if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
4910
      type = keywords$1[word];
4911
    }
4912
    return this.finishToken(type, word)
4913
  };
4914

    
4915
  // Acorn is a tiny, fast JavaScript parser written in JavaScript.
4916

    
4917
  var version = "6.4.0";
4918

    
4919
  Parser.acorn = {
4920
    Parser: Parser,
4921
    version: version,
4922
    defaultOptions: defaultOptions,
4923
    Position: Position,
4924
    SourceLocation: SourceLocation,
4925
    getLineInfo: getLineInfo,
4926
    Node: Node,
4927
    TokenType: TokenType,
4928
    tokTypes: types,
4929
    keywordTypes: keywords$1,
4930
    TokContext: TokContext,
4931
    tokContexts: types$1,
4932
    isIdentifierChar: isIdentifierChar,
4933
    isIdentifierStart: isIdentifierStart,
4934
    Token: Token,
4935
    isNewLine: isNewLine,
4936
    lineBreak: lineBreak,
4937
    lineBreakG: lineBreakG,
4938
    nonASCIIwhitespace: nonASCIIwhitespace
4939
  };
4940

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

    
4948
  function parse(input, options) {
4949
    return Parser.parse(input, options)
4950
  }
4951

    
4952
  // This function tries to parse a single expression at a given
4953
  // offset in a string. Useful for parsing mixed-language formats
4954
  // that embed JavaScript expressions.
4955

    
4956
  function parseExpressionAt(input, pos, options) {
4957
    return Parser.parseExpressionAt(input, pos, options)
4958
  }
4959

    
4960
  // Acorn is organized as a tokenizer and a recursive-descent parser.
4961
  // The `tokenizer` export provides an interface to the tokenizer.
4962

    
4963
  function tokenizer(input, options) {
4964
    return Parser.tokenizer(input, options)
4965
  }
4966

    
4967
  exports.Node = Node;
4968
  exports.Parser = Parser;
4969
  exports.Position = Position;
4970
  exports.SourceLocation = SourceLocation;
4971
  exports.TokContext = TokContext;
4972
  exports.Token = Token;
4973
  exports.TokenType = TokenType;
4974
  exports.defaultOptions = defaultOptions;
4975
  exports.getLineInfo = getLineInfo;
4976
  exports.isIdentifierChar = isIdentifierChar;
4977
  exports.isIdentifierStart = isIdentifierStart;
4978
  exports.isNewLine = isNewLine;
4979
  exports.keywordTypes = keywords$1;
4980
  exports.lineBreak = lineBreak;
4981
  exports.lineBreakG = lineBreakG;
4982
  exports.nonASCIIwhitespace = nonASCIIwhitespace;
4983
  exports.parse = parse;
4984
  exports.parseExpressionAt = parseExpressionAt;
4985
  exports.tokContexts = types$1;
4986
  exports.tokTypes = types;
4987
  exports.tokenizer = tokenizer;
4988
  exports.version = version;
4989

    
4990
  Object.defineProperty(exports, '__esModule', { value: true });
4991

    
4992
}));
(2-2/6)