source: frontend/node_modules/@babel/parser/lib/index.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 500.7 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6function _objectWithoutPropertiesLoose(r, e) {
7 if (null == r) return {};
8 var t = {};
9 for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
10 if (-1 !== e.indexOf(n)) continue;
11 t[n] = r[n];
12 }
13 return t;
14}
15class Position {
16 constructor(line, col, index) {
17 this.line = void 0;
18 this.column = void 0;
19 this.index = void 0;
20 this.line = line;
21 this.column = col;
22 this.index = index;
23 }
24}
25class SourceLocation {
26 constructor(start, end) {
27 this.start = void 0;
28 this.end = void 0;
29 this.filename = void 0;
30 this.identifierName = void 0;
31 this.start = start;
32 this.end = end;
33 }
34}
35function createPositionWithColumnOffset(position, columnOffset) {
36 const {
37 line,
38 column,
39 index
40 } = position;
41 return new Position(line, column + columnOffset, index + columnOffset);
42}
43const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
44var ModuleErrors = {
45 ImportMetaOutsideModule: {
46 message: `import.meta may appear only with 'sourceType: "module"'`,
47 code
48 },
49 ImportOutsideModule: {
50 message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
51 code
52 }
53};
54const NodeDescriptions = {
55 ArrayPattern: "array destructuring pattern",
56 AssignmentExpression: "assignment expression",
57 AssignmentPattern: "assignment expression",
58 ArrowFunctionExpression: "arrow function expression",
59 ConditionalExpression: "conditional expression",
60 CatchClause: "catch clause",
61 ForOfStatement: "for-of statement",
62 ForInStatement: "for-in statement",
63 ForStatement: "for-loop",
64 FormalParameters: "function parameter list",
65 Identifier: "identifier",
66 ImportSpecifier: "import specifier",
67 ImportDefaultSpecifier: "import default specifier",
68 ImportNamespaceSpecifier: "import namespace specifier",
69 ObjectPattern: "object destructuring pattern",
70 ParenthesizedExpression: "parenthesized expression",
71 RestElement: "rest element",
72 UpdateExpression: {
73 true: "prefix operation",
74 false: "postfix operation"
75 },
76 VariableDeclarator: "variable declaration",
77 YieldExpression: "yield expression"
78};
79const toNodeDescription = node => node.type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[`${node.prefix}`] : NodeDescriptions[node.type];
80var StandardErrors = {
81 AccessorIsGenerator: ({
82 kind
83 }) => `A ${kind}ter cannot be a generator.`,
84 ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
85 AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
86 AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
87 AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
88 AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
89 AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
90 AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
91 BadGetterArity: "A 'get' accessor must not have any formal parameters.",
92 BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
93 BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
94 ConstructorClassField: "Classes may not have a field named 'constructor'.",
95 ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
96 ConstructorIsAccessor: "Class constructor may not be an accessor.",
97 ConstructorIsAsync: "Constructor can't be an async function.",
98 ConstructorIsGenerator: "Constructor can't be a generator.",
99 DeclarationMissingInitializer: ({
100 kind
101 }) => `Missing initializer in ${kind} declaration.`,
102 DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
103 DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
104 DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
105 DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
106 DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
107 DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
108 DecoratorStaticBlock: "Decorators can't be used with a static block.",
109 DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
110 DeletePrivateField: "Deleting a private field is not allowed.",
111 DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
112 DuplicateConstructor: "Duplicate constructor in the same class.",
113 DuplicateDefaultExport: "Only one default export allowed per module.",
114 DuplicateExport: ({
115 exportName
116 }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
117 DuplicateProto: "Redefinition of __proto__ property.",
118 DuplicateRegExpFlags: "Duplicate regular expression flag.",
119 ElementAfterRest: "Rest element must be last element.",
120 EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
121 ExportBindingIsString: ({
122 localName,
123 exportName
124 }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
125 ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
126 ForInOfLoopInitializer: ({
127 type
128 }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
129 ForInUsing: "For-in loop may not start with 'using' declaration.",
130 ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
131 ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
132 GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
133 IllegalBreakContinue: ({
134 type
135 }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
136 IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
137 IllegalReturn: "'return' outside of function.",
138 ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedImportAssert` parser plugin to suppress this error.",
139 ImportBindingIsString: ({
140 importName
141 }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
142 ImportCallArity: `\`import()\` requires exactly one or two arguments.`,
143 ImportCallNotNewExpression: "Cannot use new with import(...).",
144 ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
145 ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
146 ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
147 ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
148 IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
149 InvalidBigIntLiteral: "Invalid BigIntLiteral.",
150 InvalidCodePoint: "Code point out of bounds.",
151 InvalidCoverDiscardElement: "'void' must be followed by an expression when not used in a binding position.",
152 InvalidCoverInitializedName: "Invalid shorthand property initializer.",
153 InvalidDecimal: "Invalid decimal.",
154 InvalidDigit: ({
155 radix
156 }) => `Expected number in radix ${radix}.`,
157 InvalidEscapeSequence: "Bad character escape sequence.",
158 InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
159 InvalidEscapedReservedWord: ({
160 reservedWord
161 }) => `Escape sequence in keyword ${reservedWord}.`,
162 InvalidIdentifier: ({
163 identifierName
164 }) => `Invalid identifier ${identifierName}.`,
165 InvalidLhs: ({
166 ancestor
167 }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
168 InvalidLhsBinding: ({
169 ancestor
170 }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
171 InvalidLhsOptionalChaining: ({
172 ancestor
173 }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
174 InvalidNumber: "Invalid number.",
175 InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
176 InvalidOrUnexpectedToken: ({
177 unexpected
178 }) => `Unexpected character '${unexpected}'.`,
179 InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
180 InvalidPrivateFieldResolution: ({
181 identifierName
182 }) => `Private name #${identifierName} is not defined.`,
183 InvalidPropertyBindingPattern: "Binding member expression.",
184 InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
185 InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
186 LabelRedeclaration: ({
187 labelName
188 }) => `Label '${labelName}' is already declared.`,
189 LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
190 LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
191 MalformedRegExpFlags: "Invalid regular expression flag.",
192 MissingClassName: "A class name is required.",
193 MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
194 MissingSemicolon: "Missing semicolon.",
195 MissingPlugin: ({
196 missingPlugin
197 }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
198 MissingOneOfPlugins: ({
199 missingPlugin
200 }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
201 MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
202 MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
203 ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
204 ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
205 ModuleAttributesWithDuplicateKeys: ({
206 key
207 }) => `Duplicate key "${key}" is not allowed in module attributes.`,
208 ModuleExportNameHasLoneSurrogate: ({
209 surrogateCharCode
210 }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
211 ModuleExportUndefined: ({
212 localName
213 }) => `Export '${localName}' is not defined.`,
214 MultipleDefaultsInSwitch: "Multiple default clauses.",
215 NewlineAfterThrow: "Illegal newline after throw.",
216 NoCatchOrFinally: "Missing catch or finally clause.",
217 NumberIdentifier: "Identifier directly after number.",
218 NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
219 ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
220 OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
221 OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
222 OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
223 ParamDupe: "Argument name clash.",
224 PatternHasAccessor: "Object pattern can't contain getter or setter.",
225 PatternHasMethod: "Object pattern can't contain methods.",
226 PrivateInExpectedIn: ({
227 identifierName
228 }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
229 PrivateNameRedeclaration: ({
230 identifierName
231 }) => `Duplicate private name #${identifierName}.`,
232 RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
233 RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
234 RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
235 RecordNoProto: "'__proto__' is not allowed in Record expressions.",
236 RestTrailingComma: "Unexpected trailing comma after rest element.",
237 SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
238 SloppyFunctionAnnexB: "In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement.",
239 SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
240 StaticPrototype: "Classes may not have static property named prototype.",
241 SuperNotAllowed: "`super()` is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class?",
242 SuperPrivateField: "Private fields can't be accessed on super.",
243 TrailingDecorator: "Decorators must be attached to a class element.",
244 TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
245 TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
246 TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
247 UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
248 UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
249 UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
250 UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
251 UnexpectedKeyword: ({
252 keyword
253 }) => `Unexpected keyword '${keyword}'.`,
254 UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
255 UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
256 UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
257 UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
258 UnexpectedPrivateField: "Unexpected private name.",
259 UnexpectedReservedWord: ({
260 reservedWord
261 }) => `Unexpected reserved word '${reservedWord}'.`,
262 UnexpectedSuper: "'super' is only allowed in object methods and classes.",
263 UnexpectedToken: ({
264 expected,
265 unexpected
266 }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
267 UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
268 UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement.",
269 UnexpectedVoidPattern: "Unexpected void binding.",
270 UnsupportedBind: "Binding should be performed on object property.",
271 UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
272 UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
273 UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
274 UnsupportedMetaProperty: ({
275 target,
276 onlyValidPropertyName
277 }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
278 UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
279 UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
280 UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
281 UnterminatedComment: "Unterminated comment.",
282 UnterminatedRegExp: "Unterminated regular expression.",
283 UnterminatedString: "Unterminated string constant.",
284 UnterminatedTemplate: "Unterminated template.",
285 UsingDeclarationExport: "Using declaration cannot be exported.",
286 UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
287 VarRedeclaration: ({
288 identifierName
289 }) => `Identifier '${identifierName}' has already been declared.`,
290 VoidPatternCatchClauseParam: "A void binding can not be the catch clause parameter. Use `try { ... } catch { ... }` if you want to discard the caught error.",
291 VoidPatternInitializer: "A void binding may not have an initializer.",
292 YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
293 YieldInParameter: "Yield expression is not allowed in formal parameters.",
294 YieldNotInGeneratorFunction: "'yield' is only allowed within generator functions.",
295 ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
296};
297var StrictModeErrors = {
298 StrictDelete: "Deleting local variable in strict mode.",
299 StrictEvalArguments: ({
300 referenceName
301 }) => `Assigning to '${referenceName}' in strict mode.`,
302 StrictEvalArgumentsBinding: ({
303 bindingName
304 }) => `Binding '${bindingName}' in strict mode.`,
305 StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
306 StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
307 StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
308 StrictWith: "'with' in strict mode."
309};
310var ParseExpressionErrors = {
311 ParseExpressionEmptyInput: "Unexpected parseExpression() input: The input is empty or contains only comments.",
312 ParseExpressionExpectsEOF: ({
313 unexpected
314 }) => `Unexpected parseExpression() input: The input should contain exactly one expression, but the first expression is followed by the unexpected character \`${String.fromCodePoint(unexpected)}\`.`
315};
316const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
317var PipelineOperatorErrors = Object.assign({
318 PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
319 PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
320 PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
321 PipeTopicUnconfiguredToken: ({
322 token
323 }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
324 PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
325 PipeUnparenthesizedBody: ({
326 type
327 }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
328 type
329 })}; please wrap it in parentheses.`
330}, {
331 PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
332 PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
333 PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
334 PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
335 PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
336 PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
337});
338const _excluded = ["message"];
339function defineHidden(obj, key, value) {
340 Object.defineProperty(obj, key, {
341 enumerable: false,
342 configurable: true,
343 value
344 });
345}
346function toParseErrorConstructor({
347 toMessage,
348 code,
349 reasonCode,
350 syntaxPlugin
351}) {
352 const hasMissingPlugin = reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins";
353 const oldReasonCodes = {
354 AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
355 AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
356 ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
357 SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
358 SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
359 SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
360 };
361 if (oldReasonCodes[reasonCode]) {
362 reasonCode = oldReasonCodes[reasonCode];
363 }
364 return function constructor(loc, details) {
365 const error = new SyntaxError();
366 error.code = code;
367 error.reasonCode = reasonCode;
368 error.loc = loc;
369 error.pos = loc.index;
370 error.syntaxPlugin = syntaxPlugin;
371 if (hasMissingPlugin) {
372 error.missingPlugin = details.missingPlugin;
373 }
374 defineHidden(error, "clone", function clone(overrides = {}) {
375 var _overrides$loc;
376 const {
377 line,
378 column,
379 index
380 } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
381 return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
382 });
383 defineHidden(error, "details", details);
384 Object.defineProperty(error, "message", {
385 configurable: true,
386 get() {
387 const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
388 this.message = message;
389 return message;
390 },
391 set(value) {
392 Object.defineProperty(this, "message", {
393 value,
394 writable: true
395 });
396 }
397 });
398 return error;
399 };
400}
401function ParseErrorEnum(argument, syntaxPlugin) {
402 if (Array.isArray(argument)) {
403 return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
404 }
405 const ParseErrorConstructors = {};
406 for (const reasonCode of Object.keys(argument)) {
407 const template = argument[reasonCode];
408 const _ref = typeof template === "string" ? {
409 message: () => template
410 } : typeof template === "function" ? {
411 message: template
412 } : template,
413 {
414 message
415 } = _ref,
416 rest = _objectWithoutPropertiesLoose(_ref, _excluded);
417 const toMessage = typeof message === "string" ? () => message : message;
418 ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
419 code: "BABEL_PARSER_SYNTAX_ERROR",
420 reasonCode,
421 toMessage
422 }, syntaxPlugin ? {
423 syntaxPlugin
424 } : {}, rest));
425 }
426 return ParseErrorConstructors;
427}
428const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum(ParseExpressionErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
429function createDefaultOptions() {
430 return {
431 sourceType: "script",
432 sourceFilename: undefined,
433 startIndex: 0,
434 startColumn: 0,
435 startLine: 1,
436 allowAwaitOutsideFunction: false,
437 allowReturnOutsideFunction: false,
438 allowNewTargetOutsideFunction: false,
439 allowImportExportEverywhere: false,
440 allowSuperOutsideMethod: false,
441 allowUndeclaredExports: false,
442 allowYieldOutsideFunction: false,
443 plugins: [],
444 strictMode: undefined,
445 ranges: false,
446 tokens: false,
447 createImportExpressions: false,
448 createParenthesizedExpressions: false,
449 errorRecovery: false,
450 attachComment: true,
451 annexB: true
452 };
453}
454function getOptions(opts) {
455 const options = createDefaultOptions();
456 if (opts == null) {
457 return options;
458 }
459 if (opts.annexB != null && opts.annexB !== false) {
460 throw new Error("The `annexB` option can only be set to `false`.");
461 }
462 for (const key of Object.keys(options)) {
463 if (opts[key] != null) options[key] = opts[key];
464 }
465 if (options.startLine === 1) {
466 if (opts.startIndex == null && options.startColumn > 0) {
467 options.startIndex = options.startColumn;
468 } else if (opts.startColumn == null && options.startIndex > 0) {
469 options.startColumn = options.startIndex;
470 }
471 } else if (opts.startColumn == null || opts.startIndex == null) {
472 if (opts.startIndex != null) {
473 throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
474 }
475 }
476 if (options.sourceType === "commonjs") {
477 if (opts.allowAwaitOutsideFunction != null) {
478 throw new Error("The `allowAwaitOutsideFunction` option cannot be used with `sourceType: 'commonjs'`.");
479 }
480 if (opts.allowReturnOutsideFunction != null) {
481 throw new Error("`sourceType: 'commonjs'` implies `allowReturnOutsideFunction: true`, please remove the `allowReturnOutsideFunction` option or use `sourceType: 'script'`.");
482 }
483 if (opts.allowNewTargetOutsideFunction != null) {
484 throw new Error("`sourceType: 'commonjs'` implies `allowNewTargetOutsideFunction: true`, please remove the `allowNewTargetOutsideFunction` option or use `sourceType: 'script'`.");
485 }
486 }
487 return options;
488}
489const {
490 defineProperty
491} = Object;
492const toUnenumerable = (object, key) => {
493 if (object) {
494 defineProperty(object, key, {
495 enumerable: false,
496 value: object[key]
497 });
498 }
499};
500function toESTreeLocation(node) {
501 toUnenumerable(node.loc.start, "index");
502 toUnenumerable(node.loc.end, "index");
503 return node;
504}
505var estree = superClass => class ESTreeParserMixin extends superClass {
506 parse() {
507 const file = toESTreeLocation(super.parse());
508 if (this.optionFlags & 256) {
509 file.tokens = file.tokens.map(toESTreeLocation);
510 }
511 return file;
512 }
513 parseRegExpLiteral({
514 pattern,
515 flags
516 }) {
517 let regex = null;
518 try {
519 regex = new RegExp(pattern, flags);
520 } catch (_) {}
521 const node = this.estreeParseLiteral(regex);
522 node.regex = {
523 pattern,
524 flags
525 };
526 return node;
527 }
528 parseBigIntLiteral(value) {
529 let bigInt;
530 try {
531 bigInt = BigInt(value);
532 } catch (_unused) {
533 bigInt = null;
534 }
535 const node = this.estreeParseLiteral(bigInt);
536 node.bigint = String(node.value || value);
537 return node;
538 }
539 parseDecimalLiteral(value) {
540 const decimal = null;
541 const node = this.estreeParseLiteral(decimal);
542 node.decimal = String(node.value || value);
543 return node;
544 }
545 estreeParseLiteral(value) {
546 return this.parseLiteral(value, "Literal");
547 }
548 parseStringLiteral(value) {
549 return this.estreeParseLiteral(value);
550 }
551 parseNumericLiteral(value) {
552 return this.estreeParseLiteral(value);
553 }
554 parseNullLiteral() {
555 return this.estreeParseLiteral(null);
556 }
557 parseBooleanLiteral(value) {
558 return this.estreeParseLiteral(value);
559 }
560 estreeParseChainExpression(node, endLoc) {
561 const chain = this.startNodeAtNode(node);
562 chain.expression = node;
563 return this.finishNodeAt(chain, "ChainExpression", endLoc);
564 }
565 directiveToStmt(directive) {
566 const expression = directive.value;
567 delete directive.value;
568 this.castNodeTo(expression, "Literal");
569 expression.raw = expression.extra.raw;
570 expression.value = expression.extra.expressionValue;
571 const stmt = this.castNodeTo(directive, "ExpressionStatement");
572 stmt.expression = expression;
573 stmt.directive = expression.extra.rawValue;
574 delete expression.extra;
575 return stmt;
576 }
577 fillOptionalPropertiesForTSESLint(node) {}
578 cloneEstreeStringLiteral(node) {
579 const {
580 start,
581 end,
582 loc,
583 range,
584 raw,
585 value
586 } = node;
587 const cloned = Object.create(node.constructor.prototype);
588 cloned.type = "Literal";
589 cloned.start = start;
590 cloned.end = end;
591 cloned.loc = loc;
592 cloned.range = range;
593 cloned.raw = raw;
594 cloned.value = value;
595 return cloned;
596 }
597 initFunction(node, isAsync) {
598 super.initFunction(node, isAsync);
599 node.expression = false;
600 }
601 checkDeclaration(node) {
602 if (node != null && this.isObjectProperty(node)) {
603 this.checkDeclaration(node.value);
604 } else {
605 super.checkDeclaration(node);
606 }
607 }
608 getObjectOrClassMethodParams(method) {
609 return method.value.params;
610 }
611 isValidDirective(stmt) {
612 var _stmt$expression$extr;
613 return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
614 }
615 parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
616 super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
617 const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
618 node.body = directiveStatements.concat(node.body);
619 delete node.directives;
620 }
621 parsePrivateName() {
622 const node = super.parsePrivateName();
623 if (!this.getPluginOption("estree", "classFeatures")) {
624 return node;
625 }
626 return this.convertPrivateNameToPrivateIdentifier(node);
627 }
628 convertPrivateNameToPrivateIdentifier(node) {
629 const name = super.getPrivateNameSV(node);
630 delete node.id;
631 node.name = name;
632 return this.castNodeTo(node, "PrivateIdentifier");
633 }
634 isPrivateName(node) {
635 if (!this.getPluginOption("estree", "classFeatures")) {
636 return super.isPrivateName(node);
637 }
638 return node.type === "PrivateIdentifier";
639 }
640 getPrivateNameSV(node) {
641 if (!this.getPluginOption("estree", "classFeatures")) {
642 return super.getPrivateNameSV(node);
643 }
644 return node.name;
645 }
646 parseLiteral(value, type) {
647 const node = super.parseLiteral(value, type);
648 node.raw = node.extra.raw;
649 delete node.extra;
650 return node;
651 }
652 parseFunctionBody(node, allowExpression, isMethod = false) {
653 super.parseFunctionBody(node, allowExpression, isMethod);
654 node.expression = node.body.type !== "BlockStatement";
655 }
656 parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
657 let funcNode = this.startNode();
658 funcNode.kind = node.kind;
659 funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
660 delete funcNode.kind;
661 const {
662 typeParameters
663 } = node;
664 if (typeParameters) {
665 delete node.typeParameters;
666 funcNode.typeParameters = typeParameters;
667 this.resetStartLocationFromNode(funcNode, typeParameters);
668 }
669 const valueNode = this.castNodeTo(funcNode, "FunctionExpression");
670 node.value = valueNode;
671 if (type === "ClassPrivateMethod") {
672 node.computed = false;
673 }
674 if (type === "ObjectMethod") {
675 if (node.kind === "method") {
676 node.kind = "init";
677 }
678 node.shorthand = false;
679 return this.finishNode(node, "Property");
680 } else {
681 return this.finishNode(node, "MethodDefinition");
682 }
683 }
684 nameIsConstructor(key) {
685 if (key.type === "Literal") return key.value === "constructor";
686 return super.nameIsConstructor(key);
687 }
688 parseClassProperty(...args) {
689 const propertyNode = super.parseClassProperty(...args);
690 if (!this.getPluginOption("estree", "classFeatures")) {
691 return propertyNode;
692 }
693 this.castNodeTo(propertyNode, "PropertyDefinition");
694 return propertyNode;
695 }
696 parseClassPrivateProperty(...args) {
697 const propertyNode = super.parseClassPrivateProperty(...args);
698 if (!this.getPluginOption("estree", "classFeatures")) {
699 return propertyNode;
700 }
701 this.castNodeTo(propertyNode, "PropertyDefinition");
702 propertyNode.computed = false;
703 return propertyNode;
704 }
705 parseClassAccessorProperty(node) {
706 const accessorPropertyNode = super.parseClassAccessorProperty(node);
707 if (!this.getPluginOption("estree", "classFeatures")) {
708 return accessorPropertyNode;
709 }
710 if (accessorPropertyNode.abstract && this.hasPlugin("typescript")) {
711 delete accessorPropertyNode.abstract;
712 this.castNodeTo(accessorPropertyNode, "TSAbstractAccessorProperty");
713 } else {
714 this.castNodeTo(accessorPropertyNode, "AccessorProperty");
715 }
716 return accessorPropertyNode;
717 }
718 parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
719 const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
720 if (node) {
721 node.kind = "init";
722 this.castNodeTo(node, "Property");
723 }
724 return node;
725 }
726 finishObjectProperty(node) {
727 node.kind = "init";
728 return this.finishNode(node, "Property");
729 }
730 isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
731 return type === "Property" ? "value" : super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
732 }
733 isAssignable(node, isBinding) {
734 if (node != null && this.isObjectProperty(node)) {
735 return this.isAssignable(node.value, isBinding);
736 }
737 return super.isAssignable(node, isBinding);
738 }
739 toAssignable(node, isLHS = false) {
740 if (node != null && this.isObjectProperty(node)) {
741 const {
742 key,
743 value
744 } = node;
745 if (this.isPrivateName(key)) {
746 this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
747 }
748 this.toAssignable(value, isLHS);
749 } else {
750 super.toAssignable(node, isLHS);
751 }
752 }
753 toAssignableObjectExpressionProp(prop, isLast, isLHS) {
754 if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
755 this.raise(Errors.PatternHasAccessor, prop.key);
756 } else if (prop.type === "Property" && prop.method) {
757 this.raise(Errors.PatternHasMethod, prop.key);
758 } else {
759 super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
760 }
761 }
762 finishCallExpression(unfinished, optional) {
763 const node = super.finishCallExpression(unfinished, optional);
764 if (node.callee.type === "Import") {
765 var _ref, _ref2;
766 this.castNodeTo(node, "ImportExpression");
767 node.source = node.arguments[0];
768 node.options = (_ref = node.arguments[1]) != null ? _ref : null;
769 node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
770 delete node.arguments;
771 delete node.callee;
772 } else if (node.type === "OptionalCallExpression") {
773 this.castNodeTo(node, "CallExpression");
774 } else {
775 node.optional = false;
776 }
777 return node;
778 }
779 toReferencedArguments(node) {
780 if (node.type === "ImportExpression") {
781 return;
782 }
783 super.toReferencedArguments(node);
784 }
785 parseExport(unfinished, decorators) {
786 const exportStartLoc = this.state.lastTokStartLoc;
787 const node = super.parseExport(unfinished, decorators);
788 switch (node.type) {
789 case "ExportAllDeclaration":
790 node.exported = null;
791 break;
792 case "ExportNamedDeclaration":
793 if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
794 this.castNodeTo(node, "ExportAllDeclaration");
795 node.exported = node.specifiers[0].exported;
796 delete node.specifiers;
797 }
798 case "ExportDefaultDeclaration":
799 {
800 var _declaration$decorato;
801 const {
802 declaration
803 } = node;
804 if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
805 this.resetStartLocation(node, exportStartLoc);
806 }
807 }
808 break;
809 }
810 return node;
811 }
812 stopParseSubscript(base, state) {
813 const node = super.stopParseSubscript(base, state);
814 if (state.optionalChainMember) {
815 return this.estreeParseChainExpression(node, base.loc.end);
816 }
817 return node;
818 }
819 parseMember(base, startLoc, state, computed, optional) {
820 const node = super.parseMember(base, startLoc, state, computed, optional);
821 if (node.type === "OptionalMemberExpression") {
822 this.castNodeTo(node, "MemberExpression");
823 } else {
824 node.optional = false;
825 }
826 return node;
827 }
828 isOptionalMemberExpression(node) {
829 if (node.type === "ChainExpression") {
830 return node.expression.type === "MemberExpression";
831 }
832 return super.isOptionalMemberExpression(node);
833 }
834 hasPropertyAsPrivateName(node) {
835 if (node.type === "ChainExpression") {
836 node = node.expression;
837 }
838 return super.hasPropertyAsPrivateName(node);
839 }
840 isObjectProperty(node) {
841 return node.type === "Property" && node.kind === "init" && !node.method;
842 }
843 isObjectMethod(node) {
844 return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
845 }
846 castNodeTo(node, type) {
847 const result = super.castNodeTo(node, type);
848 this.fillOptionalPropertiesForTSESLint(result);
849 return result;
850 }
851 cloneIdentifier(node) {
852 const cloned = super.cloneIdentifier(node);
853 this.fillOptionalPropertiesForTSESLint(cloned);
854 return cloned;
855 }
856 cloneStringLiteral(node) {
857 if (node.type === "Literal") {
858 return this.cloneEstreeStringLiteral(node);
859 }
860 return super.cloneStringLiteral(node);
861 }
862 finishNodeAt(node, type, endLoc) {
863 return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
864 }
865 finishNode(node, type) {
866 const result = super.finishNode(node, type);
867 this.fillOptionalPropertiesForTSESLint(result);
868 return result;
869 }
870 resetStartLocation(node, startLoc) {
871 super.resetStartLocation(node, startLoc);
872 toESTreeLocation(node);
873 }
874 resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
875 super.resetEndLocation(node, endLoc);
876 toESTreeLocation(node);
877 }
878};
879class TokContext {
880 constructor(token, preserveSpace) {
881 this.token = void 0;
882 this.preserveSpace = void 0;
883 this.token = token;
884 this.preserveSpace = !!preserveSpace;
885 }
886}
887const types = {
888 brace: new TokContext("{"),
889 j_oTag: new TokContext("<tag"),
890 j_cTag: new TokContext("</tag"),
891 j_expr: new TokContext("<tag>...</tag>", true)
892};
893types.template = new TokContext("`", true);
894const beforeExpr = true;
895const startsExpr = true;
896const isLoop = true;
897const isAssign = true;
898const prefix = true;
899const postfix = true;
900class ExportedTokenType {
901 constructor(label, conf = {}) {
902 this.label = void 0;
903 this.keyword = void 0;
904 this.beforeExpr = void 0;
905 this.startsExpr = void 0;
906 this.rightAssociative = void 0;
907 this.isLoop = void 0;
908 this.isAssign = void 0;
909 this.prefix = void 0;
910 this.postfix = void 0;
911 this.binop = void 0;
912 this.label = label;
913 this.keyword = conf.keyword;
914 this.beforeExpr = !!conf.beforeExpr;
915 this.startsExpr = !!conf.startsExpr;
916 this.rightAssociative = !!conf.rightAssociative;
917 this.isLoop = !!conf.isLoop;
918 this.isAssign = !!conf.isAssign;
919 this.prefix = !!conf.prefix;
920 this.postfix = !!conf.postfix;
921 this.binop = conf.binop != null ? conf.binop : null;
922 this.updateContext = null;
923 }
924}
925const keywords$1 = new Map();
926function createKeyword(name, options = {}) {
927 options.keyword = name;
928 const token = createToken(name, options);
929 keywords$1.set(name, token);
930 return token;
931}
932function createBinop(name, binop) {
933 return createToken(name, {
934 beforeExpr,
935 binop
936 });
937}
938let tokenTypeCounter = -1;
939const tokenTypes = [];
940const tokenLabels = [];
941const tokenBinops = [];
942const tokenBeforeExprs = [];
943const tokenStartsExprs = [];
944const tokenPrefixes = [];
945function createToken(name, options = {}) {
946 var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
947 ++tokenTypeCounter;
948 tokenLabels.push(name);
949 tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
950 tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
951 tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
952 tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
953 tokenTypes.push(new ExportedTokenType(name, options));
954 return tokenTypeCounter;
955}
956function createKeywordLike(name, options = {}) {
957 var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
958 ++tokenTypeCounter;
959 keywords$1.set(name, tokenTypeCounter);
960 tokenLabels.push(name);
961 tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
962 tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
963 tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
964 tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
965 tokenTypes.push(new ExportedTokenType("name", options));
966 return tokenTypeCounter;
967}
968const tt = {
969 bracketL: createToken("[", {
970 beforeExpr,
971 startsExpr
972 }),
973 bracketHashL: createToken("#[", {
974 beforeExpr,
975 startsExpr
976 }),
977 bracketBarL: createToken("[|", {
978 beforeExpr,
979 startsExpr
980 }),
981 bracketR: createToken("]"),
982 bracketBarR: createToken("|]"),
983 braceL: createToken("{", {
984 beforeExpr,
985 startsExpr
986 }),
987 braceBarL: createToken("{|", {
988 beforeExpr,
989 startsExpr
990 }),
991 braceHashL: createToken("#{", {
992 beforeExpr,
993 startsExpr
994 }),
995 braceR: createToken("}"),
996 braceBarR: createToken("|}"),
997 parenL: createToken("(", {
998 beforeExpr,
999 startsExpr
1000 }),
1001 parenR: createToken(")"),
1002 comma: createToken(",", {
1003 beforeExpr
1004 }),
1005 semi: createToken(";", {
1006 beforeExpr
1007 }),
1008 colon: createToken(":", {
1009 beforeExpr
1010 }),
1011 doubleColon: createToken("::", {
1012 beforeExpr
1013 }),
1014 dot: createToken("."),
1015 question: createToken("?", {
1016 beforeExpr
1017 }),
1018 questionDot: createToken("?."),
1019 arrow: createToken("=>", {
1020 beforeExpr
1021 }),
1022 template: createToken("template"),
1023 ellipsis: createToken("...", {
1024 beforeExpr
1025 }),
1026 backQuote: createToken("`", {
1027 startsExpr
1028 }),
1029 dollarBraceL: createToken("${", {
1030 beforeExpr,
1031 startsExpr
1032 }),
1033 templateTail: createToken("...`", {
1034 startsExpr
1035 }),
1036 templateNonTail: createToken("...${", {
1037 beforeExpr,
1038 startsExpr
1039 }),
1040 at: createToken("@"),
1041 hash: createToken("#", {
1042 startsExpr
1043 }),
1044 interpreterDirective: createToken("#!..."),
1045 eq: createToken("=", {
1046 beforeExpr,
1047 isAssign
1048 }),
1049 assign: createToken("_=", {
1050 beforeExpr,
1051 isAssign
1052 }),
1053 slashAssign: createToken("_=", {
1054 beforeExpr,
1055 isAssign
1056 }),
1057 xorAssign: createToken("_=", {
1058 beforeExpr,
1059 isAssign
1060 }),
1061 moduloAssign: createToken("_=", {
1062 beforeExpr,
1063 isAssign
1064 }),
1065 incDec: createToken("++/--", {
1066 prefix,
1067 postfix,
1068 startsExpr
1069 }),
1070 bang: createToken("!", {
1071 beforeExpr,
1072 prefix,
1073 startsExpr
1074 }),
1075 tilde: createToken("~", {
1076 beforeExpr,
1077 prefix,
1078 startsExpr
1079 }),
1080 doubleCaret: createToken("^^", {
1081 startsExpr
1082 }),
1083 doubleAt: createToken("@@", {
1084 startsExpr
1085 }),
1086 pipeline: createBinop("|>", 0),
1087 nullishCoalescing: createBinop("??", 1),
1088 logicalOR: createBinop("||", 1),
1089 logicalAND: createBinop("&&", 2),
1090 bitwiseOR: createBinop("|", 3),
1091 bitwiseXOR: createBinop("^", 4),
1092 bitwiseAND: createBinop("&", 5),
1093 equality: createBinop("==/!=/===/!==", 6),
1094 lt: createBinop("</>/<=/>=", 7),
1095 gt: createBinop("</>/<=/>=", 7),
1096 relational: createBinop("</>/<=/>=", 7),
1097 bitShift: createBinop("<</>>/>>>", 8),
1098 bitShiftL: createBinop("<</>>/>>>", 8),
1099 bitShiftR: createBinop("<</>>/>>>", 8),
1100 plusMin: createToken("+/-", {
1101 beforeExpr,
1102 binop: 9,
1103 prefix,
1104 startsExpr
1105 }),
1106 modulo: createToken("%", {
1107 binop: 10,
1108 startsExpr
1109 }),
1110 star: createToken("*", {
1111 binop: 10
1112 }),
1113 slash: createBinop("/", 10),
1114 exponent: createToken("**", {
1115 beforeExpr,
1116 binop: 11,
1117 rightAssociative: true
1118 }),
1119 _in: createKeyword("in", {
1120 beforeExpr,
1121 binop: 7
1122 }),
1123 _instanceof: createKeyword("instanceof", {
1124 beforeExpr,
1125 binop: 7
1126 }),
1127 _break: createKeyword("break"),
1128 _case: createKeyword("case", {
1129 beforeExpr
1130 }),
1131 _catch: createKeyword("catch"),
1132 _continue: createKeyword("continue"),
1133 _debugger: createKeyword("debugger"),
1134 _default: createKeyword("default", {
1135 beforeExpr
1136 }),
1137 _else: createKeyword("else", {
1138 beforeExpr
1139 }),
1140 _finally: createKeyword("finally"),
1141 _function: createKeyword("function", {
1142 startsExpr
1143 }),
1144 _if: createKeyword("if"),
1145 _return: createKeyword("return", {
1146 beforeExpr
1147 }),
1148 _switch: createKeyword("switch"),
1149 _throw: createKeyword("throw", {
1150 beforeExpr,
1151 prefix,
1152 startsExpr
1153 }),
1154 _try: createKeyword("try"),
1155 _var: createKeyword("var"),
1156 _const: createKeyword("const"),
1157 _with: createKeyword("with"),
1158 _new: createKeyword("new", {
1159 beforeExpr,
1160 startsExpr
1161 }),
1162 _this: createKeyword("this", {
1163 startsExpr
1164 }),
1165 _super: createKeyword("super", {
1166 startsExpr
1167 }),
1168 _class: createKeyword("class", {
1169 startsExpr
1170 }),
1171 _extends: createKeyword("extends", {
1172 beforeExpr
1173 }),
1174 _export: createKeyword("export"),
1175 _import: createKeyword("import", {
1176 startsExpr
1177 }),
1178 _null: createKeyword("null", {
1179 startsExpr
1180 }),
1181 _true: createKeyword("true", {
1182 startsExpr
1183 }),
1184 _false: createKeyword("false", {
1185 startsExpr
1186 }),
1187 _typeof: createKeyword("typeof", {
1188 beforeExpr,
1189 prefix,
1190 startsExpr
1191 }),
1192 _void: createKeyword("void", {
1193 beforeExpr,
1194 prefix,
1195 startsExpr
1196 }),
1197 _delete: createKeyword("delete", {
1198 beforeExpr,
1199 prefix,
1200 startsExpr
1201 }),
1202 _do: createKeyword("do", {
1203 isLoop,
1204 beforeExpr
1205 }),
1206 _for: createKeyword("for", {
1207 isLoop
1208 }),
1209 _while: createKeyword("while", {
1210 isLoop
1211 }),
1212 _as: createKeywordLike("as", {
1213 startsExpr
1214 }),
1215 _assert: createKeywordLike("assert", {
1216 startsExpr
1217 }),
1218 _async: createKeywordLike("async", {
1219 startsExpr
1220 }),
1221 _await: createKeywordLike("await", {
1222 startsExpr
1223 }),
1224 _defer: createKeywordLike("defer", {
1225 startsExpr
1226 }),
1227 _from: createKeywordLike("from", {
1228 startsExpr
1229 }),
1230 _get: createKeywordLike("get", {
1231 startsExpr
1232 }),
1233 _let: createKeywordLike("let", {
1234 startsExpr
1235 }),
1236 _meta: createKeywordLike("meta", {
1237 startsExpr
1238 }),
1239 _of: createKeywordLike("of", {
1240 startsExpr
1241 }),
1242 _sent: createKeywordLike("sent", {
1243 startsExpr
1244 }),
1245 _set: createKeywordLike("set", {
1246 startsExpr
1247 }),
1248 _source: createKeywordLike("source", {
1249 startsExpr
1250 }),
1251 _static: createKeywordLike("static", {
1252 startsExpr
1253 }),
1254 _using: createKeywordLike("using", {
1255 startsExpr
1256 }),
1257 _yield: createKeywordLike("yield", {
1258 startsExpr
1259 }),
1260 _asserts: createKeywordLike("asserts", {
1261 startsExpr
1262 }),
1263 _checks: createKeywordLike("checks", {
1264 startsExpr
1265 }),
1266 _exports: createKeywordLike("exports", {
1267 startsExpr
1268 }),
1269 _global: createKeywordLike("global", {
1270 startsExpr
1271 }),
1272 _implements: createKeywordLike("implements", {
1273 startsExpr
1274 }),
1275 _intrinsic: createKeywordLike("intrinsic", {
1276 startsExpr
1277 }),
1278 _infer: createKeywordLike("infer", {
1279 startsExpr
1280 }),
1281 _is: createKeywordLike("is", {
1282 startsExpr
1283 }),
1284 _mixins: createKeywordLike("mixins", {
1285 startsExpr
1286 }),
1287 _proto: createKeywordLike("proto", {
1288 startsExpr
1289 }),
1290 _require: createKeywordLike("require", {
1291 startsExpr
1292 }),
1293 _satisfies: createKeywordLike("satisfies", {
1294 startsExpr
1295 }),
1296 _keyof: createKeywordLike("keyof", {
1297 startsExpr
1298 }),
1299 _readonly: createKeywordLike("readonly", {
1300 startsExpr
1301 }),
1302 _unique: createKeywordLike("unique", {
1303 startsExpr
1304 }),
1305 _abstract: createKeywordLike("abstract", {
1306 startsExpr
1307 }),
1308 _declare: createKeywordLike("declare", {
1309 startsExpr
1310 }),
1311 _enum: createKeywordLike("enum", {
1312 startsExpr
1313 }),
1314 _module: createKeywordLike("module", {
1315 startsExpr
1316 }),
1317 _namespace: createKeywordLike("namespace", {
1318 startsExpr
1319 }),
1320 _interface: createKeywordLike("interface", {
1321 startsExpr
1322 }),
1323 _type: createKeywordLike("type", {
1324 startsExpr
1325 }),
1326 _opaque: createKeywordLike("opaque", {
1327 startsExpr
1328 }),
1329 name: createToken("name", {
1330 startsExpr
1331 }),
1332 placeholder: createToken("%%", {
1333 startsExpr
1334 }),
1335 string: createToken("string", {
1336 startsExpr
1337 }),
1338 num: createToken("num", {
1339 startsExpr
1340 }),
1341 bigint: createToken("bigint", {
1342 startsExpr
1343 }),
1344 decimal: createToken("decimal", {
1345 startsExpr
1346 }),
1347 regexp: createToken("regexp", {
1348 startsExpr
1349 }),
1350 privateName: createToken("#name", {
1351 startsExpr
1352 }),
1353 eof: createToken("eof"),
1354 jsxName: createToken("jsxName"),
1355 jsxText: createToken("jsxText", {
1356 beforeExpr
1357 }),
1358 jsxTagStart: createToken("jsxTagStart", {
1359 startsExpr
1360 }),
1361 jsxTagEnd: createToken("jsxTagEnd")
1362};
1363function tokenIsIdentifier(token) {
1364 return token >= 93 && token <= 133;
1365}
1366function tokenKeywordOrIdentifierIsKeyword(token) {
1367 return token <= 92;
1368}
1369function tokenIsKeywordOrIdentifier(token) {
1370 return token >= 58 && token <= 133;
1371}
1372function tokenIsLiteralPropertyName(token) {
1373 return token >= 58 && token <= 137;
1374}
1375function tokenComesBeforeExpression(token) {
1376 return tokenBeforeExprs[token];
1377}
1378function tokenCanStartExpression(token) {
1379 return tokenStartsExprs[token];
1380}
1381function tokenIsAssignment(token) {
1382 return token >= 29 && token <= 33;
1383}
1384function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
1385 return token >= 129 && token <= 131;
1386}
1387function tokenIsLoop(token) {
1388 return token >= 90 && token <= 92;
1389}
1390function tokenIsKeyword(token) {
1391 return token >= 58 && token <= 92;
1392}
1393function tokenIsOperator(token) {
1394 return token >= 39 && token <= 59;
1395}
1396function tokenIsPostfix(token) {
1397 return token === 34;
1398}
1399function tokenIsPrefix(token) {
1400 return tokenPrefixes[token];
1401}
1402function tokenIsTSTypeOperator(token) {
1403 return token >= 121 && token <= 123;
1404}
1405function tokenIsTSDeclarationStart(token) {
1406 return token >= 124 && token <= 130;
1407}
1408function tokenLabelName(token) {
1409 return tokenLabels[token];
1410}
1411function tokenOperatorPrecedence(token) {
1412 return tokenBinops[token];
1413}
1414function tokenIsRightAssociative(token) {
1415 return token === 57;
1416}
1417function tokenIsTemplate(token) {
1418 return token >= 24 && token <= 25;
1419}
1420function getExportedToken(token) {
1421 return tokenTypes[token];
1422}
1423tokenTypes[8].updateContext = context => {
1424 context.pop();
1425};
1426tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
1427 context.push(types.brace);
1428};
1429tokenTypes[22].updateContext = context => {
1430 if (context[context.length - 1] === types.template) {
1431 context.pop();
1432 } else {
1433 context.push(types.template);
1434 }
1435};
1436tokenTypes[143].updateContext = context => {
1437 context.push(types.j_expr, types.j_oTag);
1438};
1439let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088f\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5c\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdc-\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c8a\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7dc\ua7f1-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
1440let nonASCIIidentifierChars = "\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0897-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1add\u1ae0-\u1aeb\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
1441const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
1442const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
1443nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
1444const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 7, 25, 39, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 5, 57, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 24, 43, 261, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 33, 24, 3, 24, 45, 74, 6, 0, 67, 12, 65, 1, 2, 0, 15, 4, 10, 7381, 42, 31, 98, 114, 8702, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 208, 30, 2, 2, 2, 1, 2, 6, 3, 4, 10, 1, 225, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4381, 3, 5773, 3, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 8489];
1445const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 78, 5, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 199, 7, 137, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 55, 9, 266, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
1446function isInAstralSet(code, set) {
1447 let pos = 0x10000;
1448 for (let i = 0, length = set.length; i < length; i += 2) {
1449 pos += set[i];
1450 if (pos > code) return false;
1451 pos += set[i + 1];
1452 if (pos >= code) return true;
1453 }
1454 return false;
1455}
1456function isIdentifierStart(code) {
1457 if (code < 65) return code === 36;
1458 if (code <= 90) return true;
1459 if (code < 97) return code === 95;
1460 if (code <= 122) return true;
1461 if (code <= 0xffff) {
1462 return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
1463 }
1464 return isInAstralSet(code, astralIdentifierStartCodes);
1465}
1466function isIdentifierChar(code) {
1467 if (code < 48) return code === 36;
1468 if (code < 58) return true;
1469 if (code < 65) return false;
1470 if (code <= 90) return true;
1471 if (code < 97) return code === 95;
1472 if (code <= 122) return true;
1473 if (code <= 0xffff) {
1474 return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
1475 }
1476 return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
1477}
1478const reservedWords = {
1479 keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"],
1480 strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
1481 strictBind: ["eval", "arguments"]
1482};
1483const keywords = new Set(reservedWords.keyword);
1484const reservedWordsStrictSet = new Set(reservedWords.strict);
1485const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
1486function isReservedWord(word, inModule) {
1487 return inModule && word === "await" || word === "enum";
1488}
1489function isStrictReservedWord(word, inModule) {
1490 return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
1491}
1492function isStrictBindOnlyReservedWord(word) {
1493 return reservedWordsStrictBindSet.has(word);
1494}
1495function isStrictBindReservedWord(word, inModule) {
1496 return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
1497}
1498function isKeyword(word) {
1499 return keywords.has(word);
1500}
1501function isIteratorStart(current, next, next2) {
1502 return current === 64 && next === 64 && isIdentifierStart(next2);
1503}
1504const reservedWordLikeSet = new Set(["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete", "implements", "interface", "let", "package", "private", "protected", "public", "static", "yield", "eval", "arguments", "enum", "await"]);
1505function canBeReservedWord(word) {
1506 return reservedWordLikeSet.has(word);
1507}
1508class Scope {
1509 constructor(flags) {
1510 this.flags = 0;
1511 this.names = new Map();
1512 this.firstLexicalName = "";
1513 this.flags = flags;
1514 }
1515}
1516class ScopeHandler {
1517 constructor(parser, inModule) {
1518 this.parser = void 0;
1519 this.scopeStack = [];
1520 this.inModule = void 0;
1521 this.undefinedExports = new Map();
1522 this.parser = parser;
1523 this.inModule = inModule;
1524 }
1525 get inTopLevel() {
1526 return (this.currentScope().flags & 1) > 0;
1527 }
1528 get inFunction() {
1529 return (this.currentVarScopeFlags() & 2) > 0;
1530 }
1531 get allowSuper() {
1532 return (this.currentThisScopeFlags() & 16) > 0;
1533 }
1534 get allowDirectSuper() {
1535 return (this.currentThisScopeFlags() & 32) > 0;
1536 }
1537 get allowNewTarget() {
1538 return (this.currentThisScopeFlags() & 512) > 0;
1539 }
1540 get inClass() {
1541 return (this.currentThisScopeFlags() & 64) > 0;
1542 }
1543 get inClassAndNotInNonArrowFunction() {
1544 const flags = this.currentThisScopeFlags();
1545 return (flags & 64) > 0 && (flags & 2) === 0;
1546 }
1547 get inStaticBlock() {
1548 for (let i = this.scopeStack.length - 1;; i--) {
1549 const {
1550 flags
1551 } = this.scopeStack[i];
1552 if (flags & 128) {
1553 return true;
1554 }
1555 if (flags & (1667 | 64)) {
1556 return false;
1557 }
1558 }
1559 }
1560 get inNonArrowFunction() {
1561 return (this.currentThisScopeFlags() & 2) > 0;
1562 }
1563 get inBareCaseStatement() {
1564 return (this.currentScope().flags & 256) > 0;
1565 }
1566 get treatFunctionsAsVar() {
1567 return this.treatFunctionsAsVarInScope(this.currentScope());
1568 }
1569 createScope(flags) {
1570 return new Scope(flags);
1571 }
1572 enter(flags) {
1573 this.scopeStack.push(this.createScope(flags));
1574 }
1575 exit() {
1576 const scope = this.scopeStack.pop();
1577 return scope.flags;
1578 }
1579 treatFunctionsAsVarInScope(scope) {
1580 return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
1581 }
1582 declareName(name, bindingType, loc) {
1583 let scope = this.currentScope();
1584 if (bindingType & 8 || bindingType & 16) {
1585 this.checkRedeclarationInScope(scope, name, bindingType, loc);
1586 let type = scope.names.get(name) || 0;
1587 if (bindingType & 16) {
1588 type = type | 4;
1589 } else {
1590 if (!scope.firstLexicalName) {
1591 scope.firstLexicalName = name;
1592 }
1593 type = type | 2;
1594 }
1595 scope.names.set(name, type);
1596 if (bindingType & 8) {
1597 this.maybeExportDefined(scope, name);
1598 }
1599 } else if (bindingType & 4) {
1600 for (let i = this.scopeStack.length - 1; i >= 0; --i) {
1601 scope = this.scopeStack[i];
1602 this.checkRedeclarationInScope(scope, name, bindingType, loc);
1603 scope.names.set(name, (scope.names.get(name) || 0) | 1);
1604 this.maybeExportDefined(scope, name);
1605 if (scope.flags & 1667) break;
1606 }
1607 }
1608 if (this.parser.inModule && scope.flags & 1) {
1609 this.undefinedExports.delete(name);
1610 }
1611 }
1612 maybeExportDefined(scope, name) {
1613 if (this.parser.inModule && scope.flags & 1) {
1614 this.undefinedExports.delete(name);
1615 }
1616 }
1617 checkRedeclarationInScope(scope, name, bindingType, loc) {
1618 if (this.isRedeclaredInScope(scope, name, bindingType)) {
1619 this.parser.raise(Errors.VarRedeclaration, loc, {
1620 identifierName: name
1621 });
1622 }
1623 }
1624 isRedeclaredInScope(scope, name, bindingType) {
1625 if (!(bindingType & 1)) return false;
1626 if (bindingType & 8) {
1627 return scope.names.has(name);
1628 }
1629 const type = scope.names.get(name) || 0;
1630 if (bindingType & 16) {
1631 return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
1632 }
1633 return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
1634 }
1635 checkLocalExport(id) {
1636 const {
1637 name
1638 } = id;
1639 const topLevelScope = this.scopeStack[0];
1640 if (!topLevelScope.names.has(name)) {
1641 this.undefinedExports.set(name, id.loc.start);
1642 }
1643 }
1644 currentScope() {
1645 return this.scopeStack[this.scopeStack.length - 1];
1646 }
1647 currentVarScopeFlags() {
1648 for (let i = this.scopeStack.length - 1;; i--) {
1649 const {
1650 flags
1651 } = this.scopeStack[i];
1652 if (flags & 1667) {
1653 return flags;
1654 }
1655 }
1656 }
1657 currentThisScopeFlags() {
1658 for (let i = this.scopeStack.length - 1;; i--) {
1659 const {
1660 flags
1661 } = this.scopeStack[i];
1662 if (flags & (1667 | 64) && !(flags & 4)) {
1663 return flags;
1664 }
1665 }
1666 }
1667}
1668class FlowScope extends Scope {
1669 constructor(...args) {
1670 super(...args);
1671 this.declareFunctions = new Set();
1672 }
1673}
1674class FlowScopeHandler extends ScopeHandler {
1675 createScope(flags) {
1676 return new FlowScope(flags);
1677 }
1678 declareName(name, bindingType, loc) {
1679 const scope = this.currentScope();
1680 if (bindingType & 2048) {
1681 this.checkRedeclarationInScope(scope, name, bindingType, loc);
1682 this.maybeExportDefined(scope, name);
1683 scope.declareFunctions.add(name);
1684 return;
1685 }
1686 super.declareName(name, bindingType, loc);
1687 }
1688 isRedeclaredInScope(scope, name, bindingType) {
1689 if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
1690 if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
1691 const type = scope.names.get(name);
1692 return (type & 4) > 0 || (type & 2) > 0;
1693 }
1694 return false;
1695 }
1696 checkLocalExport(id) {
1697 if (!this.scopeStack[0].declareFunctions.has(id.name)) {
1698 super.checkLocalExport(id);
1699 }
1700 }
1701}
1702const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
1703const FlowErrors = ParseErrorEnum`flow`({
1704 AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
1705 AmbiguousDeclareModuleKind: "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module.",
1706 AssignReservedType: ({
1707 reservedType
1708 }) => `Cannot overwrite reserved type ${reservedType}.`,
1709 DeclareClassElement: "The `declare` modifier can only appear on class fields.",
1710 DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
1711 DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
1712 EnumBooleanMemberNotInitialized: ({
1713 memberName,
1714 enumName
1715 }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
1716 EnumDuplicateMemberName: ({
1717 memberName,
1718 enumName
1719 }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
1720 EnumInconsistentMemberValues: ({
1721 enumName
1722 }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
1723 EnumInvalidExplicitType: ({
1724 invalidEnumType,
1725 enumName
1726 }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
1727 EnumInvalidExplicitTypeUnknownSupplied: ({
1728 enumName
1729 }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
1730 EnumInvalidMemberInitializerPrimaryType: ({
1731 enumName,
1732 memberName,
1733 explicitType
1734 }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
1735 EnumInvalidMemberInitializerSymbolType: ({
1736 enumName,
1737 memberName
1738 }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
1739 EnumInvalidMemberInitializerUnknownType: ({
1740 enumName,
1741 memberName
1742 }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
1743 EnumInvalidMemberName: ({
1744 enumName,
1745 memberName,
1746 suggestion
1747 }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
1748 EnumNumberMemberNotInitialized: ({
1749 enumName,
1750 memberName
1751 }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
1752 EnumStringMemberInconsistentlyInitialized: ({
1753 enumName
1754 }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
1755 GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
1756 ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
1757 ImportTypeShorthandOnlyInPureImport: "The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements.",
1758 InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
1759 InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
1760 InexactVariance: "Explicit inexact syntax cannot have variance.",
1761 InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
1762 MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
1763 NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
1764 NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
1765 PatternIsOptional: Object.assign({
1766 message: "A binding pattern parameter cannot be optional in an implementation signature."
1767 }, {
1768 reasonCode: "OptionalBindingPattern"
1769 }),
1770 SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
1771 SpreadVariance: "Spread properties cannot have variance.",
1772 ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
1773 ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
1774 ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
1775 ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
1776 ThisParamNoDefault: "The `this` parameter may not have a default value.",
1777 TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
1778 TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
1779 UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
1780 UnexpectedReservedType: ({
1781 reservedType
1782 }) => `Unexpected reserved type ${reservedType}.`,
1783 UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
1784 UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
1785 UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
1786 UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
1787 UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
1788 UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
1789 UnsupportedDeclareExportKind: ({
1790 unsupportedExportKind,
1791 suggestion
1792 }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
1793 UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
1794 UnterminatedFlowComment: "Unterminated flow-comment."
1795});
1796function isEsModuleType(bodyElement) {
1797 return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
1798}
1799function hasTypeImportKind(node) {
1800 return node.importKind === "type" || node.importKind === "typeof";
1801}
1802const exportSuggestions = {
1803 const: "declare export var",
1804 let: "declare export var",
1805 type: "export type",
1806 interface: "export interface"
1807};
1808function partition(list, test) {
1809 const list1 = [];
1810 const list2 = [];
1811 for (let i = 0; i < list.length; i++) {
1812 (test(list[i], i, list) ? list1 : list2).push(list[i]);
1813 }
1814 return [list1, list2];
1815}
1816const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
1817var flow = superClass => class FlowParserMixin extends superClass {
1818 constructor(...args) {
1819 super(...args);
1820 this.flowPragma = undefined;
1821 }
1822 getScopeHandler() {
1823 return FlowScopeHandler;
1824 }
1825 shouldParseTypes() {
1826 return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
1827 }
1828 finishToken(type, val) {
1829 if (type !== 134 && type !== 13 && type !== 28) {
1830 if (this.flowPragma === undefined) {
1831 this.flowPragma = null;
1832 }
1833 }
1834 super.finishToken(type, val);
1835 }
1836 addComment(comment) {
1837 if (this.flowPragma === undefined) {
1838 const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
1839 if (!matches) ;else if (matches[1] === "flow") {
1840 this.flowPragma = "flow";
1841 } else if (matches[1] === "noflow") {
1842 this.flowPragma = "noflow";
1843 } else {
1844 throw new Error("Unexpected flow pragma");
1845 }
1846 }
1847 super.addComment(comment);
1848 }
1849 flowParseTypeInitialiser(tok) {
1850 const oldInType = this.state.inType;
1851 this.state.inType = true;
1852 this.expect(tok || 14);
1853 const type = this.flowParseType();
1854 this.state.inType = oldInType;
1855 return type;
1856 }
1857 flowParsePredicate() {
1858 const node = this.startNode();
1859 const moduloLoc = this.state.startLoc;
1860 this.next();
1861 this.expectContextual(110);
1862 if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
1863 this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
1864 }
1865 if (this.eat(10)) {
1866 node.value = super.parseExpression();
1867 this.expect(11);
1868 return this.finishNode(node, "DeclaredPredicate");
1869 } else {
1870 return this.finishNode(node, "InferredPredicate");
1871 }
1872 }
1873 flowParseTypeAndPredicateInitialiser() {
1874 const oldInType = this.state.inType;
1875 this.state.inType = true;
1876 this.expect(14);
1877 let type = null;
1878 let predicate = null;
1879 if (this.match(54)) {
1880 this.state.inType = oldInType;
1881 predicate = this.flowParsePredicate();
1882 } else {
1883 type = this.flowParseType();
1884 this.state.inType = oldInType;
1885 if (this.match(54)) {
1886 predicate = this.flowParsePredicate();
1887 }
1888 }
1889 return [type, predicate];
1890 }
1891 flowParseDeclareClass(node) {
1892 this.next();
1893 this.flowParseInterfaceish(node, true);
1894 return this.finishNode(node, "DeclareClass");
1895 }
1896 flowParseDeclareFunction(node) {
1897 this.next();
1898 const id = node.id = this.parseIdentifier();
1899 const typeNode = this.startNode();
1900 const typeContainer = this.startNode();
1901 if (this.match(47)) {
1902 typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
1903 } else {
1904 typeNode.typeParameters = null;
1905 }
1906 this.expect(10);
1907 const tmp = this.flowParseFunctionTypeParams();
1908 typeNode.params = tmp.params;
1909 typeNode.rest = tmp.rest;
1910 typeNode.this = tmp._this;
1911 this.expect(11);
1912 [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
1913 typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
1914 id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
1915 this.resetEndLocation(id);
1916 this.semicolon();
1917 this.scope.declareName(node.id.name, 2048, node.id.loc.start);
1918 return this.finishNode(node, "DeclareFunction");
1919 }
1920 flowParseDeclare(node, insideModule) {
1921 if (this.match(80)) {
1922 return this.flowParseDeclareClass(node);
1923 } else if (this.match(68)) {
1924 return this.flowParseDeclareFunction(node);
1925 } else if (this.match(74)) {
1926 return this.flowParseDeclareVariable(node);
1927 } else if (this.eatContextual(127)) {
1928 if (this.match(16)) {
1929 return this.flowParseDeclareModuleExports(node);
1930 } else {
1931 if (insideModule) {
1932 this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
1933 }
1934 return this.flowParseDeclareModule(node);
1935 }
1936 } else if (this.isContextual(130)) {
1937 return this.flowParseDeclareTypeAlias(node);
1938 } else if (this.isContextual(131)) {
1939 return this.flowParseDeclareOpaqueType(node);
1940 } else if (this.isContextual(129)) {
1941 return this.flowParseDeclareInterface(node);
1942 } else if (this.match(82)) {
1943 return this.flowParseDeclareExportDeclaration(node, insideModule);
1944 }
1945 throw this.unexpected();
1946 }
1947 flowParseDeclareVariable(node) {
1948 this.next();
1949 node.id = this.flowParseTypeAnnotatableIdentifier();
1950 this.scope.declareName(node.id.name, 5, node.id.loc.start);
1951 this.semicolon();
1952 return this.finishNode(node, "DeclareVariable");
1953 }
1954 flowParseDeclareModule(node) {
1955 this.scope.enter(0);
1956 if (this.match(134)) {
1957 node.id = super.parseExprAtom();
1958 } else {
1959 node.id = this.parseIdentifier();
1960 }
1961 const bodyNode = node.body = this.startNode();
1962 const body = bodyNode.body = [];
1963 this.expect(5);
1964 while (!this.match(8)) {
1965 const bodyNode = this.startNode();
1966 if (this.match(83)) {
1967 this.next();
1968 if (!this.isContextual(130) && !this.match(87)) {
1969 this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
1970 }
1971 body.push(super.parseImport(bodyNode));
1972 } else {
1973 this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
1974 body.push(this.flowParseDeclare(bodyNode, true));
1975 }
1976 }
1977 this.scope.exit();
1978 this.expect(8);
1979 this.finishNode(bodyNode, "BlockStatement");
1980 let kind = null;
1981 let hasModuleExport = false;
1982 body.forEach(bodyElement => {
1983 if (isEsModuleType(bodyElement)) {
1984 if (kind === "CommonJS") {
1985 this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
1986 }
1987 kind = "ES";
1988 } else if (bodyElement.type === "DeclareModuleExports") {
1989 if (hasModuleExport) {
1990 this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
1991 }
1992 if (kind === "ES") {
1993 this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
1994 }
1995 kind = "CommonJS";
1996 hasModuleExport = true;
1997 }
1998 });
1999 node.kind = kind || "CommonJS";
2000 return this.finishNode(node, "DeclareModule");
2001 }
2002 flowParseDeclareExportDeclaration(node, insideModule) {
2003 this.expect(82);
2004 if (this.eat(65)) {
2005 if (this.match(68) || this.match(80)) {
2006 node.declaration = this.flowParseDeclare(this.startNode());
2007 } else {
2008 node.declaration = this.flowParseType();
2009 this.semicolon();
2010 }
2011 node.default = true;
2012 return this.finishNode(node, "DeclareExportDeclaration");
2013 } else {
2014 if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
2015 const label = this.state.value;
2016 throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
2017 unsupportedExportKind: label,
2018 suggestion: exportSuggestions[label]
2019 });
2020 }
2021 if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
2022 node.declaration = this.flowParseDeclare(this.startNode());
2023 node.default = false;
2024 return this.finishNode(node, "DeclareExportDeclaration");
2025 } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
2026 node = this.parseExport(node, null);
2027 if (node.type === "ExportNamedDeclaration") {
2028 node.default = false;
2029 delete node.exportKind;
2030 return this.castNodeTo(node, "DeclareExportDeclaration");
2031 } else {
2032 return this.castNodeTo(node, "DeclareExportAllDeclaration");
2033 }
2034 }
2035 }
2036 throw this.unexpected();
2037 }
2038 flowParseDeclareModuleExports(node) {
2039 this.next();
2040 this.expectContextual(111);
2041 node.typeAnnotation = this.flowParseTypeAnnotation();
2042 this.semicolon();
2043 return this.finishNode(node, "DeclareModuleExports");
2044 }
2045 flowParseDeclareTypeAlias(node) {
2046 this.next();
2047 const finished = this.flowParseTypeAlias(node);
2048 this.castNodeTo(finished, "DeclareTypeAlias");
2049 return finished;
2050 }
2051 flowParseDeclareOpaqueType(node) {
2052 this.next();
2053 const finished = this.flowParseOpaqueType(node, true);
2054 this.castNodeTo(finished, "DeclareOpaqueType");
2055 return finished;
2056 }
2057 flowParseDeclareInterface(node) {
2058 this.next();
2059 this.flowParseInterfaceish(node, false);
2060 return this.finishNode(node, "DeclareInterface");
2061 }
2062 flowParseInterfaceish(node, isClass) {
2063 node.id = this.flowParseRestrictedIdentifier(!isClass, true);
2064 this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
2065 if (this.match(47)) {
2066 node.typeParameters = this.flowParseTypeParameterDeclaration();
2067 } else {
2068 node.typeParameters = null;
2069 }
2070 node.extends = [];
2071 if (this.eat(81)) {
2072 do {
2073 node.extends.push(this.flowParseInterfaceExtends());
2074 } while (!isClass && this.eat(12));
2075 }
2076 if (isClass) {
2077 node.implements = [];
2078 node.mixins = [];
2079 if (this.eatContextual(117)) {
2080 do {
2081 node.mixins.push(this.flowParseInterfaceExtends());
2082 } while (this.eat(12));
2083 }
2084 if (this.eatContextual(113)) {
2085 do {
2086 node.implements.push(this.flowParseInterfaceExtends());
2087 } while (this.eat(12));
2088 }
2089 }
2090 node.body = this.flowParseObjectType({
2091 allowStatic: isClass,
2092 allowExact: false,
2093 allowSpread: false,
2094 allowProto: isClass,
2095 allowInexact: false
2096 });
2097 }
2098 flowParseInterfaceExtends() {
2099 const node = this.startNode();
2100 node.id = this.flowParseQualifiedTypeIdentifier();
2101 if (this.match(47)) {
2102 node.typeParameters = this.flowParseTypeParameterInstantiation();
2103 } else {
2104 node.typeParameters = null;
2105 }
2106 return this.finishNode(node, "InterfaceExtends");
2107 }
2108 flowParseInterface(node) {
2109 this.flowParseInterfaceish(node, false);
2110 return this.finishNode(node, "InterfaceDeclaration");
2111 }
2112 checkNotUnderscore(word) {
2113 if (word === "_") {
2114 this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
2115 }
2116 }
2117 checkReservedType(word, startLoc, declaration) {
2118 if (!reservedTypes.has(word)) return;
2119 this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
2120 reservedType: word
2121 });
2122 }
2123 flowParseRestrictedIdentifierName(liberal, declaration) {
2124 this.checkReservedType(this.state.value, this.state.startLoc, declaration);
2125 return this.parseIdentifierName(liberal);
2126 }
2127 flowParseRestrictedIdentifier(liberal, declaration) {
2128 const node = this.startNode();
2129 const name = this.flowParseRestrictedIdentifierName(liberal, declaration);
2130 return this.createIdentifier(node, name);
2131 }
2132 flowParseTypeAlias(node) {
2133 node.id = this.flowParseRestrictedIdentifier(false, true);
2134 this.scope.declareName(node.id.name, 8201, node.id.loc.start);
2135 if (this.match(47)) {
2136 node.typeParameters = this.flowParseTypeParameterDeclaration();
2137 } else {
2138 node.typeParameters = null;
2139 }
2140 node.right = this.flowParseTypeInitialiser(29);
2141 this.semicolon();
2142 return this.finishNode(node, "TypeAlias");
2143 }
2144 flowParseOpaqueType(node, declare) {
2145 this.expectContextual(130);
2146 node.id = this.flowParseRestrictedIdentifier(true, true);
2147 this.scope.declareName(node.id.name, 8201, node.id.loc.start);
2148 if (this.match(47)) {
2149 node.typeParameters = this.flowParseTypeParameterDeclaration();
2150 } else {
2151 node.typeParameters = null;
2152 }
2153 node.supertype = null;
2154 if (this.match(14)) {
2155 node.supertype = this.flowParseTypeInitialiser(14);
2156 }
2157 node.impltype = null;
2158 if (!declare) {
2159 node.impltype = this.flowParseTypeInitialiser(29);
2160 }
2161 this.semicolon();
2162 return this.finishNode(node, "OpaqueType");
2163 }
2164 flowParseTypeParameterBound() {
2165 if (this.match(14) || this.isContextual(81)) {
2166 const node = this.startNode();
2167 this.next();
2168 node.typeAnnotation = this.flowParseType();
2169 return this.finishNode(node, "TypeAnnotation");
2170 }
2171 }
2172 flowParseTypeParameter(requireDefault = false) {
2173 const nodeStartLoc = this.state.startLoc;
2174 const node = this.startNode();
2175 const variance = this.flowParseVariance();
2176 node.name = this.flowParseRestrictedIdentifierName();
2177 node.variance = variance;
2178 node.bound = this.flowParseTypeParameterBound();
2179 if (this.match(29)) {
2180 this.eat(29);
2181 node.default = this.flowParseType();
2182 } else {
2183 if (requireDefault) {
2184 this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
2185 }
2186 }
2187 return this.finishNode(node, "TypeParameter");
2188 }
2189 flowParseTypeParameterDeclaration() {
2190 const oldInType = this.state.inType;
2191 const node = this.startNode();
2192 node.params = [];
2193 this.state.inType = true;
2194 if (this.match(47) || this.match(143)) {
2195 this.next();
2196 } else {
2197 this.unexpected();
2198 }
2199 let defaultRequired = false;
2200 do {
2201 const typeParameter = this.flowParseTypeParameter(defaultRequired);
2202 node.params.push(typeParameter);
2203 if (typeParameter.default) {
2204 defaultRequired = true;
2205 }
2206 if (!this.match(48)) {
2207 this.expect(12);
2208 }
2209 } while (!this.match(48));
2210 this.expect(48);
2211 this.state.inType = oldInType;
2212 return this.finishNode(node, "TypeParameterDeclaration");
2213 }
2214 flowInTopLevelContext(cb) {
2215 if (this.curContext() !== types.brace) {
2216 const oldContext = this.state.context;
2217 this.state.context = [oldContext[0]];
2218 try {
2219 return cb();
2220 } finally {
2221 this.state.context = oldContext;
2222 }
2223 } else {
2224 return cb();
2225 }
2226 }
2227 flowParseTypeParameterInstantiationInExpression() {
2228 if (this.reScan_lt() !== 47) return;
2229 return this.flowParseTypeParameterInstantiation();
2230 }
2231 flowParseTypeParameterInstantiation() {
2232 const node = this.startNode();
2233 const oldInType = this.state.inType;
2234 this.state.inType = true;
2235 node.params = [];
2236 this.flowInTopLevelContext(() => {
2237 this.expect(47);
2238 const oldNoAnonFunctionType = this.state.noAnonFunctionType;
2239 this.state.noAnonFunctionType = false;
2240 while (!this.match(48)) {
2241 node.params.push(this.flowParseType());
2242 if (!this.match(48)) {
2243 this.expect(12);
2244 }
2245 }
2246 this.state.noAnonFunctionType = oldNoAnonFunctionType;
2247 });
2248 this.state.inType = oldInType;
2249 if (!this.state.inType && this.curContext() === types.brace) {
2250 this.reScan_lt_gt();
2251 }
2252 this.expect(48);
2253 return this.finishNode(node, "TypeParameterInstantiation");
2254 }
2255 flowParseTypeParameterInstantiationCallOrNew() {
2256 if (this.reScan_lt() !== 47) return null;
2257 const node = this.startNode();
2258 const oldInType = this.state.inType;
2259 node.params = [];
2260 this.state.inType = true;
2261 this.expect(47);
2262 while (!this.match(48)) {
2263 node.params.push(this.flowParseTypeOrImplicitInstantiation());
2264 if (!this.match(48)) {
2265 this.expect(12);
2266 }
2267 }
2268 this.expect(48);
2269 this.state.inType = oldInType;
2270 return this.finishNode(node, "TypeParameterInstantiation");
2271 }
2272 flowParseInterfaceType() {
2273 const node = this.startNode();
2274 this.expectContextual(129);
2275 node.extends = [];
2276 if (this.eat(81)) {
2277 do {
2278 node.extends.push(this.flowParseInterfaceExtends());
2279 } while (this.eat(12));
2280 }
2281 node.body = this.flowParseObjectType({
2282 allowStatic: false,
2283 allowExact: false,
2284 allowSpread: false,
2285 allowProto: false,
2286 allowInexact: false
2287 });
2288 return this.finishNode(node, "InterfaceTypeAnnotation");
2289 }
2290 flowParseObjectPropertyKey() {
2291 return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
2292 }
2293 flowParseObjectTypeIndexer(node, isStatic, variance) {
2294 node.static = isStatic;
2295 if (this.lookahead().type === 14) {
2296 node.id = this.flowParseObjectPropertyKey();
2297 node.key = this.flowParseTypeInitialiser();
2298 } else {
2299 node.id = null;
2300 node.key = this.flowParseType();
2301 }
2302 this.expect(3);
2303 node.value = this.flowParseTypeInitialiser();
2304 node.variance = variance;
2305 return this.finishNode(node, "ObjectTypeIndexer");
2306 }
2307 flowParseObjectTypeInternalSlot(node, isStatic) {
2308 node.static = isStatic;
2309 node.id = this.flowParseObjectPropertyKey();
2310 this.expect(3);
2311 this.expect(3);
2312 if (this.match(47) || this.match(10)) {
2313 node.method = true;
2314 node.optional = false;
2315 node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
2316 } else {
2317 node.method = false;
2318 if (this.eat(17)) {
2319 node.optional = true;
2320 }
2321 node.value = this.flowParseTypeInitialiser();
2322 }
2323 return this.finishNode(node, "ObjectTypeInternalSlot");
2324 }
2325 flowParseObjectTypeMethodish(node) {
2326 node.params = [];
2327 node.rest = null;
2328 node.typeParameters = null;
2329 node.this = null;
2330 if (this.match(47)) {
2331 node.typeParameters = this.flowParseTypeParameterDeclaration();
2332 }
2333 this.expect(10);
2334 if (this.match(78)) {
2335 node.this = this.flowParseFunctionTypeParam(true);
2336 node.this.name = null;
2337 if (!this.match(11)) {
2338 this.expect(12);
2339 }
2340 }
2341 while (!this.match(11) && !this.match(21)) {
2342 node.params.push(this.flowParseFunctionTypeParam(false));
2343 if (!this.match(11)) {
2344 this.expect(12);
2345 }
2346 }
2347 if (this.eat(21)) {
2348 node.rest = this.flowParseFunctionTypeParam(false);
2349 }
2350 this.expect(11);
2351 node.returnType = this.flowParseTypeInitialiser();
2352 return this.finishNode(node, "FunctionTypeAnnotation");
2353 }
2354 flowParseObjectTypeCallProperty(node, isStatic) {
2355 const valueNode = this.startNode();
2356 node.static = isStatic;
2357 node.value = this.flowParseObjectTypeMethodish(valueNode);
2358 return this.finishNode(node, "ObjectTypeCallProperty");
2359 }
2360 flowParseObjectType({
2361 allowStatic,
2362 allowExact,
2363 allowSpread,
2364 allowProto,
2365 allowInexact
2366 }) {
2367 const oldInType = this.state.inType;
2368 this.state.inType = true;
2369 const nodeStart = this.startNode();
2370 nodeStart.callProperties = [];
2371 nodeStart.properties = [];
2372 nodeStart.indexers = [];
2373 nodeStart.internalSlots = [];
2374 let endDelim;
2375 let exact;
2376 let inexact = false;
2377 if (allowExact && this.match(6)) {
2378 this.expect(6);
2379 endDelim = 9;
2380 exact = true;
2381 } else {
2382 this.expect(5);
2383 endDelim = 8;
2384 exact = false;
2385 }
2386 nodeStart.exact = exact;
2387 while (!this.match(endDelim)) {
2388 let isStatic = false;
2389 let protoStartLoc = null;
2390 let inexactStartLoc = null;
2391 const node = this.startNode();
2392 if (allowProto && this.isContextual(118)) {
2393 const lookahead = this.lookahead();
2394 if (lookahead.type !== 14 && lookahead.type !== 17) {
2395 this.next();
2396 protoStartLoc = this.state.startLoc;
2397 allowStatic = false;
2398 }
2399 }
2400 if (allowStatic && this.isContextual(106)) {
2401 const lookahead = this.lookahead();
2402 if (lookahead.type !== 14 && lookahead.type !== 17) {
2403 this.next();
2404 isStatic = true;
2405 }
2406 }
2407 const variance = this.flowParseVariance();
2408 if (this.eat(0)) {
2409 if (protoStartLoc != null) {
2410 this.unexpected(protoStartLoc);
2411 }
2412 if (this.eat(0)) {
2413 if (variance) {
2414 this.unexpected(variance.loc.start);
2415 }
2416 nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
2417 } else {
2418 nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
2419 }
2420 } else if (this.match(10) || this.match(47)) {
2421 if (protoStartLoc != null) {
2422 this.unexpected(protoStartLoc);
2423 }
2424 if (variance) {
2425 this.unexpected(variance.loc.start);
2426 }
2427 nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
2428 } else {
2429 let kind = "init";
2430 if (this.isContextual(99) || this.isContextual(104)) {
2431 const lookahead = this.lookahead();
2432 if (tokenIsLiteralPropertyName(lookahead.type)) {
2433 kind = this.state.value;
2434 this.next();
2435 }
2436 }
2437 const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
2438 if (propOrInexact === null) {
2439 inexact = true;
2440 inexactStartLoc = this.state.lastTokStartLoc;
2441 } else {
2442 nodeStart.properties.push(propOrInexact);
2443 }
2444 }
2445 this.flowObjectTypeSemicolon();
2446 if (inexactStartLoc && !this.match(8) && !this.match(9)) {
2447 this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
2448 }
2449 }
2450 this.expect(endDelim);
2451 if (allowSpread) {
2452 nodeStart.inexact = inexact;
2453 }
2454 const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
2455 this.state.inType = oldInType;
2456 return out;
2457 }
2458 flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
2459 if (this.eat(21)) {
2460 const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
2461 if (isInexactToken) {
2462 if (!allowSpread) {
2463 this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
2464 } else if (!allowInexact) {
2465 this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
2466 }
2467 if (variance) {
2468 this.raise(FlowErrors.InexactVariance, variance);
2469 }
2470 return null;
2471 }
2472 if (!allowSpread) {
2473 this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
2474 }
2475 if (protoStartLoc != null) {
2476 this.unexpected(protoStartLoc);
2477 }
2478 if (variance) {
2479 this.raise(FlowErrors.SpreadVariance, variance);
2480 }
2481 node.argument = this.flowParseType();
2482 return this.finishNode(node, "ObjectTypeSpreadProperty");
2483 } else {
2484 node.key = this.flowParseObjectPropertyKey();
2485 node.static = isStatic;
2486 node.proto = protoStartLoc != null;
2487 node.kind = kind;
2488 let optional = false;
2489 if (this.match(47) || this.match(10)) {
2490 node.method = true;
2491 if (protoStartLoc != null) {
2492 this.unexpected(protoStartLoc);
2493 }
2494 if (variance) {
2495 this.unexpected(variance.loc.start);
2496 }
2497 node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
2498 if (kind === "get" || kind === "set") {
2499 this.flowCheckGetterSetterParams(node);
2500 }
2501 if (!allowSpread && node.key.name === "constructor" && node.value.this) {
2502 this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
2503 }
2504 } else {
2505 if (kind !== "init") this.unexpected();
2506 node.method = false;
2507 if (this.eat(17)) {
2508 optional = true;
2509 }
2510 node.value = this.flowParseTypeInitialiser();
2511 node.variance = variance;
2512 }
2513 node.optional = optional;
2514 return this.finishNode(node, "ObjectTypeProperty");
2515 }
2516 }
2517 flowCheckGetterSetterParams(property) {
2518 const paramCount = property.kind === "get" ? 0 : 1;
2519 const length = property.value.params.length + (property.value.rest ? 1 : 0);
2520 if (property.value.this) {
2521 this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
2522 }
2523 if (length !== paramCount) {
2524 this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
2525 }
2526 if (property.kind === "set" && property.value.rest) {
2527 this.raise(Errors.BadSetterRestParameter, property);
2528 }
2529 }
2530 flowObjectTypeSemicolon() {
2531 if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
2532 this.unexpected();
2533 }
2534 }
2535 flowParseQualifiedTypeIdentifier(startLoc, id) {
2536 startLoc != null ? startLoc : startLoc = this.state.startLoc;
2537 let node = id || this.flowParseRestrictedIdentifier(true);
2538 while (this.eat(16)) {
2539 const node2 = this.startNodeAt(startLoc);
2540 node2.qualification = node;
2541 node2.id = this.flowParseRestrictedIdentifier(true);
2542 node = this.finishNode(node2, "QualifiedTypeIdentifier");
2543 }
2544 return node;
2545 }
2546 flowParseGenericType(startLoc, id) {
2547 const node = this.startNodeAt(startLoc);
2548 node.typeParameters = null;
2549 node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
2550 if (this.match(47)) {
2551 node.typeParameters = this.flowParseTypeParameterInstantiation();
2552 }
2553 return this.finishNode(node, "GenericTypeAnnotation");
2554 }
2555 flowParseTypeofType() {
2556 const node = this.startNode();
2557 this.expect(87);
2558 node.argument = this.flowParsePrimaryType();
2559 return this.finishNode(node, "TypeofTypeAnnotation");
2560 }
2561 flowParseTupleType() {
2562 const node = this.startNode();
2563 node.types = [];
2564 this.expect(0);
2565 while (this.state.pos < this.length && !this.match(3)) {
2566 node.types.push(this.flowParseType());
2567 if (this.match(3)) break;
2568 this.expect(12);
2569 }
2570 this.expect(3);
2571 return this.finishNode(node, "TupleTypeAnnotation");
2572 }
2573 flowParseFunctionTypeParam(first) {
2574 let name = null;
2575 let optional = false;
2576 let typeAnnotation = null;
2577 const node = this.startNode();
2578 const lh = this.lookahead();
2579 const isThis = this.state.type === 78;
2580 if (lh.type === 14 || lh.type === 17) {
2581 if (isThis && !first) {
2582 this.raise(FlowErrors.ThisParamMustBeFirst, node);
2583 }
2584 name = this.parseIdentifier(isThis);
2585 if (this.eat(17)) {
2586 optional = true;
2587 if (isThis) {
2588 this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
2589 }
2590 }
2591 typeAnnotation = this.flowParseTypeInitialiser();
2592 } else {
2593 typeAnnotation = this.flowParseType();
2594 }
2595 node.name = name;
2596 node.optional = optional;
2597 node.typeAnnotation = typeAnnotation;
2598 return this.finishNode(node, "FunctionTypeParam");
2599 }
2600 reinterpretTypeAsFunctionTypeParam(type) {
2601 const node = this.startNodeAt(type.loc.start);
2602 node.name = null;
2603 node.optional = false;
2604 node.typeAnnotation = type;
2605 return this.finishNode(node, "FunctionTypeParam");
2606 }
2607 flowParseFunctionTypeParams(params = []) {
2608 let rest = null;
2609 let _this = null;
2610 if (this.match(78)) {
2611 _this = this.flowParseFunctionTypeParam(true);
2612 _this.name = null;
2613 if (!this.match(11)) {
2614 this.expect(12);
2615 }
2616 }
2617 while (!this.match(11) && !this.match(21)) {
2618 params.push(this.flowParseFunctionTypeParam(false));
2619 if (!this.match(11)) {
2620 this.expect(12);
2621 }
2622 }
2623 if (this.eat(21)) {
2624 rest = this.flowParseFunctionTypeParam(false);
2625 }
2626 return {
2627 params,
2628 rest,
2629 _this
2630 };
2631 }
2632 flowIdentToTypeAnnotation(startLoc, node, id) {
2633 switch (id.name) {
2634 case "any":
2635 return this.finishNode(node, "AnyTypeAnnotation");
2636 case "bool":
2637 case "boolean":
2638 return this.finishNode(node, "BooleanTypeAnnotation");
2639 case "mixed":
2640 return this.finishNode(node, "MixedTypeAnnotation");
2641 case "empty":
2642 return this.finishNode(node, "EmptyTypeAnnotation");
2643 case "number":
2644 return this.finishNode(node, "NumberTypeAnnotation");
2645 case "string":
2646 return this.finishNode(node, "StringTypeAnnotation");
2647 case "symbol":
2648 return this.finishNode(node, "SymbolTypeAnnotation");
2649 default:
2650 this.checkNotUnderscore(id.name);
2651 return this.flowParseGenericType(startLoc, id);
2652 }
2653 }
2654 flowParsePrimaryType() {
2655 const startLoc = this.state.startLoc;
2656 const node = this.startNode();
2657 let tmp;
2658 let type;
2659 let isGroupedType = false;
2660 const oldNoAnonFunctionType = this.state.noAnonFunctionType;
2661 switch (this.state.type) {
2662 case 5:
2663 return this.flowParseObjectType({
2664 allowStatic: false,
2665 allowExact: false,
2666 allowSpread: true,
2667 allowProto: false,
2668 allowInexact: true
2669 });
2670 case 6:
2671 return this.flowParseObjectType({
2672 allowStatic: false,
2673 allowExact: true,
2674 allowSpread: true,
2675 allowProto: false,
2676 allowInexact: false
2677 });
2678 case 0:
2679 this.state.noAnonFunctionType = false;
2680 type = this.flowParseTupleType();
2681 this.state.noAnonFunctionType = oldNoAnonFunctionType;
2682 return type;
2683 case 47:
2684 {
2685 const node = this.startNode();
2686 node.typeParameters = this.flowParseTypeParameterDeclaration();
2687 this.expect(10);
2688 tmp = this.flowParseFunctionTypeParams();
2689 node.params = tmp.params;
2690 node.rest = tmp.rest;
2691 node.this = tmp._this;
2692 this.expect(11);
2693 this.expect(19);
2694 node.returnType = this.flowParseType();
2695 return this.finishNode(node, "FunctionTypeAnnotation");
2696 }
2697 case 10:
2698 {
2699 const node = this.startNode();
2700 this.next();
2701 if (!this.match(11) && !this.match(21)) {
2702 if (tokenIsIdentifier(this.state.type) || this.match(78)) {
2703 const token = this.lookahead().type;
2704 isGroupedType = token !== 17 && token !== 14;
2705 } else {
2706 isGroupedType = true;
2707 }
2708 }
2709 if (isGroupedType) {
2710 this.state.noAnonFunctionType = false;
2711 type = this.flowParseType();
2712 this.state.noAnonFunctionType = oldNoAnonFunctionType;
2713 if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
2714 this.expect(11);
2715 return type;
2716 } else {
2717 this.eat(12);
2718 }
2719 }
2720 if (type) {
2721 tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
2722 } else {
2723 tmp = this.flowParseFunctionTypeParams();
2724 }
2725 node.params = tmp.params;
2726 node.rest = tmp.rest;
2727 node.this = tmp._this;
2728 this.expect(11);
2729 this.expect(19);
2730 node.returnType = this.flowParseType();
2731 node.typeParameters = null;
2732 return this.finishNode(node, "FunctionTypeAnnotation");
2733 }
2734 case 134:
2735 return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
2736 case 85:
2737 case 86:
2738 node.value = this.match(85);
2739 this.next();
2740 return this.finishNode(node, "BooleanLiteralTypeAnnotation");
2741 case 53:
2742 if (this.state.value === "-") {
2743 this.next();
2744 if (this.match(135)) {
2745 return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
2746 }
2747 if (this.match(136)) {
2748 return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
2749 }
2750 throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
2751 }
2752 throw this.unexpected();
2753 case 135:
2754 return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
2755 case 136:
2756 return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
2757 case 88:
2758 this.next();
2759 return this.finishNode(node, "VoidTypeAnnotation");
2760 case 84:
2761 this.next();
2762 return this.finishNode(node, "NullLiteralTypeAnnotation");
2763 case 78:
2764 this.next();
2765 return this.finishNode(node, "ThisTypeAnnotation");
2766 case 55:
2767 this.next();
2768 return this.finishNode(node, "ExistsTypeAnnotation");
2769 case 87:
2770 return this.flowParseTypeofType();
2771 default:
2772 if (tokenIsKeyword(this.state.type)) {
2773 const label = tokenLabelName(this.state.type);
2774 this.next();
2775 return super.createIdentifier(node, label);
2776 } else if (tokenIsIdentifier(this.state.type)) {
2777 if (this.isContextual(129)) {
2778 return this.flowParseInterfaceType();
2779 }
2780 return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
2781 }
2782 }
2783 throw this.unexpected();
2784 }
2785 flowParsePostfixType() {
2786 const startLoc = this.state.startLoc;
2787 let type = this.flowParsePrimaryType();
2788 let seenOptionalIndexedAccess = false;
2789 while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
2790 const node = this.startNodeAt(startLoc);
2791 const optional = this.eat(18);
2792 seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
2793 this.expect(0);
2794 if (!optional && this.match(3)) {
2795 node.elementType = type;
2796 this.next();
2797 type = this.finishNode(node, "ArrayTypeAnnotation");
2798 } else {
2799 node.objectType = type;
2800 node.indexType = this.flowParseType();
2801 this.expect(3);
2802 if (seenOptionalIndexedAccess) {
2803 node.optional = optional;
2804 type = this.finishNode(node, "OptionalIndexedAccessType");
2805 } else {
2806 type = this.finishNode(node, "IndexedAccessType");
2807 }
2808 }
2809 }
2810 return type;
2811 }
2812 flowParsePrefixType() {
2813 const node = this.startNode();
2814 if (this.eat(17)) {
2815 node.typeAnnotation = this.flowParsePrefixType();
2816 return this.finishNode(node, "NullableTypeAnnotation");
2817 } else {
2818 return this.flowParsePostfixType();
2819 }
2820 }
2821 flowParseAnonFunctionWithoutParens() {
2822 const param = this.flowParsePrefixType();
2823 if (!this.state.noAnonFunctionType && this.eat(19)) {
2824 const node = this.startNodeAt(param.loc.start);
2825 node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
2826 node.rest = null;
2827 node.this = null;
2828 node.returnType = this.flowParseType();
2829 node.typeParameters = null;
2830 return this.finishNode(node, "FunctionTypeAnnotation");
2831 }
2832 return param;
2833 }
2834 flowParseIntersectionType() {
2835 const node = this.startNode();
2836 this.eat(45);
2837 const type = this.flowParseAnonFunctionWithoutParens();
2838 node.types = [type];
2839 while (this.eat(45)) {
2840 node.types.push(this.flowParseAnonFunctionWithoutParens());
2841 }
2842 return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
2843 }
2844 flowParseUnionType() {
2845 const node = this.startNode();
2846 this.eat(43);
2847 const type = this.flowParseIntersectionType();
2848 node.types = [type];
2849 while (this.eat(43)) {
2850 node.types.push(this.flowParseIntersectionType());
2851 }
2852 return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
2853 }
2854 flowParseType() {
2855 const oldInType = this.state.inType;
2856 this.state.inType = true;
2857 const type = this.flowParseUnionType();
2858 this.state.inType = oldInType;
2859 return type;
2860 }
2861 flowParseTypeOrImplicitInstantiation() {
2862 if (this.state.type === 132 && this.state.value === "_") {
2863 const startLoc = this.state.startLoc;
2864 const node = this.parseIdentifier();
2865 return this.flowParseGenericType(startLoc, node);
2866 } else {
2867 return this.flowParseType();
2868 }
2869 }
2870 flowParseTypeAnnotation() {
2871 const node = this.startNode();
2872 node.typeAnnotation = this.flowParseTypeInitialiser();
2873 return this.finishNode(node, "TypeAnnotation");
2874 }
2875 flowParseTypeAnnotatableIdentifier() {
2876 const node = this.startNode();
2877 const name = this.parseIdentifierName();
2878 if (this.match(14)) {
2879 node.typeAnnotation = this.flowParseTypeAnnotation();
2880 }
2881 return this.createIdentifier(node, name);
2882 }
2883 typeCastToParameter(node) {
2884 node.expression.typeAnnotation = node.typeAnnotation;
2885 this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
2886 return node.expression;
2887 }
2888 flowParseVariance() {
2889 let variance = null;
2890 if (this.match(53)) {
2891 variance = this.startNode();
2892 if (this.state.value === "+") {
2893 variance.kind = "plus";
2894 } else {
2895 variance.kind = "minus";
2896 }
2897 this.next();
2898 return this.finishNode(variance, "Variance");
2899 }
2900 return variance;
2901 }
2902 parseFunctionBody(node, allowExpressionBody, isMethod = false) {
2903 if (allowExpressionBody) {
2904 this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
2905 return;
2906 }
2907 super.parseFunctionBody(node, false, isMethod);
2908 }
2909 parseFunctionBodyAndFinish(node, type, isMethod = false) {
2910 if (this.match(14)) {
2911 const typeNode = this.startNode();
2912 [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
2913 node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
2914 }
2915 return super.parseFunctionBodyAndFinish(node, type, isMethod);
2916 }
2917 parseStatementLike(flags) {
2918 if (this.state.strict && this.isContextual(129)) {
2919 const lookahead = this.lookahead();
2920 if (tokenIsKeywordOrIdentifier(lookahead.type)) {
2921 const node = this.startNode();
2922 this.next();
2923 return this.flowParseInterface(node);
2924 }
2925 } else if (this.isContextual(126)) {
2926 const node = this.startNode();
2927 this.next();
2928 return this.flowParseEnumDeclaration(node);
2929 }
2930 const stmt = super.parseStatementLike(flags);
2931 if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
2932 this.flowPragma = null;
2933 }
2934 return stmt;
2935 }
2936 parseExpressionStatement(node, expr, decorators) {
2937 if (expr.type === "Identifier") {
2938 if (expr.name === "declare") {
2939 if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
2940 return this.flowParseDeclare(node);
2941 }
2942 } else if (tokenIsIdentifier(this.state.type)) {
2943 if (expr.name === "interface") {
2944 return this.flowParseInterface(node);
2945 } else if (expr.name === "type") {
2946 return this.flowParseTypeAlias(node);
2947 } else if (expr.name === "opaque") {
2948 return this.flowParseOpaqueType(node, false);
2949 }
2950 }
2951 }
2952 return super.parseExpressionStatement(node, expr, decorators);
2953 }
2954 shouldParseExportDeclaration() {
2955 const {
2956 type
2957 } = this.state;
2958 if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
2959 return !this.state.containsEsc;
2960 }
2961 return super.shouldParseExportDeclaration();
2962 }
2963 isExportDefaultSpecifier() {
2964 const {
2965 type
2966 } = this.state;
2967 if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
2968 return this.state.containsEsc;
2969 }
2970 return super.isExportDefaultSpecifier();
2971 }
2972 parseExportDefaultExpression() {
2973 if (this.isContextual(126)) {
2974 const node = this.startNode();
2975 this.next();
2976 return this.flowParseEnumDeclaration(node);
2977 }
2978 return super.parseExportDefaultExpression();
2979 }
2980 parseConditional(expr, startLoc, refExpressionErrors) {
2981 if (!this.match(17)) return expr;
2982 if (this.state.maybeInArrowParameters) {
2983 const nextCh = this.lookaheadCharCode();
2984 if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
2985 this.setOptionalParametersError(refExpressionErrors);
2986 return expr;
2987 }
2988 }
2989 this.expect(17);
2990 const state = this.state.clone();
2991 const originalNoArrowAt = this.state.noArrowAt;
2992 const node = this.startNodeAt(startLoc);
2993 let {
2994 consequent,
2995 failed
2996 } = this.tryParseConditionalConsequent();
2997 let [valid, invalid] = this.getArrowLikeExpressions(consequent);
2998 if (failed || invalid.length > 0) {
2999 const noArrowAt = [...originalNoArrowAt];
3000 if (invalid.length > 0) {
3001 this.state = state;
3002 this.state.noArrowAt = noArrowAt;
3003 for (let i = 0; i < invalid.length; i++) {
3004 noArrowAt.push(invalid[i].start);
3005 }
3006 ({
3007 consequent,
3008 failed
3009 } = this.tryParseConditionalConsequent());
3010 [valid, invalid] = this.getArrowLikeExpressions(consequent);
3011 }
3012 if (failed && valid.length > 1) {
3013 this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
3014 }
3015 if (failed && valid.length === 1) {
3016 this.state = state;
3017 noArrowAt.push(valid[0].start);
3018 this.state.noArrowAt = noArrowAt;
3019 ({
3020 consequent,
3021 failed
3022 } = this.tryParseConditionalConsequent());
3023 }
3024 }
3025 this.getArrowLikeExpressions(consequent, true);
3026 this.state.noArrowAt = originalNoArrowAt;
3027 this.expect(14);
3028 node.test = expr;
3029 node.consequent = consequent;
3030 node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
3031 return this.finishNode(node, "ConditionalExpression");
3032 }
3033 tryParseConditionalConsequent() {
3034 this.state.noArrowParamsConversionAt.push(this.state.start);
3035 const consequent = this.parseMaybeAssignAllowIn();
3036 const failed = !this.match(14);
3037 this.state.noArrowParamsConversionAt.pop();
3038 return {
3039 consequent,
3040 failed
3041 };
3042 }
3043 getArrowLikeExpressions(node, disallowInvalid) {
3044 const stack = [node];
3045 const arrows = [];
3046 while (stack.length !== 0) {
3047 const node = stack.pop();
3048 if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
3049 if (node.typeParameters || !node.returnType) {
3050 this.finishArrowValidation(node);
3051 } else {
3052 arrows.push(node);
3053 }
3054 stack.push(node.body);
3055 } else if (node.type === "ConditionalExpression") {
3056 stack.push(node.consequent);
3057 stack.push(node.alternate);
3058 }
3059 }
3060 if (disallowInvalid) {
3061 arrows.forEach(node => this.finishArrowValidation(node));
3062 return [arrows, []];
3063 }
3064 return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
3065 }
3066 finishArrowValidation(node) {
3067 var _node$extra;
3068 this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
3069 this.scope.enter(514 | 4);
3070 super.checkParams(node, false, true);
3071 this.scope.exit();
3072 }
3073 forwardNoArrowParamsConversionAt(node, parse) {
3074 let result;
3075 if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
3076 this.state.noArrowParamsConversionAt.push(this.state.start);
3077 result = parse();
3078 this.state.noArrowParamsConversionAt.pop();
3079 } else {
3080 result = parse();
3081 }
3082 return result;
3083 }
3084 parseParenItem(node, startLoc) {
3085 const newNode = super.parseParenItem(node, startLoc);
3086 if (this.eat(17)) {
3087 newNode.optional = true;
3088 this.resetEndLocation(node);
3089 }
3090 if (this.match(14)) {
3091 const typeCastNode = this.startNodeAt(startLoc);
3092 typeCastNode.expression = newNode;
3093 typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
3094 return this.finishNode(typeCastNode, "TypeCastExpression");
3095 }
3096 return newNode;
3097 }
3098 assertModuleNodeAllowed(node) {
3099 if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
3100 return;
3101 }
3102 super.assertModuleNodeAllowed(node);
3103 }
3104 parseExportDeclaration(node) {
3105 if (this.isContextual(130)) {
3106 node.exportKind = "type";
3107 const declarationNode = this.startNode();
3108 this.next();
3109 if (this.match(5)) {
3110 node.specifiers = this.parseExportSpecifiers(true);
3111 super.parseExportFrom(node);
3112 return null;
3113 } else {
3114 return this.flowParseTypeAlias(declarationNode);
3115 }
3116 } else if (this.isContextual(131)) {
3117 node.exportKind = "type";
3118 const declarationNode = this.startNode();
3119 this.next();
3120 return this.flowParseOpaqueType(declarationNode, false);
3121 } else if (this.isContextual(129)) {
3122 node.exportKind = "type";
3123 const declarationNode = this.startNode();
3124 this.next();
3125 return this.flowParseInterface(declarationNode);
3126 } else if (this.isContextual(126)) {
3127 node.exportKind = "value";
3128 const declarationNode = this.startNode();
3129 this.next();
3130 return this.flowParseEnumDeclaration(declarationNode);
3131 } else {
3132 return super.parseExportDeclaration(node);
3133 }
3134 }
3135 eatExportStar(node) {
3136 if (super.eatExportStar(node)) return true;
3137 if (this.isContextual(130) && this.lookahead().type === 55) {
3138 node.exportKind = "type";
3139 this.next();
3140 this.next();
3141 return true;
3142 }
3143 return false;
3144 }
3145 maybeParseExportNamespaceSpecifier(node) {
3146 const {
3147 startLoc
3148 } = this.state;
3149 const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
3150 if (hasNamespace && node.exportKind === "type") {
3151 this.unexpected(startLoc);
3152 }
3153 return hasNamespace;
3154 }
3155 parseClassId(node, isStatement, optionalId) {
3156 super.parseClassId(node, isStatement, optionalId);
3157 if (this.match(47)) {
3158 node.typeParameters = this.flowParseTypeParameterDeclaration();
3159 }
3160 }
3161 parseClassMember(classBody, member, state) {
3162 const {
3163 startLoc
3164 } = this.state;
3165 if (this.isContextual(125)) {
3166 if (super.parseClassMemberFromModifier(classBody, member)) {
3167 return;
3168 }
3169 member.declare = true;
3170 }
3171 super.parseClassMember(classBody, member, state);
3172 if (member.declare) {
3173 if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
3174 this.raise(FlowErrors.DeclareClassElement, startLoc);
3175 } else if (member.value) {
3176 this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
3177 }
3178 }
3179 }
3180 isIterator(word) {
3181 return word === "iterator" || word === "asyncIterator";
3182 }
3183 readIterator() {
3184 const word = super.readWord1();
3185 const fullWord = "@@" + word;
3186 if (!this.isIterator(word) || !this.state.inType) {
3187 this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
3188 identifierName: fullWord
3189 });
3190 }
3191 this.finishToken(132, fullWord);
3192 }
3193 getTokenFromCode(code) {
3194 const next = this.input.charCodeAt(this.state.pos + 1);
3195 if (code === 123 && next === 124) {
3196 this.finishOp(6, 2);
3197 } else if (this.state.inType && (code === 62 || code === 60)) {
3198 this.finishOp(code === 62 ? 48 : 47, 1);
3199 } else if (this.state.inType && code === 63) {
3200 if (next === 46) {
3201 this.finishOp(18, 2);
3202 } else {
3203 this.finishOp(17, 1);
3204 }
3205 } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
3206 this.state.pos += 2;
3207 this.readIterator();
3208 } else {
3209 super.getTokenFromCode(code);
3210 }
3211 }
3212 isAssignable(node, isBinding) {
3213 if (node.type === "TypeCastExpression") {
3214 return this.isAssignable(node.expression, isBinding);
3215 } else {
3216 return super.isAssignable(node, isBinding);
3217 }
3218 }
3219 toAssignable(node, isLHS = false) {
3220 if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
3221 node.left = this.typeCastToParameter(node.left);
3222 }
3223 super.toAssignable(node, isLHS);
3224 }
3225 toAssignableList(exprList, trailingCommaLoc, isLHS) {
3226 for (let i = 0; i < exprList.length; i++) {
3227 const expr = exprList[i];
3228 if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
3229 exprList[i] = this.typeCastToParameter(expr);
3230 }
3231 }
3232 super.toAssignableList(exprList, trailingCommaLoc, isLHS);
3233 }
3234 toReferencedList(exprList, isParenthesizedExpr) {
3235 for (let i = 0; i < exprList.length; i++) {
3236 var _expr$extra;
3237 const expr = exprList[i];
3238 if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
3239 this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
3240 }
3241 }
3242 return exprList;
3243 }
3244 parseArrayLike(close, isTuple, refExpressionErrors) {
3245 const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
3246 if (refExpressionErrors != null && !this.state.maybeInArrowParameters) {
3247 this.toReferencedList(node.elements);
3248 }
3249 return node;
3250 }
3251 isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
3252 return type === "TypeCastExpression" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
3253 }
3254 parseClassProperty(node) {
3255 if (this.match(14)) {
3256 node.typeAnnotation = this.flowParseTypeAnnotation();
3257 }
3258 return super.parseClassProperty(node);
3259 }
3260 parseClassPrivateProperty(node) {
3261 if (this.match(14)) {
3262 node.typeAnnotation = this.flowParseTypeAnnotation();
3263 }
3264 return super.parseClassPrivateProperty(node);
3265 }
3266 isClassMethod() {
3267 return this.match(47) || super.isClassMethod();
3268 }
3269 isClassProperty() {
3270 return this.match(14) || super.isClassProperty();
3271 }
3272 isNonstaticConstructor(method) {
3273 return !this.match(14) && super.isNonstaticConstructor(method);
3274 }
3275 pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
3276 if (method.variance) {
3277 this.unexpected(method.variance.loc.start);
3278 }
3279 delete method.variance;
3280 if (this.match(47)) {
3281 method.typeParameters = this.flowParseTypeParameterDeclaration();
3282 }
3283 super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
3284 if (method.params && isConstructor) {
3285 const params = method.params;
3286 if (params.length > 0 && this.isThisParam(params[0])) {
3287 this.raise(FlowErrors.ThisParamBannedInConstructor, method);
3288 }
3289 } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
3290 const params = method.value.params;
3291 if (params.length > 0 && this.isThisParam(params[0])) {
3292 this.raise(FlowErrors.ThisParamBannedInConstructor, method);
3293 }
3294 }
3295 }
3296 pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
3297 if (method.variance) {
3298 this.unexpected(method.variance.loc.start);
3299 }
3300 delete method.variance;
3301 if (this.match(47)) {
3302 method.typeParameters = this.flowParseTypeParameterDeclaration();
3303 }
3304 super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
3305 }
3306 parseClassSuper(node) {
3307 super.parseClassSuper(node);
3308 if (node.superClass && (this.match(47) || this.match(51))) {
3309 node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
3310 }
3311 if (this.isContextual(113)) {
3312 this.next();
3313 const implemented = node.implements = [];
3314 do {
3315 const node = this.startNode();
3316 node.id = this.flowParseRestrictedIdentifier(true);
3317 if (this.match(47)) {
3318 node.typeParameters = this.flowParseTypeParameterInstantiation();
3319 } else {
3320 node.typeParameters = null;
3321 }
3322 implemented.push(this.finishNode(node, "ClassImplements"));
3323 } while (this.eat(12));
3324 }
3325 }
3326 checkGetterSetterParams(method) {
3327 super.checkGetterSetterParams(method);
3328 const params = this.getObjectOrClassMethodParams(method);
3329 if (params.length > 0) {
3330 const param = params[0];
3331 if (this.isThisParam(param) && method.kind === "get") {
3332 this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
3333 } else if (this.isThisParam(param)) {
3334 this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
3335 }
3336 }
3337 }
3338 parsePropertyNamePrefixOperator(node) {
3339 node.variance = this.flowParseVariance();
3340 }
3341 parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
3342 if (prop.variance) {
3343 this.unexpected(prop.variance.loc.start);
3344 }
3345 delete prop.variance;
3346 let typeParameters;
3347 if (this.match(47) && !isAccessor) {
3348 typeParameters = this.flowParseTypeParameterDeclaration();
3349 if (!this.match(10)) this.unexpected();
3350 }
3351 const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
3352 if (typeParameters) {
3353 (result.value || result).typeParameters = typeParameters;
3354 }
3355 return result;
3356 }
3357 parseFunctionParamType(param) {
3358 if (this.eat(17)) {
3359 if (param.type !== "Identifier") {
3360 this.raise(FlowErrors.PatternIsOptional, param);
3361 }
3362 if (this.isThisParam(param)) {
3363 this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
3364 }
3365 param.optional = true;
3366 }
3367 if (this.match(14)) {
3368 param.typeAnnotation = this.flowParseTypeAnnotation();
3369 } else if (this.isThisParam(param)) {
3370 this.raise(FlowErrors.ThisParamAnnotationRequired, param);
3371 }
3372 if (this.match(29) && this.isThisParam(param)) {
3373 this.raise(FlowErrors.ThisParamNoDefault, param);
3374 }
3375 this.resetEndLocation(param);
3376 return param;
3377 }
3378 parseMaybeDefault(startLoc, left) {
3379 const node = super.parseMaybeDefault(startLoc, left);
3380 if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
3381 this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
3382 }
3383 return node;
3384 }
3385 checkImportReflection(node) {
3386 super.checkImportReflection(node);
3387 if (node.module && node.importKind !== "value") {
3388 this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
3389 }
3390 }
3391 parseImportSpecifierLocal(node, specifier, type) {
3392 specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
3393 node.specifiers.push(this.finishImportSpecifier(specifier, type));
3394 }
3395 isPotentialImportPhase(isExport) {
3396 if (super.isPotentialImportPhase(isExport)) return true;
3397 if (this.isContextual(130)) {
3398 if (!isExport) return true;
3399 const ch = this.lookaheadCharCode();
3400 return ch === 123 || ch === 42;
3401 }
3402 return !isExport && this.isContextual(87);
3403 }
3404 applyImportPhase(node, isExport, phase, loc) {
3405 super.applyImportPhase(node, isExport, phase, loc);
3406 if (isExport) {
3407 if (!phase && this.match(65)) {
3408 return;
3409 }
3410 node.exportKind = phase === "type" ? phase : "value";
3411 } else {
3412 if (phase === "type" && this.match(55)) this.unexpected();
3413 node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
3414 }
3415 }
3416 parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
3417 const firstIdent = specifier.imported;
3418 let specifierTypeKind = null;
3419 if (firstIdent.type === "Identifier") {
3420 if (firstIdent.name === "type") {
3421 specifierTypeKind = "type";
3422 } else if (firstIdent.name === "typeof") {
3423 specifierTypeKind = "typeof";
3424 }
3425 }
3426 let isBinding = false;
3427 if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
3428 const as_ident = this.parseIdentifier(true);
3429 if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
3430 specifier.imported = as_ident;
3431 specifier.importKind = specifierTypeKind;
3432 specifier.local = this.cloneIdentifier(as_ident);
3433 } else {
3434 specifier.imported = firstIdent;
3435 specifier.importKind = null;
3436 specifier.local = this.parseIdentifier();
3437 }
3438 } else {
3439 if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
3440 specifier.imported = this.parseIdentifier(true);
3441 specifier.importKind = specifierTypeKind;
3442 } else {
3443 if (importedIsString) {
3444 throw this.raise(Errors.ImportBindingIsString, specifier, {
3445 importName: firstIdent.value
3446 });
3447 }
3448 specifier.imported = firstIdent;
3449 specifier.importKind = null;
3450 }
3451 if (this.eatContextual(93)) {
3452 specifier.local = this.parseIdentifier();
3453 } else {
3454 isBinding = true;
3455 specifier.local = this.cloneIdentifier(specifier.imported);
3456 }
3457 }
3458 const specifierIsTypeImport = hasTypeImportKind(specifier);
3459 if (isInTypeOnlyImport && specifierIsTypeImport) {
3460 this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
3461 }
3462 if (isInTypeOnlyImport || specifierIsTypeImport) {
3463 this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
3464 }
3465 if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
3466 this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
3467 }
3468 return this.finishImportSpecifier(specifier, "ImportSpecifier");
3469 }
3470 parseBindingAtom() {
3471 switch (this.state.type) {
3472 case 78:
3473 return this.parseIdentifier(true);
3474 default:
3475 return super.parseBindingAtom();
3476 }
3477 }
3478 parseFunctionParams(node, isConstructor) {
3479 const kind = node.kind;
3480 if (kind !== "get" && kind !== "set" && this.match(47)) {
3481 node.typeParameters = this.flowParseTypeParameterDeclaration();
3482 }
3483 super.parseFunctionParams(node, isConstructor);
3484 }
3485 parseVarId(decl, kind) {
3486 super.parseVarId(decl, kind);
3487 if (this.match(14)) {
3488 decl.id.typeAnnotation = this.flowParseTypeAnnotation();
3489 this.resetEndLocation(decl.id);
3490 }
3491 }
3492 parseAsyncArrowFromCallExpression(node, call) {
3493 if (this.match(14)) {
3494 const oldNoAnonFunctionType = this.state.noAnonFunctionType;
3495 this.state.noAnonFunctionType = true;
3496 node.returnType = this.flowParseTypeAnnotation();
3497 this.state.noAnonFunctionType = oldNoAnonFunctionType;
3498 }
3499 return super.parseAsyncArrowFromCallExpression(node, call);
3500 }
3501 shouldParseAsyncArrow() {
3502 return this.match(14) || super.shouldParseAsyncArrow();
3503 }
3504 parseMaybeAssign(refExpressionErrors, afterLeftParse) {
3505 var _jsx;
3506 let state = null;
3507 let jsx;
3508 if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
3509 state = this.state.clone();
3510 jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
3511 if (!jsx.error) return jsx.node;
3512 const {
3513 context
3514 } = this.state;
3515 const currentContext = context[context.length - 1];
3516 if (currentContext === types.j_oTag || currentContext === types.j_expr) {
3517 context.pop();
3518 }
3519 }
3520 if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
3521 var _jsx2, _jsx3;
3522 state = state || this.state.clone();
3523 let typeParameters;
3524 const arrow = this.tryParse(abort => {
3525 var _arrowExpression$extr;
3526 typeParameters = this.flowParseTypeParameterDeclaration();
3527 const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
3528 const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
3529 this.resetStartLocationFromNode(result, typeParameters);
3530 return result;
3531 });
3532 if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
3533 const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
3534 if (expr.type !== "ArrowFunctionExpression") abort();
3535 expr.typeParameters = typeParameters;
3536 this.resetStartLocationFromNode(expr, typeParameters);
3537 return arrowExpression;
3538 }, state);
3539 let arrowExpression = null;
3540 if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
3541 if (!arrow.error && !arrow.aborted) {
3542 if (arrow.node.async) {
3543 this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
3544 }
3545 return arrow.node;
3546 }
3547 arrowExpression = arrow.node;
3548 }
3549 if ((_jsx2 = jsx) != null && _jsx2.node) {
3550 this.state = jsx.failState;
3551 return jsx.node;
3552 }
3553 if (arrowExpression) {
3554 this.state = arrow.failState;
3555 return arrowExpression;
3556 }
3557 if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
3558 if (arrow.thrown) throw arrow.error;
3559 throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
3560 }
3561 return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
3562 }
3563 parseArrow(node) {
3564 if (this.match(14)) {
3565 const result = this.tryParse(() => {
3566 const oldNoAnonFunctionType = this.state.noAnonFunctionType;
3567 this.state.noAnonFunctionType = true;
3568 const typeNode = this.startNode();
3569 [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
3570 this.state.noAnonFunctionType = oldNoAnonFunctionType;
3571 if (this.canInsertSemicolon()) this.unexpected();
3572 if (!this.match(19)) this.unexpected();
3573 return typeNode;
3574 });
3575 if (result.thrown) return null;
3576 if (result.error) this.state = result.failState;
3577 node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
3578 }
3579 return super.parseArrow(node);
3580 }
3581 shouldParseArrow(params) {
3582 return this.match(14) || super.shouldParseArrow(params);
3583 }
3584 setArrowFunctionParameters(node, params) {
3585 if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
3586 node.params = params;
3587 } else {
3588 super.setArrowFunctionParameters(node, params);
3589 }
3590 }
3591 checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
3592 if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
3593 return;
3594 }
3595 for (let i = 0; i < node.params.length; i++) {
3596 if (this.isThisParam(node.params[i]) && i > 0) {
3597 this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
3598 }
3599 }
3600 super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
3601 }
3602 parseParenAndDistinguishExpression(canBeArrow) {
3603 return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
3604 }
3605 parseSubscripts(base, startLoc, noCalls) {
3606 if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
3607 this.next();
3608 const node = this.startNodeAt(startLoc);
3609 node.callee = base;
3610 node.arguments = super.parseCallExpressionArguments();
3611 base = this.finishNode(node, "CallExpression");
3612 } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
3613 const state = this.state.clone();
3614 const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
3615 if (!arrow.error && !arrow.aborted) return arrow.node;
3616 const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
3617 if (result.node && !result.error) return result.node;
3618 if (arrow.node) {
3619 this.state = arrow.failState;
3620 return arrow.node;
3621 }
3622 if (result.node) {
3623 this.state = result.failState;
3624 return result.node;
3625 }
3626 throw arrow.error || result.error;
3627 }
3628 return super.parseSubscripts(base, startLoc, noCalls);
3629 }
3630 parseSubscript(base, startLoc, noCalls, subscriptState) {
3631 if (this.match(18) && this.isLookaheadToken_lt()) {
3632 subscriptState.optionalChainMember = true;
3633 if (noCalls) {
3634 subscriptState.stop = true;
3635 return base;
3636 }
3637 this.next();
3638 const node = this.startNodeAt(startLoc);
3639 node.callee = base;
3640 node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
3641 this.expect(10);
3642 node.arguments = this.parseCallExpressionArguments();
3643 node.optional = true;
3644 return this.finishCallExpression(node, true);
3645 } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
3646 const node = this.startNodeAt(startLoc);
3647 node.callee = base;
3648 const result = this.tryParse(() => {
3649 node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
3650 this.expect(10);
3651 node.arguments = super.parseCallExpressionArguments();
3652 if (subscriptState.optionalChainMember) {
3653 node.optional = false;
3654 }
3655 return this.finishCallExpression(node, subscriptState.optionalChainMember);
3656 });
3657 if (result.node) {
3658 if (result.error) this.state = result.failState;
3659 return result.node;
3660 }
3661 }
3662 return super.parseSubscript(base, startLoc, noCalls, subscriptState);
3663 }
3664 parseNewCallee(node) {
3665 super.parseNewCallee(node);
3666 let targs = null;
3667 if (this.shouldParseTypes() && this.match(47)) {
3668 targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
3669 }
3670 node.typeArguments = targs;
3671 }
3672 parseAsyncArrowWithTypeParameters(startLoc) {
3673 const node = this.startNodeAt(startLoc);
3674 this.parseFunctionParams(node, false);
3675 if (!this.parseArrow(node)) return;
3676 return super.parseArrowExpression(node, undefined, true);
3677 }
3678 readToken_mult_modulo(code) {
3679 const next = this.input.charCodeAt(this.state.pos + 1);
3680 if (code === 42 && next === 47 && this.state.hasFlowComment) {
3681 this.state.hasFlowComment = false;
3682 this.state.pos += 2;
3683 this.nextToken();
3684 return;
3685 }
3686 super.readToken_mult_modulo(code);
3687 }
3688 readToken_pipe_amp(code) {
3689 const next = this.input.charCodeAt(this.state.pos + 1);
3690 if (code === 124 && next === 125) {
3691 this.finishOp(9, 2);
3692 return;
3693 }
3694 super.readToken_pipe_amp(code);
3695 }
3696 parseTopLevel(file, program) {
3697 const fileNode = super.parseTopLevel(file, program);
3698 if (this.state.hasFlowComment) {
3699 this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
3700 }
3701 return fileNode;
3702 }
3703 skipBlockComment() {
3704 if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
3705 if (this.state.hasFlowComment) {
3706 throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
3707 }
3708 this.hasFlowCommentCompletion();
3709 const commentSkip = this.skipFlowComment();
3710 if (commentSkip) {
3711 this.state.pos += commentSkip;
3712 this.state.hasFlowComment = true;
3713 }
3714 return;
3715 }
3716 return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
3717 }
3718 skipFlowComment() {
3719 const {
3720 pos
3721 } = this.state;
3722 let shiftToFirstNonWhiteSpace = 2;
3723 while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
3724 shiftToFirstNonWhiteSpace++;
3725 }
3726 const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
3727 const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
3728 if (ch2 === 58 && ch3 === 58) {
3729 return shiftToFirstNonWhiteSpace + 2;
3730 }
3731 if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
3732 return shiftToFirstNonWhiteSpace + 12;
3733 }
3734 if (ch2 === 58 && ch3 !== 58) {
3735 return shiftToFirstNonWhiteSpace;
3736 }
3737 return false;
3738 }
3739 hasFlowCommentCompletion() {
3740 const end = this.input.indexOf("*/", this.state.pos);
3741 if (end === -1) {
3742 throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
3743 }
3744 }
3745 flowEnumErrorBooleanMemberNotInitialized(loc, {
3746 enumName,
3747 memberName
3748 }) {
3749 this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
3750 memberName,
3751 enumName
3752 });
3753 }
3754 flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
3755 return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
3756 }
3757 flowEnumErrorNumberMemberNotInitialized(loc, details) {
3758 this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
3759 }
3760 flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
3761 this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
3762 }
3763 flowEnumMemberInit() {
3764 const startLoc = this.state.startLoc;
3765 const endOfInit = () => this.match(12) || this.match(8);
3766 switch (this.state.type) {
3767 case 135:
3768 {
3769 const literal = this.parseNumericLiteral(this.state.value);
3770 if (endOfInit()) {
3771 return {
3772 type: "number",
3773 loc: literal.loc.start,
3774 value: literal
3775 };
3776 }
3777 return {
3778 type: "invalid",
3779 loc: startLoc
3780 };
3781 }
3782 case 134:
3783 {
3784 const literal = this.parseStringLiteral(this.state.value);
3785 if (endOfInit()) {
3786 return {
3787 type: "string",
3788 loc: literal.loc.start,
3789 value: literal
3790 };
3791 }
3792 return {
3793 type: "invalid",
3794 loc: startLoc
3795 };
3796 }
3797 case 85:
3798 case 86:
3799 {
3800 const literal = this.parseBooleanLiteral(this.match(85));
3801 if (endOfInit()) {
3802 return {
3803 type: "boolean",
3804 loc: literal.loc.start,
3805 value: literal
3806 };
3807 }
3808 return {
3809 type: "invalid",
3810 loc: startLoc
3811 };
3812 }
3813 default:
3814 return {
3815 type: "invalid",
3816 loc: startLoc
3817 };
3818 }
3819 }
3820 flowEnumMemberRaw() {
3821 const loc = this.state.startLoc;
3822 const id = this.parseIdentifier(true);
3823 const init = this.eat(29) ? this.flowEnumMemberInit() : {
3824 type: "none",
3825 loc
3826 };
3827 return {
3828 id,
3829 init
3830 };
3831 }
3832 flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
3833 const {
3834 explicitType
3835 } = context;
3836 if (explicitType === null) {
3837 return;
3838 }
3839 if (explicitType !== expectedType) {
3840 this.flowEnumErrorInvalidMemberInitializer(loc, context);
3841 }
3842 }
3843 flowEnumMembers({
3844 enumName,
3845 explicitType
3846 }) {
3847 const seenNames = new Set();
3848 const members = {
3849 booleanMembers: [],
3850 numberMembers: [],
3851 stringMembers: [],
3852 defaultedMembers: []
3853 };
3854 let hasUnknownMembers = false;
3855 while (!this.match(8)) {
3856 if (this.eat(21)) {
3857 hasUnknownMembers = true;
3858 break;
3859 }
3860 const memberNode = this.startNode();
3861 const {
3862 id,
3863 init
3864 } = this.flowEnumMemberRaw();
3865 const memberName = id.name;
3866 if (memberName === "") {
3867 continue;
3868 }
3869 if (/^[a-z]/.test(memberName)) {
3870 this.raise(FlowErrors.EnumInvalidMemberName, id, {
3871 memberName,
3872 suggestion: memberName[0].toUpperCase() + memberName.slice(1),
3873 enumName
3874 });
3875 }
3876 if (seenNames.has(memberName)) {
3877 this.raise(FlowErrors.EnumDuplicateMemberName, id, {
3878 memberName,
3879 enumName
3880 });
3881 }
3882 seenNames.add(memberName);
3883 const context = {
3884 enumName,
3885 explicitType,
3886 memberName
3887 };
3888 memberNode.id = id;
3889 switch (init.type) {
3890 case "boolean":
3891 {
3892 this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
3893 memberNode.init = init.value;
3894 members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
3895 break;
3896 }
3897 case "number":
3898 {
3899 this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
3900 memberNode.init = init.value;
3901 members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
3902 break;
3903 }
3904 case "string":
3905 {
3906 this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
3907 memberNode.init = init.value;
3908 members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
3909 break;
3910 }
3911 case "invalid":
3912 {
3913 throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
3914 }
3915 case "none":
3916 {
3917 switch (explicitType) {
3918 case "boolean":
3919 this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
3920 break;
3921 case "number":
3922 this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
3923 break;
3924 default:
3925 members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
3926 }
3927 }
3928 }
3929 if (!this.match(8)) {
3930 this.expect(12);
3931 }
3932 }
3933 return {
3934 members,
3935 hasUnknownMembers
3936 };
3937 }
3938 flowEnumStringMembers(initializedMembers, defaultedMembers, {
3939 enumName
3940 }) {
3941 if (initializedMembers.length === 0) {
3942 return defaultedMembers;
3943 } else if (defaultedMembers.length === 0) {
3944 return initializedMembers;
3945 } else if (defaultedMembers.length > initializedMembers.length) {
3946 for (const member of initializedMembers) {
3947 this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
3948 enumName
3949 });
3950 }
3951 return defaultedMembers;
3952 } else {
3953 for (const member of defaultedMembers) {
3954 this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
3955 enumName
3956 });
3957 }
3958 return initializedMembers;
3959 }
3960 }
3961 flowEnumParseExplicitType({
3962 enumName
3963 }) {
3964 if (!this.eatContextual(102)) return null;
3965 if (!tokenIsIdentifier(this.state.type)) {
3966 throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
3967 enumName
3968 });
3969 }
3970 const {
3971 value
3972 } = this.state;
3973 this.next();
3974 if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
3975 this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
3976 enumName,
3977 invalidEnumType: value
3978 });
3979 }
3980 return value;
3981 }
3982 flowEnumBody(node, id) {
3983 const enumName = id.name;
3984 const nameLoc = id.loc.start;
3985 const explicitType = this.flowEnumParseExplicitType({
3986 enumName
3987 });
3988 this.expect(5);
3989 const {
3990 members,
3991 hasUnknownMembers
3992 } = this.flowEnumMembers({
3993 enumName,
3994 explicitType
3995 });
3996 node.hasUnknownMembers = hasUnknownMembers;
3997 switch (explicitType) {
3998 case "boolean":
3999 node.explicitType = true;
4000 node.members = members.booleanMembers;
4001 this.expect(8);
4002 return this.finishNode(node, "EnumBooleanBody");
4003 case "number":
4004 node.explicitType = true;
4005 node.members = members.numberMembers;
4006 this.expect(8);
4007 return this.finishNode(node, "EnumNumberBody");
4008 case "string":
4009 node.explicitType = true;
4010 node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
4011 enumName
4012 });
4013 this.expect(8);
4014 return this.finishNode(node, "EnumStringBody");
4015 case "symbol":
4016 node.members = members.defaultedMembers;
4017 this.expect(8);
4018 return this.finishNode(node, "EnumSymbolBody");
4019 default:
4020 {
4021 const empty = () => {
4022 node.members = [];
4023 this.expect(8);
4024 return this.finishNode(node, "EnumStringBody");
4025 };
4026 node.explicitType = false;
4027 const boolsLen = members.booleanMembers.length;
4028 const numsLen = members.numberMembers.length;
4029 const strsLen = members.stringMembers.length;
4030 const defaultedLen = members.defaultedMembers.length;
4031 if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
4032 return empty();
4033 } else if (!boolsLen && !numsLen) {
4034 node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
4035 enumName
4036 });
4037 this.expect(8);
4038 return this.finishNode(node, "EnumStringBody");
4039 } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
4040 for (const member of members.defaultedMembers) {
4041 this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
4042 enumName,
4043 memberName: member.id.name
4044 });
4045 }
4046 node.members = members.booleanMembers;
4047 this.expect(8);
4048 return this.finishNode(node, "EnumBooleanBody");
4049 } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
4050 for (const member of members.defaultedMembers) {
4051 this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
4052 enumName,
4053 memberName: member.id.name
4054 });
4055 }
4056 node.members = members.numberMembers;
4057 this.expect(8);
4058 return this.finishNode(node, "EnumNumberBody");
4059 } else {
4060 this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
4061 enumName
4062 });
4063 return empty();
4064 }
4065 }
4066 }
4067 }
4068 flowParseEnumDeclaration(node) {
4069 const id = this.parseIdentifier();
4070 node.id = id;
4071 node.body = this.flowEnumBody(this.startNode(), id);
4072 return this.finishNode(node, "EnumDeclaration");
4073 }
4074 jsxParseOpeningElementAfterName(node) {
4075 if (this.shouldParseTypes()) {
4076 if (this.match(47) || this.match(51)) {
4077 node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
4078 }
4079 }
4080 return super.jsxParseOpeningElementAfterName(node);
4081 }
4082 isLookaheadToken_lt() {
4083 const next = this.nextTokenStart();
4084 if (this.input.charCodeAt(next) === 60) {
4085 const afterNext = this.input.charCodeAt(next + 1);
4086 return afterNext !== 60 && afterNext !== 61;
4087 }
4088 return false;
4089 }
4090 reScan_lt_gt() {
4091 const {
4092 type
4093 } = this.state;
4094 if (type === 47) {
4095 this.state.pos -= 1;
4096 this.readToken_lt();
4097 } else if (type === 48) {
4098 this.state.pos -= 1;
4099 this.readToken_gt();
4100 }
4101 }
4102 reScan_lt() {
4103 const {
4104 type
4105 } = this.state;
4106 if (type === 51) {
4107 this.state.pos -= 2;
4108 this.finishOp(47, 1);
4109 return 47;
4110 }
4111 return type;
4112 }
4113 maybeUnwrapTypeCastExpression(node) {
4114 return node.type === "TypeCastExpression" ? node.expression : node;
4115 }
4116};
4117const entities = {
4118 __proto__: null,
4119 quot: "\u0022",
4120 amp: "&",
4121 apos: "\u0027",
4122 lt: "<",
4123 gt: ">",
4124 nbsp: "\u00A0",
4125 iexcl: "\u00A1",
4126 cent: "\u00A2",
4127 pound: "\u00A3",
4128 curren: "\u00A4",
4129 yen: "\u00A5",
4130 brvbar: "\u00A6",
4131 sect: "\u00A7",
4132 uml: "\u00A8",
4133 copy: "\u00A9",
4134 ordf: "\u00AA",
4135 laquo: "\u00AB",
4136 not: "\u00AC",
4137 shy: "\u00AD",
4138 reg: "\u00AE",
4139 macr: "\u00AF",
4140 deg: "\u00B0",
4141 plusmn: "\u00B1",
4142 sup2: "\u00B2",
4143 sup3: "\u00B3",
4144 acute: "\u00B4",
4145 micro: "\u00B5",
4146 para: "\u00B6",
4147 middot: "\u00B7",
4148 cedil: "\u00B8",
4149 sup1: "\u00B9",
4150 ordm: "\u00BA",
4151 raquo: "\u00BB",
4152 frac14: "\u00BC",
4153 frac12: "\u00BD",
4154 frac34: "\u00BE",
4155 iquest: "\u00BF",
4156 Agrave: "\u00C0",
4157 Aacute: "\u00C1",
4158 Acirc: "\u00C2",
4159 Atilde: "\u00C3",
4160 Auml: "\u00C4",
4161 Aring: "\u00C5",
4162 AElig: "\u00C6",
4163 Ccedil: "\u00C7",
4164 Egrave: "\u00C8",
4165 Eacute: "\u00C9",
4166 Ecirc: "\u00CA",
4167 Euml: "\u00CB",
4168 Igrave: "\u00CC",
4169 Iacute: "\u00CD",
4170 Icirc: "\u00CE",
4171 Iuml: "\u00CF",
4172 ETH: "\u00D0",
4173 Ntilde: "\u00D1",
4174 Ograve: "\u00D2",
4175 Oacute: "\u00D3",
4176 Ocirc: "\u00D4",
4177 Otilde: "\u00D5",
4178 Ouml: "\u00D6",
4179 times: "\u00D7",
4180 Oslash: "\u00D8",
4181 Ugrave: "\u00D9",
4182 Uacute: "\u00DA",
4183 Ucirc: "\u00DB",
4184 Uuml: "\u00DC",
4185 Yacute: "\u00DD",
4186 THORN: "\u00DE",
4187 szlig: "\u00DF",
4188 agrave: "\u00E0",
4189 aacute: "\u00E1",
4190 acirc: "\u00E2",
4191 atilde: "\u00E3",
4192 auml: "\u00E4",
4193 aring: "\u00E5",
4194 aelig: "\u00E6",
4195 ccedil: "\u00E7",
4196 egrave: "\u00E8",
4197 eacute: "\u00E9",
4198 ecirc: "\u00EA",
4199 euml: "\u00EB",
4200 igrave: "\u00EC",
4201 iacute: "\u00ED",
4202 icirc: "\u00EE",
4203 iuml: "\u00EF",
4204 eth: "\u00F0",
4205 ntilde: "\u00F1",
4206 ograve: "\u00F2",
4207 oacute: "\u00F3",
4208 ocirc: "\u00F4",
4209 otilde: "\u00F5",
4210 ouml: "\u00F6",
4211 divide: "\u00F7",
4212 oslash: "\u00F8",
4213 ugrave: "\u00F9",
4214 uacute: "\u00FA",
4215 ucirc: "\u00FB",
4216 uuml: "\u00FC",
4217 yacute: "\u00FD",
4218 thorn: "\u00FE",
4219 yuml: "\u00FF",
4220 OElig: "\u0152",
4221 oelig: "\u0153",
4222 Scaron: "\u0160",
4223 scaron: "\u0161",
4224 Yuml: "\u0178",
4225 fnof: "\u0192",
4226 circ: "\u02C6",
4227 tilde: "\u02DC",
4228 Alpha: "\u0391",
4229 Beta: "\u0392",
4230 Gamma: "\u0393",
4231 Delta: "\u0394",
4232 Epsilon: "\u0395",
4233 Zeta: "\u0396",
4234 Eta: "\u0397",
4235 Theta: "\u0398",
4236 Iota: "\u0399",
4237 Kappa: "\u039A",
4238 Lambda: "\u039B",
4239 Mu: "\u039C",
4240 Nu: "\u039D",
4241 Xi: "\u039E",
4242 Omicron: "\u039F",
4243 Pi: "\u03A0",
4244 Rho: "\u03A1",
4245 Sigma: "\u03A3",
4246 Tau: "\u03A4",
4247 Upsilon: "\u03A5",
4248 Phi: "\u03A6",
4249 Chi: "\u03A7",
4250 Psi: "\u03A8",
4251 Omega: "\u03A9",
4252 alpha: "\u03B1",
4253 beta: "\u03B2",
4254 gamma: "\u03B3",
4255 delta: "\u03B4",
4256 epsilon: "\u03B5",
4257 zeta: "\u03B6",
4258 eta: "\u03B7",
4259 theta: "\u03B8",
4260 iota: "\u03B9",
4261 kappa: "\u03BA",
4262 lambda: "\u03BB",
4263 mu: "\u03BC",
4264 nu: "\u03BD",
4265 xi: "\u03BE",
4266 omicron: "\u03BF",
4267 pi: "\u03C0",
4268 rho: "\u03C1",
4269 sigmaf: "\u03C2",
4270 sigma: "\u03C3",
4271 tau: "\u03C4",
4272 upsilon: "\u03C5",
4273 phi: "\u03C6",
4274 chi: "\u03C7",
4275 psi: "\u03C8",
4276 omega: "\u03C9",
4277 thetasym: "\u03D1",
4278 upsih: "\u03D2",
4279 piv: "\u03D6",
4280 ensp: "\u2002",
4281 emsp: "\u2003",
4282 thinsp: "\u2009",
4283 zwnj: "\u200C",
4284 zwj: "\u200D",
4285 lrm: "\u200E",
4286 rlm: "\u200F",
4287 ndash: "\u2013",
4288 mdash: "\u2014",
4289 lsquo: "\u2018",
4290 rsquo: "\u2019",
4291 sbquo: "\u201A",
4292 ldquo: "\u201C",
4293 rdquo: "\u201D",
4294 bdquo: "\u201E",
4295 dagger: "\u2020",
4296 Dagger: "\u2021",
4297 bull: "\u2022",
4298 hellip: "\u2026",
4299 permil: "\u2030",
4300 prime: "\u2032",
4301 Prime: "\u2033",
4302 lsaquo: "\u2039",
4303 rsaquo: "\u203A",
4304 oline: "\u203E",
4305 frasl: "\u2044",
4306 euro: "\u20AC",
4307 image: "\u2111",
4308 weierp: "\u2118",
4309 real: "\u211C",
4310 trade: "\u2122",
4311 alefsym: "\u2135",
4312 larr: "\u2190",
4313 uarr: "\u2191",
4314 rarr: "\u2192",
4315 darr: "\u2193",
4316 harr: "\u2194",
4317 crarr: "\u21B5",
4318 lArr: "\u21D0",
4319 uArr: "\u21D1",
4320 rArr: "\u21D2",
4321 dArr: "\u21D3",
4322 hArr: "\u21D4",
4323 forall: "\u2200",
4324 part: "\u2202",
4325 exist: "\u2203",
4326 empty: "\u2205",
4327 nabla: "\u2207",
4328 isin: "\u2208",
4329 notin: "\u2209",
4330 ni: "\u220B",
4331 prod: "\u220F",
4332 sum: "\u2211",
4333 minus: "\u2212",
4334 lowast: "\u2217",
4335 radic: "\u221A",
4336 prop: "\u221D",
4337 infin: "\u221E",
4338 ang: "\u2220",
4339 and: "\u2227",
4340 or: "\u2228",
4341 cap: "\u2229",
4342 cup: "\u222A",
4343 int: "\u222B",
4344 there4: "\u2234",
4345 sim: "\u223C",
4346 cong: "\u2245",
4347 asymp: "\u2248",
4348 ne: "\u2260",
4349 equiv: "\u2261",
4350 le: "\u2264",
4351 ge: "\u2265",
4352 sub: "\u2282",
4353 sup: "\u2283",
4354 nsub: "\u2284",
4355 sube: "\u2286",
4356 supe: "\u2287",
4357 oplus: "\u2295",
4358 otimes: "\u2297",
4359 perp: "\u22A5",
4360 sdot: "\u22C5",
4361 lceil: "\u2308",
4362 rceil: "\u2309",
4363 lfloor: "\u230A",
4364 rfloor: "\u230B",
4365 lang: "\u2329",
4366 rang: "\u232A",
4367 loz: "\u25CA",
4368 spades: "\u2660",
4369 clubs: "\u2663",
4370 hearts: "\u2665",
4371 diams: "\u2666"
4372};
4373const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
4374const lineBreakG = new RegExp(lineBreak.source, "g");
4375function isNewLine(code) {
4376 switch (code) {
4377 case 10:
4378 case 13:
4379 case 8232:
4380 case 8233:
4381 return true;
4382 default:
4383 return false;
4384 }
4385}
4386function hasNewLine(input, start, end) {
4387 for (let i = start; i < end; i++) {
4388 if (isNewLine(input.charCodeAt(i))) {
4389 return true;
4390 }
4391 }
4392 return false;
4393}
4394const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
4395const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
4396function isWhitespace(code) {
4397 switch (code) {
4398 case 0x0009:
4399 case 0x000b:
4400 case 0x000c:
4401 case 32:
4402 case 160:
4403 case 5760:
4404 case 0x2000:
4405 case 0x2001:
4406 case 0x2002:
4407 case 0x2003:
4408 case 0x2004:
4409 case 0x2005:
4410 case 0x2006:
4411 case 0x2007:
4412 case 0x2008:
4413 case 0x2009:
4414 case 0x200a:
4415 case 0x202f:
4416 case 0x205f:
4417 case 0x3000:
4418 case 0xfeff:
4419 return true;
4420 default:
4421 return false;
4422 }
4423}
4424const JsxErrors = ParseErrorEnum`jsx`({
4425 AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
4426 MissingClosingTagElement: ({
4427 openingTagName
4428 }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
4429 MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
4430 UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
4431 UnexpectedToken: ({
4432 unexpected,
4433 HTMLEntity
4434 }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
4435 UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
4436 UnterminatedJsxContent: "Unterminated JSX contents.",
4437 UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
4438});
4439function isFragment(object) {
4440 return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
4441}
4442function getQualifiedJSXName(object) {
4443 if (object.type === "JSXIdentifier") {
4444 return object.name;
4445 }
4446 if (object.type === "JSXNamespacedName") {
4447 return object.namespace.name + ":" + object.name.name;
4448 }
4449 if (object.type === "JSXMemberExpression") {
4450 return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
4451 }
4452 throw new Error("Node had unexpected type: " + object.type);
4453}
4454var jsx = superClass => class JSXParserMixin extends superClass {
4455 jsxReadToken() {
4456 let out = "";
4457 let chunkStart = this.state.pos;
4458 for (;;) {
4459 if (this.state.pos >= this.length) {
4460 throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
4461 }
4462 const ch = this.input.charCodeAt(this.state.pos);
4463 switch (ch) {
4464 case 60:
4465 case 123:
4466 if (this.state.pos === this.state.start) {
4467 if (ch === 60 && this.state.canStartJSXElement) {
4468 ++this.state.pos;
4469 this.finishToken(143);
4470 } else {
4471 super.getTokenFromCode(ch);
4472 }
4473 return;
4474 }
4475 out += this.input.slice(chunkStart, this.state.pos);
4476 this.finishToken(142, out);
4477 return;
4478 case 38:
4479 out += this.input.slice(chunkStart, this.state.pos);
4480 out += this.jsxReadEntity();
4481 chunkStart = this.state.pos;
4482 break;
4483 case 62:
4484 case 125:
4485 default:
4486 if (isNewLine(ch)) {
4487 out += this.input.slice(chunkStart, this.state.pos);
4488 out += this.jsxReadNewLine(true);
4489 chunkStart = this.state.pos;
4490 } else {
4491 ++this.state.pos;
4492 }
4493 }
4494 }
4495 }
4496 jsxReadNewLine(normalizeCRLF) {
4497 const ch = this.input.charCodeAt(this.state.pos);
4498 let out;
4499 ++this.state.pos;
4500 if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
4501 ++this.state.pos;
4502 out = normalizeCRLF ? "\n" : "\r\n";
4503 } else {
4504 out = String.fromCharCode(ch);
4505 }
4506 ++this.state.curLine;
4507 this.state.lineStart = this.state.pos;
4508 return out;
4509 }
4510 jsxReadString(quote) {
4511 let out = "";
4512 let chunkStart = ++this.state.pos;
4513 for (;;) {
4514 if (this.state.pos >= this.length) {
4515 throw this.raise(Errors.UnterminatedString, this.state.startLoc);
4516 }
4517 const ch = this.input.charCodeAt(this.state.pos);
4518 if (ch === quote) break;
4519 if (ch === 38) {
4520 out += this.input.slice(chunkStart, this.state.pos);
4521 out += this.jsxReadEntity();
4522 chunkStart = this.state.pos;
4523 } else if (isNewLine(ch)) {
4524 out += this.input.slice(chunkStart, this.state.pos);
4525 out += this.jsxReadNewLine(false);
4526 chunkStart = this.state.pos;
4527 } else {
4528 ++this.state.pos;
4529 }
4530 }
4531 out += this.input.slice(chunkStart, this.state.pos++);
4532 this.finishToken(134, out);
4533 }
4534 jsxReadEntity() {
4535 const startPos = ++this.state.pos;
4536 if (this.codePointAtPos(this.state.pos) === 35) {
4537 ++this.state.pos;
4538 let radix = 10;
4539 if (this.codePointAtPos(this.state.pos) === 120) {
4540 radix = 16;
4541 ++this.state.pos;
4542 }
4543 const codePoint = this.readInt(radix, undefined, false, "bail");
4544 if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
4545 ++this.state.pos;
4546 return String.fromCodePoint(codePoint);
4547 }
4548 } else {
4549 let count = 0;
4550 let semi = false;
4551 while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
4552 ++this.state.pos;
4553 }
4554 if (semi) {
4555 const desc = this.input.slice(startPos, this.state.pos);
4556 const entity = entities[desc];
4557 ++this.state.pos;
4558 if (entity) {
4559 return entity;
4560 }
4561 }
4562 }
4563 this.state.pos = startPos;
4564 return "&";
4565 }
4566 jsxReadWord() {
4567 let ch;
4568 const start = this.state.pos;
4569 do {
4570 ch = this.input.charCodeAt(++this.state.pos);
4571 } while (isIdentifierChar(ch) || ch === 45);
4572 this.finishToken(141, this.input.slice(start, this.state.pos));
4573 }
4574 jsxParseIdentifier() {
4575 const node = this.startNode();
4576 if (this.match(141)) {
4577 node.name = this.state.value;
4578 } else if (tokenIsKeyword(this.state.type)) {
4579 node.name = tokenLabelName(this.state.type);
4580 } else {
4581 this.unexpected();
4582 }
4583 this.next();
4584 return this.finishNode(node, "JSXIdentifier");
4585 }
4586 jsxParseNamespacedName() {
4587 const startLoc = this.state.startLoc;
4588 const name = this.jsxParseIdentifier();
4589 if (!this.eat(14)) return name;
4590 const node = this.startNodeAt(startLoc);
4591 node.namespace = name;
4592 node.name = this.jsxParseIdentifier();
4593 return this.finishNode(node, "JSXNamespacedName");
4594 }
4595 jsxParseElementName() {
4596 const startLoc = this.state.startLoc;
4597 let node = this.jsxParseNamespacedName();
4598 if (node.type === "JSXNamespacedName") {
4599 return node;
4600 }
4601 while (this.eat(16)) {
4602 const newNode = this.startNodeAt(startLoc);
4603 newNode.object = node;
4604 newNode.property = this.jsxParseIdentifier();
4605 node = this.finishNode(newNode, "JSXMemberExpression");
4606 }
4607 return node;
4608 }
4609 jsxParseAttributeValue() {
4610 let node;
4611 switch (this.state.type) {
4612 case 5:
4613 node = this.startNode();
4614 this.setContext(types.brace);
4615 this.next();
4616 node = this.jsxParseExpressionContainer(node, types.j_oTag);
4617 if (node.expression.type === "JSXEmptyExpression") {
4618 this.raise(JsxErrors.AttributeIsEmpty, node);
4619 }
4620 return node;
4621 case 143:
4622 case 134:
4623 return this.parseExprAtom();
4624 default:
4625 throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
4626 }
4627 }
4628 jsxParseEmptyExpression() {
4629 const node = this.startNodeAt(this.state.lastTokEndLoc);
4630 return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
4631 }
4632 jsxParseSpreadChild(node) {
4633 this.next();
4634 node.expression = this.parseExpression();
4635 this.setContext(types.j_expr);
4636 this.state.canStartJSXElement = true;
4637 this.expect(8);
4638 return this.finishNode(node, "JSXSpreadChild");
4639 }
4640 jsxParseExpressionContainer(node, previousContext) {
4641 if (this.match(8)) {
4642 node.expression = this.jsxParseEmptyExpression();
4643 } else {
4644 const expression = this.parseExpression();
4645 node.expression = expression;
4646 }
4647 this.setContext(previousContext);
4648 this.state.canStartJSXElement = true;
4649 this.expect(8);
4650 return this.finishNode(node, "JSXExpressionContainer");
4651 }
4652 jsxParseAttribute() {
4653 const node = this.startNode();
4654 if (this.match(5)) {
4655 this.setContext(types.brace);
4656 this.next();
4657 this.expect(21);
4658 node.argument = this.parseMaybeAssignAllowIn();
4659 this.setContext(types.j_oTag);
4660 this.state.canStartJSXElement = true;
4661 this.expect(8);
4662 return this.finishNode(node, "JSXSpreadAttribute");
4663 }
4664 node.name = this.jsxParseNamespacedName();
4665 node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
4666 return this.finishNode(node, "JSXAttribute");
4667 }
4668 jsxParseOpeningElementAt(startLoc) {
4669 const node = this.startNodeAt(startLoc);
4670 if (this.eat(144)) {
4671 return this.finishNode(node, "JSXOpeningFragment");
4672 }
4673 node.name = this.jsxParseElementName();
4674 return this.jsxParseOpeningElementAfterName(node);
4675 }
4676 jsxParseOpeningElementAfterName(node) {
4677 const attributes = [];
4678 while (!this.match(56) && !this.match(144)) {
4679 attributes.push(this.jsxParseAttribute());
4680 }
4681 node.attributes = attributes;
4682 node.selfClosing = this.eat(56);
4683 this.expect(144);
4684 return this.finishNode(node, "JSXOpeningElement");
4685 }
4686 jsxParseClosingElementAt(startLoc) {
4687 const node = this.startNodeAt(startLoc);
4688 if (this.eat(144)) {
4689 return this.finishNode(node, "JSXClosingFragment");
4690 }
4691 node.name = this.jsxParseElementName();
4692 this.expect(144);
4693 return this.finishNode(node, "JSXClosingElement");
4694 }
4695 jsxParseElementAt(startLoc) {
4696 const node = this.startNodeAt(startLoc);
4697 const children = [];
4698 const openingElement = this.jsxParseOpeningElementAt(startLoc);
4699 let closingElement = null;
4700 if (!openingElement.selfClosing) {
4701 contents: for (;;) {
4702 switch (this.state.type) {
4703 case 143:
4704 startLoc = this.state.startLoc;
4705 this.next();
4706 if (this.eat(56)) {
4707 closingElement = this.jsxParseClosingElementAt(startLoc);
4708 break contents;
4709 }
4710 children.push(this.jsxParseElementAt(startLoc));
4711 break;
4712 case 142:
4713 children.push(this.parseLiteral(this.state.value, "JSXText"));
4714 break;
4715 case 5:
4716 {
4717 const node = this.startNode();
4718 this.setContext(types.brace);
4719 this.next();
4720 if (this.match(21)) {
4721 children.push(this.jsxParseSpreadChild(node));
4722 } else {
4723 children.push(this.jsxParseExpressionContainer(node, types.j_expr));
4724 }
4725 break;
4726 }
4727 default:
4728 this.unexpected();
4729 }
4730 }
4731 if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
4732 this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
4733 } else if (!isFragment(openingElement) && isFragment(closingElement)) {
4734 this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
4735 openingTagName: getQualifiedJSXName(openingElement.name)
4736 });
4737 } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
4738 if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
4739 this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
4740 openingTagName: getQualifiedJSXName(openingElement.name)
4741 });
4742 }
4743 }
4744 }
4745 if (isFragment(openingElement)) {
4746 node.openingFragment = openingElement;
4747 node.closingFragment = closingElement;
4748 } else {
4749 node.openingElement = openingElement;
4750 node.closingElement = closingElement;
4751 }
4752 node.children = children;
4753 if (this.match(47)) {
4754 throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
4755 }
4756 return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
4757 }
4758 jsxParseElement() {
4759 const startLoc = this.state.startLoc;
4760 this.next();
4761 return this.jsxParseElementAt(startLoc);
4762 }
4763 setContext(newContext) {
4764 const {
4765 context
4766 } = this.state;
4767 context[context.length - 1] = newContext;
4768 }
4769 parseExprAtom(refExpressionErrors) {
4770 if (this.match(143)) {
4771 return this.jsxParseElement();
4772 } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
4773 this.replaceToken(143);
4774 return this.jsxParseElement();
4775 } else {
4776 return super.parseExprAtom(refExpressionErrors);
4777 }
4778 }
4779 skipSpace() {
4780 const curContext = this.curContext();
4781 if (!curContext.preserveSpace) super.skipSpace();
4782 }
4783 getTokenFromCode(code) {
4784 const context = this.curContext();
4785 if (context === types.j_expr) {
4786 this.jsxReadToken();
4787 return;
4788 }
4789 if (context === types.j_oTag || context === types.j_cTag) {
4790 if (isIdentifierStart(code)) {
4791 this.jsxReadWord();
4792 return;
4793 }
4794 if (code === 62) {
4795 ++this.state.pos;
4796 this.finishToken(144);
4797 return;
4798 }
4799 if ((code === 34 || code === 39) && context === types.j_oTag) {
4800 this.jsxReadString(code);
4801 return;
4802 }
4803 }
4804 if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
4805 ++this.state.pos;
4806 this.finishToken(143);
4807 return;
4808 }
4809 super.getTokenFromCode(code);
4810 }
4811 updateContext(prevType) {
4812 const {
4813 context,
4814 type
4815 } = this.state;
4816 if (type === 56 && prevType === 143) {
4817 context.splice(-2, 2, types.j_cTag);
4818 this.state.canStartJSXElement = false;
4819 } else if (type === 143) {
4820 context.push(types.j_oTag);
4821 } else if (type === 144) {
4822 const out = context[context.length - 1];
4823 if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
4824 context.pop();
4825 this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
4826 } else {
4827 this.setContext(types.j_expr);
4828 this.state.canStartJSXElement = true;
4829 }
4830 } else {
4831 this.state.canStartJSXElement = tokenComesBeforeExpression(type);
4832 }
4833 }
4834};
4835class TypeScriptScope extends Scope {
4836 constructor(...args) {
4837 super(...args);
4838 this.tsNames = new Map();
4839 }
4840}
4841class TypeScriptScopeHandler extends ScopeHandler {
4842 constructor(...args) {
4843 super(...args);
4844 this.importsStack = [];
4845 }
4846 createScope(flags) {
4847 this.importsStack.push(new Set());
4848 return new TypeScriptScope(flags);
4849 }
4850 enter(flags) {
4851 if (flags === 1024) {
4852 this.importsStack.push(new Set());
4853 }
4854 super.enter(flags);
4855 }
4856 exit() {
4857 const flags = super.exit();
4858 if (flags === 1024) {
4859 this.importsStack.pop();
4860 }
4861 return flags;
4862 }
4863 hasImport(name, allowShadow) {
4864 const len = this.importsStack.length;
4865 if (this.importsStack[len - 1].has(name)) {
4866 return true;
4867 }
4868 if (!allowShadow && len > 1) {
4869 for (let i = 0; i < len - 1; i++) {
4870 if (this.importsStack[i].has(name)) return true;
4871 }
4872 }
4873 return false;
4874 }
4875 declareName(name, bindingType, loc) {
4876 if (bindingType & 4096) {
4877 if (this.hasImport(name, true)) {
4878 this.parser.raise(Errors.VarRedeclaration, loc, {
4879 identifierName: name
4880 });
4881 }
4882 this.importsStack[this.importsStack.length - 1].add(name);
4883 return;
4884 }
4885 const scope = this.currentScope();
4886 let type = scope.tsNames.get(name) || 0;
4887 if (bindingType & 1024) {
4888 this.maybeExportDefined(scope, name);
4889 scope.tsNames.set(name, type | 16);
4890 return;
4891 }
4892 super.declareName(name, bindingType, loc);
4893 if (bindingType & 2) {
4894 if (!(bindingType & 1)) {
4895 this.checkRedeclarationInScope(scope, name, bindingType, loc);
4896 this.maybeExportDefined(scope, name);
4897 }
4898 type = type | 1;
4899 }
4900 if (bindingType & 256) {
4901 type = type | 2;
4902 }
4903 if (bindingType & 512) {
4904 type = type | 4;
4905 }
4906 if (bindingType & 128) {
4907 type = type | 8;
4908 }
4909 if (type) scope.tsNames.set(name, type);
4910 }
4911 isRedeclaredInScope(scope, name, bindingType) {
4912 const type = scope.tsNames.get(name);
4913 if ((type & 2) > 0) {
4914 if (bindingType & 256) {
4915 const isConst = !!(bindingType & 512);
4916 const wasConst = (type & 4) > 0;
4917 return isConst !== wasConst;
4918 }
4919 return true;
4920 }
4921 if (bindingType & 128 && (type & 8) > 0) {
4922 if (scope.names.get(name) & 2) {
4923 return !!(bindingType & 1);
4924 } else {
4925 return false;
4926 }
4927 }
4928 if (bindingType & 2 && (type & 1) > 0) {
4929 return true;
4930 }
4931 return super.isRedeclaredInScope(scope, name, bindingType);
4932 }
4933 checkLocalExport(id) {
4934 const {
4935 name
4936 } = id;
4937 if (this.hasImport(name)) return;
4938 const len = this.scopeStack.length;
4939 for (let i = len - 1; i >= 0; i--) {
4940 const scope = this.scopeStack[i];
4941 const type = scope.tsNames.get(name);
4942 if ((type & 1) > 0 || (type & 16) > 0) {
4943 return;
4944 }
4945 }
4946 super.checkLocalExport(id);
4947 }
4948}
4949class ProductionParameterHandler {
4950 constructor() {
4951 this.stacks = [];
4952 }
4953 enter(flags) {
4954 this.stacks.push(flags);
4955 }
4956 exit() {
4957 this.stacks.pop();
4958 }
4959 currentFlags() {
4960 return this.stacks[this.stacks.length - 1];
4961 }
4962 get hasAwait() {
4963 return (this.currentFlags() & 2) > 0;
4964 }
4965 get hasYield() {
4966 return (this.currentFlags() & 1) > 0;
4967 }
4968 get hasReturn() {
4969 return (this.currentFlags() & 4) > 0;
4970 }
4971 get hasIn() {
4972 return (this.currentFlags() & 8) > 0;
4973 }
4974}
4975function functionFlags(isAsync, isGenerator) {
4976 return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
4977}
4978class BaseParser {
4979 constructor() {
4980 this.sawUnambiguousESM = false;
4981 this.ambiguousScriptDifferentAst = false;
4982 }
4983 sourceToOffsetPos(sourcePos) {
4984 return sourcePos + this.startIndex;
4985 }
4986 offsetToSourcePos(offsetPos) {
4987 return offsetPos - this.startIndex;
4988 }
4989 hasPlugin(pluginConfig) {
4990 if (typeof pluginConfig === "string") {
4991 return this.plugins.has(pluginConfig);
4992 } else {
4993 const [pluginName, pluginOptions] = pluginConfig;
4994 if (!this.hasPlugin(pluginName)) {
4995 return false;
4996 }
4997 const actualOptions = this.plugins.get(pluginName);
4998 for (const key of Object.keys(pluginOptions)) {
4999 if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
5000 return false;
5001 }
5002 }
5003 return true;
5004 }
5005 }
5006 getPluginOption(plugin, name) {
5007 var _this$plugins$get;
5008 return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
5009 }
5010}
5011function setTrailingComments(node, comments) {
5012 if (node.trailingComments === undefined) {
5013 node.trailingComments = comments;
5014 } else {
5015 node.trailingComments.unshift(...comments);
5016 }
5017}
5018function setLeadingComments(node, comments) {
5019 if (node.leadingComments === undefined) {
5020 node.leadingComments = comments;
5021 } else {
5022 node.leadingComments.unshift(...comments);
5023 }
5024}
5025function setInnerComments(node, comments) {
5026 if (node.innerComments === undefined) {
5027 node.innerComments = comments;
5028 } else {
5029 node.innerComments.unshift(...comments);
5030 }
5031}
5032function adjustInnerComments(node, elements, commentWS) {
5033 let lastElement = null;
5034 let i = elements.length;
5035 while (lastElement === null && i > 0) {
5036 lastElement = elements[--i];
5037 }
5038 if (lastElement === null || lastElement.start > commentWS.start) {
5039 setInnerComments(node, commentWS.comments);
5040 } else {
5041 setTrailingComments(lastElement, commentWS.comments);
5042 }
5043}
5044class CommentsParser extends BaseParser {
5045 addComment(comment) {
5046 if (this.filename) comment.loc.filename = this.filename;
5047 const {
5048 commentsLen
5049 } = this.state;
5050 if (this.comments.length !== commentsLen) {
5051 this.comments.length = commentsLen;
5052 }
5053 this.comments.push(comment);
5054 this.state.commentsLen++;
5055 }
5056 processComment(node) {
5057 const {
5058 commentStack
5059 } = this.state;
5060 const commentStackLength = commentStack.length;
5061 if (commentStackLength === 0) return;
5062 let i = commentStackLength - 1;
5063 const lastCommentWS = commentStack[i];
5064 if (lastCommentWS.start === node.end) {
5065 lastCommentWS.leadingNode = node;
5066 i--;
5067 }
5068 const {
5069 start: nodeStart
5070 } = node;
5071 for (; i >= 0; i--) {
5072 const commentWS = commentStack[i];
5073 const commentEnd = commentWS.end;
5074 if (commentEnd > nodeStart) {
5075 commentWS.containingNode = node;
5076 this.finalizeComment(commentWS);
5077 commentStack.splice(i, 1);
5078 } else {
5079 if (commentEnd === nodeStart) {
5080 commentWS.trailingNode = node;
5081 }
5082 break;
5083 }
5084 }
5085 }
5086 finalizeComment(commentWS) {
5087 var _node$options;
5088 const {
5089 comments
5090 } = commentWS;
5091 if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
5092 if (commentWS.leadingNode !== null) {
5093 setTrailingComments(commentWS.leadingNode, comments);
5094 }
5095 if (commentWS.trailingNode !== null) {
5096 setLeadingComments(commentWS.trailingNode, comments);
5097 }
5098 } else {
5099 const node = commentWS.containingNode;
5100 const commentStart = commentWS.start;
5101 if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
5102 switch (node.type) {
5103 case "ObjectExpression":
5104 case "ObjectPattern":
5105 adjustInnerComments(node, node.properties, commentWS);
5106 break;
5107 case "CallExpression":
5108 case "NewExpression":
5109 case "OptionalCallExpression":
5110 adjustInnerComments(node, node.arguments, commentWS);
5111 break;
5112 case "ImportExpression":
5113 adjustInnerComments(node, [node.source, (_node$options = node.options) != null ? _node$options : null], commentWS);
5114 break;
5115 case "FunctionDeclaration":
5116 case "FunctionExpression":
5117 case "ArrowFunctionExpression":
5118 case "ObjectMethod":
5119 case "ClassMethod":
5120 case "ClassPrivateMethod":
5121 case "TSTypeParameterDeclaration":
5122 adjustInnerComments(node, node.params, commentWS);
5123 break;
5124 case "ArrayExpression":
5125 case "ArrayPattern":
5126 adjustInnerComments(node, node.elements, commentWS);
5127 break;
5128 case "ExportNamedDeclaration":
5129 case "ImportDeclaration":
5130 adjustInnerComments(node, node.specifiers, commentWS);
5131 break;
5132 case "TSEnumDeclaration":
5133 adjustInnerComments(node, node.members, commentWS);
5134 break;
5135 case "TSEnumBody":
5136 adjustInnerComments(node, node.members, commentWS);
5137 break;
5138 case "TSInterfaceBody":
5139 adjustInnerComments(node, node.body, commentWS);
5140 break;
5141 default:
5142 {
5143 if (node.type === "RecordExpression") {
5144 adjustInnerComments(node, node.properties, commentWS);
5145 break;
5146 }
5147 if (node.type === "TupleExpression") {
5148 adjustInnerComments(node, node.elements, commentWS);
5149 break;
5150 }
5151 setInnerComments(node, comments);
5152 }
5153 }
5154 } else {
5155 setInnerComments(node, comments);
5156 }
5157 }
5158 }
5159 finalizeRemainingComments() {
5160 const {
5161 commentStack
5162 } = this.state;
5163 for (let i = commentStack.length - 1; i >= 0; i--) {
5164 this.finalizeComment(commentStack[i]);
5165 }
5166 this.state.commentStack = [];
5167 }
5168 resetPreviousNodeTrailingComments(node) {
5169 const {
5170 commentStack
5171 } = this.state;
5172 const {
5173 length
5174 } = commentStack;
5175 if (length === 0) return;
5176 const commentWS = commentStack[length - 1];
5177 if (commentWS.leadingNode === node) {
5178 commentWS.leadingNode = null;
5179 }
5180 }
5181 takeSurroundingComments(node, start, end) {
5182 const {
5183 commentStack
5184 } = this.state;
5185 const commentStackLength = commentStack.length;
5186 if (commentStackLength === 0) return;
5187 let i = commentStackLength - 1;
5188 for (; i >= 0; i--) {
5189 const commentWS = commentStack[i];
5190 const commentEnd = commentWS.end;
5191 const commentStart = commentWS.start;
5192 if (commentStart === end) {
5193 commentWS.leadingNode = node;
5194 } else if (commentEnd === start) {
5195 commentWS.trailingNode = node;
5196 } else if (commentEnd < start) {
5197 break;
5198 }
5199 }
5200 }
5201}
5202class State {
5203 constructor() {
5204 this.flags = 1024;
5205 this.startIndex = void 0;
5206 this.curLine = void 0;
5207 this.lineStart = void 0;
5208 this.startLoc = void 0;
5209 this.endLoc = void 0;
5210 this.errors = [];
5211 this.potentialArrowAt = -1;
5212 this.noArrowAt = [];
5213 this.noArrowParamsConversionAt = [];
5214 this.topicContext = {
5215 maxNumOfResolvableTopics: 0,
5216 maxTopicIndex: null
5217 };
5218 this.labels = [];
5219 this.commentsLen = 0;
5220 this.commentStack = [];
5221 this.pos = 0;
5222 this.type = 140;
5223 this.value = null;
5224 this.start = 0;
5225 this.end = 0;
5226 this.lastTokEndLoc = null;
5227 this.lastTokStartLoc = null;
5228 this.context = [types.brace];
5229 this.firstInvalidTemplateEscapePos = null;
5230 this.strictErrors = new Map();
5231 this.tokensLength = 0;
5232 }
5233 get strict() {
5234 return (this.flags & 1) > 0;
5235 }
5236 set strict(v) {
5237 if (v) this.flags |= 1;else this.flags &= -2;
5238 }
5239 init({
5240 strictMode,
5241 sourceType,
5242 startIndex,
5243 startLine,
5244 startColumn
5245 }) {
5246 this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
5247 this.startIndex = startIndex;
5248 this.curLine = startLine;
5249 this.lineStart = -startColumn;
5250 this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
5251 }
5252 get maybeInArrowParameters() {
5253 return (this.flags & 2) > 0;
5254 }
5255 set maybeInArrowParameters(v) {
5256 if (v) this.flags |= 2;else this.flags &= -3;
5257 }
5258 get inType() {
5259 return (this.flags & 4) > 0;
5260 }
5261 set inType(v) {
5262 if (v) this.flags |= 4;else this.flags &= -5;
5263 }
5264 get noAnonFunctionType() {
5265 return (this.flags & 8) > 0;
5266 }
5267 set noAnonFunctionType(v) {
5268 if (v) this.flags |= 8;else this.flags &= -9;
5269 }
5270 get hasFlowComment() {
5271 return (this.flags & 16) > 0;
5272 }
5273 set hasFlowComment(v) {
5274 if (v) this.flags |= 16;else this.flags &= -17;
5275 }
5276 get isAmbientContext() {
5277 return (this.flags & 32) > 0;
5278 }
5279 set isAmbientContext(v) {
5280 if (v) this.flags |= 32;else this.flags &= -33;
5281 }
5282 get inAbstractClass() {
5283 return (this.flags & 64) > 0;
5284 }
5285 set inAbstractClass(v) {
5286 if (v) this.flags |= 64;else this.flags &= -65;
5287 }
5288 get inDisallowConditionalTypesContext() {
5289 return (this.flags & 128) > 0;
5290 }
5291 set inDisallowConditionalTypesContext(v) {
5292 if (v) this.flags |= 128;else this.flags &= -129;
5293 }
5294 get soloAwait() {
5295 return (this.flags & 256) > 0;
5296 }
5297 set soloAwait(v) {
5298 if (v) this.flags |= 256;else this.flags &= -257;
5299 }
5300 get inFSharpPipelineDirectBody() {
5301 return (this.flags & 512) > 0;
5302 }
5303 set inFSharpPipelineDirectBody(v) {
5304 if (v) this.flags |= 512;else this.flags &= -513;
5305 }
5306 get canStartJSXElement() {
5307 return (this.flags & 1024) > 0;
5308 }
5309 set canStartJSXElement(v) {
5310 if (v) this.flags |= 1024;else this.flags &= -1025;
5311 }
5312 get containsEsc() {
5313 return (this.flags & 2048) > 0;
5314 }
5315 set containsEsc(v) {
5316 if (v) this.flags |= 2048;else this.flags &= -2049;
5317 }
5318 get hasTopLevelAwait() {
5319 return (this.flags & 4096) > 0;
5320 }
5321 set hasTopLevelAwait(v) {
5322 if (v) this.flags |= 4096;else this.flags &= -4097;
5323 }
5324 curPosition() {
5325 return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
5326 }
5327 clone() {
5328 const state = new State();
5329 state.flags = this.flags;
5330 state.startIndex = this.startIndex;
5331 state.curLine = this.curLine;
5332 state.lineStart = this.lineStart;
5333 state.startLoc = this.startLoc;
5334 state.endLoc = this.endLoc;
5335 state.errors = this.errors.slice();
5336 state.potentialArrowAt = this.potentialArrowAt;
5337 state.noArrowAt = this.noArrowAt.slice();
5338 state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
5339 state.topicContext = this.topicContext;
5340 state.labels = this.labels.slice();
5341 state.commentsLen = this.commentsLen;
5342 state.commentStack = this.commentStack.slice();
5343 state.pos = this.pos;
5344 state.type = this.type;
5345 state.value = this.value;
5346 state.start = this.start;
5347 state.end = this.end;
5348 state.lastTokEndLoc = this.lastTokEndLoc;
5349 state.lastTokStartLoc = this.lastTokStartLoc;
5350 state.context = this.context.slice();
5351 state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
5352 state.strictErrors = this.strictErrors;
5353 state.tokensLength = this.tokensLength;
5354 return state;
5355 }
5356}
5357var _isDigit = function isDigit(code) {
5358 return code >= 48 && code <= 57;
5359};
5360const forbiddenNumericSeparatorSiblings = {
5361 decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
5362 hex: new Set([46, 88, 95, 120])
5363};
5364const isAllowedNumericSeparatorSibling = {
5365 bin: ch => ch === 48 || ch === 49,
5366 oct: ch => ch >= 48 && ch <= 55,
5367 dec: ch => ch >= 48 && ch <= 57,
5368 hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
5369};
5370function readStringContents(type, input, pos, lineStart, curLine, errors) {
5371 const initialPos = pos;
5372 const initialLineStart = lineStart;
5373 const initialCurLine = curLine;
5374 let out = "";
5375 let firstInvalidLoc = null;
5376 let chunkStart = pos;
5377 const {
5378 length
5379 } = input;
5380 for (;;) {
5381 if (pos >= length) {
5382 errors.unterminated(initialPos, initialLineStart, initialCurLine);
5383 out += input.slice(chunkStart, pos);
5384 break;
5385 }
5386 const ch = input.charCodeAt(pos);
5387 if (isStringEnd(type, ch, input, pos)) {
5388 out += input.slice(chunkStart, pos);
5389 break;
5390 }
5391 if (ch === 92) {
5392 out += input.slice(chunkStart, pos);
5393 const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
5394 if (res.ch === null && !firstInvalidLoc) {
5395 firstInvalidLoc = {
5396 pos,
5397 lineStart,
5398 curLine
5399 };
5400 } else {
5401 out += res.ch;
5402 }
5403 ({
5404 pos,
5405 lineStart,
5406 curLine
5407 } = res);
5408 chunkStart = pos;
5409 } else if (ch === 8232 || ch === 8233) {
5410 ++pos;
5411 ++curLine;
5412 lineStart = pos;
5413 } else if (ch === 10 || ch === 13) {
5414 if (type === "template") {
5415 out += input.slice(chunkStart, pos) + "\n";
5416 ++pos;
5417 if (ch === 13 && input.charCodeAt(pos) === 10) {
5418 ++pos;
5419 }
5420 ++curLine;
5421 chunkStart = lineStart = pos;
5422 } else {
5423 errors.unterminated(initialPos, initialLineStart, initialCurLine);
5424 }
5425 } else {
5426 ++pos;
5427 }
5428 }
5429 return {
5430 pos,
5431 str: out,
5432 firstInvalidLoc,
5433 lineStart,
5434 curLine,
5435 containsInvalid: !!firstInvalidLoc
5436 };
5437}
5438function isStringEnd(type, ch, input, pos) {
5439 if (type === "template") {
5440 return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
5441 }
5442 return ch === (type === "double" ? 34 : 39);
5443}
5444function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
5445 const throwOnInvalid = !inTemplate;
5446 pos++;
5447 const res = ch => ({
5448 pos,
5449 ch,
5450 lineStart,
5451 curLine
5452 });
5453 const ch = input.charCodeAt(pos++);
5454 switch (ch) {
5455 case 110:
5456 return res("\n");
5457 case 114:
5458 return res("\r");
5459 case 120:
5460 {
5461 let code;
5462 ({
5463 code,
5464 pos
5465 } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
5466 return res(code === null ? null : String.fromCharCode(code));
5467 }
5468 case 117:
5469 {
5470 let code;
5471 ({
5472 code,
5473 pos
5474 } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
5475 return res(code === null ? null : String.fromCodePoint(code));
5476 }
5477 case 116:
5478 return res("\t");
5479 case 98:
5480 return res("\b");
5481 case 118:
5482 return res("\u000b");
5483 case 102:
5484 return res("\f");
5485 case 13:
5486 if (input.charCodeAt(pos) === 10) {
5487 ++pos;
5488 }
5489 case 10:
5490 lineStart = pos;
5491 ++curLine;
5492 case 8232:
5493 case 8233:
5494 return res("");
5495 case 56:
5496 case 57:
5497 if (inTemplate) {
5498 return res(null);
5499 } else {
5500 errors.strictNumericEscape(pos - 1, lineStart, curLine);
5501 }
5502 default:
5503 if (ch >= 48 && ch <= 55) {
5504 const startPos = pos - 1;
5505 const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
5506 let octalStr = match[0];
5507 let octal = parseInt(octalStr, 8);
5508 if (octal > 255) {
5509 octalStr = octalStr.slice(0, -1);
5510 octal = parseInt(octalStr, 8);
5511 }
5512 pos += octalStr.length - 1;
5513 const next = input.charCodeAt(pos);
5514 if (octalStr !== "0" || next === 56 || next === 57) {
5515 if (inTemplate) {
5516 return res(null);
5517 } else {
5518 errors.strictNumericEscape(startPos, lineStart, curLine);
5519 }
5520 }
5521 return res(String.fromCharCode(octal));
5522 }
5523 return res(String.fromCharCode(ch));
5524 }
5525}
5526function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
5527 const initialPos = pos;
5528 let n;
5529 ({
5530 n,
5531 pos
5532 } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
5533 if (n === null) {
5534 if (throwOnInvalid) {
5535 errors.invalidEscapeSequence(initialPos, lineStart, curLine);
5536 } else {
5537 pos = initialPos - 1;
5538 }
5539 }
5540 return {
5541 code: n,
5542 pos
5543 };
5544}
5545function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
5546 const start = pos;
5547 const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
5548 const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
5549 let invalid = false;
5550 let total = 0;
5551 for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
5552 const code = input.charCodeAt(pos);
5553 let val;
5554 if (code === 95 && allowNumSeparator !== "bail") {
5555 const prev = input.charCodeAt(pos - 1);
5556 const next = input.charCodeAt(pos + 1);
5557 if (!allowNumSeparator) {
5558 if (bailOnError) return {
5559 n: null,
5560 pos
5561 };
5562 errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
5563 } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
5564 if (bailOnError) return {
5565 n: null,
5566 pos
5567 };
5568 errors.unexpectedNumericSeparator(pos, lineStart, curLine);
5569 }
5570 ++pos;
5571 continue;
5572 }
5573 if (code >= 97) {
5574 val = code - 97 + 10;
5575 } else if (code >= 65) {
5576 val = code - 65 + 10;
5577 } else if (_isDigit(code)) {
5578 val = code - 48;
5579 } else {
5580 val = Infinity;
5581 }
5582 if (val >= radix) {
5583 if (val <= 9 && bailOnError) {
5584 return {
5585 n: null,
5586 pos
5587 };
5588 } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
5589 val = 0;
5590 } else if (forceLen) {
5591 val = 0;
5592 invalid = true;
5593 } else {
5594 break;
5595 }
5596 }
5597 ++pos;
5598 total = total * radix + val;
5599 }
5600 if (pos === start || len != null && pos - start !== len || invalid) {
5601 return {
5602 n: null,
5603 pos
5604 };
5605 }
5606 return {
5607 n: total,
5608 pos
5609 };
5610}
5611function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
5612 const ch = input.charCodeAt(pos);
5613 let code;
5614 if (ch === 123) {
5615 ++pos;
5616 ({
5617 code,
5618 pos
5619 } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
5620 ++pos;
5621 if (code !== null && code > 0x10ffff) {
5622 if (throwOnInvalid) {
5623 errors.invalidCodePoint(pos, lineStart, curLine);
5624 } else {
5625 return {
5626 code: null,
5627 pos
5628 };
5629 }
5630 }
5631 } else {
5632 ({
5633 code,
5634 pos
5635 } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
5636 }
5637 return {
5638 code,
5639 pos
5640 };
5641}
5642function buildPosition(pos, lineStart, curLine) {
5643 return new Position(curLine, pos - lineStart, pos);
5644}
5645const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
5646class Token {
5647 constructor(state) {
5648 const startIndex = state.startIndex || 0;
5649 this.type = state.type;
5650 this.value = state.value;
5651 this.start = startIndex + state.start;
5652 this.end = startIndex + state.end;
5653 this.loc = new SourceLocation(state.startLoc, state.endLoc);
5654 }
5655}
5656class Tokenizer extends CommentsParser {
5657 constructor(options, input) {
5658 super();
5659 this.isLookahead = void 0;
5660 this.tokens = [];
5661 this.errorHandlers_readInt = {
5662 invalidDigit: (pos, lineStart, curLine, radix) => {
5663 if (!(this.optionFlags & 2048)) return false;
5664 this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
5665 radix
5666 });
5667 return true;
5668 },
5669 numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
5670 unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
5671 };
5672 this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
5673 invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
5674 invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
5675 });
5676 this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
5677 strictNumericEscape: (pos, lineStart, curLine) => {
5678 this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
5679 },
5680 unterminated: (pos, lineStart, curLine) => {
5681 throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
5682 }
5683 });
5684 this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
5685 strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
5686 unterminated: (pos, lineStart, curLine) => {
5687 throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
5688 }
5689 });
5690 this.state = new State();
5691 this.state.init(options);
5692 this.input = input;
5693 this.length = input.length;
5694 this.comments = [];
5695 this.isLookahead = false;
5696 }
5697 pushToken(token) {
5698 this.tokens.length = this.state.tokensLength;
5699 this.tokens.push(token);
5700 ++this.state.tokensLength;
5701 }
5702 next() {
5703 this.checkKeywordEscapes();
5704 if (this.optionFlags & 256) {
5705 this.pushToken(new Token(this.state));
5706 }
5707 this.state.lastTokEndLoc = this.state.endLoc;
5708 this.state.lastTokStartLoc = this.state.startLoc;
5709 this.nextToken();
5710 }
5711 eat(type) {
5712 if (this.match(type)) {
5713 this.next();
5714 return true;
5715 } else {
5716 return false;
5717 }
5718 }
5719 match(type) {
5720 return this.state.type === type;
5721 }
5722 createLookaheadState(state) {
5723 return {
5724 pos: state.pos,
5725 value: null,
5726 type: state.type,
5727 start: state.start,
5728 end: state.end,
5729 context: [this.curContext()],
5730 inType: state.inType,
5731 startLoc: state.startLoc,
5732 lastTokEndLoc: state.lastTokEndLoc,
5733 curLine: state.curLine,
5734 lineStart: state.lineStart,
5735 curPosition: state.curPosition
5736 };
5737 }
5738 lookahead() {
5739 const old = this.state;
5740 this.state = this.createLookaheadState(old);
5741 this.isLookahead = true;
5742 this.nextToken();
5743 this.isLookahead = false;
5744 const curr = this.state;
5745 this.state = old;
5746 return curr;
5747 }
5748 nextTokenStart() {
5749 return this.nextTokenStartSince(this.state.pos);
5750 }
5751 nextTokenStartSince(pos) {
5752 skipWhiteSpace.lastIndex = pos;
5753 return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
5754 }
5755 lookaheadCharCode() {
5756 return this.lookaheadCharCodeSince(this.state.pos);
5757 }
5758 lookaheadCharCodeSince(pos) {
5759 return this.input.charCodeAt(this.nextTokenStartSince(pos));
5760 }
5761 nextTokenInLineStart() {
5762 return this.nextTokenInLineStartSince(this.state.pos);
5763 }
5764 nextTokenInLineStartSince(pos) {
5765 skipWhiteSpaceInLine.lastIndex = pos;
5766 return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
5767 }
5768 lookaheadInLineCharCode() {
5769 return this.input.charCodeAt(this.nextTokenInLineStart());
5770 }
5771 codePointAtPos(pos) {
5772 let cp = this.input.charCodeAt(pos);
5773 if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
5774 const trail = this.input.charCodeAt(pos);
5775 if ((trail & 0xfc00) === 0xdc00) {
5776 cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
5777 }
5778 }
5779 return cp;
5780 }
5781 setStrict(strict) {
5782 this.state.strict = strict;
5783 if (strict) {
5784 this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
5785 this.state.strictErrors.clear();
5786 }
5787 }
5788 curContext() {
5789 return this.state.context[this.state.context.length - 1];
5790 }
5791 nextToken() {
5792 this.skipSpace();
5793 this.state.start = this.state.pos;
5794 if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
5795 if (this.state.pos >= this.length) {
5796 this.finishToken(140);
5797 return;
5798 }
5799 this.getTokenFromCode(this.codePointAtPos(this.state.pos));
5800 }
5801 skipBlockComment(commentEnd) {
5802 let startLoc;
5803 if (!this.isLookahead) startLoc = this.state.curPosition();
5804 const start = this.state.pos;
5805 const end = this.input.indexOf(commentEnd, start + 2);
5806 if (end === -1) {
5807 throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
5808 }
5809 this.state.pos = end + commentEnd.length;
5810 lineBreakG.lastIndex = start + 2;
5811 while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
5812 ++this.state.curLine;
5813 this.state.lineStart = lineBreakG.lastIndex;
5814 }
5815 if (this.isLookahead) return;
5816 const comment = {
5817 type: "CommentBlock",
5818 value: this.input.slice(start + 2, end),
5819 start: this.sourceToOffsetPos(start),
5820 end: this.sourceToOffsetPos(end + commentEnd.length),
5821 loc: new SourceLocation(startLoc, this.state.curPosition())
5822 };
5823 if (this.optionFlags & 256) this.pushToken(comment);
5824 return comment;
5825 }
5826 skipLineComment(startSkip) {
5827 const start = this.state.pos;
5828 let startLoc;
5829 if (!this.isLookahead) startLoc = this.state.curPosition();
5830 let ch = this.input.charCodeAt(this.state.pos += startSkip);
5831 if (this.state.pos < this.length) {
5832 while (!isNewLine(ch) && ++this.state.pos < this.length) {
5833 ch = this.input.charCodeAt(this.state.pos);
5834 }
5835 }
5836 if (this.isLookahead) return;
5837 const end = this.state.pos;
5838 const value = this.input.slice(start + startSkip, end);
5839 const comment = {
5840 type: "CommentLine",
5841 value,
5842 start: this.sourceToOffsetPos(start),
5843 end: this.sourceToOffsetPos(end),
5844 loc: new SourceLocation(startLoc, this.state.curPosition())
5845 };
5846 if (this.optionFlags & 256) this.pushToken(comment);
5847 return comment;
5848 }
5849 skipSpace() {
5850 const spaceStart = this.state.pos;
5851 const comments = this.optionFlags & 4096 ? [] : null;
5852 loop: while (this.state.pos < this.length) {
5853 const ch = this.input.charCodeAt(this.state.pos);
5854 switch (ch) {
5855 case 32:
5856 case 160:
5857 case 9:
5858 ++this.state.pos;
5859 break;
5860 case 13:
5861 if (this.input.charCodeAt(this.state.pos + 1) === 10) {
5862 ++this.state.pos;
5863 }
5864 case 10:
5865 case 8232:
5866 case 8233:
5867 ++this.state.pos;
5868 ++this.state.curLine;
5869 this.state.lineStart = this.state.pos;
5870 break;
5871 case 47:
5872 switch (this.input.charCodeAt(this.state.pos + 1)) {
5873 case 42:
5874 {
5875 const comment = this.skipBlockComment("*/");
5876 if (comment !== undefined) {
5877 this.addComment(comment);
5878 comments == null || comments.push(comment);
5879 }
5880 break;
5881 }
5882 case 47:
5883 {
5884 const comment = this.skipLineComment(2);
5885 if (comment !== undefined) {
5886 this.addComment(comment);
5887 comments == null || comments.push(comment);
5888 }
5889 break;
5890 }
5891 default:
5892 break loop;
5893 }
5894 break;
5895 default:
5896 if (isWhitespace(ch)) {
5897 ++this.state.pos;
5898 } else if (ch === 45 && !this.inModule && this.optionFlags & 8192) {
5899 const pos = this.state.pos;
5900 if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
5901 const comment = this.skipLineComment(3);
5902 if (comment !== undefined) {
5903 this.addComment(comment);
5904 comments == null || comments.push(comment);
5905 }
5906 } else {
5907 break loop;
5908 }
5909 } else if (ch === 60 && !this.inModule && this.optionFlags & 8192) {
5910 const pos = this.state.pos;
5911 if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
5912 const comment = this.skipLineComment(4);
5913 if (comment !== undefined) {
5914 this.addComment(comment);
5915 comments == null || comments.push(comment);
5916 }
5917 } else {
5918 break loop;
5919 }
5920 } else {
5921 break loop;
5922 }
5923 }
5924 }
5925 if ((comments == null ? void 0 : comments.length) > 0) {
5926 const end = this.state.pos;
5927 const commentWhitespace = {
5928 start: this.sourceToOffsetPos(spaceStart),
5929 end: this.sourceToOffsetPos(end),
5930 comments: comments,
5931 leadingNode: null,
5932 trailingNode: null,
5933 containingNode: null
5934 };
5935 this.state.commentStack.push(commentWhitespace);
5936 }
5937 }
5938 finishToken(type, val) {
5939 this.state.end = this.state.pos;
5940 this.state.endLoc = this.state.curPosition();
5941 const prevType = this.state.type;
5942 this.state.type = type;
5943 this.state.value = val;
5944 if (!this.isLookahead) {
5945 this.updateContext(prevType);
5946 }
5947 }
5948 replaceToken(type) {
5949 this.state.type = type;
5950 this.updateContext();
5951 }
5952 readToken_numberSign() {
5953 if (this.state.pos === 0 && this.readToken_interpreter()) {
5954 return;
5955 }
5956 const nextPos = this.state.pos + 1;
5957 const next = this.codePointAtPos(nextPos);
5958 if (next >= 48 && next <= 57) {
5959 throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
5960 }
5961 if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
5962 this.expectPlugin("recordAndTuple");
5963 if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
5964 throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
5965 }
5966 this.state.pos += 2;
5967 if (next === 123) {
5968 this.finishToken(7);
5969 } else {
5970 this.finishToken(1);
5971 }
5972 } else if (isIdentifierStart(next)) {
5973 ++this.state.pos;
5974 this.finishToken(139, this.readWord1(next));
5975 } else if (next === 92) {
5976 ++this.state.pos;
5977 this.finishToken(139, this.readWord1());
5978 } else {
5979 this.finishOp(27, 1);
5980 }
5981 }
5982 readToken_dot() {
5983 const next = this.input.charCodeAt(this.state.pos + 1);
5984 if (next >= 48 && next <= 57) {
5985 this.readNumber(true);
5986 return;
5987 }
5988 if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
5989 this.state.pos += 3;
5990 this.finishToken(21);
5991 } else {
5992 ++this.state.pos;
5993 this.finishToken(16);
5994 }
5995 }
5996 readToken_slash() {
5997 const next = this.input.charCodeAt(this.state.pos + 1);
5998 if (next === 61) {
5999 this.finishOp(31, 2);
6000 } else {
6001 this.finishOp(56, 1);
6002 }
6003 }
6004 readToken_interpreter() {
6005 if (this.state.pos !== 0 || this.length < 2) return false;
6006 let ch = this.input.charCodeAt(this.state.pos + 1);
6007 if (ch !== 33) return false;
6008 const start = this.state.pos;
6009 this.state.pos += 1;
6010 while (!isNewLine(ch) && ++this.state.pos < this.length) {
6011 ch = this.input.charCodeAt(this.state.pos);
6012 }
6013 const value = this.input.slice(start + 2, this.state.pos);
6014 this.finishToken(28, value);
6015 return true;
6016 }
6017 readToken_mult_modulo(code) {
6018 let type = code === 42 ? 55 : 54;
6019 let width = 1;
6020 let next = this.input.charCodeAt(this.state.pos + 1);
6021 if (code === 42 && next === 42) {
6022 width++;
6023 next = this.input.charCodeAt(this.state.pos + 2);
6024 type = 57;
6025 }
6026 if (next === 61 && !this.state.inType) {
6027 width++;
6028 type = code === 37 ? 33 : 30;
6029 }
6030 this.finishOp(type, width);
6031 }
6032 readToken_pipe_amp(code) {
6033 const next = this.input.charCodeAt(this.state.pos + 1);
6034 if (next === code) {
6035 if (this.input.charCodeAt(this.state.pos + 2) === 61) {
6036 this.finishOp(30, 3);
6037 } else {
6038 this.finishOp(code === 124 ? 41 : 42, 2);
6039 }
6040 return;
6041 }
6042 if (code === 124) {
6043 if (next === 62) {
6044 this.finishOp(39, 2);
6045 return;
6046 }
6047 if (this.hasPlugin("recordAndTuple") && next === 125) {
6048 if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
6049 throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
6050 }
6051 this.state.pos += 2;
6052 this.finishToken(9);
6053 return;
6054 }
6055 if (this.hasPlugin("recordAndTuple") && next === 93) {
6056 if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
6057 throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
6058 }
6059 this.state.pos += 2;
6060 this.finishToken(4);
6061 return;
6062 }
6063 }
6064 if (next === 61) {
6065 this.finishOp(30, 2);
6066 return;
6067 }
6068 this.finishOp(code === 124 ? 43 : 45, 1);
6069 }
6070 readToken_caret() {
6071 const next = this.input.charCodeAt(this.state.pos + 1);
6072 if (next === 61 && !this.state.inType) {
6073 this.finishOp(32, 2);
6074 } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
6075 proposal: "hack",
6076 topicToken: "^^"
6077 }])) {
6078 this.finishOp(37, 2);
6079 const lookaheadCh = this.input.codePointAt(this.state.pos);
6080 if (lookaheadCh === 94) {
6081 this.unexpected();
6082 }
6083 } else {
6084 this.finishOp(44, 1);
6085 }
6086 }
6087 readToken_atSign() {
6088 const next = this.input.charCodeAt(this.state.pos + 1);
6089 if (next === 64 && this.hasPlugin(["pipelineOperator", {
6090 proposal: "hack",
6091 topicToken: "@@"
6092 }])) {
6093 this.finishOp(38, 2);
6094 } else {
6095 this.finishOp(26, 1);
6096 }
6097 }
6098 readToken_plus_min(code) {
6099 const next = this.input.charCodeAt(this.state.pos + 1);
6100 if (next === code) {
6101 this.finishOp(34, 2);
6102 return;
6103 }
6104 if (next === 61) {
6105 this.finishOp(30, 2);
6106 } else {
6107 this.finishOp(53, 1);
6108 }
6109 }
6110 readToken_lt() {
6111 const {
6112 pos
6113 } = this.state;
6114 const next = this.input.charCodeAt(pos + 1);
6115 if (next === 60) {
6116 if (this.input.charCodeAt(pos + 2) === 61) {
6117 this.finishOp(30, 3);
6118 return;
6119 }
6120 this.finishOp(51, 2);
6121 return;
6122 }
6123 if (next === 61) {
6124 this.finishOp(49, 2);
6125 return;
6126 }
6127 this.finishOp(47, 1);
6128 }
6129 readToken_gt() {
6130 const {
6131 pos
6132 } = this.state;
6133 const next = this.input.charCodeAt(pos + 1);
6134 if (next === 62) {
6135 const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
6136 if (this.input.charCodeAt(pos + size) === 61) {
6137 this.finishOp(30, size + 1);
6138 return;
6139 }
6140 this.finishOp(52, size);
6141 return;
6142 }
6143 if (next === 61) {
6144 this.finishOp(49, 2);
6145 return;
6146 }
6147 this.finishOp(48, 1);
6148 }
6149 readToken_eq_excl(code) {
6150 const next = this.input.charCodeAt(this.state.pos + 1);
6151 if (next === 61) {
6152 this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
6153 return;
6154 }
6155 if (code === 61 && next === 62) {
6156 this.state.pos += 2;
6157 this.finishToken(19);
6158 return;
6159 }
6160 this.finishOp(code === 61 ? 29 : 35, 1);
6161 }
6162 readToken_question() {
6163 const next = this.input.charCodeAt(this.state.pos + 1);
6164 const next2 = this.input.charCodeAt(this.state.pos + 2);
6165 if (next === 63) {
6166 if (next2 === 61) {
6167 this.finishOp(30, 3);
6168 } else {
6169 this.finishOp(40, 2);
6170 }
6171 } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
6172 this.state.pos += 2;
6173 this.finishToken(18);
6174 } else {
6175 ++this.state.pos;
6176 this.finishToken(17);
6177 }
6178 }
6179 getTokenFromCode(code) {
6180 switch (code) {
6181 case 46:
6182 this.readToken_dot();
6183 return;
6184 case 40:
6185 ++this.state.pos;
6186 this.finishToken(10);
6187 return;
6188 case 41:
6189 ++this.state.pos;
6190 this.finishToken(11);
6191 return;
6192 case 59:
6193 ++this.state.pos;
6194 this.finishToken(13);
6195 return;
6196 case 44:
6197 ++this.state.pos;
6198 this.finishToken(12);
6199 return;
6200 case 91:
6201 if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
6202 if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
6203 throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
6204 }
6205 this.state.pos += 2;
6206 this.finishToken(2);
6207 } else {
6208 ++this.state.pos;
6209 this.finishToken(0);
6210 }
6211 return;
6212 case 93:
6213 ++this.state.pos;
6214 this.finishToken(3);
6215 return;
6216 case 123:
6217 if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
6218 if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
6219 throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
6220 }
6221 this.state.pos += 2;
6222 this.finishToken(6);
6223 } else {
6224 ++this.state.pos;
6225 this.finishToken(5);
6226 }
6227 return;
6228 case 125:
6229 ++this.state.pos;
6230 this.finishToken(8);
6231 return;
6232 case 58:
6233 if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
6234 this.finishOp(15, 2);
6235 } else {
6236 ++this.state.pos;
6237 this.finishToken(14);
6238 }
6239 return;
6240 case 63:
6241 this.readToken_question();
6242 return;
6243 case 96:
6244 this.readTemplateToken();
6245 return;
6246 case 48:
6247 {
6248 const next = this.input.charCodeAt(this.state.pos + 1);
6249 if (next === 120 || next === 88) {
6250 this.readRadixNumber(16);
6251 return;
6252 }
6253 if (next === 111 || next === 79) {
6254 this.readRadixNumber(8);
6255 return;
6256 }
6257 if (next === 98 || next === 66) {
6258 this.readRadixNumber(2);
6259 return;
6260 }
6261 }
6262 case 49:
6263 case 50:
6264 case 51:
6265 case 52:
6266 case 53:
6267 case 54:
6268 case 55:
6269 case 56:
6270 case 57:
6271 this.readNumber(false);
6272 return;
6273 case 34:
6274 case 39:
6275 this.readString(code);
6276 return;
6277 case 47:
6278 this.readToken_slash();
6279 return;
6280 case 37:
6281 case 42:
6282 this.readToken_mult_modulo(code);
6283 return;
6284 case 124:
6285 case 38:
6286 this.readToken_pipe_amp(code);
6287 return;
6288 case 94:
6289 this.readToken_caret();
6290 return;
6291 case 43:
6292 case 45:
6293 this.readToken_plus_min(code);
6294 return;
6295 case 60:
6296 this.readToken_lt();
6297 return;
6298 case 62:
6299 this.readToken_gt();
6300 return;
6301 case 61:
6302 case 33:
6303 this.readToken_eq_excl(code);
6304 return;
6305 case 126:
6306 this.finishOp(36, 1);
6307 return;
6308 case 64:
6309 this.readToken_atSign();
6310 return;
6311 case 35:
6312 this.readToken_numberSign();
6313 return;
6314 case 92:
6315 this.readWord();
6316 return;
6317 default:
6318 if (isIdentifierStart(code)) {
6319 this.readWord(code);
6320 return;
6321 }
6322 }
6323 throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
6324 unexpected: String.fromCodePoint(code)
6325 });
6326 }
6327 finishOp(type, size) {
6328 const str = this.input.slice(this.state.pos, this.state.pos + size);
6329 this.state.pos += size;
6330 this.finishToken(type, str);
6331 }
6332 readRegexp() {
6333 const startLoc = this.state.startLoc;
6334 const start = this.state.start + 1;
6335 let escaped, inClass;
6336 let {
6337 pos
6338 } = this.state;
6339 for (;; ++pos) {
6340 if (pos >= this.length) {
6341 throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
6342 }
6343 const ch = this.input.charCodeAt(pos);
6344 if (isNewLine(ch)) {
6345 throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
6346 }
6347 if (escaped) {
6348 escaped = false;
6349 } else {
6350 if (ch === 91) {
6351 inClass = true;
6352 } else if (ch === 93 && inClass) {
6353 inClass = false;
6354 } else if (ch === 47 && !inClass) {
6355 break;
6356 }
6357 escaped = ch === 92;
6358 }
6359 }
6360 const content = this.input.slice(start, pos);
6361 ++pos;
6362 let mods = "";
6363 const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
6364 while (pos < this.length) {
6365 const cp = this.codePointAtPos(pos);
6366 const char = String.fromCharCode(cp);
6367 if (VALID_REGEX_FLAGS.has(cp)) {
6368 if (cp === 118) {
6369 if (mods.includes("u")) {
6370 this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
6371 }
6372 } else if (cp === 117) {
6373 if (mods.includes("v")) {
6374 this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
6375 }
6376 }
6377 if (mods.includes(char)) {
6378 this.raise(Errors.DuplicateRegExpFlags, nextPos());
6379 }
6380 } else if (isIdentifierChar(cp) || cp === 92) {
6381 this.raise(Errors.MalformedRegExpFlags, nextPos());
6382 } else {
6383 break;
6384 }
6385 ++pos;
6386 mods += char;
6387 }
6388 this.state.pos = pos;
6389 this.finishToken(138, {
6390 pattern: content,
6391 flags: mods
6392 });
6393 }
6394 readInt(radix, len, forceLen = false, allowNumSeparator = true) {
6395 const {
6396 n,
6397 pos
6398 } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
6399 this.state.pos = pos;
6400 return n;
6401 }
6402 readRadixNumber(radix) {
6403 const start = this.state.pos;
6404 const startLoc = this.state.curPosition();
6405 let isBigInt = false;
6406 this.state.pos += 2;
6407 const val = this.readInt(radix);
6408 if (val == null) {
6409 this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
6410 radix
6411 });
6412 }
6413 const next = this.input.charCodeAt(this.state.pos);
6414 if (next === 110) {
6415 ++this.state.pos;
6416 isBigInt = true;
6417 } else if (next === 109) {
6418 throw this.raise(Errors.InvalidDecimal, startLoc);
6419 }
6420 if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
6421 throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
6422 }
6423 if (isBigInt) {
6424 const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
6425 this.finishToken(136, str);
6426 return;
6427 }
6428 this.finishToken(135, val);
6429 }
6430 readNumber(startsWithDot) {
6431 const start = this.state.pos;
6432 const startLoc = this.state.curPosition();
6433 let isFloat = false;
6434 let isBigInt = false;
6435 let hasExponent = false;
6436 let isOctal = false;
6437 if (!startsWithDot && this.readInt(10) === null) {
6438 this.raise(Errors.InvalidNumber, this.state.curPosition());
6439 }
6440 const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
6441 if (hasLeadingZero) {
6442 const integer = this.input.slice(start, this.state.pos);
6443 this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
6444 if (!this.state.strict) {
6445 const underscorePos = integer.indexOf("_");
6446 if (underscorePos > 0) {
6447 this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
6448 }
6449 }
6450 isOctal = hasLeadingZero && !/[89]/.test(integer);
6451 }
6452 let next = this.input.charCodeAt(this.state.pos);
6453 if (next === 46 && !isOctal) {
6454 ++this.state.pos;
6455 this.readInt(10);
6456 isFloat = true;
6457 next = this.input.charCodeAt(this.state.pos);
6458 }
6459 if ((next === 69 || next === 101) && !isOctal) {
6460 next = this.input.charCodeAt(++this.state.pos);
6461 if (next === 43 || next === 45) {
6462 ++this.state.pos;
6463 }
6464 if (this.readInt(10) === null) {
6465 this.raise(Errors.InvalidOrMissingExponent, startLoc);
6466 }
6467 isFloat = true;
6468 hasExponent = true;
6469 next = this.input.charCodeAt(this.state.pos);
6470 }
6471 if (next === 110) {
6472 if (isFloat || hasLeadingZero) {
6473 this.raise(Errors.InvalidBigIntLiteral, startLoc);
6474 }
6475 ++this.state.pos;
6476 isBigInt = true;
6477 }
6478 if (next === 109) {
6479 this.expectPlugin("decimal", this.state.curPosition());
6480 if (hasExponent || hasLeadingZero) {
6481 this.raise(Errors.InvalidDecimal, startLoc);
6482 }
6483 ++this.state.pos;
6484 var isDecimal = true;
6485 }
6486 if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
6487 throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
6488 }
6489 const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
6490 if (isBigInt) {
6491 this.finishToken(136, str);
6492 return;
6493 }
6494 if (isDecimal) {
6495 this.finishToken(137, str);
6496 return;
6497 }
6498 const val = isOctal ? parseInt(str, 8) : parseFloat(str);
6499 this.finishToken(135, val);
6500 }
6501 readCodePoint(throwOnInvalid) {
6502 const {
6503 code,
6504 pos
6505 } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
6506 this.state.pos = pos;
6507 return code;
6508 }
6509 readString(quote) {
6510 const {
6511 str,
6512 pos,
6513 curLine,
6514 lineStart
6515 } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
6516 this.state.pos = pos + 1;
6517 this.state.lineStart = lineStart;
6518 this.state.curLine = curLine;
6519 this.finishToken(134, str);
6520 }
6521 readTemplateContinuation() {
6522 if (!this.match(8)) {
6523 this.unexpected(null, 8);
6524 }
6525 this.state.pos--;
6526 this.readTemplateToken();
6527 }
6528 readTemplateToken() {
6529 const opening = this.input[this.state.pos];
6530 const {
6531 str,
6532 firstInvalidLoc,
6533 pos,
6534 curLine,
6535 lineStart
6536 } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
6537 this.state.pos = pos + 1;
6538 this.state.lineStart = lineStart;
6539 this.state.curLine = curLine;
6540 if (firstInvalidLoc) {
6541 this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
6542 }
6543 if (this.input.codePointAt(pos) === 96) {
6544 this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
6545 } else {
6546 this.state.pos++;
6547 this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
6548 }
6549 }
6550 recordStrictModeErrors(toParseError, at) {
6551 const index = at.index;
6552 if (this.state.strict && !this.state.strictErrors.has(index)) {
6553 this.raise(toParseError, at);
6554 } else {
6555 this.state.strictErrors.set(index, [toParseError, at]);
6556 }
6557 }
6558 readWord1(firstCode) {
6559 this.state.containsEsc = false;
6560 let word = "";
6561 const start = this.state.pos;
6562 let chunkStart = this.state.pos;
6563 if (firstCode !== undefined) {
6564 this.state.pos += firstCode <= 0xffff ? 1 : 2;
6565 }
6566 while (this.state.pos < this.length) {
6567 const ch = this.codePointAtPos(this.state.pos);
6568 if (isIdentifierChar(ch)) {
6569 this.state.pos += ch <= 0xffff ? 1 : 2;
6570 } else if (ch === 92) {
6571 this.state.containsEsc = true;
6572 word += this.input.slice(chunkStart, this.state.pos);
6573 const escStart = this.state.curPosition();
6574 const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
6575 if (this.input.charCodeAt(++this.state.pos) !== 117) {
6576 this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
6577 chunkStart = this.state.pos - 1;
6578 continue;
6579 }
6580 ++this.state.pos;
6581 const esc = this.readCodePoint(true);
6582 if (esc !== null) {
6583 if (!identifierCheck(esc)) {
6584 this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
6585 }
6586 word += String.fromCodePoint(esc);
6587 }
6588 chunkStart = this.state.pos;
6589 } else {
6590 break;
6591 }
6592 }
6593 return word + this.input.slice(chunkStart, this.state.pos);
6594 }
6595 readWord(firstCode) {
6596 const word = this.readWord1(firstCode);
6597 const type = keywords$1.get(word);
6598 if (type !== undefined) {
6599 this.finishToken(type, tokenLabelName(type));
6600 } else {
6601 this.finishToken(132, word);
6602 }
6603 }
6604 checkKeywordEscapes() {
6605 const {
6606 type
6607 } = this.state;
6608 if (tokenIsKeyword(type) && this.state.containsEsc) {
6609 this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
6610 reservedWord: tokenLabelName(type)
6611 });
6612 }
6613 }
6614 raise(toParseError, at, details = {}) {
6615 const loc = at instanceof Position ? at : at.loc.start;
6616 const error = toParseError(loc, details);
6617 if (!(this.optionFlags & 2048)) throw error;
6618 if (!this.isLookahead) this.state.errors.push(error);
6619 return error;
6620 }
6621 raiseOverwrite(toParseError, at, details = {}) {
6622 const loc = at instanceof Position ? at : at.loc.start;
6623 const pos = loc.index;
6624 const errors = this.state.errors;
6625 for (let i = errors.length - 1; i >= 0; i--) {
6626 const error = errors[i];
6627 if (error.loc.index === pos) {
6628 return errors[i] = toParseError(loc, details);
6629 }
6630 if (error.loc.index < pos) break;
6631 }
6632 return this.raise(toParseError, at, details);
6633 }
6634 updateContext(prevType) {}
6635 unexpected(loc, type) {
6636 throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
6637 expected: type ? tokenLabelName(type) : null
6638 });
6639 }
6640 expectPlugin(pluginName, loc) {
6641 if (this.hasPlugin(pluginName)) {
6642 return true;
6643 }
6644 throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
6645 missingPlugin: [pluginName]
6646 });
6647 }
6648 expectOnePlugin(pluginNames) {
6649 if (!pluginNames.some(name => this.hasPlugin(name))) {
6650 throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
6651 missingPlugin: pluginNames
6652 });
6653 }
6654 }
6655 errorBuilder(error) {
6656 return (pos, lineStart, curLine) => {
6657 this.raise(error, buildPosition(pos, lineStart, curLine));
6658 };
6659 }
6660}
6661class ClassScope {
6662 constructor() {
6663 this.privateNames = new Set();
6664 this.loneAccessors = new Map();
6665 this.undefinedPrivateNames = new Map();
6666 }
6667}
6668class ClassScopeHandler {
6669 constructor(parser) {
6670 this.parser = void 0;
6671 this.stack = [];
6672 this.undefinedPrivateNames = new Map();
6673 this.parser = parser;
6674 }
6675 current() {
6676 return this.stack[this.stack.length - 1];
6677 }
6678 enter() {
6679 this.stack.push(new ClassScope());
6680 }
6681 exit() {
6682 const oldClassScope = this.stack.pop();
6683 const current = this.current();
6684 for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
6685 if (current) {
6686 if (!current.undefinedPrivateNames.has(name)) {
6687 current.undefinedPrivateNames.set(name, loc);
6688 }
6689 } else {
6690 this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
6691 identifierName: name
6692 });
6693 }
6694 }
6695 }
6696 declarePrivateName(name, elementType, loc) {
6697 const {
6698 privateNames,
6699 loneAccessors,
6700 undefinedPrivateNames
6701 } = this.current();
6702 let redefined = privateNames.has(name);
6703 if (elementType & 3) {
6704 const accessor = redefined && loneAccessors.get(name);
6705 if (accessor) {
6706 const oldStatic = accessor & 4;
6707 const newStatic = elementType & 4;
6708 const oldKind = accessor & 3;
6709 const newKind = elementType & 3;
6710 redefined = oldKind === newKind || oldStatic !== newStatic;
6711 if (!redefined) loneAccessors.delete(name);
6712 } else if (!redefined) {
6713 loneAccessors.set(name, elementType);
6714 }
6715 }
6716 if (redefined) {
6717 this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
6718 identifierName: name
6719 });
6720 }
6721 privateNames.add(name);
6722 undefinedPrivateNames.delete(name);
6723 }
6724 usePrivateName(name, loc) {
6725 let classScope;
6726 for (classScope of this.stack) {
6727 if (classScope.privateNames.has(name)) return;
6728 }
6729 if (classScope) {
6730 classScope.undefinedPrivateNames.set(name, loc);
6731 } else {
6732 this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
6733 identifierName: name
6734 });
6735 }
6736 }
6737}
6738class ExpressionScope {
6739 constructor(type = 0) {
6740 this.type = type;
6741 }
6742 canBeArrowParameterDeclaration() {
6743 return this.type === 2 || this.type === 1;
6744 }
6745 isCertainlyParameterDeclaration() {
6746 return this.type === 3;
6747 }
6748}
6749class ArrowHeadParsingScope extends ExpressionScope {
6750 constructor(type) {
6751 super(type);
6752 this.declarationErrors = new Map();
6753 }
6754 recordDeclarationError(ParsingErrorClass, at) {
6755 const index = at.index;
6756 this.declarationErrors.set(index, [ParsingErrorClass, at]);
6757 }
6758 clearDeclarationError(index) {
6759 this.declarationErrors.delete(index);
6760 }
6761 iterateErrors(iterator) {
6762 this.declarationErrors.forEach(iterator);
6763 }
6764}
6765class ExpressionScopeHandler {
6766 constructor(parser) {
6767 this.parser = void 0;
6768 this.stack = [new ExpressionScope()];
6769 this.parser = parser;
6770 }
6771 enter(scope) {
6772 this.stack.push(scope);
6773 }
6774 exit() {
6775 this.stack.pop();
6776 }
6777 recordParameterInitializerError(toParseError, node) {
6778 const origin = node.loc.start;
6779 const {
6780 stack
6781 } = this;
6782 let i = stack.length - 1;
6783 let scope = stack[i];
6784 while (!scope.isCertainlyParameterDeclaration()) {
6785 if (scope.canBeArrowParameterDeclaration()) {
6786 scope.recordDeclarationError(toParseError, origin);
6787 } else {
6788 return;
6789 }
6790 scope = stack[--i];
6791 }
6792 this.parser.raise(toParseError, origin);
6793 }
6794 recordArrowParameterBindingError(error, node) {
6795 const {
6796 stack
6797 } = this;
6798 const scope = stack[stack.length - 1];
6799 const origin = node.loc.start;
6800 if (scope.isCertainlyParameterDeclaration()) {
6801 this.parser.raise(error, origin);
6802 } else if (scope.canBeArrowParameterDeclaration()) {
6803 scope.recordDeclarationError(error, origin);
6804 } else {
6805 return;
6806 }
6807 }
6808 recordAsyncArrowParametersError(at) {
6809 const {
6810 stack
6811 } = this;
6812 let i = stack.length - 1;
6813 let scope = stack[i];
6814 while (scope.canBeArrowParameterDeclaration()) {
6815 if (scope.type === 2) {
6816 scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
6817 }
6818 scope = stack[--i];
6819 }
6820 }
6821 validateAsPattern() {
6822 const {
6823 stack
6824 } = this;
6825 const currentScope = stack[stack.length - 1];
6826 if (!currentScope.canBeArrowParameterDeclaration()) return;
6827 currentScope.iterateErrors(([toParseError, loc]) => {
6828 this.parser.raise(toParseError, loc);
6829 let i = stack.length - 2;
6830 let scope = stack[i];
6831 while (scope.canBeArrowParameterDeclaration()) {
6832 scope.clearDeclarationError(loc.index);
6833 scope = stack[--i];
6834 }
6835 });
6836 }
6837}
6838function newParameterDeclarationScope() {
6839 return new ExpressionScope(3);
6840}
6841function newArrowHeadScope() {
6842 return new ArrowHeadParsingScope(1);
6843}
6844function newAsyncArrowScope() {
6845 return new ArrowHeadParsingScope(2);
6846}
6847function newExpressionScope() {
6848 return new ExpressionScope();
6849}
6850class UtilParser extends Tokenizer {
6851 addExtra(node, key, value, enumerable = true) {
6852 if (!node) return;
6853 let {
6854 extra
6855 } = node;
6856 if (extra == null) {
6857 extra = {};
6858 node.extra = extra;
6859 }
6860 if (enumerable) {
6861 extra[key] = value;
6862 } else {
6863 Object.defineProperty(extra, key, {
6864 enumerable,
6865 value
6866 });
6867 }
6868 }
6869 isContextual(token) {
6870 return this.state.type === token && !this.state.containsEsc;
6871 }
6872 isUnparsedContextual(nameStart, name) {
6873 if (this.input.startsWith(name, nameStart)) {
6874 const nextCh = this.input.charCodeAt(nameStart + name.length);
6875 return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
6876 }
6877 return false;
6878 }
6879 isLookaheadContextual(name) {
6880 const next = this.nextTokenStart();
6881 return this.isUnparsedContextual(next, name);
6882 }
6883 eatContextual(token) {
6884 if (this.isContextual(token)) {
6885 this.next();
6886 return true;
6887 }
6888 return false;
6889 }
6890 expectContextual(token, toParseError) {
6891 if (!this.eatContextual(token)) {
6892 if (toParseError != null) {
6893 throw this.raise(toParseError, this.state.startLoc);
6894 }
6895 this.unexpected(null, token);
6896 }
6897 }
6898 canInsertSemicolon() {
6899 return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
6900 }
6901 hasPrecedingLineBreak() {
6902 return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
6903 }
6904 hasFollowingLineBreak() {
6905 return hasNewLine(this.input, this.state.end, this.nextTokenStart());
6906 }
6907 isLineTerminator() {
6908 return this.eat(13) || this.canInsertSemicolon();
6909 }
6910 semicolon(allowAsi = true) {
6911 if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
6912 this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
6913 }
6914 expect(type, loc) {
6915 if (!this.eat(type)) {
6916 this.unexpected(loc, type);
6917 }
6918 }
6919 tryParse(fn, oldState = this.state.clone()) {
6920 const abortSignal = {
6921 node: null
6922 };
6923 try {
6924 const node = fn((node = null) => {
6925 abortSignal.node = node;
6926 throw abortSignal;
6927 });
6928 if (this.state.errors.length > oldState.errors.length) {
6929 const failState = this.state;
6930 this.state = oldState;
6931 this.state.tokensLength = failState.tokensLength;
6932 return {
6933 node,
6934 error: failState.errors[oldState.errors.length],
6935 thrown: false,
6936 aborted: false,
6937 failState
6938 };
6939 }
6940 return {
6941 node: node,
6942 error: null,
6943 thrown: false,
6944 aborted: false,
6945 failState: null
6946 };
6947 } catch (error) {
6948 const failState = this.state;
6949 this.state = oldState;
6950 if (error instanceof SyntaxError) {
6951 return {
6952 node: null,
6953 error,
6954 thrown: true,
6955 aborted: false,
6956 failState
6957 };
6958 }
6959 if (error === abortSignal) {
6960 return {
6961 node: abortSignal.node,
6962 error: null,
6963 thrown: false,
6964 aborted: true,
6965 failState
6966 };
6967 }
6968 throw error;
6969 }
6970 }
6971 checkExpressionErrors(refExpressionErrors, andThrow) {
6972 if (!refExpressionErrors) return false;
6973 const {
6974 shorthandAssignLoc,
6975 doubleProtoLoc,
6976 privateKeyLoc,
6977 optionalParametersLoc,
6978 voidPatternLoc
6979 } = refExpressionErrors;
6980 const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc || !!voidPatternLoc;
6981 if (!andThrow) {
6982 return hasErrors;
6983 }
6984 if (shorthandAssignLoc != null) {
6985 this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
6986 }
6987 if (doubleProtoLoc != null) {
6988 this.raise(Errors.DuplicateProto, doubleProtoLoc);
6989 }
6990 if (privateKeyLoc != null) {
6991 this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
6992 }
6993 if (optionalParametersLoc != null) {
6994 this.unexpected(optionalParametersLoc);
6995 }
6996 if (voidPatternLoc != null) {
6997 this.raise(Errors.InvalidCoverDiscardElement, voidPatternLoc);
6998 }
6999 }
7000 isLiteralPropertyName() {
7001 return tokenIsLiteralPropertyName(this.state.type);
7002 }
7003 isPrivateName(node) {
7004 return node.type === "PrivateName";
7005 }
7006 getPrivateNameSV(node) {
7007 return node.id.name;
7008 }
7009 hasPropertyAsPrivateName(node) {
7010 return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
7011 }
7012 isObjectProperty(node) {
7013 return node.type === "ObjectProperty";
7014 }
7015 isObjectMethod(node) {
7016 return node.type === "ObjectMethod";
7017 }
7018 initializeScopes(inModule = this.options.sourceType === "module") {
7019 const oldLabels = this.state.labels;
7020 this.state.labels = [];
7021 const oldExportedIdentifiers = this.exportedIdentifiers;
7022 this.exportedIdentifiers = new Set();
7023 const oldInModule = this.inModule;
7024 this.inModule = inModule;
7025 const oldScope = this.scope;
7026 const ScopeHandler = this.getScopeHandler();
7027 this.scope = new ScopeHandler(this, inModule);
7028 const oldProdParam = this.prodParam;
7029 this.prodParam = new ProductionParameterHandler();
7030 const oldClassScope = this.classScope;
7031 this.classScope = new ClassScopeHandler(this);
7032 const oldExpressionScope = this.expressionScope;
7033 this.expressionScope = new ExpressionScopeHandler(this);
7034 return () => {
7035 this.state.labels = oldLabels;
7036 this.exportedIdentifiers = oldExportedIdentifiers;
7037 this.inModule = oldInModule;
7038 this.scope = oldScope;
7039 this.prodParam = oldProdParam;
7040 this.classScope = oldClassScope;
7041 this.expressionScope = oldExpressionScope;
7042 };
7043 }
7044 enterInitialScopes() {
7045 let paramFlags = 0;
7046 if (this.inModule || this.optionFlags & 1) {
7047 paramFlags |= 2;
7048 }
7049 if (this.optionFlags & 32) {
7050 paramFlags |= 1;
7051 }
7052 const isCommonJS = !this.inModule && this.options.sourceType === "commonjs";
7053 if (isCommonJS || this.optionFlags & 2) {
7054 paramFlags |= 4;
7055 }
7056 this.prodParam.enter(paramFlags);
7057 let scopeFlags = isCommonJS ? 514 : 1;
7058 if (this.optionFlags & 4) {
7059 scopeFlags |= 512;
7060 }
7061 this.scope.enter(scopeFlags);
7062 }
7063 checkDestructuringPrivate(refExpressionErrors) {
7064 const {
7065 privateKeyLoc
7066 } = refExpressionErrors;
7067 if (privateKeyLoc !== null) {
7068 this.expectPlugin("destructuringPrivate", privateKeyLoc);
7069 }
7070 }
7071}
7072class ExpressionErrors {
7073 constructor() {
7074 this.shorthandAssignLoc = null;
7075 this.doubleProtoLoc = null;
7076 this.privateKeyLoc = null;
7077 this.optionalParametersLoc = null;
7078 this.voidPatternLoc = null;
7079 }
7080}
7081class Node {
7082 constructor(parser, pos, loc) {
7083 this.type = "";
7084 this.start = pos;
7085 this.end = 0;
7086 this.loc = new SourceLocation(loc);
7087 if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
7088 if (parser != null && parser.filename) this.loc.filename = parser.filename;
7089 }
7090}
7091const NodePrototype = Node.prototype;
7092NodePrototype.__clone = function () {
7093 const newNode = new Node(undefined, this.start, this.loc.start);
7094 const keys = Object.keys(this);
7095 for (let i = 0, length = keys.length; i < length; i++) {
7096 const key = keys[i];
7097 if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
7098 newNode[key] = this[key];
7099 }
7100 }
7101 return newNode;
7102};
7103class NodeUtils extends UtilParser {
7104 startNode() {
7105 const loc = this.state.startLoc;
7106 return new Node(this, loc.index, loc);
7107 }
7108 startNodeAt(loc) {
7109 return new Node(this, loc.index, loc);
7110 }
7111 startNodeAtNode(type) {
7112 return this.startNodeAt(type.loc.start);
7113 }
7114 finishNode(node, type) {
7115 return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
7116 }
7117 finishNodeAt(node, type, endLoc) {
7118 node.type = type;
7119 node.end = endLoc.index;
7120 node.loc.end = endLoc;
7121 if (this.optionFlags & 128) node.range[1] = endLoc.index;
7122 if (this.optionFlags & 4096) {
7123 this.processComment(node);
7124 }
7125 return node;
7126 }
7127 resetStartLocation(node, startLoc) {
7128 node.start = startLoc.index;
7129 node.loc.start = startLoc;
7130 if (this.optionFlags & 128) node.range[0] = startLoc.index;
7131 }
7132 resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
7133 node.end = endLoc.index;
7134 node.loc.end = endLoc;
7135 if (this.optionFlags & 128) node.range[1] = endLoc.index;
7136 }
7137 resetStartLocationFromNode(node, locationNode) {
7138 this.resetStartLocation(node, locationNode.loc.start);
7139 }
7140 castNodeTo(node, type) {
7141 node.type = type;
7142 return node;
7143 }
7144 cloneIdentifier(node) {
7145 const {
7146 type,
7147 start,
7148 end,
7149 loc,
7150 range,
7151 name
7152 } = node;
7153 const cloned = Object.create(NodePrototype);
7154 cloned.type = type;
7155 cloned.start = start;
7156 cloned.end = end;
7157 cloned.loc = loc;
7158 cloned.range = range;
7159 cloned.name = name;
7160 if (node.extra) cloned.extra = node.extra;
7161 return cloned;
7162 }
7163 cloneStringLiteral(node) {
7164 const {
7165 type,
7166 start,
7167 end,
7168 loc,
7169 range,
7170 extra
7171 } = node;
7172 const cloned = Object.create(NodePrototype);
7173 cloned.type = type;
7174 cloned.start = start;
7175 cloned.end = end;
7176 cloned.loc = loc;
7177 cloned.range = range;
7178 cloned.extra = extra;
7179 cloned.value = node.value;
7180 return cloned;
7181 }
7182}
7183const unwrapParenthesizedExpression = node => {
7184 return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
7185};
7186class LValParser extends NodeUtils {
7187 toAssignable(node, isLHS = false) {
7188 var _node$extra, _node$extra3;
7189 let parenthesized = undefined;
7190 if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
7191 parenthesized = unwrapParenthesizedExpression(node);
7192 if (isLHS) {
7193 if (parenthesized.type === "Identifier") {
7194 this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
7195 } else if (parenthesized.type !== "CallExpression" && parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
7196 this.raise(Errors.InvalidParenthesizedAssignment, node);
7197 }
7198 } else {
7199 this.raise(Errors.InvalidParenthesizedAssignment, node);
7200 }
7201 }
7202 switch (node.type) {
7203 case "Identifier":
7204 case "ObjectPattern":
7205 case "ArrayPattern":
7206 case "AssignmentPattern":
7207 case "RestElement":
7208 case "VoidPattern":
7209 break;
7210 case "ObjectExpression":
7211 this.castNodeTo(node, "ObjectPattern");
7212 for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
7213 var _node$extra2;
7214 const prop = node.properties[i];
7215 const isLast = i === last;
7216 this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
7217 if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
7218 this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
7219 }
7220 }
7221 break;
7222 case "ObjectProperty":
7223 {
7224 const {
7225 key,
7226 value
7227 } = node;
7228 if (this.isPrivateName(key)) {
7229 this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
7230 }
7231 this.toAssignable(value, isLHS);
7232 break;
7233 }
7234 case "SpreadElement":
7235 {
7236 throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
7237 }
7238 case "ArrayExpression":
7239 this.castNodeTo(node, "ArrayPattern");
7240 this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
7241 break;
7242 case "AssignmentExpression":
7243 if (node.operator !== "=") {
7244 this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
7245 }
7246 this.castNodeTo(node, "AssignmentPattern");
7247 delete node.operator;
7248 if (node.left.type === "VoidPattern") {
7249 this.raise(Errors.VoidPatternInitializer, node.left);
7250 }
7251 this.toAssignable(node.left, isLHS);
7252 break;
7253 case "ParenthesizedExpression":
7254 this.toAssignable(parenthesized, isLHS);
7255 break;
7256 }
7257 }
7258 toAssignableObjectExpressionProp(prop, isLast, isLHS) {
7259 if (prop.type === "ObjectMethod") {
7260 this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
7261 } else if (prop.type === "SpreadElement") {
7262 this.castNodeTo(prop, "RestElement");
7263 const arg = prop.argument;
7264 this.checkToRestConversion(arg, false);
7265 this.toAssignable(arg, isLHS);
7266 if (!isLast) {
7267 this.raise(Errors.RestTrailingComma, prop);
7268 }
7269 } else {
7270 this.toAssignable(prop, isLHS);
7271 }
7272 }
7273 toAssignableList(exprList, trailingCommaLoc, isLHS) {
7274 const end = exprList.length - 1;
7275 for (let i = 0; i <= end; i++) {
7276 const elt = exprList[i];
7277 if (!elt) continue;
7278 this.toAssignableListItem(exprList, i, isLHS);
7279 if (elt.type === "RestElement") {
7280 if (i < end) {
7281 this.raise(Errors.RestTrailingComma, elt);
7282 } else if (trailingCommaLoc) {
7283 this.raise(Errors.RestTrailingComma, trailingCommaLoc);
7284 }
7285 }
7286 }
7287 }
7288 toAssignableListItem(exprList, index, isLHS) {
7289 const node = exprList[index];
7290 if (node.type === "SpreadElement") {
7291 this.castNodeTo(node, "RestElement");
7292 const arg = node.argument;
7293 this.checkToRestConversion(arg, true);
7294 this.toAssignable(arg, isLHS);
7295 } else {
7296 this.toAssignable(node, isLHS);
7297 }
7298 }
7299 isAssignable(node, isBinding) {
7300 switch (node.type) {
7301 case "Identifier":
7302 case "ObjectPattern":
7303 case "ArrayPattern":
7304 case "AssignmentPattern":
7305 case "RestElement":
7306 case "VoidPattern":
7307 return true;
7308 case "ObjectExpression":
7309 {
7310 const last = node.properties.length - 1;
7311 return node.properties.every((prop, i) => {
7312 return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
7313 });
7314 }
7315 case "ObjectProperty":
7316 return this.isAssignable(node.value);
7317 case "SpreadElement":
7318 return this.isAssignable(node.argument);
7319 case "ArrayExpression":
7320 return node.elements.every(element => element === null || this.isAssignable(element));
7321 case "AssignmentExpression":
7322 return node.operator === "=";
7323 case "ParenthesizedExpression":
7324 return this.isAssignable(node.expression);
7325 case "MemberExpression":
7326 case "OptionalMemberExpression":
7327 return !isBinding;
7328 default:
7329 return false;
7330 }
7331 }
7332 toReferencedList(exprList, isParenthesizedExpr) {
7333 return exprList;
7334 }
7335 toReferencedListDeep(exprList, isParenthesizedExpr) {
7336 this.toReferencedList(exprList, isParenthesizedExpr);
7337 for (const expr of exprList) {
7338 if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
7339 this.toReferencedListDeep(expr.elements);
7340 }
7341 }
7342 }
7343 parseSpread(refExpressionErrors) {
7344 const node = this.startNode();
7345 this.next();
7346 node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
7347 return this.finishNode(node, "SpreadElement");
7348 }
7349 parseRestBinding() {
7350 const node = this.startNode();
7351 this.next();
7352 const argument = this.parseBindingAtom();
7353 if (argument.type === "VoidPattern") {
7354 this.raise(Errors.UnexpectedVoidPattern, argument);
7355 }
7356 node.argument = argument;
7357 return this.finishNode(node, "RestElement");
7358 }
7359 parseBindingAtom() {
7360 switch (this.state.type) {
7361 case 0:
7362 {
7363 const node = this.startNode();
7364 this.next();
7365 node.elements = this.parseBindingList(3, 93, 1);
7366 return this.finishNode(node, "ArrayPattern");
7367 }
7368 case 5:
7369 return this.parseObjectLike(8, true);
7370 case 88:
7371 return this.parseVoidPattern(null);
7372 }
7373 return this.parseIdentifier();
7374 }
7375 parseBindingList(close, closeCharCode, flags) {
7376 const allowEmpty = flags & 1;
7377 const elts = [];
7378 let first = true;
7379 while (!this.eat(close)) {
7380 if (first) {
7381 first = false;
7382 } else {
7383 this.expect(12);
7384 }
7385 if (allowEmpty && this.match(12)) {
7386 elts.push(null);
7387 } else if (this.eat(close)) {
7388 break;
7389 } else if (this.match(21)) {
7390 let rest = this.parseRestBinding();
7391 if (this.hasPlugin("flow") || flags & 2) {
7392 rest = this.parseFunctionParamType(rest);
7393 }
7394 elts.push(rest);
7395 if (!this.checkCommaAfterRest(closeCharCode)) {
7396 this.expect(close);
7397 break;
7398 }
7399 } else {
7400 const decorators = [];
7401 if (flags & 2) {
7402 if (this.match(26) && this.hasPlugin("decorators")) {
7403 this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
7404 }
7405 while (this.match(26)) {
7406 decorators.push(this.parseDecorator());
7407 }
7408 }
7409 elts.push(this.parseBindingElement(flags, decorators));
7410 }
7411 }
7412 return elts;
7413 }
7414 parseBindingRestProperty(prop) {
7415 this.next();
7416 if (this.hasPlugin("discardBinding") && this.match(88)) {
7417 prop.argument = this.parseVoidPattern(null);
7418 this.raise(Errors.UnexpectedVoidPattern, prop.argument);
7419 } else {
7420 prop.argument = this.parseIdentifier();
7421 }
7422 this.checkCommaAfterRest(125);
7423 return this.finishNode(prop, "RestElement");
7424 }
7425 parseBindingProperty() {
7426 const {
7427 type,
7428 startLoc
7429 } = this.state;
7430 if (type === 21) {
7431 return this.parseBindingRestProperty(this.startNode());
7432 }
7433 const prop = this.startNode();
7434 if (type === 139) {
7435 this.expectPlugin("destructuringPrivate", startLoc);
7436 this.classScope.usePrivateName(this.state.value, startLoc);
7437 prop.key = this.parsePrivateName();
7438 } else {
7439 this.parsePropertyName(prop);
7440 }
7441 prop.method = false;
7442 return this.parseObjPropValue(prop, startLoc, false, false, true, false);
7443 }
7444 parseBindingElement(flags, decorators) {
7445 const left = this.parseMaybeDefault();
7446 if (this.hasPlugin("flow") || flags & 2) {
7447 this.parseFunctionParamType(left);
7448 }
7449 if (decorators.length) {
7450 left.decorators = decorators;
7451 this.resetStartLocationFromNode(left, decorators[0]);
7452 }
7453 const elt = this.parseMaybeDefault(left.loc.start, left);
7454 return elt;
7455 }
7456 parseFunctionParamType(param) {
7457 return param;
7458 }
7459 parseMaybeDefault(startLoc, left) {
7460 startLoc != null ? startLoc : startLoc = this.state.startLoc;
7461 left = left != null ? left : this.parseBindingAtom();
7462 if (!this.eat(29)) return left;
7463 const node = this.startNodeAt(startLoc);
7464 if (left.type === "VoidPattern") {
7465 this.raise(Errors.VoidPatternInitializer, left);
7466 }
7467 node.left = left;
7468 node.right = this.parseMaybeAssignAllowIn();
7469 return this.finishNode(node, "AssignmentPattern");
7470 }
7471 isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
7472 switch (type) {
7473 case "AssignmentPattern":
7474 return "left";
7475 case "RestElement":
7476 return "argument";
7477 case "ObjectProperty":
7478 return "value";
7479 case "ParenthesizedExpression":
7480 return "expression";
7481 case "ArrayPattern":
7482 return "elements";
7483 case "ObjectPattern":
7484 return "properties";
7485 case "VoidPattern":
7486 return true;
7487 case "CallExpression":
7488 if (!disallowCallExpression && !this.state.strict && this.optionFlags & 8192) {
7489 return true;
7490 }
7491 }
7492 return false;
7493 }
7494 isOptionalMemberExpression(expression) {
7495 return expression.type === "OptionalMemberExpression";
7496 }
7497 checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false, disallowCallExpression = false) {
7498 var _expression$extra;
7499 const type = expression.type;
7500 if (this.isObjectMethod(expression)) return;
7501 const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
7502 if (isOptionalMemberExpression || type === "MemberExpression") {
7503 if (isOptionalMemberExpression) {
7504 this.expectPlugin("optionalChainingAssign", expression.loc.start);
7505 if (ancestor.type !== "AssignmentExpression") {
7506 this.raise(Errors.InvalidLhsOptionalChaining, expression, {
7507 ancestor
7508 });
7509 }
7510 }
7511 if (binding !== 64) {
7512 this.raise(Errors.InvalidPropertyBindingPattern, expression);
7513 }
7514 return;
7515 }
7516 if (type === "Identifier") {
7517 this.checkIdentifier(expression, binding, strictModeChanged);
7518 const {
7519 name
7520 } = expression;
7521 if (checkClashes) {
7522 if (checkClashes.has(name)) {
7523 this.raise(Errors.ParamDupe, expression);
7524 } else {
7525 checkClashes.add(name);
7526 }
7527 }
7528 return;
7529 } else if (type === "VoidPattern" && ancestor.type === "CatchClause") {
7530 this.raise(Errors.VoidPatternCatchClauseParam, expression);
7531 }
7532 const unwrappedExpression = unwrapParenthesizedExpression(expression);
7533 disallowCallExpression || (disallowCallExpression = unwrappedExpression.type === "CallExpression" && (unwrappedExpression.callee.type === "Import" || unwrappedExpression.callee.type === "Super"));
7534 const validity = this.isValidLVal(type, disallowCallExpression, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
7535 if (validity === true) return;
7536 if (validity === false) {
7537 const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
7538 this.raise(ParseErrorClass, expression, {
7539 ancestor
7540 });
7541 return;
7542 }
7543 let key, isParenthesizedExpression;
7544 if (typeof validity === "string") {
7545 key = validity;
7546 isParenthesizedExpression = type === "ParenthesizedExpression";
7547 } else {
7548 [key, isParenthesizedExpression] = validity;
7549 }
7550 const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
7551 type
7552 } : ancestor;
7553 const val = expression[key];
7554 if (Array.isArray(val)) {
7555 for (const child of val) {
7556 if (child) {
7557 this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, true);
7558 }
7559 }
7560 } else if (val) {
7561 this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, disallowCallExpression);
7562 }
7563 }
7564 checkIdentifier(at, bindingType, strictModeChanged = false) {
7565 if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
7566 if (bindingType === 64) {
7567 this.raise(Errors.StrictEvalArguments, at, {
7568 referenceName: at.name
7569 });
7570 } else {
7571 this.raise(Errors.StrictEvalArgumentsBinding, at, {
7572 bindingName: at.name
7573 });
7574 }
7575 }
7576 if (bindingType & 8192 && at.name === "let") {
7577 this.raise(Errors.LetInLexicalBinding, at);
7578 }
7579 if (!(bindingType & 64)) {
7580 this.declareNameFromIdentifier(at, bindingType);
7581 }
7582 }
7583 declareNameFromIdentifier(identifier, binding) {
7584 this.scope.declareName(identifier.name, binding, identifier.loc.start);
7585 }
7586 checkToRestConversion(node, allowPattern) {
7587 switch (node.type) {
7588 case "ParenthesizedExpression":
7589 this.checkToRestConversion(node.expression, allowPattern);
7590 break;
7591 case "Identifier":
7592 case "MemberExpression":
7593 break;
7594 case "ArrayExpression":
7595 case "ObjectExpression":
7596 if (allowPattern) break;
7597 default:
7598 this.raise(Errors.InvalidRestAssignmentPattern, node);
7599 }
7600 }
7601 checkCommaAfterRest(close) {
7602 if (!this.match(12)) {
7603 return false;
7604 }
7605 this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
7606 return true;
7607 }
7608}
7609const keywordAndTSRelationalOperator = /in(?:stanceof)?|as|satisfies/y;
7610function nonNull(x) {
7611 if (x == null) {
7612 throw new Error(`Unexpected ${x} value.`);
7613 }
7614 return x;
7615}
7616function assert(x) {
7617 if (!x) {
7618 throw new Error("Assert fail");
7619 }
7620}
7621const TSErrors = ParseErrorEnum`typescript`({
7622 AbstractMethodHasImplementation: ({
7623 methodName
7624 }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
7625 AbstractPropertyHasInitializer: ({
7626 propertyName
7627 }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
7628 AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
7629 AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
7630 AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
7631 ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
7632 ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
7633 ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
7634 ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
7635 DeclareAccessor: ({
7636 kind
7637 }) => `'declare' is not allowed in ${kind}ters.`,
7638 DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
7639 DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
7640 DuplicateAccessibilityModifier: ({
7641 modifier
7642 }) => `Accessibility modifier already seen: '${modifier}'.`,
7643 DuplicateModifier: ({
7644 modifier
7645 }) => `Duplicate modifier: '${modifier}'.`,
7646 EmptyHeritageClauseType: ({
7647 token
7648 }) => `'${token}' list cannot be empty.`,
7649 EmptyTypeArguments: "Type argument list cannot be empty.",
7650 EmptyTypeParameters: "Type parameter list cannot be empty.",
7651 ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
7652 ImportAliasHasImportType: "An import alias can not use 'import type'.",
7653 ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
7654 IncompatibleModifiers: ({
7655 modifiers
7656 }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
7657 IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
7658 IndexSignatureHasAccessibility: ({
7659 modifier
7660 }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
7661 IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
7662 IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
7663 IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
7664 InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
7665 InvalidHeritageClauseType: ({
7666 token
7667 }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
7668 InvalidModifierOnAwaitUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on an await using declaration.`,
7669 InvalidModifierOnTypeMember: ({
7670 modifier
7671 }) => `'${modifier}' modifier cannot appear on a type member.`,
7672 InvalidModifierOnTypeParameter: ({
7673 modifier
7674 }) => `'${modifier}' modifier cannot appear on a type parameter.`,
7675 InvalidModifierOnTypeParameterPositions: ({
7676 modifier
7677 }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
7678 InvalidModifierOnUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on a using declaration.`,
7679 InvalidModifiersOrder: ({
7680 orderedModifiers
7681 }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
7682 InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
7683 InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
7684 MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
7685 NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
7686 NonClassMethodPropertyHasAbstractModifier: "'abstract' modifier can only appear on a class, method, or property declaration.",
7687 OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
7688 OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
7689 PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
7690 PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
7691 PrivateElementHasAccessibility: ({
7692 modifier
7693 }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
7694 ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
7695 ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
7696 ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
7697 SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
7698 SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
7699 SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
7700 SingleTypeParameterWithoutTrailingComma: ({
7701 typeParameterName
7702 }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
7703 StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
7704 TupleOptionalAfterType: "A labeled tuple optional element must be declared using a question mark after the name and before the colon (`name?: type`), rather than after the type (`name: type?`).",
7705 TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
7706 TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
7707 TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
7708 TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
7709 UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
7710 UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
7711 UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
7712 UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
7713 UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
7714 UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
7715 UnsupportedSignatureParameterKind: ({
7716 type
7717 }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`,
7718 UsingDeclarationInAmbientContext: kind => `'${kind}' declarations are not allowed in ambient contexts.`
7719});
7720function keywordTypeFromName(value) {
7721 switch (value) {
7722 case "any":
7723 return "TSAnyKeyword";
7724 case "boolean":
7725 return "TSBooleanKeyword";
7726 case "bigint":
7727 return "TSBigIntKeyword";
7728 case "never":
7729 return "TSNeverKeyword";
7730 case "number":
7731 return "TSNumberKeyword";
7732 case "object":
7733 return "TSObjectKeyword";
7734 case "string":
7735 return "TSStringKeyword";
7736 case "symbol":
7737 return "TSSymbolKeyword";
7738 case "undefined":
7739 return "TSUndefinedKeyword";
7740 case "unknown":
7741 return "TSUnknownKeyword";
7742 default:
7743 return undefined;
7744 }
7745}
7746function tsIsAccessModifier(modifier) {
7747 return modifier === "private" || modifier === "public" || modifier === "protected";
7748}
7749function tsIsVarianceAnnotations(modifier) {
7750 return modifier === "in" || modifier === "out";
7751}
7752var typescript = superClass => class TypeScriptParserMixin extends superClass {
7753 constructor(...args) {
7754 super(...args);
7755 this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
7756 allowedModifiers: ["in", "out"],
7757 disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
7758 errorTemplate: TSErrors.InvalidModifierOnTypeParameter
7759 });
7760 this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
7761 allowedModifiers: ["const"],
7762 disallowedModifiers: ["in", "out"],
7763 errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
7764 });
7765 this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
7766 allowedModifiers: ["in", "out", "const"],
7767 disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
7768 errorTemplate: TSErrors.InvalidModifierOnTypeParameter
7769 });
7770 }
7771 getScopeHandler() {
7772 return TypeScriptScopeHandler;
7773 }
7774 tsIsIdentifier() {
7775 return tokenIsIdentifier(this.state.type);
7776 }
7777 tsTokenCanFollowModifier() {
7778 return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
7779 }
7780 tsNextTokenOnSameLineAndCanFollowModifier() {
7781 this.next();
7782 if (this.hasPrecedingLineBreak()) {
7783 return false;
7784 }
7785 return this.tsTokenCanFollowModifier();
7786 }
7787 tsNextTokenCanFollowModifier() {
7788 if (this.match(106)) {
7789 this.next();
7790 return this.tsTokenCanFollowModifier();
7791 }
7792 return this.tsNextTokenOnSameLineAndCanFollowModifier();
7793 }
7794 tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
7795 if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
7796 return undefined;
7797 }
7798 const modifier = this.state.value;
7799 if (allowedModifiers.includes(modifier)) {
7800 if (hasSeenStaticModifier && this.match(106)) {
7801 return undefined;
7802 }
7803 if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
7804 return undefined;
7805 }
7806 if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
7807 return modifier;
7808 }
7809 }
7810 return undefined;
7811 }
7812 tsParseModifiers({
7813 allowedModifiers,
7814 disallowedModifiers,
7815 stopOnStartOfClassStaticBlock,
7816 errorTemplate = TSErrors.InvalidModifierOnTypeMember
7817 }, modified) {
7818 const enforceOrder = (loc, modifier, before, after) => {
7819 if (modifier === before && modified[after]) {
7820 this.raise(TSErrors.InvalidModifiersOrder, loc, {
7821 orderedModifiers: [before, after]
7822 });
7823 }
7824 };
7825 const incompatible = (loc, modifier, mod1, mod2) => {
7826 if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
7827 this.raise(TSErrors.IncompatibleModifiers, loc, {
7828 modifiers: [mod1, mod2]
7829 });
7830 }
7831 };
7832 for (;;) {
7833 const {
7834 startLoc
7835 } = this.state;
7836 const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock, modified.static);
7837 if (!modifier) break;
7838 if (tsIsAccessModifier(modifier)) {
7839 if (modified.accessibility) {
7840 this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
7841 modifier
7842 });
7843 } else {
7844 enforceOrder(startLoc, modifier, modifier, "override");
7845 enforceOrder(startLoc, modifier, modifier, "static");
7846 enforceOrder(startLoc, modifier, modifier, "readonly");
7847 modified.accessibility = modifier;
7848 }
7849 } else if (tsIsVarianceAnnotations(modifier)) {
7850 if (modified[modifier]) {
7851 this.raise(TSErrors.DuplicateModifier, startLoc, {
7852 modifier
7853 });
7854 }
7855 modified[modifier] = true;
7856 enforceOrder(startLoc, modifier, "in", "out");
7857 } else {
7858 if (hasOwnProperty.call(modified, modifier)) {
7859 this.raise(TSErrors.DuplicateModifier, startLoc, {
7860 modifier
7861 });
7862 } else {
7863 enforceOrder(startLoc, modifier, "static", "readonly");
7864 enforceOrder(startLoc, modifier, "static", "override");
7865 enforceOrder(startLoc, modifier, "override", "readonly");
7866 enforceOrder(startLoc, modifier, "abstract", "override");
7867 incompatible(startLoc, modifier, "declare", "override");
7868 incompatible(startLoc, modifier, "static", "abstract");
7869 }
7870 modified[modifier] = true;
7871 }
7872 if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
7873 this.raise(errorTemplate, startLoc, {
7874 modifier
7875 });
7876 }
7877 }
7878 }
7879 tsIsListTerminator(kind) {
7880 switch (kind) {
7881 case "EnumMembers":
7882 case "TypeMembers":
7883 return this.match(8);
7884 case "HeritageClauseElement":
7885 return this.match(5);
7886 case "TupleElementTypes":
7887 return this.match(3);
7888 case "TypeParametersOrArguments":
7889 return this.match(48);
7890 }
7891 }
7892 tsParseList(kind, parseElement) {
7893 const result = [];
7894 while (!this.tsIsListTerminator(kind)) {
7895 result.push(parseElement());
7896 }
7897 return result;
7898 }
7899 tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
7900 return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
7901 }
7902 tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
7903 const result = [];
7904 let trailingCommaPos = -1;
7905 for (;;) {
7906 if (this.tsIsListTerminator(kind)) {
7907 break;
7908 }
7909 trailingCommaPos = -1;
7910 const element = parseElement();
7911 if (element == null) {
7912 return undefined;
7913 }
7914 result.push(element);
7915 if (this.eat(12)) {
7916 trailingCommaPos = this.state.lastTokStartLoc.index;
7917 continue;
7918 }
7919 if (this.tsIsListTerminator(kind)) {
7920 break;
7921 }
7922 if (expectSuccess) {
7923 this.expect(12);
7924 }
7925 return undefined;
7926 }
7927 if (refTrailingCommaPos) {
7928 refTrailingCommaPos.value = trailingCommaPos;
7929 }
7930 return result;
7931 }
7932 tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
7933 if (!skipFirstToken) {
7934 if (bracket) {
7935 this.expect(0);
7936 } else {
7937 this.expect(47);
7938 }
7939 }
7940 const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
7941 if (bracket) {
7942 this.expect(3);
7943 } else {
7944 this.expect(48);
7945 }
7946 return result;
7947 }
7948 tsParseImportType() {
7949 const node = this.startNode();
7950 this.expect(83);
7951 this.expect(10);
7952 if (!this.match(134)) {
7953 this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
7954 node.argument = super.parseExprAtom();
7955 } else {
7956 node.argument = this.parseStringLiteral(this.state.value);
7957 }
7958 if (this.eat(12)) {
7959 node.options = this.tsParseImportTypeOptions();
7960 } else {
7961 node.options = null;
7962 }
7963 this.expect(11);
7964 if (this.eat(16)) {
7965 node.qualifier = this.tsParseEntityName(1 | 2);
7966 }
7967 if (this.match(47)) {
7968 node.typeParameters = this.tsParseTypeArguments();
7969 }
7970 return this.finishNode(node, "TSImportType");
7971 }
7972 tsParseImportTypeOptions() {
7973 const node = this.startNode();
7974 this.expect(5);
7975 const withProperty = this.startNode();
7976 if (this.isContextual(76)) {
7977 withProperty.method = false;
7978 withProperty.key = this.parseIdentifier(true);
7979 withProperty.computed = false;
7980 withProperty.shorthand = false;
7981 } else {
7982 this.unexpected(null, 76);
7983 }
7984 this.expect(14);
7985 withProperty.value = this.tsParseImportTypeWithPropertyValue();
7986 node.properties = [this.finishObjectProperty(withProperty)];
7987 this.eat(12);
7988 this.expect(8);
7989 return this.finishNode(node, "ObjectExpression");
7990 }
7991 tsParseImportTypeWithPropertyValue() {
7992 const node = this.startNode();
7993 const properties = [];
7994 this.expect(5);
7995 while (!this.match(8)) {
7996 const type = this.state.type;
7997 if (tokenIsIdentifier(type) || type === 134) {
7998 properties.push(super.parsePropertyDefinition(null));
7999 } else {
8000 this.unexpected();
8001 }
8002 this.eat(12);
8003 }
8004 node.properties = properties;
8005 this.next();
8006 return this.finishNode(node, "ObjectExpression");
8007 }
8008 tsParseEntityName(flags) {
8009 let entity;
8010 if (flags & 1 && this.match(78)) {
8011 if (flags & 2) {
8012 entity = this.parseIdentifier(true);
8013 } else {
8014 const node = this.startNode();
8015 this.next();
8016 entity = this.finishNode(node, "ThisExpression");
8017 }
8018 } else {
8019 entity = this.parseIdentifier(!!(flags & 1));
8020 }
8021 while (this.eat(16)) {
8022 const node = this.startNodeAtNode(entity);
8023 node.left = entity;
8024 node.right = this.parseIdentifier(!!(flags & 1));
8025 entity = this.finishNode(node, "TSQualifiedName");
8026 }
8027 return entity;
8028 }
8029 tsParseTypeReference() {
8030 const node = this.startNode();
8031 node.typeName = this.tsParseEntityName(1);
8032 if (!this.hasPrecedingLineBreak() && this.match(47)) {
8033 node.typeParameters = this.tsParseTypeArguments();
8034 }
8035 return this.finishNode(node, "TSTypeReference");
8036 }
8037 tsParseThisTypePredicate(lhs) {
8038 this.next();
8039 const node = this.startNodeAtNode(lhs);
8040 node.parameterName = lhs;
8041 node.typeAnnotation = this.tsParseTypeAnnotation(false);
8042 node.asserts = false;
8043 return this.finishNode(node, "TSTypePredicate");
8044 }
8045 tsParseThisTypeNode() {
8046 const node = this.startNode();
8047 this.next();
8048 return this.finishNode(node, "TSThisType");
8049 }
8050 tsParseTypeQuery() {
8051 const node = this.startNode();
8052 this.expect(87);
8053 if (this.match(83)) {
8054 node.exprName = this.tsParseImportType();
8055 } else {
8056 node.exprName = this.tsParseEntityName(1 | 2);
8057 }
8058 if (!this.hasPrecedingLineBreak() && this.match(47)) {
8059 node.typeParameters = this.tsParseTypeArguments();
8060 }
8061 return this.finishNode(node, "TSTypeQuery");
8062 }
8063 tsParseTypeParameter(parseModifiers) {
8064 const node = this.startNode();
8065 parseModifiers(node);
8066 node.name = this.tsParseTypeParameterName();
8067 node.constraint = this.tsEatThenParseType(81);
8068 node.default = this.tsEatThenParseType(29);
8069 return this.finishNode(node, "TSTypeParameter");
8070 }
8071 tsTryParseTypeParameters(parseModifiers) {
8072 if (this.match(47)) {
8073 return this.tsParseTypeParameters(parseModifiers);
8074 }
8075 }
8076 tsParseTypeParameters(parseModifiers) {
8077 const node = this.startNode();
8078 if (this.match(47) || this.match(143)) {
8079 this.next();
8080 } else {
8081 this.unexpected();
8082 }
8083 const refTrailingCommaPos = {
8084 value: -1
8085 };
8086 node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
8087 if (node.params.length === 0) {
8088 this.raise(TSErrors.EmptyTypeParameters, node);
8089 }
8090 if (refTrailingCommaPos.value !== -1) {
8091 this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
8092 }
8093 return this.finishNode(node, "TSTypeParameterDeclaration");
8094 }
8095 tsFillSignature(returnToken, signature) {
8096 const returnTokenRequired = returnToken === 19;
8097 const paramsKey = "parameters";
8098 const returnTypeKey = "typeAnnotation";
8099 signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
8100 this.expect(10);
8101 signature[paramsKey] = this.tsParseBindingListForSignature();
8102 if (returnTokenRequired) {
8103 signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
8104 } else if (this.match(returnToken)) {
8105 signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
8106 }
8107 }
8108 tsParseBindingListForSignature() {
8109 const list = super.parseBindingList(11, 41, 2);
8110 for (const pattern of list) {
8111 const {
8112 type
8113 } = pattern;
8114 if (type === "AssignmentPattern" || type === "TSParameterProperty") {
8115 this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
8116 type
8117 });
8118 }
8119 }
8120 return list;
8121 }
8122 tsParseTypeMemberSemicolon() {
8123 if (!this.eat(12) && !this.isLineTerminator()) {
8124 this.expect(13);
8125 }
8126 }
8127 tsParseSignatureMember(kind, node) {
8128 this.tsFillSignature(14, node);
8129 this.tsParseTypeMemberSemicolon();
8130 return this.finishNode(node, kind);
8131 }
8132 tsIsUnambiguouslyIndexSignature() {
8133 this.next();
8134 if (tokenIsIdentifier(this.state.type)) {
8135 this.next();
8136 return this.match(14);
8137 }
8138 return false;
8139 }
8140 tsTryParseIndexSignature(node) {
8141 if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
8142 return;
8143 }
8144 this.expect(0);
8145 const id = this.parseIdentifier();
8146 id.typeAnnotation = this.tsParseTypeAnnotation();
8147 this.resetEndLocation(id);
8148 this.expect(3);
8149 node.parameters = [id];
8150 const type = this.tsTryParseTypeAnnotation();
8151 if (type) node.typeAnnotation = type;
8152 this.tsParseTypeMemberSemicolon();
8153 return this.finishNode(node, "TSIndexSignature");
8154 }
8155 tsParsePropertyOrMethodSignature(node, readonly) {
8156 if (this.eat(17)) node.optional = true;
8157 if (this.match(10) || this.match(47)) {
8158 if (readonly) {
8159 this.raise(TSErrors.ReadonlyForMethodSignature, node);
8160 }
8161 const method = node;
8162 if (method.kind && this.match(47)) {
8163 this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
8164 }
8165 this.tsFillSignature(14, method);
8166 this.tsParseTypeMemberSemicolon();
8167 const paramsKey = "parameters";
8168 const returnTypeKey = "typeAnnotation";
8169 if (method.kind === "get") {
8170 if (method[paramsKey].length > 0) {
8171 this.raise(Errors.BadGetterArity, this.state.curPosition());
8172 if (this.isThisParam(method[paramsKey][0])) {
8173 this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
8174 }
8175 }
8176 } else if (method.kind === "set") {
8177 if (method[paramsKey].length !== 1) {
8178 this.raise(Errors.BadSetterArity, this.state.curPosition());
8179 } else {
8180 const firstParameter = method[paramsKey][0];
8181 if (this.isThisParam(firstParameter)) {
8182 this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
8183 }
8184 if (firstParameter.type === "Identifier" && firstParameter.optional) {
8185 this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
8186 }
8187 if (firstParameter.type === "RestElement") {
8188 this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
8189 }
8190 }
8191 if (method[returnTypeKey]) {
8192 this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
8193 }
8194 } else {
8195 method.kind = "method";
8196 }
8197 return this.finishNode(method, "TSMethodSignature");
8198 } else {
8199 const property = node;
8200 if (readonly) property.readonly = true;
8201 const type = this.tsTryParseTypeAnnotation();
8202 if (type) property.typeAnnotation = type;
8203 this.tsParseTypeMemberSemicolon();
8204 return this.finishNode(property, "TSPropertySignature");
8205 }
8206 }
8207 tsParseTypeMember() {
8208 const node = this.startNode();
8209 if (this.match(10) || this.match(47)) {
8210 return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
8211 }
8212 if (this.match(77)) {
8213 const id = this.startNode();
8214 this.next();
8215 if (this.match(10) || this.match(47)) {
8216 return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
8217 } else {
8218 node.key = this.createIdentifier(id, "new");
8219 return this.tsParsePropertyOrMethodSignature(node, false);
8220 }
8221 }
8222 this.tsParseModifiers({
8223 allowedModifiers: ["readonly"],
8224 disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
8225 }, node);
8226 const idx = this.tsTryParseIndexSignature(node);
8227 if (idx) {
8228 return idx;
8229 }
8230 super.parsePropertyName(node);
8231 if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
8232 node.kind = node.key.name;
8233 super.parsePropertyName(node);
8234 if (!this.match(10) && !this.match(47)) {
8235 this.unexpected(null, 10);
8236 }
8237 }
8238 return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
8239 }
8240 tsParseTypeLiteral() {
8241 const node = this.startNode();
8242 node.members = this.tsParseObjectTypeMembers();
8243 return this.finishNode(node, "TSTypeLiteral");
8244 }
8245 tsParseObjectTypeMembers() {
8246 this.expect(5);
8247 const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
8248 this.expect(8);
8249 return members;
8250 }
8251 tsIsStartOfMappedType() {
8252 this.next();
8253 if (this.eat(53)) {
8254 return this.isContextual(122);
8255 }
8256 if (this.isContextual(122)) {
8257 this.next();
8258 }
8259 if (!this.match(0)) {
8260 return false;
8261 }
8262 this.next();
8263 if (!this.tsIsIdentifier()) {
8264 return false;
8265 }
8266 this.next();
8267 return this.match(58);
8268 }
8269 tsParseMappedType() {
8270 const node = this.startNode();
8271 this.expect(5);
8272 if (this.match(53)) {
8273 node.readonly = this.state.value;
8274 this.next();
8275 this.expectContextual(122);
8276 } else if (this.eatContextual(122)) {
8277 node.readonly = true;
8278 }
8279 this.expect(0);
8280 const typeParameter = this.startNode();
8281 typeParameter.name = this.tsParseTypeParameterName();
8282 typeParameter.constraint = this.tsExpectThenParseType(58);
8283 node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
8284 node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
8285 this.expect(3);
8286 if (this.match(53)) {
8287 node.optional = this.state.value;
8288 this.next();
8289 this.expect(17);
8290 } else if (this.eat(17)) {
8291 node.optional = true;
8292 }
8293 node.typeAnnotation = this.tsTryParseType();
8294 this.semicolon();
8295 this.expect(8);
8296 return this.finishNode(node, "TSMappedType");
8297 }
8298 tsParseTupleType() {
8299 const node = this.startNode();
8300 node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
8301 let seenOptionalElement = false;
8302 node.elementTypes.forEach(elementNode => {
8303 const {
8304 type
8305 } = elementNode;
8306 if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
8307 this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
8308 }
8309 seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
8310 });
8311 return this.finishNode(node, "TSTupleType");
8312 }
8313 tsParseTupleElementType() {
8314 const restStartLoc = this.state.startLoc;
8315 const rest = this.eat(21);
8316 const {
8317 startLoc
8318 } = this.state;
8319 let labeled;
8320 let label;
8321 let optional;
8322 let type;
8323 const isWord = tokenIsKeywordOrIdentifier(this.state.type);
8324 const chAfterWord = isWord ? this.lookaheadCharCode() : null;
8325 if (chAfterWord === 58) {
8326 labeled = true;
8327 optional = false;
8328 label = this.parseIdentifier(true);
8329 this.expect(14);
8330 type = this.tsParseType();
8331 } else if (chAfterWord === 63) {
8332 optional = true;
8333 const wordName = this.state.value;
8334 const typeOrLabel = this.tsParseNonArrayType();
8335 if (this.lookaheadCharCode() === 58) {
8336 labeled = true;
8337 label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
8338 this.expect(17);
8339 this.expect(14);
8340 type = this.tsParseType();
8341 } else {
8342 labeled = false;
8343 type = typeOrLabel;
8344 this.expect(17);
8345 }
8346 } else {
8347 type = this.tsParseType();
8348 optional = this.eat(17);
8349 labeled = this.eat(14);
8350 }
8351 if (labeled) {
8352 let labeledNode;
8353 if (label) {
8354 labeledNode = this.startNodeAt(startLoc);
8355 labeledNode.optional = optional;
8356 labeledNode.label = label;
8357 labeledNode.elementType = type;
8358 if (this.eat(17)) {
8359 labeledNode.optional = true;
8360 this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
8361 }
8362 } else {
8363 labeledNode = this.startNodeAt(startLoc);
8364 labeledNode.optional = optional;
8365 this.raise(TSErrors.InvalidTupleMemberLabel, type);
8366 labeledNode.label = type;
8367 labeledNode.elementType = this.tsParseType();
8368 }
8369 type = this.finishNode(labeledNode, "TSNamedTupleMember");
8370 } else if (optional) {
8371 const optionalTypeNode = this.startNodeAt(startLoc);
8372 optionalTypeNode.typeAnnotation = type;
8373 type = this.finishNode(optionalTypeNode, "TSOptionalType");
8374 }
8375 if (rest) {
8376 const restNode = this.startNodeAt(restStartLoc);
8377 restNode.typeAnnotation = type;
8378 type = this.finishNode(restNode, "TSRestType");
8379 }
8380 return type;
8381 }
8382 tsParseParenthesizedType() {
8383 const node = this.startNode();
8384 this.expect(10);
8385 node.typeAnnotation = this.tsParseType();
8386 this.expect(11);
8387 return this.finishNode(node, "TSParenthesizedType");
8388 }
8389 tsParseFunctionOrConstructorType(type, abstract) {
8390 const node = this.startNode();
8391 if (type === "TSConstructorType") {
8392 node.abstract = !!abstract;
8393 if (abstract) this.next();
8394 this.next();
8395 }
8396 this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
8397 return this.finishNode(node, type);
8398 }
8399 tsParseLiteralTypeNode() {
8400 const node = this.startNode();
8401 switch (this.state.type) {
8402 case 135:
8403 case 136:
8404 case 134:
8405 case 85:
8406 case 86:
8407 node.literal = super.parseExprAtom();
8408 break;
8409 default:
8410 this.unexpected();
8411 }
8412 return this.finishNode(node, "TSLiteralType");
8413 }
8414 tsParseTemplateLiteralType() {
8415 const node = this.startNode();
8416 node.literal = super.parseTemplate(false);
8417 return this.finishNode(node, "TSLiteralType");
8418 }
8419 parseTemplateSubstitution() {
8420 if (this.state.inType) return this.tsParseType();
8421 return super.parseTemplateSubstitution();
8422 }
8423 tsParseThisTypeOrThisTypePredicate() {
8424 const thisKeyword = this.tsParseThisTypeNode();
8425 if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
8426 return this.tsParseThisTypePredicate(thisKeyword);
8427 } else {
8428 return thisKeyword;
8429 }
8430 }
8431 tsParseNonArrayType() {
8432 switch (this.state.type) {
8433 case 134:
8434 case 135:
8435 case 136:
8436 case 85:
8437 case 86:
8438 return this.tsParseLiteralTypeNode();
8439 case 53:
8440 if (this.state.value === "-") {
8441 const node = this.startNode();
8442 const nextToken = this.lookahead();
8443 if (nextToken.type !== 135 && nextToken.type !== 136) {
8444 this.unexpected();
8445 }
8446 node.literal = this.parseMaybeUnary();
8447 return this.finishNode(node, "TSLiteralType");
8448 }
8449 break;
8450 case 78:
8451 return this.tsParseThisTypeOrThisTypePredicate();
8452 case 87:
8453 return this.tsParseTypeQuery();
8454 case 83:
8455 return this.tsParseImportType();
8456 case 5:
8457 return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
8458 case 0:
8459 return this.tsParseTupleType();
8460 case 10:
8461 return this.tsParseParenthesizedType();
8462 case 25:
8463 case 24:
8464 return this.tsParseTemplateLiteralType();
8465 default:
8466 {
8467 const {
8468 type
8469 } = this.state;
8470 if (tokenIsIdentifier(type) || type === 88 || type === 84) {
8471 const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
8472 if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
8473 const node = this.startNode();
8474 this.next();
8475 return this.finishNode(node, nodeType);
8476 }
8477 return this.tsParseTypeReference();
8478 }
8479 }
8480 }
8481 throw this.unexpected();
8482 }
8483 tsParseArrayTypeOrHigher() {
8484 const {
8485 startLoc
8486 } = this.state;
8487 let type = this.tsParseNonArrayType();
8488 while (!this.hasPrecedingLineBreak() && this.eat(0)) {
8489 if (this.match(3)) {
8490 const node = this.startNodeAt(startLoc);
8491 node.elementType = type;
8492 this.expect(3);
8493 type = this.finishNode(node, "TSArrayType");
8494 } else {
8495 const node = this.startNodeAt(startLoc);
8496 node.objectType = type;
8497 node.indexType = this.tsParseType();
8498 this.expect(3);
8499 type = this.finishNode(node, "TSIndexedAccessType");
8500 }
8501 }
8502 return type;
8503 }
8504 tsParseTypeOperator() {
8505 const node = this.startNode();
8506 const operator = this.state.value;
8507 this.next();
8508 node.operator = operator;
8509 node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
8510 if (operator === "readonly") {
8511 this.tsCheckTypeAnnotationForReadOnly(node);
8512 }
8513 return this.finishNode(node, "TSTypeOperator");
8514 }
8515 tsCheckTypeAnnotationForReadOnly(node) {
8516 switch (node.typeAnnotation.type) {
8517 case "TSTupleType":
8518 case "TSArrayType":
8519 return;
8520 default:
8521 this.raise(TSErrors.UnexpectedReadonly, node);
8522 }
8523 }
8524 tsParseInferType() {
8525 const node = this.startNode();
8526 this.expectContextual(115);
8527 const typeParameter = this.startNode();
8528 typeParameter.name = this.tsParseTypeParameterName();
8529 typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
8530 node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
8531 return this.finishNode(node, "TSInferType");
8532 }
8533 tsParseConstraintForInferType() {
8534 if (this.eat(81)) {
8535 const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
8536 if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
8537 return constraint;
8538 }
8539 }
8540 }
8541 tsParseTypeOperatorOrHigher() {
8542 const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
8543 return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
8544 }
8545 tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
8546 const node = this.startNode();
8547 const hasLeadingOperator = this.eat(operator);
8548 const types = [];
8549 do {
8550 types.push(parseConstituentType());
8551 } while (this.eat(operator));
8552 if (types.length === 1 && !hasLeadingOperator) {
8553 return types[0];
8554 }
8555 node.types = types;
8556 return this.finishNode(node, kind);
8557 }
8558 tsParseIntersectionTypeOrHigher() {
8559 return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
8560 }
8561 tsParseUnionTypeOrHigher() {
8562 return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
8563 }
8564 tsIsStartOfFunctionType() {
8565 if (this.match(47)) {
8566 return true;
8567 }
8568 return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
8569 }
8570 tsSkipParameterStart() {
8571 if (tokenIsIdentifier(this.state.type) || this.match(78)) {
8572 this.next();
8573 return true;
8574 }
8575 if (this.match(5)) {
8576 const {
8577 errors
8578 } = this.state;
8579 const previousErrorCount = errors.length;
8580 try {
8581 this.parseObjectLike(8, true);
8582 return errors.length === previousErrorCount;
8583 } catch (_unused) {
8584 return false;
8585 }
8586 }
8587 if (this.match(0)) {
8588 this.next();
8589 const {
8590 errors
8591 } = this.state;
8592 const previousErrorCount = errors.length;
8593 try {
8594 super.parseBindingList(3, 93, 1);
8595 return errors.length === previousErrorCount;
8596 } catch (_unused2) {
8597 return false;
8598 }
8599 }
8600 return false;
8601 }
8602 tsIsUnambiguouslyStartOfFunctionType() {
8603 this.next();
8604 if (this.match(11) || this.match(21)) {
8605 return true;
8606 }
8607 if (this.tsSkipParameterStart()) {
8608 if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
8609 return true;
8610 }
8611 if (this.match(11)) {
8612 this.next();
8613 if (this.match(19)) {
8614 return true;
8615 }
8616 }
8617 }
8618 return false;
8619 }
8620 tsParseTypeOrTypePredicateAnnotation(returnToken) {
8621 return this.tsInType(() => {
8622 const t = this.startNode();
8623 this.expect(returnToken);
8624 const node = this.startNode();
8625 const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
8626 if (asserts && this.match(78)) {
8627 let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
8628 if (thisTypePredicate.type === "TSThisType") {
8629 node.parameterName = thisTypePredicate;
8630 node.asserts = true;
8631 node.typeAnnotation = null;
8632 thisTypePredicate = this.finishNode(node, "TSTypePredicate");
8633 } else {
8634 this.resetStartLocationFromNode(thisTypePredicate, node);
8635 thisTypePredicate.asserts = true;
8636 }
8637 t.typeAnnotation = thisTypePredicate;
8638 return this.finishNode(t, "TSTypeAnnotation");
8639 }
8640 const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
8641 if (!typePredicateVariable) {
8642 if (!asserts) {
8643 return this.tsParseTypeAnnotation(false, t);
8644 }
8645 node.parameterName = this.parseIdentifier();
8646 node.asserts = asserts;
8647 node.typeAnnotation = null;
8648 t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
8649 return this.finishNode(t, "TSTypeAnnotation");
8650 }
8651 const type = this.tsParseTypeAnnotation(false);
8652 node.parameterName = typePredicateVariable;
8653 node.typeAnnotation = type;
8654 node.asserts = asserts;
8655 t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
8656 return this.finishNode(t, "TSTypeAnnotation");
8657 });
8658 }
8659 tsTryParseTypeOrTypePredicateAnnotation() {
8660 if (this.match(14)) {
8661 return this.tsParseTypeOrTypePredicateAnnotation(14);
8662 }
8663 }
8664 tsTryParseTypeAnnotation() {
8665 if (this.match(14)) {
8666 return this.tsParseTypeAnnotation();
8667 }
8668 }
8669 tsTryParseType() {
8670 return this.tsEatThenParseType(14);
8671 }
8672 tsParseTypePredicatePrefix() {
8673 const id = this.parseIdentifier();
8674 if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
8675 this.next();
8676 return id;
8677 }
8678 }
8679 tsParseTypePredicateAsserts() {
8680 if (this.state.type !== 109) {
8681 return false;
8682 }
8683 const containsEsc = this.state.containsEsc;
8684 this.next();
8685 if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
8686 return false;
8687 }
8688 if (containsEsc) {
8689 this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
8690 reservedWord: "asserts"
8691 });
8692 }
8693 return true;
8694 }
8695 tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
8696 this.tsInType(() => {
8697 if (eatColon) this.expect(14);
8698 t.typeAnnotation = this.tsParseType();
8699 });
8700 return this.finishNode(t, "TSTypeAnnotation");
8701 }
8702 tsParseType() {
8703 assert(this.state.inType);
8704 const type = this.tsParseNonConditionalType();
8705 if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
8706 return type;
8707 }
8708 const node = this.startNodeAtNode(type);
8709 node.checkType = type;
8710 node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
8711 this.expect(17);
8712 node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
8713 this.expect(14);
8714 node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
8715 return this.finishNode(node, "TSConditionalType");
8716 }
8717 isAbstractConstructorSignature() {
8718 return this.isContextual(124) && this.isLookaheadContextual("new");
8719 }
8720 tsParseNonConditionalType() {
8721 if (this.tsIsStartOfFunctionType()) {
8722 return this.tsParseFunctionOrConstructorType("TSFunctionType");
8723 }
8724 if (this.match(77)) {
8725 return this.tsParseFunctionOrConstructorType("TSConstructorType");
8726 } else if (this.isAbstractConstructorSignature()) {
8727 return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
8728 }
8729 return this.tsParseUnionTypeOrHigher();
8730 }
8731 tsParseTypeAssertion() {
8732 if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
8733 this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
8734 }
8735 const node = this.startNode();
8736 node.typeAnnotation = this.tsInType(() => {
8737 this.next();
8738 return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
8739 });
8740 this.expect(48);
8741 node.expression = this.parseMaybeUnary();
8742 return this.finishNode(node, "TSTypeAssertion");
8743 }
8744 tsParseHeritageClause(token) {
8745 const originalStartLoc = this.state.startLoc;
8746 const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
8747 const node = this.startNode();
8748 node.expression = this.tsParseEntityName(1 | 2);
8749 if (this.match(47)) {
8750 node.typeParameters = this.tsParseTypeArguments();
8751 }
8752 return this.finishNode(node, "TSExpressionWithTypeArguments");
8753 });
8754 if (!delimitedList.length) {
8755 this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
8756 token
8757 });
8758 }
8759 return delimitedList;
8760 }
8761 tsParseInterfaceDeclaration(node, properties = {}) {
8762 if (this.hasFollowingLineBreak()) return null;
8763 this.expectContextual(129);
8764 if (properties.declare) node.declare = true;
8765 if (tokenIsIdentifier(this.state.type)) {
8766 node.id = this.parseIdentifier();
8767 this.checkIdentifier(node.id, 130);
8768 } else {
8769 node.id = null;
8770 this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
8771 }
8772 node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
8773 if (this.eat(81)) {
8774 node.extends = this.tsParseHeritageClause("extends");
8775 }
8776 const body = this.startNode();
8777 body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
8778 node.body = this.finishNode(body, "TSInterfaceBody");
8779 return this.finishNode(node, "TSInterfaceDeclaration");
8780 }
8781 tsParseTypeAliasDeclaration(node) {
8782 node.id = this.parseIdentifier();
8783 this.checkIdentifier(node.id, 2);
8784 node.typeAnnotation = this.tsInType(() => {
8785 node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
8786 this.expect(29);
8787 if (this.isContextual(114) && this.lookaheadCharCode() !== 46) {
8788 const node = this.startNode();
8789 this.next();
8790 return this.finishNode(node, "TSIntrinsicKeyword");
8791 }
8792 return this.tsParseType();
8793 });
8794 this.semicolon();
8795 return this.finishNode(node, "TSTypeAliasDeclaration");
8796 }
8797 tsInTopLevelContext(cb) {
8798 if (this.curContext() !== types.brace) {
8799 const oldContext = this.state.context;
8800 this.state.context = [oldContext[0]];
8801 try {
8802 return cb();
8803 } finally {
8804 this.state.context = oldContext;
8805 }
8806 } else {
8807 return cb();
8808 }
8809 }
8810 tsInType(cb) {
8811 const oldInType = this.state.inType;
8812 this.state.inType = true;
8813 try {
8814 return cb();
8815 } finally {
8816 this.state.inType = oldInType;
8817 }
8818 }
8819 tsInDisallowConditionalTypesContext(cb) {
8820 const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
8821 this.state.inDisallowConditionalTypesContext = true;
8822 try {
8823 return cb();
8824 } finally {
8825 this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
8826 }
8827 }
8828 tsInAllowConditionalTypesContext(cb) {
8829 const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
8830 this.state.inDisallowConditionalTypesContext = false;
8831 try {
8832 return cb();
8833 } finally {
8834 this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
8835 }
8836 }
8837 tsEatThenParseType(token) {
8838 if (this.match(token)) {
8839 return this.tsNextThenParseType();
8840 }
8841 }
8842 tsExpectThenParseType(token) {
8843 return this.tsInType(() => {
8844 this.expect(token);
8845 return this.tsParseType();
8846 });
8847 }
8848 tsNextThenParseType() {
8849 return this.tsInType(() => {
8850 this.next();
8851 return this.tsParseType();
8852 });
8853 }
8854 tsParseEnumMember() {
8855 const node = this.startNode();
8856 node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
8857 if (this.eat(29)) {
8858 node.initializer = super.parseMaybeAssignAllowIn();
8859 }
8860 return this.finishNode(node, "TSEnumMember");
8861 }
8862 tsParseEnumDeclaration(node, properties = {}) {
8863 if (properties.const) node.const = true;
8864 if (properties.declare) node.declare = true;
8865 this.expectContextual(126);
8866 node.id = this.parseIdentifier();
8867 this.checkIdentifier(node.id, node.const ? 8971 : 8459);
8868 this.expect(5);
8869 node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
8870 this.expect(8);
8871 return this.finishNode(node, "TSEnumDeclaration");
8872 }
8873 tsParseEnumBody() {
8874 const node = this.startNode();
8875 this.expect(5);
8876 node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
8877 this.expect(8);
8878 return this.finishNode(node, "TSEnumBody");
8879 }
8880 tsParseModuleBlock() {
8881 const node = this.startNode();
8882 this.scope.enter(0);
8883 this.expect(5);
8884 super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
8885 this.scope.exit();
8886 return this.finishNode(node, "TSModuleBlock");
8887 }
8888 tsParseModuleOrNamespaceDeclaration(node, nested = false) {
8889 node.id = this.parseIdentifier();
8890 if (!nested) {
8891 this.checkIdentifier(node.id, 1024);
8892 }
8893 if (this.eat(16)) {
8894 const inner = this.startNode();
8895 this.tsParseModuleOrNamespaceDeclaration(inner, true);
8896 node.body = inner;
8897 } else {
8898 this.scope.enter(1024);
8899 this.prodParam.enter(0);
8900 node.body = this.tsParseModuleBlock();
8901 this.prodParam.exit();
8902 this.scope.exit();
8903 }
8904 return this.finishNode(node, "TSModuleDeclaration");
8905 }
8906 tsParseAmbientExternalModuleDeclaration(node) {
8907 if (this.isContextual(112)) {
8908 node.kind = "global";
8909 node.global = true;
8910 node.id = this.parseIdentifier();
8911 } else if (this.match(134)) {
8912 node.kind = "module";
8913 node.id = super.parseStringLiteral(this.state.value);
8914 } else {
8915 this.unexpected();
8916 }
8917 if (this.match(5)) {
8918 this.scope.enter(1024);
8919 this.prodParam.enter(0);
8920 node.body = this.tsParseModuleBlock();
8921 this.prodParam.exit();
8922 this.scope.exit();
8923 } else {
8924 this.semicolon();
8925 }
8926 return this.finishNode(node, "TSModuleDeclaration");
8927 }
8928 tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
8929 node.isExport = isExport || false;
8930 node.id = maybeDefaultIdentifier || this.parseIdentifier();
8931 this.checkIdentifier(node.id, 4096);
8932 this.expect(29);
8933 const moduleReference = this.tsParseModuleReference();
8934 if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
8935 this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
8936 }
8937 node.moduleReference = moduleReference;
8938 this.semicolon();
8939 return this.finishNode(node, "TSImportEqualsDeclaration");
8940 }
8941 tsIsExternalModuleReference() {
8942 return this.isContextual(119) && this.lookaheadCharCode() === 40;
8943 }
8944 tsParseModuleReference() {
8945 return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
8946 }
8947 tsParseExternalModuleReference() {
8948 const node = this.startNode();
8949 this.expectContextual(119);
8950 this.expect(10);
8951 if (!this.match(134)) {
8952 this.unexpected();
8953 }
8954 node.expression = super.parseExprAtom();
8955 this.expect(11);
8956 this.sawUnambiguousESM = true;
8957 return this.finishNode(node, "TSExternalModuleReference");
8958 }
8959 tsLookAhead(f) {
8960 const state = this.state.clone();
8961 const res = f();
8962 this.state = state;
8963 return res;
8964 }
8965 tsTryParseAndCatch(f) {
8966 const result = this.tryParse(abort => f() || abort());
8967 if (result.aborted || !result.node) return;
8968 if (result.error) this.state = result.failState;
8969 return result.node;
8970 }
8971 tsTryParse(f) {
8972 const state = this.state.clone();
8973 const result = f();
8974 if (result !== undefined && result !== false) {
8975 return result;
8976 }
8977 this.state = state;
8978 }
8979 tsTryParseDeclare(node) {
8980 if (this.isLineTerminator()) {
8981 return;
8982 }
8983 const startType = this.state.type;
8984 return this.tsInAmbientContext(() => {
8985 switch (startType) {
8986 case 68:
8987 node.declare = true;
8988 return super.parseFunctionStatement(node, false, false);
8989 case 80:
8990 node.declare = true;
8991 return this.parseClass(node, true, false);
8992 case 126:
8993 return this.tsParseEnumDeclaration(node, {
8994 declare: true
8995 });
8996 case 112:
8997 return this.tsParseAmbientExternalModuleDeclaration(node);
8998 case 100:
8999 if (this.state.containsEsc) {
9000 return;
9001 }
9002 case 75:
9003 case 74:
9004 if (!this.match(75) || !this.isLookaheadContextual("enum")) {
9005 node.declare = true;
9006 return this.parseVarStatement(node, this.state.value, true);
9007 }
9008 this.expect(75);
9009 return this.tsParseEnumDeclaration(node, {
9010 const: true,
9011 declare: true
9012 });
9013 case 107:
9014 if (this.isUsing()) {
9015 this.raise(TSErrors.InvalidModifierOnUsingDeclaration, this.state.startLoc, "declare");
9016 node.declare = true;
9017 return this.parseVarStatement(node, "using", true);
9018 }
9019 break;
9020 case 96:
9021 if (this.isAwaitUsing()) {
9022 this.raise(TSErrors.InvalidModifierOnAwaitUsingDeclaration, this.state.startLoc, "declare");
9023 node.declare = true;
9024 this.next();
9025 return this.parseVarStatement(node, "await using", true);
9026 }
9027 break;
9028 case 129:
9029 {
9030 const result = this.tsParseInterfaceDeclaration(node, {
9031 declare: true
9032 });
9033 if (result) return result;
9034 }
9035 default:
9036 if (tokenIsIdentifier(startType)) {
9037 return this.tsParseDeclaration(node, this.state.type, true, null);
9038 }
9039 }
9040 });
9041 }
9042 tsTryParseExportDeclaration() {
9043 return this.tsParseDeclaration(this.startNode(), this.state.type, true, null);
9044 }
9045 tsParseDeclaration(node, type, next, decorators) {
9046 switch (type) {
9047 case 124:
9048 if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
9049 return this.tsParseAbstractDeclaration(node, decorators);
9050 }
9051 break;
9052 case 127:
9053 if (this.tsCheckLineTerminator(next)) {
9054 if (this.match(134)) {
9055 return this.tsParseAmbientExternalModuleDeclaration(node);
9056 } else if (tokenIsIdentifier(this.state.type)) {
9057 node.kind = "module";
9058 return this.tsParseModuleOrNamespaceDeclaration(node);
9059 }
9060 }
9061 break;
9062 case 128:
9063 if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
9064 node.kind = "namespace";
9065 return this.tsParseModuleOrNamespaceDeclaration(node);
9066 }
9067 break;
9068 case 130:
9069 if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
9070 return this.tsParseTypeAliasDeclaration(node);
9071 }
9072 break;
9073 }
9074 }
9075 tsCheckLineTerminator(next) {
9076 if (next) {
9077 if (this.hasFollowingLineBreak()) return false;
9078 this.next();
9079 return true;
9080 }
9081 return !this.isLineTerminator();
9082 }
9083 tsTryParseGenericAsyncArrowFunction(startLoc) {
9084 if (!this.match(47)) return;
9085 const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
9086 this.state.maybeInArrowParameters = true;
9087 const res = this.tsTryParseAndCatch(() => {
9088 const node = this.startNodeAt(startLoc);
9089 node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
9090 super.parseFunctionParams(node);
9091 node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
9092 this.expect(19);
9093 return node;
9094 });
9095 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
9096 if (!res) return;
9097 return super.parseArrowExpression(res, null, true);
9098 }
9099 tsParseTypeArgumentsInExpression() {
9100 if (this.reScan_lt() !== 47) return;
9101 return this.tsParseTypeArguments();
9102 }
9103 tsParseTypeArguments() {
9104 const node = this.startNode();
9105 node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
9106 this.expect(47);
9107 return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
9108 }));
9109 if (node.params.length === 0) {
9110 this.raise(TSErrors.EmptyTypeArguments, node);
9111 } else if (!this.state.inType && this.curContext() === types.brace) {
9112 this.reScan_lt_gt();
9113 }
9114 this.expect(48);
9115 return this.finishNode(node, "TSTypeParameterInstantiation");
9116 }
9117 tsIsDeclarationStart() {
9118 return tokenIsTSDeclarationStart(this.state.type);
9119 }
9120 isExportDefaultSpecifier() {
9121 if (this.tsIsDeclarationStart()) return false;
9122 return super.isExportDefaultSpecifier();
9123 }
9124 parseBindingElement(flags, decorators) {
9125 const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
9126 const modified = {};
9127 this.tsParseModifiers({
9128 allowedModifiers: ["public", "private", "protected", "override", "readonly"]
9129 }, modified);
9130 const accessibility = modified.accessibility;
9131 const override = modified.override;
9132 const readonly = modified.readonly;
9133 if (!(flags & 4) && (accessibility || readonly || override)) {
9134 this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
9135 }
9136 const left = this.parseMaybeDefault();
9137 if (flags & 2) {
9138 this.parseFunctionParamType(left);
9139 }
9140 const elt = this.parseMaybeDefault(left.loc.start, left);
9141 if (accessibility || readonly || override) {
9142 const pp = this.startNodeAt(startLoc);
9143 if (decorators.length) {
9144 pp.decorators = decorators;
9145 }
9146 if (accessibility) pp.accessibility = accessibility;
9147 if (readonly) pp.readonly = readonly;
9148 if (override) pp.override = override;
9149 if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
9150 this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
9151 }
9152 pp.parameter = elt;
9153 return this.finishNode(pp, "TSParameterProperty");
9154 }
9155 if (decorators.length) {
9156 left.decorators = decorators;
9157 }
9158 return elt;
9159 }
9160 isSimpleParameter(node) {
9161 return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
9162 }
9163 tsDisallowOptionalPattern(node) {
9164 for (const param of node.params) {
9165 if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
9166 this.raise(TSErrors.PatternIsOptional, param);
9167 }
9168 }
9169 }
9170 setArrowFunctionParameters(node, params, trailingCommaLoc) {
9171 super.setArrowFunctionParameters(node, params, trailingCommaLoc);
9172 this.tsDisallowOptionalPattern(node);
9173 }
9174 parseFunctionBodyAndFinish(node, type, isMethod = false) {
9175 if (this.match(14)) {
9176 node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
9177 }
9178 const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
9179 if (bodilessType && !this.match(5) && this.isLineTerminator()) {
9180 return this.finishNode(node, bodilessType);
9181 }
9182 if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
9183 this.raise(TSErrors.DeclareFunctionHasImplementation, node);
9184 if (node.declare) {
9185 return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
9186 }
9187 }
9188 this.tsDisallowOptionalPattern(node);
9189 return super.parseFunctionBodyAndFinish(node, type, isMethod);
9190 }
9191 registerFunctionStatementId(node) {
9192 if (!node.body && node.id) {
9193 this.checkIdentifier(node.id, 1024);
9194 } else {
9195 super.registerFunctionStatementId(node);
9196 }
9197 }
9198 tsCheckForInvalidTypeCasts(items) {
9199 items.forEach(node => {
9200 if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
9201 this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
9202 }
9203 });
9204 }
9205 toReferencedList(exprList, isInParens) {
9206 this.tsCheckForInvalidTypeCasts(exprList);
9207 return exprList;
9208 }
9209 parseArrayLike(close, isTuple, refExpressionErrors) {
9210 const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
9211 if (node.type === "ArrayExpression") {
9212 this.tsCheckForInvalidTypeCasts(node.elements);
9213 }
9214 return node;
9215 }
9216 parseSubscript(base, startLoc, noCalls, state) {
9217 if (!this.hasPrecedingLineBreak() && this.match(35)) {
9218 this.state.canStartJSXElement = false;
9219 this.next();
9220 const nonNullExpression = this.startNodeAt(startLoc);
9221 nonNullExpression.expression = base;
9222 return this.finishNode(nonNullExpression, "TSNonNullExpression");
9223 }
9224 let isOptionalCall = false;
9225 if (this.match(18) && this.lookaheadCharCode() === 60) {
9226 if (noCalls) {
9227 state.stop = true;
9228 return base;
9229 }
9230 state.optionalChainMember = isOptionalCall = true;
9231 this.next();
9232 }
9233 if (this.match(47) || this.match(51)) {
9234 let missingParenErrorLoc;
9235 const result = this.tsTryParseAndCatch(() => {
9236 if (!noCalls && this.atPossibleAsyncArrow(base)) {
9237 const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
9238 if (asyncArrowFn) {
9239 state.stop = true;
9240 return asyncArrowFn;
9241 }
9242 }
9243 const typeArguments = this.tsParseTypeArgumentsInExpression();
9244 if (!typeArguments) return;
9245 if (isOptionalCall && !this.match(10)) {
9246 missingParenErrorLoc = this.state.curPosition();
9247 return;
9248 }
9249 if (tokenIsTemplate(this.state.type)) {
9250 const result = super.parseTaggedTemplateExpression(base, startLoc, state);
9251 result.typeParameters = typeArguments;
9252 return result;
9253 }
9254 if (!noCalls && this.eat(10)) {
9255 const node = this.startNodeAt(startLoc);
9256 node.callee = base;
9257 node.arguments = this.parseCallExpressionArguments();
9258 this.tsCheckForInvalidTypeCasts(node.arguments);
9259 node.typeParameters = typeArguments;
9260 if (state.optionalChainMember) {
9261 node.optional = isOptionalCall;
9262 }
9263 return this.finishCallExpression(node, state.optionalChainMember);
9264 }
9265 const tokenType = this.state.type;
9266 if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenType !== 93 && tokenType !== 120 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
9267 return;
9268 }
9269 const node = this.startNodeAt(startLoc);
9270 node.expression = base;
9271 node.typeParameters = typeArguments;
9272 return this.finishNode(node, "TSInstantiationExpression");
9273 });
9274 if (missingParenErrorLoc) {
9275 this.unexpected(missingParenErrorLoc, 10);
9276 }
9277 if (result) {
9278 if (result.type === "TSInstantiationExpression") {
9279 if (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40) {
9280 this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
9281 }
9282 if (!this.match(16) && !this.match(18)) {
9283 result.expression = super.stopParseSubscript(base, state);
9284 }
9285 }
9286 return result;
9287 }
9288 }
9289 return super.parseSubscript(base, startLoc, noCalls, state);
9290 }
9291 parseNewCallee(node) {
9292 var _callee$extra;
9293 super.parseNewCallee(node);
9294 const {
9295 callee
9296 } = node;
9297 if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
9298 node.typeParameters = callee.typeParameters;
9299 node.callee = callee.expression;
9300 }
9301 }
9302 parseExprOp(left, leftStartLoc, minPrec) {
9303 let isSatisfies;
9304 if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
9305 const node = this.startNodeAt(leftStartLoc);
9306 node.expression = left;
9307 node.typeAnnotation = this.tsInType(() => {
9308 this.next();
9309 if (this.match(75)) {
9310 if (isSatisfies) {
9311 this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
9312 keyword: "const"
9313 });
9314 }
9315 return this.tsParseTypeReference();
9316 }
9317 return this.tsParseType();
9318 });
9319 this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
9320 this.reScan_lt_gt();
9321 return this.parseExprOp(node, leftStartLoc, minPrec);
9322 }
9323 return super.parseExprOp(left, leftStartLoc, minPrec);
9324 }
9325 checkReservedWord(word, startLoc, checkKeywords, isBinding) {
9326 if (!this.state.isAmbientContext) {
9327 super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
9328 }
9329 }
9330 checkImportReflection(node) {
9331 super.checkImportReflection(node);
9332 if (node.module && node.importKind !== "value") {
9333 this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
9334 }
9335 }
9336 checkDuplicateExports() {}
9337 isPotentialImportPhase(isExport) {
9338 if (super.isPotentialImportPhase(isExport)) return true;
9339 if (this.isContextual(130)) {
9340 const ch = this.lookaheadCharCode();
9341 return isExport ? ch === 123 || ch === 42 : ch !== 61;
9342 }
9343 return !isExport && this.isContextual(87);
9344 }
9345 applyImportPhase(node, isExport, phase, loc) {
9346 super.applyImportPhase(node, isExport, phase, loc);
9347 if (isExport) {
9348 node.exportKind = phase === "type" ? "type" : "value";
9349 } else {
9350 node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
9351 }
9352 }
9353 parseImport(node) {
9354 if (this.match(134)) {
9355 node.importKind = "value";
9356 return super.parseImport(node);
9357 }
9358 let importNode;
9359 if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
9360 node.importKind = "value";
9361 return this.tsParseImportEqualsDeclaration(node);
9362 } else if (this.isContextual(130)) {
9363 const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
9364 if (this.lookaheadCharCode() === 61) {
9365 return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
9366 } else {
9367 importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
9368 }
9369 } else {
9370 importNode = super.parseImport(node);
9371 }
9372 if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
9373 this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
9374 }
9375 return importNode;
9376 }
9377 parseExport(node, decorators) {
9378 if (this.match(83)) {
9379 const nodeImportEquals = node;
9380 this.next();
9381 let maybeDefaultIdentifier = null;
9382 if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
9383 maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
9384 } else {
9385 nodeImportEquals.importKind = "value";
9386 }
9387 const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
9388 return declaration;
9389 } else if (this.eat(29)) {
9390 const assign = node;
9391 assign.expression = super.parseExpression();
9392 this.semicolon();
9393 this.sawUnambiguousESM = true;
9394 return this.finishNode(assign, "TSExportAssignment");
9395 } else if (this.eatContextual(93)) {
9396 const decl = node;
9397 this.expectContextual(128);
9398 decl.id = this.parseIdentifier();
9399 this.semicolon();
9400 return this.finishNode(decl, "TSNamespaceExportDeclaration");
9401 } else {
9402 return super.parseExport(node, decorators);
9403 }
9404 }
9405 isAbstractClass() {
9406 return this.isContextual(124) && this.isLookaheadContextual("class");
9407 }
9408 parseExportDefaultExpression() {
9409 if (this.isAbstractClass()) {
9410 const cls = this.startNode();
9411 this.next();
9412 cls.abstract = true;
9413 return this.parseClass(cls, true, true);
9414 }
9415 if (this.match(129)) {
9416 const result = this.tsParseInterfaceDeclaration(this.startNode());
9417 if (result) return result;
9418 }
9419 return super.parseExportDefaultExpression();
9420 }
9421 parseVarStatement(node, kind, allowMissingInitializer = false) {
9422 const {
9423 isAmbientContext
9424 } = this.state;
9425 const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
9426 if (!isAmbientContext) return declaration;
9427 if (!node.declare && (kind === "using" || kind === "await using")) {
9428 this.raiseOverwrite(TSErrors.UsingDeclarationInAmbientContext, node, kind);
9429 return declaration;
9430 }
9431 for (const {
9432 id,
9433 init
9434 } of declaration.declarations) {
9435 if (!init) continue;
9436 if (kind === "var" || kind === "let" || !!id.typeAnnotation) {
9437 this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
9438 } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
9439 this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
9440 }
9441 }
9442 return declaration;
9443 }
9444 parseStatementContent(flags, decorators) {
9445 if (!this.state.containsEsc) {
9446 switch (this.state.type) {
9447 case 75:
9448 {
9449 if (this.isLookaheadContextual("enum")) {
9450 const node = this.startNode();
9451 this.expect(75);
9452 return this.tsParseEnumDeclaration(node, {
9453 const: true
9454 });
9455 }
9456 break;
9457 }
9458 case 124:
9459 case 125:
9460 {
9461 if (this.nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine()) {
9462 const token = this.state.type;
9463 const node = this.startNode();
9464 this.next();
9465 const declaration = token === 125 ? this.tsTryParseDeclare(node) : this.tsParseAbstractDeclaration(node, decorators);
9466 if (declaration) {
9467 if (token === 125) {
9468 declaration.declare = true;
9469 }
9470 return declaration;
9471 } else {
9472 node.expression = this.createIdentifier(this.startNodeAt(node.loc.start), token === 125 ? "declare" : "abstract");
9473 this.semicolon(false);
9474 return this.finishNode(node, "ExpressionStatement");
9475 }
9476 }
9477 break;
9478 }
9479 case 126:
9480 return this.tsParseEnumDeclaration(this.startNode());
9481 case 112:
9482 {
9483 const nextCh = this.lookaheadCharCode();
9484 if (nextCh === 123) {
9485 const node = this.startNode();
9486 return this.tsParseAmbientExternalModuleDeclaration(node);
9487 }
9488 break;
9489 }
9490 case 129:
9491 {
9492 const result = this.tsParseInterfaceDeclaration(this.startNode());
9493 if (result) return result;
9494 break;
9495 }
9496 case 127:
9497 {
9498 if (this.nextTokenIsIdentifierOrStringLiteralOnSameLine()) {
9499 const node = this.startNode();
9500 this.next();
9501 return this.tsParseDeclaration(node, 127, false, decorators);
9502 }
9503 break;
9504 }
9505 case 128:
9506 {
9507 if (this.nextTokenIsIdentifierOnSameLine()) {
9508 const node = this.startNode();
9509 this.next();
9510 return this.tsParseDeclaration(node, 128, false, decorators);
9511 }
9512 break;
9513 }
9514 case 130:
9515 {
9516 if (this.nextTokenIsIdentifierOnSameLine()) {
9517 const node = this.startNode();
9518 this.next();
9519 return this.tsParseTypeAliasDeclaration(node);
9520 }
9521 break;
9522 }
9523 }
9524 }
9525 return super.parseStatementContent(flags, decorators);
9526 }
9527 parseAccessModifier() {
9528 return this.tsParseModifier(["public", "protected", "private"]);
9529 }
9530 tsHasSomeModifiers(member, modifiers) {
9531 return modifiers.some(modifier => {
9532 if (tsIsAccessModifier(modifier)) {
9533 return member.accessibility === modifier;
9534 }
9535 return !!member[modifier];
9536 });
9537 }
9538 tsIsStartOfStaticBlocks() {
9539 return this.isContextual(106) && this.lookaheadCharCode() === 123;
9540 }
9541 parseClassMember(classBody, member, state) {
9542 const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
9543 this.tsParseModifiers({
9544 allowedModifiers: modifiers,
9545 disallowedModifiers: ["in", "out"],
9546 stopOnStartOfClassStaticBlock: true,
9547 errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
9548 }, member);
9549 const callParseClassMemberWithIsStatic = () => {
9550 if (this.tsIsStartOfStaticBlocks()) {
9551 this.next();
9552 this.next();
9553 if (this.tsHasSomeModifiers(member, modifiers)) {
9554 this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
9555 }
9556 super.parseClassStaticBlock(classBody, member);
9557 } else {
9558 this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
9559 }
9560 };
9561 if (member.declare) {
9562 this.tsInAmbientContext(callParseClassMemberWithIsStatic);
9563 } else {
9564 callParseClassMemberWithIsStatic();
9565 }
9566 }
9567 parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
9568 const idx = this.tsTryParseIndexSignature(member);
9569 if (idx) {
9570 classBody.body.push(idx);
9571 if (member.abstract) {
9572 this.raise(TSErrors.IndexSignatureHasAbstract, member);
9573 }
9574 if (member.accessibility) {
9575 this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
9576 modifier: member.accessibility
9577 });
9578 }
9579 if (member.declare) {
9580 this.raise(TSErrors.IndexSignatureHasDeclare, member);
9581 }
9582 if (member.override) {
9583 this.raise(TSErrors.IndexSignatureHasOverride, member);
9584 }
9585 return;
9586 }
9587 if (!this.state.inAbstractClass && member.abstract) {
9588 this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
9589 }
9590 if (member.override) {
9591 if (!state.hadSuperClass) {
9592 this.raise(TSErrors.OverrideNotInSubClass, member);
9593 }
9594 }
9595 super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
9596 }
9597 parsePostMemberNameModifiers(methodOrProp) {
9598 const optional = this.eat(17);
9599 if (optional) methodOrProp.optional = true;
9600 if (methodOrProp.readonly && this.match(10)) {
9601 this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
9602 }
9603 if (methodOrProp.declare && this.match(10)) {
9604 this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
9605 }
9606 }
9607 shouldParseExportDeclaration() {
9608 if (this.tsIsDeclarationStart()) return true;
9609 return super.shouldParseExportDeclaration();
9610 }
9611 parseConditional(expr, startLoc, refExpressionErrors) {
9612 if (!this.match(17)) return expr;
9613 if (this.state.maybeInArrowParameters) {
9614 const nextCh = this.lookaheadCharCode();
9615 if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
9616 this.setOptionalParametersError(refExpressionErrors);
9617 return expr;
9618 }
9619 }
9620 return super.parseConditional(expr, startLoc, refExpressionErrors);
9621 }
9622 parseParenItem(node, startLoc) {
9623 const newNode = super.parseParenItem(node, startLoc);
9624 if (this.eat(17)) {
9625 newNode.optional = true;
9626 this.resetEndLocation(node);
9627 }
9628 if (this.match(14)) {
9629 const typeCastNode = this.startNodeAt(startLoc);
9630 typeCastNode.expression = node;
9631 typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
9632 return this.finishNode(typeCastNode, "TSTypeCastExpression");
9633 }
9634 return node;
9635 }
9636 parseExportDeclaration(node) {
9637 if (!this.state.isAmbientContext && this.isContextual(125)) {
9638 return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
9639 }
9640 const startLoc = this.state.startLoc;
9641 const isDeclare = this.eatContextual(125);
9642 if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
9643 throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
9644 }
9645 const isIdentifier = tokenIsIdentifier(this.state.type);
9646 const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
9647 if (!declaration) return null;
9648 if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
9649 node.exportKind = "type";
9650 }
9651 if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
9652 this.resetStartLocation(declaration, startLoc);
9653 declaration.declare = true;
9654 }
9655 return declaration;
9656 }
9657 parseClassId(node, isStatement, optionalId, bindingType) {
9658 if ((!isStatement || optionalId) && this.isContextual(113)) {
9659 return;
9660 }
9661 super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
9662 const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
9663 if (typeParameters) node.typeParameters = typeParameters;
9664 }
9665 parseClassPropertyAnnotation(node) {
9666 if (!node.optional) {
9667 if (this.eat(35)) {
9668 node.definite = true;
9669 } else if (this.eat(17)) {
9670 node.optional = true;
9671 }
9672 }
9673 const type = this.tsTryParseTypeAnnotation();
9674 if (type) node.typeAnnotation = type;
9675 }
9676 parseClassProperty(node) {
9677 this.parseClassPropertyAnnotation(node);
9678 if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
9679 this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
9680 }
9681 if (node.abstract && this.match(29)) {
9682 const {
9683 key
9684 } = node;
9685 this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
9686 propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
9687 });
9688 }
9689 return super.parseClassProperty(node);
9690 }
9691 parseClassPrivateProperty(node) {
9692 if (node.abstract) {
9693 this.raise(TSErrors.PrivateElementHasAbstract, node);
9694 }
9695 if (node.accessibility) {
9696 this.raise(TSErrors.PrivateElementHasAccessibility, node, {
9697 modifier: node.accessibility
9698 });
9699 }
9700 this.parseClassPropertyAnnotation(node);
9701 return super.parseClassPrivateProperty(node);
9702 }
9703 parseClassAccessorProperty(node) {
9704 this.parseClassPropertyAnnotation(node);
9705 if (node.optional) {
9706 this.raise(TSErrors.AccessorCannotBeOptional, node);
9707 }
9708 return super.parseClassAccessorProperty(node);
9709 }
9710 pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
9711 const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9712 if (typeParameters && isConstructor) {
9713 this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
9714 }
9715 const {
9716 declare = false,
9717 kind
9718 } = method;
9719 if (declare && (kind === "get" || kind === "set")) {
9720 this.raise(TSErrors.DeclareAccessor, method, {
9721 kind
9722 });
9723 }
9724 if (typeParameters) method.typeParameters = typeParameters;
9725 super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
9726 }
9727 pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
9728 const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9729 if (typeParameters) method.typeParameters = typeParameters;
9730 super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
9731 }
9732 declareClassPrivateMethodInScope(node, kind) {
9733 if (node.type === "TSDeclareMethod") return;
9734 if (node.type === "MethodDefinition" && node.value.body == null) {
9735 return;
9736 }
9737 super.declareClassPrivateMethodInScope(node, kind);
9738 }
9739 parseClassSuper(node) {
9740 super.parseClassSuper(node);
9741 if (node.superClass) {
9742 if (node.superClass.type === "TSInstantiationExpression") {
9743 const tsInstantiationExpression = node.superClass;
9744 const superClass = tsInstantiationExpression.expression;
9745 this.takeSurroundingComments(superClass, superClass.start, superClass.end);
9746 const superTypeArguments = tsInstantiationExpression.typeParameters;
9747 this.takeSurroundingComments(superTypeArguments, superTypeArguments.start, superTypeArguments.end);
9748 node.superClass = superClass;
9749 node.superTypeParameters = superTypeArguments;
9750 } else if (this.match(47) || this.match(51)) {
9751 node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
9752 }
9753 }
9754 if (this.eatContextual(113)) {
9755 node.implements = this.tsParseHeritageClause("implements");
9756 }
9757 }
9758 parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
9759 const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9760 if (typeParameters) prop.typeParameters = typeParameters;
9761 return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
9762 }
9763 parseFunctionParams(node, isConstructor) {
9764 const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9765 if (typeParameters) node.typeParameters = typeParameters;
9766 super.parseFunctionParams(node, isConstructor);
9767 }
9768 parseVarId(decl, kind) {
9769 super.parseVarId(decl, kind);
9770 if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
9771 decl.definite = true;
9772 }
9773 const type = this.tsTryParseTypeAnnotation();
9774 if (type) {
9775 decl.id.typeAnnotation = type;
9776 this.resetEndLocation(decl.id);
9777 }
9778 }
9779 parseAsyncArrowFromCallExpression(node, call) {
9780 if (this.match(14)) {
9781 node.returnType = this.tsParseTypeAnnotation();
9782 }
9783 return super.parseAsyncArrowFromCallExpression(node, call);
9784 }
9785 parseMaybeAssign(refExpressionErrors, afterLeftParse) {
9786 var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
9787 let state;
9788 let jsx;
9789 let typeCast;
9790 if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
9791 state = this.state.clone();
9792 jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
9793 if (!jsx.error) return jsx.node;
9794 const {
9795 context
9796 } = this.state;
9797 const currentContext = context[context.length - 1];
9798 if (currentContext === types.j_oTag || currentContext === types.j_expr) {
9799 context.pop();
9800 }
9801 }
9802 if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
9803 return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
9804 }
9805 if (!state || state === this.state) state = this.state.clone();
9806 let typeParameters;
9807 const arrow = this.tryParse(abort => {
9808 var _expr$extra, _typeParameters;
9809 typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
9810 const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
9811 if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
9812 abort();
9813 }
9814 if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
9815 this.resetStartLocationFromNode(expr, typeParameters);
9816 }
9817 expr.typeParameters = typeParameters;
9818 return expr;
9819 }, state);
9820 if (!arrow.error && !arrow.aborted) {
9821 if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
9822 return arrow.node;
9823 }
9824 if (!jsx) {
9825 assert(!this.hasPlugin("jsx"));
9826 typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
9827 if (!typeCast.error) return typeCast.node;
9828 }
9829 if ((_jsx2 = jsx) != null && _jsx2.node) {
9830 this.state = jsx.failState;
9831 return jsx.node;
9832 }
9833 if (arrow.node) {
9834 this.state = arrow.failState;
9835 if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
9836 return arrow.node;
9837 }
9838 if ((_typeCast = typeCast) != null && _typeCast.node) {
9839 this.state = typeCast.failState;
9840 return typeCast.node;
9841 }
9842 throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
9843 }
9844 reportReservedArrowTypeParam(node) {
9845 var _node$extra2;
9846 if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra2 = node.extra) != null && _node$extra2.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
9847 this.raise(TSErrors.ReservedArrowTypeParam, node);
9848 }
9849 }
9850 parseMaybeUnary(refExpressionErrors, sawUnary) {
9851 if (!this.hasPlugin("jsx") && this.match(47)) {
9852 return this.tsParseTypeAssertion();
9853 }
9854 return super.parseMaybeUnary(refExpressionErrors, sawUnary);
9855 }
9856 parseArrow(node) {
9857 if (this.match(14)) {
9858 const result = this.tryParse(abort => {
9859 const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
9860 if (this.canInsertSemicolon() || !this.match(19)) abort();
9861 return returnType;
9862 });
9863 if (result.aborted) return;
9864 if (!result.thrown) {
9865 if (result.error) this.state = result.failState;
9866 node.returnType = result.node;
9867 }
9868 }
9869 return super.parseArrow(node);
9870 }
9871 parseFunctionParamType(param) {
9872 if (this.eat(17)) {
9873 param.optional = true;
9874 }
9875 const type = this.tsTryParseTypeAnnotation();
9876 if (type) param.typeAnnotation = type;
9877 this.resetEndLocation(param);
9878 return param;
9879 }
9880 isAssignable(node, isBinding) {
9881 switch (node.type) {
9882 case "TSTypeCastExpression":
9883 return this.isAssignable(node.expression, isBinding);
9884 case "TSParameterProperty":
9885 return true;
9886 default:
9887 return super.isAssignable(node, isBinding);
9888 }
9889 }
9890 toAssignable(node, isLHS = false) {
9891 switch (node.type) {
9892 case "ParenthesizedExpression":
9893 this.toAssignableParenthesizedExpression(node, isLHS);
9894 break;
9895 case "TSAsExpression":
9896 case "TSSatisfiesExpression":
9897 case "TSNonNullExpression":
9898 case "TSTypeAssertion":
9899 if (isLHS) {
9900 this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
9901 } else {
9902 this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
9903 }
9904 this.toAssignable(node.expression, isLHS);
9905 break;
9906 case "AssignmentExpression":
9907 if (!isLHS && node.left.type === "TSTypeCastExpression") {
9908 node.left = this.typeCastToParameter(node.left);
9909 }
9910 default:
9911 super.toAssignable(node, isLHS);
9912 }
9913 }
9914 toAssignableParenthesizedExpression(node, isLHS) {
9915 switch (node.expression.type) {
9916 case "TSAsExpression":
9917 case "TSSatisfiesExpression":
9918 case "TSNonNullExpression":
9919 case "TSTypeAssertion":
9920 case "ParenthesizedExpression":
9921 this.toAssignable(node.expression, isLHS);
9922 break;
9923 default:
9924 super.toAssignable(node, isLHS);
9925 }
9926 }
9927 checkToRestConversion(node, allowPattern) {
9928 switch (node.type) {
9929 case "TSAsExpression":
9930 case "TSSatisfiesExpression":
9931 case "TSTypeAssertion":
9932 case "TSNonNullExpression":
9933 this.checkToRestConversion(node.expression, false);
9934 break;
9935 default:
9936 super.checkToRestConversion(node, allowPattern);
9937 }
9938 }
9939 isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
9940 switch (type) {
9941 case "TSTypeCastExpression":
9942 return true;
9943 case "TSParameterProperty":
9944 return "parameter";
9945 case "TSNonNullExpression":
9946 return "expression";
9947 case "TSAsExpression":
9948 case "TSSatisfiesExpression":
9949 case "TSTypeAssertion":
9950 return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
9951 default:
9952 return super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
9953 }
9954 }
9955 parseBindingAtom() {
9956 if (this.state.type === 78) {
9957 return this.parseIdentifier(true);
9958 }
9959 return super.parseBindingAtom();
9960 }
9961 parseMaybeDecoratorArguments(expr, startLoc) {
9962 if (this.match(47) || this.match(51)) {
9963 const typeArguments = this.tsParseTypeArgumentsInExpression();
9964 if (this.match(10)) {
9965 const call = super.parseMaybeDecoratorArguments(expr, startLoc);
9966 call.typeParameters = typeArguments;
9967 return call;
9968 }
9969 this.unexpected(null, 10);
9970 }
9971 return super.parseMaybeDecoratorArguments(expr, startLoc);
9972 }
9973 checkCommaAfterRest(close) {
9974 if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
9975 this.next();
9976 return false;
9977 }
9978 return super.checkCommaAfterRest(close);
9979 }
9980 isClassMethod() {
9981 return this.match(47) || super.isClassMethod();
9982 }
9983 isClassProperty() {
9984 return this.match(35) || this.match(14) || super.isClassProperty();
9985 }
9986 parseMaybeDefault(startLoc, left) {
9987 const node = super.parseMaybeDefault(startLoc, left);
9988 if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
9989 this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
9990 }
9991 return node;
9992 }
9993 getTokenFromCode(code) {
9994 if (this.state.inType) {
9995 if (code === 62) {
9996 this.finishOp(48, 1);
9997 return;
9998 }
9999 if (code === 60) {
10000 this.finishOp(47, 1);
10001 return;
10002 }
10003 }
10004 super.getTokenFromCode(code);
10005 }
10006 reScan_lt_gt() {
10007 const {
10008 type
10009 } = this.state;
10010 if (type === 47) {
10011 this.state.pos -= 1;
10012 this.readToken_lt();
10013 } else if (type === 48) {
10014 this.state.pos -= 1;
10015 this.readToken_gt();
10016 }
10017 }
10018 reScan_lt() {
10019 const {
10020 type
10021 } = this.state;
10022 if (type === 51) {
10023 this.state.pos -= 2;
10024 this.finishOp(47, 1);
10025 return 47;
10026 }
10027 return type;
10028 }
10029 toAssignableListItem(exprList, index, isLHS) {
10030 const node = exprList[index];
10031 if (node.type === "TSTypeCastExpression") {
10032 exprList[index] = this.typeCastToParameter(node);
10033 }
10034 super.toAssignableListItem(exprList, index, isLHS);
10035 }
10036 typeCastToParameter(node) {
10037 node.expression.typeAnnotation = node.typeAnnotation;
10038 this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
10039 return node.expression;
10040 }
10041 shouldParseArrow(params) {
10042 if (this.match(14)) {
10043 return params.every(expr => this.isAssignable(expr, true));
10044 }
10045 return super.shouldParseArrow(params);
10046 }
10047 shouldParseAsyncArrow() {
10048 return this.match(14) || super.shouldParseAsyncArrow();
10049 }
10050 canHaveLeadingDecorator() {
10051 return super.canHaveLeadingDecorator() || this.isAbstractClass();
10052 }
10053 jsxParseOpeningElementAfterName(node) {
10054 if (this.match(47) || this.match(51)) {
10055 const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
10056 if (typeArguments) {
10057 node.typeParameters = typeArguments;
10058 }
10059 }
10060 return super.jsxParseOpeningElementAfterName(node);
10061 }
10062 getGetterSetterExpectedParamCount(method) {
10063 const baseCount = super.getGetterSetterExpectedParamCount(method);
10064 const params = this.getObjectOrClassMethodParams(method);
10065 const firstParam = params[0];
10066 const hasContextParam = firstParam && this.isThisParam(firstParam);
10067 return hasContextParam ? baseCount + 1 : baseCount;
10068 }
10069 parseCatchClauseParam() {
10070 const param = super.parseCatchClauseParam();
10071 const type = this.tsTryParseTypeAnnotation();
10072 if (type) {
10073 param.typeAnnotation = type;
10074 this.resetEndLocation(param);
10075 }
10076 return param;
10077 }
10078 tsInAmbientContext(cb) {
10079 const {
10080 isAmbientContext: oldIsAmbientContext,
10081 strict: oldStrict
10082 } = this.state;
10083 this.state.isAmbientContext = true;
10084 this.state.strict = false;
10085 try {
10086 return cb();
10087 } finally {
10088 this.state.isAmbientContext = oldIsAmbientContext;
10089 this.state.strict = oldStrict;
10090 }
10091 }
10092 parseClass(node, isStatement, optionalId) {
10093 const oldInAbstractClass = this.state.inAbstractClass;
10094 this.state.inAbstractClass = !!node.abstract;
10095 try {
10096 return super.parseClass(node, isStatement, optionalId);
10097 } finally {
10098 this.state.inAbstractClass = oldInAbstractClass;
10099 }
10100 }
10101 tsParseAbstractDeclaration(node, decorators) {
10102 if (this.match(80)) {
10103 node.abstract = true;
10104 return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
10105 } else if (this.isContextual(129)) {
10106 if (!this.hasFollowingLineBreak()) {
10107 node.abstract = true;
10108 this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifier, node);
10109 return this.tsParseInterfaceDeclaration(node);
10110 } else {
10111 return null;
10112 }
10113 }
10114 throw this.unexpected(null, 80);
10115 }
10116 parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
10117 const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
10118 if (method.abstract || method.type === "TSAbstractMethodDefinition") {
10119 const hasEstreePlugin = this.hasPlugin("estree");
10120 const methodFn = hasEstreePlugin ? method.value : method;
10121 if (methodFn.body) {
10122 const {
10123 key
10124 } = method;
10125 this.raise(TSErrors.AbstractMethodHasImplementation, method, {
10126 methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
10127 });
10128 }
10129 }
10130 return method;
10131 }
10132 tsParseTypeParameterName() {
10133 const typeName = this.parseIdentifier();
10134 return typeName.name;
10135 }
10136 shouldParseAsAmbientContext() {
10137 return !!this.getPluginOption("typescript", "dts");
10138 }
10139 parse() {
10140 if (this.shouldParseAsAmbientContext()) {
10141 this.state.isAmbientContext = true;
10142 }
10143 return super.parse();
10144 }
10145 getExpression() {
10146 if (this.shouldParseAsAmbientContext()) {
10147 this.state.isAmbientContext = true;
10148 }
10149 return super.getExpression();
10150 }
10151 parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
10152 if (!isString && isMaybeTypeOnly) {
10153 this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
10154 return this.finishNode(node, "ExportSpecifier");
10155 }
10156 node.exportKind = "value";
10157 return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
10158 }
10159 parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
10160 if (!importedIsString && isMaybeTypeOnly) {
10161 this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
10162 return this.finishNode(specifier, "ImportSpecifier");
10163 }
10164 specifier.importKind = "value";
10165 return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
10166 }
10167 parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
10168 const leftOfAsKey = isImport ? "imported" : "local";
10169 const rightOfAsKey = isImport ? "local" : "exported";
10170 let leftOfAs = node[leftOfAsKey];
10171 let rightOfAs;
10172 let hasTypeSpecifier = false;
10173 let canParseAsKeyword = true;
10174 const loc = leftOfAs.loc.start;
10175 if (this.isContextual(93)) {
10176 const firstAs = this.parseIdentifier();
10177 if (this.isContextual(93)) {
10178 const secondAs = this.parseIdentifier();
10179 if (tokenIsKeywordOrIdentifier(this.state.type)) {
10180 hasTypeSpecifier = true;
10181 leftOfAs = firstAs;
10182 rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
10183 canParseAsKeyword = false;
10184 } else {
10185 rightOfAs = secondAs;
10186 canParseAsKeyword = false;
10187 }
10188 } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
10189 canParseAsKeyword = false;
10190 rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
10191 } else {
10192 hasTypeSpecifier = true;
10193 leftOfAs = firstAs;
10194 }
10195 } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
10196 hasTypeSpecifier = true;
10197 if (isImport) {
10198 leftOfAs = this.parseIdentifier(true);
10199 if (!this.isContextual(93)) {
10200 this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
10201 }
10202 } else {
10203 leftOfAs = this.parseModuleExportName();
10204 }
10205 }
10206 if (hasTypeSpecifier && isInTypeOnlyImportExport) {
10207 this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
10208 }
10209 node[leftOfAsKey] = leftOfAs;
10210 node[rightOfAsKey] = rightOfAs;
10211 const kindKey = isImport ? "importKind" : "exportKind";
10212 node[kindKey] = hasTypeSpecifier ? "type" : "value";
10213 if (canParseAsKeyword && this.eatContextual(93)) {
10214 node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
10215 }
10216 if (!node[rightOfAsKey]) {
10217 node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
10218 }
10219 if (isImport) {
10220 this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
10221 }
10222 }
10223 fillOptionalPropertiesForTSESLint(node) {
10224 var _node$directive, _node$decorators, _node$optional, _node$typeAnnotation, _node$accessibility, _node$decorators2, _node$override, _node$readonly, _node$static, _node$declare, _node$returnType, _node$typeParameters, _node$optional2, _node$optional3, _node$accessibility2, _node$readonly2, _node$static2, _node$declare2, _node$definite, _node$readonly3, _node$typeAnnotation2, _node$accessibility3, _node$decorators3, _node$override2, _node$optional4, _node$id, _node$abstract, _node$declare3, _node$decorators4, _node$implements, _node$superTypeArgume, _node$typeParameters2, _node$declare4, _node$definite2, _node$const, _node$declare5, _node$computed, _node$qualifier, _node$options, _node$declare6, _node$extends, _node$optional5, _node$readonly4, _node$declare7, _node$global, _node$const2, _node$in, _node$out;
10225 switch (node.type) {
10226 case "ExpressionStatement":
10227 (_node$directive = node.directive) != null ? _node$directive : node.directive = undefined;
10228 return;
10229 case "RestElement":
10230 node.value = undefined;
10231 case "Identifier":
10232 case "ArrayPattern":
10233 case "AssignmentPattern":
10234 case "ObjectPattern":
10235 (_node$decorators = node.decorators) != null ? _node$decorators : node.decorators = [];
10236 (_node$optional = node.optional) != null ? _node$optional : node.optional = false;
10237 (_node$typeAnnotation = node.typeAnnotation) != null ? _node$typeAnnotation : node.typeAnnotation = undefined;
10238 return;
10239 case "TSParameterProperty":
10240 (_node$accessibility = node.accessibility) != null ? _node$accessibility : node.accessibility = undefined;
10241 (_node$decorators2 = node.decorators) != null ? _node$decorators2 : node.decorators = [];
10242 (_node$override = node.override) != null ? _node$override : node.override = false;
10243 (_node$readonly = node.readonly) != null ? _node$readonly : node.readonly = false;
10244 (_node$static = node.static) != null ? _node$static : node.static = false;
10245 return;
10246 case "TSEmptyBodyFunctionExpression":
10247 node.body = null;
10248 case "TSDeclareFunction":
10249 case "FunctionDeclaration":
10250 case "FunctionExpression":
10251 case "ClassMethod":
10252 case "ClassPrivateMethod":
10253 (_node$declare = node.declare) != null ? _node$declare : node.declare = false;
10254 (_node$returnType = node.returnType) != null ? _node$returnType : node.returnType = undefined;
10255 (_node$typeParameters = node.typeParameters) != null ? _node$typeParameters : node.typeParameters = undefined;
10256 return;
10257 case "Property":
10258 (_node$optional2 = node.optional) != null ? _node$optional2 : node.optional = false;
10259 return;
10260 case "TSMethodSignature":
10261 case "TSPropertySignature":
10262 (_node$optional3 = node.optional) != null ? _node$optional3 : node.optional = false;
10263 case "TSIndexSignature":
10264 (_node$accessibility2 = node.accessibility) != null ? _node$accessibility2 : node.accessibility = undefined;
10265 (_node$readonly2 = node.readonly) != null ? _node$readonly2 : node.readonly = false;
10266 (_node$static2 = node.static) != null ? _node$static2 : node.static = false;
10267 return;
10268 case "TSAbstractPropertyDefinition":
10269 case "PropertyDefinition":
10270 case "TSAbstractAccessorProperty":
10271 case "AccessorProperty":
10272 (_node$declare2 = node.declare) != null ? _node$declare2 : node.declare = false;
10273 (_node$definite = node.definite) != null ? _node$definite : node.definite = false;
10274 (_node$readonly3 = node.readonly) != null ? _node$readonly3 : node.readonly = false;
10275 (_node$typeAnnotation2 = node.typeAnnotation) != null ? _node$typeAnnotation2 : node.typeAnnotation = undefined;
10276 case "TSAbstractMethodDefinition":
10277 case "MethodDefinition":
10278 (_node$accessibility3 = node.accessibility) != null ? _node$accessibility3 : node.accessibility = undefined;
10279 (_node$decorators3 = node.decorators) != null ? _node$decorators3 : node.decorators = [];
10280 (_node$override2 = node.override) != null ? _node$override2 : node.override = false;
10281 (_node$optional4 = node.optional) != null ? _node$optional4 : node.optional = false;
10282 return;
10283 case "ClassExpression":
10284 (_node$id = node.id) != null ? _node$id : node.id = null;
10285 case "ClassDeclaration":
10286 (_node$abstract = node.abstract) != null ? _node$abstract : node.abstract = false;
10287 (_node$declare3 = node.declare) != null ? _node$declare3 : node.declare = false;
10288 (_node$decorators4 = node.decorators) != null ? _node$decorators4 : node.decorators = [];
10289 (_node$implements = node.implements) != null ? _node$implements : node.implements = [];
10290 (_node$superTypeArgume = node.superTypeArguments) != null ? _node$superTypeArgume : node.superTypeArguments = undefined;
10291 (_node$typeParameters2 = node.typeParameters) != null ? _node$typeParameters2 : node.typeParameters = undefined;
10292 return;
10293 case "TSTypeAliasDeclaration":
10294 case "VariableDeclaration":
10295 (_node$declare4 = node.declare) != null ? _node$declare4 : node.declare = false;
10296 return;
10297 case "VariableDeclarator":
10298 (_node$definite2 = node.definite) != null ? _node$definite2 : node.definite = false;
10299 return;
10300 case "TSEnumDeclaration":
10301 (_node$const = node.const) != null ? _node$const : node.const = false;
10302 (_node$declare5 = node.declare) != null ? _node$declare5 : node.declare = false;
10303 return;
10304 case "TSEnumMember":
10305 (_node$computed = node.computed) != null ? _node$computed : node.computed = false;
10306 return;
10307 case "TSImportType":
10308 (_node$qualifier = node.qualifier) != null ? _node$qualifier : node.qualifier = null;
10309 (_node$options = node.options) != null ? _node$options : node.options = null;
10310 return;
10311 case "TSInterfaceDeclaration":
10312 (_node$declare6 = node.declare) != null ? _node$declare6 : node.declare = false;
10313 (_node$extends = node.extends) != null ? _node$extends : node.extends = [];
10314 return;
10315 case "TSMappedType":
10316 (_node$optional5 = node.optional) != null ? _node$optional5 : node.optional = false;
10317 (_node$readonly4 = node.readonly) != null ? _node$readonly4 : node.readonly = undefined;
10318 return;
10319 case "TSModuleDeclaration":
10320 (_node$declare7 = node.declare) != null ? _node$declare7 : node.declare = false;
10321 (_node$global = node.global) != null ? _node$global : node.global = node.kind === "global";
10322 return;
10323 case "TSTypeParameter":
10324 (_node$const2 = node.const) != null ? _node$const2 : node.const = false;
10325 (_node$in = node.in) != null ? _node$in : node.in = false;
10326 (_node$out = node.out) != null ? _node$out : node.out = false;
10327 return;
10328 }
10329 }
10330 chStartsBindingIdentifierAndNotRelationalOperator(ch, pos) {
10331 if (isIdentifierStart(ch)) {
10332 keywordAndTSRelationalOperator.lastIndex = pos;
10333 if (keywordAndTSRelationalOperator.test(this.input)) {
10334 const endCh = this.codePointAtPos(keywordAndTSRelationalOperator.lastIndex);
10335 if (!isIdentifierChar(endCh) && endCh !== 92) {
10336 return false;
10337 }
10338 }
10339 return true;
10340 } else if (ch === 92) {
10341 return true;
10342 } else {
10343 return false;
10344 }
10345 }
10346 nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine() {
10347 const next = this.nextTokenInLineStart();
10348 const nextCh = this.codePointAtPos(next);
10349 return this.chStartsBindingIdentifierAndNotRelationalOperator(nextCh, next);
10350 }
10351 nextTokenIsIdentifierOrStringLiteralOnSameLine() {
10352 const next = this.nextTokenInLineStart();
10353 const nextCh = this.codePointAtPos(next);
10354 return this.chStartsBindingIdentifier(nextCh, next) || nextCh === 34 || nextCh === 39;
10355 }
10356};
10357function isPossiblyLiteralEnum(expression) {
10358 if (expression.type !== "MemberExpression") return false;
10359 const {
10360 computed,
10361 property
10362 } = expression;
10363 if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
10364 return false;
10365 }
10366 return isUncomputedMemberExpressionChain(expression.object);
10367}
10368function isValidAmbientConstInitializer(expression, estree) {
10369 var _expression$extra;
10370 const {
10371 type
10372 } = expression;
10373 if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
10374 return false;
10375 }
10376 if (estree) {
10377 if (type === "Literal") {
10378 const {
10379 value
10380 } = expression;
10381 if (typeof value === "string" || typeof value === "boolean") {
10382 return true;
10383 }
10384 }
10385 } else {
10386 if (type === "StringLiteral" || type === "BooleanLiteral") {
10387 return true;
10388 }
10389 }
10390 if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
10391 return true;
10392 }
10393 if (type === "TemplateLiteral" && expression.expressions.length === 0) {
10394 return true;
10395 }
10396 if (isPossiblyLiteralEnum(expression)) {
10397 return true;
10398 }
10399 return false;
10400}
10401function isNumber(expression, estree) {
10402 if (estree) {
10403 return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
10404 }
10405 return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
10406}
10407function isNegativeNumber(expression, estree) {
10408 if (expression.type === "UnaryExpression") {
10409 const {
10410 operator,
10411 argument
10412 } = expression;
10413 if (operator === "-" && isNumber(argument, estree)) {
10414 return true;
10415 }
10416 }
10417 return false;
10418}
10419function isUncomputedMemberExpressionChain(expression) {
10420 if (expression.type === "Identifier") return true;
10421 if (expression.type !== "MemberExpression" || expression.computed) {
10422 return false;
10423 }
10424 return isUncomputedMemberExpressionChain(expression.object);
10425}
10426const PlaceholderErrors = ParseErrorEnum`placeholders`({
10427 ClassNameIsRequired: "A class name is required.",
10428 UnexpectedSpace: "Unexpected space in placeholder."
10429});
10430var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
10431 parsePlaceholder(expectedNode) {
10432 if (this.match(133)) {
10433 const node = this.startNode();
10434 this.next();
10435 this.assertNoSpace();
10436 node.name = super.parseIdentifier(true);
10437 this.assertNoSpace();
10438 this.expect(133);
10439 return this.finishPlaceholder(node, expectedNode);
10440 }
10441 }
10442 finishPlaceholder(node, expectedNode) {
10443 let placeholder = node;
10444 if (!placeholder.expectedNode || !placeholder.type) {
10445 placeholder = this.finishNode(placeholder, "Placeholder");
10446 }
10447 placeholder.expectedNode = expectedNode;
10448 return placeholder;
10449 }
10450 getTokenFromCode(code) {
10451 if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
10452 this.finishOp(133, 2);
10453 } else {
10454 super.getTokenFromCode(code);
10455 }
10456 }
10457 parseExprAtom(refExpressionErrors) {
10458 return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
10459 }
10460 parseIdentifier(liberal) {
10461 return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
10462 }
10463 checkReservedWord(word, startLoc, checkKeywords, isBinding) {
10464 if (word !== undefined) {
10465 super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
10466 }
10467 }
10468 cloneIdentifier(node) {
10469 const cloned = super.cloneIdentifier(node);
10470 if (cloned.type === "Placeholder") {
10471 cloned.expectedNode = node.expectedNode;
10472 }
10473 return cloned;
10474 }
10475 cloneStringLiteral(node) {
10476 if (node.type === "Placeholder") {
10477 return this.cloneIdentifier(node);
10478 }
10479 return super.cloneStringLiteral(node);
10480 }
10481 parseBindingAtom() {
10482 return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
10483 }
10484 isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
10485 return type === "Placeholder" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
10486 }
10487 toAssignable(node, isLHS) {
10488 if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
10489 node.expectedNode = "Pattern";
10490 } else {
10491 super.toAssignable(node, isLHS);
10492 }
10493 }
10494 chStartsBindingIdentifier(ch, pos) {
10495 if (super.chStartsBindingIdentifier(ch, pos)) {
10496 return true;
10497 }
10498 const next = this.nextTokenStart();
10499 if (this.input.charCodeAt(next) === 37 && this.input.charCodeAt(next + 1) === 37) {
10500 return true;
10501 }
10502 return false;
10503 }
10504 verifyBreakContinue(node, isBreak) {
10505 var _node$label;
10506 if (((_node$label = node.label) == null ? void 0 : _node$label.type) === "Placeholder") return;
10507 super.verifyBreakContinue(node, isBreak);
10508 }
10509 parseExpressionStatement(node, expr) {
10510 var _expr$extra;
10511 if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
10512 return super.parseExpressionStatement(node, expr);
10513 }
10514 if (this.match(14)) {
10515 const stmt = node;
10516 stmt.label = this.finishPlaceholder(expr, "Identifier");
10517 this.next();
10518 stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
10519 return this.finishNode(stmt, "LabeledStatement");
10520 }
10521 this.semicolon();
10522 const stmtPlaceholder = node;
10523 stmtPlaceholder.name = expr.name;
10524 return this.finishPlaceholder(stmtPlaceholder, "Statement");
10525 }
10526 parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
10527 return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
10528 }
10529 parseFunctionId(requireId) {
10530 return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
10531 }
10532 parseClass(node, isStatement, optionalId) {
10533 const type = isStatement ? "ClassDeclaration" : "ClassExpression";
10534 this.next();
10535 const oldStrict = this.state.strict;
10536 const placeholder = this.parsePlaceholder("Identifier");
10537 if (placeholder) {
10538 if (this.match(81) || this.match(133) || this.match(5)) {
10539 node.id = placeholder;
10540 } else if (optionalId || !isStatement) {
10541 node.id = null;
10542 node.body = this.finishPlaceholder(placeholder, "ClassBody");
10543 return this.finishNode(node, type);
10544 } else {
10545 throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
10546 }
10547 } else {
10548 this.parseClassId(node, isStatement, optionalId);
10549 }
10550 super.parseClassSuper(node);
10551 node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
10552 return this.finishNode(node, type);
10553 }
10554 parseExport(node, decorators) {
10555 const placeholder = this.parsePlaceholder("Identifier");
10556 if (!placeholder) return super.parseExport(node, decorators);
10557 const node2 = node;
10558 if (!this.isContextual(98) && !this.match(12)) {
10559 node2.specifiers = [];
10560 node2.source = null;
10561 node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
10562 return this.finishNode(node2, "ExportNamedDeclaration");
10563 }
10564 this.expectPlugin("exportDefaultFrom");
10565 const specifier = this.startNode();
10566 specifier.exported = placeholder;
10567 node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
10568 return super.parseExport(node2, decorators);
10569 }
10570 isExportDefaultSpecifier() {
10571 if (this.match(65)) {
10572 const next = this.nextTokenStart();
10573 if (this.isUnparsedContextual(next, "from")) {
10574 if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
10575 return true;
10576 }
10577 }
10578 }
10579 return super.isExportDefaultSpecifier();
10580 }
10581 maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
10582 var _specifiers;
10583 if ((_specifiers = node.specifiers) != null && _specifiers.length) {
10584 return true;
10585 }
10586 return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
10587 }
10588 checkExport(node) {
10589 const {
10590 specifiers
10591 } = node;
10592 if (specifiers != null && specifiers.length) {
10593 node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
10594 }
10595 super.checkExport(node);
10596 node.specifiers = specifiers;
10597 }
10598 parseImport(node) {
10599 const placeholder = this.parsePlaceholder("Identifier");
10600 if (!placeholder) return super.parseImport(node);
10601 node.specifiers = [];
10602 if (!this.isContextual(98) && !this.match(12)) {
10603 node.source = this.finishPlaceholder(placeholder, "StringLiteral");
10604 this.semicolon();
10605 return this.finishNode(node, "ImportDeclaration");
10606 }
10607 const specifier = this.startNodeAtNode(placeholder);
10608 specifier.local = placeholder;
10609 node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
10610 if (this.eat(12)) {
10611 const hasStarImport = this.maybeParseStarImportSpecifier(node);
10612 if (!hasStarImport) this.parseNamedImportSpecifiers(node);
10613 }
10614 this.expectContextual(98);
10615 node.source = this.parseImportSource();
10616 this.semicolon();
10617 return this.finishNode(node, "ImportDeclaration");
10618 }
10619 parseImportSource() {
10620 return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
10621 }
10622 assertNoSpace() {
10623 if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
10624 this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
10625 }
10626 }
10627};
10628var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
10629 parseV8Intrinsic() {
10630 if (this.match(54)) {
10631 const v8IntrinsicStartLoc = this.state.startLoc;
10632 const node = this.startNode();
10633 this.next();
10634 if (tokenIsIdentifier(this.state.type)) {
10635 const name = this.parseIdentifierName();
10636 const identifier = this.createIdentifier(node, name);
10637 this.castNodeTo(identifier, "V8IntrinsicIdentifier");
10638 if (this.match(10)) {
10639 return identifier;
10640 }
10641 }
10642 this.unexpected(v8IntrinsicStartLoc);
10643 }
10644 }
10645 parseExprAtom(refExpressionErrors) {
10646 return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
10647 }
10648};
10649const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
10650const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
10651function validatePlugins(pluginsMap) {
10652 if (pluginsMap.has("decorators")) {
10653 if (pluginsMap.has("decorators-legacy")) {
10654 throw new Error("Cannot use the decorators and decorators-legacy plugin together");
10655 }
10656 const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
10657 if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
10658 throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
10659 }
10660 const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
10661 if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
10662 throw new Error("'allowCallParenthesized' must be a boolean.");
10663 }
10664 }
10665 if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
10666 throw new Error("Cannot combine flow and typescript plugins.");
10667 }
10668 if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
10669 throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
10670 }
10671 if (pluginsMap.has("pipelineOperator")) {
10672 var _pluginsMap$get2;
10673 const proposal = pluginsMap.get("pipelineOperator").proposal;
10674 if (!PIPELINE_PROPOSALS.includes(proposal)) {
10675 const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
10676 throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
10677 }
10678 if (proposal === "hack") {
10679 var _pluginsMap$get;
10680 if (pluginsMap.has("placeholders")) {
10681 throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
10682 }
10683 if (pluginsMap.has("v8intrinsic")) {
10684 throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
10685 }
10686 const topicToken = pluginsMap.get("pipelineOperator").topicToken;
10687 if (!TOPIC_TOKENS.includes(topicToken)) {
10688 const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
10689 throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
10690 }
10691 if (topicToken === "#" && ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash") {
10692 throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
10693 }
10694 } else if (proposal === "smart" && ((_pluginsMap$get2 = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get2.syntaxType) === "hash") {
10695 throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
10696 }
10697 }
10698 if (pluginsMap.has("moduleAttributes")) {
10699 if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
10700 throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
10701 }
10702 const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
10703 if (moduleAttributesVersionPluginOption !== "may-2020") {
10704 throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
10705 }
10706 }
10707 if (pluginsMap.has("importAssertions")) {
10708 if (pluginsMap.has("deprecatedImportAssert")) {
10709 throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
10710 }
10711 }
10712 if (pluginsMap.has("deprecatedImportAssert")) ;else if (pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
10713 pluginsMap.set("deprecatedImportAssert", {});
10714 }
10715 if (pluginsMap.has("recordAndTuple")) {
10716 const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
10717 if (syntaxType != null) {
10718 const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
10719 if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
10720 throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
10721 }
10722 }
10723 }
10724 if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
10725 const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
10726 error.missingPlugins = "doExpressions";
10727 throw error;
10728 }
10729 if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
10730 throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
10731 }
10732 if (pluginsMap.has("discardBinding") && pluginsMap.get("discardBinding").syntaxType !== "void") {
10733 throw new Error("The 'discardBinding' plugin requires a 'syntaxType' option. Currently the only supported value is 'void'.");
10734 }
10735}
10736const mixinPlugins = {
10737 estree,
10738 jsx,
10739 flow,
10740 typescript,
10741 v8intrinsic,
10742 placeholders
10743};
10744const mixinPluginNames = Object.keys(mixinPlugins);
10745class ExpressionParser extends LValParser {
10746 checkProto(prop, isRecord, sawProto, refExpressionErrors) {
10747 if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
10748 return sawProto;
10749 }
10750 const key = prop.key;
10751 const name = key.type === "Identifier" ? key.name : key.value;
10752 if (name === "__proto__") {
10753 if (isRecord) {
10754 this.raise(Errors.RecordNoProto, key);
10755 return true;
10756 }
10757 if (sawProto) {
10758 if (refExpressionErrors) {
10759 if (refExpressionErrors.doubleProtoLoc === null) {
10760 refExpressionErrors.doubleProtoLoc = key.loc.start;
10761 }
10762 } else {
10763 this.raise(Errors.DuplicateProto, key);
10764 }
10765 }
10766 return true;
10767 }
10768 return sawProto;
10769 }
10770 shouldExitDescending(expr, potentialArrowAt) {
10771 return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
10772 }
10773 getExpression() {
10774 this.enterInitialScopes();
10775 this.nextToken();
10776 if (this.match(140)) {
10777 throw this.raise(Errors.ParseExpressionEmptyInput, this.state.startLoc);
10778 }
10779 const expr = this.parseExpression();
10780 if (!this.match(140)) {
10781 throw this.raise(Errors.ParseExpressionExpectsEOF, this.state.startLoc, {
10782 unexpected: this.input.codePointAt(this.state.start)
10783 });
10784 }
10785 this.finalizeRemainingComments();
10786 expr.comments = this.comments;
10787 expr.errors = this.state.errors;
10788 if (this.optionFlags & 256) {
10789 expr.tokens = this.tokens;
10790 }
10791 return expr;
10792 }
10793 parseExpression(disallowIn, refExpressionErrors) {
10794 if (disallowIn) {
10795 return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
10796 }
10797 return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
10798 }
10799 parseExpressionBase(refExpressionErrors) {
10800 const startLoc = this.state.startLoc;
10801 const expr = this.parseMaybeAssign(refExpressionErrors);
10802 if (this.match(12)) {
10803 const node = this.startNodeAt(startLoc);
10804 node.expressions = [expr];
10805 while (this.eat(12)) {
10806 node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
10807 }
10808 this.toReferencedList(node.expressions);
10809 return this.finishNode(node, "SequenceExpression");
10810 }
10811 return expr;
10812 }
10813 parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
10814 return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
10815 }
10816 parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
10817 return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
10818 }
10819 setOptionalParametersError(refExpressionErrors) {
10820 refExpressionErrors.optionalParametersLoc = this.state.startLoc;
10821 }
10822 parseMaybeAssign(refExpressionErrors, afterLeftParse) {
10823 const startLoc = this.state.startLoc;
10824 const isYield = this.isContextual(108);
10825 if (isYield) {
10826 if (this.prodParam.hasYield) {
10827 this.next();
10828 let left = this.parseYield(startLoc);
10829 if (afterLeftParse) {
10830 left = afterLeftParse.call(this, left, startLoc);
10831 }
10832 return left;
10833 }
10834 }
10835 let ownExpressionErrors;
10836 if (refExpressionErrors) {
10837 ownExpressionErrors = false;
10838 } else {
10839 refExpressionErrors = new ExpressionErrors();
10840 ownExpressionErrors = true;
10841 }
10842 const {
10843 type
10844 } = this.state;
10845 if (type === 10 || tokenIsIdentifier(type)) {
10846 this.state.potentialArrowAt = this.state.start;
10847 }
10848 let left = this.parseMaybeConditional(refExpressionErrors);
10849 if (afterLeftParse) {
10850 left = afterLeftParse.call(this, left, startLoc);
10851 }
10852 if (tokenIsAssignment(this.state.type)) {
10853 const node = this.startNodeAt(startLoc);
10854 const operator = this.state.value;
10855 node.operator = operator;
10856 if (this.match(29)) {
10857 this.toAssignable(left, true);
10858 node.left = left;
10859 const startIndex = startLoc.index;
10860 if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
10861 refExpressionErrors.doubleProtoLoc = null;
10862 }
10863 if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
10864 refExpressionErrors.shorthandAssignLoc = null;
10865 }
10866 if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
10867 this.checkDestructuringPrivate(refExpressionErrors);
10868 refExpressionErrors.privateKeyLoc = null;
10869 }
10870 if (refExpressionErrors.voidPatternLoc != null && refExpressionErrors.voidPatternLoc.index >= startIndex) {
10871 refExpressionErrors.voidPatternLoc = null;
10872 }
10873 } else {
10874 node.left = left;
10875 }
10876 this.next();
10877 node.right = this.parseMaybeAssign();
10878 this.checkLVal(left, this.finishNode(node, "AssignmentExpression"), undefined, undefined, undefined, undefined, operator === "||=" || operator === "&&=" || operator === "??=");
10879 return node;
10880 } else if (ownExpressionErrors) {
10881 this.checkExpressionErrors(refExpressionErrors, true);
10882 }
10883 if (isYield) {
10884 const {
10885 type
10886 } = this.state;
10887 const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
10888 if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
10889 this.raiseOverwrite(Errors.YieldNotInGeneratorFunction, startLoc);
10890 return this.parseYield(startLoc);
10891 }
10892 }
10893 return left;
10894 }
10895 parseMaybeConditional(refExpressionErrors) {
10896 const startLoc = this.state.startLoc;
10897 const potentialArrowAt = this.state.potentialArrowAt;
10898 const expr = this.parseExprOps(refExpressionErrors);
10899 if (this.shouldExitDescending(expr, potentialArrowAt)) {
10900 return expr;
10901 }
10902 return this.parseConditional(expr, startLoc, refExpressionErrors);
10903 }
10904 parseConditional(expr, startLoc, refExpressionErrors) {
10905 if (this.eat(17)) {
10906 const node = this.startNodeAt(startLoc);
10907 node.test = expr;
10908 node.consequent = this.parseMaybeAssignAllowIn();
10909 this.expect(14);
10910 node.alternate = this.parseMaybeAssign();
10911 return this.finishNode(node, "ConditionalExpression");
10912 }
10913 return expr;
10914 }
10915 parseMaybeUnaryOrPrivate(refExpressionErrors) {
10916 return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
10917 }
10918 parseExprOps(refExpressionErrors) {
10919 const startLoc = this.state.startLoc;
10920 const potentialArrowAt = this.state.potentialArrowAt;
10921 const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
10922 if (this.shouldExitDescending(expr, potentialArrowAt)) {
10923 return expr;
10924 }
10925 return this.parseExprOp(expr, startLoc, -1);
10926 }
10927 parseExprOp(left, leftStartLoc, minPrec) {
10928 if (this.isPrivateName(left)) {
10929 const value = this.getPrivateNameSV(left);
10930 if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
10931 this.raise(Errors.PrivateInExpectedIn, left, {
10932 identifierName: value
10933 });
10934 }
10935 this.classScope.usePrivateName(value, left.loc.start);
10936 }
10937 const op = this.state.type;
10938 if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
10939 let prec = tokenOperatorPrecedence(op);
10940 if (prec > minPrec) {
10941 if (op === 39) {
10942 this.expectPlugin("pipelineOperator");
10943 if (this.state.inFSharpPipelineDirectBody) {
10944 return left;
10945 }
10946 this.checkPipelineAtInfixOperator(left, leftStartLoc);
10947 }
10948 const node = this.startNodeAt(leftStartLoc);
10949 node.left = left;
10950 node.operator = this.state.value;
10951 const logical = op === 41 || op === 42;
10952 const coalesce = op === 40;
10953 if (coalesce) {
10954 prec = tokenOperatorPrecedence(42);
10955 }
10956 this.next();
10957 if (op === 39 && this.hasPlugin(["pipelineOperator", {
10958 proposal: "minimal"
10959 }])) {
10960 if (this.state.type === 96 && this.prodParam.hasAwait) {
10961 throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
10962 }
10963 }
10964 node.right = this.parseExprOpRightExpr(op, prec);
10965 const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
10966 const nextOp = this.state.type;
10967 if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
10968 throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
10969 }
10970 return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
10971 }
10972 }
10973 return left;
10974 }
10975 parseExprOpRightExpr(op, prec) {
10976 const startLoc = this.state.startLoc;
10977 switch (op) {
10978 case 39:
10979 switch (this.getPluginOption("pipelineOperator", "proposal")) {
10980 case "hack":
10981 return this.withTopicBindingContext(() => {
10982 return this.parseHackPipeBody();
10983 });
10984 case "fsharp":
10985 return this.withSoloAwaitPermittingContext(() => {
10986 return this.parseFSharpPipelineBody(prec);
10987 });
10988 }
10989 if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
10990 return this.withTopicBindingContext(() => {
10991 if (this.prodParam.hasYield && this.isContextual(108)) {
10992 throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
10993 }
10994 return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
10995 });
10996 }
10997 default:
10998 return this.parseExprOpBaseRightExpr(op, prec);
10999 }
11000 }
11001 parseExprOpBaseRightExpr(op, prec) {
11002 const startLoc = this.state.startLoc;
11003 return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
11004 }
11005 parseHackPipeBody() {
11006 var _body$extra;
11007 const {
11008 startLoc
11009 } = this.state;
11010 const body = this.parseMaybeAssign();
11011 const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
11012 if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
11013 this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
11014 type: body.type
11015 });
11016 }
11017 if (!this.topicReferenceWasUsedInCurrentContext()) {
11018 this.raise(Errors.PipeTopicUnused, startLoc);
11019 }
11020 return body;
11021 }
11022 checkExponentialAfterUnary(node) {
11023 if (this.match(57)) {
11024 this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
11025 }
11026 }
11027 parseMaybeUnary(refExpressionErrors, sawUnary) {
11028 const startLoc = this.state.startLoc;
11029 const isAwait = this.isContextual(96);
11030 if (isAwait && this.recordAwaitIfAllowed()) {
11031 this.next();
11032 const expr = this.parseAwait(startLoc);
11033 if (!sawUnary) this.checkExponentialAfterUnary(expr);
11034 return expr;
11035 }
11036 const update = this.match(34);
11037 const node = this.startNode();
11038 if (tokenIsPrefix(this.state.type)) {
11039 node.operator = this.state.value;
11040 node.prefix = true;
11041 if (this.match(72)) {
11042 this.expectPlugin("throwExpressions");
11043 }
11044 const isDelete = this.match(89);
11045 this.next();
11046 node.argument = this.parseMaybeUnary(null, true);
11047 this.checkExpressionErrors(refExpressionErrors, true);
11048 if (this.state.strict && isDelete) {
11049 const arg = node.argument;
11050 if (arg.type === "Identifier") {
11051 this.raise(Errors.StrictDelete, node);
11052 } else if (this.hasPropertyAsPrivateName(arg)) {
11053 this.raise(Errors.DeletePrivateField, node);
11054 }
11055 }
11056 if (!update) {
11057 if (!sawUnary) {
11058 this.checkExponentialAfterUnary(node);
11059 }
11060 return this.finishNode(node, "UnaryExpression");
11061 }
11062 }
11063 const expr = this.parseUpdate(node, update, refExpressionErrors);
11064 if (isAwait) {
11065 const {
11066 type
11067 } = this.state;
11068 const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
11069 if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
11070 this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
11071 return this.parseAwait(startLoc);
11072 }
11073 }
11074 return expr;
11075 }
11076 parseUpdate(node, update, refExpressionErrors) {
11077 if (update) {
11078 const updateExpressionNode = node;
11079 this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
11080 return node;
11081 }
11082 const startLoc = this.state.startLoc;
11083 let expr = this.parseExprSubscripts(refExpressionErrors);
11084 if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
11085 while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
11086 const node = this.startNodeAt(startLoc);
11087 node.operator = this.state.value;
11088 node.prefix = false;
11089 node.argument = expr;
11090 this.next();
11091 this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
11092 }
11093 return expr;
11094 }
11095 parseExprSubscripts(refExpressionErrors) {
11096 const startLoc = this.state.startLoc;
11097 const potentialArrowAt = this.state.potentialArrowAt;
11098 const expr = this.parseExprAtom(refExpressionErrors);
11099 if (this.shouldExitDescending(expr, potentialArrowAt)) {
11100 return expr;
11101 }
11102 return this.parseSubscripts(expr, startLoc);
11103 }
11104 parseSubscripts(base, startLoc, noCalls) {
11105 const state = {
11106 optionalChainMember: false,
11107 maybeAsyncArrow: this.atPossibleAsyncArrow(base),
11108 stop: false
11109 };
11110 do {
11111 base = this.parseSubscript(base, startLoc, noCalls, state);
11112 state.maybeAsyncArrow = false;
11113 } while (!state.stop);
11114 return base;
11115 }
11116 parseSubscript(base, startLoc, noCalls, state) {
11117 const {
11118 type
11119 } = this.state;
11120 if (!noCalls && type === 15) {
11121 return this.parseBind(base, startLoc, noCalls, state);
11122 } else if (tokenIsTemplate(type)) {
11123 return this.parseTaggedTemplateExpression(base, startLoc, state);
11124 }
11125 let optional = false;
11126 if (type === 18) {
11127 if (noCalls) {
11128 this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
11129 if (this.lookaheadCharCode() === 40) {
11130 return this.stopParseSubscript(base, state);
11131 }
11132 }
11133 state.optionalChainMember = optional = true;
11134 this.next();
11135 }
11136 if (!noCalls && this.match(10)) {
11137 return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
11138 } else {
11139 const computed = this.eat(0);
11140 if (computed || optional || this.eat(16)) {
11141 return this.parseMember(base, startLoc, state, computed, optional);
11142 } else {
11143 return this.stopParseSubscript(base, state);
11144 }
11145 }
11146 }
11147 stopParseSubscript(base, state) {
11148 state.stop = true;
11149 return base;
11150 }
11151 parseMember(base, startLoc, state, computed, optional) {
11152 const node = this.startNodeAt(startLoc);
11153 node.object = base;
11154 node.computed = computed;
11155 if (computed) {
11156 node.property = this.parseExpression();
11157 this.expect(3);
11158 } else if (this.match(139)) {
11159 if (base.type === "Super") {
11160 this.raise(Errors.SuperPrivateField, startLoc);
11161 }
11162 this.classScope.usePrivateName(this.state.value, this.state.startLoc);
11163 node.property = this.parsePrivateName();
11164 } else {
11165 node.property = this.parseIdentifier(true);
11166 }
11167 if (state.optionalChainMember) {
11168 node.optional = optional;
11169 return this.finishNode(node, "OptionalMemberExpression");
11170 } else {
11171 return this.finishNode(node, "MemberExpression");
11172 }
11173 }
11174 parseBind(base, startLoc, noCalls, state) {
11175 const node = this.startNodeAt(startLoc);
11176 node.object = base;
11177 this.next();
11178 node.callee = this.parseNoCallExpr();
11179 state.stop = true;
11180 return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
11181 }
11182 parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
11183 const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
11184 let refExpressionErrors = null;
11185 this.state.maybeInArrowParameters = true;
11186 this.next();
11187 const node = this.startNodeAt(startLoc);
11188 node.callee = base;
11189 const {
11190 maybeAsyncArrow,
11191 optionalChainMember
11192 } = state;
11193 if (maybeAsyncArrow) {
11194 this.expressionScope.enter(newAsyncArrowScope());
11195 refExpressionErrors = new ExpressionErrors();
11196 }
11197 if (optionalChainMember) {
11198 node.optional = optional;
11199 }
11200 if (optional) {
11201 node.arguments = this.parseCallExpressionArguments();
11202 } else {
11203 node.arguments = this.parseCallExpressionArguments(base.type !== "Super", node, refExpressionErrors);
11204 }
11205 let finishedNode = this.finishCallExpression(node, optionalChainMember);
11206 if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
11207 state.stop = true;
11208 this.checkDestructuringPrivate(refExpressionErrors);
11209 this.expressionScope.validateAsPattern();
11210 this.expressionScope.exit();
11211 finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
11212 } else {
11213 if (maybeAsyncArrow) {
11214 this.checkExpressionErrors(refExpressionErrors, true);
11215 this.expressionScope.exit();
11216 }
11217 this.toReferencedArguments(finishedNode);
11218 }
11219 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
11220 return finishedNode;
11221 }
11222 toReferencedArguments(node, isParenthesizedExpr) {
11223 this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
11224 }
11225 parseTaggedTemplateExpression(base, startLoc, state) {
11226 const node = this.startNodeAt(startLoc);
11227 node.tag = base;
11228 node.quasi = this.parseTemplate(true);
11229 if (state.optionalChainMember) {
11230 this.raise(Errors.OptionalChainingNoTemplate, startLoc);
11231 }
11232 return this.finishNode(node, "TaggedTemplateExpression");
11233 }
11234 atPossibleAsyncArrow(base) {
11235 return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && this.offsetToSourcePos(base.start) === this.state.potentialArrowAt;
11236 }
11237 finishCallExpression(node, optional) {
11238 if (node.callee.type === "Import") {
11239 if (node.arguments.length === 0 || node.arguments.length > 2) {
11240 this.raise(Errors.ImportCallArity, node);
11241 } else {
11242 for (const arg of node.arguments) {
11243 if (arg.type === "SpreadElement") {
11244 this.raise(Errors.ImportCallSpreadArgument, arg);
11245 }
11246 }
11247 }
11248 }
11249 return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
11250 }
11251 parseCallExpressionArguments(allowPlaceholder, nodeForExtra, refExpressionErrors) {
11252 const elts = [];
11253 let first = true;
11254 const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
11255 this.state.inFSharpPipelineDirectBody = false;
11256 while (!this.eat(11)) {
11257 if (first) {
11258 first = false;
11259 } else {
11260 this.expect(12);
11261 if (this.match(11)) {
11262 if (nodeForExtra) {
11263 this.addTrailingCommaExtraToNode(nodeForExtra);
11264 }
11265 this.next();
11266 break;
11267 }
11268 }
11269 elts.push(this.parseExprListItem(11, false, refExpressionErrors, allowPlaceholder));
11270 }
11271 this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
11272 return elts;
11273 }
11274 shouldParseAsyncArrow() {
11275 return this.match(19) && !this.canInsertSemicolon();
11276 }
11277 parseAsyncArrowFromCallExpression(node, call) {
11278 var _call$extra;
11279 this.resetPreviousNodeTrailingComments(call);
11280 this.expect(19);
11281 this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
11282 if (call.innerComments) {
11283 setInnerComments(node, call.innerComments);
11284 }
11285 if (call.callee.trailingComments) {
11286 setInnerComments(node, call.callee.trailingComments);
11287 }
11288 return node;
11289 }
11290 parseNoCallExpr() {
11291 const startLoc = this.state.startLoc;
11292 return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
11293 }
11294 parseExprAtom(refExpressionErrors) {
11295 let node;
11296 let decorators = null;
11297 const {
11298 type
11299 } = this.state;
11300 switch (type) {
11301 case 79:
11302 return this.parseSuper();
11303 case 83:
11304 node = this.startNode();
11305 this.next();
11306 if (this.match(16)) {
11307 return this.parseImportMetaPropertyOrPhaseCall(node);
11308 }
11309 if (this.match(10)) {
11310 if (this.optionFlags & 512) {
11311 return this.parseImportCall(node);
11312 } else {
11313 return this.finishNode(node, "Import");
11314 }
11315 } else {
11316 this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
11317 return this.finishNode(node, "Import");
11318 }
11319 case 78:
11320 node = this.startNode();
11321 this.next();
11322 return this.finishNode(node, "ThisExpression");
11323 case 90:
11324 {
11325 return this.parseDo(this.startNode(), false);
11326 }
11327 case 56:
11328 case 31:
11329 {
11330 this.readRegexp();
11331 return this.parseRegExpLiteral(this.state.value);
11332 }
11333 case 135:
11334 return this.parseNumericLiteral(this.state.value);
11335 case 136:
11336 return this.parseBigIntLiteral(this.state.value);
11337 case 134:
11338 return this.parseStringLiteral(this.state.value);
11339 case 84:
11340 return this.parseNullLiteral();
11341 case 85:
11342 return this.parseBooleanLiteral(true);
11343 case 86:
11344 return this.parseBooleanLiteral(false);
11345 case 10:
11346 {
11347 const canBeArrow = this.state.potentialArrowAt === this.state.start;
11348 return this.parseParenAndDistinguishExpression(canBeArrow);
11349 }
11350 case 0:
11351 {
11352 return this.parseArrayLike(3, false, refExpressionErrors);
11353 }
11354 case 5:
11355 {
11356 return this.parseObjectLike(8, false, false, refExpressionErrors);
11357 }
11358 case 68:
11359 return this.parseFunctionOrFunctionSent();
11360 case 26:
11361 decorators = this.parseDecorators();
11362 case 80:
11363 return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
11364 case 77:
11365 return this.parseNewOrNewTarget();
11366 case 25:
11367 case 24:
11368 return this.parseTemplate(false);
11369 case 15:
11370 {
11371 node = this.startNode();
11372 this.next();
11373 node.object = null;
11374 const callee = node.callee = this.parseNoCallExpr();
11375 if (callee.type === "MemberExpression") {
11376 return this.finishNode(node, "BindExpression");
11377 } else {
11378 throw this.raise(Errors.UnsupportedBind, callee);
11379 }
11380 }
11381 case 139:
11382 {
11383 this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
11384 identifierName: this.state.value
11385 });
11386 return this.parsePrivateName();
11387 }
11388 case 33:
11389 {
11390 return this.parseTopicReferenceThenEqualsSign(54, "%");
11391 }
11392 case 32:
11393 {
11394 return this.parseTopicReferenceThenEqualsSign(44, "^");
11395 }
11396 case 37:
11397 case 38:
11398 {
11399 return this.parseTopicReference("hack");
11400 }
11401 case 44:
11402 case 54:
11403 case 27:
11404 {
11405 const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
11406 if (pipeProposal) {
11407 return this.parseTopicReference(pipeProposal);
11408 }
11409 throw this.unexpected();
11410 }
11411 case 47:
11412 {
11413 const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
11414 if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
11415 throw this.expectOnePlugin(["jsx", "flow", "typescript"]);
11416 }
11417 throw this.unexpected();
11418 }
11419 default:
11420 if (type === 137) {
11421 return this.parseDecimalLiteral(this.state.value);
11422 } else if (type === 2 || type === 1) {
11423 return this.parseArrayLike(this.state.type === 2 ? 4 : 3, true);
11424 } else if (type === 6 || type === 7) {
11425 return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
11426 }
11427 if (tokenIsIdentifier(type)) {
11428 if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
11429 return this.parseModuleExpression();
11430 }
11431 const canBeArrow = this.state.potentialArrowAt === this.state.start;
11432 const containsEsc = this.state.containsEsc;
11433 const id = this.parseIdentifier();
11434 if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
11435 const {
11436 type
11437 } = this.state;
11438 if (type === 68) {
11439 this.resetPreviousNodeTrailingComments(id);
11440 this.next();
11441 return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
11442 } else if (tokenIsIdentifier(type)) {
11443 if (canBeArrow && this.lookaheadCharCode() === 61) {
11444 return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
11445 } else {
11446 return id;
11447 }
11448 } else if (type === 90) {
11449 this.resetPreviousNodeTrailingComments(id);
11450 return this.parseDo(this.startNodeAtNode(id), true);
11451 }
11452 }
11453 if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
11454 this.next();
11455 return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
11456 }
11457 return id;
11458 } else {
11459 throw this.unexpected();
11460 }
11461 }
11462 }
11463 parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
11464 const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
11465 if (pipeProposal) {
11466 this.state.type = topicTokenType;
11467 this.state.value = topicTokenValue;
11468 this.state.pos--;
11469 this.state.end--;
11470 this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
11471 return this.parseTopicReference(pipeProposal);
11472 }
11473 throw this.unexpected();
11474 }
11475 parseTopicReference(pipeProposal) {
11476 const node = this.startNode();
11477 const startLoc = this.state.startLoc;
11478 const tokenType = this.state.type;
11479 this.next();
11480 return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
11481 }
11482 finishTopicReference(node, startLoc, pipeProposal, tokenType) {
11483 if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
11484 if (pipeProposal === "hack") {
11485 if (!this.topicReferenceIsAllowedInCurrentContext()) {
11486 this.raise(Errors.PipeTopicUnbound, startLoc);
11487 }
11488 this.registerTopicReference();
11489 return this.finishNode(node, "TopicReference");
11490 } else {
11491 if (!this.topicReferenceIsAllowedInCurrentContext()) {
11492 this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
11493 }
11494 this.registerTopicReference();
11495 return this.finishNode(node, "PipelinePrimaryTopicReference");
11496 }
11497 } else {
11498 throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
11499 token: tokenLabelName(tokenType)
11500 });
11501 }
11502 }
11503 testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
11504 switch (pipeProposal) {
11505 case "hack":
11506 {
11507 return this.hasPlugin(["pipelineOperator", {
11508 topicToken: tokenLabelName(tokenType)
11509 }]);
11510 }
11511 case "smart":
11512 return tokenType === 27;
11513 default:
11514 throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
11515 }
11516 }
11517 parseAsyncArrowUnaryFunction(node) {
11518 this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
11519 const params = [this.parseIdentifier()];
11520 this.prodParam.exit();
11521 if (this.hasPrecedingLineBreak()) {
11522 this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
11523 }
11524 this.expect(19);
11525 return this.parseArrowExpression(node, params, true);
11526 }
11527 parseDo(node, isAsync) {
11528 this.expectPlugin("doExpressions");
11529 if (isAsync) {
11530 this.expectPlugin("asyncDoExpressions");
11531 }
11532 node.async = isAsync;
11533 this.next();
11534 const oldLabels = this.state.labels;
11535 this.state.labels = [];
11536 if (isAsync) {
11537 this.prodParam.enter(2);
11538 node.body = this.parseBlock();
11539 this.prodParam.exit();
11540 } else {
11541 node.body = this.parseBlock();
11542 }
11543 this.state.labels = oldLabels;
11544 return this.finishNode(node, "DoExpression");
11545 }
11546 parseSuper() {
11547 const node = this.startNode();
11548 this.next();
11549 if (this.match(10) && !this.scope.allowDirectSuper) {
11550 if (!(this.optionFlags & 16)) {
11551 this.raise(Errors.SuperNotAllowed, node);
11552 }
11553 } else if (!this.scope.allowSuper) {
11554 if (!(this.optionFlags & 16)) {
11555 this.raise(Errors.UnexpectedSuper, node);
11556 }
11557 }
11558 if (!this.match(10) && !this.match(0) && !this.match(16)) {
11559 this.raise(Errors.UnsupportedSuper, node);
11560 }
11561 return this.finishNode(node, "Super");
11562 }
11563 parsePrivateName() {
11564 const node = this.startNode();
11565 const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
11566 const name = this.state.value;
11567 this.next();
11568 node.id = this.createIdentifier(id, name);
11569 return this.finishNode(node, "PrivateName");
11570 }
11571 parseFunctionOrFunctionSent() {
11572 const node = this.startNode();
11573 this.next();
11574 if (this.prodParam.hasYield && this.match(16)) {
11575 const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
11576 this.next();
11577 if (this.match(103)) {
11578 this.expectPlugin("functionSent");
11579 } else if (!this.hasPlugin("functionSent")) {
11580 this.unexpected();
11581 }
11582 return this.parseMetaProperty(node, meta, "sent");
11583 }
11584 return this.parseFunction(node);
11585 }
11586 parseMetaProperty(node, meta, propertyName) {
11587 node.meta = meta;
11588 const containsEsc = this.state.containsEsc;
11589 node.property = this.parseIdentifier(true);
11590 if (node.property.name !== propertyName || containsEsc) {
11591 this.raise(Errors.UnsupportedMetaProperty, node.property, {
11592 target: meta.name,
11593 onlyValidPropertyName: propertyName
11594 });
11595 }
11596 return this.finishNode(node, "MetaProperty");
11597 }
11598 parseImportMetaPropertyOrPhaseCall(node) {
11599 this.next();
11600 if (this.isContextual(105) || this.isContextual(97)) {
11601 const isSource = this.isContextual(105);
11602 this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
11603 this.next();
11604 node.phase = isSource ? "source" : "defer";
11605 return this.parseImportCall(node);
11606 } else {
11607 const id = this.createIdentifierAt(this.startNodeAtNode(node), "import", this.state.lastTokStartLoc);
11608 if (this.isContextual(101)) {
11609 if (!this.inModule) {
11610 this.raise(Errors.ImportMetaOutsideModule, id);
11611 }
11612 this.sawUnambiguousESM = true;
11613 }
11614 return this.parseMetaProperty(node, id, "meta");
11615 }
11616 }
11617 parseLiteralAtNode(value, type, node) {
11618 this.addExtra(node, "rawValue", value);
11619 this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
11620 node.value = value;
11621 this.next();
11622 return this.finishNode(node, type);
11623 }
11624 parseLiteral(value, type) {
11625 const node = this.startNode();
11626 return this.parseLiteralAtNode(value, type, node);
11627 }
11628 parseStringLiteral(value) {
11629 return this.parseLiteral(value, "StringLiteral");
11630 }
11631 parseNumericLiteral(value) {
11632 return this.parseLiteral(value, "NumericLiteral");
11633 }
11634 parseBigIntLiteral(value) {
11635 return this.parseLiteral(value, "BigIntLiteral");
11636 }
11637 parseDecimalLiteral(value) {
11638 return this.parseLiteral(value, "DecimalLiteral");
11639 }
11640 parseRegExpLiteral(value) {
11641 const node = this.startNode();
11642 this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
11643 node.pattern = value.pattern;
11644 node.flags = value.flags;
11645 this.next();
11646 return this.finishNode(node, "RegExpLiteral");
11647 }
11648 parseBooleanLiteral(value) {
11649 const node = this.startNode();
11650 node.value = value;
11651 this.next();
11652 return this.finishNode(node, "BooleanLiteral");
11653 }
11654 parseNullLiteral() {
11655 const node = this.startNode();
11656 this.next();
11657 return this.finishNode(node, "NullLiteral");
11658 }
11659 parseParenAndDistinguishExpression(canBeArrow) {
11660 const startLoc = this.state.startLoc;
11661 let val;
11662 this.next();
11663 this.expressionScope.enter(newArrowHeadScope());
11664 const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
11665 const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
11666 this.state.maybeInArrowParameters = true;
11667 this.state.inFSharpPipelineDirectBody = false;
11668 const innerStartLoc = this.state.startLoc;
11669 const exprList = [];
11670 const refExpressionErrors = new ExpressionErrors();
11671 let first = true;
11672 let spreadStartLoc;
11673 let optionalCommaStartLoc;
11674 while (!this.match(11)) {
11675 if (first) {
11676 first = false;
11677 } else {
11678 this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
11679 if (this.match(11)) {
11680 optionalCommaStartLoc = this.state.startLoc;
11681 break;
11682 }
11683 }
11684 if (this.match(21)) {
11685 const spreadNodeStartLoc = this.state.startLoc;
11686 spreadStartLoc = this.state.startLoc;
11687 exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
11688 if (!this.checkCommaAfterRest(41)) {
11689 break;
11690 }
11691 } else {
11692 exprList.push(this.parseMaybeAssignAllowInOrVoidPattern(11, refExpressionErrors, this.parseParenItem));
11693 }
11694 }
11695 const innerEndLoc = this.state.lastTokEndLoc;
11696 this.expect(11);
11697 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
11698 this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
11699 let arrowNode = this.startNodeAt(startLoc);
11700 if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
11701 this.checkDestructuringPrivate(refExpressionErrors);
11702 this.expressionScope.validateAsPattern();
11703 this.expressionScope.exit();
11704 this.parseArrowExpression(arrowNode, exprList, false);
11705 return arrowNode;
11706 }
11707 this.expressionScope.exit();
11708 if (!exprList.length) {
11709 this.unexpected(this.state.lastTokStartLoc);
11710 }
11711 if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
11712 if (spreadStartLoc) this.unexpected(spreadStartLoc);
11713 this.checkExpressionErrors(refExpressionErrors, true);
11714 this.toReferencedListDeep(exprList, true);
11715 if (exprList.length > 1) {
11716 val = this.startNodeAt(innerStartLoc);
11717 val.expressions = exprList;
11718 this.finishNode(val, "SequenceExpression");
11719 this.resetEndLocation(val, innerEndLoc);
11720 } else {
11721 val = exprList[0];
11722 }
11723 return this.wrapParenthesis(startLoc, val);
11724 }
11725 wrapParenthesis(startLoc, expression) {
11726 if (!(this.optionFlags & 1024)) {
11727 this.addExtra(expression, "parenthesized", true);
11728 this.addExtra(expression, "parenStart", startLoc.index);
11729 this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
11730 return expression;
11731 }
11732 const parenExpression = this.startNodeAt(startLoc);
11733 parenExpression.expression = expression;
11734 return this.finishNode(parenExpression, "ParenthesizedExpression");
11735 }
11736 shouldParseArrow(params) {
11737 return !this.canInsertSemicolon();
11738 }
11739 parseArrow(node) {
11740 if (this.eat(19)) {
11741 return node;
11742 }
11743 }
11744 parseParenItem(node, startLoc) {
11745 return node;
11746 }
11747 parseNewOrNewTarget() {
11748 const node = this.startNode();
11749 this.next();
11750 if (this.match(16)) {
11751 const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
11752 this.next();
11753 const metaProp = this.parseMetaProperty(node, meta, "target");
11754 if (!this.scope.allowNewTarget) {
11755 this.raise(Errors.UnexpectedNewTarget, metaProp);
11756 }
11757 return metaProp;
11758 }
11759 return this.parseNew(node);
11760 }
11761 parseNew(node) {
11762 this.parseNewCallee(node);
11763 if (this.eat(10)) {
11764 const args = this.parseExprList(11);
11765 this.toReferencedList(args);
11766 node.arguments = args;
11767 } else {
11768 node.arguments = [];
11769 }
11770 return this.finishNode(node, "NewExpression");
11771 }
11772 parseNewCallee(node) {
11773 const isImport = this.match(83);
11774 const callee = this.parseNoCallExpr();
11775 node.callee = callee;
11776 if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
11777 this.raise(Errors.ImportCallNotNewExpression, callee);
11778 }
11779 }
11780 parseTemplateElement(isTagged) {
11781 const {
11782 start,
11783 startLoc,
11784 end,
11785 value
11786 } = this.state;
11787 const elemStart = start + 1;
11788 const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
11789 if (value === null) {
11790 if (!isTagged) {
11791 this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
11792 }
11793 }
11794 const isTail = this.match(24);
11795 const endOffset = isTail ? -1 : -2;
11796 const elemEnd = end + endOffset;
11797 elem.value = {
11798 raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
11799 cooked: value === null ? null : value.slice(1, endOffset)
11800 };
11801 elem.tail = isTail;
11802 this.next();
11803 const finishedNode = this.finishNode(elem, "TemplateElement");
11804 this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
11805 return finishedNode;
11806 }
11807 parseTemplate(isTagged) {
11808 const node = this.startNode();
11809 let curElt = this.parseTemplateElement(isTagged);
11810 const quasis = [curElt];
11811 const substitutions = [];
11812 while (!curElt.tail) {
11813 substitutions.push(this.parseTemplateSubstitution());
11814 this.readTemplateContinuation();
11815 quasis.push(curElt = this.parseTemplateElement(isTagged));
11816 }
11817 node.expressions = substitutions;
11818 node.quasis = quasis;
11819 return this.finishNode(node, "TemplateLiteral");
11820 }
11821 parseTemplateSubstitution() {
11822 return this.parseExpression();
11823 }
11824 parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
11825 if (isRecord) {
11826 this.expectPlugin("recordAndTuple");
11827 }
11828 const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
11829 this.state.inFSharpPipelineDirectBody = false;
11830 let sawProto = false;
11831 let first = true;
11832 const node = this.startNode();
11833 node.properties = [];
11834 this.next();
11835 while (!this.match(close)) {
11836 if (first) {
11837 first = false;
11838 } else {
11839 this.expect(12);
11840 if (this.match(close)) {
11841 this.addTrailingCommaExtraToNode(node);
11842 break;
11843 }
11844 }
11845 let prop;
11846 if (isPattern) {
11847 prop = this.parseBindingProperty();
11848 } else {
11849 prop = this.parsePropertyDefinition(refExpressionErrors);
11850 sawProto = this.checkProto(prop, isRecord, sawProto, refExpressionErrors);
11851 }
11852 if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
11853 this.raise(Errors.InvalidRecordProperty, prop);
11854 }
11855 if (prop.shorthand) {
11856 this.addExtra(prop, "shorthand", true);
11857 }
11858 node.properties.push(prop);
11859 }
11860 this.next();
11861 this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
11862 let type = "ObjectExpression";
11863 if (isPattern) {
11864 type = "ObjectPattern";
11865 } else if (isRecord) {
11866 type = "RecordExpression";
11867 }
11868 return this.finishNode(node, type);
11869 }
11870 addTrailingCommaExtraToNode(node) {
11871 this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
11872 this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
11873 }
11874 maybeAsyncOrAccessorProp(prop) {
11875 return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
11876 }
11877 parsePropertyDefinition(refExpressionErrors) {
11878 let decorators = [];
11879 if (this.match(26)) {
11880 if (this.hasPlugin("decorators")) {
11881 this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
11882 }
11883 while (this.match(26)) {
11884 decorators.push(this.parseDecorator());
11885 }
11886 }
11887 const prop = this.startNode();
11888 let isAsync = false;
11889 let isAccessor = false;
11890 let startLoc;
11891 if (this.match(21)) {
11892 if (decorators.length) this.unexpected();
11893 return this.parseSpread();
11894 }
11895 if (decorators.length) {
11896 prop.decorators = decorators;
11897 decorators = [];
11898 }
11899 prop.method = false;
11900 if (refExpressionErrors) {
11901 startLoc = this.state.startLoc;
11902 }
11903 let isGenerator = this.eat(55);
11904 this.parsePropertyNamePrefixOperator(prop);
11905 const containsEsc = this.state.containsEsc;
11906 this.parsePropertyName(prop, refExpressionErrors);
11907 if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
11908 const {
11909 key
11910 } = prop;
11911 const keyName = key.name;
11912 if (keyName === "async" && !this.hasPrecedingLineBreak()) {
11913 isAsync = true;
11914 this.resetPreviousNodeTrailingComments(key);
11915 isGenerator = this.eat(55);
11916 this.parsePropertyName(prop);
11917 }
11918 if (keyName === "get" || keyName === "set") {
11919 isAccessor = true;
11920 this.resetPreviousNodeTrailingComments(key);
11921 prop.kind = keyName;
11922 if (this.match(55)) {
11923 isGenerator = true;
11924 this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
11925 kind: keyName
11926 });
11927 this.next();
11928 }
11929 this.parsePropertyName(prop);
11930 }
11931 }
11932 return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
11933 }
11934 getGetterSetterExpectedParamCount(method) {
11935 return method.kind === "get" ? 0 : 1;
11936 }
11937 getObjectOrClassMethodParams(method) {
11938 return method.params;
11939 }
11940 checkGetterSetterParams(method) {
11941 var _params;
11942 const paramCount = this.getGetterSetterExpectedParamCount(method);
11943 const params = this.getObjectOrClassMethodParams(method);
11944 if (params.length !== paramCount) {
11945 this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
11946 }
11947 if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
11948 this.raise(Errors.BadSetterRestParameter, method);
11949 }
11950 }
11951 parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
11952 if (isAccessor) {
11953 const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
11954 this.checkGetterSetterParams(finishedProp);
11955 return finishedProp;
11956 }
11957 if (isAsync || isGenerator || this.match(10)) {
11958 if (isPattern) this.unexpected();
11959 prop.kind = "method";
11960 prop.method = true;
11961 return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
11962 }
11963 }
11964 parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
11965 prop.shorthand = false;
11966 if (this.eat(14)) {
11967 prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowInOrVoidPattern(8, refExpressionErrors);
11968 return this.finishObjectProperty(prop);
11969 }
11970 if (!prop.computed && prop.key.type === "Identifier") {
11971 this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
11972 if (isPattern) {
11973 prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
11974 } else if (this.match(29)) {
11975 const shorthandAssignLoc = this.state.startLoc;
11976 if (refExpressionErrors != null) {
11977 if (refExpressionErrors.shorthandAssignLoc === null) {
11978 refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
11979 }
11980 } else {
11981 this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
11982 }
11983 prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
11984 } else {
11985 prop.value = this.cloneIdentifier(prop.key);
11986 }
11987 prop.shorthand = true;
11988 return this.finishObjectProperty(prop);
11989 }
11990 }
11991 finishObjectProperty(node) {
11992 return this.finishNode(node, "ObjectProperty");
11993 }
11994 parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
11995 const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
11996 if (!node) this.unexpected();
11997 return node;
11998 }
11999 parsePropertyName(prop, refExpressionErrors) {
12000 if (this.eat(0)) {
12001 prop.computed = true;
12002 prop.key = this.parseMaybeAssignAllowIn();
12003 this.expect(3);
12004 } else {
12005 const {
12006 type,
12007 value
12008 } = this.state;
12009 let key;
12010 if (tokenIsKeywordOrIdentifier(type)) {
12011 key = this.parseIdentifier(true);
12012 } else {
12013 switch (type) {
12014 case 135:
12015 key = this.parseNumericLiteral(value);
12016 break;
12017 case 134:
12018 key = this.parseStringLiteral(value);
12019 break;
12020 case 136:
12021 key = this.parseBigIntLiteral(value);
12022 break;
12023 case 139:
12024 {
12025 const privateKeyLoc = this.state.startLoc;
12026 if (refExpressionErrors != null) {
12027 if (refExpressionErrors.privateKeyLoc === null) {
12028 refExpressionErrors.privateKeyLoc = privateKeyLoc;
12029 }
12030 } else {
12031 this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
12032 }
12033 key = this.parsePrivateName();
12034 break;
12035 }
12036 default:
12037 if (type === 137) {
12038 key = this.parseDecimalLiteral(value);
12039 break;
12040 }
12041 this.unexpected();
12042 }
12043 }
12044 prop.key = key;
12045 if (type !== 139) {
12046 prop.computed = false;
12047 }
12048 }
12049 }
12050 initFunction(node, isAsync) {
12051 node.id = null;
12052 node.generator = false;
12053 node.async = isAsync;
12054 }
12055 parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
12056 this.initFunction(node, isAsync);
12057 node.generator = isGenerator;
12058 this.scope.enter(514 | 16 | (inClassScope ? 576 : 0) | (allowDirectSuper ? 32 : 0));
12059 this.prodParam.enter(functionFlags(isAsync, node.generator));
12060 this.parseFunctionParams(node, isConstructor);
12061 const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
12062 this.prodParam.exit();
12063 this.scope.exit();
12064 return finishedNode;
12065 }
12066 parseArrayLike(close, isTuple, refExpressionErrors) {
12067 if (isTuple) {
12068 this.expectPlugin("recordAndTuple");
12069 }
12070 const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
12071 this.state.inFSharpPipelineDirectBody = false;
12072 const node = this.startNode();
12073 this.next();
12074 node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
12075 this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
12076 return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
12077 }
12078 parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
12079 this.scope.enter(514 | 4);
12080 let flags = functionFlags(isAsync, false);
12081 if (!this.match(5) && this.prodParam.hasIn) {
12082 flags |= 8;
12083 }
12084 this.prodParam.enter(flags);
12085 this.initFunction(node, isAsync);
12086 const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
12087 if (params) {
12088 this.state.maybeInArrowParameters = true;
12089 this.setArrowFunctionParameters(node, params, trailingCommaLoc);
12090 }
12091 this.state.maybeInArrowParameters = false;
12092 this.parseFunctionBody(node, true);
12093 this.prodParam.exit();
12094 this.scope.exit();
12095 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
12096 return this.finishNode(node, "ArrowFunctionExpression");
12097 }
12098 setArrowFunctionParameters(node, params, trailingCommaLoc) {
12099 this.toAssignableList(params, trailingCommaLoc, false);
12100 node.params = params;
12101 }
12102 parseFunctionBodyAndFinish(node, type, isMethod = false) {
12103 this.parseFunctionBody(node, false, isMethod);
12104 return this.finishNode(node, type);
12105 }
12106 parseFunctionBody(node, allowExpression, isMethod = false) {
12107 const isExpression = allowExpression && !this.match(5);
12108 this.expressionScope.enter(newExpressionScope());
12109 if (isExpression) {
12110 node.body = this.parseMaybeAssign();
12111 this.checkParams(node, false, allowExpression, false);
12112 } else {
12113 const oldStrict = this.state.strict;
12114 const oldLabels = this.state.labels;
12115 this.state.labels = [];
12116 this.prodParam.enter(this.prodParam.currentFlags() | 4);
12117 node.body = this.parseBlock(true, false, hasStrictModeDirective => {
12118 const nonSimple = !this.isSimpleParamList(node.params);
12119 if (hasStrictModeDirective && nonSimple) {
12120 this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
12121 }
12122 const strictModeChanged = !oldStrict && this.state.strict;
12123 this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
12124 if (this.state.strict && node.id) {
12125 this.checkIdentifier(node.id, 65, strictModeChanged);
12126 }
12127 });
12128 this.prodParam.exit();
12129 this.state.labels = oldLabels;
12130 }
12131 this.expressionScope.exit();
12132 }
12133 isSimpleParameter(node) {
12134 return node.type === "Identifier";
12135 }
12136 isSimpleParamList(params) {
12137 for (let i = 0, len = params.length; i < len; i++) {
12138 if (!this.isSimpleParameter(params[i])) return false;
12139 }
12140 return true;
12141 }
12142 checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
12143 const checkClashes = !allowDuplicates && new Set();
12144 const formalParameters = {
12145 type: "FormalParameters"
12146 };
12147 for (const param of node.params) {
12148 this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
12149 }
12150 }
12151 parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
12152 const elts = [];
12153 let first = true;
12154 while (!this.eat(close)) {
12155 if (first) {
12156 first = false;
12157 } else {
12158 this.expect(12);
12159 if (this.match(close)) {
12160 if (nodeForExtra) {
12161 this.addTrailingCommaExtraToNode(nodeForExtra);
12162 }
12163 this.next();
12164 break;
12165 }
12166 }
12167 elts.push(this.parseExprListItem(close, allowEmpty, refExpressionErrors));
12168 }
12169 return elts;
12170 }
12171 parseExprListItem(close, allowEmpty, refExpressionErrors, allowPlaceholder) {
12172 let elt;
12173 if (this.match(12)) {
12174 if (!allowEmpty) {
12175 this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
12176 unexpected: ","
12177 });
12178 }
12179 elt = null;
12180 } else if (this.match(21)) {
12181 const spreadNodeStartLoc = this.state.startLoc;
12182 elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
12183 } else if (this.match(17)) {
12184 this.expectPlugin("partialApplication");
12185 if (!allowPlaceholder) {
12186 this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
12187 }
12188 const node = this.startNode();
12189 this.next();
12190 elt = this.finishNode(node, "ArgumentPlaceholder");
12191 } else {
12192 elt = this.parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, this.parseParenItem);
12193 }
12194 return elt;
12195 }
12196 parseIdentifier(liberal) {
12197 const node = this.startNode();
12198 const name = this.parseIdentifierName(liberal);
12199 return this.createIdentifier(node, name);
12200 }
12201 createIdentifier(node, name) {
12202 node.name = name;
12203 node.loc.identifierName = name;
12204 return this.finishNode(node, "Identifier");
12205 }
12206 createIdentifierAt(node, name, endLoc) {
12207 node.name = name;
12208 node.loc.identifierName = name;
12209 return this.finishNodeAt(node, "Identifier", endLoc);
12210 }
12211 parseIdentifierName(liberal) {
12212 let name;
12213 const {
12214 startLoc,
12215 type
12216 } = this.state;
12217 if (tokenIsKeywordOrIdentifier(type)) {
12218 name = this.state.value;
12219 } else {
12220 this.unexpected();
12221 }
12222 const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
12223 if (liberal) {
12224 if (tokenIsKeyword) {
12225 this.replaceToken(132);
12226 }
12227 } else {
12228 this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
12229 }
12230 this.next();
12231 return name;
12232 }
12233 checkReservedWord(word, startLoc, checkKeywords, isBinding) {
12234 if (word.length > 10) {
12235 return;
12236 }
12237 if (!canBeReservedWord(word)) {
12238 return;
12239 }
12240 if (checkKeywords && isKeyword(word)) {
12241 this.raise(Errors.UnexpectedKeyword, startLoc, {
12242 keyword: word
12243 });
12244 return;
12245 }
12246 const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
12247 if (reservedTest(word, this.inModule)) {
12248 this.raise(Errors.UnexpectedReservedWord, startLoc, {
12249 reservedWord: word
12250 });
12251 return;
12252 } else if (word === "yield") {
12253 if (this.prodParam.hasYield) {
12254 this.raise(Errors.YieldBindingIdentifier, startLoc);
12255 return;
12256 }
12257 } else if (word === "await") {
12258 if (this.prodParam.hasAwait) {
12259 this.raise(Errors.AwaitBindingIdentifier, startLoc);
12260 return;
12261 }
12262 if (this.scope.inStaticBlock) {
12263 this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
12264 return;
12265 }
12266 this.expressionScope.recordAsyncArrowParametersError(startLoc);
12267 } else if (word === "arguments") {
12268 if (this.scope.inClassAndNotInNonArrowFunction) {
12269 this.raise(Errors.ArgumentsInClass, startLoc);
12270 return;
12271 }
12272 }
12273 }
12274 recordAwaitIfAllowed() {
12275 const isAwaitAllowed = this.prodParam.hasAwait;
12276 if (isAwaitAllowed && !this.scope.inFunction) {
12277 this.state.hasTopLevelAwait = true;
12278 }
12279 return isAwaitAllowed;
12280 }
12281 parseAwait(startLoc) {
12282 const node = this.startNodeAt(startLoc);
12283 this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
12284 if (this.eat(55)) {
12285 this.raise(Errors.ObsoleteAwaitStar, node);
12286 }
12287 if (!this.scope.inFunction && !(this.optionFlags & 1)) {
12288 if (this.isAmbiguousPrefixOrIdentifier()) {
12289 this.ambiguousScriptDifferentAst = true;
12290 } else {
12291 this.sawUnambiguousESM = true;
12292 }
12293 }
12294 if (!this.state.soloAwait) {
12295 node.argument = this.parseMaybeUnary(null, true);
12296 }
12297 return this.finishNode(node, "AwaitExpression");
12298 }
12299 isAmbiguousPrefixOrIdentifier() {
12300 if (this.hasPrecedingLineBreak()) return true;
12301 const {
12302 type
12303 } = this.state;
12304 return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
12305 }
12306 parseYield(startLoc) {
12307 const node = this.startNodeAt(startLoc);
12308 this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
12309 let delegating = false;
12310 let argument = null;
12311 if (!this.hasPrecedingLineBreak()) {
12312 delegating = this.eat(55);
12313 switch (this.state.type) {
12314 case 13:
12315 case 140:
12316 case 8:
12317 case 11:
12318 case 3:
12319 case 9:
12320 case 14:
12321 case 12:
12322 if (!delegating) break;
12323 default:
12324 argument = this.parseMaybeAssign();
12325 }
12326 }
12327 node.delegate = delegating;
12328 node.argument = argument;
12329 return this.finishNode(node, "YieldExpression");
12330 }
12331 parseImportCall(node) {
12332 this.next();
12333 node.source = this.parseMaybeAssignAllowIn();
12334 node.options = null;
12335 if (this.eat(12)) {
12336 if (!this.match(11)) {
12337 node.options = this.parseMaybeAssignAllowIn();
12338 if (this.eat(12)) {
12339 this.addTrailingCommaExtraToNode(node.options);
12340 if (!this.match(11)) {
12341 do {
12342 this.parseMaybeAssignAllowIn();
12343 } while (this.eat(12) && !this.match(11));
12344 this.raise(Errors.ImportCallArity, node);
12345 }
12346 }
12347 } else {
12348 this.addTrailingCommaExtraToNode(node.source);
12349 }
12350 }
12351 this.expect(11);
12352 return this.finishNode(node, "ImportExpression");
12353 }
12354 checkPipelineAtInfixOperator(left, leftStartLoc) {
12355 if (this.hasPlugin(["pipelineOperator", {
12356 proposal: "smart"
12357 }])) {
12358 if (left.type === "SequenceExpression") {
12359 this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
12360 }
12361 }
12362 }
12363 parseSmartPipelineBodyInStyle(childExpr, startLoc) {
12364 if (this.isSimpleReference(childExpr)) {
12365 const bodyNode = this.startNodeAt(startLoc);
12366 bodyNode.callee = childExpr;
12367 return this.finishNode(bodyNode, "PipelineBareFunction");
12368 } else {
12369 const bodyNode = this.startNodeAt(startLoc);
12370 this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
12371 bodyNode.expression = childExpr;
12372 return this.finishNode(bodyNode, "PipelineTopicExpression");
12373 }
12374 }
12375 isSimpleReference(expression) {
12376 switch (expression.type) {
12377 case "MemberExpression":
12378 return !expression.computed && this.isSimpleReference(expression.object);
12379 case "Identifier":
12380 return true;
12381 default:
12382 return false;
12383 }
12384 }
12385 checkSmartPipeTopicBodyEarlyErrors(startLoc) {
12386 if (this.match(19)) {
12387 throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
12388 }
12389 if (!this.topicReferenceWasUsedInCurrentContext()) {
12390 this.raise(Errors.PipelineTopicUnused, startLoc);
12391 }
12392 }
12393 withTopicBindingContext(callback) {
12394 const outerContextTopicState = this.state.topicContext;
12395 this.state.topicContext = {
12396 maxNumOfResolvableTopics: 1,
12397 maxTopicIndex: null
12398 };
12399 try {
12400 return callback();
12401 } finally {
12402 this.state.topicContext = outerContextTopicState;
12403 }
12404 }
12405 withSmartMixTopicForbiddingContext(callback) {
12406 if (this.hasPlugin(["pipelineOperator", {
12407 proposal: "smart"
12408 }])) {
12409 const outerContextTopicState = this.state.topicContext;
12410 this.state.topicContext = {
12411 maxNumOfResolvableTopics: 0,
12412 maxTopicIndex: null
12413 };
12414 try {
12415 return callback();
12416 } finally {
12417 this.state.topicContext = outerContextTopicState;
12418 }
12419 } else {
12420 return callback();
12421 }
12422 }
12423 withSoloAwaitPermittingContext(callback) {
12424 const outerContextSoloAwaitState = this.state.soloAwait;
12425 this.state.soloAwait = true;
12426 try {
12427 return callback();
12428 } finally {
12429 this.state.soloAwait = outerContextSoloAwaitState;
12430 }
12431 }
12432 allowInAnd(callback) {
12433 const flags = this.prodParam.currentFlags();
12434 const prodParamToSet = 8 & ~flags;
12435 if (prodParamToSet) {
12436 this.prodParam.enter(flags | 8);
12437 try {
12438 return callback();
12439 } finally {
12440 this.prodParam.exit();
12441 }
12442 }
12443 return callback();
12444 }
12445 disallowInAnd(callback) {
12446 const flags = this.prodParam.currentFlags();
12447 const prodParamToClear = 8 & flags;
12448 if (prodParamToClear) {
12449 this.prodParam.enter(flags & ~8);
12450 try {
12451 return callback();
12452 } finally {
12453 this.prodParam.exit();
12454 }
12455 }
12456 return callback();
12457 }
12458 registerTopicReference() {
12459 this.state.topicContext.maxTopicIndex = 0;
12460 }
12461 topicReferenceIsAllowedInCurrentContext() {
12462 return this.state.topicContext.maxNumOfResolvableTopics >= 1;
12463 }
12464 topicReferenceWasUsedInCurrentContext() {
12465 return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
12466 }
12467 parseFSharpPipelineBody(prec) {
12468 const startLoc = this.state.startLoc;
12469 this.state.potentialArrowAt = this.state.start;
12470 const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
12471 this.state.inFSharpPipelineDirectBody = true;
12472 const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
12473 this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
12474 return ret;
12475 }
12476 parseModuleExpression() {
12477 this.expectPlugin("moduleBlocks");
12478 const node = this.startNode();
12479 this.next();
12480 if (!this.match(5)) {
12481 this.unexpected(null, 5);
12482 }
12483 const program = this.startNodeAt(this.state.endLoc);
12484 this.next();
12485 const revertScopes = this.initializeScopes(true);
12486 this.enterInitialScopes();
12487 try {
12488 node.body = this.parseProgram(program, 8, "module");
12489 } finally {
12490 revertScopes();
12491 }
12492 return this.finishNode(node, "ModuleExpression");
12493 }
12494 parseVoidPattern(refExpressionErrors) {
12495 this.expectPlugin("discardBinding");
12496 const node = this.startNode();
12497 if (refExpressionErrors != null) {
12498 refExpressionErrors.voidPatternLoc = this.state.startLoc;
12499 }
12500 this.next();
12501 return this.finishNode(node, "VoidPattern");
12502 }
12503 parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, afterLeftParse) {
12504 if (refExpressionErrors != null && this.match(88)) {
12505 const nextCode = this.lookaheadCharCode();
12506 if (nextCode === 44 || nextCode === (close === 3 ? 93 : close === 8 ? 125 : 41) || nextCode === 61) {
12507 return this.parseMaybeDefault(this.state.startLoc, this.parseVoidPattern(refExpressionErrors));
12508 }
12509 }
12510 return this.parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse);
12511 }
12512 parsePropertyNamePrefixOperator(prop) {}
12513}
12514const loopLabel = {
12515 kind: 1
12516 },
12517 switchLabel = {
12518 kind: 2
12519 };
12520const loneSurrogate = /[\uD800-\uDFFF]/u;
12521const keywordRelationalOperator = /in(?:stanceof)?/y;
12522function babel7CompatTokens(tokens, input, startIndex) {
12523 for (let i = 0; i < tokens.length; i++) {
12524 const token = tokens[i];
12525 const {
12526 type
12527 } = token;
12528 if (typeof type === "number") {
12529 if (type === 139) {
12530 const {
12531 loc,
12532 start,
12533 value,
12534 end
12535 } = token;
12536 const hashEndPos = start + 1;
12537 const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
12538 tokens.splice(i, 1, new Token({
12539 type: getExportedToken(27),
12540 value: "#",
12541 start: start,
12542 end: hashEndPos,
12543 startLoc: loc.start,
12544 endLoc: hashEndLoc
12545 }), new Token({
12546 type: getExportedToken(132),
12547 value: value,
12548 start: hashEndPos,
12549 end: end,
12550 startLoc: hashEndLoc,
12551 endLoc: loc.end
12552 }));
12553 i++;
12554 continue;
12555 }
12556 if (tokenIsTemplate(type)) {
12557 const {
12558 loc,
12559 start,
12560 value,
12561 end
12562 } = token;
12563 const backquoteEnd = start + 1;
12564 const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
12565 let startToken;
12566 if (input.charCodeAt(start - startIndex) === 96) {
12567 startToken = new Token({
12568 type: getExportedToken(22),
12569 value: "`",
12570 start: start,
12571 end: backquoteEnd,
12572 startLoc: loc.start,
12573 endLoc: backquoteEndLoc
12574 });
12575 } else {
12576 startToken = new Token({
12577 type: getExportedToken(8),
12578 value: "}",
12579 start: start,
12580 end: backquoteEnd,
12581 startLoc: loc.start,
12582 endLoc: backquoteEndLoc
12583 });
12584 }
12585 let templateValue, templateElementEnd, templateElementEndLoc, endToken;
12586 if (type === 24) {
12587 templateElementEnd = end - 1;
12588 templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
12589 templateValue = value === null ? null : value.slice(1, -1);
12590 endToken = new Token({
12591 type: getExportedToken(22),
12592 value: "`",
12593 start: templateElementEnd,
12594 end: end,
12595 startLoc: templateElementEndLoc,
12596 endLoc: loc.end
12597 });
12598 } else {
12599 templateElementEnd = end - 2;
12600 templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
12601 templateValue = value === null ? null : value.slice(1, -2);
12602 endToken = new Token({
12603 type: getExportedToken(23),
12604 value: "${",
12605 start: templateElementEnd,
12606 end: end,
12607 startLoc: templateElementEndLoc,
12608 endLoc: loc.end
12609 });
12610 }
12611 tokens.splice(i, 1, startToken, new Token({
12612 type: getExportedToken(20),
12613 value: templateValue,
12614 start: backquoteEnd,
12615 end: templateElementEnd,
12616 startLoc: backquoteEndLoc,
12617 endLoc: templateElementEndLoc
12618 }), endToken);
12619 i += 2;
12620 continue;
12621 }
12622 token.type = getExportedToken(type);
12623 }
12624 }
12625 return tokens;
12626}
12627class StatementParser extends ExpressionParser {
12628 parseTopLevel(file, program) {
12629 file.program = this.parseProgram(program, 140, this.options.sourceType === "module" ? "module" : "script");
12630 file.comments = this.comments;
12631 if (this.optionFlags & 256) {
12632 file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
12633 }
12634 return this.finishNode(file, "File");
12635 }
12636 parseProgram(program, end, sourceType) {
12637 program.sourceType = sourceType;
12638 program.interpreter = this.parseInterpreterDirective();
12639 this.parseBlockBody(program, true, true, end);
12640 if (this.inModule) {
12641 if (!(this.optionFlags & 64) && this.scope.undefinedExports.size > 0) {
12642 for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
12643 this.raise(Errors.ModuleExportUndefined, at, {
12644 localName
12645 });
12646 }
12647 }
12648 this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
12649 }
12650 let finishedProgram;
12651 if (end === 140) {
12652 finishedProgram = this.finishNode(program, "Program");
12653 } else {
12654 finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
12655 }
12656 return finishedProgram;
12657 }
12658 stmtToDirective(stmt) {
12659 const directive = this.castNodeTo(stmt, "Directive");
12660 const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
12661 const expressionValue = directiveLiteral.value;
12662 const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
12663 const val = directiveLiteral.value = raw.slice(1, -1);
12664 this.addExtra(directiveLiteral, "raw", raw);
12665 this.addExtra(directiveLiteral, "rawValue", val);
12666 this.addExtra(directiveLiteral, "expressionValue", expressionValue);
12667 directive.value = directiveLiteral;
12668 delete stmt.expression;
12669 return directive;
12670 }
12671 parseInterpreterDirective() {
12672 if (!this.match(28)) {
12673 return null;
12674 }
12675 const node = this.startNode();
12676 node.value = this.state.value;
12677 this.next();
12678 return this.finishNode(node, "InterpreterDirective");
12679 }
12680 isLet() {
12681 if (!this.isContextual(100)) {
12682 return false;
12683 }
12684 return this.hasFollowingBindingAtom();
12685 }
12686 isUsing() {
12687 if (!this.isContextual(107)) {
12688 return false;
12689 }
12690 return this.nextTokenIsIdentifierOnSameLine();
12691 }
12692 isForUsing() {
12693 if (!this.isContextual(107)) {
12694 return false;
12695 }
12696 const next = this.nextTokenInLineStart();
12697 const nextCh = this.codePointAtPos(next);
12698 if (this.isUnparsedContextual(next, "of")) {
12699 const nextCharAfterOf = this.lookaheadCharCodeSince(next + 2);
12700 if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
12701 return false;
12702 }
12703 }
12704 if (this.chStartsBindingIdentifier(nextCh, next) || this.isUnparsedContextual(next, "void")) {
12705 return true;
12706 }
12707 return false;
12708 }
12709 nextTokenIsIdentifierOnSameLine() {
12710 const next = this.nextTokenInLineStart();
12711 const nextCh = this.codePointAtPos(next);
12712 return this.chStartsBindingIdentifier(nextCh, next);
12713 }
12714 isAwaitUsing() {
12715 if (!this.isContextual(96)) {
12716 return false;
12717 }
12718 let next = this.nextTokenInLineStart();
12719 if (this.isUnparsedContextual(next, "using")) {
12720 next = this.nextTokenInLineStartSince(next + 5);
12721 const nextCh = this.codePointAtPos(next);
12722 if (this.chStartsBindingIdentifier(nextCh, next)) {
12723 return true;
12724 }
12725 }
12726 return false;
12727 }
12728 chStartsBindingIdentifier(ch, pos) {
12729 if (isIdentifierStart(ch)) {
12730 keywordRelationalOperator.lastIndex = pos;
12731 if (keywordRelationalOperator.test(this.input)) {
12732 const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
12733 if (!isIdentifierChar(endCh) && endCh !== 92) {
12734 return false;
12735 }
12736 }
12737 return true;
12738 } else if (ch === 92) {
12739 return true;
12740 } else {
12741 return false;
12742 }
12743 }
12744 chStartsBindingPattern(ch) {
12745 return ch === 91 || ch === 123;
12746 }
12747 hasFollowingBindingAtom() {
12748 const next = this.nextTokenStart();
12749 const nextCh = this.codePointAtPos(next);
12750 return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
12751 }
12752 hasInLineFollowingBindingIdentifierOrBrace() {
12753 const next = this.nextTokenInLineStart();
12754 const nextCh = this.codePointAtPos(next);
12755 return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
12756 }
12757 allowsUsing() {
12758 return (this.scope.inModule || !this.scope.inTopLevel) && !this.scope.inBareCaseStatement;
12759 }
12760 parseModuleItem() {
12761 return this.parseStatementLike(1 | 2 | 4 | 8);
12762 }
12763 parseStatementListItem() {
12764 return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
12765 }
12766 parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
12767 let flags = 0;
12768 if (this.options.annexB && !this.state.strict) {
12769 flags |= 4;
12770 if (allowLabeledFunction) {
12771 flags |= 8;
12772 }
12773 }
12774 return this.parseStatementLike(flags);
12775 }
12776 parseStatement() {
12777 return this.parseStatementLike(0);
12778 }
12779 parseStatementLike(flags) {
12780 let decorators = null;
12781 if (this.match(26)) {
12782 decorators = this.parseDecorators(true);
12783 }
12784 return this.parseStatementContent(flags, decorators);
12785 }
12786 parseStatementContent(flags, decorators) {
12787 const startType = this.state.type;
12788 const node = this.startNode();
12789 const allowDeclaration = !!(flags & 2);
12790 const allowFunctionDeclaration = !!(flags & 4);
12791 const topLevel = flags & 1;
12792 switch (startType) {
12793 case 60:
12794 return this.parseBreakContinueStatement(node, true);
12795 case 63:
12796 return this.parseBreakContinueStatement(node, false);
12797 case 64:
12798 return this.parseDebuggerStatement(node);
12799 case 90:
12800 return this.parseDoWhileStatement(node);
12801 case 91:
12802 return this.parseForStatement(node);
12803 case 68:
12804 if (this.lookaheadCharCode() === 46) break;
12805 if (!allowFunctionDeclaration) {
12806 this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
12807 }
12808 return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
12809 case 80:
12810 if (!allowDeclaration) this.unexpected();
12811 return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
12812 case 69:
12813 return this.parseIfStatement(node);
12814 case 70:
12815 return this.parseReturnStatement(node);
12816 case 71:
12817 return this.parseSwitchStatement(node);
12818 case 72:
12819 return this.parseThrowStatement(node);
12820 case 73:
12821 return this.parseTryStatement(node);
12822 case 96:
12823 if (this.isAwaitUsing()) {
12824 if (!this.allowsUsing()) {
12825 this.raise(Errors.UnexpectedUsingDeclaration, node);
12826 } else if (!allowDeclaration) {
12827 this.raise(Errors.UnexpectedLexicalDeclaration, node);
12828 } else if (!this.recordAwaitIfAllowed()) {
12829 this.raise(Errors.AwaitUsingNotInAsyncContext, node);
12830 }
12831 this.next();
12832 return this.parseVarStatement(node, "await using");
12833 }
12834 break;
12835 case 107:
12836 if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
12837 break;
12838 }
12839 if (!this.allowsUsing()) {
12840 this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
12841 } else if (!allowDeclaration) {
12842 this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
12843 }
12844 return this.parseVarStatement(node, "using");
12845 case 100:
12846 {
12847 if (this.state.containsEsc) {
12848 break;
12849 }
12850 const next = this.nextTokenStart();
12851 const nextCh = this.codePointAtPos(next);
12852 if (nextCh !== 91) {
12853 if (!allowDeclaration && this.hasFollowingLineBreak()) break;
12854 if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
12855 break;
12856 }
12857 }
12858 }
12859 case 75:
12860 {
12861 if (!allowDeclaration) {
12862 this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
12863 }
12864 }
12865 case 74:
12866 {
12867 const kind = this.state.value;
12868 return this.parseVarStatement(node, kind);
12869 }
12870 case 92:
12871 return this.parseWhileStatement(node);
12872 case 76:
12873 return this.parseWithStatement(node);
12874 case 5:
12875 return this.parseBlock();
12876 case 13:
12877 return this.parseEmptyStatement(node);
12878 case 83:
12879 {
12880 const nextTokenCharCode = this.lookaheadCharCode();
12881 if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
12882 break;
12883 }
12884 }
12885 case 82:
12886 {
12887 if (!(this.optionFlags & 8) && !topLevel) {
12888 this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
12889 }
12890 this.next();
12891 let result;
12892 if (startType === 83) {
12893 result = this.parseImport(node);
12894 } else {
12895 result = this.parseExport(node, decorators);
12896 }
12897 this.assertModuleNodeAllowed(result);
12898 return result;
12899 }
12900 default:
12901 {
12902 if (this.isAsyncFunction()) {
12903 if (!allowDeclaration) {
12904 this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
12905 }
12906 this.next();
12907 return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
12908 }
12909 }
12910 }
12911 const maybeName = this.state.value;
12912 const expr = this.parseExpression();
12913 if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
12914 return this.parseLabeledStatement(node, maybeName, expr, flags);
12915 } else {
12916 return this.parseExpressionStatement(node, expr, decorators);
12917 }
12918 }
12919 assertModuleNodeAllowed(node) {
12920 if (!(this.optionFlags & 8) && !this.inModule) {
12921 this.raise(Errors.ImportOutsideModule, node);
12922 }
12923 }
12924 decoratorsEnabledBeforeExport() {
12925 if (this.hasPlugin("decorators-legacy")) return true;
12926 return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
12927 }
12928 maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
12929 if (maybeDecorators) {
12930 var _classNode$decorators;
12931 if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
12932 if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
12933 this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
12934 }
12935 classNode.decorators.unshift(...maybeDecorators);
12936 } else {
12937 classNode.decorators = maybeDecorators;
12938 }
12939 this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
12940 if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
12941 }
12942 return classNode;
12943 }
12944 canHaveLeadingDecorator() {
12945 return this.match(80);
12946 }
12947 parseDecorators(allowExport) {
12948 const decorators = [];
12949 do {
12950 decorators.push(this.parseDecorator());
12951 } while (this.match(26));
12952 if (this.match(82)) {
12953 if (!allowExport) {
12954 this.unexpected();
12955 }
12956 if (!this.decoratorsEnabledBeforeExport()) {
12957 this.raise(Errors.DecoratorExportClass, this.state.startLoc);
12958 }
12959 } else if (!this.canHaveLeadingDecorator()) {
12960 throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
12961 }
12962 return decorators;
12963 }
12964 parseDecorator() {
12965 this.expectOnePlugin(["decorators", "decorators-legacy"]);
12966 const node = this.startNode();
12967 this.next();
12968 if (this.hasPlugin("decorators")) {
12969 const startLoc = this.state.startLoc;
12970 let expr;
12971 if (this.match(10)) {
12972 const startLoc = this.state.startLoc;
12973 this.next();
12974 expr = this.parseExpression();
12975 this.expect(11);
12976 expr = this.wrapParenthesis(startLoc, expr);
12977 const paramsStartLoc = this.state.startLoc;
12978 node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
12979 if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
12980 this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
12981 }
12982 } else {
12983 expr = this.parseIdentifier(false);
12984 while (this.eat(16)) {
12985 const node = this.startNodeAt(startLoc);
12986 node.object = expr;
12987 if (this.match(139)) {
12988 this.classScope.usePrivateName(this.state.value, this.state.startLoc);
12989 node.property = this.parsePrivateName();
12990 } else {
12991 node.property = this.parseIdentifier(true);
12992 }
12993 node.computed = false;
12994 expr = this.finishNode(node, "MemberExpression");
12995 }
12996 node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
12997 }
12998 } else {
12999 node.expression = this.parseExprSubscripts();
13000 }
13001 return this.finishNode(node, "Decorator");
13002 }
13003 parseMaybeDecoratorArguments(expr, startLoc) {
13004 if (this.eat(10)) {
13005 const node = this.startNodeAt(startLoc);
13006 node.callee = expr;
13007 node.arguments = this.parseCallExpressionArguments();
13008 this.toReferencedList(node.arguments);
13009 return this.finishNode(node, "CallExpression");
13010 }
13011 return expr;
13012 }
13013 parseBreakContinueStatement(node, isBreak) {
13014 this.next();
13015 if (this.isLineTerminator()) {
13016 node.label = null;
13017 } else {
13018 node.label = this.parseIdentifier();
13019 this.semicolon();
13020 }
13021 this.verifyBreakContinue(node, isBreak);
13022 return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
13023 }
13024 verifyBreakContinue(node, isBreak) {
13025 let i;
13026 for (i = 0; i < this.state.labels.length; ++i) {
13027 const lab = this.state.labels[i];
13028 if (node.label == null || lab.name === node.label.name) {
13029 if (lab.kind != null && (isBreak || lab.kind === 1)) {
13030 break;
13031 }
13032 if (node.label && isBreak) break;
13033 }
13034 }
13035 if (i === this.state.labels.length) {
13036 const type = isBreak ? "BreakStatement" : "ContinueStatement";
13037 this.raise(Errors.IllegalBreakContinue, node, {
13038 type
13039 });
13040 }
13041 }
13042 parseDebuggerStatement(node) {
13043 this.next();
13044 this.semicolon();
13045 return this.finishNode(node, "DebuggerStatement");
13046 }
13047 parseHeaderExpression() {
13048 this.expect(10);
13049 const val = this.parseExpression();
13050 this.expect(11);
13051 return val;
13052 }
13053 parseDoWhileStatement(node) {
13054 this.next();
13055 this.state.labels.push(loopLabel);
13056 node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
13057 this.state.labels.pop();
13058 this.expect(92);
13059 node.test = this.parseHeaderExpression();
13060 this.eat(13);
13061 return this.finishNode(node, "DoWhileStatement");
13062 }
13063 parseForStatement(node) {
13064 this.next();
13065 this.state.labels.push(loopLabel);
13066 let awaitAt = null;
13067 if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
13068 awaitAt = this.state.startLoc;
13069 this.next();
13070 }
13071 this.scope.enter(0);
13072 this.expect(10);
13073 if (this.match(13)) {
13074 if (awaitAt !== null) {
13075 this.unexpected(awaitAt);
13076 }
13077 return this.parseFor(node, null);
13078 }
13079 const startsWithLet = this.isContextual(100);
13080 {
13081 const startsWithAwaitUsing = this.isAwaitUsing();
13082 const starsWithUsingDeclaration = startsWithAwaitUsing || this.isForUsing();
13083 const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
13084 if (this.match(74) || this.match(75) || isLetOrUsing) {
13085 const initNode = this.startNode();
13086 let kind;
13087 if (startsWithAwaitUsing) {
13088 kind = "await using";
13089 if (!this.recordAwaitIfAllowed()) {
13090 this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
13091 }
13092 this.next();
13093 } else {
13094 kind = this.state.value;
13095 }
13096 this.next();
13097 this.parseVar(initNode, true, kind);
13098 const init = this.finishNode(initNode, "VariableDeclaration");
13099 const isForIn = this.match(58);
13100 if (isForIn && starsWithUsingDeclaration) {
13101 this.raise(Errors.ForInUsing, init);
13102 }
13103 if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
13104 return this.parseForIn(node, init, awaitAt);
13105 }
13106 if (awaitAt !== null) {
13107 this.unexpected(awaitAt);
13108 }
13109 return this.parseFor(node, init);
13110 }
13111 }
13112 const startsWithAsync = this.isContextual(95);
13113 const refExpressionErrors = new ExpressionErrors();
13114 const init = this.parseExpression(true, refExpressionErrors);
13115 const isForOf = this.isContextual(102);
13116 if (isForOf) {
13117 if (startsWithLet) {
13118 this.raise(Errors.ForOfLet, init);
13119 }
13120 if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
13121 this.raise(Errors.ForOfAsync, init);
13122 }
13123 }
13124 if (isForOf || this.match(58)) {
13125 this.checkDestructuringPrivate(refExpressionErrors);
13126 this.toAssignable(init, true);
13127 const type = isForOf ? "ForOfStatement" : "ForInStatement";
13128 this.checkLVal(init, {
13129 type
13130 });
13131 return this.parseForIn(node, init, awaitAt);
13132 } else {
13133 this.checkExpressionErrors(refExpressionErrors, true);
13134 }
13135 if (awaitAt !== null) {
13136 this.unexpected(awaitAt);
13137 }
13138 return this.parseFor(node, init);
13139 }
13140 parseFunctionStatement(node, isAsync, isHangingDeclaration) {
13141 this.next();
13142 return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
13143 }
13144 parseIfStatement(node) {
13145 this.next();
13146 node.test = this.parseHeaderExpression();
13147 node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
13148 node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
13149 return this.finishNode(node, "IfStatement");
13150 }
13151 parseReturnStatement(node) {
13152 if (!this.prodParam.hasReturn) {
13153 this.raise(Errors.IllegalReturn, this.state.startLoc);
13154 }
13155 this.next();
13156 if (this.isLineTerminator()) {
13157 node.argument = null;
13158 } else {
13159 node.argument = this.parseExpression();
13160 this.semicolon();
13161 }
13162 return this.finishNode(node, "ReturnStatement");
13163 }
13164 parseSwitchStatement(node) {
13165 this.next();
13166 node.discriminant = this.parseHeaderExpression();
13167 const cases = node.cases = [];
13168 this.expect(5);
13169 this.state.labels.push(switchLabel);
13170 this.scope.enter(256);
13171 let cur;
13172 for (let sawDefault; !this.match(8);) {
13173 if (this.match(61) || this.match(65)) {
13174 const isCase = this.match(61);
13175 if (cur) this.finishNode(cur, "SwitchCase");
13176 cases.push(cur = this.startNode());
13177 cur.consequent = [];
13178 this.next();
13179 if (isCase) {
13180 cur.test = this.parseExpression();
13181 } else {
13182 if (sawDefault) {
13183 this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
13184 }
13185 sawDefault = true;
13186 cur.test = null;
13187 }
13188 this.expect(14);
13189 } else {
13190 if (cur) {
13191 cur.consequent.push(this.parseStatementListItem());
13192 } else {
13193 this.unexpected();
13194 }
13195 }
13196 }
13197 this.scope.exit();
13198 if (cur) this.finishNode(cur, "SwitchCase");
13199 this.next();
13200 this.state.labels.pop();
13201 return this.finishNode(node, "SwitchStatement");
13202 }
13203 parseThrowStatement(node) {
13204 this.next();
13205 if (this.hasPrecedingLineBreak()) {
13206 this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
13207 }
13208 node.argument = this.parseExpression();
13209 this.semicolon();
13210 return this.finishNode(node, "ThrowStatement");
13211 }
13212 parseCatchClauseParam() {
13213 const param = this.parseBindingAtom();
13214 this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
13215 this.checkLVal(param, {
13216 type: "CatchClause"
13217 }, 9);
13218 return param;
13219 }
13220 parseTryStatement(node) {
13221 this.next();
13222 node.block = this.parseBlock();
13223 node.handler = null;
13224 if (this.match(62)) {
13225 const clause = this.startNode();
13226 this.next();
13227 if (this.match(10)) {
13228 this.expect(10);
13229 clause.param = this.parseCatchClauseParam();
13230 this.expect(11);
13231 } else {
13232 clause.param = null;
13233 this.scope.enter(0);
13234 }
13235 clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
13236 this.scope.exit();
13237 node.handler = this.finishNode(clause, "CatchClause");
13238 }
13239 node.finalizer = this.eat(67) ? this.parseBlock() : null;
13240 if (!node.handler && !node.finalizer) {
13241 this.raise(Errors.NoCatchOrFinally, node);
13242 }
13243 return this.finishNode(node, "TryStatement");
13244 }
13245 parseVarStatement(node, kind, allowMissingInitializer = false) {
13246 this.next();
13247 this.parseVar(node, false, kind, allowMissingInitializer);
13248 this.semicolon();
13249 return this.finishNode(node, "VariableDeclaration");
13250 }
13251 parseWhileStatement(node) {
13252 this.next();
13253 node.test = this.parseHeaderExpression();
13254 this.state.labels.push(loopLabel);
13255 node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
13256 this.state.labels.pop();
13257 return this.finishNode(node, "WhileStatement");
13258 }
13259 parseWithStatement(node) {
13260 if (this.state.strict) {
13261 this.raise(Errors.StrictWith, this.state.startLoc);
13262 }
13263 this.next();
13264 node.object = this.parseHeaderExpression();
13265 node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
13266 return this.finishNode(node, "WithStatement");
13267 }
13268 parseEmptyStatement(node) {
13269 this.next();
13270 return this.finishNode(node, "EmptyStatement");
13271 }
13272 parseLabeledStatement(node, maybeName, expr, flags) {
13273 for (const label of this.state.labels) {
13274 if (label.name === maybeName) {
13275 this.raise(Errors.LabelRedeclaration, expr, {
13276 labelName: maybeName
13277 });
13278 }
13279 }
13280 const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
13281 for (let i = this.state.labels.length - 1; i >= 0; i--) {
13282 const label = this.state.labels[i];
13283 if (label.statementStart === node.start) {
13284 label.statementStart = this.sourceToOffsetPos(this.state.start);
13285 label.kind = kind;
13286 } else {
13287 break;
13288 }
13289 }
13290 this.state.labels.push({
13291 name: maybeName,
13292 kind: kind,
13293 statementStart: this.sourceToOffsetPos(this.state.start)
13294 });
13295 node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
13296 this.state.labels.pop();
13297 node.label = expr;
13298 return this.finishNode(node, "LabeledStatement");
13299 }
13300 parseExpressionStatement(node, expr, decorators) {
13301 node.expression = expr;
13302 this.semicolon();
13303 return this.finishNode(node, "ExpressionStatement");
13304 }
13305 parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
13306 const node = this.startNode();
13307 if (allowDirectives) {
13308 this.state.strictErrors.clear();
13309 }
13310 this.expect(5);
13311 if (createNewLexicalScope) {
13312 this.scope.enter(0);
13313 }
13314 this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
13315 if (createNewLexicalScope) {
13316 this.scope.exit();
13317 }
13318 return this.finishNode(node, "BlockStatement");
13319 }
13320 isValidDirective(stmt) {
13321 return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
13322 }
13323 parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
13324 const body = node.body = [];
13325 const directives = node.directives = [];
13326 this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
13327 }
13328 parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
13329 const oldStrict = this.state.strict;
13330 let hasStrictModeDirective = false;
13331 let parsedNonDirective = false;
13332 while (!this.match(end)) {
13333 const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
13334 if (directives && !parsedNonDirective) {
13335 if (this.isValidDirective(stmt)) {
13336 const directive = this.stmtToDirective(stmt);
13337 directives.push(directive);
13338 if (!hasStrictModeDirective && directive.value.value === "use strict") {
13339 hasStrictModeDirective = true;
13340 this.setStrict(true);
13341 }
13342 continue;
13343 }
13344 parsedNonDirective = true;
13345 this.state.strictErrors.clear();
13346 }
13347 body.push(stmt);
13348 }
13349 afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
13350 if (!oldStrict) {
13351 this.setStrict(false);
13352 }
13353 this.next();
13354 }
13355 parseFor(node, init) {
13356 node.init = init;
13357 this.semicolon(false);
13358 node.test = this.match(13) ? null : this.parseExpression();
13359 this.semicolon(false);
13360 node.update = this.match(11) ? null : this.parseExpression();
13361 this.expect(11);
13362 node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
13363 this.scope.exit();
13364 this.state.labels.pop();
13365 return this.finishNode(node, "ForStatement");
13366 }
13367 parseForIn(node, init, awaitAt) {
13368 const isForIn = this.match(58);
13369 this.next();
13370 if (isForIn) {
13371 if (awaitAt !== null) this.unexpected(awaitAt);
13372 } else {
13373 node.await = awaitAt !== null;
13374 }
13375 if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || !this.options.annexB || this.state.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) {
13376 this.raise(Errors.ForInOfLoopInitializer, init, {
13377 type: isForIn ? "ForInStatement" : "ForOfStatement"
13378 });
13379 }
13380 if (init.type === "AssignmentPattern") {
13381 this.raise(Errors.InvalidLhs, init, {
13382 ancestor: {
13383 type: "ForStatement"
13384 }
13385 });
13386 }
13387 node.left = init;
13388 node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
13389 this.expect(11);
13390 node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
13391 this.scope.exit();
13392 this.state.labels.pop();
13393 return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
13394 }
13395 parseVar(node, isFor, kind, allowMissingInitializer = false) {
13396 const declarations = node.declarations = [];
13397 node.kind = kind;
13398 for (;;) {
13399 const decl = this.startNode();
13400 this.parseVarId(decl, kind);
13401 decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
13402 if (decl.init === null && !allowMissingInitializer) {
13403 if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
13404 this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
13405 kind: "destructuring"
13406 });
13407 } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
13408 this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
13409 kind
13410 });
13411 }
13412 }
13413 declarations.push(this.finishNode(decl, "VariableDeclarator"));
13414 if (!this.eat(12)) break;
13415 }
13416 return node;
13417 }
13418 parseVarId(decl, kind) {
13419 const id = this.parseBindingAtom();
13420 if (kind === "using" || kind === "await using") {
13421 if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
13422 this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
13423 }
13424 } else {
13425 if (id.type === "VoidPattern") {
13426 this.raise(Errors.UnexpectedVoidPattern, id.loc.start);
13427 }
13428 }
13429 this.checkLVal(id, {
13430 type: "VariableDeclarator"
13431 }, kind === "var" ? 5 : 8201);
13432 decl.id = id;
13433 }
13434 parseAsyncFunctionExpression(node) {
13435 return this.parseFunction(node, 8);
13436 }
13437 parseFunction(node, flags = 0) {
13438 const hangingDeclaration = flags & 2;
13439 const isDeclaration = !!(flags & 1);
13440 const requireId = isDeclaration && !(flags & 4);
13441 const isAsync = !!(flags & 8);
13442 this.initFunction(node, isAsync);
13443 if (this.match(55)) {
13444 if (hangingDeclaration) {
13445 this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
13446 }
13447 this.next();
13448 node.generator = true;
13449 }
13450 if (isDeclaration) {
13451 node.id = this.parseFunctionId(requireId);
13452 }
13453 const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
13454 this.state.maybeInArrowParameters = false;
13455 this.scope.enter(514);
13456 this.prodParam.enter(functionFlags(isAsync, node.generator));
13457 if (!isDeclaration) {
13458 node.id = this.parseFunctionId();
13459 }
13460 this.parseFunctionParams(node, false);
13461 this.withSmartMixTopicForbiddingContext(() => {
13462 this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
13463 });
13464 this.prodParam.exit();
13465 this.scope.exit();
13466 if (isDeclaration && !hangingDeclaration) {
13467 this.registerFunctionStatementId(node);
13468 }
13469 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
13470 return node;
13471 }
13472 parseFunctionId(requireId) {
13473 return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
13474 }
13475 parseFunctionParams(node, isConstructor) {
13476 this.expect(10);
13477 this.expressionScope.enter(newParameterDeclarationScope());
13478 node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
13479 this.expressionScope.exit();
13480 }
13481 registerFunctionStatementId(node) {
13482 if (!node.id) return;
13483 this.scope.declareName(node.id.name, !this.options.annexB || this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? 5 : 8201 : 17, node.id.loc.start);
13484 }
13485 parseClass(node, isStatement, optionalId) {
13486 this.next();
13487 const oldStrict = this.state.strict;
13488 this.state.strict = true;
13489 this.parseClassId(node, isStatement, optionalId);
13490 this.parseClassSuper(node);
13491 node.body = this.parseClassBody(!!node.superClass, oldStrict);
13492 return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
13493 }
13494 isClassProperty() {
13495 return this.match(29) || this.match(13) || this.match(8);
13496 }
13497 isClassMethod() {
13498 return this.match(10);
13499 }
13500 nameIsConstructor(key) {
13501 return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
13502 }
13503 isNonstaticConstructor(method) {
13504 return !method.computed && !method.static && this.nameIsConstructor(method.key);
13505 }
13506 parseClassBody(hadSuperClass, oldStrict) {
13507 this.classScope.enter();
13508 const state = {
13509 hadConstructor: false,
13510 hadSuperClass
13511 };
13512 let decorators = [];
13513 const classBody = this.startNode();
13514 classBody.body = [];
13515 this.expect(5);
13516 this.withSmartMixTopicForbiddingContext(() => {
13517 while (!this.match(8)) {
13518 if (this.eat(13)) {
13519 if (decorators.length > 0) {
13520 throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
13521 }
13522 continue;
13523 }
13524 if (this.match(26)) {
13525 decorators.push(this.parseDecorator());
13526 continue;
13527 }
13528 const member = this.startNode();
13529 if (decorators.length) {
13530 member.decorators = decorators;
13531 this.resetStartLocationFromNode(member, decorators[0]);
13532 decorators = [];
13533 }
13534 this.parseClassMember(classBody, member, state);
13535 if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
13536 this.raise(Errors.DecoratorConstructor, member);
13537 }
13538 }
13539 });
13540 this.state.strict = oldStrict;
13541 this.next();
13542 if (decorators.length) {
13543 throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
13544 }
13545 this.classScope.exit();
13546 return this.finishNode(classBody, "ClassBody");
13547 }
13548 parseClassMemberFromModifier(classBody, member) {
13549 const key = this.parseIdentifier(true);
13550 if (this.isClassMethod()) {
13551 const method = member;
13552 method.kind = "method";
13553 method.computed = false;
13554 method.key = key;
13555 method.static = false;
13556 this.pushClassMethod(classBody, method, false, false, false, false);
13557 return true;
13558 } else if (this.isClassProperty()) {
13559 const prop = member;
13560 prop.computed = false;
13561 prop.key = key;
13562 prop.static = false;
13563 classBody.body.push(this.parseClassProperty(prop));
13564 return true;
13565 }
13566 this.resetPreviousNodeTrailingComments(key);
13567 return false;
13568 }
13569 parseClassMember(classBody, member, state) {
13570 const isStatic = this.isContextual(106);
13571 if (isStatic) {
13572 if (this.parseClassMemberFromModifier(classBody, member)) {
13573 return;
13574 }
13575 if (this.eat(5)) {
13576 this.parseClassStaticBlock(classBody, member);
13577 return;
13578 }
13579 }
13580 this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
13581 }
13582 parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
13583 const publicMethod = member;
13584 const privateMethod = member;
13585 const publicProp = member;
13586 const privateProp = member;
13587 const accessorProp = member;
13588 const method = publicMethod;
13589 const publicMember = publicMethod;
13590 member.static = isStatic;
13591 this.parsePropertyNamePrefixOperator(member);
13592 if (this.eat(55)) {
13593 method.kind = "method";
13594 const isPrivateName = this.match(139);
13595 this.parseClassElementName(method);
13596 this.parsePostMemberNameModifiers(method);
13597 if (isPrivateName) {
13598 this.pushClassPrivateMethod(classBody, privateMethod, true, false);
13599 return;
13600 }
13601 if (this.isNonstaticConstructor(publicMethod)) {
13602 this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
13603 }
13604 this.pushClassMethod(classBody, publicMethod, true, false, false, false);
13605 return;
13606 }
13607 const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
13608 const key = this.parseClassElementName(member);
13609 const maybeContextualKw = isContextual ? key.name : null;
13610 const isPrivate = this.isPrivateName(key);
13611 const maybeQuestionTokenStartLoc = this.state.startLoc;
13612 this.parsePostMemberNameModifiers(publicMember);
13613 if (this.isClassMethod()) {
13614 method.kind = "method";
13615 if (isPrivate) {
13616 this.pushClassPrivateMethod(classBody, privateMethod, false, false);
13617 return;
13618 }
13619 const isConstructor = this.isNonstaticConstructor(publicMethod);
13620 let allowsDirectSuper = false;
13621 if (isConstructor) {
13622 publicMethod.kind = "constructor";
13623 if (state.hadConstructor && !this.hasPlugin("typescript")) {
13624 this.raise(Errors.DuplicateConstructor, key);
13625 }
13626 if (isConstructor && this.hasPlugin("typescript") && member.override) {
13627 this.raise(Errors.OverrideOnConstructor, key);
13628 }
13629 state.hadConstructor = true;
13630 allowsDirectSuper = state.hadSuperClass;
13631 }
13632 this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
13633 } else if (this.isClassProperty()) {
13634 if (isPrivate) {
13635 this.pushClassPrivateProperty(classBody, privateProp);
13636 } else {
13637 this.pushClassProperty(classBody, publicProp);
13638 }
13639 } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
13640 this.resetPreviousNodeTrailingComments(key);
13641 const isGenerator = this.eat(55);
13642 if (publicMember.optional) {
13643 this.unexpected(maybeQuestionTokenStartLoc);
13644 }
13645 method.kind = "method";
13646 const isPrivate = this.match(139);
13647 this.parseClassElementName(method);
13648 this.parsePostMemberNameModifiers(publicMember);
13649 if (isPrivate) {
13650 this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
13651 } else {
13652 if (this.isNonstaticConstructor(publicMethod)) {
13653 this.raise(Errors.ConstructorIsAsync, publicMethod.key);
13654 }
13655 this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
13656 }
13657 } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
13658 this.resetPreviousNodeTrailingComments(key);
13659 method.kind = maybeContextualKw;
13660 const isPrivate = this.match(139);
13661 this.parseClassElementName(publicMethod);
13662 if (isPrivate) {
13663 this.pushClassPrivateMethod(classBody, privateMethod, false, false);
13664 } else {
13665 if (this.isNonstaticConstructor(publicMethod)) {
13666 this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
13667 }
13668 this.pushClassMethod(classBody, publicMethod, false, false, false, false);
13669 }
13670 this.checkGetterSetterParams(publicMethod);
13671 } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
13672 this.expectPlugin("decoratorAutoAccessors");
13673 this.resetPreviousNodeTrailingComments(key);
13674 const isPrivate = this.match(139);
13675 this.parseClassElementName(publicProp);
13676 this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
13677 } else if (this.isLineTerminator()) {
13678 if (isPrivate) {
13679 this.pushClassPrivateProperty(classBody, privateProp);
13680 } else {
13681 this.pushClassProperty(classBody, publicProp);
13682 }
13683 } else {
13684 this.unexpected();
13685 }
13686 }
13687 parseClassElementName(member) {
13688 const {
13689 type,
13690 value
13691 } = this.state;
13692 if ((type === 132 || type === 134) && member.static && value === "prototype") {
13693 this.raise(Errors.StaticPrototype, this.state.startLoc);
13694 }
13695 if (type === 139) {
13696 if (value === "constructor") {
13697 this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
13698 }
13699 const key = this.parsePrivateName();
13700 member.key = key;
13701 return key;
13702 }
13703 this.parsePropertyName(member);
13704 return member.key;
13705 }
13706 parseClassStaticBlock(classBody, member) {
13707 var _member$decorators;
13708 this.scope.enter(576 | 128 | 16);
13709 const oldLabels = this.state.labels;
13710 this.state.labels = [];
13711 this.prodParam.enter(0);
13712 const body = member.body = [];
13713 this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
13714 this.prodParam.exit();
13715 this.scope.exit();
13716 this.state.labels = oldLabels;
13717 classBody.body.push(this.finishNode(member, "StaticBlock"));
13718 if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
13719 this.raise(Errors.DecoratorStaticBlock, member);
13720 }
13721 }
13722 pushClassProperty(classBody, prop) {
13723 if (!prop.computed && this.nameIsConstructor(prop.key)) {
13724 this.raise(Errors.ConstructorClassField, prop.key);
13725 }
13726 classBody.body.push(this.parseClassProperty(prop));
13727 }
13728 pushClassPrivateProperty(classBody, prop) {
13729 const node = this.parseClassPrivateProperty(prop);
13730 classBody.body.push(node);
13731 this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
13732 }
13733 pushClassAccessorProperty(classBody, prop, isPrivate) {
13734 if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
13735 this.raise(Errors.ConstructorClassField, prop.key);
13736 }
13737 const node = this.parseClassAccessorProperty(prop);
13738 classBody.body.push(node);
13739 if (isPrivate) {
13740 this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
13741 }
13742 }
13743 pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
13744 classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
13745 }
13746 pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
13747 const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
13748 classBody.body.push(node);
13749 const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
13750 this.declareClassPrivateMethodInScope(node, kind);
13751 }
13752 declareClassPrivateMethodInScope(node, kind) {
13753 this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
13754 }
13755 parsePostMemberNameModifiers(methodOrProp) {}
13756 parseClassPrivateProperty(node) {
13757 this.parseInitializer(node);
13758 this.semicolon();
13759 return this.finishNode(node, "ClassPrivateProperty");
13760 }
13761 parseClassProperty(node) {
13762 this.parseInitializer(node);
13763 this.semicolon();
13764 return this.finishNode(node, "ClassProperty");
13765 }
13766 parseClassAccessorProperty(node) {
13767 this.parseInitializer(node);
13768 this.semicolon();
13769 return this.finishNode(node, "ClassAccessorProperty");
13770 }
13771 parseInitializer(node) {
13772 this.scope.enter(576 | 16);
13773 this.expressionScope.enter(newExpressionScope());
13774 this.prodParam.enter(0);
13775 node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
13776 this.expressionScope.exit();
13777 this.prodParam.exit();
13778 this.scope.exit();
13779 }
13780 parseClassId(node, isStatement, optionalId, bindingType = 8331) {
13781 if (tokenIsIdentifier(this.state.type)) {
13782 node.id = this.parseIdentifier();
13783 if (isStatement) {
13784 this.declareNameFromIdentifier(node.id, bindingType);
13785 }
13786 } else {
13787 if (optionalId || !isStatement) {
13788 node.id = null;
13789 } else {
13790 throw this.raise(Errors.MissingClassName, this.state.startLoc);
13791 }
13792 }
13793 }
13794 parseClassSuper(node) {
13795 node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
13796 }
13797 parseExport(node, decorators) {
13798 const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
13799 const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
13800 const parseAfterDefault = !hasDefault || this.eat(12);
13801 const hasStar = parseAfterDefault && this.eatExportStar(node);
13802 const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
13803 const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
13804 const isFromRequired = hasDefault || hasStar;
13805 if (hasStar && !hasNamespace) {
13806 if (hasDefault) this.unexpected();
13807 if (decorators) {
13808 throw this.raise(Errors.UnsupportedDecoratorExport, node);
13809 }
13810 this.parseExportFrom(node, true);
13811 this.sawUnambiguousESM = true;
13812 return this.finishNode(node, "ExportAllDeclaration");
13813 }
13814 const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
13815 if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
13816 this.unexpected(null, 5);
13817 }
13818 if (hasNamespace && parseAfterNamespace) {
13819 this.unexpected(null, 98);
13820 }
13821 let hasDeclaration;
13822 if (isFromRequired || hasSpecifiers) {
13823 hasDeclaration = false;
13824 if (decorators) {
13825 throw this.raise(Errors.UnsupportedDecoratorExport, node);
13826 }
13827 this.parseExportFrom(node, isFromRequired);
13828 } else {
13829 hasDeclaration = this.maybeParseExportDeclaration(node);
13830 }
13831 if (isFromRequired || hasSpecifiers || hasDeclaration) {
13832 var _node2$declaration;
13833 const node2 = node;
13834 this.checkExport(node2, true, false, !!node2.source);
13835 if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
13836 this.maybeTakeDecorators(decorators, node2.declaration, node2);
13837 } else if (decorators) {
13838 throw this.raise(Errors.UnsupportedDecoratorExport, node);
13839 }
13840 this.sawUnambiguousESM = true;
13841 return this.finishNode(node2, "ExportNamedDeclaration");
13842 }
13843 if (this.eat(65)) {
13844 const node2 = node;
13845 const decl = this.parseExportDefaultExpression();
13846 node2.declaration = decl;
13847 if (decl.type === "ClassDeclaration") {
13848 this.maybeTakeDecorators(decorators, decl, node2);
13849 } else if (decorators) {
13850 throw this.raise(Errors.UnsupportedDecoratorExport, node);
13851 }
13852 this.checkExport(node2, true, true);
13853 this.sawUnambiguousESM = true;
13854 return this.finishNode(node2, "ExportDefaultDeclaration");
13855 }
13856 throw this.unexpected(null, 5);
13857 }
13858 eatExportStar(node) {
13859 return this.eat(55);
13860 }
13861 maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
13862 if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
13863 this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
13864 const id = maybeDefaultIdentifier || this.parseIdentifier(true);
13865 const specifier = this.startNodeAtNode(id);
13866 specifier.exported = id;
13867 node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
13868 return true;
13869 }
13870 return false;
13871 }
13872 maybeParseExportNamespaceSpecifier(node) {
13873 if (this.isContextual(93)) {
13874 var _ref, _ref$specifiers;
13875 (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
13876 const specifier = this.startNodeAt(this.state.lastTokStartLoc);
13877 this.next();
13878 specifier.exported = this.parseModuleExportName();
13879 node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
13880 return true;
13881 }
13882 return false;
13883 }
13884 maybeParseExportNamedSpecifiers(node) {
13885 if (this.match(5)) {
13886 const node2 = node;
13887 if (!node2.specifiers) node2.specifiers = [];
13888 const isTypeExport = node2.exportKind === "type";
13889 node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
13890 node2.source = null;
13891 if (this.hasPlugin("importAssertions")) {
13892 node2.assertions = [];
13893 } else {
13894 node2.attributes = [];
13895 }
13896 node2.declaration = null;
13897 return true;
13898 }
13899 return false;
13900 }
13901 maybeParseExportDeclaration(node) {
13902 if (this.shouldParseExportDeclaration()) {
13903 node.specifiers = [];
13904 node.source = null;
13905 if (this.hasPlugin("importAssertions")) {
13906 node.assertions = [];
13907 } else {
13908 node.attributes = [];
13909 }
13910 node.declaration = this.parseExportDeclaration(node);
13911 return true;
13912 }
13913 return false;
13914 }
13915 isAsyncFunction() {
13916 if (!this.isContextual(95)) return false;
13917 const next = this.nextTokenInLineStart();
13918 return this.isUnparsedContextual(next, "function");
13919 }
13920 parseExportDefaultExpression() {
13921 const expr = this.startNode();
13922 if (this.match(68)) {
13923 this.next();
13924 return this.parseFunction(expr, 1 | 4);
13925 } else if (this.isAsyncFunction()) {
13926 this.next();
13927 this.next();
13928 return this.parseFunction(expr, 1 | 4 | 8);
13929 }
13930 if (this.match(80)) {
13931 return this.parseClass(expr, true, true);
13932 }
13933 if (this.match(26)) {
13934 if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
13935 this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
13936 }
13937 return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
13938 }
13939 if (this.match(75) || this.match(74) || this.isLet() || this.isUsing() || this.isAwaitUsing()) {
13940 throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
13941 }
13942 const res = this.parseMaybeAssignAllowIn();
13943 this.semicolon();
13944 return res;
13945 }
13946 parseExportDeclaration(node) {
13947 if (this.match(80)) {
13948 const node = this.parseClass(this.startNode(), true, false);
13949 return node;
13950 }
13951 return this.parseStatementListItem();
13952 }
13953 isExportDefaultSpecifier() {
13954 const {
13955 type
13956 } = this.state;
13957 if (tokenIsIdentifier(type)) {
13958 if (type === 95 && !this.state.containsEsc || type === 100) {
13959 return false;
13960 }
13961 if ((type === 130 || type === 129) && !this.state.containsEsc) {
13962 const next = this.nextTokenStart();
13963 const nextChar = this.input.charCodeAt(next);
13964 if (nextChar === 123 || this.chStartsBindingIdentifier(nextChar, next) && !this.input.startsWith("from", next)) {
13965 this.expectOnePlugin(["flow", "typescript"]);
13966 return false;
13967 }
13968 }
13969 } else if (!this.match(65)) {
13970 return false;
13971 }
13972 const next = this.nextTokenStart();
13973 const hasFrom = this.isUnparsedContextual(next, "from");
13974 if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
13975 return true;
13976 }
13977 if (this.match(65) && hasFrom) {
13978 const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
13979 return nextAfterFrom === 34 || nextAfterFrom === 39;
13980 }
13981 return false;
13982 }
13983 parseExportFrom(node, expect) {
13984 if (this.eatContextual(98)) {
13985 node.source = this.parseImportSource();
13986 this.checkExport(node);
13987 this.maybeParseImportAttributes(node);
13988 this.checkJSONModuleImport(node);
13989 } else if (expect) {
13990 this.unexpected();
13991 }
13992 this.semicolon();
13993 }
13994 shouldParseExportDeclaration() {
13995 const {
13996 type
13997 } = this.state;
13998 if (type === 26) {
13999 this.expectOnePlugin(["decorators", "decorators-legacy"]);
14000 if (this.hasPlugin("decorators")) {
14001 if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
14002 this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
14003 }
14004 return true;
14005 }
14006 }
14007 if (this.isUsing()) {
14008 this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
14009 return true;
14010 }
14011 if (this.isAwaitUsing()) {
14012 this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
14013 return true;
14014 }
14015 return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
14016 }
14017 checkExport(node, checkNames, isDefault, isFrom) {
14018 if (checkNames) {
14019 var _node$specifiers;
14020 if (isDefault) {
14021 this.checkDuplicateExports(node, "default");
14022 if (this.hasPlugin("exportDefaultFrom")) {
14023 var _declaration$extra;
14024 const declaration = node.declaration;
14025 if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
14026 this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
14027 }
14028 }
14029 } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
14030 for (const specifier of node.specifiers) {
14031 const {
14032 exported
14033 } = specifier;
14034 const exportName = exported.type === "Identifier" ? exported.name : exported.value;
14035 this.checkDuplicateExports(specifier, exportName);
14036 if (!isFrom && specifier.local) {
14037 const {
14038 local
14039 } = specifier;
14040 if (local.type !== "Identifier") {
14041 this.raise(Errors.ExportBindingIsString, specifier, {
14042 localName: local.value,
14043 exportName
14044 });
14045 } else {
14046 this.checkReservedWord(local.name, local.loc.start, true, false);
14047 this.scope.checkLocalExport(local);
14048 }
14049 }
14050 }
14051 } else if (node.declaration) {
14052 const decl = node.declaration;
14053 if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
14054 const {
14055 id
14056 } = decl;
14057 if (!id) throw new Error("Assertion failure");
14058 this.checkDuplicateExports(node, id.name);
14059 } else if (decl.type === "VariableDeclaration") {
14060 for (const declaration of decl.declarations) {
14061 this.checkDeclaration(declaration.id);
14062 }
14063 }
14064 }
14065 }
14066 }
14067 checkDeclaration(node) {
14068 if (node.type === "Identifier") {
14069 this.checkDuplicateExports(node, node.name);
14070 } else if (node.type === "ObjectPattern") {
14071 for (const prop of node.properties) {
14072 this.checkDeclaration(prop);
14073 }
14074 } else if (node.type === "ArrayPattern") {
14075 for (const elem of node.elements) {
14076 if (elem) {
14077 this.checkDeclaration(elem);
14078 }
14079 }
14080 } else if (node.type === "ObjectProperty") {
14081 this.checkDeclaration(node.value);
14082 } else if (node.type === "RestElement") {
14083 this.checkDeclaration(node.argument);
14084 } else if (node.type === "AssignmentPattern") {
14085 this.checkDeclaration(node.left);
14086 }
14087 }
14088 checkDuplicateExports(node, exportName) {
14089 if (this.exportedIdentifiers.has(exportName)) {
14090 if (exportName === "default") {
14091 this.raise(Errors.DuplicateDefaultExport, node);
14092 } else {
14093 this.raise(Errors.DuplicateExport, node, {
14094 exportName
14095 });
14096 }
14097 }
14098 this.exportedIdentifiers.add(exportName);
14099 }
14100 parseExportSpecifiers(isInTypeExport) {
14101 const nodes = [];
14102 let first = true;
14103 this.expect(5);
14104 while (!this.eat(8)) {
14105 if (first) {
14106 first = false;
14107 } else {
14108 this.expect(12);
14109 if (this.eat(8)) break;
14110 }
14111 const isMaybeTypeOnly = this.isContextual(130);
14112 const isString = this.match(134);
14113 const node = this.startNode();
14114 node.local = this.parseModuleExportName();
14115 nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
14116 }
14117 return nodes;
14118 }
14119 parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
14120 if (this.eatContextual(93)) {
14121 node.exported = this.parseModuleExportName();
14122 } else if (isString) {
14123 node.exported = this.cloneStringLiteral(node.local);
14124 } else if (!node.exported) {
14125 node.exported = this.cloneIdentifier(node.local);
14126 }
14127 return this.finishNode(node, "ExportSpecifier");
14128 }
14129 parseModuleExportName() {
14130 if (this.match(134)) {
14131 const result = this.parseStringLiteral(this.state.value);
14132 const surrogate = loneSurrogate.exec(result.value);
14133 if (surrogate) {
14134 this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
14135 surrogateCharCode: surrogate[0].charCodeAt(0)
14136 });
14137 }
14138 return result;
14139 }
14140 return this.parseIdentifier(true);
14141 }
14142 isJSONModuleImport(node) {
14143 if (node.assertions != null) {
14144 return node.assertions.some(({
14145 key,
14146 value
14147 }) => {
14148 return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
14149 });
14150 }
14151 return false;
14152 }
14153 checkImportReflection(node) {
14154 const {
14155 specifiers
14156 } = node;
14157 const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
14158 if (node.phase === "source") {
14159 if (singleBindingType !== "ImportDefaultSpecifier") {
14160 this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
14161 }
14162 } else if (node.phase === "defer") {
14163 if (singleBindingType !== "ImportNamespaceSpecifier") {
14164 this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
14165 }
14166 } else if (node.module) {
14167 var _node$assertions;
14168 if (singleBindingType !== "ImportDefaultSpecifier") {
14169 this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
14170 }
14171 if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
14172 this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
14173 }
14174 }
14175 }
14176 checkJSONModuleImport(node) {
14177 if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
14178 const {
14179 specifiers
14180 } = node;
14181 if (specifiers != null) {
14182 const nonDefaultNamedSpecifier = specifiers.find(specifier => {
14183 let imported;
14184 if (specifier.type === "ExportSpecifier") {
14185 imported = specifier.local;
14186 } else if (specifier.type === "ImportSpecifier") {
14187 imported = specifier.imported;
14188 }
14189 if (imported !== undefined) {
14190 return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
14191 }
14192 });
14193 if (nonDefaultNamedSpecifier !== undefined) {
14194 this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
14195 }
14196 }
14197 }
14198 }
14199 isPotentialImportPhase(isExport) {
14200 if (isExport) return false;
14201 return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
14202 }
14203 applyImportPhase(node, isExport, phase, loc) {
14204 if (isExport) {
14205 return;
14206 }
14207 if (phase === "module") {
14208 this.expectPlugin("importReflection", loc);
14209 node.module = true;
14210 } else if (this.hasPlugin("importReflection")) {
14211 node.module = false;
14212 }
14213 if (phase === "source") {
14214 this.expectPlugin("sourcePhaseImports", loc);
14215 node.phase = "source";
14216 } else if (phase === "defer") {
14217 this.expectPlugin("deferredImportEvaluation", loc);
14218 node.phase = "defer";
14219 } else if (this.hasPlugin("sourcePhaseImports")) {
14220 node.phase = null;
14221 }
14222 }
14223 parseMaybeImportPhase(node, isExport) {
14224 if (!this.isPotentialImportPhase(isExport)) {
14225 this.applyImportPhase(node, isExport, null);
14226 return null;
14227 }
14228 const phaseIdentifier = this.startNode();
14229 const phaseIdentifierName = this.parseIdentifierName(true);
14230 const {
14231 type
14232 } = this.state;
14233 const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
14234 if (isImportPhase) {
14235 this.applyImportPhase(node, isExport, phaseIdentifierName, phaseIdentifier.loc.start);
14236 return null;
14237 } else {
14238 this.applyImportPhase(node, isExport, null);
14239 return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
14240 }
14241 }
14242 isPrecedingIdImportPhase(phase) {
14243 const {
14244 type
14245 } = this.state;
14246 return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
14247 }
14248 parseImport(node) {
14249 if (this.match(134)) {
14250 return this.parseImportSourceAndAttributes(node);
14251 }
14252 return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
14253 }
14254 parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
14255 node.specifiers = [];
14256 const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
14257 const parseNext = !hasDefault || this.eat(12);
14258 const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
14259 if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
14260 this.expectContextual(98);
14261 return this.parseImportSourceAndAttributes(node);
14262 }
14263 parseImportSourceAndAttributes(node) {
14264 var _node$specifiers2;
14265 (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
14266 node.source = this.parseImportSource();
14267 this.maybeParseImportAttributes(node);
14268 this.checkImportReflection(node);
14269 this.checkJSONModuleImport(node);
14270 this.semicolon();
14271 this.sawUnambiguousESM = true;
14272 return this.finishNode(node, "ImportDeclaration");
14273 }
14274 parseImportSource() {
14275 if (!this.match(134)) this.unexpected();
14276 return this.parseExprAtom();
14277 }
14278 parseImportSpecifierLocal(node, specifier, type) {
14279 specifier.local = this.parseIdentifier();
14280 node.specifiers.push(this.finishImportSpecifier(specifier, type));
14281 }
14282 finishImportSpecifier(specifier, type, bindingType = 8201) {
14283 this.checkLVal(specifier.local, {
14284 type
14285 }, bindingType);
14286 return this.finishNode(specifier, type);
14287 }
14288 parseImportAttributes() {
14289 this.expect(5);
14290 const attrs = [];
14291 const attrNames = new Set();
14292 do {
14293 if (this.match(8)) {
14294 break;
14295 }
14296 const node = this.startNode();
14297 const keyName = this.state.value;
14298 if (attrNames.has(keyName)) {
14299 this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
14300 key: keyName
14301 });
14302 }
14303 attrNames.add(keyName);
14304 if (this.match(134)) {
14305 node.key = this.parseStringLiteral(keyName);
14306 } else {
14307 node.key = this.parseIdentifier(true);
14308 }
14309 this.expect(14);
14310 if (!this.match(134)) {
14311 throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
14312 }
14313 node.value = this.parseStringLiteral(this.state.value);
14314 attrs.push(this.finishNode(node, "ImportAttribute"));
14315 } while (this.eat(12));
14316 this.expect(8);
14317 return attrs;
14318 }
14319 parseModuleAttributes() {
14320 const attrs = [];
14321 const attributes = new Set();
14322 do {
14323 const node = this.startNode();
14324 node.key = this.parseIdentifier(true);
14325 if (node.key.name !== "type") {
14326 this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
14327 }
14328 if (attributes.has(node.key.name)) {
14329 this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
14330 key: node.key.name
14331 });
14332 }
14333 attributes.add(node.key.name);
14334 this.expect(14);
14335 if (!this.match(134)) {
14336 throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
14337 }
14338 node.value = this.parseStringLiteral(this.state.value);
14339 attrs.push(this.finishNode(node, "ImportAttribute"));
14340 } while (this.eat(12));
14341 return attrs;
14342 }
14343 maybeParseImportAttributes(node) {
14344 let attributes;
14345 var useWith = false;
14346 if (this.match(76)) {
14347 if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
14348 return;
14349 }
14350 this.next();
14351 if (this.hasPlugin("moduleAttributes")) {
14352 attributes = this.parseModuleAttributes();
14353 this.addExtra(node, "deprecatedWithLegacySyntax", true);
14354 } else {
14355 attributes = this.parseImportAttributes();
14356 }
14357 useWith = true;
14358 } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
14359 if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
14360 this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
14361 }
14362 if (!this.hasPlugin("importAssertions")) {
14363 this.addExtra(node, "deprecatedAssertSyntax", true);
14364 }
14365 this.next();
14366 attributes = this.parseImportAttributes();
14367 } else {
14368 attributes = [];
14369 }
14370 if (!useWith && this.hasPlugin("importAssertions")) {
14371 node.assertions = attributes;
14372 } else {
14373 node.attributes = attributes;
14374 }
14375 }
14376 maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
14377 if (maybeDefaultIdentifier) {
14378 const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
14379 specifier.local = maybeDefaultIdentifier;
14380 node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
14381 return true;
14382 } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
14383 this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
14384 return true;
14385 }
14386 return false;
14387 }
14388 maybeParseStarImportSpecifier(node) {
14389 if (this.match(55)) {
14390 const specifier = this.startNode();
14391 this.next();
14392 this.expectContextual(93);
14393 this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
14394 return true;
14395 }
14396 return false;
14397 }
14398 parseNamedImportSpecifiers(node) {
14399 let first = true;
14400 this.expect(5);
14401 while (!this.eat(8)) {
14402 if (first) {
14403 first = false;
14404 } else {
14405 if (this.eat(14)) {
14406 throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
14407 }
14408 this.expect(12);
14409 if (this.eat(8)) break;
14410 }
14411 const specifier = this.startNode();
14412 const importedIsString = this.match(134);
14413 const isMaybeTypeOnly = this.isContextual(130);
14414 specifier.imported = this.parseModuleExportName();
14415 const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
14416 node.specifiers.push(importSpecifier);
14417 }
14418 }
14419 parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
14420 if (this.eatContextual(93)) {
14421 specifier.local = this.parseIdentifier();
14422 } else {
14423 const {
14424 imported
14425 } = specifier;
14426 if (importedIsString) {
14427 throw this.raise(Errors.ImportBindingIsString, specifier, {
14428 importName: imported.value
14429 });
14430 }
14431 this.checkReservedWord(imported.name, specifier.loc.start, true, true);
14432 if (!specifier.local) {
14433 specifier.local = this.cloneIdentifier(imported);
14434 }
14435 }
14436 return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
14437 }
14438 isThisParam(param) {
14439 return param.type === "Identifier" && param.name === "this";
14440 }
14441}
14442class Parser extends StatementParser {
14443 constructor(options, input, pluginsMap) {
14444 const normalizedOptions = getOptions(options);
14445 super(normalizedOptions, input);
14446 this.options = normalizedOptions;
14447 this.initializeScopes();
14448 this.plugins = pluginsMap;
14449 this.filename = normalizedOptions.sourceFilename;
14450 this.startIndex = normalizedOptions.startIndex;
14451 let optionFlags = 0;
14452 if (normalizedOptions.allowAwaitOutsideFunction) {
14453 optionFlags |= 1;
14454 }
14455 if (normalizedOptions.allowReturnOutsideFunction) {
14456 optionFlags |= 2;
14457 }
14458 if (normalizedOptions.allowImportExportEverywhere) {
14459 optionFlags |= 8;
14460 }
14461 if (normalizedOptions.allowSuperOutsideMethod) {
14462 optionFlags |= 16;
14463 }
14464 if (normalizedOptions.allowUndeclaredExports) {
14465 optionFlags |= 64;
14466 }
14467 if (normalizedOptions.allowNewTargetOutsideFunction) {
14468 optionFlags |= 4;
14469 }
14470 if (normalizedOptions.allowYieldOutsideFunction) {
14471 optionFlags |= 32;
14472 }
14473 if (normalizedOptions.ranges) {
14474 optionFlags |= 128;
14475 }
14476 if (normalizedOptions.tokens) {
14477 optionFlags |= 256;
14478 }
14479 if (normalizedOptions.createImportExpressions) {
14480 optionFlags |= 512;
14481 }
14482 if (normalizedOptions.createParenthesizedExpressions) {
14483 optionFlags |= 1024;
14484 }
14485 if (normalizedOptions.errorRecovery) {
14486 optionFlags |= 2048;
14487 }
14488 if (normalizedOptions.attachComment) {
14489 optionFlags |= 4096;
14490 }
14491 if (normalizedOptions.annexB) {
14492 optionFlags |= 8192;
14493 }
14494 this.optionFlags = optionFlags;
14495 }
14496 getScopeHandler() {
14497 return ScopeHandler;
14498 }
14499 parse() {
14500 this.enterInitialScopes();
14501 const file = this.startNode();
14502 const program = this.startNode();
14503 this.nextToken();
14504 file.errors = null;
14505 const result = this.parseTopLevel(file, program);
14506 result.errors = this.state.errors;
14507 result.comments.length = this.state.commentsLen;
14508 return result;
14509 }
14510}
14511function parse(input, options) {
14512 var _options;
14513 if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
14514 options = Object.assign({}, options);
14515 try {
14516 options.sourceType = "module";
14517 const parser = getParser(options, input);
14518 const ast = parser.parse();
14519 if (parser.sawUnambiguousESM) {
14520 return ast;
14521 }
14522 if (parser.ambiguousScriptDifferentAst) {
14523 try {
14524 options.sourceType = "script";
14525 return getParser(options, input).parse();
14526 } catch (_unused) {}
14527 } else {
14528 ast.program.sourceType = "script";
14529 }
14530 return ast;
14531 } catch (moduleError) {
14532 try {
14533 options.sourceType = "script";
14534 return getParser(options, input).parse();
14535 } catch (_unused2) {}
14536 throw moduleError;
14537 }
14538 } else {
14539 return getParser(options, input).parse();
14540 }
14541}
14542function parseExpression(input, options) {
14543 const parser = getParser(options, input);
14544 if (parser.options.strictMode) {
14545 parser.state.strict = true;
14546 }
14547 return parser.getExpression();
14548}
14549function generateExportedTokenTypes(internalTokenTypes) {
14550 const tokenTypes = {};
14551 for (const typeName of Object.keys(internalTokenTypes)) {
14552 tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
14553 }
14554 return tokenTypes;
14555}
14556const tokTypes = generateExportedTokenTypes(tt);
14557function getParser(options, input) {
14558 let cls = Parser;
14559 const pluginsMap = new Map();
14560 if (options != null && options.plugins) {
14561 for (const plugin of options.plugins) {
14562 let name, opts;
14563 if (typeof plugin === "string") {
14564 name = plugin;
14565 } else {
14566 [name, opts] = plugin;
14567 }
14568 if (!pluginsMap.has(name)) {
14569 pluginsMap.set(name, opts || {});
14570 }
14571 }
14572 validatePlugins(pluginsMap);
14573 cls = getParserClass(pluginsMap);
14574 }
14575 return new cls(options, input, pluginsMap);
14576}
14577const parserClassCache = new Map();
14578function getParserClass(pluginsMap) {
14579 const pluginList = [];
14580 for (const name of mixinPluginNames) {
14581 if (pluginsMap.has(name)) {
14582 pluginList.push(name);
14583 }
14584 }
14585 const key = pluginList.join("|");
14586 let cls = parserClassCache.get(key);
14587 if (!cls) {
14588 cls = Parser;
14589 for (const plugin of pluginList) {
14590 cls = mixinPlugins[plugin](cls);
14591 }
14592 parserClassCache.set(key, cls);
14593 }
14594 return cls;
14595}
14596exports.parse = parse;
14597exports.parseExpression = parseExpression;
14598exports.tokTypes = tokTypes;
14599//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.