meriyah 4.5.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +340 -449
  2. package/README.md +22 -28
  3. package/dist/meriyah.amd.js +8916 -8806
  4. package/dist/meriyah.amd.min.js +1 -1
  5. package/dist/meriyah.cjs +8916 -8806
  6. package/dist/meriyah.cjs.js +8916 -8806
  7. package/dist/meriyah.cjs.min.js +1 -1
  8. package/dist/meriyah.esm.js +8916 -8806
  9. package/dist/meriyah.esm.min.js +1 -1
  10. package/dist/meriyah.esm.min.mjs +1 -1
  11. package/dist/meriyah.esm.mjs +8916 -8806
  12. package/dist/meriyah.iife.js +8916 -8806
  13. package/dist/meriyah.iife.min.js +1 -1
  14. package/dist/meriyah.min.cjs +1 -1
  15. package/dist/meriyah.system.js +8916 -8806
  16. package/dist/meriyah.system.min.js +1 -1
  17. package/dist/meriyah.umd.cjs +8916 -8806
  18. package/dist/meriyah.umd.es5.js +8925 -8830
  19. package/dist/meriyah.umd.es5.min.js +1 -1
  20. package/dist/meriyah.umd.js +8916 -8806
  21. package/dist/meriyah.umd.min.cjs +1 -1
  22. package/dist/meriyah.umd.min.js +1 -1
  23. package/dist/src/chars.d.ts +135 -135
  24. package/dist/src/common.d.ts +201 -200
  25. package/dist/src/common.d.ts.map +1 -1
  26. package/dist/src/errors.d.ts +188 -187
  27. package/dist/src/errors.d.ts.map +1 -1
  28. package/dist/src/estree.d.ts +515 -507
  29. package/dist/src/estree.d.ts.map +1 -1
  30. package/dist/src/lexer/charClassifier.d.ts +24 -24
  31. package/dist/src/lexer/charClassifier.d.ts.map +1 -1
  32. package/dist/src/lexer/comments.d.ts +14 -14
  33. package/dist/src/lexer/common.d.ts +26 -26
  34. package/dist/src/lexer/decodeHTML.d.ts +1 -1
  35. package/dist/src/lexer/decodeHTML.d.ts.map +1 -1
  36. package/dist/src/lexer/identifier.d.ts +8 -8
  37. package/dist/src/lexer/index.d.ts +9 -9
  38. package/dist/src/lexer/jsx.d.ts +6 -6
  39. package/dist/src/lexer/jsx.d.ts.map +1 -1
  40. package/dist/src/lexer/numeric.d.ts +5 -5
  41. package/dist/src/lexer/regexp.d.ts +3 -3
  42. package/dist/src/lexer/scan.d.ts +6 -6
  43. package/dist/src/lexer/scan.d.ts.map +1 -1
  44. package/dist/src/lexer/string.d.ts +12 -12
  45. package/dist/src/lexer/template.d.ts +4 -4
  46. package/dist/src/meriyah.d.ts +7 -7
  47. package/dist/src/meriyah.d.ts.map +1 -1
  48. package/dist/src/parser.d.ts +119 -118
  49. package/dist/src/parser.d.ts.map +1 -1
  50. package/dist/src/token.d.ts +167 -167
  51. package/dist/src/unicode.d.ts +5 -5
  52. package/package.json +32 -27
  53. package/src/common.ts +42 -49
  54. package/src/errors.ts +3 -1
  55. package/src/estree.ts +11 -1
  56. package/src/lexer/comments.ts +1 -1
  57. package/src/lexer/decodeHTML.ts +3 -5
  58. package/src/lexer/identifier.ts +4 -4
  59. package/src/lexer/jsx.ts +13 -12
  60. package/src/lexer/numeric.ts +2 -2
  61. package/src/lexer/regexp.ts +3 -3
  62. package/src/lexer/scan.ts +8 -6
  63. package/src/lexer/string.ts +2 -2
  64. package/src/meriyah.ts +1 -2
  65. package/src/parser.ts +681 -533
package/src/parser.ts CHANGED
@@ -59,6 +59,8 @@ export function create(
59
59
  onToken: OnToken | void,
60
60
  onInsertedSemicolon: OnInsertedSemicolon | void
61
61
  ): ParserState {
62
+ let token = Token.EOF;
63
+
62
64
  return {
63
65
  /**
64
66
  * The source code to be parsed
@@ -132,9 +134,22 @@ export function create(
132
134
  tokenValue: '',
133
135
 
134
136
  /**
135
- * The current token in the stream to consume
137
+ * Get the current token in the stream to consume
138
+ * This function exists as workaround for TS issue
139
+ * https://github.com/microsoft/TypeScript/issues/9998
140
+ */
141
+ getToken() {
142
+ return token;
143
+ },
144
+
145
+ /**
146
+ * Set the current token in the stream to consume
147
+ * This function exists as workaround for TS issue
148
+ * https://github.com/microsoft/TypeScript/issues/9998
136
149
  */
137
- token: Token.EOF,
150
+ setToken(value: Token) {
151
+ return (token = value);
152
+ },
138
153
 
139
154
  /**
140
155
  * Holds the raw text that have been scanned by the lexer
@@ -272,7 +287,7 @@ export function parseSource(source: string, options: Options | void, context: Co
272
287
  const parser = create(source, sourceFile, onComment, onToken, onInsertedSemicolon);
273
288
 
274
289
  // See: https://github.com/tc39/proposal-hashbang
275
- if (context & Context.OptionsNext) skipHashBang(parser);
290
+ skipHashBang(parser);
276
291
 
277
292
  const scope: ScopeState | undefined = context & Context.OptionsLexical ? createScope() : void 0;
278
293
 
@@ -338,15 +353,16 @@ export function parseStatementList(
338
353
 
339
354
  const statements: ESTree.Statement[] = [];
340
355
 
341
- while (parser.token === Token.StringLiteral) {
356
+ while (parser.getToken() === Token.StringLiteral) {
342
357
  // "use strict" must be the exact literal without escape sequences or line continuation.
343
- const { index, tokenPos, tokenValue, linePos, colPos, token } = parser;
358
+ const { index, tokenPos, tokenValue, linePos, colPos } = parser;
359
+ const token = parser.getToken();
344
360
  const expr = parseLiteral(parser, context);
345
361
  if (isValidStrictMode(parser, index, tokenPos, tokenValue)) context |= Context.Strict;
346
362
  statements.push(parseDirective(parser, context, expr, token, tokenPos, linePos, colPos));
347
363
  }
348
364
 
349
- while (parser.token !== Token.EOF) {
365
+ while (parser.getToken() !== Token.EOF) {
350
366
  statements.push(parseStatementListItem(parser, context, scope, Origin.TopLevel, {}) as ESTree.Statement);
351
367
  }
352
368
  return statements;
@@ -381,13 +397,14 @@ export function parseModuleItemList(
381
397
  // most of the time, considering the prevalence of strict mode and the fact modules
382
398
  // are already in strict mode.
383
399
  if (context & Context.OptionsDirectives) {
384
- while (parser.token === Token.StringLiteral) {
385
- const { tokenPos, linePos, colPos, token } = parser;
400
+ while (parser.getToken() === Token.StringLiteral) {
401
+ const { tokenPos, linePos, colPos } = parser;
402
+ const token = parser.getToken();
386
403
  statements.push(parseDirective(parser, context, parseLiteral(parser, context), token, tokenPos, linePos, colPos));
387
404
  }
388
405
  }
389
406
 
390
- while (parser.token !== Token.EOF) {
407
+ while (parser.getToken() !== Token.EOF) {
391
408
  statements.push(parseModuleItem(parser, context, scope) as ESTree.Statement);
392
409
  }
393
410
  return statements;
@@ -414,7 +431,7 @@ export function parseModuleItem(parser: ParserState, context: Context, scope: Sc
414
431
  // StatementListItem
415
432
 
416
433
  let moduleItem;
417
- switch (parser.token) {
434
+ switch (parser.getToken()) {
418
435
  case Token.ExportKeyword:
419
436
  moduleItem = parseExportDeclaration(parser, context, scope);
420
437
  break;
@@ -466,7 +483,7 @@ export function parseStatementListItem(
466
483
  const line = parser.linePos;
467
484
  const column = parser.colPos;
468
485
 
469
- switch (parser.token) {
486
+ switch (parser.getToken()) {
470
487
  // HoistableDeclaration[?Yield, ~Default]
471
488
  case Token.FunctionKeyword:
472
489
  return parseFunctionDeclaration(
@@ -481,10 +498,9 @@ export function parseStatementListItem(
481
498
  line,
482
499
  column
483
500
  );
484
- // @decorator
485
- case Token.Decorator:
486
- // ClassDeclaration[?Yield, ~Default]
487
- case Token.ClassKeyword:
501
+
502
+ case Token.Decorator: // @decorator
503
+ case Token.ClassKeyword: // ClassDeclaration[?Yield, ~Default]
488
504
  return parseClassDeclaration(parser, context, scope, HoistedClassFlags.None, start, line, column);
489
505
  // LexicalDeclaration[In, ?Yield]
490
506
  // LetOrConst BindingList[?In, ?Yield]
@@ -498,7 +514,7 @@ export function parseStatementListItem(
498
514
  // ImportDeclaration
499
515
  case Token.ImportKeyword:
500
516
  nextToken(parser, context);
501
- switch (parser.token) {
517
+ switch (parser.getToken()) {
502
518
  case Token.LeftParen:
503
519
  return parseImportCallDeclaration(parser, context, start, line, column);
504
520
  case Token.Period:
@@ -551,7 +567,7 @@ export function parseStatement(
551
567
  // TryStatement
552
568
  // DebuggerStatement
553
569
 
554
- switch (parser.token) {
570
+ switch (parser.getToken()) {
555
571
  // VariableStatement[?Yield]
556
572
  case Token.VarKeyword:
557
573
  return parseVariableStatement(parser, context, scope, Origin.None, start, line, column);
@@ -619,8 +635,8 @@ export function parseStatement(
619
635
  context & Context.Strict
620
636
  ? Errors.StrictFunction
621
637
  : (context & Context.OptionsWebCompat) === 0
622
- ? Errors.WebCompatFunction
623
- : Errors.SloppyFunction
638
+ ? Errors.WebCompatFunction
639
+ : Errors.SloppyFunction
624
640
  );
625
641
  case Token.ClassKeyword:
626
642
  report(parser, Errors.ClassForbiddenAsStatement);
@@ -666,7 +682,8 @@ export function parseExpressionOrLabelledStatement(
666
682
  // ExpressionStatement[Yield] :
667
683
  // [lookahead notin {{, function, class, let [}] Expression[In, ?Yield] ;
668
684
 
669
- const { tokenValue, token } = parser;
685
+ const { tokenValue } = parser;
686
+ const token = parser.getToken();
670
687
 
671
688
  let expr: ESTree.Expression;
672
689
 
@@ -678,7 +695,7 @@ export function parseExpressionOrLabelledStatement(
678
695
  // "let" followed by either "[", "{" or an identifier means a lexical
679
696
  // declaration, which should not appear here.
680
697
  // However, ASI may insert a line break before an identifier or a brace.
681
- if (parser.token === Token.LeftBracket) report(parser, Errors.RestrictedLetProduction);
698
+ if (parser.getToken() === Token.LeftBracket) report(parser, Errors.RestrictedLetProduction);
682
699
 
683
700
  break;
684
701
 
@@ -706,7 +723,7 @@ export function parseExpressionOrLabelledStatement(
706
723
  * ExpressionStatement[Yield] :
707
724
  * [lookahead notin {{, function, class, let [}] Expression[In, ?Yield] ;
708
725
  */
709
- if (token & Token.IsIdentifier && parser.token === Token.Colon) {
726
+ if (token & Token.IsIdentifier && parser.getToken() === Token.Colon) {
710
727
  return parseLabelledStatement(
711
728
  parser,
712
729
  context,
@@ -759,7 +776,7 @@ export function parseExpressionOrLabelledStatement(
759
776
  * https://github.com/estree/estree/blob/master/es5.md#sequenceexpression
760
777
  *
761
778
  */
762
- if (parser.token === Token.Comma) {
779
+ if (parser.getToken() === Token.Comma) {
763
780
  expr = parseSequenceExpression(parser, context, 0, start, line, column, expr);
764
781
  }
765
782
 
@@ -799,7 +816,7 @@ export function parseBlock(
799
816
  // '{' StatementList '}'
800
817
  const body: ESTree.Statement[] = [];
801
818
  consume(parser, context | Context.AllowRegExp, Token.LeftBrace);
802
- while (parser.token !== Token.RightBrace) {
819
+ while (parser.getToken() !== Token.RightBrace) {
803
820
  body.push(parseStatementListItem(parser, context, scope, Origin.BlockStatement, { $: labels }) as any);
804
821
  }
805
822
 
@@ -836,7 +853,7 @@ export function parseReturnStatement(
836
853
  nextToken(parser, context | Context.AllowRegExp);
837
854
 
838
855
  const argument =
839
- parser.flags & Flags.NewLine || parser.token & Token.IsAutoSemicolon
856
+ parser.flags & Flags.NewLine || parser.getToken() & Token.IsAutoSemicolon
840
857
  ? null
841
858
  : parseExpressions(parser, context, 0, 1, parser.tokenPos, parser.linePos, parser.colPos);
842
859
 
@@ -917,7 +934,7 @@ export function parseLabelledStatement(
917
934
  context & Context.OptionsWebCompat &&
918
935
  // In sloppy mode, Annex B.3.2 allows labelled function declarations.
919
936
  // Otherwise it's a parse error.
920
- parser.token === Token.FunctionKeyword
937
+ parser.getToken() === Token.FunctionKeyword
921
938
  ? parseFunctionDeclaration(
922
939
  parser,
923
940
  context,
@@ -991,11 +1008,12 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration(
991
1008
  // AsyncFunctionBody:
992
1009
  // FunctionBody[~Yield, +Await]
993
1010
 
994
- const { token, tokenValue } = parser;
1011
+ const { tokenValue } = parser;
1012
+ const token = parser.getToken();
995
1013
 
996
1014
  let expr: ESTree.Expression = parseIdentifier(parser, context);
997
1015
 
998
- if (parser.token === Token.Colon) {
1016
+ if (parser.getToken() === Token.Colon) {
999
1017
  return parseLabelledStatement(
1000
1018
  parser,
1001
1019
  context,
@@ -1016,7 +1034,7 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration(
1016
1034
 
1017
1035
  if (!asyncNewLine) {
1018
1036
  // async function ...
1019
- if (parser.token === Token.FunctionKeyword) {
1037
+ if (parser.getToken() === Token.FunctionKeyword) {
1020
1038
  if (!allowFuncDecl) report(parser, Errors.AsyncFunctionInSingleStatementContext);
1021
1039
 
1022
1040
  return parseFunctionDeclaration(
@@ -1034,12 +1052,13 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration(
1034
1052
  }
1035
1053
 
1036
1054
  // async Identifier => ...
1037
- if ((parser.token & Token.IsIdentifier) === Token.IsIdentifier) {
1055
+ if ((parser.getToken() & Token.IsIdentifier) === Token.IsIdentifier) {
1038
1056
  /** ArrowFunction[In, Yield, Await]:
1039
1057
  * ArrowParameters[?Yield, ?Await][no LineTerminator here]=>ConciseBody[?In]
1040
1058
  */
1041
1059
  expr = parseAsyncArrowAfterIdent(parser, context, /* assignable */ 1, start, line, column);
1042
- if (parser.token === Token.Comma) expr = parseSequenceExpression(parser, context, 0, start, line, column, expr);
1060
+ if (parser.getToken() === Token.Comma)
1061
+ expr = parseSequenceExpression(parser, context, 0, start, line, column, expr);
1043
1062
 
1044
1063
  /**
1045
1064
  * ExpressionStatement[Yield, Await]:
@@ -1052,7 +1071,7 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration(
1052
1071
  /** ArrowFunction[In, Yield, Await]:
1053
1072
  * ArrowParameters[?Yield, ?Await][no LineTerminator here]=>ConciseBody[?In]
1054
1073
  */
1055
- if (parser.token === Token.LeftParen) {
1074
+ if (parser.getToken() === Token.LeftParen) {
1056
1075
  expr = parseAsyncArrowOrCallExpression(
1057
1076
  parser,
1058
1077
  context,
@@ -1066,7 +1085,7 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration(
1066
1085
  column
1067
1086
  );
1068
1087
  } else {
1069
- if (parser.token === Token.Arrow) {
1088
+ if (parser.getToken() === Token.Arrow) {
1070
1089
  classifyIdentifier(parser, context, token);
1071
1090
  expr = parseArrowFromIdentifier(parser, context, parser.tokenValue, expr, 0, 1, 0, start, line, column);
1072
1091
  }
@@ -1112,7 +1131,7 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration(
1112
1131
  * https://github.com/estree/estree/blob/master/es5.md#sequenceexpression
1113
1132
  *
1114
1133
  */
1115
- if (parser.token === Token.Comma) {
1134
+ if (parser.getToken() === Token.Comma) {
1116
1135
  expr = parseSequenceExpression(parser, context, 0, start, line, column, expr);
1117
1136
  }
1118
1137
 
@@ -1151,10 +1170,10 @@ export function parseDirective(
1151
1170
 
1152
1171
  expression = parseMemberOrUpdateExpression(parser, context, expression, 0, 0, start, line, column);
1153
1172
 
1154
- if (parser.token !== Token.Semicolon) {
1173
+ if (parser.getToken() !== Token.Semicolon) {
1155
1174
  expression = parseAssignmentExpression(parser, context, 0, 0, start, line, column, expression);
1156
1175
 
1157
- if (parser.token === Token.Comma) {
1176
+ if (parser.getToken() === Token.Comma) {
1158
1177
  expression = parseSequenceExpression(parser, context, 0, start, line, column, expression);
1159
1178
  }
1160
1179
  }
@@ -1276,7 +1295,7 @@ export function parseIfStatement(
1276
1295
  parser.colPos
1277
1296
  );
1278
1297
  let alternate: ESTree.Statement | null = null;
1279
- if (parser.token === Token.ElseKeyword) {
1298
+ if (parser.getToken() === Token.ElseKeyword) {
1280
1299
  nextToken(parser, context | Context.AllowRegExp);
1281
1300
  alternate = parseConsequentOrAlternative(
1282
1301
  parser,
@@ -1318,7 +1337,7 @@ export function parseConsequentOrAlternative(
1318
1337
  return context & Context.Strict ||
1319
1338
  // Disallow if web compatibility is off
1320
1339
  (context & Context.OptionsWebCompat) === 0 ||
1321
- parser.token !== Token.FunctionKeyword
1340
+ parser.getToken() !== Token.FunctionKeyword
1322
1341
  ? parseStatement(
1323
1342
  parser,
1324
1343
  context,
@@ -1377,7 +1396,7 @@ export function parseSwitchStatement(
1377
1396
  const cases: ESTree.SwitchCase[] = [];
1378
1397
  let seenDefault: 0 | 1 = 0;
1379
1398
  if (scope) scope = addChildScope(scope, ScopeKind.SwitchStatement);
1380
- while (parser.token !== Token.RightBrace) {
1399
+ while (parser.getToken() !== Token.RightBrace) {
1381
1400
  const { tokenPos, linePos, colPos } = parser;
1382
1401
  let test: ESTree.Expression | null = null;
1383
1402
  const consequent: ESTree.Statement[] = [];
@@ -1390,9 +1409,9 @@ export function parseSwitchStatement(
1390
1409
  }
1391
1410
  consume(parser, context | Context.AllowRegExp, Token.Colon);
1392
1411
  while (
1393
- parser.token !== Token.CaseKeyword &&
1394
- parser.token !== Token.RightBrace &&
1395
- parser.token !== Token.DefaultKeyword
1412
+ parser.getToken() !== Token.CaseKeyword &&
1413
+ parser.getToken() !== Token.RightBrace &&
1414
+ parser.getToken() !== Token.DefaultKeyword
1396
1415
  ) {
1397
1416
  consequent.push(
1398
1417
  parseStatementListItem(parser, context | Context.InSwitch, scope, Origin.BlockStatement, {
@@ -1504,7 +1523,7 @@ export function parseContinueStatement(
1504
1523
  if ((context & Context.InIteration) === 0) report(parser, Errors.IllegalContinue);
1505
1524
  nextToken(parser, context);
1506
1525
  let label: ESTree.Identifier | undefined | null = null;
1507
- if ((parser.flags & Flags.NewLine) === 0 && parser.token & Token.IsIdentifier) {
1526
+ if ((parser.flags & Flags.NewLine) === 0 && parser.getToken() & Token.IsIdentifier) {
1508
1527
  const { tokenValue } = parser;
1509
1528
  label = parseIdentifier(parser, context | Context.AllowRegExp);
1510
1529
  if (!isValidLabel(parser, labels, tokenValue, /* requireIterationStatement */ 1))
@@ -1540,7 +1559,7 @@ export function parseBreakStatement(
1540
1559
  // 'break' Identifier? ';'
1541
1560
  nextToken(parser, context | Context.AllowRegExp);
1542
1561
  let label: ESTree.Identifier | undefined | null = null;
1543
- if ((parser.flags & Flags.NewLine) === 0 && parser.token & Token.IsIdentifier) {
1562
+ if ((parser.flags & Flags.NewLine) === 0 && parser.getToken() & Token.IsIdentifier) {
1544
1563
  const { tokenValue } = parser;
1545
1564
  label = parseIdentifier(parser, context | Context.AllowRegExp);
1546
1565
  if (!isValidLabel(parser, labels, tokenValue, /* requireIterationStatement */ 0))
@@ -1676,7 +1695,7 @@ export function parseTryStatement(
1676
1695
 
1677
1696
  let finalizer: ESTree.BlockStatement | null = null;
1678
1697
 
1679
- if (parser.token === Token.FinallyKeyword) {
1698
+ if (parser.getToken() === Token.FinallyKeyword) {
1680
1699
  nextToken(parser, context | Context.AllowRegExp);
1681
1700
  const finalizerScope = firstScope ? addChildScope(scope, ScopeKind.CatchStatement) : void 0;
1682
1701
  finalizer = parseBlock(
@@ -1737,7 +1756,7 @@ export function parseCatchBlock(
1737
1756
  parser,
1738
1757
  context,
1739
1758
  scope,
1740
- (parser.token & Token.IsPatternStart) === Token.IsPatternStart
1759
+ (parser.getToken() & Token.IsPatternStart) === Token.IsPatternStart
1741
1760
  ? BindingKind.CatchPattern
1742
1761
  : BindingKind.CatchIdentifier,
1743
1762
  Origin.None,
@@ -1746,9 +1765,9 @@ export function parseCatchBlock(
1746
1765
  parser.colPos
1747
1766
  );
1748
1767
 
1749
- if (parser.token === Token.Comma) {
1768
+ if (parser.getToken() === Token.Comma) {
1750
1769
  report(parser, Errors.InvalidCatchParams);
1751
- } else if (parser.token === Token.Assign) {
1770
+ } else if (parser.getToken() === Token.Assign) {
1752
1771
  report(parser, Errors.InvalidCatchParamDefault);
1753
1772
  }
1754
1773
 
@@ -1876,10 +1895,11 @@ export function parseLetIdentOrVarDeclarationStatement(
1876
1895
  line: number,
1877
1896
  column: number
1878
1897
  ): ESTree.VariableDeclaration | ESTree.LabeledStatement | ESTree.ExpressionStatement {
1879
- const { token, tokenValue } = parser;
1898
+ const { tokenValue } = parser;
1899
+ const token = parser.getToken();
1880
1900
  let expr: ESTree.Identifier | ESTree.Expression = parseIdentifier(parser, context);
1881
1901
 
1882
- if (parser.token & (Token.IsIdentifier | Token.IsPatternStart)) {
1902
+ if (parser.getToken() & (Token.IsIdentifier | Token.IsPatternStart)) {
1883
1903
  /* VariableDeclarations ::
1884
1904
  * ('let') (Identifier ('=' AssignmentExpression)?)+[',']
1885
1905
  */
@@ -1909,7 +1929,7 @@ export function parseLetIdentOrVarDeclarationStatement(
1909
1929
  * [lookahead notin {{, function, class, let [}] Expression[In, ?Yield] ;
1910
1930
  */
1911
1931
 
1912
- if (parser.token === Token.Colon) {
1932
+ if (parser.getToken() === Token.Colon) {
1913
1933
  return parseLabelledStatement(parser, context, scope, origin, {}, tokenValue, expr, token, 0, start, line, column);
1914
1934
  }
1915
1935
 
@@ -1922,7 +1942,7 @@ export function parseLetIdentOrVarDeclarationStatement(
1922
1942
  * { FunctionBody }
1923
1943
  *
1924
1944
  */
1925
- if (parser.token === Token.Arrow) {
1945
+ if (parser.getToken() === Token.Arrow) {
1926
1946
  let scope: ScopeState | undefined = void 0;
1927
1947
 
1928
1948
  if (context & Context.OptionsLexical) scope = createArrowHeadParsingScope(parser, context, tokenValue);
@@ -1960,7 +1980,7 @@ export function parseLetIdentOrVarDeclarationStatement(
1960
1980
 
1961
1981
  /** Sequence expression
1962
1982
  */
1963
- if (parser.token === Token.Comma) {
1983
+ if (parser.getToken() === Token.Comma) {
1964
1984
  expr = parseSequenceExpression(parser, context, 0, start, line, column, expr);
1965
1985
  }
1966
1986
 
@@ -2072,8 +2092,8 @@ export function parseVariableDeclarationList(
2072
2092
  list.push(parseVariableDeclaration(parser, context, scope, kind, origin));
2073
2093
  }
2074
2094
 
2075
- if (bindingCount > 1 && origin & Origin.ForStatement && parser.token & Token.IsInOrOf) {
2076
- report(parser, Errors.ForInOfLoopMultiBindings, KeywordDescTable[parser.token & Token.Type]);
2095
+ if (bindingCount > 1 && origin & Origin.ForStatement && parser.getToken() & Token.IsInOrOf) {
2096
+ report(parser, Errors.ForInOfLoopMultiBindings, KeywordDescTable[parser.getToken() & Token.Type]);
2077
2097
  }
2078
2098
  return list;
2079
2099
  }
@@ -2105,21 +2125,22 @@ function parseVariableDeclaration(
2105
2125
  // BindingIdentifier InitializerNoInopt
2106
2126
  // BindingPattern InitializerNoIn
2107
2127
 
2108
- const { token, tokenPos, linePos, colPos } = parser;
2128
+ const { tokenPos, linePos, colPos } = parser;
2129
+ const token = parser.getToken();
2109
2130
 
2110
2131
  let init: ESTree.Expression | ESTree.BindingPattern | ESTree.Identifier | null = null;
2111
2132
 
2112
2133
  const id = parseBindingPattern(parser, context, scope, kind, origin, tokenPos, linePos, colPos);
2113
2134
 
2114
- if (parser.token === Token.Assign) {
2135
+ if (parser.getToken() === Token.Assign) {
2115
2136
  nextToken(parser, context | Context.AllowRegExp);
2116
2137
  init = parseExpression(parser, context, 1, 0, parser.tokenPos, parser.linePos, parser.colPos);
2117
2138
  if (origin & Origin.ForStatement || (token & Token.IsPatternStart) === 0) {
2118
2139
  // Lexical declarations in for-in / for-of loops can't be initialized
2119
2140
 
2120
2141
  if (
2121
- parser.token === Token.OfKeyword ||
2122
- (parser.token === Token.InKeyword &&
2142
+ parser.getToken() === Token.OfKeyword ||
2143
+ (parser.getToken() === Token.InKeyword &&
2123
2144
  (token & Token.IsPatternStart || (kind & BindingKind.Variable) === 0 || context & Context.Strict))
2124
2145
  ) {
2125
2146
  reportMessageAt(
@@ -2127,14 +2148,14 @@ function parseVariableDeclaration(
2127
2148
  parser.line,
2128
2149
  parser.index - 3,
2129
2150
  Errors.ForInOfLoopInitializer,
2130
- parser.token === Token.OfKeyword ? 'of' : 'in'
2151
+ parser.getToken() === Token.OfKeyword ? 'of' : 'in'
2131
2152
  );
2132
2153
  }
2133
2154
  }
2134
2155
  // Normal const declarations, and const declarations in for(;;) heads, must be initialized.
2135
2156
  } else if (
2136
2157
  (kind & BindingKind.Const || (token & Token.IsPatternStart) > 0) &&
2137
- (parser.token & Token.IsInOrOf) !== Token.IsInOrOf
2158
+ (parser.getToken() & Token.IsInOrOf) !== Token.IsInOrOf
2138
2159
  ) {
2139
2160
  report(parser, Errors.DeclarationMissingInitializer, kind & BindingKind.Const ? 'const' : 'destructuring');
2140
2161
  }
@@ -2183,16 +2204,19 @@ export function parseForStatement(
2183
2204
  let destructible: AssignmentKind | DestructuringKind = 0;
2184
2205
  let init = null;
2185
2206
  let isVarDecl =
2186
- parser.token === Token.VarKeyword || parser.token === Token.LetKeyword || parser.token === Token.ConstKeyword;
2207
+ parser.getToken() === Token.VarKeyword ||
2208
+ parser.getToken() === Token.LetKeyword ||
2209
+ parser.getToken() === Token.ConstKeyword;
2187
2210
  let right;
2188
2211
 
2189
- const { token, tokenPos, linePos, colPos } = parser;
2212
+ const { tokenPos, linePos, colPos } = parser;
2213
+ const token = parser.getToken();
2190
2214
 
2191
2215
  if (isVarDecl) {
2192
2216
  if (token === Token.LetKeyword) {
2193
2217
  init = parseIdentifier(parser, context);
2194
- if (parser.token & (Token.IsIdentifier | Token.IsPatternStart)) {
2195
- if (parser.token === Token.InKeyword) {
2218
+ if (parser.getToken() & (Token.IsIdentifier | Token.IsPatternStart)) {
2219
+ if (parser.getToken() === Token.InKeyword) {
2196
2220
  if (context & Context.Strict) report(parser, Errors.DisallowedLetInStrict);
2197
2221
  } else {
2198
2222
  init = finishNode(parser, context, tokenPos, linePos, colPos, {
@@ -2217,7 +2241,7 @@ export function parseForStatement(
2217
2241
  init = parseMemberOrUpdateExpression(parser, context, init, 0, 0, tokenPos, linePos, colPos);
2218
2242
 
2219
2243
  // `for of` only allows LeftHandSideExpressions which do not start with `let`, and no other production matches
2220
- if (parser.token === Token.OfKeyword) report(parser, Errors.ForOfLet);
2244
+ if (parser.getToken() === Token.OfKeyword) report(parser, Errors.ForOfLet);
2221
2245
  }
2222
2246
  } else {
2223
2247
  nextToken(parser, context);
@@ -2310,8 +2334,8 @@ export function parseForStatement(
2310
2334
  init = parseLeftHandSideExpression(parser, context | Context.DisallowIn, 1, 0, 1, tokenPos, linePos, colPos);
2311
2335
  }
2312
2336
 
2313
- if ((parser.token & Token.IsInOrOf) === Token.IsInOrOf) {
2314
- if (parser.token === Token.OfKeyword) {
2337
+ if ((parser.getToken() & Token.IsInOrOf) === Token.IsInOrOf) {
2338
+ if (parser.getToken() === Token.OfKeyword) {
2315
2339
  if (parser.assignable & AssignmentKind.CannotAssign)
2316
2340
  report(parser, Errors.CantAssignToInOfForLoop, forAwait ? 'await' : 'of');
2317
2341
 
@@ -2362,24 +2386,24 @@ export function parseForStatement(
2362
2386
  if (forAwait) report(parser, Errors.InvalidForAwait);
2363
2387
 
2364
2388
  if (!isVarDecl) {
2365
- if (destructible & DestructuringKind.HasToDestruct && parser.token !== Token.Assign) {
2389
+ if (destructible & DestructuringKind.HasToDestruct && parser.getToken() !== Token.Assign) {
2366
2390
  report(parser, Errors.CantAssignToInOfForLoop, 'loop');
2367
2391
  }
2368
2392
 
2369
2393
  init = parseAssignmentExpression(parser, context | Context.DisallowIn, 0, 0, tokenPos, linePos, colPos, init);
2370
2394
  }
2371
2395
 
2372
- if (parser.token === Token.Comma)
2396
+ if (parser.getToken() === Token.Comma)
2373
2397
  init = parseSequenceExpression(parser, context, 0, parser.tokenPos, parser.linePos, parser.colPos, init);
2374
2398
 
2375
2399
  consume(parser, context | Context.AllowRegExp, Token.Semicolon);
2376
2400
 
2377
- if (parser.token !== Token.Semicolon)
2401
+ if (parser.getToken() !== Token.Semicolon)
2378
2402
  test = parseExpressions(parser, context, 0, 1, parser.tokenPos, parser.linePos, parser.colPos);
2379
2403
 
2380
2404
  consume(parser, context | Context.AllowRegExp, Token.Semicolon);
2381
2405
 
2382
- if (parser.token !== Token.RightParen)
2406
+ if (parser.getToken() !== Token.RightParen)
2383
2407
  update = parseExpressions(parser, context, 0, 1, parser.tokenPos, parser.linePos, parser.colPos);
2384
2408
 
2385
2409
  consume(parser, context | Context.AllowRegExp, Token.RightParen);
@@ -2408,8 +2432,9 @@ export function parseRestrictedIdentifier(
2408
2432
  context: Context,
2409
2433
  scope: ScopeState | undefined
2410
2434
  ): ESTree.Identifier {
2411
- if (!isValidIdentifier(context, parser.token)) report(parser, Errors.UnexpectedStrictReserved);
2412
- if ((parser.token & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) report(parser, Errors.StrictEvalArguments);
2435
+ if (!isValidIdentifier(context, parser.getToken())) report(parser, Errors.UnexpectedStrictReserved);
2436
+ if ((parser.getToken() & Token.IsEvalOrArguments) === Token.IsEvalOrArguments)
2437
+ report(parser, Errors.StrictEvalArguments);
2413
2438
  if (scope) addBlockName(parser, context, scope, parser.tokenValue, BindingKind.Let, Origin.None);
2414
2439
  return parseIdentifier(parser, context);
2415
2440
  }
@@ -2454,10 +2479,10 @@ function parseImportDeclaration(
2454
2479
  let specifiers: (ESTree.ImportSpecifier | ESTree.ImportDefaultSpecifier | ESTree.ImportNamespaceSpecifier)[] = [];
2455
2480
 
2456
2481
  // 'import' ModuleSpecifier ';'
2457
- if (parser.token === Token.StringLiteral) {
2482
+ if (parser.getToken() === Token.StringLiteral) {
2458
2483
  source = parseLiteral(parser, context);
2459
2484
  } else {
2460
- if (parser.token & Token.IsIdentifier) {
2485
+ if (parser.getToken() & Token.IsIdentifier) {
2461
2486
  const local = parseRestrictedIdentifier(parser, context, scope);
2462
2487
  specifiers = [
2463
2488
  finishNode(parser, context, tokenPos, linePos, colPos, {
@@ -2468,7 +2493,7 @@ function parseImportDeclaration(
2468
2493
 
2469
2494
  // NameSpaceImport
2470
2495
  if (consumeOpt(parser, context, Token.Comma)) {
2471
- switch (parser.token) {
2496
+ switch (parser.getToken()) {
2472
2497
  case Token.Multiply:
2473
2498
  specifiers.push(parseImportNamespaceSpecifier(parser, context, scope));
2474
2499
  break;
@@ -2483,7 +2508,7 @@ function parseImportDeclaration(
2483
2508
  }
2484
2509
  } else {
2485
2510
  // Parse NameSpaceImport or NamedImports if present
2486
- switch (parser.token) {
2511
+ switch (parser.getToken()) {
2487
2512
  case Token.Multiply:
2488
2513
  specifiers = [parseImportNamespaceSpecifier(parser, context, scope)];
2489
2514
  break;
@@ -2495,20 +2520,26 @@ function parseImportDeclaration(
2495
2520
  case Token.Period:
2496
2521
  return parseImportMetaDeclaration(parser, context, start, line, column);
2497
2522
  default:
2498
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
2523
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
2499
2524
  }
2500
2525
  }
2501
2526
 
2502
2527
  source = parseModuleSpecifier(parser, context);
2503
2528
  }
2504
2529
 
2505
- matchOrInsertSemicolon(parser, context | Context.AllowRegExp);
2506
-
2507
- return finishNode(parser, context, start, line, column, {
2530
+ const node: ESTree.ImportDeclaration = {
2508
2531
  type: 'ImportDeclaration',
2509
2532
  specifiers,
2510
2533
  source
2511
- });
2534
+ };
2535
+
2536
+ if (context & Context.OptionsNext) {
2537
+ node.attributes = parser.getToken() === Token.WithKeyword ? parseImportAttributes(parser, context, specifiers) : [];
2538
+ }
2539
+
2540
+ matchOrInsertSemicolon(parser, context | Context.AllowRegExp);
2541
+
2542
+ return finishNode(parser, context, start, line, column, node);
2512
2543
  }
2513
2544
 
2514
2545
  /**
@@ -2532,13 +2563,13 @@ function parseImportNamespaceSpecifier(
2532
2563
  consume(parser, context, Token.AsKeyword);
2533
2564
 
2534
2565
  // 'import * as class from "foo":'
2535
- if ((parser.token & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
2566
+ if ((parser.getToken() & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
2536
2567
  reportMessageAt(
2537
2568
  tokenPos,
2538
2569
  parser.line,
2539
2570
  parser.index,
2540
2571
  Errors.UnexpectedToken,
2541
- KeywordDescTable[parser.token & Token.Type]
2572
+ KeywordDescTable[parser.getToken() & Token.Type]
2542
2573
  );
2543
2574
  }
2544
2575
 
@@ -2559,11 +2590,8 @@ function parseImportNamespaceSpecifier(
2559
2590
  function parseModuleSpecifier(parser: ParserState, context: Context): ESTree.Literal {
2560
2591
  // ModuleSpecifier :
2561
2592
  // StringLiteral
2562
- if (!consumeOpt(parser, context, Token.FromKeyword)) {
2563
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
2564
- }
2565
-
2566
- if (parser.token !== Token.StringLiteral) report(parser, Errors.InvalidExportImportSource, 'Import');
2593
+ consume(parser, context, Token.FromKeyword);
2594
+ if (parser.getToken() !== Token.StringLiteral) report(parser, Errors.InvalidExportImportSource, 'Import');
2567
2595
 
2568
2596
  return parseLiteral(parser, context);
2569
2597
  }
@@ -2589,16 +2617,20 @@ function parseImportSpecifierOrNamedImports(
2589
2617
 
2590
2618
  nextToken(parser, context);
2591
2619
 
2592
- while (parser.token & Token.IsIdentifier) {
2593
- let { token, tokenValue, tokenPos, linePos, colPos } = parser;
2620
+ while (parser.getToken() & Token.IsIdentifier) {
2621
+ let { tokenValue, tokenPos, linePos, colPos } = parser;
2622
+ const token = parser.getToken();
2594
2623
  const imported = parseIdentifier(parser, context);
2595
2624
  let local: ESTree.Identifier;
2596
2625
 
2597
2626
  if (consumeOpt(parser, context, Token.AsKeyword)) {
2598
- if ((parser.token & Token.IsStringOrNumber) === Token.IsStringOrNumber || parser.token === Token.Comma) {
2627
+ if (
2628
+ (parser.getToken() & Token.IsStringOrNumber) === Token.IsStringOrNumber ||
2629
+ parser.getToken() === Token.Comma
2630
+ ) {
2599
2631
  report(parser, Errors.InvalidKeywordAsAlias);
2600
2632
  } else {
2601
- validateBindingIdentifier(parser, context, BindingKind.Const, parser.token, 0);
2633
+ validateBindingIdentifier(parser, context, BindingKind.Const, parser.getToken(), 0);
2602
2634
  }
2603
2635
  tokenValue = parser.tokenValue;
2604
2636
  local = parseIdentifier(parser, context);
@@ -2621,7 +2653,7 @@ function parseImportSpecifierOrNamedImports(
2621
2653
  })
2622
2654
  );
2623
2655
 
2624
- if (parser.token !== Token.RightBrace) consume(parser, context, Token.Comma);
2656
+ if (parser.getToken() !== Token.RightBrace) consume(parser, context, Token.Comma);
2625
2657
  }
2626
2658
 
2627
2659
  consume(parser, context, Token.RightBrace);
@@ -2686,7 +2718,7 @@ export function parseImportMetaDeclaration(
2686
2718
 
2687
2719
  expr = parseAssignmentExpression(parser, context, 0, 0, start, line, column, expr as ESTree.Expression);
2688
2720
 
2689
- if (parser.token === Token.Comma) {
2721
+ if (parser.getToken() === Token.Comma) {
2690
2722
  expr = parseSequenceExpression(parser, context, 0, start, line, column, expr);
2691
2723
  }
2692
2724
 
@@ -2736,7 +2768,7 @@ function parseImportCallDeclaration(
2736
2768
 
2737
2769
  expr = parseMemberOrUpdateExpression(parser, context, expr, 0, 0, start, line, column);
2738
2770
 
2739
- if (parser.token === Token.Comma) {
2771
+ if (parser.getToken() === Token.Comma) {
2740
2772
  expr = parseSequenceExpression(parser, context, 0, start, line, column, expr);
2741
2773
  }
2742
2774
 
@@ -2785,7 +2817,7 @@ function parseExportDeclaration(
2785
2817
  // export default ClassDeclaration[Default]
2786
2818
  // export default [lookahead not-in {function, class}] AssignmentExpression[In] ;
2787
2819
 
2788
- switch (parser.token) {
2820
+ switch (parser.getToken()) {
2789
2821
  // export default HoistableDeclaration[Default]
2790
2822
  case Token.FunctionKeyword: {
2791
2823
  declaration = parseFunctionDeclaration(
@@ -2818,7 +2850,7 @@ function parseExportDeclaration(
2818
2850
  break;
2819
2851
 
2820
2852
  // export default HoistableDeclaration[Default]
2821
- case Token.AsyncKeyword:
2853
+ case Token.AsyncKeyword: {
2822
2854
  const { tokenPos, linePos, colPos } = parser;
2823
2855
 
2824
2856
  declaration = parseIdentifier(parser, context);
@@ -2826,7 +2858,7 @@ function parseExportDeclaration(
2826
2858
  const { flags } = parser;
2827
2859
 
2828
2860
  if ((flags & Flags.NewLine) === 0) {
2829
- if (parser.token === Token.FunctionKeyword) {
2861
+ if (parser.getToken() === Token.FunctionKeyword) {
2830
2862
  declaration = parseFunctionDeclaration(
2831
2863
  parser,
2832
2864
  context,
@@ -2840,7 +2872,7 @@ function parseExportDeclaration(
2840
2872
  colPos
2841
2873
  );
2842
2874
  } else {
2843
- if (parser.token === Token.LeftParen) {
2875
+ if (parser.getToken() === Token.LeftParen) {
2844
2876
  declaration = parseAsyncArrowOrCallExpression(
2845
2877
  parser,
2846
2878
  context,
@@ -2873,7 +2905,7 @@ function parseExportDeclaration(
2873
2905
  colPos,
2874
2906
  declaration as any
2875
2907
  );
2876
- } else if (parser.token & Token.IsIdentifier) {
2908
+ } else if (parser.getToken() & Token.IsIdentifier) {
2877
2909
  if (scope) scope = createArrowHeadParsingScope(parser, context, parser.tokenValue);
2878
2910
 
2879
2911
  declaration = parseIdentifier(parser, context);
@@ -2891,6 +2923,7 @@ function parseExportDeclaration(
2891
2923
  }
2892
2924
  }
2893
2925
  break;
2926
+ }
2894
2927
 
2895
2928
  default:
2896
2929
  // export default [lookahead ∉ {function, class}] AssignmentExpression[In] ;
@@ -2907,7 +2940,7 @@ function parseExportDeclaration(
2907
2940
  });
2908
2941
  }
2909
2942
 
2910
- switch (parser.token) {
2943
+ switch (parser.getToken()) {
2911
2944
  case Token.Multiply: {
2912
2945
  //
2913
2946
  // 'export' '*' 'as' IdentifierName 'from' ModuleSpecifier ';'
@@ -2925,17 +2958,23 @@ function parseExportDeclaration(
2925
2958
 
2926
2959
  consume(parser, context, Token.FromKeyword);
2927
2960
 
2928
- if (parser.token !== Token.StringLiteral) report(parser, Errors.InvalidExportImportSource, 'Export');
2961
+ if (parser.getToken() !== Token.StringLiteral) report(parser, Errors.InvalidExportImportSource, 'Export');
2929
2962
 
2930
2963
  source = parseLiteral(parser, context);
2931
2964
 
2932
- matchOrInsertSemicolon(parser, context | Context.AllowRegExp);
2933
-
2934
- return finishNode(parser, context, start, line, column, {
2965
+ const node: ESTree.ExportAllDeclaration = {
2935
2966
  type: 'ExportAllDeclaration',
2936
2967
  source,
2937
2968
  exported
2938
- } as any);
2969
+ };
2970
+
2971
+ if (context & Context.OptionsNext) {
2972
+ node.attributes = parser.getToken() === Token.WithKeyword ? parseImportAttributes(parser, context) : [];
2973
+ }
2974
+
2975
+ matchOrInsertSemicolon(parser, context | Context.AllowRegExp);
2976
+
2977
+ return finishNode(parser, context, start, line, column, node);
2939
2978
  }
2940
2979
  case Token.LeftBrace: {
2941
2980
  // ExportClause :
@@ -2956,15 +2995,15 @@ function parseExportDeclaration(
2956
2995
  const tmpExportedNames: string[] = [];
2957
2996
  const tmpExportedBindings: string[] = [];
2958
2997
 
2959
- while (parser.token & Token.IsIdentifier) {
2998
+ while (parser.getToken() & Token.IsIdentifier) {
2960
2999
  const { tokenPos, tokenValue, linePos, colPos } = parser;
2961
3000
  const local = parseIdentifier(parser, context);
2962
3001
 
2963
3002
  let exported: ESTree.Identifier | null;
2964
3003
 
2965
- if (parser.token === Token.AsKeyword) {
3004
+ if (parser.getToken() === Token.AsKeyword) {
2966
3005
  nextToken(parser, context);
2967
- if ((parser.token & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
3006
+ if ((parser.getToken() & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
2968
3007
  report(parser, Errors.InvalidKeywordAsAlias);
2969
3008
  }
2970
3009
  if (scope) {
@@ -2988,7 +3027,7 @@ function parseExportDeclaration(
2988
3027
  })
2989
3028
  );
2990
3029
 
2991
- if (parser.token !== Token.RightBrace) consume(parser, context, Token.Comma);
3030
+ if (parser.getToken() !== Token.RightBrace) consume(parser, context, Token.Comma);
2992
3031
  }
2993
3032
 
2994
3033
  consume(parser, context, Token.RightBrace);
@@ -2996,7 +3035,7 @@ function parseExportDeclaration(
2996
3035
  if (consumeOpt(parser, context, Token.FromKeyword)) {
2997
3036
  // The left hand side can't be a keyword where there is no
2998
3037
  // 'from' keyword since it references a local binding.
2999
- if (parser.token !== Token.StringLiteral) report(parser, Errors.InvalidExportImportSource, 'Export');
3038
+ if (parser.getToken() !== Token.StringLiteral) report(parser, Errors.InvalidExportImportSource, 'Export');
3000
3039
 
3001
3040
  source = parseLiteral(parser, context);
3002
3041
  } else if (scope) {
@@ -3079,12 +3118,12 @@ function parseExportDeclaration(
3079
3118
  parser.colPos
3080
3119
  );
3081
3120
  break;
3082
- case Token.AsyncKeyword:
3121
+ case Token.AsyncKeyword: {
3083
3122
  const { tokenPos, linePos, colPos } = parser;
3084
3123
 
3085
3124
  nextToken(parser, context);
3086
3125
 
3087
- if ((parser.flags & Flags.NewLine) === 0 && parser.token === Token.FunctionKeyword) {
3126
+ if ((parser.flags & Flags.NewLine) === 0 && parser.getToken() === Token.FunctionKeyword) {
3088
3127
  declaration = parseFunctionDeclaration(
3089
3128
  parser,
3090
3129
  context,
@@ -3103,9 +3142,10 @@ function parseExportDeclaration(
3103
3142
  }
3104
3143
  break;
3105
3144
  }
3145
+ }
3106
3146
  // falls through
3107
3147
  default:
3108
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
3148
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
3109
3149
  }
3110
3150
 
3111
3151
  return finishNode(parser, context, start, line, column, {
@@ -3194,7 +3234,7 @@ export function parseExpressions(
3194
3234
  column: number
3195
3235
  ): ESTree.SequenceExpression | ESTree.Expression {
3196
3236
  const expr = parseExpression(parser, context, canAssign, inGroup, start, line, column);
3197
- return parser.token === Token.Comma
3237
+ return parser.getToken() === Token.Comma
3198
3238
  ? parseSequenceExpression(parser, context, inGroup, start, line, column, expr)
3199
3239
  : expr;
3200
3240
  }
@@ -3232,7 +3272,7 @@ export function parseAssignmentExpression(
3232
3272
  * LeftHandSideExpression AssignmentOperator AssignmentExpression
3233
3273
  */
3234
3274
 
3235
- const { token } = parser;
3275
+ const token = parser.getToken();
3236
3276
 
3237
3277
  if ((token & Token.IsAssignOp) === Token.IsAssignOp) {
3238
3278
  if (parser.assignable & AssignmentKind.CannotAssign) report(parser, Errors.CantAssignTo);
@@ -3315,7 +3355,7 @@ export function parseAssignmentExpressionOrPattern(
3315
3355
  column: number,
3316
3356
  left: any
3317
3357
  ): any {
3318
- const { token } = parser;
3358
+ const token = parser.getToken();
3319
3359
 
3320
3360
  nextToken(parser, context | Context.AllowRegExp);
3321
3361
 
@@ -3414,8 +3454,8 @@ export function parseBinaryExpression(
3414
3454
 
3415
3455
  parser.assignable = AssignmentKind.CannotAssign;
3416
3456
 
3417
- while (parser.token & Token.IsBinaryOp) {
3418
- t = parser.token;
3457
+ while (parser.getToken() & Token.IsBinaryOp) {
3458
+ t = parser.getToken();
3419
3459
  prec = t & Token.Precedence;
3420
3460
 
3421
3461
  if ((t & Token.IsLogical && operator & Token.IsCoalesc) || (operator & Token.IsLogical && t & Token.IsCoalesc)) {
@@ -3445,7 +3485,7 @@ export function parseBinaryExpression(
3445
3485
  });
3446
3486
  }
3447
3487
 
3448
- if (parser.token === Token.Assign) report(parser, Errors.CantAssignTo);
3488
+ if (parser.getToken() === Token.Assign) report(parser, Errors.CantAssignTo);
3449
3489
 
3450
3490
  return left;
3451
3491
  }
@@ -3478,7 +3518,7 @@ export function parseUnaryExpression(
3478
3518
  * 9) AwaitExpression
3479
3519
  */
3480
3520
  if (!isLHS) report(parser, Errors.Unexpected);
3481
- const unaryOperator = parser.token;
3521
+ const unaryOperator = parser.getToken();
3482
3522
  nextToken(parser, context | Context.AllowRegExp);
3483
3523
  const arg = parseLeftHandSideExpression(
3484
3524
  parser,
@@ -3490,7 +3530,7 @@ export function parseUnaryExpression(
3490
3530
  parser.linePos,
3491
3531
  parser.colPos
3492
3532
  );
3493
- if (parser.token === Token.Exponentiate) report(parser, Errors.InvalidExponentiationLHS);
3533
+ if (parser.getToken() === Token.Exponentiate) report(parser, Errors.InvalidExponentiationLHS);
3494
3534
  if (context & Context.Strict && unaryOperator === Token.DeleteKeyword) {
3495
3535
  if (arg.type === 'Identifier') {
3496
3536
  report(parser, Errors.StrictDelete);
@@ -3527,25 +3567,25 @@ export function parseAsyncExpression(
3527
3567
  line: number,
3528
3568
  column: number
3529
3569
  ): ESTree.FunctionExpression | ESTree.ArrowFunctionExpression | ESTree.CallExpression | ESTree.Identifier {
3530
- const { token } = parser;
3570
+ const token = parser.getToken();
3531
3571
  const expr = parseIdentifier(parser, context);
3532
3572
  const { flags } = parser;
3533
3573
 
3534
3574
  if ((flags & Flags.NewLine) === 0) {
3535
3575
  // async function ...
3536
- if (parser.token === Token.FunctionKeyword) {
3576
+ if (parser.getToken() === Token.FunctionKeyword) {
3537
3577
  return parseFunctionExpression(parser, context, /* isAsync */ 1, inGroup, start, line, column);
3538
3578
  }
3539
3579
 
3540
3580
  // async Identifier => ...
3541
- if ((parser.token & Token.IsIdentifier) === Token.IsIdentifier) {
3581
+ if ((parser.getToken() & Token.IsIdentifier) === Token.IsIdentifier) {
3542
3582
  if (!isLHS) report(parser, Errors.Unexpected);
3543
3583
  return parseAsyncArrowAfterIdent(parser, context, canAssign, start, line, column);
3544
3584
  }
3545
3585
  }
3546
3586
 
3547
3587
  // async (...) => ...
3548
- if (!inNew && parser.token === Token.LeftParen) {
3588
+ if (!inNew && parser.getToken() === Token.LeftParen) {
3549
3589
  return parseAsyncArrowOrCallExpression(
3550
3590
  parser,
3551
3591
  context,
@@ -3560,7 +3600,7 @@ export function parseAsyncExpression(
3560
3600
  );
3561
3601
  }
3562
3602
 
3563
- if (parser.token === Token.Arrow) {
3603
+ if (parser.getToken() === Token.Arrow) {
3564
3604
  classifyIdentifier(parser, context, token);
3565
3605
  if (inNew) report(parser, Errors.InvalidAsyncArrow);
3566
3606
  return parseArrowFromIdentifier(parser, context, parser.tokenValue, expr, inNew, canAssign, 0, start, line, column);
@@ -3595,14 +3635,14 @@ export function parseYieldExpression(
3595
3635
  nextToken(parser, context | Context.AllowRegExp);
3596
3636
  if (context & Context.InArgumentList) report(parser, Errors.YieldInParameter);
3597
3637
  if (!canAssign) report(parser, Errors.CantAssignTo);
3598
- if (parser.token === Token.QuestionMark) report(parser, Errors.InvalidTernaryYield);
3638
+ if (parser.getToken() === Token.QuestionMark) report(parser, Errors.InvalidTernaryYield);
3599
3639
 
3600
3640
  let argument: ESTree.Expression | null = null;
3601
3641
  let delegate = false; // yield*
3602
3642
 
3603
3643
  if ((parser.flags & Flags.NewLine) === 0) {
3604
3644
  delegate = consumeOpt(parser, context | Context.AllowRegExp, Token.Multiply);
3605
- if (parser.token & (Token.Contextual | Token.IsExpressionStart) || delegate) {
3645
+ if (parser.getToken() & (Token.Contextual | Token.IsExpressionStart) || delegate) {
3606
3646
  argument = parseExpression(parser, context, 1, 0, parser.tokenPos, parser.linePos, parser.colPos);
3607
3647
  }
3608
3648
  }
@@ -3658,7 +3698,7 @@ export function parseAwaitExpression(
3658
3698
  parser.colPos
3659
3699
  );
3660
3700
 
3661
- if (parser.token === Token.Exponentiate) report(parser, Errors.InvalidExponentiationLHS);
3701
+ if (parser.getToken() === Token.Exponentiate) report(parser, Errors.InvalidExponentiationLHS);
3662
3702
 
3663
3703
  parser.assignable = AssignmentKind.CannotAssign;
3664
3704
 
@@ -3697,9 +3737,10 @@ export function parseFunctionBody(
3697
3737
  const body: ESTree.Statement[] = [];
3698
3738
  const prevContext = context;
3699
3739
 
3700
- if (parser.token !== Token.RightBrace) {
3701
- while (parser.token === Token.StringLiteral) {
3702
- const { index, tokenPos, tokenValue, token } = parser;
3740
+ if (parser.getToken() !== Token.RightBrace) {
3741
+ while (parser.getToken() === Token.StringLiteral) {
3742
+ const { index, tokenPos, tokenValue } = parser;
3743
+ const token = parser.getToken();
3703
3744
  const expr = parseLiteral(parser, context);
3704
3745
  if (isValidStrictMode(parser, index, tokenPos, tokenValue)) {
3705
3746
  context |= Context.Strict;
@@ -3746,7 +3787,7 @@ export function parseFunctionBody(
3746
3787
 
3747
3788
  parser.destructible = (parser.destructible | DestructuringKind.Yield) ^ DestructuringKind.Yield;
3748
3789
 
3749
- while (parser.token !== Token.RightBrace) {
3790
+ while (parser.getToken() !== Token.RightBrace) {
3750
3791
  body.push(parseStatementListItem(parser, context, scope, Origin.TopLevel, {}) as ESTree.Statement);
3751
3792
  }
3752
3793
 
@@ -3758,7 +3799,7 @@ export function parseFunctionBody(
3758
3799
 
3759
3800
  parser.flags &= ~(Flags.SimpleParameterList | Flags.Octals);
3760
3801
 
3761
- if (parser.token === Token.Assign) report(parser, Errors.CantAssignTo);
3802
+ if (parser.getToken() === Token.Assign) report(parser, Errors.CantAssignTo);
3762
3803
 
3763
3804
  return finishNode(parser, context, tokenPos, linePos, colPos, {
3764
3805
  type: 'BlockStatement',
@@ -3781,7 +3822,7 @@ export function parseSuperExpression(
3781
3822
  ): ESTree.Super {
3782
3823
  nextToken(parser, context);
3783
3824
 
3784
- switch (parser.token) {
3825
+ switch (parser.getToken()) {
3785
3826
  case Token.QuestionMarkPeriod:
3786
3827
  report(parser, Errors.OptionalChainingNoSuper);
3787
3828
  case Token.LeftParen: {
@@ -3870,7 +3911,7 @@ function parseUpdateExpression(
3870
3911
  ) {
3871
3912
  if (parser.assignable & AssignmentKind.CannotAssign) report(parser, Errors.InvalidIncDecTarget);
3872
3913
 
3873
- const { token } = parser;
3914
+ const token = parser.getToken();
3874
3915
 
3875
3916
  nextToken(parser, context);
3876
3917
 
@@ -3904,17 +3945,17 @@ export function parseMemberOrUpdateExpression(
3904
3945
  line: number,
3905
3946
  column: number
3906
3947
  ): any {
3907
- if ((parser.token & Token.IsUpdateOp) === Token.IsUpdateOp && (parser.flags & Flags.NewLine) === 0) {
3948
+ if ((parser.getToken() & Token.IsUpdateOp) === Token.IsUpdateOp && (parser.flags & Flags.NewLine) === 0) {
3908
3949
  expr = parseUpdateExpression(parser, context, expr, start, line, column);
3909
- } else if ((parser.token & Token.IsMemberOrCallExpression) === Token.IsMemberOrCallExpression) {
3950
+ } else if ((parser.getToken() & Token.IsMemberOrCallExpression) === Token.IsMemberOrCallExpression) {
3910
3951
  context = (context | Context.DisallowIn) ^ Context.DisallowIn;
3911
3952
 
3912
- switch (parser.token) {
3953
+ switch (parser.getToken()) {
3913
3954
  /* Property */
3914
3955
  case Token.Period: {
3915
3956
  nextToken(parser, (context | Context.AllowEscapedKeyword | Context.InGlobal) ^ Context.InGlobal);
3916
3957
 
3917
- if (context & Context.InClass && parser.token === Token.PrivateField && parser.tokenValue === 'super') {
3958
+ if (context & Context.InClass && parser.getToken() === Token.PrivateField && parser.tokenValue === 'super') {
3918
3959
  report(parser, Errors.InvalidSuperProperty);
3919
3960
  }
3920
3961
 
@@ -4010,7 +4051,7 @@ export function parseMemberOrUpdateExpression(
4010
4051
  type: 'TaggedTemplateExpression',
4011
4052
  tag: expr,
4012
4053
  quasi:
4013
- parser.token === Token.TemplateContinuation
4054
+ parser.getToken() === Token.TemplateContinuation
4014
4055
  ? parseTemplate(parser, context | Context.TaggedTemplate)
4015
4056
  : parseTemplateLiteral(parser, context, parser.tokenPos, parser.linePos, parser.colPos)
4016
4057
  });
@@ -4050,13 +4091,13 @@ export function parseOptionalChain(
4050
4091
  ): ESTree.MemberExpression | ESTree.CallExpression {
4051
4092
  let restoreHasOptionalChaining = false;
4052
4093
  let node;
4053
- if (parser.token === Token.LeftBracket || parser.token === Token.LeftParen) {
4094
+ if (parser.getToken() === Token.LeftBracket || parser.getToken() === Token.LeftParen) {
4054
4095
  if ((parser.flags & Flags.HasOptionalChaining) === Flags.HasOptionalChaining) {
4055
4096
  restoreHasOptionalChaining = true;
4056
4097
  parser.flags = (parser.flags | Flags.HasOptionalChaining) ^ Flags.HasOptionalChaining;
4057
4098
  }
4058
4099
  }
4059
- if (parser.token === Token.LeftBracket) {
4100
+ if (parser.getToken() === Token.LeftBracket) {
4060
4101
  nextToken(parser, context | Context.AllowRegExp);
4061
4102
  const { tokenPos, linePos, colPos } = parser;
4062
4103
  const property = parseExpressions(parser, context, 0, 1, tokenPos, linePos, colPos);
@@ -4069,7 +4110,7 @@ export function parseOptionalChain(
4069
4110
  optional: true,
4070
4111
  property
4071
4112
  });
4072
- } else if (parser.token === Token.LeftParen) {
4113
+ } else if (parser.getToken() === Token.LeftParen) {
4073
4114
  const args = parseArguments(parser, context, 0);
4074
4115
 
4075
4116
  parser.assignable = AssignmentKind.CannotAssign;
@@ -4081,7 +4122,7 @@ export function parseOptionalChain(
4081
4122
  optional: true
4082
4123
  });
4083
4124
  } else {
4084
- if ((parser.token & (Token.IsIdentifier | Token.Keyword)) === 0) report(parser, Errors.InvalidDotProperty);
4125
+ if ((parser.getToken() & (Token.IsIdentifier | Token.Keyword)) === 0) report(parser, Errors.InvalidDotProperty);
4085
4126
  const property = parseIdentifier(parser, context);
4086
4127
  parser.assignable = AssignmentKind.CannotAssign;
4087
4128
  node = finishNode(parser, context, start, line, column, {
@@ -4106,11 +4147,11 @@ export function parseOptionalChain(
4106
4147
  * @param context Context masks
4107
4148
  */
4108
4149
  export function parsePropertyOrPrivatePropertyName(parser: ParserState, context: Context): any {
4109
- if ((parser.token & (Token.IsIdentifier | Token.Keyword)) === 0 && parser.token !== Token.PrivateField) {
4150
+ if ((parser.getToken() & (Token.IsIdentifier | Token.Keyword)) === 0 && parser.getToken() !== Token.PrivateField) {
4110
4151
  report(parser, Errors.InvalidDotProperty);
4111
4152
  }
4112
4153
 
4113
- return context & Context.OptionsNext && parser.token === Token.PrivateField
4154
+ return parser.getToken() === Token.PrivateField
4114
4155
  ? parsePrivateIdentifier(parser, context, parser.tokenPos, parser.linePos, parser.colPos)
4115
4156
  : parseIdentifier(parser, context);
4116
4157
  }
@@ -4140,7 +4181,7 @@ export function parseUpdateExpressionPrefixed(
4140
4181
  if (inNew) report(parser, Errors.InvalidIncDecNew);
4141
4182
  if (!isLHS) report(parser, Errors.Unexpected);
4142
4183
 
4143
- const { token } = parser;
4184
+ const token = parser.getToken();
4144
4185
 
4145
4186
  nextToken(parser, context | Context.AllowRegExp);
4146
4187
 
@@ -4212,8 +4253,8 @@ export function parsePrimaryExpression(
4212
4253
  // Intrinsic
4213
4254
  // JSX
4214
4255
 
4215
- if ((parser.token & Token.IsIdentifier) === Token.IsIdentifier) {
4216
- switch (parser.token) {
4256
+ if ((parser.getToken() & Token.IsIdentifier) === Token.IsIdentifier) {
4257
+ switch (parser.getToken()) {
4217
4258
  case Token.AwaitKeyword:
4218
4259
  return parseAwaitExpression(parser, context, inNew, inGroup, start, line, column);
4219
4260
  case Token.YieldKeyword:
@@ -4223,11 +4264,12 @@ export function parsePrimaryExpression(
4223
4264
  default: // ignore
4224
4265
  }
4225
4266
 
4226
- const { token, tokenValue } = parser;
4267
+ const { tokenValue } = parser;
4268
+ const token = parser.getToken();
4227
4269
 
4228
4270
  const expr = parseIdentifier(parser, context | Context.TaggedTemplate);
4229
4271
 
4230
- if (parser.token === Token.Arrow) {
4272
+ if (parser.getToken() === Token.Arrow) {
4231
4273
  if (!isLHS) report(parser, Errors.Unexpected);
4232
4274
  classifyIdentifier(parser, context, token);
4233
4275
  return parseArrowFromIdentifier(parser, context, tokenValue, expr, inNew, canAssign, 0, start, line, column);
@@ -4250,12 +4292,12 @@ export function parsePrimaryExpression(
4250
4292
  return expr;
4251
4293
  }
4252
4294
 
4253
- if ((parser.token & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
4295
+ if ((parser.getToken() & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
4254
4296
  return parseLiteral(parser, context);
4255
4297
  }
4256
4298
 
4257
4299
  // Update + Unary + Primary expression
4258
- switch (parser.token) {
4300
+ switch (parser.getToken()) {
4259
4301
  case Token.Increment:
4260
4302
  case Token.Decrement:
4261
4303
  return parseUpdateExpressionPrefixed(parser, context, inNew, isLHS, start, line, column);
@@ -4313,8 +4355,9 @@ export function parsePrimaryExpression(
4313
4355
  if (context & Context.OptionsJSX)
4314
4356
  return parseJSXRootElementOrFragment(parser, context, /*inJSXChild*/ 1, start, line, column);
4315
4357
  default:
4316
- if (isValidIdentifier(context, parser.token)) return parseIdentifierOrArrow(parser, context, start, line, column);
4317
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
4358
+ if (isValidIdentifier(context, parser.getToken()))
4359
+ return parseIdentifierOrArrow(parser, context, start, line, column);
4360
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
4318
4361
  }
4319
4362
  }
4320
4363
 
@@ -4342,7 +4385,7 @@ function parseImportCallOrMetaExpression(
4342
4385
 
4343
4386
  let expr: ESTree.Identifier | ESTree.ImportExpression = parseIdentifier(parser, context);
4344
4387
 
4345
- if (parser.token === Token.Period) {
4388
+ if (parser.getToken() === Token.Period) {
4346
4389
  return parseImportMetaExpression(parser, context, expr, start, line, column);
4347
4390
  }
4348
4391
 
@@ -4378,8 +4421,8 @@ export function parseImportMetaExpression(
4378
4421
 
4379
4422
  nextToken(parser, context); // skips: '.'
4380
4423
 
4381
- if (parser.token !== Token.Meta && parser.tokenValue !== 'meta')
4382
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
4424
+ if (parser.getToken() !== Token.Meta && parser.tokenValue !== 'meta')
4425
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
4383
4426
 
4384
4427
  parser.assignable = AssignmentKind.CannotAssign;
4385
4428
 
@@ -4411,16 +4454,113 @@ export function parseImportExpression(
4411
4454
  ): ESTree.ImportExpression {
4412
4455
  consume(parser, context | Context.AllowRegExp, Token.LeftParen);
4413
4456
 
4414
- if (parser.token === Token.Ellipsis) report(parser, Errors.InvalidSpreadInImport);
4457
+ if (parser.getToken() === Token.Ellipsis) report(parser, Errors.InvalidSpreadInImport);
4415
4458
 
4416
4459
  const source = parseExpression(parser, context, 1, inGroup, parser.tokenPos, parser.linePos, parser.colPos);
4460
+ const node: ESTree.ImportExpression = {
4461
+ type: 'ImportExpression',
4462
+ source
4463
+ };
4464
+
4465
+ if (context & Context.OptionsNext) {
4466
+ let options: ESTree.Expression | null = null;
4467
+
4468
+ if (parser.getToken() === Token.Comma) {
4469
+ consume(parser, context, Token.Comma);
4470
+
4471
+ if (parser.getToken() !== Token.RightParen) {
4472
+ const expContext = (context | Context.DisallowIn) ^ Context.DisallowIn;
4473
+ options = parseExpression(parser, expContext, 1, inGroup, parser.tokenPos, parser.linePos, parser.colPos);
4474
+ }
4475
+ }
4476
+
4477
+ node.options = options;
4478
+ consumeOpt(parser, context, Token.Comma);
4479
+ }
4417
4480
 
4418
4481
  consume(parser, context, Token.RightParen);
4419
4482
 
4420
- return finishNode(parser, context, start, line, column, {
4421
- type: 'ImportExpression',
4422
- source
4423
- });
4483
+ return finishNode(parser, context, start, line, column, node);
4484
+ }
4485
+
4486
+ /**
4487
+ * Parses import attributes
4488
+ *
4489
+ * @param parser Parser object
4490
+ * @param context Context masks
4491
+ * @returns
4492
+ */
4493
+
4494
+ export function parseImportAttributes(
4495
+ parser: ParserState,
4496
+ context: Context,
4497
+ specifiers: ESTree.ImportDeclaration['specifiers'] = []
4498
+ ): ESTree.ImportAttribute[] {
4499
+ consume(parser, context, Token.WithKeyword);
4500
+ consume(parser, context, Token.LeftBrace);
4501
+
4502
+ const attributes: ESTree.ImportAttribute[] = [];
4503
+ const keysContent = new Set<ESTree.Literal['value'] | ESTree.Identifier['name']>();
4504
+
4505
+ while (parser.getToken() !== Token.RightBrace) {
4506
+ const start = parser.tokenPos;
4507
+ const line = parser.linePos;
4508
+ const column = parser.colPos;
4509
+
4510
+ const key = parseIdentifierOrStringLiteral(parser, context);
4511
+ consume(parser, context, Token.Colon);
4512
+ const value = parseStringLiteral(parser, context);
4513
+ const keyContent = key.type === 'Literal' ? key.value : key.name;
4514
+ const isJSONImportAttribute = keyContent === 'type' && value.value === 'json';
4515
+
4516
+ if (isJSONImportAttribute) {
4517
+ const validJSONImportAttributeBindings =
4518
+ specifiers.length === 1 &&
4519
+ (specifiers[0].type === 'ImportDefaultSpecifier' ||
4520
+ specifiers[0].type === 'ImportNamespaceSpecifier' ||
4521
+ (specifiers[0].type === 'ImportSpecifier' && specifiers[0].imported.name === 'default'));
4522
+
4523
+ if (!validJSONImportAttributeBindings) report(parser, Errors.InvalidJSONImportBinding);
4524
+ }
4525
+
4526
+ if (keysContent.has(keyContent)) {
4527
+ report(parser, Errors.DuplicateBinding, `${keyContent}`);
4528
+ }
4529
+
4530
+ keysContent.add(keyContent);
4531
+ attributes.push(
4532
+ finishNode(parser, context, start, line, column, {
4533
+ type: 'ImportAttribute',
4534
+ key,
4535
+ value
4536
+ })
4537
+ );
4538
+
4539
+ if (parser.getToken() !== Token.RightBrace) {
4540
+ consume(parser, context, Token.Comma);
4541
+ }
4542
+ }
4543
+
4544
+ consume(parser, context, Token.RightBrace);
4545
+ return attributes;
4546
+ }
4547
+
4548
+ function parseStringLiteral(parser: ParserState, context: Context): ESTree.Literal {
4549
+ if (parser.getToken() === Token.StringLiteral) {
4550
+ return parseLiteral(parser, context);
4551
+ } else {
4552
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
4553
+ }
4554
+ }
4555
+
4556
+ function parseIdentifierOrStringLiteral(parser: ParserState, context: Context): ESTree.Identifier | ESTree.Literal {
4557
+ if (parser.getToken() === Token.StringLiteral) {
4558
+ return parseLiteral(parser, context);
4559
+ } else if (parser.getToken() & Token.IsIdentifier) {
4560
+ return parseIdentifier(parser, context);
4561
+ } else {
4562
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
4563
+ }
4424
4564
  }
4425
4565
 
4426
4566
  /**
@@ -4535,9 +4675,9 @@ export function parseTemplate(parser: ParserState, context: Context): ESTree.Tem
4535
4675
 
4536
4676
  const expressions = [parseExpressions(parser, context, 0, 1, parser.tokenPos, parser.linePos, parser.colPos)];
4537
4677
 
4538
- if (parser.token !== Token.RightBrace) report(parser, Errors.InvalidTemplateContinuation);
4678
+ if (parser.getToken() !== Token.RightBrace) report(parser, Errors.InvalidTemplateContinuation);
4539
4679
 
4540
- while ((parser.token = scanTemplateTail(parser, context)) !== Token.TemplateSpan) {
4680
+ while (parser.setToken(scanTemplateTail(parser, context)) !== Token.TemplateSpan) {
4541
4681
  const { tokenValue, tokenRaw, tokenPos, linePos, colPos } = parser;
4542
4682
  consume(parser, context | Context.AllowRegExp, Token.TemplateContinuation);
4543
4683
  quasis.push(
@@ -4545,7 +4685,7 @@ export function parseTemplate(parser: ParserState, context: Context): ESTree.Tem
4545
4685
  );
4546
4686
 
4547
4687
  expressions.push(parseExpressions(parser, context, 0, 1, parser.tokenPos, parser.linePos, parser.colPos));
4548
- if (parser.token !== Token.RightBrace) report(parser, Errors.InvalidTemplateContinuation);
4688
+ if (parser.getToken() !== Token.RightBrace) report(parser, Errors.InvalidTemplateContinuation);
4549
4689
  }
4550
4690
 
4551
4691
  {
@@ -4651,23 +4791,23 @@ export function parseArguments(
4651
4791
 
4652
4792
  const args: (ESTree.Expression | ESTree.SpreadElement)[] = [];
4653
4793
 
4654
- if (parser.token === Token.RightParen) {
4794
+ if (parser.getToken() === Token.RightParen) {
4655
4795
  nextToken(parser, context | Context.TaggedTemplate);
4656
4796
  return args;
4657
4797
  }
4658
4798
 
4659
- while (parser.token !== Token.RightParen) {
4660
- if (parser.token === Token.Ellipsis) {
4799
+ while (parser.getToken() !== Token.RightParen) {
4800
+ if (parser.getToken() === Token.Ellipsis) {
4661
4801
  args.push(parseSpreadElement(parser, context, parser.tokenPos, parser.linePos, parser.colPos));
4662
4802
  } else {
4663
4803
  args.push(parseExpression(parser, context, 1, inGroup, parser.tokenPos, parser.linePos, parser.colPos));
4664
4804
  }
4665
4805
 
4666
- if (parser.token !== Token.Comma) break;
4806
+ if (parser.getToken() !== Token.Comma) break;
4667
4807
 
4668
4808
  nextToken(parser, context | Context.AllowRegExp);
4669
4809
 
4670
- if (parser.token === Token.RightParen) break;
4810
+ if (parser.getToken() === Token.RightParen) break;
4671
4811
  }
4672
4812
 
4673
4813
  consume(parser, context, Token.RightParen);
@@ -4699,7 +4839,7 @@ export function parseIdentifier(parser: ParserState, context: Context): ESTree.I
4699
4839
  */
4700
4840
  export function parseLiteral(parser: ParserState, context: Context): ESTree.Literal {
4701
4841
  const { tokenValue, tokenRaw, tokenPos, linePos, colPos } = parser;
4702
- if (parser.token === Token.BigIntLiteral) {
4842
+ if (parser.getToken() === Token.BigIntLiteral) {
4703
4843
  return parseBigIntLiteral(parser, context, tokenPos, linePos, colPos);
4704
4844
  }
4705
4845
 
@@ -4737,8 +4877,8 @@ export function parseNullOrTrueOrFalseLiteral(
4737
4877
  line: number,
4738
4878
  column: number
4739
4879
  ): ESTree.Literal {
4740
- const raw = KeywordDescTable[parser.token & Token.Type];
4741
- const value = parser.token === Token.NullKeyword ? null : raw === 'true';
4880
+ const raw = KeywordDescTable[parser.getToken() & Token.Type];
4881
+ const value = parser.getToken() === Token.NullKeyword ? null : raw === 'true';
4742
4882
 
4743
4883
  nextToken(parser, context);
4744
4884
  parser.assignable = AssignmentKind.CannotAssign;
@@ -4825,7 +4965,7 @@ export function parseFunctionDeclaration(
4825
4965
  // Create a new function scope
4826
4966
  let functionScope = scope ? createScope() : void 0;
4827
4967
 
4828
- if (parser.token === Token.LeftParen) {
4968
+ if (parser.getToken() === Token.LeftParen) {
4829
4969
  if ((flags & HoistedClassFlags.Hoisted) === 0) report(parser, Errors.DeclNoName, 'Function');
4830
4970
  } else {
4831
4971
  // In ES6, a function behaves as a lexical binding, except in
@@ -4835,7 +4975,7 @@ export function parseFunctionDeclaration(
4835
4975
  ? BindingKind.Variable
4836
4976
  : BindingKind.FunctionLexical;
4837
4977
 
4838
- validateFunctionName(parser, context | ((context & 0b0000000000000000000_1100_00000000) << 11), parser.token);
4978
+ validateFunctionName(parser, context, parser.getToken());
4839
4979
 
4840
4980
  if (scope) {
4841
4981
  if (kind & BindingKind.Variable) {
@@ -4853,19 +4993,28 @@ export function parseFunctionDeclaration(
4853
4993
  }
4854
4994
  }
4855
4995
 
4856
- firstRestricted = parser.token;
4996
+ firstRestricted = parser.getToken();
4857
4997
 
4858
- if (parser.token & Token.IsIdentifier) {
4998
+ if (parser.getToken() & Token.IsIdentifier) {
4859
4999
  id = parseIdentifier(parser, context);
4860
5000
  } else {
4861
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
5001
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
4862
5002
  }
4863
5003
  }
4864
5004
 
5005
+ const modifierFlags =
5006
+ Context.SuperProperty |
5007
+ Context.SuperCall |
5008
+ Context.InYieldContext |
5009
+ Context.InAwaitContext |
5010
+ Context.InArgumentList |
5011
+ Context.InConstructor;
5012
+
4865
5013
  context =
4866
- ((context | 0b0000001111011000000_0000_00000000) ^ 0b0000001111011000000_0000_00000000) |
5014
+ ((context | modifierFlags) ^ modifierFlags) |
4867
5015
  Context.AllowNewTarget |
4868
- ((isAsync * 2 + isGenerator) << 21) |
5016
+ (isAsync ? Context.InAwaitContext : 0) |
5017
+ (isGenerator ? Context.InYieldContext : 0) |
4869
5018
  (isGenerator ? 0 : Context.AllowEscapedKeyword);
4870
5019
 
4871
5020
  if (scope) functionScope = addChildScope(functionScope, ScopeKind.FunctionParams);
@@ -4923,7 +5072,7 @@ export function parseFunctionExpression(
4923
5072
  nextToken(parser, context | Context.AllowRegExp);
4924
5073
 
4925
5074
  const isGenerator = optionalBit(parser, context, Token.Multiply);
4926
- const generatorAndAsyncFlags = (isAsync * 2 + isGenerator) << 21;
5075
+ const generatorAndAsyncFlags = (isAsync ? Context.InAwaitContext : 0) | (isGenerator ? Context.InYieldContext : 0);
4927
5076
 
4928
5077
  let id: ESTree.Identifier | null = null;
4929
5078
  let firstRestricted: Token | undefined;
@@ -4931,17 +5080,29 @@ export function parseFunctionExpression(
4931
5080
  // Create a new function scope
4932
5081
  let scope = context & Context.OptionsLexical ? createScope() : void 0;
4933
5082
 
4934
- if ((parser.token & (Token.IsIdentifier | Token.Keyword | Token.FutureReserved)) > 0) {
4935
- validateFunctionName(parser, ((context | 0x1ec0000) ^ 0x1ec0000) | generatorAndAsyncFlags, parser.token);
5083
+ const modifierFlags =
5084
+ Context.SuperProperty |
5085
+ Context.SuperCall |
5086
+ Context.InYieldContext |
5087
+ Context.InAwaitContext |
5088
+ Context.InArgumentList |
5089
+ Context.InConstructor;
5090
+
5091
+ if ((parser.getToken() & (Token.IsIdentifier | Token.Keyword | Token.FutureReserved)) > 0) {
5092
+ validateFunctionName(
5093
+ parser,
5094
+ ((context | modifierFlags) ^ modifierFlags) | generatorAndAsyncFlags,
5095
+ parser.getToken()
5096
+ );
4936
5097
 
4937
5098
  if (scope) scope = addChildScope(scope, ScopeKind.FunctionRoot);
4938
5099
 
4939
- firstRestricted = parser.token;
5100
+ firstRestricted = parser.getToken();
4940
5101
  id = parseIdentifier(parser, context);
4941
5102
  }
4942
5103
 
4943
5104
  context =
4944
- ((context | 0b0000001111011000000_0000_00000000) ^ 0b0000001111011000000_0000_00000000) |
5105
+ ((context | modifierFlags) ^ modifierFlags) |
4945
5106
  Context.AllowNewTarget |
4946
5107
  generatorAndAsyncFlags |
4947
5108
  (isGenerator ? 0 : Context.AllowEscapedKeyword);
@@ -4958,7 +5119,7 @@ export function parseFunctionExpression(
4958
5119
 
4959
5120
  const body = parseFunctionBody(
4960
5121
  parser,
4961
- context & ~(0x8001000 | Context.InGlobal | Context.InSwitch | Context.InIteration | Context.InClass),
5122
+ context & ~(Context.DisallowIn | Context.InSwitch | Context.InGlobal | Context.InIteration | Context.InClass),
4962
5123
  scope ? addChildScope(scope, ScopeKind.FunctionBody) : scope,
4963
5124
  0,
4964
5125
  firstRestricted,
@@ -5106,18 +5267,19 @@ export function parseArrayExpressionOrPattern(
5106
5267
 
5107
5268
  context = (context | Context.DisallowIn) ^ Context.DisallowIn;
5108
5269
 
5109
- while (parser.token !== Token.RightBracket) {
5270
+ while (parser.getToken() !== Token.RightBracket) {
5110
5271
  if (consumeOpt(parser, context | Context.AllowRegExp, Token.Comma)) {
5111
5272
  elements.push(null);
5112
5273
  } else {
5113
5274
  let left: any;
5114
5275
 
5115
- const { token, tokenPos, linePos, colPos, tokenValue } = parser;
5276
+ const { tokenPos, linePos, colPos, tokenValue } = parser;
5277
+ const token = parser.getToken();
5116
5278
 
5117
5279
  if (token & Token.IsIdentifier) {
5118
5280
  left = parsePrimaryExpression(parser, context, kind, 0, 1, inGroup, 1, tokenPos, linePos, colPos);
5119
5281
 
5120
- if (parser.token === Token.Assign) {
5282
+ if (parser.getToken() === Token.Assign) {
5121
5283
  if (parser.assignable & AssignmentKind.CannotAssign) report(parser, Errors.CantAssignTo);
5122
5284
 
5123
5285
  nextToken(parser, context | Context.AllowRegExp);
@@ -5150,9 +5312,9 @@ export function parseArrayExpressionOrPattern(
5150
5312
  parser.destructible & DestructuringKind.Yield
5151
5313
  ? DestructuringKind.Yield
5152
5314
  : 0 | (parser.destructible & DestructuringKind.Await)
5153
- ? DestructuringKind.Await
5154
- : 0;
5155
- } else if (parser.token === Token.Comma || parser.token === Token.RightBracket) {
5315
+ ? DestructuringKind.Await
5316
+ : 0;
5317
+ } else if (parser.getToken() === Token.Comma || parser.getToken() === Token.RightBracket) {
5156
5318
  if (parser.assignable & AssignmentKind.CannotAssign) {
5157
5319
  destructible |= DestructuringKind.CannotDestruct;
5158
5320
  } else if (scope) {
@@ -5162,22 +5324,22 @@ export function parseArrayExpressionOrPattern(
5162
5324
  parser.destructible & DestructuringKind.Yield
5163
5325
  ? DestructuringKind.Yield
5164
5326
  : 0 | (parser.destructible & DestructuringKind.Await)
5165
- ? DestructuringKind.Await
5166
- : 0;
5327
+ ? DestructuringKind.Await
5328
+ : 0;
5167
5329
  } else {
5168
5330
  destructible |=
5169
5331
  kind & BindingKind.ArgumentList
5170
5332
  ? DestructuringKind.Assignable
5171
5333
  : (kind & BindingKind.Empty) === 0
5172
- ? DestructuringKind.CannotDestruct
5173
- : 0;
5334
+ ? DestructuringKind.CannotDestruct
5335
+ : 0;
5174
5336
 
5175
5337
  left = parseMemberOrUpdateExpression(parser, context, left, inGroup, 0, tokenPos, linePos, colPos);
5176
5338
 
5177
- if (parser.token !== Token.Comma && parser.token !== Token.RightBracket) {
5178
- if (parser.token !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
5339
+ if (parser.getToken() !== Token.Comma && parser.getToken() !== Token.RightBracket) {
5340
+ if (parser.getToken() !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
5179
5341
  left = parseAssignmentExpression(parser, context, inGroup, isPattern, tokenPos, linePos, colPos, left);
5180
- } else if (parser.token !== Token.Assign) {
5342
+ } else if (parser.getToken() !== Token.Assign) {
5181
5343
  destructible |=
5182
5344
  parser.assignable & AssignmentKind.CannotAssign
5183
5345
  ? DestructuringKind.CannotDestruct
@@ -5186,7 +5348,7 @@ export function parseArrayExpressionOrPattern(
5186
5348
  }
5187
5349
  } else if (token & Token.IsPatternStart) {
5188
5350
  left =
5189
- parser.token === Token.LeftBrace
5351
+ parser.getToken() === Token.LeftBrace
5190
5352
  ? parseObjectLiteralOrPattern(
5191
5353
  parser,
5192
5354
  context,
@@ -5221,7 +5383,7 @@ export function parseArrayExpressionOrPattern(
5221
5383
  ? AssignmentKind.CannotAssign
5222
5384
  : AssignmentKind.Assignable;
5223
5385
 
5224
- if (parser.token === Token.Comma || parser.token === Token.RightBracket) {
5386
+ if (parser.getToken() === Token.Comma || parser.getToken() === Token.RightBracket) {
5225
5387
  if (parser.assignable & AssignmentKind.CannotAssign) {
5226
5388
  destructible |= DestructuringKind.CannotDestruct;
5227
5389
  }
@@ -5231,9 +5393,9 @@ export function parseArrayExpressionOrPattern(
5231
5393
  left = parseMemberOrUpdateExpression(parser, context, left, inGroup, 0, tokenPos, linePos, colPos);
5232
5394
  destructible = parser.assignable & AssignmentKind.CannotAssign ? DestructuringKind.CannotDestruct : 0;
5233
5395
 
5234
- if (parser.token !== Token.Comma && parser.token !== Token.RightBracket) {
5396
+ if (parser.getToken() !== Token.Comma && parser.getToken() !== Token.RightBracket) {
5235
5397
  left = parseAssignmentExpression(parser, context, inGroup, isPattern, tokenPos, linePos, colPos, left);
5236
- } else if (parser.token !== Token.Assign) {
5398
+ } else if (parser.getToken() !== Token.Assign) {
5237
5399
  destructible |=
5238
5400
  parser.assignable & AssignmentKind.CannotAssign
5239
5401
  ? DestructuringKind.CannotDestruct
@@ -5256,12 +5418,12 @@ export function parseArrayExpressionOrPattern(
5256
5418
  colPos
5257
5419
  );
5258
5420
  destructible |= parser.destructible;
5259
- if (parser.token !== Token.Comma && parser.token !== Token.RightBracket)
5260
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
5421
+ if (parser.getToken() !== Token.Comma && parser.getToken() !== Token.RightBracket)
5422
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
5261
5423
  } else {
5262
5424
  left = parseLeftHandSideExpression(parser, context, 1, 0, 1, tokenPos, linePos, colPos);
5263
5425
 
5264
- if (parser.token !== Token.Comma && parser.token !== Token.RightBracket) {
5426
+ if (parser.getToken() !== Token.Comma && parser.getToken() !== Token.RightBracket) {
5265
5427
  left = parseAssignmentExpression(parser, context, inGroup, isPattern, tokenPos, linePos, colPos, left);
5266
5428
  if ((kind & (BindingKind.Empty | BindingKind.ArgumentList)) === 0 && token === Token.LeftParen)
5267
5429
  destructible |= DestructuringKind.CannotDestruct;
@@ -5278,7 +5440,7 @@ export function parseArrayExpressionOrPattern(
5278
5440
  elements.push(left);
5279
5441
 
5280
5442
  if (consumeOpt(parser, context | Context.AllowRegExp, Token.Comma)) {
5281
- if (parser.token === Token.RightBracket) break;
5443
+ if (parser.getToken() === Token.RightBracket) break;
5282
5444
  } else break;
5283
5445
  }
5284
5446
  }
@@ -5290,7 +5452,7 @@ export function parseArrayExpressionOrPattern(
5290
5452
  elements
5291
5453
  } as any);
5292
5454
 
5293
- if (!skipInitializer && parser.token & Token.IsAssignOp) {
5455
+ if (!skipInitializer && parser.getToken() & Token.IsAssignOp) {
5294
5456
  return parseArrayOrObjectAssignmentPattern(
5295
5457
  parser,
5296
5458
  context,
@@ -5340,7 +5502,7 @@ function parseArrayOrObjectAssignmentPattern(
5340
5502
  // DestructuringAssignmentTarget[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]
5341
5503
  //
5342
5504
 
5343
- if (parser.token !== Token.Assign) report(parser, Errors.CantAssignTo);
5505
+ if (parser.getToken() !== Token.Assign) report(parser, Errors.CantAssignTo);
5344
5506
 
5345
5507
  nextToken(parser, context | Context.AllowRegExp);
5346
5508
 
@@ -5412,14 +5574,15 @@ function parseSpreadOrRestElement(
5412
5574
  let argument: ESTree.Expression | null = null;
5413
5575
  let destructible: AssignmentKind | DestructuringKind = DestructuringKind.None;
5414
5576
 
5415
- let { token, tokenValue, tokenPos, linePos, colPos } = parser;
5577
+ const { tokenValue, tokenPos, linePos, colPos } = parser;
5578
+ let token = parser.getToken();
5416
5579
 
5417
5580
  if (token & (Token.Keyword | Token.IsIdentifier)) {
5418
5581
  parser.assignable = AssignmentKind.Assignable;
5419
5582
 
5420
5583
  argument = parsePrimaryExpression(parser, context, kind, 0, 1, inGroup, 1, tokenPos, linePos, colPos);
5421
5584
 
5422
- token = parser.token;
5585
+ token = parser.getToken();
5423
5586
 
5424
5587
  argument = parseMemberOrUpdateExpression(
5425
5588
  parser,
@@ -5432,8 +5595,8 @@ function parseSpreadOrRestElement(
5432
5595
  colPos
5433
5596
  );
5434
5597
 
5435
- if (parser.token !== Token.Comma && parser.token !== closingToken) {
5436
- if (parser.assignable & AssignmentKind.CannotAssign && parser.token === Token.Assign)
5598
+ if (parser.getToken() !== Token.Comma && parser.getToken() !== closingToken) {
5599
+ if (parser.assignable & AssignmentKind.CannotAssign && parser.getToken() === Token.Assign)
5437
5600
  report(parser, Errors.InvalidDestructuringTarget);
5438
5601
 
5439
5602
  destructible |= DestructuringKind.CannotDestruct;
@@ -5454,7 +5617,7 @@ function parseSpreadOrRestElement(
5454
5617
  report(parser, Errors.RestMissingArg);
5455
5618
  } else if (token & Token.IsPatternStart) {
5456
5619
  argument =
5457
- parser.token === Token.LeftBrace
5620
+ parser.getToken() === Token.LeftBrace
5458
5621
  ? parseObjectLiteralOrPattern(
5459
5622
  parser,
5460
5623
  context,
@@ -5482,7 +5645,7 @@ function parseSpreadOrRestElement(
5482
5645
  colPos
5483
5646
  );
5484
5647
 
5485
- token = parser.token;
5648
+ token = parser.getToken();
5486
5649
 
5487
5650
  if (token !== Token.Assign && token !== closingToken && token !== Token.Comma) {
5488
5651
  if (parser.destructible & DestructuringKind.HasToDestruct) report(parser, Errors.InvalidDestructuringTarget);
@@ -5491,11 +5654,11 @@ function parseSpreadOrRestElement(
5491
5654
 
5492
5655
  destructible |= parser.assignable & AssignmentKind.CannotAssign ? DestructuringKind.CannotDestruct : 0;
5493
5656
 
5494
- if ((parser.token & Token.IsAssignOp) === Token.IsAssignOp) {
5495
- if (parser.token !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
5657
+ if ((parser.getToken() & Token.IsAssignOp) === Token.IsAssignOp) {
5658
+ if (parser.getToken() !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
5496
5659
  argument = parseAssignmentExpression(parser, context, inGroup, isPattern, tokenPos, linePos, colPos, argument);
5497
5660
  } else {
5498
- if ((parser.token & Token.IsBinaryOp) === Token.IsBinaryOp) {
5661
+ if ((parser.getToken() & Token.IsBinaryOp) === Token.IsBinaryOp) {
5499
5662
  argument = parseBinaryExpression(parser, context, 1, tokenPos, linePos, colPos, 4, token, argument as any);
5500
5663
  }
5501
5664
  if (consumeOpt(parser, context | Context.AllowRegExp, Token.QuestionMark)) {
@@ -5526,9 +5689,10 @@ function parseSpreadOrRestElement(
5526
5689
  parser.colPos
5527
5690
  );
5528
5691
 
5529
- const { token, tokenPos, linePos, colPos } = parser;
5692
+ const { tokenPos, linePos, colPos } = parser;
5693
+ const token = parser.getToken();
5530
5694
 
5531
- if (token === Token.Assign && token !== closingToken && token !== Token.Comma) {
5695
+ if (token === Token.Assign) {
5532
5696
  if (parser.assignable & AssignmentKind.CannotAssign) report(parser, Errors.CantAssignTo);
5533
5697
 
5534
5698
  argument = parseAssignmentExpression(parser, context, inGroup, isPattern, tokenPos, linePos, colPos, argument);
@@ -5547,7 +5711,8 @@ function parseSpreadOrRestElement(
5547
5711
 
5548
5712
  parser.destructible = destructible;
5549
5713
 
5550
- if (parser.token !== closingToken && parser.token !== Token.Comma) report(parser, Errors.UnclosedSpreadElement);
5714
+ if (parser.getToken() !== closingToken && parser.getToken() !== Token.Comma)
5715
+ report(parser, Errors.UnclosedSpreadElement);
5551
5716
 
5552
5717
  return finishNode(parser, context, start, line, column, {
5553
5718
  type: isPattern ? 'RestElement' : 'SpreadElement',
@@ -5555,7 +5720,7 @@ function parseSpreadOrRestElement(
5555
5720
  } as any);
5556
5721
  }
5557
5722
 
5558
- if (parser.token !== closingToken) {
5723
+ if (parser.getToken() !== closingToken) {
5559
5724
  if (kind & BindingKind.ArgumentList)
5560
5725
  destructible |= isAsync ? DestructuringKind.CannotDestruct : DestructuringKind.Assignable;
5561
5726
 
@@ -5622,12 +5787,19 @@ export function parseMethodDefinition(
5622
5787
  column: number
5623
5788
  ): ESTree.FunctionExpression {
5624
5789
  const modifierFlags =
5625
- (kind & PropertyKind.Constructor) === 0 ? 0b0000001111010000000_0000_00000000 : 0b0000000111000000000_0000_00000000;
5790
+ Context.InYieldContext |
5791
+ Context.InAwaitContext |
5792
+ Context.InArgumentList |
5793
+ ((kind & PropertyKind.Constructor) === 0 ? Context.SuperCall | Context.InConstructor : 0);
5626
5794
 
5627
5795
  context =
5628
5796
  ((context | modifierFlags) ^ modifierFlags) |
5629
- ((kind & 0b0000000000000000000_0000_01011000) << 18) |
5630
- 0b0000110000001000000_0000_00000000;
5797
+ (kind & PropertyKind.Generator ? Context.InYieldContext : 0) |
5798
+ (kind & PropertyKind.Async ? Context.InAwaitContext : 0) |
5799
+ (kind & PropertyKind.Constructor ? Context.InConstructor : 0) |
5800
+ Context.SuperProperty |
5801
+ Context.InMethod |
5802
+ Context.AllowNewTarget;
5631
5803
 
5632
5804
  let scope = context & Context.OptionsLexical ? addChildScope(createScope(), ScopeKind.FunctionParams) : void 0;
5633
5805
 
@@ -5642,7 +5814,14 @@ export function parseMethodDefinition(
5642
5814
 
5643
5815
  if (scope) scope = addChildScope(scope, ScopeKind.FunctionBody);
5644
5816
 
5645
- const body = parseFunctionBody(parser, context & ~(0x8001000 | Context.InGlobal), scope, Origin.None, void 0, void 0);
5817
+ const body = parseFunctionBody(
5818
+ parser,
5819
+ context & ~(Context.DisallowIn | Context.InSwitch | Context.InGlobal),
5820
+ scope,
5821
+ Origin.None,
5822
+ void 0,
5823
+ void 0
5824
+ );
5646
5825
 
5647
5826
  return finishNode(parser, context, start, line, column, {
5648
5827
  type: 'FunctionExpression',
@@ -5812,8 +5991,9 @@ export function parseObjectLiteralOrPattern(
5812
5991
 
5813
5992
  context = (context | Context.DisallowIn) ^ Context.DisallowIn;
5814
5993
 
5815
- while (parser.token !== Token.RightBrace) {
5816
- const { token, tokenValue, linePos, colPos, tokenPos } = parser;
5994
+ while (parser.getToken() !== Token.RightBrace) {
5995
+ const { tokenValue, linePos, colPos, tokenPos } = parser;
5996
+ const token = parser.getToken();
5817
5997
 
5818
5998
  if (token === Token.Ellipsis) {
5819
5999
  properties.push(
@@ -5836,11 +6016,15 @@ export function parseObjectLiteralOrPattern(
5836
6016
  let state = PropertyKind.None;
5837
6017
  let key: ESTree.Expression | null = null;
5838
6018
  let value;
5839
- const t = parser.token;
5840
- if (parser.token & (Token.IsIdentifier | Token.Keyword) || parser.token === Token.EscapedReserved) {
6019
+ const t = parser.getToken();
6020
+ if (parser.getToken() & (Token.IsIdentifier | Token.Keyword) || parser.getToken() === Token.EscapedReserved) {
5841
6021
  key = parseIdentifier(parser, context);
5842
6022
 
5843
- if (parser.token === Token.Comma || parser.token === Token.RightBrace || parser.token === Token.Assign) {
6023
+ if (
6024
+ parser.getToken() === Token.Comma ||
6025
+ parser.getToken() === Token.RightBrace ||
6026
+ parser.getToken() === Token.Assign
6027
+ ) {
5844
6028
  state |= PropertyKind.Shorthand;
5845
6029
 
5846
6030
  if (context & Context.Strict && (token & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
@@ -5860,8 +6044,8 @@ export function parseObjectLiteralOrPattern(
5860
6044
  parser.destructible & DestructuringKind.Yield
5861
6045
  ? DestructuringKind.Yield
5862
6046
  : 0 | (parser.destructible & DestructuringKind.Await)
5863
- ? DestructuringKind.Await
5864
- : 0;
6047
+ ? DestructuringKind.Await
6048
+ : 0;
5865
6049
 
5866
6050
  value = finishNode(parser, context, tokenPos, linePos, colPos, {
5867
6051
  type: 'AssignmentPattern',
@@ -5879,19 +6063,19 @@ export function parseObjectLiteralOrPattern(
5879
6063
 
5880
6064
  if (tokenValue === '__proto__') prototypeCount++;
5881
6065
 
5882
- if (parser.token & Token.IsIdentifier) {
5883
- const tokenAfterColon = parser.token;
6066
+ if (parser.getToken() & Token.IsIdentifier) {
6067
+ const tokenAfterColon = parser.getToken();
5884
6068
  const valueAfterColon = parser.tokenValue;
5885
6069
  // A reserved word is an IdentifierName that cannot be used as an Identifier
5886
6070
  destructible |= t === Token.EscapedReserved ? DestructuringKind.CannotDestruct : 0;
5887
6071
 
5888
6072
  value = parsePrimaryExpression(parser, context, kind, 0, 1, inGroup, 1, tokenPos, linePos, colPos);
5889
6073
 
5890
- const { token } = parser;
6074
+ const token = parser.getToken();
5891
6075
 
5892
6076
  value = parseMemberOrUpdateExpression(parser, context, value, inGroup, 0, tokenPos, linePos, colPos);
5893
6077
 
5894
- if (parser.token === Token.Comma || parser.token === Token.RightBrace) {
6078
+ if (parser.getToken() === Token.Comma || parser.getToken() === Token.RightBrace) {
5895
6079
  if (token === Token.Assign || token === Token.RightBrace || token === Token.Comma) {
5896
6080
  destructible |= parser.destructible & DestructuringKind.Await ? DestructuringKind.Await : 0;
5897
6081
  if (parser.assignable & AssignmentKind.CannotAssign) {
@@ -5905,7 +6089,7 @@ export function parseObjectLiteralOrPattern(
5905
6089
  ? DestructuringKind.Assignable
5906
6090
  : DestructuringKind.CannotDestruct;
5907
6091
  }
5908
- } else if ((parser.token & Token.IsAssignOp) === Token.IsAssignOp) {
6092
+ } else if ((parser.getToken() & Token.IsAssignOp) === Token.IsAssignOp) {
5909
6093
  if (parser.assignable & AssignmentKind.CannotAssign) {
5910
6094
  destructible |= DestructuringKind.CannotDestruct;
5911
6095
  } else if (token !== Token.Assign) {
@@ -5916,16 +6100,16 @@ export function parseObjectLiteralOrPattern(
5916
6100
  value = parseAssignmentExpression(parser, context, inGroup, isPattern, tokenPos, linePos, colPos, value);
5917
6101
  } else {
5918
6102
  destructible |= DestructuringKind.CannotDestruct;
5919
- if ((parser.token & Token.IsBinaryOp) === Token.IsBinaryOp) {
6103
+ if ((parser.getToken() & Token.IsBinaryOp) === Token.IsBinaryOp) {
5920
6104
  value = parseBinaryExpression(parser, context, 1, tokenPos, linePos, colPos, 4, token, value);
5921
6105
  }
5922
6106
  if (consumeOpt(parser, context | Context.AllowRegExp, Token.QuestionMark)) {
5923
6107
  value = parseConditionalExpression(parser, context, value, tokenPos, linePos, colPos);
5924
6108
  }
5925
6109
  }
5926
- } else if ((parser.token & Token.IsPatternStart) === Token.IsPatternStart) {
6110
+ } else if ((parser.getToken() & Token.IsPatternStart) === Token.IsPatternStart) {
5927
6111
  value =
5928
- parser.token === Token.LeftBracket
6112
+ parser.getToken() === Token.LeftBracket
5929
6113
  ? parseArrayExpressionOrPattern(
5930
6114
  parser,
5931
6115
  context,
@@ -5958,7 +6142,7 @@ export function parseObjectLiteralOrPattern(
5958
6142
  parser.assignable =
5959
6143
  destructible & DestructuringKind.CannotDestruct ? AssignmentKind.CannotAssign : AssignmentKind.Assignable;
5960
6144
 
5961
- if (parser.token === Token.Comma || parser.token === Token.RightBrace) {
6145
+ if (parser.getToken() === Token.Comma || parser.getToken() === Token.RightBrace) {
5962
6146
  if (parser.assignable & AssignmentKind.CannotAssign) destructible |= DestructuringKind.CannotDestruct;
5963
6147
  } else if (parser.destructible & DestructuringKind.HasToDestruct) {
5964
6148
  report(parser, Errors.InvalidDestructuringTarget);
@@ -5967,7 +6151,7 @@ export function parseObjectLiteralOrPattern(
5967
6151
 
5968
6152
  destructible = parser.assignable & AssignmentKind.CannotAssign ? DestructuringKind.CannotDestruct : 0;
5969
6153
 
5970
- if ((parser.token & Token.IsAssignOp) === Token.IsAssignOp) {
6154
+ if ((parser.getToken() & Token.IsAssignOp) === Token.IsAssignOp) {
5971
6155
  value = parseAssignmentExpressionOrPattern(
5972
6156
  parser,
5973
6157
  context,
@@ -5979,7 +6163,7 @@ export function parseObjectLiteralOrPattern(
5979
6163
  value
5980
6164
  );
5981
6165
  } else {
5982
- if ((parser.token & Token.IsBinaryOp) === Token.IsBinaryOp) {
6166
+ if ((parser.getToken() & Token.IsBinaryOp) === Token.IsBinaryOp) {
5983
6167
  value = parseBinaryExpression(parser, context, 1, tokenPos, linePos, colPos, 4, token, value);
5984
6168
  }
5985
6169
  if (consumeOpt(parser, context | Context.AllowRegExp, Token.QuestionMark)) {
@@ -5999,15 +6183,15 @@ export function parseObjectLiteralOrPattern(
5999
6183
  ? DestructuringKind.Assignable
6000
6184
  : DestructuringKind.CannotDestruct;
6001
6185
 
6002
- if (parser.token === Token.Comma || parser.token === Token.RightBrace) {
6186
+ if (parser.getToken() === Token.Comma || parser.getToken() === Token.RightBrace) {
6003
6187
  if (parser.assignable & AssignmentKind.CannotAssign) destructible |= DestructuringKind.CannotDestruct;
6004
6188
  } else {
6005
6189
  value = parseMemberOrUpdateExpression(parser, context, value, inGroup, 0, tokenPos, linePos, colPos);
6006
6190
 
6007
6191
  destructible = parser.assignable & AssignmentKind.CannotAssign ? DestructuringKind.CannotDestruct : 0;
6008
6192
 
6009
- if (parser.token !== Token.Comma && token !== Token.RightBrace) {
6010
- if (parser.token !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
6193
+ if (parser.getToken() !== Token.Comma && token !== Token.RightBrace) {
6194
+ if (parser.getToken() !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
6011
6195
  value = parseAssignmentExpression(
6012
6196
  parser,
6013
6197
  context,
@@ -6021,7 +6205,7 @@ export function parseObjectLiteralOrPattern(
6021
6205
  }
6022
6206
  }
6023
6207
  }
6024
- } else if (parser.token === Token.LeftBracket) {
6208
+ } else if (parser.getToken() === Token.LeftBracket) {
6025
6209
  destructible |= DestructuringKind.CannotDestruct;
6026
6210
  if (token === Token.AsyncKeyword) state |= PropertyKind.Async;
6027
6211
 
@@ -6029,8 +6213,8 @@ export function parseObjectLiteralOrPattern(
6029
6213
  (token === Token.GetKeyword
6030
6214
  ? PropertyKind.Getter
6031
6215
  : token === Token.SetKeyword
6032
- ? PropertyKind.Setter
6033
- : PropertyKind.Method) | PropertyKind.Computed;
6216
+ ? PropertyKind.Setter
6217
+ : PropertyKind.Method) | PropertyKind.Computed;
6034
6218
 
6035
6219
  key = parseComputedPropertyName(parser, context, inGroup);
6036
6220
  destructible |= parser.assignable;
@@ -6044,7 +6228,7 @@ export function parseObjectLiteralOrPattern(
6044
6228
  parser.linePos,
6045
6229
  parser.colPos
6046
6230
  );
6047
- } else if (parser.token & (Token.IsIdentifier | Token.Keyword)) {
6231
+ } else if (parser.getToken() & (Token.IsIdentifier | Token.Keyword)) {
6048
6232
  destructible |= DestructuringKind.CannotDestruct;
6049
6233
  if (token === Token.EscapedReserved) report(parser, Errors.InvalidEscapedKeyword);
6050
6234
  if (token === Token.AsyncKeyword) {
@@ -6057,8 +6241,8 @@ export function parseObjectLiteralOrPattern(
6057
6241
  token === Token.GetKeyword
6058
6242
  ? PropertyKind.Getter
6059
6243
  : token === Token.SetKeyword
6060
- ? PropertyKind.Setter
6061
- : PropertyKind.Method;
6244
+ ? PropertyKind.Setter
6245
+ : PropertyKind.Method;
6062
6246
 
6063
6247
  value = parseMethodDefinition(
6064
6248
  parser,
@@ -6069,7 +6253,7 @@ export function parseObjectLiteralOrPattern(
6069
6253
  parser.linePos,
6070
6254
  parser.colPos
6071
6255
  );
6072
- } else if (parser.token === Token.LeftParen) {
6256
+ } else if (parser.getToken() === Token.LeftParen) {
6073
6257
  destructible |= DestructuringKind.CannotDestruct;
6074
6258
  state |= PropertyKind.Method;
6075
6259
  value = parseMethodDefinition(
@@ -6081,7 +6265,7 @@ export function parseObjectLiteralOrPattern(
6081
6265
  parser.linePos,
6082
6266
  parser.colPos
6083
6267
  );
6084
- } else if (parser.token === Token.Multiply) {
6268
+ } else if (parser.getToken() === Token.Multiply) {
6085
6269
  destructible |= DestructuringKind.CannotDestruct;
6086
6270
 
6087
6271
  if (token === Token.GetKeyword) {
@@ -6097,16 +6281,16 @@ export function parseObjectLiteralOrPattern(
6097
6281
  state |=
6098
6282
  PropertyKind.Generator | PropertyKind.Method | (token === Token.AsyncKeyword ? PropertyKind.Async : 0);
6099
6283
 
6100
- if (parser.token & Token.IsIdentifier) {
6284
+ if (parser.getToken() & Token.IsIdentifier) {
6101
6285
  key = parseIdentifier(parser, context);
6102
- } else if ((parser.token & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
6286
+ } else if ((parser.getToken() & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
6103
6287
  key = parseLiteral(parser, context);
6104
- } else if (parser.token === Token.LeftBracket) {
6288
+ } else if (parser.getToken() === Token.LeftBracket) {
6105
6289
  state |= PropertyKind.Computed;
6106
6290
  key = parseComputedPropertyName(parser, context, inGroup);
6107
6291
  destructible |= parser.assignable;
6108
6292
  } else {
6109
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
6293
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
6110
6294
  }
6111
6295
  value = parseMethodDefinition(
6112
6296
  parser,
@@ -6117,15 +6301,15 @@ export function parseObjectLiteralOrPattern(
6117
6301
  parser.linePos,
6118
6302
  parser.colPos
6119
6303
  );
6120
- } else if ((parser.token & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
6304
+ } else if ((parser.getToken() & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
6121
6305
  if (token === Token.AsyncKeyword) state |= PropertyKind.Async;
6122
6306
 
6123
6307
  state |=
6124
6308
  token === Token.GetKeyword
6125
6309
  ? PropertyKind.Getter
6126
6310
  : token === Token.SetKeyword
6127
- ? PropertyKind.Setter
6128
- : PropertyKind.Method;
6311
+ ? PropertyKind.Setter
6312
+ : PropertyKind.Method;
6129
6313
 
6130
6314
  destructible |= DestructuringKind.CannotDestruct;
6131
6315
 
@@ -6143,24 +6327,25 @@ export function parseObjectLiteralOrPattern(
6143
6327
  } else {
6144
6328
  report(parser, Errors.UnexpectedCharAfterObjLit);
6145
6329
  }
6146
- } else if ((parser.token & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
6330
+ } else if ((parser.getToken() & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
6147
6331
  key = parseLiteral(parser, context);
6148
6332
 
6149
- if (parser.token === Token.Colon) {
6333
+ if (parser.getToken() === Token.Colon) {
6150
6334
  consume(parser, context | Context.AllowRegExp, Token.Colon);
6151
6335
 
6152
6336
  const { tokenPos, linePos, colPos } = parser;
6153
6337
 
6154
6338
  if (tokenValue === '__proto__') prototypeCount++;
6155
6339
 
6156
- if (parser.token & Token.IsIdentifier) {
6340
+ if (parser.getToken() & Token.IsIdentifier) {
6157
6341
  value = parsePrimaryExpression(parser, context, kind, 0, 1, inGroup, 1, tokenPos, linePos, colPos);
6158
6342
 
6159
- const { token, tokenValue: valueAfterColon } = parser;
6343
+ const { tokenValue: valueAfterColon } = parser;
6344
+ const token = parser.getToken();
6160
6345
 
6161
6346
  value = parseMemberOrUpdateExpression(parser, context, value, inGroup, 0, tokenPos, linePos, colPos);
6162
6347
 
6163
- if (parser.token === Token.Comma || parser.token === Token.RightBrace) {
6348
+ if (parser.getToken() === Token.Comma || parser.getToken() === Token.RightBrace) {
6164
6349
  if (token === Token.Assign || token === Token.RightBrace || token === Token.Comma) {
6165
6350
  if (parser.assignable & AssignmentKind.CannotAssign) {
6166
6351
  destructible |= DestructuringKind.CannotDestruct;
@@ -6173,16 +6358,16 @@ export function parseObjectLiteralOrPattern(
6173
6358
  ? DestructuringKind.Assignable
6174
6359
  : DestructuringKind.CannotDestruct;
6175
6360
  }
6176
- } else if (parser.token === Token.Assign) {
6361
+ } else if (parser.getToken() === Token.Assign) {
6177
6362
  if (parser.assignable & AssignmentKind.CannotAssign) destructible |= DestructuringKind.CannotDestruct;
6178
6363
  value = parseAssignmentExpression(parser, context, inGroup, isPattern, tokenPos, linePos, colPos, value);
6179
6364
  } else {
6180
6365
  destructible |= DestructuringKind.CannotDestruct;
6181
6366
  value = parseAssignmentExpression(parser, context, inGroup, isPattern, tokenPos, linePos, colPos, value);
6182
6367
  }
6183
- } else if ((parser.token & Token.IsPatternStart) === Token.IsPatternStart) {
6368
+ } else if ((parser.getToken() & Token.IsPatternStart) === Token.IsPatternStart) {
6184
6369
  value =
6185
- parser.token === Token.LeftBracket
6370
+ parser.getToken() === Token.LeftBracket
6186
6371
  ? parseArrayExpressionOrPattern(
6187
6372
  parser,
6188
6373
  context,
@@ -6215,7 +6400,7 @@ export function parseObjectLiteralOrPattern(
6215
6400
  parser.assignable =
6216
6401
  destructible & DestructuringKind.CannotDestruct ? AssignmentKind.CannotAssign : AssignmentKind.Assignable;
6217
6402
 
6218
- if (parser.token === Token.Comma || parser.token === Token.RightBrace) {
6403
+ if (parser.getToken() === Token.Comma || parser.getToken() === Token.RightBrace) {
6219
6404
  if (parser.assignable & AssignmentKind.CannotAssign) {
6220
6405
  destructible |= DestructuringKind.CannotDestruct;
6221
6406
  }
@@ -6223,7 +6408,7 @@ export function parseObjectLiteralOrPattern(
6223
6408
  value = parseMemberOrUpdateExpression(parser, context, value, inGroup, 0, tokenPos, linePos, colPos);
6224
6409
  destructible = parser.assignable & AssignmentKind.CannotAssign ? DestructuringKind.CannotDestruct : 0;
6225
6410
 
6226
- if ((parser.token & Token.IsAssignOp) === Token.IsAssignOp) {
6411
+ if ((parser.getToken() & Token.IsAssignOp) === Token.IsAssignOp) {
6227
6412
  value = parseAssignmentExpressionOrPattern(
6228
6413
  parser,
6229
6414
  context,
@@ -6235,7 +6420,7 @@ export function parseObjectLiteralOrPattern(
6235
6420
  value
6236
6421
  );
6237
6422
  } else {
6238
- if ((parser.token & Token.IsBinaryOp) === Token.IsBinaryOp) {
6423
+ if ((parser.getToken() & Token.IsBinaryOp) === Token.IsBinaryOp) {
6239
6424
  value = parseBinaryExpression(parser, context, 1, tokenPos, linePos, colPos, 4, token, value);
6240
6425
  }
6241
6426
  if (consumeOpt(parser, context | Context.AllowRegExp, Token.QuestionMark)) {
@@ -6255,7 +6440,7 @@ export function parseObjectLiteralOrPattern(
6255
6440
  ? DestructuringKind.Assignable
6256
6441
  : DestructuringKind.CannotDestruct;
6257
6442
 
6258
- if (parser.token === Token.Comma || parser.token === Token.RightBrace) {
6443
+ if (parser.getToken() === Token.Comma || parser.getToken() === Token.RightBrace) {
6259
6444
  if (parser.assignable & AssignmentKind.CannotAssign) {
6260
6445
  destructible |= DestructuringKind.CannotDestruct;
6261
6446
  }
@@ -6264,8 +6449,8 @@ export function parseObjectLiteralOrPattern(
6264
6449
 
6265
6450
  destructible = parser.assignable & AssignmentKind.Assignable ? 0 : DestructuringKind.CannotDestruct;
6266
6451
 
6267
- if (parser.token !== Token.Comma && parser.token !== Token.RightBrace) {
6268
- if (parser.token !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
6452
+ if (parser.getToken() !== Token.Comma && parser.getToken() !== Token.RightBrace) {
6453
+ if (parser.getToken() !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
6269
6454
  value = parseAssignmentExpression(
6270
6455
  parser,
6271
6456
  context,
@@ -6279,7 +6464,7 @@ export function parseObjectLiteralOrPattern(
6279
6464
  }
6280
6465
  }
6281
6466
  }
6282
- } else if (parser.token === Token.LeftParen) {
6467
+ } else if (parser.getToken() === Token.LeftParen) {
6283
6468
  state |= PropertyKind.Method;
6284
6469
  value = parseMethodDefinition(
6285
6470
  parser,
@@ -6294,32 +6479,33 @@ export function parseObjectLiteralOrPattern(
6294
6479
  } else {
6295
6480
  report(parser, Errors.InvalidObjLitKey);
6296
6481
  }
6297
- } else if (parser.token === Token.LeftBracket) {
6482
+ } else if (parser.getToken() === Token.LeftBracket) {
6298
6483
  key = parseComputedPropertyName(parser, context, inGroup);
6299
6484
 
6300
6485
  destructible |= parser.destructible & DestructuringKind.Yield ? DestructuringKind.Yield : 0;
6301
6486
 
6302
6487
  state |= PropertyKind.Computed;
6303
6488
 
6304
- if (parser.token === Token.Colon) {
6489
+ if (parser.getToken() === Token.Colon) {
6305
6490
  nextToken(parser, context | Context.AllowRegExp); // skip ':'
6306
6491
 
6307
- const { tokenPos, linePos, colPos, tokenValue, token: tokenAfterColon } = parser;
6492
+ const { tokenPos, linePos, colPos, tokenValue } = parser;
6493
+ const tokenAfterColon = parser.getToken();
6308
6494
 
6309
- if (parser.token & Token.IsIdentifier) {
6495
+ if (parser.getToken() & Token.IsIdentifier) {
6310
6496
  value = parsePrimaryExpression(parser, context, kind, 0, 1, inGroup, 1, tokenPos, linePos, colPos);
6311
6497
 
6312
- const { token } = parser;
6498
+ const token = parser.getToken();
6313
6499
 
6314
6500
  value = parseMemberOrUpdateExpression(parser, context, value, inGroup, 0, tokenPos, linePos, colPos);
6315
6501
 
6316
- if ((parser.token & Token.IsAssignOp) === Token.IsAssignOp) {
6502
+ if ((parser.getToken() & Token.IsAssignOp) === Token.IsAssignOp) {
6317
6503
  destructible |=
6318
6504
  parser.assignable & AssignmentKind.CannotAssign
6319
6505
  ? DestructuringKind.CannotDestruct
6320
6506
  : token === Token.Assign
6321
- ? 0
6322
- : DestructuringKind.Assignable;
6507
+ ? 0
6508
+ : DestructuringKind.Assignable;
6323
6509
  value = parseAssignmentExpressionOrPattern(
6324
6510
  parser,
6325
6511
  context,
@@ -6330,7 +6516,7 @@ export function parseObjectLiteralOrPattern(
6330
6516
  colPos,
6331
6517
  value
6332
6518
  );
6333
- } else if (parser.token === Token.Comma || parser.token === Token.RightBrace) {
6519
+ } else if (parser.getToken() === Token.Comma || parser.getToken() === Token.RightBrace) {
6334
6520
  if (token === Token.Assign || token === Token.RightBrace || token === Token.Comma) {
6335
6521
  if (parser.assignable & AssignmentKind.CannotAssign) {
6336
6522
  destructible |= DestructuringKind.CannotDestruct;
@@ -6347,9 +6533,9 @@ export function parseObjectLiteralOrPattern(
6347
6533
  destructible |= DestructuringKind.CannotDestruct;
6348
6534
  value = parseAssignmentExpression(parser, context, inGroup, isPattern, tokenPos, linePos, colPos, value);
6349
6535
  }
6350
- } else if ((parser.token & Token.IsPatternStart) === Token.IsPatternStart) {
6536
+ } else if ((parser.getToken() & Token.IsPatternStart) === Token.IsPatternStart) {
6351
6537
  value =
6352
- parser.token === Token.LeftBracket
6538
+ parser.getToken() === Token.LeftBracket
6353
6539
  ? parseArrayExpressionOrPattern(
6354
6540
  parser,
6355
6541
  context,
@@ -6382,7 +6568,7 @@ export function parseObjectLiteralOrPattern(
6382
6568
  parser.assignable =
6383
6569
  destructible & DestructuringKind.CannotDestruct ? AssignmentKind.CannotAssign : AssignmentKind.Assignable;
6384
6570
 
6385
- if (parser.token === Token.Comma || parser.token === Token.RightBrace) {
6571
+ if (parser.getToken() === Token.Comma || parser.getToken() === Token.RightBrace) {
6386
6572
  if (parser.assignable & AssignmentKind.CannotAssign) destructible |= DestructuringKind.CannotDestruct;
6387
6573
  } else if (destructible & DestructuringKind.HasToDestruct) {
6388
6574
  report(parser, Errors.InvalidShorthandPropInit);
@@ -6392,8 +6578,8 @@ export function parseObjectLiteralOrPattern(
6392
6578
  destructible =
6393
6579
  parser.assignable & AssignmentKind.CannotAssign ? destructible | DestructuringKind.CannotDestruct : 0;
6394
6580
 
6395
- if ((parser.token & Token.IsAssignOp) === Token.IsAssignOp) {
6396
- if (parser.token !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
6581
+ if ((parser.getToken() & Token.IsAssignOp) === Token.IsAssignOp) {
6582
+ if (parser.getToken() !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
6397
6583
  value = parseAssignmentExpressionOrPattern(
6398
6584
  parser,
6399
6585
  context,
@@ -6405,7 +6591,7 @@ export function parseObjectLiteralOrPattern(
6405
6591
  value
6406
6592
  );
6407
6593
  } else {
6408
- if ((parser.token & Token.IsBinaryOp) === Token.IsBinaryOp) {
6594
+ if ((parser.getToken() & Token.IsBinaryOp) === Token.IsBinaryOp) {
6409
6595
  value = parseBinaryExpression(parser, context, 1, tokenPos, linePos, colPos, 4, token, value);
6410
6596
  }
6411
6597
  if (consumeOpt(parser, context | Context.AllowRegExp, Token.QuestionMark)) {
@@ -6425,15 +6611,15 @@ export function parseObjectLiteralOrPattern(
6425
6611
  ? DestructuringKind.Assignable
6426
6612
  : DestructuringKind.CannotDestruct;
6427
6613
 
6428
- if (parser.token === Token.Comma || parser.token === Token.RightBrace) {
6614
+ if (parser.getToken() === Token.Comma || parser.getToken() === Token.RightBrace) {
6429
6615
  if (parser.assignable & AssignmentKind.CannotAssign) destructible |= DestructuringKind.CannotDestruct;
6430
6616
  } else {
6431
6617
  value = parseMemberOrUpdateExpression(parser, context, value, inGroup, 0, tokenPos, linePos, colPos);
6432
6618
 
6433
6619
  destructible = parser.assignable & AssignmentKind.Assignable ? 0 : DestructuringKind.CannotDestruct;
6434
6620
 
6435
- if (parser.token !== Token.Comma && parser.token !== Token.RightBrace) {
6436
- if (parser.token !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
6621
+ if (parser.getToken() !== Token.Comma && parser.getToken() !== Token.RightBrace) {
6622
+ if (parser.getToken() !== Token.Assign) destructible |= DestructuringKind.CannotDestruct;
6437
6623
  value = parseAssignmentExpression(
6438
6624
  parser,
6439
6625
  context,
@@ -6447,7 +6633,7 @@ export function parseObjectLiteralOrPattern(
6447
6633
  }
6448
6634
  }
6449
6635
  }
6450
- } else if (parser.token === Token.LeftParen) {
6636
+ } else if (parser.getToken() === Token.LeftParen) {
6451
6637
  state |= PropertyKind.Method;
6452
6638
 
6453
6639
  value = parseMethodDefinition(parser, context, state, inGroup, parser.tokenPos, linePos, colPos);
@@ -6461,14 +6647,15 @@ export function parseObjectLiteralOrPattern(
6461
6647
 
6462
6648
  state |= PropertyKind.Generator;
6463
6649
 
6464
- if (parser.token & Token.IsIdentifier) {
6465
- const { token, line, index } = parser;
6650
+ if (parser.getToken() & Token.IsIdentifier) {
6651
+ const { line, index } = parser;
6652
+ const token = parser.getToken();
6466
6653
 
6467
6654
  key = parseIdentifier(parser, context);
6468
6655
 
6469
6656
  state |= PropertyKind.Method;
6470
6657
 
6471
- if (parser.token === Token.LeftParen) {
6658
+ if (parser.getToken() === Token.LeftParen) {
6472
6659
  destructible |= DestructuringKind.CannotDestruct;
6473
6660
  value = parseMethodDefinition(
6474
6661
  parser,
@@ -6486,18 +6673,18 @@ export function parseObjectLiteralOrPattern(
6486
6673
  index,
6487
6674
  token === Token.AsyncKeyword
6488
6675
  ? Errors.InvalidAsyncGetter
6489
- : token === Token.GetKeyword || parser.token === Token.SetKeyword
6490
- ? Errors.InvalidGetSetGenerator
6491
- : Errors.InvalidGenMethodShorthand,
6676
+ : token === Token.GetKeyword || parser.getToken() === Token.SetKeyword
6677
+ ? Errors.InvalidGetSetGenerator
6678
+ : Errors.InvalidGenMethodShorthand,
6492
6679
  KeywordDescTable[token & Token.Type]
6493
6680
  );
6494
6681
  }
6495
- } else if ((parser.token & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
6682
+ } else if ((parser.getToken() & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
6496
6683
  destructible |= DestructuringKind.CannotDestruct;
6497
6684
  key = parseLiteral(parser, context);
6498
6685
  state |= PropertyKind.Method;
6499
6686
  value = parseMethodDefinition(parser, context, state, inGroup, tokenPos, linePos, colPos);
6500
- } else if (parser.token === Token.LeftBracket) {
6687
+ } else if (parser.getToken() === Token.LeftBracket) {
6501
6688
  destructible |= DestructuringKind.CannotDestruct;
6502
6689
  state |= PropertyKind.Computed | PropertyKind.Method;
6503
6690
  key = parseComputedPropertyName(parser, context, inGroup);
@@ -6535,7 +6722,7 @@ export function parseObjectLiteralOrPattern(
6535
6722
  }
6536
6723
 
6537
6724
  destructible |= parser.destructible;
6538
- if (parser.token !== Token.Comma) break;
6725
+ if (parser.getToken() !== Token.Comma) break;
6539
6726
  nextToken(parser, context);
6540
6727
  }
6541
6728
 
@@ -6548,7 +6735,7 @@ export function parseObjectLiteralOrPattern(
6548
6735
  properties
6549
6736
  });
6550
6737
 
6551
- if (!skipInitializer && parser.token & Token.IsAssignOp) {
6738
+ if (!skipInitializer && parser.getToken() & Token.IsAssignOp) {
6552
6739
  return parseArrayOrObjectAssignmentPattern(
6553
6740
  parser,
6554
6741
  context,
@@ -6593,7 +6780,7 @@ export function parseMethodFormals(
6593
6780
 
6594
6781
  parser.flags = (parser.flags | Flags.SimpleParameterList) ^ Flags.SimpleParameterList;
6595
6782
 
6596
- if (parser.token === Token.RightParen) {
6783
+ if (parser.getToken() === Token.RightParen) {
6597
6784
  if (kind & PropertyKind.Setter) {
6598
6785
  report(parser, Errors.AccessorWrongArgs, 'Setter', 'one', '');
6599
6786
  }
@@ -6604,7 +6791,7 @@ export function parseMethodFormals(
6604
6791
  if (kind & PropertyKind.Getter) {
6605
6792
  report(parser, Errors.AccessorWrongArgs, 'Getter', 'no', 's');
6606
6793
  }
6607
- if (kind & PropertyKind.Setter && parser.token === Token.Ellipsis) {
6794
+ if (kind & PropertyKind.Setter && parser.getToken() === Token.Ellipsis) {
6608
6795
  report(parser, Errors.BadSetterRestParameter);
6609
6796
  }
6610
6797
 
@@ -6613,17 +6800,17 @@ export function parseMethodFormals(
6613
6800
  let setterArgs = 0;
6614
6801
  let isSimpleParameterList: 0 | 1 = 0;
6615
6802
 
6616
- while (parser.token !== Token.Comma) {
6803
+ while (parser.getToken() !== Token.Comma) {
6617
6804
  let left = null;
6618
6805
  const { tokenPos, linePos, colPos } = parser;
6619
6806
 
6620
- if (parser.token & Token.IsIdentifier) {
6807
+ if (parser.getToken() & Token.IsIdentifier) {
6621
6808
  if ((context & Context.Strict) === 0) {
6622
- if ((parser.token & Token.FutureReserved) === Token.FutureReserved) {
6809
+ if ((parser.getToken() & Token.FutureReserved) === Token.FutureReserved) {
6623
6810
  parser.flags |= Flags.HasStrictReserved;
6624
6811
  }
6625
6812
 
6626
- if ((parser.token & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
6813
+ if ((parser.getToken() & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
6627
6814
  parser.flags |= Flags.StrictEvalArguments;
6628
6815
  }
6629
6816
  }
@@ -6639,7 +6826,7 @@ export function parseMethodFormals(
6639
6826
  colPos
6640
6827
  );
6641
6828
  } else {
6642
- if (parser.token === Token.LeftBrace) {
6829
+ if (parser.getToken() === Token.LeftBrace) {
6643
6830
  left = parseObjectLiteralOrPattern(
6644
6831
  parser,
6645
6832
  context,
@@ -6653,7 +6840,7 @@ export function parseMethodFormals(
6653
6840
  linePos,
6654
6841
  colPos
6655
6842
  );
6656
- } else if (parser.token === Token.LeftBracket) {
6843
+ } else if (parser.getToken() === Token.LeftBracket) {
6657
6844
  left = parseArrayExpressionOrPattern(
6658
6845
  parser,
6659
6846
  context,
@@ -6667,7 +6854,7 @@ export function parseMethodFormals(
6667
6854
  linePos,
6668
6855
  colPos
6669
6856
  );
6670
- } else if (parser.token === Token.Ellipsis) {
6857
+ } else if (parser.getToken() === Token.Ellipsis) {
6671
6858
  left = parseSpreadOrRestElement(
6672
6859
  parser,
6673
6860
  context,
@@ -6690,7 +6877,7 @@ export function parseMethodFormals(
6690
6877
  report(parser, Errors.InvalidBindingDestruct);
6691
6878
  }
6692
6879
 
6693
- if (parser.token === Token.Assign) {
6880
+ if (parser.getToken() === Token.Assign) {
6694
6881
  nextToken(parser, context | Context.AllowRegExp);
6695
6882
 
6696
6883
  isSimpleParameterList = 1;
@@ -6709,7 +6896,7 @@ export function parseMethodFormals(
6709
6896
  params.push(left as any);
6710
6897
 
6711
6898
  if (!consumeOpt(parser, context, Token.Comma)) break;
6712
- if (parser.token === Token.RightParen) {
6899
+ if (parser.getToken() === Token.RightParen) {
6713
6900
  // allow the trailing comma
6714
6901
  break;
6715
6902
  }
@@ -6800,15 +6987,16 @@ export function parseParenthesizedExpression(
6800
6987
 
6801
6988
  parser.assignable = AssignmentKind.Assignable;
6802
6989
 
6803
- while (parser.token !== Token.RightParen) {
6804
- const { token, tokenPos, linePos, colPos } = parser;
6990
+ while (parser.getToken() !== Token.RightParen) {
6991
+ const { tokenPos, linePos, colPos } = parser;
6992
+ const token = parser.getToken();
6805
6993
 
6806
6994
  if (token & (Token.IsIdentifier | Token.Keyword)) {
6807
6995
  if (scope) addBlockName(parser, context, scope, parser.tokenValue, BindingKind.ArgumentList, Origin.None);
6808
6996
 
6809
6997
  expr = parsePrimaryExpression(parser, context, kind, 0, 1, 1, 1, tokenPos, linePos, colPos);
6810
6998
 
6811
- if (parser.token === Token.RightParen || parser.token === Token.Comma) {
6999
+ if (parser.getToken() === Token.RightParen || parser.getToken() === Token.Comma) {
6812
7000
  if (parser.assignable & AssignmentKind.CannotAssign) {
6813
7001
  destructible |= DestructuringKind.CannotDestruct;
6814
7002
  isSimpleParameterList = 1;
@@ -6819,7 +7007,7 @@ export function parseParenthesizedExpression(
6819
7007
  isSimpleParameterList = 1;
6820
7008
  }
6821
7009
  } else {
6822
- if (parser.token === Token.Assign) {
7010
+ if (parser.getToken() === Token.Assign) {
6823
7011
  isSimpleParameterList = 1;
6824
7012
  } else {
6825
7013
  destructible |= DestructuringKind.CannotDestruct;
@@ -6827,7 +7015,7 @@ export function parseParenthesizedExpression(
6827
7015
 
6828
7016
  expr = parseMemberOrUpdateExpression(parser, context, expr, /* inGroup */ 1, 0, tokenPos, linePos, colPos);
6829
7017
 
6830
- if (parser.token !== Token.RightParen && parser.token !== Token.Comma) {
7018
+ if (parser.getToken() !== Token.RightParen && parser.getToken() !== Token.Comma) {
6831
7019
  expr = parseAssignmentExpression(parser, context, 1, 0, tokenPos, linePos, colPos, expr);
6832
7020
  }
6833
7021
  }
@@ -6867,14 +7055,14 @@ export function parseParenthesizedExpression(
6867
7055
 
6868
7056
  parser.assignable = AssignmentKind.CannotAssign;
6869
7057
 
6870
- if (parser.token !== Token.RightParen && parser.token !== Token.Comma) {
7058
+ if (parser.getToken() !== Token.RightParen && parser.getToken() !== Token.Comma) {
6871
7059
  if (destructible & DestructuringKind.HasToDestruct) report(parser, Errors.InvalidPatternTail);
6872
7060
 
6873
7061
  expr = parseMemberOrUpdateExpression(parser, context, expr, 0, 0, tokenPos, linePos, colPos);
6874
7062
 
6875
7063
  destructible |= DestructuringKind.CannotDestruct;
6876
7064
 
6877
- if (parser.token !== Token.RightParen && parser.token !== Token.Comma) {
7065
+ if (parser.getToken() !== Token.RightParen && parser.getToken() !== Token.Comma) {
6878
7066
  expr = parseAssignmentExpression(parser, context, 0, 0, tokenPos, linePos, colPos, expr);
6879
7067
  }
6880
7068
  }
@@ -6898,7 +7086,7 @@ export function parseParenthesizedExpression(
6898
7086
 
6899
7087
  isSimpleParameterList = 1;
6900
7088
 
6901
- if (isSequence && (parser.token === Token.RightParen || parser.token === Token.Comma)) {
7089
+ if (isSequence && (parser.getToken() === Token.RightParen || parser.getToken() === Token.Comma)) {
6902
7090
  expressions.push(expr);
6903
7091
  }
6904
7092
  destructible |= DestructuringKind.HasToDestruct;
@@ -6908,11 +7096,11 @@ export function parseParenthesizedExpression(
6908
7096
 
6909
7097
  expr = parseExpression(parser, context, 1, 1, tokenPos, linePos, colPos);
6910
7098
 
6911
- if (isSequence && (parser.token === Token.RightParen || parser.token === Token.Comma)) {
7099
+ if (isSequence && (parser.getToken() === Token.RightParen || parser.getToken() === Token.Comma)) {
6912
7100
  expressions.push(expr);
6913
7101
  }
6914
7102
 
6915
- if (parser.token === Token.Comma) {
7103
+ if (parser.getToken() === Token.Comma) {
6916
7104
  if (!isSequence) {
6917
7105
  isSequence = 1;
6918
7106
  expressions = [expr];
@@ -6939,7 +7127,7 @@ export function parseParenthesizedExpression(
6939
7127
  return expr;
6940
7128
  }
6941
7129
 
6942
- if (isSequence && (parser.token === Token.RightParen || parser.token === Token.Comma)) {
7130
+ if (isSequence && (parser.getToken() === Token.RightParen || parser.getToken() === Token.Comma)) {
6943
7131
  expressions.push(expr);
6944
7132
  }
6945
7133
 
@@ -6950,7 +7138,7 @@ export function parseParenthesizedExpression(
6950
7138
  expressions = [expr];
6951
7139
  }
6952
7140
 
6953
- if (parser.token === Token.RightParen) {
7141
+ if (parser.getToken() === Token.RightParen) {
6954
7142
  destructible |= DestructuringKind.HasToDestruct;
6955
7143
  break;
6956
7144
  }
@@ -6974,10 +7162,10 @@ export function parseParenthesizedExpression(
6974
7162
  parser.destructible & DestructuringKind.Yield
6975
7163
  ? DestructuringKind.Yield
6976
7164
  : 0 | (parser.destructible & DestructuringKind.Await)
6977
- ? DestructuringKind.Await
6978
- : 0;
7165
+ ? DestructuringKind.Await
7166
+ : 0;
6979
7167
 
6980
- if (parser.token === Token.Arrow) {
7168
+ if (parser.getToken() === Token.Arrow) {
6981
7169
  if (destructible & (DestructuringKind.Assignable | DestructuringKind.CannotDestruct))
6982
7170
  report(parser, Errors.InvalidArrowDestructLHS);
6983
7171
  if (context & (Context.InAwaitContext | Context.Module) && destructible & DestructuringKind.Await)
@@ -7032,7 +7220,7 @@ export function parseIdentifierOrArrow(
7032
7220
 
7033
7221
  const expr = parseIdentifier(parser, context);
7034
7222
  parser.assignable = AssignmentKind.Assignable;
7035
- if (parser.token === Token.Arrow) {
7223
+ if (parser.getToken() === Token.Arrow) {
7036
7224
  let scope: ScopeState | undefined = void 0;
7037
7225
 
7038
7226
  if (context & Context.OptionsLexical) scope = createArrowHeadParsingScope(parser, context, tokenValue);
@@ -7149,9 +7337,11 @@ export function parseArrowFunctionExpression(
7149
7337
 
7150
7338
  consume(parser, context | Context.AllowRegExp, Token.Arrow);
7151
7339
 
7152
- context = ((context | 0b0000000111100000000_0000_00000000) ^ 0b0000000111100000000_0000_00000000) | (isAsync << 22);
7340
+ const modifierFlags = Context.InYieldContext | Context.InAwaitContext | Context.InArgumentList;
7341
+
7342
+ context = ((context | modifierFlags) ^ modifierFlags) | (isAsync ? Context.InAwaitContext : 0);
7153
7343
 
7154
- const expression = parser.token !== Token.LeftBrace;
7344
+ const expression = parser.getToken() !== Token.LeftBrace;
7155
7345
 
7156
7346
  let body: ESTree.BlockStatement | ESTree.Expression;
7157
7347
 
@@ -7173,17 +7363,11 @@ export function parseArrowFunctionExpression(
7173
7363
  } else {
7174
7364
  if (scope) scope = addChildScope(scope, ScopeKind.FunctionBody);
7175
7365
 
7176
- body = parseFunctionBody(
7177
- parser,
7178
- (context | 0b0001000000000000001_0000_00000000 | Context.InGlobal | Context.InClass) ^
7179
- (0b0001000000000000001_0000_00000000 | Context.InGlobal | Context.InClass),
7180
- scope,
7181
- Origin.Arrow,
7182
- void 0,
7183
- void 0
7184
- );
7366
+ const modifierFlags = Context.InSwitch | Context.DisallowIn | Context.InGlobal | Context.InClass;
7367
+
7368
+ body = parseFunctionBody(parser, (context | modifierFlags) ^ modifierFlags, scope, Origin.Arrow, void 0, void 0);
7185
7369
 
7186
- switch (parser.token) {
7370
+ switch (parser.getToken()) {
7187
7371
  case Token.LeftBracket:
7188
7372
  if ((parser.flags & Flags.NewLine) === 0) {
7189
7373
  report(parser, Errors.InvalidInvokedBlockBodyArrow);
@@ -7201,9 +7385,9 @@ export function parseArrowFunctionExpression(
7201
7385
  break;
7202
7386
  default: // ignore
7203
7387
  }
7204
- if ((parser.token & Token.IsBinaryOp) === Token.IsBinaryOp && (parser.flags & Flags.NewLine) === 0)
7205
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
7206
- if ((parser.token & Token.IsUpdateOp) === Token.IsUpdateOp) report(parser, Errors.InvalidArrowPostfix);
7388
+ if ((parser.getToken() & Token.IsBinaryOp) === Token.IsBinaryOp && (parser.flags & Flags.NewLine) === 0)
7389
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
7390
+ if ((parser.getToken() & Token.IsUpdateOp) === Token.IsUpdateOp) report(parser, Errors.InvalidArrowPostfix);
7207
7391
  }
7208
7392
 
7209
7393
  parser.assignable = AssignmentKind.CannotAssign;
@@ -7267,17 +7451,17 @@ export function parseFormalParametersOrFormalList(
7267
7451
 
7268
7452
  let isSimpleParameterList: 0 | 1 = 0;
7269
7453
 
7270
- while (parser.token !== Token.Comma) {
7454
+ while (parser.getToken() !== Token.Comma) {
7271
7455
  let left: any;
7272
7456
 
7273
7457
  const { tokenPos, linePos, colPos } = parser;
7274
7458
 
7275
- if (parser.token & Token.IsIdentifier) {
7459
+ if (parser.getToken() & Token.IsIdentifier) {
7276
7460
  if ((context & Context.Strict) === 0) {
7277
- if ((parser.token & Token.FutureReserved) === Token.FutureReserved) {
7461
+ if ((parser.getToken() & Token.FutureReserved) === Token.FutureReserved) {
7278
7462
  parser.flags |= Flags.HasStrictReserved;
7279
7463
  }
7280
- if ((parser.token & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
7464
+ if ((parser.getToken() & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
7281
7465
  parser.flags |= Flags.StrictEvalArguments;
7282
7466
  }
7283
7467
  }
@@ -7293,7 +7477,7 @@ export function parseFormalParametersOrFormalList(
7293
7477
  colPos
7294
7478
  );
7295
7479
  } else {
7296
- if (parser.token === Token.LeftBrace) {
7480
+ if (parser.getToken() === Token.LeftBrace) {
7297
7481
  left = parseObjectLiteralOrPattern(
7298
7482
  parser,
7299
7483
  context,
@@ -7307,7 +7491,7 @@ export function parseFormalParametersOrFormalList(
7307
7491
  linePos,
7308
7492
  colPos
7309
7493
  );
7310
- } else if (parser.token === Token.LeftBracket) {
7494
+ } else if (parser.getToken() === Token.LeftBracket) {
7311
7495
  left = parseArrayExpressionOrPattern(
7312
7496
  parser,
7313
7497
  context,
@@ -7321,7 +7505,7 @@ export function parseFormalParametersOrFormalList(
7321
7505
  linePos,
7322
7506
  colPos
7323
7507
  );
7324
- } else if (parser.token === Token.Ellipsis) {
7508
+ } else if (parser.getToken() === Token.Ellipsis) {
7325
7509
  left = parseSpreadOrRestElement(
7326
7510
  parser,
7327
7511
  context,
@@ -7337,7 +7521,7 @@ export function parseFormalParametersOrFormalList(
7337
7521
  colPos
7338
7522
  );
7339
7523
  } else {
7340
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
7524
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
7341
7525
  }
7342
7526
 
7343
7527
  isSimpleParameterList = 1;
@@ -7347,7 +7531,7 @@ export function parseFormalParametersOrFormalList(
7347
7531
  }
7348
7532
  }
7349
7533
 
7350
- if (parser.token === Token.Assign) {
7534
+ if (parser.getToken() === Token.Assign) {
7351
7535
  nextToken(parser, context | Context.AllowRegExp);
7352
7536
 
7353
7537
  isSimpleParameterList = 1;
@@ -7364,7 +7548,7 @@ export function parseFormalParametersOrFormalList(
7364
7548
  params.push(left);
7365
7549
 
7366
7550
  if (!consumeOpt(parser, context, Token.Comma)) break;
7367
- if (parser.token === Token.RightParen) {
7551
+ if (parser.getToken() === Token.RightParen) {
7368
7552
  // allow the trailing comma
7369
7553
  break;
7370
7554
  }
@@ -7401,7 +7585,7 @@ export function parseMembeExpressionNoCall(
7401
7585
  line: number,
7402
7586
  column: number
7403
7587
  ): any {
7404
- const { token } = parser;
7588
+ const token = parser.getToken();
7405
7589
 
7406
7590
  if (token & Token.IsMemberOrCallExpression) {
7407
7591
  /* Property */
@@ -7463,7 +7647,7 @@ export function parseMembeExpressionNoCall(
7463
7647
  type: 'TaggedTemplateExpression',
7464
7648
  tag: expr,
7465
7649
  quasi:
7466
- parser.token === Token.TemplateContinuation
7650
+ parser.getToken() === Token.TemplateContinuation
7467
7651
  ? parseTemplate(parser, context | Context.TaggedTemplate)
7468
7652
  : parseTemplateLiteral(parser, context, parser.tokenPos, parser.linePos, parser.colPos)
7469
7653
  }),
@@ -7515,7 +7699,7 @@ export function parseNewExpression(
7515
7699
  const { tokenPos, linePos, colPos } = parser;
7516
7700
 
7517
7701
  if (consumeOpt(parser, context, Token.Period)) {
7518
- if (context & Context.AllowNewTarget && parser.token === Token.Target) {
7702
+ if (context & Context.AllowNewTarget && parser.getToken() === Token.Target) {
7519
7703
  parser.assignable = AssignmentKind.CannotAssign;
7520
7704
  return parseMetaProperty(parser, context, id, start, line, column);
7521
7705
  }
@@ -7525,15 +7709,15 @@ export function parseNewExpression(
7525
7709
 
7526
7710
  parser.assignable = AssignmentKind.CannotAssign;
7527
7711
 
7528
- if ((parser.token & Token.IsUnaryOp) === Token.IsUnaryOp) {
7529
- report(parser, Errors.InvalidNewUnary, KeywordDescTable[parser.token & Token.Type]);
7712
+ if ((parser.getToken() & Token.IsUnaryOp) === Token.IsUnaryOp) {
7713
+ report(parser, Errors.InvalidNewUnary, KeywordDescTable[parser.getToken() & Token.Type]);
7530
7714
  }
7531
7715
 
7532
7716
  const expr = parsePrimaryExpression(parser, context, BindingKind.Empty, 1, 0, inGroup, 1, tokenPos, linePos, colPos);
7533
7717
 
7534
7718
  context = (context | Context.DisallowIn) ^ Context.DisallowIn;
7535
7719
 
7536
- if (parser.token === Token.QuestionMarkPeriod) report(parser, Errors.OptionalChainingNoNew);
7720
+ if (parser.getToken() === Token.QuestionMarkPeriod) report(parser, Errors.OptionalChainingNoNew);
7537
7721
 
7538
7722
  // NewExpression without arguments.
7539
7723
  const callee = parseMembeExpressionNoCall(parser, context, expr, inGroup, tokenPos, linePos, colPos);
@@ -7543,7 +7727,7 @@ export function parseNewExpression(
7543
7727
  return finishNode(parser, context, start, line, column, {
7544
7728
  type: 'NewExpression',
7545
7729
  callee,
7546
- arguments: parser.token === Token.LeftParen ? parseArguments(parser, context, inGroup) : []
7730
+ arguments: parser.getToken() === Token.LeftParen ? parseArguments(parser, context, inGroup) : []
7547
7731
  });
7548
7732
  }
7549
7733
 
@@ -7599,13 +7783,13 @@ function parseAsyncArrowAfterIdent(
7599
7783
  line: number,
7600
7784
  column: number
7601
7785
  ) {
7602
- if (parser.token === Token.AwaitKeyword) report(parser, Errors.AwaitInParameter);
7786
+ if (parser.getToken() === Token.AwaitKeyword) report(parser, Errors.AwaitInParameter);
7603
7787
 
7604
- if (context & (Context.Strict | Context.InYieldContext) && parser.token === Token.YieldKeyword) {
7788
+ if (context & (Context.Strict | Context.InYieldContext) && parser.getToken() === Token.YieldKeyword) {
7605
7789
  report(parser, Errors.YieldInParameter);
7606
7790
  }
7607
7791
 
7608
- if ((parser.token & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
7792
+ if ((parser.getToken() & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
7609
7793
  parser.flags |= Flags.StrictEvalArguments;
7610
7794
  }
7611
7795
 
@@ -7657,7 +7841,7 @@ export function parseAsyncArrowOrCallExpression(
7657
7841
  context = (context | Context.DisallowIn) ^ Context.DisallowIn;
7658
7842
 
7659
7843
  if (consumeOpt(parser, context, Token.RightParen)) {
7660
- if (parser.token === Token.Arrow) {
7844
+ if (parser.getToken() === Token.Arrow) {
7661
7845
  if (flags & Flags.NewLine) report(parser, Errors.InvalidLineBreak);
7662
7846
  return parseParenthesizedArrow(parser, context, scope, [], canAssign, 1, start, line, column);
7663
7847
  }
@@ -7679,15 +7863,16 @@ export function parseAsyncArrowOrCallExpression(
7679
7863
 
7680
7864
  const params: ESTree.Expression[] = [];
7681
7865
 
7682
- while (parser.token !== Token.RightParen) {
7683
- const { token, tokenPos, linePos, colPos } = parser;
7866
+ while (parser.getToken() !== Token.RightParen) {
7867
+ const { tokenPos, linePos, colPos } = parser;
7868
+ const token = parser.getToken();
7684
7869
 
7685
7870
  if (token & (Token.IsIdentifier | Token.Keyword)) {
7686
7871
  if (scope) addBlockName(parser, context, scope, parser.tokenValue, kind, Origin.None);
7687
7872
 
7688
7873
  expr = parsePrimaryExpression(parser, context, kind, 0, 1, 1, 1, tokenPos, linePos, colPos);
7689
7874
 
7690
- if (parser.token === Token.RightParen || parser.token === Token.Comma) {
7875
+ if (parser.getToken() === Token.RightParen || parser.getToken() === Token.Comma) {
7691
7876
  if (parser.assignable & AssignmentKind.CannotAssign) {
7692
7877
  destructible |= DestructuringKind.CannotDestruct;
7693
7878
  isSimpleParameterList = 1;
@@ -7697,7 +7882,7 @@ export function parseAsyncArrowOrCallExpression(
7697
7882
  parser.flags |= Flags.HasStrictReserved;
7698
7883
  }
7699
7884
  } else {
7700
- if (parser.token === Token.Assign) {
7885
+ if (parser.getToken() === Token.Assign) {
7701
7886
  isSimpleParameterList = 1;
7702
7887
  } else {
7703
7888
  destructible |= DestructuringKind.CannotDestruct;
@@ -7714,7 +7899,7 @@ export function parseAsyncArrowOrCallExpression(
7714
7899
  colPos
7715
7900
  );
7716
7901
 
7717
- if (parser.token !== Token.RightParen && parser.token !== Token.Comma) {
7902
+ if (parser.getToken() !== Token.RightParen && parser.getToken() !== Token.Comma) {
7718
7903
  expr = parseAssignmentExpression(parser, context, 1, 0, tokenPos, linePos, colPos, expr as ESTree.Expression);
7719
7904
  }
7720
7905
  }
@@ -7728,14 +7913,14 @@ export function parseAsyncArrowOrCallExpression(
7728
7913
 
7729
7914
  isSimpleParameterList = 1;
7730
7915
 
7731
- if (parser.token !== Token.RightParen && parser.token !== Token.Comma) {
7916
+ if (parser.getToken() !== Token.RightParen && parser.getToken() !== Token.Comma) {
7732
7917
  if (destructible & DestructuringKind.HasToDestruct) report(parser, Errors.InvalidPatternTail);
7733
7918
 
7734
7919
  expr = parseMemberOrUpdateExpression(parser, context, expr, 0, 0, tokenPos, linePos, colPos);
7735
7920
 
7736
7921
  destructible |= DestructuringKind.CannotDestruct;
7737
7922
 
7738
- if ((parser.token & Token.IsBinaryOp) === Token.IsBinaryOp) {
7923
+ if ((parser.getToken() & Token.IsBinaryOp) === Token.IsBinaryOp) {
7739
7924
  expr = parseBinaryExpression(parser, context, 1, start, line, column, 4, token, expr as ESTree.Expression);
7740
7925
  }
7741
7926
  if (consumeOpt(parser, context | Context.AllowRegExp, Token.QuestionMark)) {
@@ -7758,7 +7943,8 @@ export function parseAsyncArrowOrCallExpression(
7758
7943
  colPos
7759
7944
  );
7760
7945
 
7761
- destructible |= (parser.token === Token.RightParen ? 0 : DestructuringKind.CannotDestruct) | parser.destructible;
7946
+ destructible |=
7947
+ (parser.getToken() === Token.RightParen ? 0 : DestructuringKind.CannotDestruct) | parser.destructible;
7762
7948
 
7763
7949
  isSimpleParameterList = 1;
7764
7950
  } else {
@@ -7798,10 +7984,10 @@ export function parseAsyncArrowOrCallExpression(
7798
7984
  parser.destructible & DestructuringKind.Yield
7799
7985
  ? DestructuringKind.Yield
7800
7986
  : 0 | (parser.destructible & DestructuringKind.Await)
7801
- ? DestructuringKind.Await
7802
- : 0;
7987
+ ? DestructuringKind.Await
7988
+ : 0;
7803
7989
 
7804
- if (parser.token === Token.Arrow) {
7990
+ if (parser.getToken() === Token.Arrow) {
7805
7991
  if (destructible & (DestructuringKind.Assignable | DestructuringKind.CannotDestruct))
7806
7992
  report(parser, Errors.InvalidLHSAsyncArrow);
7807
7993
  if (parser.flags & Flags.NewLine || flags & Flags.NewLine) report(parser, Errors.InvalidLineBreak);
@@ -7906,12 +8092,12 @@ export function parseClassDeclaration(
7906
8092
 
7907
8093
  const { tokenValue } = parser;
7908
8094
 
7909
- if (parser.token & Token.Keyword && parser.token !== Token.ExtendsKeyword) {
7910
- if (isStrictReservedWord(parser, context, parser.token)) {
8095
+ if (parser.getToken() & Token.Keyword && parser.getToken() !== Token.ExtendsKeyword) {
8096
+ if (isStrictReservedWord(parser, context, parser.getToken())) {
7911
8097
  report(parser, Errors.UnexpectedStrictReserved);
7912
8098
  }
7913
8099
 
7914
- if ((parser.token & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
8100
+ if ((parser.getToken() & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
7915
8101
  report(parser, Errors.StrictEvalArguments);
7916
8102
  }
7917
8103
 
@@ -7953,27 +8139,13 @@ export function parseClassDeclaration(
7953
8139
 
7954
8140
  const body = parseClassBody(parser, inheritedContext, context, scope, BindingKind.Empty, Origin.Declaration, 0);
7955
8141
 
7956
- return finishNode(
7957
- parser,
7958
- context,
7959
- start,
7960
- line,
7961
- column,
7962
- context & Context.OptionsNext
7963
- ? {
7964
- type: 'ClassDeclaration',
7965
- id,
7966
- superClass,
7967
- decorators,
7968
- body
7969
- }
7970
- : {
7971
- type: 'ClassDeclaration',
7972
- id,
7973
- superClass,
7974
- body
7975
- }
7976
- );
8142
+ return finishNode(parser, context, start, line, column, {
8143
+ type: 'ClassDeclaration',
8144
+ id,
8145
+ superClass,
8146
+ body,
8147
+ ...(context & Context.OptionsNext ? { decorators } : null)
8148
+ });
7977
8149
  }
7978
8150
 
7979
8151
  /**
@@ -8011,9 +8183,9 @@ export function parseClassExpression(
8011
8183
 
8012
8184
  nextToken(parser, context);
8013
8185
 
8014
- if (parser.token & Token.Keyword && parser.token !== Token.ExtendsKeyword) {
8015
- if (isStrictReservedWord(parser, context, parser.token)) report(parser, Errors.UnexpectedStrictReserved);
8016
- if ((parser.token & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
8186
+ if (parser.getToken() & Token.Keyword && parser.getToken() !== Token.ExtendsKeyword) {
8187
+ if (isStrictReservedWord(parser, context, parser.getToken())) report(parser, Errors.UnexpectedStrictReserved);
8188
+ if ((parser.getToken() & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
8017
8189
  report(parser, Errors.StrictEvalArguments);
8018
8190
  }
8019
8191
 
@@ -8043,27 +8215,13 @@ export function parseClassExpression(
8043
8215
 
8044
8216
  parser.assignable = AssignmentKind.CannotAssign;
8045
8217
 
8046
- return finishNode(
8047
- parser,
8048
- context,
8049
- start,
8050
- line,
8051
- column,
8052
- context & Context.OptionsNext
8053
- ? {
8054
- type: 'ClassExpression',
8055
- id,
8056
- superClass,
8057
- decorators,
8058
- body
8059
- }
8060
- : {
8061
- type: 'ClassExpression',
8062
- id,
8063
- superClass,
8064
- body
8065
- }
8066
- );
8218
+ return finishNode(parser, context, start, line, column, {
8219
+ type: 'ClassExpression',
8220
+ id,
8221
+ superClass,
8222
+ body,
8223
+ ...(context & Context.OptionsNext ? { decorators } : null)
8224
+ });
8067
8225
  }
8068
8226
 
8069
8227
  /**
@@ -8076,7 +8234,7 @@ export function parseDecorators(parser: ParserState, context: Context): ESTree.D
8076
8234
  const list: ESTree.Decorator[] = [];
8077
8235
 
8078
8236
  if (context & Context.OptionsNext) {
8079
- while (parser.token === Token.Decorator) {
8237
+ while (parser.getToken() === Token.Decorator) {
8080
8238
  list.push(parseDecoratorList(parser, context, parser.tokenPos, parser.linePos, parser.colPos));
8081
8239
  }
8082
8240
  }
@@ -8187,13 +8345,13 @@ export function parseClassBody(
8187
8345
  consume(parser, context | Context.AllowRegExp, Token.LeftBrace);
8188
8346
  context = (context | Context.DisallowIn) ^ Context.DisallowIn;
8189
8347
 
8190
- let hasConstr = parser.flags & Flags.HasConstructor;
8348
+ const hasConstr = parser.flags & Flags.HasConstructor;
8191
8349
  parser.flags = (parser.flags | Flags.HasConstructor) ^ Flags.HasConstructor;
8192
8350
 
8193
8351
  const body: (ESTree.MethodDefinition | ESTree.PropertyDefinition | ESTree.StaticBlock)[] = [];
8194
8352
  let decorators: ESTree.Decorator[];
8195
8353
 
8196
- while (parser.token !== Token.RightBrace) {
8354
+ while (parser.getToken() !== Token.RightBrace) {
8197
8355
  let length = 0;
8198
8356
 
8199
8357
  // See: https://github.com/tc39/proposal-decorators
@@ -8206,7 +8364,7 @@ export function parseClassBody(
8206
8364
  report(parser, Errors.GeneratorConstructor);
8207
8365
  }
8208
8366
 
8209
- if (parser.token === Token.RightBrace) report(parser, Errors.TrailingDecorators);
8367
+ if (parser.getToken() === Token.RightBrace) report(parser, Errors.TrailingDecorators);
8210
8368
 
8211
8369
  if (consumeOpt(parser, context, Token.Semicolon)) {
8212
8370
  if (length > 0) report(parser, Errors.InvalidDecoratorSemicolon);
@@ -8263,7 +8421,8 @@ function parseClassElementList(
8263
8421
  let kind: PropertyKind = isStatic ? PropertyKind.Static : PropertyKind.None;
8264
8422
  let key: ESTree.Expression | ESTree.PrivateIdentifier | null = null;
8265
8423
 
8266
- const { token, tokenPos, linePos, colPos } = parser;
8424
+ const { tokenPos, linePos, colPos } = parser;
8425
+ const token = parser.getToken();
8267
8426
 
8268
8427
  if (token & (Token.IsIdentifier | Token.FutureReserved)) {
8269
8428
  key = parseIdentifier(parser, context);
@@ -8272,9 +8431,9 @@ function parseClassElementList(
8272
8431
  case Token.StaticKeyword:
8273
8432
  if (
8274
8433
  !isStatic &&
8275
- parser.token !== Token.LeftParen &&
8276
- (parser.token & Token.IsAutoSemicolon) !== Token.IsAutoSemicolon &&
8277
- parser.token !== Token.Assign
8434
+ parser.getToken() !== Token.LeftParen &&
8435
+ (parser.getToken() & Token.IsAutoSemicolon) !== Token.IsAutoSemicolon &&
8436
+ parser.getToken() !== Token.Assign
8278
8437
  ) {
8279
8438
  return parseClassElementList(
8280
8439
  parser,
@@ -8293,8 +8452,8 @@ function parseClassElementList(
8293
8452
  break;
8294
8453
 
8295
8454
  case Token.AsyncKeyword:
8296
- if (parser.token !== Token.LeftParen && (parser.flags & Flags.NewLine) === 0) {
8297
- if (context & Context.OptionsNext && (parser.token & Token.IsClassField) === Token.IsClassField) {
8455
+ if (parser.getToken() !== Token.LeftParen && (parser.flags & Flags.NewLine) === 0) {
8456
+ if ((parser.getToken() & Token.IsClassField) === Token.IsClassField) {
8298
8457
  return parsePropertyDefinition(parser, context, key, kind, decorators, tokenPos, linePos, colPos);
8299
8458
  }
8300
8459
 
@@ -8303,8 +8462,8 @@ function parseClassElementList(
8303
8462
  break;
8304
8463
 
8305
8464
  case Token.GetKeyword:
8306
- if (parser.token !== Token.LeftParen) {
8307
- if (context & Context.OptionsNext && (parser.token & Token.IsClassField) === Token.IsClassField) {
8465
+ if (parser.getToken() !== Token.LeftParen) {
8466
+ if ((parser.getToken() & Token.IsClassField) === Token.IsClassField) {
8308
8467
  return parsePropertyDefinition(parser, context, key, kind, decorators, tokenPos, linePos, colPos);
8309
8468
  }
8310
8469
  kind |= PropertyKind.Getter;
@@ -8312,8 +8471,8 @@ function parseClassElementList(
8312
8471
  break;
8313
8472
 
8314
8473
  case Token.SetKeyword:
8315
- if (parser.token !== Token.LeftParen) {
8316
- if (context & Context.OptionsNext && (parser.token & Token.IsClassField) === Token.IsClassField) {
8474
+ if (parser.getToken() !== Token.LeftParen) {
8475
+ if ((parser.getToken() & Token.IsClassField) === Token.IsClassField) {
8317
8476
  return parsePropertyDefinition(parser, context, key, kind, decorators, tokenPos, linePos, colPos);
8318
8477
  }
8319
8478
  kind |= PropertyKind.Setter;
@@ -8330,32 +8489,32 @@ function parseClassElementList(
8330
8489
  } else if (token === Token.Multiply) {
8331
8490
  kind |= PropertyKind.Generator;
8332
8491
  nextToken(parser, context); // skip: '*'
8333
- } else if (context & Context.OptionsNext && parser.token === Token.PrivateField) {
8492
+ } else if (parser.getToken() === Token.PrivateField) {
8334
8493
  kind |= PropertyKind.PrivateField;
8335
8494
  key = parsePrivateIdentifier(parser, context | Context.InClass, tokenPos, linePos, colPos);
8336
- } else if (context & Context.OptionsNext && (parser.token & Token.IsClassField) === Token.IsClassField) {
8495
+ } else if ((parser.getToken() & Token.IsClassField) === Token.IsClassField) {
8337
8496
  kind |= PropertyKind.ClassField;
8338
8497
  } else if (isStatic && token === Token.LeftBrace) {
8339
8498
  return parseStaticBlock(parser, context, scope, tokenPos, linePos, colPos);
8340
8499
  } else if (token === Token.EscapedFutureReserved) {
8341
8500
  key = parseIdentifier(parser, context);
8342
- if (parser.token !== Token.LeftParen)
8343
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
8501
+ if (parser.getToken() !== Token.LeftParen)
8502
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
8344
8503
  } else {
8345
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
8504
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
8346
8505
  }
8347
8506
 
8348
8507
  if (kind & (PropertyKind.Generator | PropertyKind.Async | PropertyKind.GetSet)) {
8349
- if (parser.token & Token.IsIdentifier) {
8508
+ if (parser.getToken() & Token.IsIdentifier) {
8350
8509
  key = parseIdentifier(parser, context);
8351
- } else if ((parser.token & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
8510
+ } else if ((parser.getToken() & Token.IsStringOrNumber) === Token.IsStringOrNumber) {
8352
8511
  key = parseLiteral(parser, context);
8353
- } else if (parser.token === Token.LeftBracket) {
8512
+ } else if (parser.getToken() === Token.LeftBracket) {
8354
8513
  kind |= PropertyKind.Computed;
8355
8514
  key = parseComputedPropertyName(parser, context, /* inGroup */ 0);
8356
- } else if (parser.token === Token.EscapedFutureReserved) {
8515
+ } else if (parser.getToken() === Token.EscapedFutureReserved) {
8357
8516
  key = parseIdentifier(parser, context);
8358
- } else if (context & Context.OptionsNext && parser.token === Token.PrivateField) {
8517
+ } else if (parser.getToken() === Token.PrivateField) {
8359
8518
  kind |= PropertyKind.PrivateField;
8360
8519
  key = parsePrivateIdentifier(parser, context, tokenPos, linePos, colPos);
8361
8520
  } else report(parser, Errors.InvalidKeyToken);
@@ -8363,9 +8522,9 @@ function parseClassElementList(
8363
8522
 
8364
8523
  if ((kind & PropertyKind.Computed) === 0) {
8365
8524
  if (parser.tokenValue === 'constructor') {
8366
- if ((parser.token & Token.IsClassField) === Token.IsClassField) {
8525
+ if ((parser.getToken() & Token.IsClassField) === Token.IsClassField) {
8367
8526
  report(parser, Errors.InvalidClassFieldConstructor);
8368
- } else if ((kind & PropertyKind.Static) === 0 && parser.token === Token.LeftParen) {
8527
+ } else if ((kind & PropertyKind.Static) === 0 && parser.getToken() === Token.LeftParen) {
8369
8528
  if (kind & (PropertyKind.GetSet | PropertyKind.Async | PropertyKind.ClassField | PropertyKind.Generator)) {
8370
8529
  report(parser, Errors.InvalidConstructor, 'accessor');
8371
8530
  } else if ((context & Context.SuperCall) === 0) {
@@ -8384,51 +8543,28 @@ function parseClassElementList(
8384
8543
  }
8385
8544
  }
8386
8545
 
8387
- if (context & Context.OptionsNext && parser.token !== Token.LeftParen) {
8546
+ if (parser.getToken() !== Token.LeftParen && (kind & PropertyKind.GetSet) === 0) {
8388
8547
  return parsePropertyDefinition(parser, context, key, kind, decorators, tokenPos, linePos, colPos);
8389
8548
  }
8390
8549
 
8391
8550
  const value = parseMethodDefinition(parser, context, kind, inGroup, parser.tokenPos, parser.linePos, parser.colPos);
8392
8551
 
8393
- return finishNode(
8394
- parser,
8395
- context,
8396
- start,
8397
- line,
8398
- column,
8399
- context & Context.OptionsNext
8400
- ? {
8401
- type: 'MethodDefinition',
8402
- kind:
8403
- (kind & PropertyKind.Static) === 0 && kind & PropertyKind.Constructor
8404
- ? 'constructor'
8405
- : kind & PropertyKind.Getter
8406
- ? 'get'
8407
- : kind & PropertyKind.Setter
8408
- ? 'set'
8409
- : 'method',
8410
- static: (kind & PropertyKind.Static) > 0,
8411
- computed: (kind & PropertyKind.Computed) > 0,
8412
- key,
8413
- decorators,
8414
- value
8415
- }
8416
- : {
8417
- type: 'MethodDefinition',
8418
- kind:
8419
- (kind & PropertyKind.Static) === 0 && kind & PropertyKind.Constructor
8420
- ? 'constructor'
8421
- : kind & PropertyKind.Getter
8422
- ? 'get'
8423
- : kind & PropertyKind.Setter
8424
- ? 'set'
8425
- : 'method',
8426
- static: (kind & PropertyKind.Static) > 0,
8427
- computed: (kind & PropertyKind.Computed) > 0,
8428
- key,
8429
- value
8430
- }
8431
- );
8552
+ return finishNode(parser, context, start, line, column, {
8553
+ type: 'MethodDefinition',
8554
+ kind:
8555
+ (kind & PropertyKind.Static) === 0 && kind & PropertyKind.Constructor
8556
+ ? 'constructor'
8557
+ : kind & PropertyKind.Getter
8558
+ ? 'get'
8559
+ : kind & PropertyKind.Setter
8560
+ ? 'set'
8561
+ : 'method',
8562
+ static: (kind & PropertyKind.Static) > 0,
8563
+ computed: (kind & PropertyKind.Computed) > 0,
8564
+ key,
8565
+ value,
8566
+ ...(context & Context.OptionsNext ? { decorators } : null)
8567
+ });
8432
8568
  }
8433
8569
 
8434
8570
  /**
@@ -8486,22 +8622,27 @@ export function parsePropertyDefinition(
8486
8622
 
8487
8623
  if (state & PropertyKind.Generator) report(parser, Errors.Unexpected);
8488
8624
 
8489
- if (parser.token === Token.Assign) {
8625
+ if (parser.getToken() === Token.Assign) {
8490
8626
  nextToken(parser, context | Context.AllowRegExp);
8491
8627
 
8492
8628
  const { tokenPos, linePos, colPos } = parser;
8493
8629
 
8494
- if (parser.token === Token.Arguments) report(parser, Errors.StrictEvalArguments);
8630
+ if (parser.getToken() === Token.Arguments) report(parser, Errors.StrictEvalArguments);
8495
8631
 
8496
8632
  const modifierFlags =
8497
- (state & PropertyKind.Constructor) === 0
8498
- ? 0b0000001111010000000_0000_00000000
8499
- : 0b0000000111000000000_0000_00000000;
8633
+ Context.InYieldContext |
8634
+ Context.InAwaitContext |
8635
+ Context.InArgumentList |
8636
+ ((state & PropertyKind.Constructor) === 0 ? Context.SuperCall | Context.InConstructor : 0);
8500
8637
 
8501
8638
  context =
8502
8639
  ((context | modifierFlags) ^ modifierFlags) |
8503
- ((state & 0b0000000000000000000_0000_01011000) << 18) |
8504
- 0b0000110000001000000_0000_00000000;
8640
+ (state & PropertyKind.Generator ? Context.InYieldContext : 0) |
8641
+ (state & PropertyKind.Async ? Context.InAwaitContext : 0) |
8642
+ (state & PropertyKind.Constructor ? Context.InConstructor : 0) |
8643
+ Context.SuperProperty |
8644
+ Context.InMethod |
8645
+ Context.AllowNewTarget;
8505
8646
 
8506
8647
  value = parsePrimaryExpression(
8507
8648
  parser,
@@ -8517,8 +8658,8 @@ export function parsePropertyDefinition(
8517
8658
  );
8518
8659
 
8519
8660
  if (
8520
- (parser.token & Token.IsClassField) !== Token.IsClassField ||
8521
- (parser.token & Token.IsAssignOp) === Token.IsAssignOp
8661
+ (parser.getToken() & Token.IsClassField) !== Token.IsClassField ||
8662
+ (parser.getToken() & Token.IsAssignOp) === Token.IsAssignOp
8522
8663
  ) {
8523
8664
  value = parseMemberOrUpdateExpression(
8524
8665
  parser,
@@ -8532,19 +8673,18 @@ export function parsePropertyDefinition(
8532
8673
  );
8533
8674
 
8534
8675
  value = parseAssignmentExpression(parser, context | Context.InClass, 0, 0, tokenPos, linePos, colPos, value);
8535
- if (parser.token === Token.Comma) {
8536
- value = parseSequenceExpression(parser, context, 0, start, line, column, value as any);
8537
- }
8538
8676
  }
8539
8677
  }
8540
8678
 
8679
+ matchOrInsertSemicolon(parser, context);
8680
+
8541
8681
  return finishNode(parser, context, start, line, column, {
8542
8682
  type: 'PropertyDefinition',
8543
8683
  key,
8544
8684
  value,
8545
8685
  static: (state & PropertyKind.Static) > 0,
8546
8686
  computed: (state & PropertyKind.Computed) > 0,
8547
- decorators
8687
+ ...(context & Context.OptionsNext ? { decorators } : null)
8548
8688
  } as any);
8549
8689
  }
8550
8690
 
@@ -8570,14 +8710,14 @@ export function parseBindingPattern(
8570
8710
  // ArrayLiteral
8571
8711
  // ObjectLiteral
8572
8712
 
8573
- if (parser.token & Token.IsIdentifier)
8713
+ if (parser.getToken() & Token.IsIdentifier)
8574
8714
  return parseAndClassifyIdentifier(parser, context, scope, type, origin, start, line, column);
8575
8715
 
8576
- if ((parser.token & Token.IsPatternStart) !== Token.IsPatternStart)
8577
- report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
8716
+ if ((parser.getToken() & Token.IsPatternStart) !== Token.IsPatternStart)
8717
+ report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.getToken() & Token.Type]);
8578
8718
 
8579
8719
  const left: any =
8580
- parser.token === Token.LeftBracket
8720
+ parser.getToken() === Token.LeftBracket
8581
8721
  ? parseArrayExpressionOrPattern(parser, context, scope, 1, 0, 1, type, origin, start, line, column)
8582
8722
  : parseObjectLiteralOrPattern(parser, context, scope, 1, 0, 1, type, origin, start, line, column);
8583
8723
 
@@ -8605,7 +8745,8 @@ function parseAndClassifyIdentifier(
8605
8745
  line: number,
8606
8746
  column: number
8607
8747
  ): ESTree.Identifier {
8608
- const { tokenValue, token } = parser;
8748
+ const { tokenValue } = parser;
8749
+ const token = parser.getToken();
8609
8750
 
8610
8751
  if (context & Context.Strict) {
8611
8752
  if ((token & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
@@ -8661,7 +8802,7 @@ function parseJSXRootElementOrFragment(
8661
8802
  nextToken(parser, context);
8662
8803
 
8663
8804
  // JSX fragments
8664
- if (parser.token === Token.GreaterThan) {
8805
+ if (parser.getToken() === Token.GreaterThan) {
8665
8806
  return finishNode(parser, context, start, line, column, {
8666
8807
  type: 'JSXFragment',
8667
8808
  openingFragment: parseOpeningFragment(parser, context, start, line, column),
@@ -8756,7 +8897,7 @@ function parseJSXClosingElement(
8756
8897
  if (inJSXChild) {
8757
8898
  consume(parser, context, Token.GreaterThan);
8758
8899
  } else {
8759
- parser.token = scanJSXToken(parser, context);
8900
+ parser.setToken(scanJSXToken(parser, context));
8760
8901
  }
8761
8902
 
8762
8903
  return finishNode(parser, context, start, line, column, {
@@ -8804,7 +8945,7 @@ export function parseJSXClosingFragment(
8804
8945
  */
8805
8946
  export function parseJSXChildren(parser: ParserState, context: Context): ESTree.JSXChild[] {
8806
8947
  const children: ESTree.JSXChild[] = [];
8807
- while (parser.token !== Token.JSXClose) {
8948
+ while (parser.getToken() !== Token.JSXClose) {
8808
8949
  parser.index = parser.tokenPos = parser.startPos;
8809
8950
  parser.column = parser.colPos = parser.startColumn;
8810
8951
  parser.line = parser.linePos = parser.startLine;
@@ -8824,10 +8965,10 @@ export function parseJSXChildren(parser: ParserState, context: Context): ESTree.
8824
8965
  * @param column
8825
8966
  */
8826
8967
  function parseJSXChild(parser: ParserState, context: Context, start: number, line: number, column: number): any {
8827
- if (parser.token === Token.JSXText) return parseJSXText(parser, context, start, line, column);
8828
- if (parser.token === Token.LeftBrace)
8968
+ if (parser.getToken() === Token.JSXText) return parseJSXText(parser, context, start, line, column);
8969
+ if (parser.getToken() === Token.LeftBrace)
8829
8970
  return parseJSXExpressionContainer(parser, context, /*inJSXChild*/ 0, /* isAttr */ 0, start, line, column);
8830
- if (parser.token === Token.LessThan)
8971
+ if (parser.getToken() === Token.LessThan)
8831
8972
  return parseJSXRootElementOrFragment(parser, context, /*inJSXChild*/ 0, start, line, column);
8832
8973
  report(parser, Errors.Unexpected);
8833
8974
  }
@@ -8880,14 +9021,17 @@ function parseJSXOpeningFragmentOrSelfCloseElement(
8880
9021
  line: number,
8881
9022
  column: number
8882
9023
  ): ESTree.JSXOpeningElement {
8883
- if ((parser.token & Token.IsIdentifier) !== Token.IsIdentifier && (parser.token & Token.Keyword) !== Token.Keyword)
9024
+ if (
9025
+ (parser.getToken() & Token.IsIdentifier) !== Token.IsIdentifier &&
9026
+ (parser.getToken() & Token.Keyword) !== Token.Keyword
9027
+ )
8884
9028
  report(parser, Errors.Unexpected);
8885
9029
 
8886
9030
  const tagName = parseJSXElementName(parser, context, parser.tokenPos, parser.linePos, parser.colPos);
8887
9031
  const attributes = parseJSXAttributes(parser, context);
8888
- const selfClosing = parser.token === Token.Divide;
9032
+ const selfClosing = parser.getToken() === Token.Divide;
8889
9033
 
8890
- if (parser.token === Token.GreaterThan) {
9034
+ if (parser.getToken() === Token.GreaterThan) {
8891
9035
  scanJSXToken(parser, context);
8892
9036
  } else {
8893
9037
  consume(parser, context, Token.Divide);
@@ -8927,7 +9071,7 @@ function parseJSXElementName(
8927
9071
  let key: ESTree.JSXIdentifier | ESTree.JSXMemberExpression = parseJSXIdentifier(parser, context, start, line, column);
8928
9072
 
8929
9073
  // Namespace
8930
- if (parser.token === Token.Colon) return parseJSXNamespacedName(parser, context, key, start, line, column);
9074
+ if (parser.getToken() === Token.Colon) return parseJSXNamespacedName(parser, context, key, start, line, column);
8931
9075
 
8932
9076
  // Member expression
8933
9077
  while (consumeOpt(parser, context, Token.Period)) {
@@ -8976,7 +9120,11 @@ export function parseJSXAttributes(
8976
9120
  context: Context
8977
9121
  ): (ESTree.JSXAttribute | ESTree.JSXSpreadAttribute)[] {
8978
9122
  const attributes: (ESTree.JSXAttribute | ESTree.JSXSpreadAttribute)[] = [];
8979
- while (parser.token !== Token.Divide && parser.token !== Token.GreaterThan && parser.token !== Token.EOF) {
9123
+ while (
9124
+ parser.getToken() !== Token.Divide &&
9125
+ parser.getToken() !== Token.GreaterThan &&
9126
+ parser.getToken() !== Token.EOF
9127
+ ) {
8980
9128
  attributes.push(parseJsxAttribute(parser, context, parser.tokenPos, parser.linePos, parser.colPos));
8981
9129
  }
8982
9130
  return attributes;
@@ -9024,17 +9172,17 @@ function parseJsxAttribute(
9024
9172
  line: number,
9025
9173
  column: number
9026
9174
  ): ESTree.JSXAttribute | ESTree.JSXSpreadAttribute {
9027
- if (parser.token === Token.LeftBrace) return parseJSXSpreadAttribute(parser, context, start, line, column);
9175
+ if (parser.getToken() === Token.LeftBrace) return parseJSXSpreadAttribute(parser, context, start, line, column);
9028
9176
  scanJSXIdentifier(parser);
9029
9177
  let value: ESTree.JSXAttributeValue | null = null;
9030
9178
  let name: ESTree.JSXNamespacedName | ESTree.JSXIdentifier = parseJSXIdentifier(parser, context, start, line, column);
9031
9179
 
9032
- if (parser.token === Token.Colon) {
9180
+ if (parser.getToken() === Token.Colon) {
9033
9181
  name = parseJSXNamespacedName(parser, context, name, start, line, column);
9034
9182
  }
9035
9183
 
9036
9184
  // HTML empty attribute
9037
- if (parser.token === Token.Assign) {
9185
+ if (parser.getToken() === Token.Assign) {
9038
9186
  const token = scanJSXAttributeValue(parser, context);
9039
9187
  const { tokenPos, linePos, colPos } = parser;
9040
9188
  switch (token) {
@@ -9108,11 +9256,11 @@ function parseJSXExpressionContainer(
9108
9256
  ): ESTree.JSXExpressionContainer | ESTree.JSXSpreadChild {
9109
9257
  nextToken(parser, context | Context.AllowRegExp);
9110
9258
  const { tokenPos, linePos, colPos } = parser;
9111
- if (parser.token === Token.Ellipsis) return parseJSXSpreadChild(parser, context, start, line, column);
9259
+ if (parser.getToken() === Token.Ellipsis) return parseJSXSpreadChild(parser, context, start, line, column);
9112
9260
 
9113
9261
  let expression: ESTree.Expression | ESTree.JSXEmptyExpression | null = null;
9114
9262
 
9115
- if (parser.token === Token.RightBrace) {
9263
+ if (parser.getToken() === Token.RightBrace) {
9116
9264
  // JSX attributes must only be assigned a non-empty 'expression'
9117
9265
  if (isAttr) report(parser, Errors.InvalidNonEmptyJSXExpr);
9118
9266
  expression = parseJSXEmptyExpression(parser, context, parser.startPos, parser.startLine, parser.startColumn);