     1→import {
     2→  AssignmentKind,
     3→  BindingKind,
     4→  classifyIdentifier,
     5→  consume,
     6→  consumeOpt,
     7→  Context,
     8→  DestructuringKind,
     9→  Flags,
    10→  HoistedClassFlags,
    11→  HoistedFunctionFlags,
    12→  isEqualTagName,
    13→  isPropertyWithPrivateFieldKey,
    14→  isStrictReservedWord,
    15→  isValidIdentifier,
    16→  isValidLabel,
    17→  isValidStrictMode,
    18→  type Location,
    19→  matchOrInsertSemicolon,
    20→  optionalBit,
    21→  Origin,
    22→  PropertyKind,
    23→  reinterpretToPattern,
    24→  validateAndDeclareLabel,
    25→  validateBindingIdentifier,
    26→  validateFunctionName,
    27→} from './common';
    28→import { Errors, ParseError } from './errors';
    29→import type * as ESTree from './estree';
    30→import { nextToken, skipHashBang } from './lexer';
    31→import { nextJSXToken, rescanJSXIdentifier, scanJSXAttributeValue } from './lexer/jsx';
    32→import { scanTemplateTail } from './lexer/template';
    33→import { type Options } from './options';
    34→import { Parser } from './parser/parser';
    35→import { type PrivateScope } from './parser/private-scope';
    36→import { createArrowHeadParsingScope, type Scope, ScopeKind } from './parser/scope';
    37→import { KeywordDescTable, Token } from './token';
    38→
    39→/**
    40→ * Consumes a sequence of tokens and produces an syntax tree
    41→ */
    42→export function parseSource(source: string, rawOptions: Options = {}, context: Context = Context.None): ESTree.Program {
    43→  // Initialize parser state
    44→  const parser = new Parser(source, rawOptions);
    45→
    46→  if (parser.options.sourceType === 'module') context |= Context.Module | Context.Strict;
    47→  if (parser.options.sourceType === 'commonjs') context |= Context.InReturnContext | Context.AllowNewTarget;
    48→  if (parser.options.impliedStrict) context |= Context.Strict;
    49→
    50→  // See: https://github.com/tc39/proposal-hashbang
    51→  skipHashBang(parser);
    52→
    53→  const scope = parser.createScopeIfLexical();
    54→
    55→  let body: ESTree.Statement[] = [];
    56→
    57→  // https://tc39.es/ecma262/#sec-scripts
    58→  // https://tc39.es/ecma262/#sec-modules
    59→
    60→  let sourceType: 'module' | 'script' = 'script';
    61→
    62→  if (context & Context.Module) {
    63→    sourceType = 'module';
    64→    body = parseModuleItemList(parser, context | Context.InGlobal, scope);
    65→
    66→    if (scope) {
    67→      for (const name of parser.exportedBindings) {
    68→        if (!scope.hasVariable(name)) parser.report(Errors.UndeclaredExportedBinding, name);
    69→      }
    70→    }
    71→  } else {
    72→    body = parseStatementList(parser, context | Context.InGlobal, scope);
    73→  }
    74→
    75→  return parser.finishNode<ESTree.Program>(
    76→    {
    77→      type: 'Program',
    78→      sourceType,
    79→      body,
    80→    },
    81→    { index: 0, line: 1, column: 0 },
    82→    parser.currentLocation,
    83→  );
    84→}
    85→
    86→/**
    87→ * Parses statement list items
    88→ *
    89→ * @param parser  Parser object
    90→ * @param context Context masks
    91→ */
    92→function parseStatementList(parser: Parser, context: Context, scope: Scope | undefined): ESTree.Statement[] {
    93→  // StatementList ::
    94→  //   (StatementListItem)* <end_token>
    95→
    96→  nextToken(parser, context | Context.AllowRegExp | Context.AllowEscapedKeyword);
    97→
    98→  const statements: ESTree.Statement[] = [];
    99→
   100→  while (parser.getToken() === Token.StringLiteral) {
   101→    // "use strict" must be the exact literal without escape sequences or line continuation.
   102→    const { index, tokenValue, tokenStart, tokenIndex } = parser;
   103→    const token = parser.getToken();
   104→    const expr = parseLiteral<ESTree.StringLiteral>(parser, context);
   105→    if (isValidStrictMode(parser, index, tokenIndex, tokenValue)) {
   106→      context |= Context.Strict;
   107→
   108→      if (parser.flags & Flags.Octal) {
   109→        throw new ParseError(parser.tokenStart, parser.currentLocation, Errors.StrictOctalLiteral);
   110→      }
   111→
   112→      if (parser.flags & Flags.EightAndNine) {
   113→        throw new ParseError(parser.tokenStart, parser.currentLocation, Errors.StrictEightAndNine);
   114→      }
   115→    }
   116→    statements.push(parseDirective(parser, context, expr, token, tokenStart));
   117→  }
   118→
   119→  while (parser.getToken() !== Token.EOF) {
   120→    statements.push(parseStatementListItem(parser, context, scope, undefined, Origin.TopLevel, {}) as ESTree.Statement);
   121→  }
   122→  return statements;
   123→}
   124→
   125→/**
   126→ * Parse module item list
   127→ *
   128→ * @see [Link](https://tc39.github.io/ecma262/#prod-ModuleItemList)
   129→ *
   130→ * @param parser  Parser object

[8783 more lines in file. Use offset=131 to continue.]